pwc-sdk-wallet 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +2062 -0
  2. package/dist/Vault.d.ts +493 -0
  3. package/dist/Vault.js +1090 -0
  4. package/dist/chain/ChainService.d.ts +84 -0
  5. package/dist/chain/ChainService.js +136 -0
  6. package/dist/chain/SolanaChainService.d.ts +94 -0
  7. package/dist/chain/SolanaChainService.js +167 -0
  8. package/dist/config/chains.d.ts +233 -0
  9. package/dist/config/chains.js +285 -0
  10. package/dist/config/constants.d.ts +102 -0
  11. package/dist/config/constants.js +109 -0
  12. package/dist/config/environment.d.ts +46 -0
  13. package/dist/config/environment.js +114 -0
  14. package/dist/config/gas.d.ts +107 -0
  15. package/dist/config/gas.js +123 -0
  16. package/dist/crypto/EncryptionService.d.ts +74 -0
  17. package/dist/crypto/EncryptionService.js +178 -0
  18. package/dist/index.d.ts +22 -0
  19. package/dist/index.js +96 -0
  20. package/dist/keyrings/HDKeyring.d.ts +72 -0
  21. package/dist/keyrings/HDKeyring.js +156 -0
  22. package/dist/keyrings/SimpleKeyring.d.ts +31 -0
  23. package/dist/keyrings/SimpleKeyring.js +49 -0
  24. package/dist/keyrings/SolanaKeyring.d.ts +71 -0
  25. package/dist/keyrings/SolanaKeyring.js +159 -0
  26. package/dist/services/BatchProcessor.d.ts +42 -0
  27. package/dist/services/BatchProcessor.js +188 -0
  28. package/dist/services/MultiTransferService.d.ts +78 -0
  29. package/dist/services/MultiTransferService.js +252 -0
  30. package/dist/services/QRCodeService.d.ts +193 -0
  31. package/dist/services/QRCodeService.js +299 -0
  32. package/dist/services/TokenUtils.d.ts +307 -0
  33. package/dist/services/TokenUtils.js +429 -0
  34. package/dist/services/nft/MetadataResolver.d.ts +57 -0
  35. package/dist/services/nft/MetadataResolver.js +162 -0
  36. package/dist/services/nft/NFTAPIService.d.ts +53 -0
  37. package/dist/services/nft/NFTAPIService.js +122 -0
  38. package/dist/services/nft/NFTService.d.ts +241 -0
  39. package/dist/services/nft/NFTService.js +910 -0
  40. package/dist/types/multiTransfer.d.ts +68 -0
  41. package/dist/types/multiTransfer.js +2 -0
  42. package/dist/types/nft/index.d.ts +68 -0
  43. package/dist/types/nft/index.js +2 -0
  44. package/dist/types/nft.d.ts +265 -0
  45. package/dist/types/nft.js +6 -0
  46. package/package.json +70 -0
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration constants for PWC Wallet SDK
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VALIDATION_CONFIG = exports.CACHE_CONFIG = exports.NETWORK_CONFIG = exports.SECURITY_CONFIG = exports.VANITY_WALLET_CONFIG = void 0;
7
+ exports.getPBKDF2Iterations = getPBKDF2Iterations;
8
+ /**
9
+ * Configuration object for vanity wallet generation.
10
+ * Contains default settings and limits for generating wallets with specific address prefixes.
11
+ */
12
+ exports.VANITY_WALLET_CONFIG = {
13
+ /** Default prefix for vanity addresses (without '0x' for EVM chains) */
14
+ DEFAULT_PREFIX: 'aaa',
15
+ /** Maximum attempts for generating vanity wallet before giving up */
16
+ DEFAULT_MAX_ATTEMPTS: 1000000,
17
+ /** Whether prefix matching should be case sensitive (false = ignore case) */
18
+ DEFAULT_CASE_SENSITIVE: false,
19
+ /** Progress update interval in number of attempts (for progress callbacks) */
20
+ PROGRESS_UPDATE_INTERVAL: 1000,
21
+ /** Non-blocking interval to allow event loop to breathe (prevents UI freezing) */
22
+ NON_BLOCKING_INTERVAL: 10000,
23
+ /** Maximum prefix length allowed (for performance and security reasons) */
24
+ MAX_PREFIX_LENGTH: 10,
25
+ /** Maximum attempts limit as a safety cap to prevent infinite loops */
26
+ MAX_ATTEMPTS_LIMIT: 10000000,
27
+ // Mobile-optimized settings
28
+ /** Mobile-optimized prefix (much easier to find) */
29
+ MOBILE_DEFAULT_PREFIX: 'a',
30
+ /** Mobile-optimized max attempts (faster completion) */
31
+ MOBILE_DEFAULT_MAX_ATTEMPTS: 50000,
32
+ /** Mobile-optimized progress update interval (more frequent updates) */
33
+ MOBILE_PROGRESS_UPDATE_INTERVAL: 500,
34
+ /** Mobile-optimized non-blocking interval (more frequent yields) */
35
+ MOBILE_NON_BLOCKING_INTERVAL: 1000,
36
+ /** Batch size for mobile processing (process multiple attempts in batches) */
37
+ MOBILE_BATCH_SIZE: 100,
38
+ /** Mobile timeout in milliseconds (prevent infinite running) */
39
+ MOBILE_TIMEOUT_MS: 30000, // 30 seconds
40
+ };
41
+ /**
42
+ * Security configuration constants
43
+ */
44
+ exports.SECURITY_CONFIG = {
45
+ /** AES key size in bits */
46
+ AES_KEY_SIZE: 256,
47
+ /** Salt length in bytes */
48
+ SALT_LENGTH: 16,
49
+ /** IV length in bytes */
50
+ IV_LENGTH: 12,
51
+ /** Minimum password length */
52
+ MIN_PASSWORD_LENGTH: 8,
53
+ /** Maximum vault unlock attempts before lockout */
54
+ MAX_UNLOCK_ATTEMPTS: 5,
55
+ /** Lockout duration in milliseconds */
56
+ LOCKOUT_DURATION: 300000, // 5 minutes
57
+ };
58
+ /**
59
+ * Get PBKDF2 iterations based on environment
60
+ * @returns Number of iterations (5000 for development, 10000 for production)
61
+ */
62
+ function getPBKDF2Iterations() {
63
+ return process.env.NODE_ENV === 'production' ? 3000 : 2500;
64
+ }
65
+ /**
66
+ * Network configuration constants
67
+ */
68
+ exports.NETWORK_CONFIG = {
69
+ /** Default timeout for RPC calls in milliseconds */
70
+ RPC_TIMEOUT: 30000,
71
+ /** Retry attempts for failed RPC calls */
72
+ RPC_RETRY_ATTEMPTS: 3,
73
+ /** Delay between retry attempts in milliseconds */
74
+ RPC_RETRY_DELAY: 1000,
75
+ /** Maximum batch size for multi-transfer operations */
76
+ MAX_BATCH_SIZE: 50,
77
+ /** Delay between batches in milliseconds */
78
+ BATCH_DELAY: 500,
79
+ };
80
+ /**
81
+ * Cache configuration constants
82
+ */
83
+ exports.CACHE_CONFIG = {
84
+ /** Default cache TTL in milliseconds */
85
+ DEFAULT_TTL: 30000, // 30 seconds
86
+ /** Balance cache TTL in milliseconds */
87
+ BALANCE_TTL: 60000, // 1 minute
88
+ /** Token info cache TTL in milliseconds */
89
+ TOKEN_INFO_TTL: 300000, // 5 minutes
90
+ /** Transaction cache TTL in milliseconds */
91
+ TRANSACTION_TTL: 600000, // 10 minutes
92
+ /** Maximum cache size in number of entries */
93
+ MAX_CACHE_SIZE: 1000,
94
+ };
95
+ /**
96
+ * Validation configuration constants
97
+ */
98
+ exports.VALIDATION_CONFIG = {
99
+ /** Minimum address length */
100
+ MIN_ADDRESS_LENGTH: 26,
101
+ /** Maximum address length */
102
+ MAX_ADDRESS_LENGTH: 44,
103
+ /** Minimum amount for transfers */
104
+ MIN_TRANSFER_AMOUNT: '0.000001',
105
+ /** Maximum amount for transfers (safety limit) */
106
+ MAX_TRANSFER_AMOUNT: '1000000',
107
+ /** Maximum decimal places for amounts */
108
+ MAX_DECIMAL_PLACES: 18,
109
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Environment configuration for PWC Wallet SDK
3
+ * Centralizes all environment variables and provides type-safe access
4
+ */
5
+ export interface EnvironmentConfig {
6
+ /** RPC URLs for different chains */
7
+ rpcUrls: {
8
+ [chainId: string]: string;
9
+ };
10
+ /** Explorer URLs for different chains */
11
+ explorerUrls: {
12
+ [chainId: string]: string;
13
+ };
14
+ /** Gas configuration overrides */
15
+ gas: {
16
+ maxFeePerGas?: bigint;
17
+ maxPriorityFeePerGas?: bigint;
18
+ gasLimit?: number;
19
+ };
20
+ /** Network configuration */
21
+ network: {
22
+ defaultChainId: string;
23
+ supportedChains: string[];
24
+ };
25
+ /** Feature flags */
26
+ features: {
27
+ enableEIP1559: boolean;
28
+ enableBatchProcessing: boolean;
29
+ enableGasEstimation: boolean;
30
+ };
31
+ }
32
+ /**
33
+ * Get environment configuration with defaults
34
+ */
35
+ export declare function getEnvironmentConfig(): EnvironmentConfig;
36
+ /**
37
+ * Validate environment configuration
38
+ */
39
+ export declare function validateEnvironmentConfig(config: EnvironmentConfig): string[];
40
+ /**
41
+ * Get environment variable with type conversion
42
+ */
43
+ export declare function getEnvVar(key: string, defaultValue?: string): string | undefined;
44
+ export declare function getEnvVarNumber(key: string, defaultValue?: number): number | undefined;
45
+ export declare function getEnvVarBigInt(key: string, defaultValue?: bigint): bigint | undefined;
46
+ export declare function getEnvVarBoolean(key: string, defaultValue?: boolean): boolean | undefined;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Environment configuration for PWC Wallet SDK
4
+ * Centralizes all environment variables and provides type-safe access
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getEnvironmentConfig = getEnvironmentConfig;
8
+ exports.validateEnvironmentConfig = validateEnvironmentConfig;
9
+ exports.getEnvVar = getEnvVar;
10
+ exports.getEnvVarNumber = getEnvVarNumber;
11
+ exports.getEnvVarBigInt = getEnvVarBigInt;
12
+ exports.getEnvVarBoolean = getEnvVarBoolean;
13
+ /**
14
+ * Get environment configuration with defaults
15
+ */
16
+ function getEnvironmentConfig() {
17
+ return {
18
+ rpcUrls: {
19
+ '1': process.env.RPC_URL_1 || 'https://eth.llamarpc.com',
20
+ '56': process.env.RPC_URL_56 || 'https://bsc-dataseed.binance.org/',
21
+ '137': process.env.RPC_URL_137 || 'https://polygon-rpc.com/',
22
+ '42161': process.env.RPC_URL_42161 || 'https://arb1.arbitrum.io/rpc',
23
+ '10': process.env.RPC_URL_10 || 'https://mainnet.optimism.io',
24
+ '8453': process.env.RPC_URL_8453 || 'https://mainnet.base.org',
25
+ 'solana': process.env.RPC_URL_SOLANA || 'https://api.mainnet-beta.solana.com',
26
+ 'solana-devnet': process.env.RPC_URL_SOLANA_DEVNET || 'https://api.devnet.solana.com',
27
+ '97': process.env.RPC_URL_97 || 'https://bsc-testnet-dataseed.bnbchain.org',
28
+ },
29
+ explorerUrls: {
30
+ '1': process.env.EXPLORER_URL_1 || 'https://etherscan.io',
31
+ '56': process.env.EXPLORER_URL_56 || 'https://bscscan.com',
32
+ '137': process.env.EXPLORER_URL_137 || 'https://polygonscan.com',
33
+ '42161': process.env.EXPLORER_URL_42161 || 'https://arbiscan.io',
34
+ '10': process.env.EXPLORER_URL_10 || 'https://optimistic.etherscan.io',
35
+ '8453': process.env.EXPLORER_URL_8453 || 'https://basescan.org',
36
+ 'solana': process.env.EXPLORER_URL_SOLANA || 'https://solscan.io',
37
+ 'solana-devnet': process.env.EXPLORER_URL_SOLANA_DEVNET || 'https://solscan.io?cluster=devnet',
38
+ '97': process.env.EXPLORER_URL_97 || 'https://testnet.bscscan.com',
39
+ },
40
+ gas: {
41
+ maxFeePerGas: process.env.MAX_FEE_PER_GAS ? BigInt(process.env.MAX_FEE_PER_GAS) : undefined,
42
+ maxPriorityFeePerGas: process.env.MAX_PRIORITY_FEE_PER_GAS ? BigInt(process.env.MAX_PRIORITY_FEE_PER_GAS) : undefined,
43
+ gasLimit: process.env.DEFAULT_GAS_LIMIT ? parseInt(process.env.DEFAULT_GAS_LIMIT) : undefined,
44
+ },
45
+ network: {
46
+ defaultChainId: process.env.DEFAULT_CHAIN_ID || '1',
47
+ supportedChains: process.env.SUPPORTED_CHAINS ? process.env.SUPPORTED_CHAINS.split(',') : ['1', '56', '137', '42161', '10', '8453', 'solana'],
48
+ },
49
+ features: {
50
+ enableEIP1559: process.env.ENABLE_EIP1559 !== 'false',
51
+ enableBatchProcessing: process.env.ENABLE_BATCH_PROCESSING !== 'false',
52
+ enableGasEstimation: process.env.ENABLE_GAS_ESTIMATION !== 'false',
53
+ },
54
+ };
55
+ }
56
+ /**
57
+ * Validate environment configuration
58
+ */
59
+ function validateEnvironmentConfig(config) {
60
+ const errors = [];
61
+ // Validate RPC URLs
62
+ Object.entries(config.rpcUrls).forEach(([chainId, url]) => {
63
+ if (!url.startsWith('http')) {
64
+ errors.push(`Invalid RPC URL for chain ${chainId}: ${url}`);
65
+ }
66
+ });
67
+ // Validate explorer URLs
68
+ Object.entries(config.explorerUrls).forEach(([chainId, url]) => {
69
+ if (!url.startsWith('http')) {
70
+ errors.push(`Invalid explorer URL for chain ${chainId}: ${url}`);
71
+ }
72
+ });
73
+ // Validate gas configuration
74
+ if (config.gas.maxFeePerGas && config.gas.maxFeePerGas <= 0n) {
75
+ errors.push('MAX_FEE_PER_GAS must be greater than 0');
76
+ }
77
+ if (config.gas.maxPriorityFeePerGas && config.gas.maxPriorityFeePerGas <= 0n) {
78
+ errors.push('MAX_PRIORITY_FEE_PER_GAS must be greater than 0');
79
+ }
80
+ if (config.gas.gasLimit && (config.gas.gasLimit < 21000 || config.gas.gasLimit > 500000)) {
81
+ errors.push('DEFAULT_GAS_LIMIT must be between 21000 and 500000');
82
+ }
83
+ return errors;
84
+ }
85
+ /**
86
+ * Get environment variable with type conversion
87
+ */
88
+ function getEnvVar(key, defaultValue) {
89
+ return process.env[key] || defaultValue;
90
+ }
91
+ function getEnvVarNumber(key, defaultValue) {
92
+ const value = process.env[key];
93
+ if (!value)
94
+ return defaultValue;
95
+ const num = parseInt(value);
96
+ return isNaN(num) ? defaultValue : num;
97
+ }
98
+ function getEnvVarBigInt(key, defaultValue) {
99
+ const value = process.env[key];
100
+ if (!value)
101
+ return defaultValue;
102
+ try {
103
+ return BigInt(value);
104
+ }
105
+ catch {
106
+ return defaultValue;
107
+ }
108
+ }
109
+ function getEnvVarBoolean(key, defaultValue) {
110
+ const value = process.env[key];
111
+ if (!value)
112
+ return defaultValue;
113
+ return value.toLowerCase() === 'true';
114
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Gas configuration constants to avoid hardcoded values
3
+ */
4
+ export declare const GAS_CONFIG: {
5
+ /** Default gas limit for ERC-20 token transfers */
6
+ readonly ERC20_TRANSFER: 65000;
7
+ /** Default gas limit for native token transfers */
8
+ readonly NATIVE_TRANSFER: 21000;
9
+ /** Default gas limit for token approvals */
10
+ readonly TOKEN_APPROVAL: 46000;
11
+ /** Default gas limit for contract interactions */
12
+ readonly CONTRACT_INTERACTION: 100000;
13
+ /** Maximum gas limit for safety */
14
+ readonly MAX_GAS_LIMIT: 500000;
15
+ /** Gas multiplier for batch operations */
16
+ readonly BATCH_MULTIPLIER: 1.1;
17
+ /** Priority fee (tip) in wei for EIP-1559 transactions */
18
+ readonly DEFAULT_PRIORITY_FEE: 1500000000n;
19
+ /** Base fee buffer for EIP-1559 transactions */
20
+ readonly BASE_FEE_BUFFER: 1.2;
21
+ };
22
+ /**
23
+ * Set global gas configuration from mobile app (highest priority)
24
+ */
25
+ export declare function setGlobalGasConfig(config: Partial<typeof GAS_CONFIG>): void;
26
+ /**
27
+ * Set global network gas configuration from mobile app (highest priority)
28
+ */
29
+ export declare function setGlobalNetworkGasConfig(config: Record<string, Partial<{
30
+ maxFeePerGas: bigint;
31
+ maxPriorityFeePerGas: bigint;
32
+ }>>): void;
33
+ /**
34
+ * Clear all global gas configurations (reset to defaults)
35
+ */
36
+ export declare function clearGlobalGasConfigs(): void;
37
+ /**
38
+ * Get merged gas config (Mobile App > Env > SDK Defaults)
39
+ */
40
+ export declare function getGasConfig(): {
41
+ ERC20_TRANSFER: number;
42
+ NATIVE_TRANSFER: number;
43
+ TOKEN_APPROVAL: number;
44
+ CONTRACT_INTERACTION: number;
45
+ MAX_GAS_LIMIT: number;
46
+ BATCH_MULTIPLIER: number;
47
+ DEFAULT_PRIORITY_FEE: bigint;
48
+ BASE_FEE_BUFFER: number;
49
+ };
50
+ /**
51
+ * Network-specific gas configurations
52
+ */
53
+ export declare const NETWORK_GAS_CONFIG: {
54
+ readonly '1': {
55
+ readonly maxFeePerGas: 50000000000n;
56
+ readonly maxPriorityFeePerGas: 2000000000n;
57
+ };
58
+ readonly '56': {
59
+ readonly maxFeePerGas: 5000000000n;
60
+ readonly maxPriorityFeePerGas: 1000000000n;
61
+ };
62
+ readonly '137': {
63
+ readonly maxFeePerGas: 30000000000n;
64
+ readonly maxPriorityFeePerGas: 1000000000n;
65
+ };
66
+ readonly '42161': {
67
+ readonly maxFeePerGas: 100000000n;
68
+ readonly maxPriorityFeePerGas: 100000000n;
69
+ };
70
+ readonly '10': {
71
+ readonly maxFeePerGas: 1000000000n;
72
+ readonly maxPriorityFeePerGas: 100000000n;
73
+ };
74
+ readonly '8453': {
75
+ readonly maxFeePerGas: 1000000000n;
76
+ readonly maxPriorityFeePerGas: 100000000n;
77
+ };
78
+ };
79
+ /**
80
+ * Get gas configuration for a specific network with priority: Mobile App > Env > SDK Defaults
81
+ */
82
+ export declare function getNetworkGasConfig(chainId: string): {
83
+ maxFeePerGas: bigint;
84
+ maxPriorityFeePerGas: bigint;
85
+ } | {
86
+ maxFeePerGas: bigint;
87
+ maxPriorityFeePerGas: bigint;
88
+ } | {
89
+ maxFeePerGas: bigint;
90
+ maxPriorityFeePerGas: bigint;
91
+ } | {
92
+ maxFeePerGas: bigint;
93
+ maxPriorityFeePerGas: bigint;
94
+ } | {
95
+ maxFeePerGas: bigint;
96
+ maxPriorityFeePerGas: bigint;
97
+ } | {
98
+ maxFeePerGas: bigint;
99
+ maxPriorityFeePerGas: bigint;
100
+ };
101
+ /**
102
+ * Calculate optimal gas price for EIP-1559 transactions using dynamic config
103
+ */
104
+ export declare function calculateOptimalGasPrice(baseFee: bigint, chainId: string): {
105
+ maxFeePerGas: bigint;
106
+ maxPriorityFeePerGas: bigint;
107
+ };
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NETWORK_GAS_CONFIG = exports.GAS_CONFIG = void 0;
4
+ exports.setGlobalGasConfig = setGlobalGasConfig;
5
+ exports.setGlobalNetworkGasConfig = setGlobalNetworkGasConfig;
6
+ exports.clearGlobalGasConfigs = clearGlobalGasConfigs;
7
+ exports.getGasConfig = getGasConfig;
8
+ exports.getNetworkGasConfig = getNetworkGasConfig;
9
+ exports.calculateOptimalGasPrice = calculateOptimalGasPrice;
10
+ /**
11
+ * Gas configuration constants to avoid hardcoded values
12
+ */
13
+ exports.GAS_CONFIG = {
14
+ /** Default gas limit for ERC-20 token transfers */
15
+ ERC20_TRANSFER: 65000,
16
+ /** Default gas limit for native token transfers */
17
+ NATIVE_TRANSFER: 21000,
18
+ /** Default gas limit for token approvals */
19
+ TOKEN_APPROVAL: 46000,
20
+ /** Default gas limit for contract interactions */
21
+ CONTRACT_INTERACTION: 100000,
22
+ /** Maximum gas limit for safety */
23
+ MAX_GAS_LIMIT: 500000,
24
+ /** Gas multiplier for batch operations */
25
+ BATCH_MULTIPLIER: 1.1,
26
+ /** Priority fee (tip) in wei for EIP-1559 transactions */
27
+ DEFAULT_PRIORITY_FEE: 1500000000n, // 1.5 gwei
28
+ /** Base fee buffer for EIP-1559 transactions */
29
+ BASE_FEE_BUFFER: 1.2,
30
+ };
31
+ // Global gas config registry for mobile app overrides
32
+ let GLOBAL_GAS_CONFIG = {};
33
+ let GLOBAL_NETWORK_GAS_CONFIG = {};
34
+ /**
35
+ * Set global gas configuration from mobile app (highest priority)
36
+ */
37
+ function setGlobalGasConfig(config) {
38
+ GLOBAL_GAS_CONFIG = { ...GLOBAL_GAS_CONFIG, ...config };
39
+ }
40
+ /**
41
+ * Set global network gas configuration from mobile app (highest priority)
42
+ */
43
+ function setGlobalNetworkGasConfig(config) {
44
+ GLOBAL_NETWORK_GAS_CONFIG = { ...GLOBAL_NETWORK_GAS_CONFIG, ...config };
45
+ }
46
+ /**
47
+ * Clear all global gas configurations (reset to defaults)
48
+ */
49
+ function clearGlobalGasConfigs() {
50
+ GLOBAL_GAS_CONFIG = {};
51
+ GLOBAL_NETWORK_GAS_CONFIG = {};
52
+ }
53
+ /**
54
+ * Get merged gas config (Mobile App > Env > SDK Defaults)
55
+ */
56
+ function getGasConfig() {
57
+ return {
58
+ ...exports.GAS_CONFIG,
59
+ ...GLOBAL_GAS_CONFIG,
60
+ // Environment variables override
61
+ ERC20_TRANSFER: parseInt(process.env.GAS_ERC20_TRANSFER || GLOBAL_GAS_CONFIG.ERC20_TRANSFER?.toString() || exports.GAS_CONFIG.ERC20_TRANSFER.toString()),
62
+ NATIVE_TRANSFER: parseInt(process.env.GAS_NATIVE_TRANSFER || GLOBAL_GAS_CONFIG.NATIVE_TRANSFER?.toString() || exports.GAS_CONFIG.NATIVE_TRANSFER.toString()),
63
+ TOKEN_APPROVAL: parseInt(process.env.GAS_TOKEN_APPROVAL || GLOBAL_GAS_CONFIG.TOKEN_APPROVAL?.toString() || exports.GAS_CONFIG.TOKEN_APPROVAL.toString()),
64
+ CONTRACT_INTERACTION: parseInt(process.env.GAS_CONTRACT_INTERACTION || GLOBAL_GAS_CONFIG.CONTRACT_INTERACTION?.toString() || exports.GAS_CONFIG.CONTRACT_INTERACTION.toString()),
65
+ MAX_GAS_LIMIT: parseInt(process.env.GAS_MAX_LIMIT || GLOBAL_GAS_CONFIG.MAX_GAS_LIMIT?.toString() || exports.GAS_CONFIG.MAX_GAS_LIMIT.toString()),
66
+ BATCH_MULTIPLIER: parseFloat(process.env.GAS_BATCH_MULTIPLIER || GLOBAL_GAS_CONFIG.BATCH_MULTIPLIER?.toString() || exports.GAS_CONFIG.BATCH_MULTIPLIER.toString()),
67
+ DEFAULT_PRIORITY_FEE: BigInt(process.env.GAS_DEFAULT_PRIORITY_FEE || GLOBAL_GAS_CONFIG.DEFAULT_PRIORITY_FEE?.toString() || exports.GAS_CONFIG.DEFAULT_PRIORITY_FEE.toString()),
68
+ BASE_FEE_BUFFER: parseFloat(process.env.GAS_BASE_FEE_BUFFER || GLOBAL_GAS_CONFIG.BASE_FEE_BUFFER?.toString() || exports.GAS_CONFIG.BASE_FEE_BUFFER.toString()),
69
+ };
70
+ }
71
+ /**
72
+ * Network-specific gas configurations
73
+ */
74
+ exports.NETWORK_GAS_CONFIG = {
75
+ '1': {
76
+ maxFeePerGas: 50000000000n, // 50 gwei
77
+ maxPriorityFeePerGas: 2000000000n, // 2 gwei
78
+ },
79
+ '56': {
80
+ maxFeePerGas: 5000000000n, // 5 gwei
81
+ maxPriorityFeePerGas: 1000000000n, // 1 gwei
82
+ },
83
+ '137': {
84
+ maxFeePerGas: 30000000000n, // 30 gwei
85
+ maxPriorityFeePerGas: 1000000000n, // 1 gwei
86
+ },
87
+ '42161': {
88
+ maxFeePerGas: 100000000n, // 0.1 gwei
89
+ maxPriorityFeePerGas: 100000000n, // 0.1 gwei
90
+ },
91
+ '10': {
92
+ maxFeePerGas: 1000000000n, // 1 gwei
93
+ maxPriorityFeePerGas: 100000000n, // 0.1 gwei
94
+ },
95
+ '8453': {
96
+ maxFeePerGas: 1000000000n, // 1 gwei
97
+ maxPriorityFeePerGas: 100000000n, // 0.1 gwei
98
+ },
99
+ };
100
+ /**
101
+ * Get gas configuration for a specific network with priority: Mobile App > Env > SDK Defaults
102
+ */
103
+ function getNetworkGasConfig(chainId) {
104
+ const defaultConfig = exports.NETWORK_GAS_CONFIG[chainId] || {
105
+ maxFeePerGas: 20000000000n, // 20 gwei default
106
+ maxPriorityFeePerGas: 1000000000n, // 1 gwei default
107
+ };
108
+ const override = GLOBAL_NETWORK_GAS_CONFIG[chainId] || {};
109
+ return { ...defaultConfig, ...override };
110
+ }
111
+ /**
112
+ * Calculate optimal gas price for EIP-1559 transactions using dynamic config
113
+ */
114
+ function calculateOptimalGasPrice(baseFee, chainId) {
115
+ const networkConfig = getNetworkGasConfig(chainId);
116
+ const gasConfig = getGasConfig();
117
+ const priorityFee = networkConfig.maxPriorityFeePerGas;
118
+ const maxFeePerGas = baseFee * BigInt(Math.ceil(gasConfig.BASE_FEE_BUFFER * 100)) / BigInt(100) + priorityFee;
119
+ return {
120
+ maxFeePerGas: maxFeePerGas > networkConfig.maxFeePerGas ? networkConfig.maxFeePerGas : maxFeePerGas,
121
+ maxPriorityFeePerGas: priorityFee,
122
+ };
123
+ }
@@ -0,0 +1,74 @@
1
+ import { Buffer } from 'buffer';
2
+ /**
3
+ * Interface representing encrypted data structure.
4
+ * Contains the encrypted data, initialization vector, and salt used for encryption.
5
+ */
6
+ export interface EncryptedData {
7
+ /** The encrypted data as a base64 string */
8
+ encryptedData: string;
9
+ /** The initialization vector used for encryption as a base64 string */
10
+ iv: string;
11
+ /** The salt used for key derivation as a base64 string */
12
+ salt: string;
13
+ }
14
+ /**
15
+ * Service providing cryptographic operations including mnemonic generation,
16
+ * encryption/decryption, and key derivation for the wallet SDK.
17
+ */
18
+ export declare class EncryptionService {
19
+ /**
20
+ * Generates a cryptographically secure mnemonic phrase.
21
+ * @returns A 24-word mnemonic phrase following BIP-39 standard
22
+ */
23
+ static generateMnemonic(): string;
24
+ /**
25
+ * Validates a mnemonic phrase to ensure it's properly formatted and contains valid words.
26
+ * @param mnemonic - The mnemonic phrase to validate (12, 15, 18, 21, or 24 words)
27
+ * @returns True if the mnemonic is valid, false otherwise
28
+ */
29
+ static validateMnemonic(mnemonic: string): boolean;
30
+ /**
31
+ * Encrypts data using AES-256-CBC with PBKDF2 key derivation.
32
+ * @param data - The plaintext data to encrypt
33
+ * @param password - The password to use for key derivation
34
+ * @returns Promise resolving to the encrypted data structure
35
+ * @throws Error if encryption fails
36
+ */
37
+ static encrypt(data: string, password: string): Promise<EncryptedData>;
38
+ /**
39
+ * Decrypts data that was encrypted using the encrypt method.
40
+ * @param encryptedData - The encrypted data structure containing data, iv, and salt
41
+ * @param password - The password used for the original encryption
42
+ * @returns Promise resolving to the decrypted plaintext data
43
+ * @throws Error if decryption fails due to incorrect password or corrupted data
44
+ */
45
+ static decrypt(encryptedData: EncryptedData, password: string): Promise<string>;
46
+ /**
47
+ * Converts a mnemonic phrase to a seed buffer using PBKDF2.
48
+ * @param mnemonic - The mnemonic phrase to convert
49
+ * @returns Promise resolving to the seed buffer
50
+ */
51
+ static mnemonicToSeed(mnemonic: string): Promise<Buffer>;
52
+ /**
53
+ * Derives a private key from a seed using BIP-32 derivation.
54
+ * @param seed - The seed buffer to derive from
55
+ * @param path - The derivation path to use (defaults to EVM path)
56
+ * @returns Promise resolving to the derived private key buffer
57
+ * @throws Error if private key derivation fails
58
+ */
59
+ static derivePrivateKey(seed: Buffer, path?: string): Promise<Buffer>;
60
+ /**
61
+ * Attempts to clear sensitive data from memory.
62
+ * Note: JavaScript doesn't guarantee memory clearing, but this helps reduce exposure.
63
+ * @param data - The sensitive data to clear (string or buffer)
64
+ */
65
+ static clearSensitiveData(data: string | Buffer): void;
66
+ /**
67
+ * Creates a temporary copy of sensitive data that gets cleared after use.
68
+ * This is a security measure to minimize the time sensitive data stays in memory.
69
+ * @param data - The sensitive data to use temporarily
70
+ * @param callback - Function to execute with the temporary data
71
+ * @returns The result of the callback function
72
+ */
73
+ static withTemporaryData<T>(data: string | Buffer, callback: (tempData: string | Buffer) => T): T;
74
+ }