p-sdk-wallet
Version:
A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.
75 lines (74 loc) • 3.42 kB
TypeScript
import { Buffer } from 'buffer';
/**
* Interface representing encrypted data structure.
* Contains the encrypted data, initialization vector, and salt used for encryption.
*/
export interface EncryptedData {
/** The encrypted data as a base64 string */
encryptedData: string;
/** The initialization vector used for encryption as a base64 string */
iv: string;
/** The salt used for key derivation as a base64 string */
salt: string;
}
/**
* Service providing cryptographic operations including mnemonic generation,
* encryption/decryption, and key derivation for the wallet SDK.
*/
export declare class EncryptionService {
/**
* Generates a cryptographically secure mnemonic phrase.
* @returns A 24-word mnemonic phrase following BIP-39 standard
*/
static generateMnemonic(): string;
/**
* Validates a mnemonic phrase to ensure it's properly formatted and contains valid words.
* @param mnemonic - The mnemonic phrase to validate (12, 15, 18, 21, or 24 words)
* @returns True if the mnemonic is valid, false otherwise
*/
static validateMnemonic(mnemonic: string): boolean;
/**
* Encrypts data using AES-256-CBC with PBKDF2 key derivation.
* @param data - The plaintext data to encrypt
* @param password - The password to use for key derivation
* @returns Promise resolving to the encrypted data structure
* @throws Error if encryption fails
*/
static encrypt(data: string, password: string): Promise<EncryptedData>;
/**
* Decrypts data that was encrypted using the encrypt method.
* @param encryptedData - The encrypted data structure containing data, iv, and salt
* @param password - The password used for the original encryption
* @returns Promise resolving to the decrypted plaintext data
* @throws Error if decryption fails due to incorrect password or corrupted data
*/
static decrypt(encryptedData: EncryptedData, password: string): Promise<string>;
/**
* Converts a mnemonic phrase to a seed buffer using PBKDF2.
* @param mnemonic - The mnemonic phrase to convert
* @returns Promise resolving to the seed buffer
*/
static mnemonicToSeed(mnemonic: string): Promise<Buffer>;
/**
* Derives a private key from a seed using BIP-32 derivation.
* @param seed - The seed buffer to derive from
* @param path - The derivation path to use (defaults to EVM path)
* @returns Promise resolving to the derived private key buffer
* @throws Error if private key derivation fails
*/
static derivePrivateKey(seed: Buffer, path?: string): Promise<Buffer>;
/**
* Attempts to clear sensitive data from memory.
* Note: JavaScript doesn't guarantee memory clearing, but this helps reduce exposure.
* @param data - The sensitive data to clear (string or buffer)
*/
static clearSensitiveData(data: string | Buffer): void;
/**
* Creates a temporary copy of sensitive data that gets cleared after use.
* This is a security measure to minimize the time sensitive data stays in memory.
* @param data - The sensitive data to use temporarily
* @param callback - Function to execute with the temporary data
* @returns The result of the callback function
*/
static withTemporaryData<T>(data: string | Buffer, callback: (tempData: string | Buffer) => T): T;
}