Overview
Explore how the ZkLoginExtension integrates into the Web SDK to facilitate secure login processes with zero-knowledge proofs. It enables users to authenticate without revealing sensitive information, preserving privacy while accessing blockchain services.
Installation
To install the Credenza ZkLogin Extension, use the following npm command:
npm i @credenza3/core-web-sui-zklogin-extimport { ZkLoginExtension } from '@credenza3/core-web-sui-zklogin-ext'Create SDK Instance
To create an SDK instance with the ZkLogin Extension, you need to configure the CredenzaSDK with the appropriate extensions. The ZkLoginExtension needs to be included in the extensions array of the SuiExtension object.
Below is an example setup process:
const sdk = new CredenzaSDK({
extensions: [
new SuiExtension({ suiNetwork: suiNetworkName, extensions: [new ZkLoginExtension()] }),
]
});
This code snippet initializes the SDK with both the SuiExtension and the ZkLoginExtension, ensuring ZkLoginExtension is part of the Sui network configuration.
ZK Mode Activation
When ZkLoginExtension is in the extensions list, SUI runs in ZK mode automatically.
All methods listed below are avaialbe directly by using sdk.sui.METHOD_NAME if ZK extensions is used. So basically sdk.sui.getAddress is returning the result of sdk.sui.zkLogin.getAddress if ZK extensions is active.
Methods and Properties
Get Current Sui ZK Address
sdk.sui.zkLogin.getAddress(): string
Retrieve the current Sui ZK address using the getAddress method. This method returns a string with the Sui ZK address.
const address = await sdk.sui.zkLogin.getAddress(): stringSign Personal Message
sdk.sui.zkLogin.signPersonalMessage(message: string): Promise<{signature: string; bytes: string}>
Sign a personal message using the signPersonalMessage method. Provide the message as a string to receive a promise with the signature and bytes.
const result = await sdk.sui.zkLogin.signPersonalMessage(message: string): Promise<{signature: string; bytes: string}>Sign Transaction Block
sdk.sui.zkLogin.signTransactionBlock(tbx: Transaction): Promise<{signature: string; transactionBlock: Uint8Array}>
Sign a transaction block using the signTransactionBlock method. Provide the transaction block object to receive a promise with the signature and transaction block bytes.
const result = await sdk.sui.zkLogin.signTransactionBlock(tbx: Transaction): Promise<{signature: string; transactionBlock: Uint8Array}>