Skip to main content
Version: 2.1.34

Secret Manager

The SecretManager class securely manages secrets and private keys, deriving a P256 key through an EIP-712 signature. The signature is hashed using SHA-256 to produce the key, ensuring security and compatibility. It extends the EventBroker class and the events are:

  • initialized: Fired when the SecretManager is successfully initialized.

Usage

import { SecretManager } from './SecretManager';

const secretManager_using_walletClient = SecretManager.fromWalletClient(walletClient); //initialize with walletClient (or)

const digestKey = <YOUR_DIGEST_KEY>
const secretManger_using_digestKey = SecretManager.fromDigestKey(digestKey); //initialize with digestKey

Initiation

static fromDigestKey(digestKey: string): SecretManager
(or)
static fromWalletClient(walletClient: WalletClient): SecretManager

Returns:


Methods

initialize

async initialize(): Promise<AsyncResult<string, string>>

Initializes the SecretManager, deriving the p256 key if necessary and emitting the initialized event.

Returns:

  • AsyncResult<string, string>

generateSecret

async generateSecret(nonce: number): Promise<AsyncResult<{ secret: string; secretHash: string }, string>>

Generates a secret and its hash using a given nonce.

Parameters:

  • nonce (number): The nonce to use for generating the secret.

Returns:

  • AsyncResult<{ secret: string; secretHash: string }, string>

getDigestKey

async getDigestKey: () => AsyncResult<string, string>;

Returns a digest key. If digest key already exists, it returns the existing digest key. Otherwise, it generates a new digest key by hashing the signature generated by signing a message with wallet client.

Returns:

  • AsyncResult<string, string>