@chorus-one/signer-local
Version:
Local signer for Chorus One SDK that utilizes a BIP39 mnemonic for signing operations
68 lines (67 loc) • 2.71 kB
TypeScript
import type { Signature, SignerData, AddressDerivationFn, MnemonicToSeedFn, SeedToKeypairFn } from '@chorus-one/signer';
import { KeyType } from '@chorus-one/signer';
import type { Logger } from '@chorus-one/utils';
/**
* The LocalSigner in the Chorus One SDK is a specialized implementation of the Signer interface that utilizes a `BIP39`
* mnemonic for signing operations.
*
* This signer is ideal for local environments where you need a straightforward and
* secure method to generate and manage cryptographic keys from mnemonic phrases.
*/
export declare class LocalSigner {
private readonly config;
private accounts;
private addressDerivationFn;
private mnemonicToSeedFn;
private seedToKeypairFn?;
private logger;
/**
* Constructs a new LocalSigner.
*
* @param params - The parameters required to initialize the LocalSigner
* @param params.mnemonic - A string containing your `BIP39` mnemonic phrase
* @param params.keyType - An enum specifying the signing key type (e.g. SECP256K1, ED25519)
* @param params.accounts - An array of account objects, each containing an HD path
* @param params.addressDerivationFn - A function that derives the address from the public key
* @param params.logger - (Optional) A logger to use for logging messages, i.e `console`
*
* @returns A new instance of LocalSigner.
*/
constructor(params: {
mnemonic: string;
accounts: [{
hdPath: string;
}];
keyType: KeyType;
addressDerivationFn: AddressDerivationFn;
mnemonicToSeedFn?: MnemonicToSeedFn;
seedToKeypairFn?: SeedToKeypairFn;
logger?: Logger;
});
/**
* Initializes the signer, performing any necessary setup or configuration.
* @returns A promise that resolves once the initialization is complete.
*/
init(): Promise<void>;
/**
* Signs the provided data using the private key associated with the signer's address.
*
* @param signerAddress - The address of the signer
* @param signerData - The data to be signed, which can be a raw message or custom data
*
* @returns A promise that resolves to an object containing the signature and public key.
*/
sign(signerAddress: string, signerData: SignerData): Promise<{
sig: Signature;
pk: Uint8Array;
}>;
/**
* Retrieves the public key associated with the signer's address.
*
* @param address - The address of the signer
*
* @returns A promise that resolves to a Uint8Array representing the public key.
*/
getPublicKey(address: string): Promise<Uint8Array>;
private getPrivateKey;
}