👨‍đŸ’ģSDK core

To install the Banana SDK Pass (Passkey Manager Module), use either of the following commands:

npm install @rize-labs/paas

Or

yarn add @rize-labs/paas

Instance Creation and Imports

Developers can access the PasskeyEoaSigner module by importing it from the '@rize-labs/paas' SDK:

import { PasskeyEoaSigner } from '@rize-labs/paas'

Once the PasskeyEoaSigner module is successfully imported, you can create an instance by passing a JSON-RPC provider. After creating the instance, you can start using it by initializing it with a unique username using the init method. This mapping between the signer and passkeys is facilitated by the 'paas' package for signing messages and transactions.

Create a PasskeySignerEoa instance as follows:

// importing PasskeyEoaSigner from paas (passkey as a signer) package
import { PasskeyEoaSigner } from '@rize-labs/paas' 

// creating an instance of it
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// initializing signer 
await passkeySigner.init(<unique username>);

Note: If the provided username is already in use, the corresponding public key will be fetched. An authentication request will be sent to sign a random message to check if a private key exists in the device's secure enclave environment. If successful, the signer will be initialized. Otherwise, an error will be thrown "You are not authorized to use this wallet",indicating that you are not authorized to use this wallet.

Methods by passkeySigner

PasskeyEoaSigner class overrides the existing Signer class methods, adds a few more methods for passkey management, and implements the TypedDataSigner class provided by ethers library. It inherits and overrides all the necessary methods required by an abstract signer class which are

  • getChainId

  • getAddress

  • signTransaction

  • signMessage

  • _signTypedData

  • static getPasskey

  • connect

Below are the details and usage of each of the methods.

getChainId

getChainId: Retrieves the chainId of the current network corresponding to the JSON-RPC provider passed during the initialization of the PasskeyEoaSigner instance.

Usage

// importing PasskeyEoaSigner from paas (passkey as a signer) package
import { PasskeyEoaSigner } from '@rize-labs/paas' 

// creating an instance of it
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// initializing signer 
await passkeySigner.init(<unique username>);

// getting chainId by calling getChainId on passkeySigner
const chainId: number = await passkeySigner.getChainId();

getAddress

getAddress: Retrieves the Ethereum-compatible address (H160 formatted) corresponding to the EOA of the signer instance. PasskeyEoaSigner overrides this method and calculates the address from the fetched public values of the passkeys.

Usage

// importing PasskeyEoaSigner from paas (passkey as a signer) package
import { PasskeyEoaSigner } from '@rize-labs/paas' 

// creating an instance of it
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// initializing signer 
await passkeySigner.init(<unique username>);

// getting address by calling getAddress method on passkeySigner
const address: string = passkeySigner.getAddress();

signTransaction

signTransaction: Currently not supported by PasskeyEoaSigner, as it is not required for 4337 smart contract wallets. In 4337 compatible smart contract wallets, userOpHash is signed using the signMessage method.

signMessage

signMessage: Signs a provided message (bytes or string) using the passkeys initialized/fetched by the signer. The method returns the signature appended with the signed message. The first 32 bytes of the signature represent the signature itself, while the remaining 32 bytes contain the signed message.

Usage

// importing PasskeyEoaSigner from paas (passkey as a signer) package
import { PasskeyEoaSigner } from '@rize-labs/paas' 

// creating an instance of it
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// initializing signer 
await passkeySigner.init(<unique username>);

// getting signature by passing message and calling signMessage method of passkeySigner
const signature: string = passkeySigner.signMessage(<message>);

_signTypedData

_signTypedData: Signs a hash of a typed message by providing the domain, types, and value as arguments. The method returns the signature appended with the signed message hash. The first 32 bytes of the signature represent the signature, while the remaining 32 bytes contain the signed message.

Usage

// importing PasskeyEoaSigner from paas (passkey as a signer) package
import { PasskeyEoaSigner } from '@rize-labs/paas' 

// creating an instance of it
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// initializing signer 
await passkeySigner.init(<unique username>);

// getting signature by domain, type and value
const signature: string = passkeySigner._signTypedData(<domain>, <types>, <value>);

getPasskey

getPasskey: A static method implemented in PasskeyEoaSigner to retrieve the passkey's public values corresponding to a given username. The passkey's X and Y public values are used to set the owner of the smart contract wallet during initialization. Additionally, theinitialize method is also used to generate an init code which would help in contract deployment via userOp and also to fetch the counterfactual address of where the smart contract wallet would going to be deployed.

Usage

import { PasskeyEoaSigner, Passkey } from '@rize-labs/paas';

// Create an instance of PasskeyEoaSigner
const passkeySigner = new PasskeyEoaSigner(<json rpc provider>);

// Initialize the signer
await passkeySigner.init(<unique username>);

// Retrieve the passkey's public values
const passkey: Passkey = passkeySigner.getPasskey(<username>);

The getPasskey method is commonly used for operations such as setting the owner of a smart contract wallet, generating initialization code for contract deployment via userOp, and obtaining the counterfactual address where the smart contract wallet will be deployed.

Please note that the returned Passkey object contains the public values of the passkey, not the private key itself.

connect

connect Not implemented because not required.

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

Last updated