mnee
Version:
Legacy package for interacting with MNEE USD stablecoin. Includes experimental features.
112 lines (111 loc) • 4.41 kB
TypeScript
/**
* Note: We're using the HD class from @bsv/sdk despite it being marked as deprecated.
* The deprecation is because BSV is moving towards BRC-42 (invoice-based key derivation),
* but for MNEE token management, standard BIP32/BIP44 HD wallets are still the appropriate
* choice because:
* - Users expect standard mnemonic/HD wallet functionality
* - It needs to be compatible with existing wallet software
* - The use case is for token management, not the privacy-focused invoice system of BRC-42
*/
export interface AddressInfo {
address: string;
privateKey: string;
path: string;
}
export interface HDWalletOptions {
derivationPath: string;
cacheSize?: number;
}
export declare class HDWallet {
private readonly masterKey;
private readonly derivationPath;
private readonly cacheSize;
private readonly cache;
constructor(mnemonic: string, options: HDWalletOptions);
/**
* Generate a new random mnemonic phrase
* @returns A new BIP39 mnemonic phrase (12 words)
* @example
* const mnemonic = HDWallet.generateMnemonic();
* const hdWallet = new HDWallet(mnemonic, { derivationPath: "m/44'/236'/0'" });
*/
static generateMnemonic(): string;
/**
* Validate a mnemonic phrase
* @param mnemonic - The mnemonic phrase to validate
* @returns true if valid, false otherwise
*/
static isValidMnemonic(mnemonic: string): boolean;
/**
* Derive individual address with caching
* @param index - The index of the address to derive
* @param isChange - Whether this is a change address (default: false)
* @returns Address information including address, private key, and derivation path
*/
deriveAddress(index: number, isChange?: boolean): AddressInfo;
/**
* Batch derive addresses for performance
* @param startIndex - Starting index for derivation
* @param count - Number of addresses to derive
* @param isChange - Whether these are change addresses (default: false)
* @returns Array of address information
*/
deriveAddresses(startIndex: number, count: number, isChange?: boolean): Promise<AddressInfo[]>;
/**
* Helper for transferMulti integration - get private keys for specific addresses
* @param addresses - Array of addresses to get private keys for
* @param options - Optional configuration for the search
* @returns Object with private keys and derivation paths for each address
* @throws Error if any addresses cannot be found within the scan limits
*/
getPrivateKeysForAddresses(addresses: string[], options?: {
maxScanReceive?: number;
maxScanChange?: number;
scanStrategy?: 'sequential' | 'parallel';
}): {
privateKeys: {
[address: string]: string;
};
paths: {
[address: string]: string;
};
};
/**
* Helper for transferMulti integration - get private keys for specific addresses (simplified version)
* @param addresses - Array of addresses to get private keys for
* @param options - Optional configuration for the search
* @returns Object mapping addresses to their private keys (WIF format)
* @throws Error if any addresses cannot be found within the scan limits
*/
getPrivateKeys(addresses: string[], options?: {
maxScanReceive?: number;
maxScanChange?: number;
scanStrategy?: 'sequential' | 'parallel';
}): {
[address: string]: string;
};
/**
* Scan for addresses with a gap limit (BIP44 standard)
* This is useful for finding all used addresses in a wallet
* @param gapLimit - Number of consecutive unused addresses before stopping (default: 20)
* @param scanChange - Whether to scan change addresses too (default: true)
* @param maxScan - Maximum addresses to scan per type (default: 10000)
* @returns Object with arrays of discovered addresses
*/
scanAddressesWithGapLimit(checkAddressUsed: (address: string) => Promise<boolean>, options?: {
gapLimit?: number;
scanChange?: boolean;
maxScan?: number;
}): Promise<{
receive: AddressInfo[];
change: AddressInfo[];
}>;
/**
* Clear the cache to free memory
*/
clearCache(): void;
/**
* Get the current cache size
*/
getCacheSize(): number;
}