p-sdk-wallet
Version:
A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.
194 lines (193 loc) • 7.08 kB
TypeScript
import { EncryptedData } from '../crypto/EncryptionService';
/**
* Interface for QR code data structure
*/
export interface QRCodeData {
/** Type of QR code data */
type: 'address' | 'mnemonic' | 'transaction' | 'wallet-import';
/** The actual data content */
data: any;
/** Timestamp when QR was generated */
timestamp: number;
/** Version for future compatibility */
version: string;
}
/**
* Interface for wallet import QR data
*/
export interface WalletImportData {
/** Encrypted mnemonic data */
encryptedMnemonic: EncryptedData;
/** Chain type */
chainType: string;
/** Number of accounts to import */
accountCount: number;
}
/**
* Interface for transaction QR data
*/
export interface TransactionData {
/** Transaction type */
txType: 'native' | 'token' | 'nft';
/** Chain ID */
chainId: string;
/** Recipient address */
to: string;
/** Amount to send */
amount: string;
/** Token contract address (for token transfers) */
tokenAddress?: string;
/** Token ID (for NFT transfers) */
tokenId?: string;
/** Gas limit */
gasLimit?: string;
/** Gas price */
gasPrice?: string;
}
/**
* Service for generating and scanning QR codes for wallet operations.
* Supports address sharing, mnemonic backup, and transaction signing.
*/
export declare class QRCodeService {
private static readonly QR_VERSION;
/**
* Generates QR code data for a wallet address
* @param address - The wallet address to encode
* @param label - Optional label for the address
* @returns QR code data string
*/
static generateAddressQR(address: string, label?: string): string;
/**
* Generates QR code data for encrypted mnemonic backup
* @param mnemonic - The mnemonic phrase to encrypt
* @param password - Password for encryption
* @param chainType - Type of blockchain (evm, solana, etc.)
* @param accountCount - Number of accounts to import
* @returns Promise resolving to QR code data string
* @throws Error if encryption fails
*/
static generateMnemonicQR(mnemonic: string, password: string, chainType?: string, accountCount?: number): Promise<string>;
/**
* Generates QR code data for transaction signing
* @param transactionData - Transaction details
* @returns QR code data string
*/
static generateTransactionQR(transactionData: TransactionData): string;
/**
* Parses QR code data and validates its structure
* @param qrString - The QR code string to parse
* @returns Parsed QR code data
* @throws Error if QR data is invalid or unsupported
*/
static parseQRData(qrString: string): QRCodeData;
/**
* Extracts wallet address from QR code data
* @param qrString - The QR code string
* @returns The wallet address
* @throws Error if QR code doesn't contain address data
*/
static extractAddress(qrString: string): string;
/**
* Extracts wallet import data from QR code
* @param qrString - The QR code string
* @returns Wallet import data
* @throws Error if QR code doesn't contain wallet import data
*/
static extractWalletImportData(qrString: string): WalletImportData;
/**
* Extracts transaction data from QR code
* @param qrString - The QR code string
* @returns Transaction data
* @throws Error if QR code doesn't contain transaction data
*/
static extractTransactionData(qrString: string): TransactionData;
/**
* Validates if a string is a valid Ethereum address
* @param address - Address to validate
* @returns True if valid Ethereum address
*/
static isValidEthereumAddress(address: string): boolean;
/**
* Validates if a string is a valid Solana address
* @param address - Address to validate
* @returns True if valid Solana address
*/
static isValidSolanaAddress(address: string): boolean;
/**
* Gets the address type based on format
* @param address - Address to check
* @returns 'ethereum', 'solana', or 'unknown'
*/
static getAddressType(address: string): 'ethereum' | 'solana' | 'unknown';
/**
* Clears sensitive data from memory
* @param data - Sensitive data to clear
*/
static clearSensitiveData(data: string): void;
/**
* Generates QR code data for a wallet address from Vault.
* Utility function to be used outside of Vault class.
* @param vault - The vault instance
* @param accountIndex - Index of the account to generate QR for (default: 0)
* @param label - Optional label for the address
* @returns QR code data string
* @throws Error if account index is invalid
*
* @example
* ```typescript
* import { QRCodeService, Vault } from 'pwc-wallet-sdk';
*
* // Generate QR for first account
* const qrData = QRCodeService.generateAddressQRFromVault(vault, 0, 'My Wallet');
* ```
*/
static generateAddressQRFromVault(vault: any, accountIndex?: number, label?: string): string;
/**
* Generates QR code data for encrypted mnemonic backup from Vault.
* Utility function to be used outside of Vault class.
* @param vault - The vault instance
* @param password - Password for encryption
* @param accountCount - Number of accounts to import (default: 1)
* @returns Promise resolving to QR code data string
* @throws Error if encryption fails or no HD keyring available
*
* @example
* ```typescript
* import { QRCodeService, Vault } from 'pwc-wallet-sdk';
*
* // Generate backup QR with password
* const qrData = await QRCodeService.generateMnemonicQRFromVault(vault, 'my-secure-password', 3);
* ```
*/
static generateMnemonicQRFromVault(vault: any, password: string, accountCount?: number): Promise<string>;
/**
* Validates QR code data without processing it.
* @param qrString - QR code string to validate
* @returns Object containing validation result and data type
*
* @example
* ```typescript
* // Validate QR code before processing
* const validation = QRCodeService.validateQRCode(qrString);
* console.log('QR type:', validation.type);
* console.log('Is valid:', validation.isValid);
* ```
*/
static validateQRCode(qrString: string): {
isValid: boolean;
type: string;
data?: any;
};
/**
* Generates an EIP-681 compatible QR string for wallet address.
* This format is compatible with Metamask, Binance, Trust Wallet, etc.
* @param address - The wallet address to encode
* @returns EIP-681 URI string (e.g., 'ethereum:0x1234...')
* @example
* ```typescript
* const qrString = QRCodeService.generateEIP681AddressQR('0x1234...');
* // Use this string with a QR code generator for maximum wallet compatibility
* ```
*/
static generateEIP681AddressQR(address: string): string;
}