p-sdk-wallet
Version:
A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.
73 lines (72 loc) • 2.89 kB
TypeScript
/**
* HD (Hierarchical Deterministic) keyring for managing multiple accounts
* derived from a single mnemonic phrase using BIP-44 derivation paths.
* Supports EVM-compatible chains.
*/
export declare class HDKeyring {
readonly type = "HD";
private mnemonic;
private seed;
private static seedCache;
accounts: string[];
/**
* Creates a new HDKeyring instance from a mnemonic phrase.
* @param mnemonic - The mnemonic phrase (12, 15, 18, 21, or 24 words)
* @throws Error if the mnemonic is invalid
*/
constructor(mnemonic: string);
/**
* Initializes the keyring by generating the seed and creating the first account.
* This method must be called before using the keyring.
* @returns Promise that resolves when initialization is complete
* @throws Error if seed generation or account derivation fails
*/
initialize(): Promise<void>;
/**
* Derives an account at a specific index using BIP-44 derivation.
* @param index - The account index to derive (0-based)
* @returns Promise resolving to an object containing the derived address and private key
* @throws Error if the keyring is not initialized or derivation fails
*/
private deriveAccount;
/**
* Adds a new account derived from the mnemonic at the next available index.
* @returns Promise resolving to the address of the newly created account
* @throws Error if account derivation fails or duplicate address is generated
*/
addNewAccount(): Promise<string>;
/**
* Gets the private key for a given address managed by this keyring.
* @param address - The account address to get the private key for
* @returns Promise resolving to the private key as a hex string
* @throws Error if the address is not found in this keyring
*/
getPrivateKeyForAddress(address: string): Promise<string>;
/**
* Returns the mnemonic phrase. USE WITH CAUTION - this exposes sensitive data.
* @returns The mnemonic phrase as a string
*/
getMnemonic(): string;
/**
* Serializes the keyring data for encryption and storage.
* @returns An object containing the keyring type, mnemonic, and account addresses
*/
serialize(): any;
/**
* Deserializes data into an HDKeyring instance.
* @param data - The serialized keyring data
* @returns Promise resolving to a new HDKeyring instance
* @throws Error if the data is invalid or missing required fields
*/
static deserialize(data: any): Promise<HDKeyring>;
/**
* Clears the seed cache to free up memory.
* Call this when you want to clear sensitive data from memory.
*/
static clearSeedCache(): void;
/**
* Gets the cache size for debugging purposes.
* @returns Number of cached seeds
*/
static getSeedCacheSize(): number;
}