Methods Usage v0.1.13

import { Banana } from '@rize-labs/banana-wallet-sdk/dist/BananaProvider'
import { Chains } from '@rize-labs/banana-wallet-sdk/dist/Constants'

/**
 * Banana Module:
 * This module will be responsible to deliver everything related to account abstraction
 * , smart contract wallets and touchId authentication i.e aaProvider, walletAddress, walletapi etc
 */

/*
 * Banana Module Initialization
 * @params chain enum and JsonRpcUrl
 * @returns Banana Class instance
 */
const jsonRpcUrl = 'https://eth-goerli.g.alchemy.com/v2/<Alchemy goerli api key>';
const bananaInstance = new Banana(Chains.goerli, jsonRpcUrl);

/*
 * @params none
 * @returns walletName: string
 * accessed from the banana instance and used to fetch walletname.
 * cached in user's cookie storage 
 */
const walletName: string = bananaInstance.getWalletName();

// In case walletName is not fetched, the dev needs to prompt the user to enter the walletName which he had
// previously used with the dapp. In case the user hasn't created any wallet with the dapp dev can promt
// user for new wallet name for his wallet.

/*
 * @params walletName: string
 * @returns isUnique: bool
 * @nature async
 * accessed from banana instance and be used to check if walletName 
 * for new wallet provided by user is unique or not
 */
const isUnqiue: boolean = await bananaInstance.isWalletNameUnique(walletName);

// when the user doesn't possess any wallet corresponding to walletName username 
const walletCreationResponse = await bananaInstance.createWallet(walletName);

// when the user already has a wallet with username walletName. This username can be given directly by user
// or fetched by dev using getWalletName() method
const walletConnectionResponse = await bananaInstance.connectWallet(walletName);

// method which returns the provider which can be further used to retreive signer and initialize contract
const bananaProvider = await bananaInstance.getBananaProvider();

// extracting aaSigner
const bananaSigner = bananaProvider.getSigner();

// initializing sample greeter contract with aaSigner
const GreeterContract = new ethers.Contract(
     addresses.Greeter,
     GreeterArtifact.abi,
     bananaSigner
   );

// greeter contract greet calldata
const greetCallData = GreeterContract.interface.encodeFunctionData(
      "greet",
       []
    );

/*
 * @params functionCalldata: bytes, walletAddress: string, address: string, value: double
 * @return transaction hash
 * @nature async
 */
const txn = await bananaInstance.execute(greetCallData, Greeter.address, amount);

//Similar for signing and verifying message the flow looks like

/**
 * @method verify
 * @param { string } signature, { string } messageSigned, { string } eoaAddress
 * @returns { boolean } isVerified
 * method to verify message against signature
 */
const sampleMsg = "Hello World";
const eoaAddress = bananaInstance.getEOAAddress();
const signMessageResponse = await bananaInstance.signMessage(sampleMsg);
const messageSigned = signMessageResponse.messageSigned;
const signatuer = signMessageResponse.signature;
const signedMessage = await bananaInstance.verifySignature(signature, messageSigned, eoaAddress);

If you have any questions please post them Banana SDK Discord forum.

Last updated