Comment on page
🪄

ZkAuth Module

Instance creation and imports

Devs can directly access the Zk module from our SDK by just importing the ZkAuth module from the package banana-wallet-sdk
import { ZkAuth } from '@rize-labs/banana-wallet-sdk'
Once you successfully import ZkAuth Module, you can start accessing the methods it exposes just by creating an instance of it.
You can create a ZkAuth Instance as:
// importing zkAuth module from banana-wallet-sdk package
import { ZkAuth } from '@rize-labs/banana-wallet-sdk'
​
// creating an instance of zkAuth package
const zkAuthInstance = new ZkAuth()

Methods by ZkAuth module

Once the ZkInstance is ready, devs can access multiple methods provided by the ZkAuth module.
Methods offered by the ZkAuth module are:
  • init
  • getMerkleRoot
  • getMerkleTreeUri
  • checkOtp
  • getOtpInput

init

Once zkAuthInstance has successfully obtained. The init method of zkAuth should be called once. As it generates and caches Merkle root along with other necessary entities at the core. Which later can be accessed by other methods. Due to its singular call nature, it takes nothing and returns nothing. The seed for creating the qr-code-uri and Merkle tree is same, it is destroyed soon after the deployment.
Usage:
// init function is async in nature takes nothing and returns nothing
await zkAuthInstance.init();

getMerkleRoot

Devs can use the getMerkleRoot method of zkAuthInstance To access the root generated at the core when zk module has been initialized.
Usage:
// it returns the root of type BigNumberish
const root: BigNumberish = zkAuthInstance.getMerkleRoot();

getMerkleTreeUri

With getMerkleTreeUri method devs can get access to the qr-code-urigenerated by the SDK core for their user. Users can scan it using google authenticator, which further generates the OTP to validate the transactions. The URI returned by this method is an image blob which can be rendered simply by any react component as a static asset.
Usage.
// getting the qr-code-uri
const uri: string = zkAuthInstance.getMerkleRoot()
​
// rendering uri simply using img tag
<img src={uri} alt="qr-code-uri" />

checkOtp

checkOtp method of zkAuthInstance enables devs to add a pre-check before the query for the actual input for the OTP. It returns a boolean result based on the validity of OTP entered by the user.
Usage
// check if otp entered by user is valid or not.
const isOtpValid: boolean = await zkAuthInstance.checkOtp()

getOtpInput

getOtpInput methods enable devs to get actual input corresponding to the OTP. If OTP is valid, they can further use to pass as a param in bananaInstance.execute the method to validate a transaction.
Usage
// getting actual OTP input for a valid otp
const otpInput: Object = await zkAuthInstance.getOtpInput(otp)
​
// passing otpInput in banana.execute to enable 2FA over txn
const txn: TransactionResponse = await bananaInstance.execute(greetCallData, otpInput, scwAddress, destination, value);
If you have any questions please post them Banana SDK Discord forum.​