👨‍đŸ’ģSDK core

Compatible Networks

  • Optimism Goerli

  • Polygon Mumbai

  • Goerli Testnet

  • Arbitrum Testnet

Instance creation and imports

Developers can directly get access to Banana module through our SDK just by importing the banana module from banana-wallet-sdk

import { Banana } from '@bananahq/react-native-sdk'

While setting up the instance you will also require app deeplink you can refer below material for creating deeplink for IOS and android.

Creating deeplink for android here

Creating deeplink for IOS here

After creating deeplink, You can start accessing the methods it exposes just by creating an instance of Banana by specifying the appropriate chain and deeplink

You can create a banana Instance as:

// importing chains and banana module from banana wallet sdk
import { Banana, Chains } from 'bananahq/react-native-sdk' 

const APP_DEEPLINK = <YOUR APP's DEEPLINK>

// creating chain specific instance of banana module
const bananaInstance = new Banana(Chains.mumbai, APP_DEEPLINK);

Methods by Banana Module

Once the instance is ready, developers can access multiple methods the banana module provides.

Methods offered by the banana module are:

  • createWallet

  • connectWallet

  • getWalletName

  • getEOAAddress

  • resetWallet

  • verifySignature

  • signBananaMessage (attached with signer)

createWallet

createWallet the method enables developers to create a wallet for their users. This method should be called only when the user has to create a wallet. Invoking this method prompts the user to enter a name for his wallet once entered the wallet name provided by the user is mapped with the generated wallet. Later on, the user can use this wallet name to access his wallet.

Once the wallet is successfully created this method caches some public wallet metadata at the user's browsers storage to enable the user to fastly connect with his already created wallet using connectWallet method.

This method doesn't take any param in input as the wallet name-taking process is already hardcoded in it. On successful wallet creation, this method returns a wallet instance. Through this developer can query for provider and signer corresponding to that wallet using getSigner and getProvider methods.

Usage

import { Wallet } from 'bananahq/react-native-sdk';
/**
 * @method createWallet
 * @param { string } walletIdentifier
 * @returns 
 * success: returns { status: success, address: walletAddress }
 * error: returns { status: error, address: "" }
 * set up signers and provider along with it create walletmetadata corresponding to the new wallet request.
 */
   
const walletInstanace: Wallet = await bananaInstance.createWallet()

connectWallet

connectWallet the method is to be used when developers know that the user has already created a wallet on a dapp or the user either knows his wallet name or wallet metadata is present in browser cookie storage (this can be checked using the getWalletName method). connectWallet expects a wallet name and it returns a wallet instance from which devs can extract corresponding providers and signers for the wallet.

This method can be used to automatically connect the wallet when the user switches between different pages or reloads a website.

Usage

import { Wallet } from 'bananahq/react-native-sdk' 
/** 
 * @method connectWallet
 * @param { string } walletIdentifier
 * @returns 
 * success: returns { status: success, address: walletAddress }
 * error: returns { status: error, address: "" }
 * set up providers and signers at the sdk end in case user's already has a wallet created before.
 */
const walletInstance: Wallet = bananaInstance.connectWallet(walletName);

getWalletName

getWalletName the method enables developers to read the user's cookie and retrieve the saved wallet name for display purposes. If this method does not return anything, it indicates that the user may have cleared their cookies. In such cases, developers should manually prompt the user for the wallet name.

Usage

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

getEOAAddress

getEOAAddress the method enables developers to retrieve the q values, which are the public address representation of the address generated by the device. The q values returned can be used for verifying the signature.

Usage


/**
 * @method getOwnerAddress
 * @param { string } walletName
 * @returns { string } eoaAddress
 * method to return the hardware address for a specific walletName.
 */
const qValues = await bananaInstance.getEOAAdress();

isWalletNameUnique

isWalletNameUnique the method enables developers to check if the wallet name suggested by their user is unique or not. This is possible because the wallet name serves as the primary key in the wallet credentials database on our server. As a suggestion, users can choose to keep their Gmail account username as their wallet name, as it is always unique.

Usage

/**
 * @method isWalletNameUnique
 * @param { string } walletName
 * @returns { boolean } isWalletNameTaken
 * check isWalletName user is giving is already taken or not
 */
const isUnqiue: boolean = await bananaInstance.isWalletNameUnique(walletName);

resetWallet

resetWallet the method enables developers to clear the current wallet metadata from the cookie's local storage. This enables the user to deploy a new wallet with a new username if needed. The method does not delete the existing wallet; instead, the user can roll back and use their previous wallet on the dapp by simply entering their previous wallet username by passing the previous walletName in connectWallet method. This method does not require any input parameters and does not return any values. Developers can call it directly to clear the wallet metadata.

Usage

/**
 * @method resetWallet
 * @param none
 * @returns { string } walletName
 * method to remove current wallet metadata from browser
 */ 
bananaInstance.resetWallet()

verifySignature

Developers can utilize the verifySignature method of bananaInstance to verify the signed message signature against the user's hardware (EOA) address. The method expects three arguments: signature, messageSigned, and eoaAddress.

Usage

/**
 * @method verify
 * @param { string } signature, { string } message, { string } eoaAddress
 * @returns { boolean } isVerified
 * method to verify message against signature
 */
const walletName = 'sample-wallet';
const walletInstance = await bananaInstance.connectWallet(walletName);
const sampleMsg = "Hello World";
const eoaAddress = await bananaInstance.getEOAAddress();
const signer = walletInstance.getSigner();
const signMessageResponse = await signer.signBananaMessage(sampleMsg);
const signature = signMessageResponse.signature;
const isVerified = await bananaInstance.verifySignature(signature, sampleMsg, eoaAddress);

signBananaMessage

As banana-wallet-sdk provides touchid-based wallets to users. And the signature generated from the hardware infra of the device is r1 type signature which is different from the current k1-based signature scheme. k1 based signature schemes are unique with respect to messages signed means for each message signed we can receive only one unique signature. In r1 based signature mechanism as the hardware of the device in itself adds some sort of entropy to the message it returns a different signature string for the same message if tried repeatedly.

The signature you'll receive from signBananaMessage is not just the signature it contains several more field encoded into it which gets decoded onchain at validation stage.

Usage

/**
 * @method signBananaMessage
 * @params { string } message
 * @returns { object } { signature } 
 * method to sign message through wallet
 */
const walletName = 'sample-wallet';
const walletInstance = await bananaInstance.connectWallet(walletName);
const sampleMsg = "Hello World";
const signer = walletInstance.getSigner();
const signMessageResponse = await signer.signBananaMessage(sampleMsg);
const signature = signMessageResponse.signature;

PS: if after following this documentation you are experiencing webpack polyfill issue please refer to this page

If you have any questions, please feel free to ask on the Banana SDK Discord forum.

Last updated