@spacesops/wdk-react-native-core 1.0.0-beta.40
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.
- package/README.md +551 -0
- package/dist/__mocks__/react.d.ts +40 -0
- package/dist/__mocks__/react.js +33 -0
- package/dist/__mocks__/react.js.map +1 -0
- package/dist/__mocks__/secureStorage.d.ts +26 -0
- package/dist/__mocks__/secureStorage.js +80 -0
- package/dist/__mocks__/secureStorage.js.map +1 -0
- package/dist/__tests__/hooks/useBalance.test.d.ts +6 -0
- package/dist/__tests__/hooks/useBalance.test.js +217 -0
- package/dist/__tests__/hooks/useBalance.test.js.map +1 -0
- package/dist/__tests__/hooks/useWallet.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWallet.test.js +105 -0
- package/dist/__tests__/hooks/useWallet.test.js.map +1 -0
- package/dist/__tests__/hooks/useWalletManager.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWalletManager.test.js +193 -0
- package/dist/__tests__/hooks/useWalletManager.test.js.map +1 -0
- package/dist/__tests__/hooks/useWdkApp.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWdkApp.test.js +55 -0
- package/dist/__tests__/hooks/useWdkApp.test.js.map +1 -0
- package/dist/__tests__/hooks/useWorklet.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWorklet.test.js +168 -0
- package/dist/__tests__/hooks/useWorklet.test.js.map +1 -0
- package/dist/__tests__/provider/WdkAppProvider.test.d.ts +6 -0
- package/dist/__tests__/provider/WdkAppProvider.test.js +57 -0
- package/dist/__tests__/provider/WdkAppProvider.test.js.map +1 -0
- package/dist/__tests__/services/accountService.test.d.ts +6 -0
- package/dist/__tests__/services/accountService.test.js +216 -0
- package/dist/__tests__/services/accountService.test.js.map +1 -0
- package/dist/__tests__/services/addressService.test.d.ts +6 -0
- package/dist/__tests__/services/addressService.test.js +246 -0
- package/dist/__tests__/services/addressService.test.js.map +1 -0
- package/dist/__tests__/services/balanceService.test.d.ts +6 -0
- package/dist/__tests__/services/balanceService.test.js +333 -0
- package/dist/__tests__/services/balanceService.test.js.map +1 -0
- package/dist/__tests__/services/walletSetupService.test.d.ts +6 -0
- package/dist/__tests__/services/walletSetupService.test.js +304 -0
- package/dist/__tests__/services/walletSetupService.test.js.map +1 -0
- package/dist/__tests__/services/walletSwitchingService.test.d.ts +6 -0
- package/dist/__tests__/services/walletSwitchingService.test.js +209 -0
- package/dist/__tests__/services/walletSwitchingService.test.js.map +1 -0
- package/dist/__tests__/services/workletLifecycleService.test.d.ts +6 -0
- package/dist/__tests__/services/workletLifecycleService.test.js +451 -0
- package/dist/__tests__/services/workletLifecycleService.test.js.map +1 -0
- package/dist/__tests__/setup.d.ts +7 -0
- package/dist/__tests__/setup.js +49 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/__tests__/storage/mmkvStorage.test.d.ts +6 -0
- package/dist/__tests__/storage/mmkvStorage.test.js +213 -0
- package/dist/__tests__/storage/mmkvStorage.test.js.map +1 -0
- package/dist/__tests__/store/walletStore.test.d.ts +4 -0
- package/dist/__tests__/store/walletStore.test.js +86 -0
- package/dist/__tests__/store/walletStore.test.js.map +1 -0
- package/dist/__tests__/store/workletStore.test.d.ts +4 -0
- package/dist/__tests__/store/workletStore.test.js +255 -0
- package/dist/__tests__/store/workletStore.test.js.map +1 -0
- package/dist/__tests__/types/hrpc.test.d.ts +4 -0
- package/dist/__tests__/types/hrpc.test.js +99 -0
- package/dist/__tests__/types/hrpc.test.js.map +1 -0
- package/dist/__tests__/utils/balanceUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/balanceUtils.test.js +133 -0
- package/dist/__tests__/utils/balanceUtils.test.js.map +1 -0
- package/dist/__tests__/utils/errorHandling.test.d.ts +6 -0
- package/dist/__tests__/utils/errorHandling.test.js +119 -0
- package/dist/__tests__/utils/errorHandling.test.js.map +1 -0
- package/dist/__tests__/utils/errorUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/errorUtils.test.js +133 -0
- package/dist/__tests__/utils/errorUtils.test.js.map +1 -0
- package/dist/__tests__/utils/initializationState.test.d.ts +6 -0
- package/dist/__tests__/utils/initializationState.test.js +243 -0
- package/dist/__tests__/utils/initializationState.test.js.map +1 -0
- package/dist/__tests__/utils/jsonUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/jsonUtils.test.js +118 -0
- package/dist/__tests__/utils/jsonUtils.test.js.map +1 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.d.ts +6 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.js +158 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.js.map +1 -0
- package/dist/__tests__/utils/mnemonicUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/mnemonicUtils.test.js +40 -0
- package/dist/__tests__/utils/mnemonicUtils.test.js.map +1 -0
- package/dist/__tests__/utils/raceConditions.test.d.ts +6 -0
- package/dist/__tests__/utils/raceConditions.test.js +239 -0
- package/dist/__tests__/utils/raceConditions.test.js.map +1 -0
- package/dist/__tests__/utils/result.test.d.ts +4 -0
- package/dist/__tests__/utils/result.test.js +66 -0
- package/dist/__tests__/utils/result.test.js.map +1 -0
- package/dist/__tests__/utils/schemas.test.d.ts +4 -0
- package/dist/__tests__/utils/schemas.test.js +66 -0
- package/dist/__tests__/utils/schemas.test.js.map +1 -0
- package/dist/__tests__/utils/storeHelpers.test.d.ts +4 -0
- package/dist/__tests__/utils/storeHelpers.test.js +227 -0
- package/dist/__tests__/utils/storeHelpers.test.js.map +1 -0
- package/dist/__tests__/utils/typeGuards.test.d.ts +4 -0
- package/dist/__tests__/utils/typeGuards.test.js +175 -0
- package/dist/__tests__/utils/typeGuards.test.js.map +1 -0
- package/dist/__tests__/utils/validation.test.d.ts +4 -0
- package/dist/__tests__/utils/validation.test.js +126 -0
- package/dist/__tests__/utils/validation.test.js.map +1 -0
- package/dist/__tests__/utils/walletUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/walletUtils.test.js +156 -0
- package/dist/__tests__/utils/walletUtils.test.js.map +1 -0
- package/dist/hooks/useBalance.d.ts +170 -0
- package/dist/hooks/useBalance.js +442 -0
- package/dist/hooks/useBalance.js.map +1 -0
- package/dist/hooks/useWallet.d.ts +43 -0
- package/dist/hooks/useWallet.js +193 -0
- package/dist/hooks/useWallet.js.map +1 -0
- package/dist/hooks/useWalletManager.d.ts +100 -0
- package/dist/hooks/useWalletManager.js +526 -0
- package/dist/hooks/useWalletManager.js.map +1 -0
- package/dist/hooks/useWdkApp.d.ts +66 -0
- package/dist/hooks/useWdkApp.js +74 -0
- package/dist/hooks/useWdkApp.js.map +1 -0
- package/dist/hooks/useWorklet.d.ts +66 -0
- package/dist/hooks/useWorklet.js +42 -0
- package/dist/hooks/useWorklet.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/WdkAppProvider.d.ts +112 -0
- package/dist/provider/WdkAppProvider.js +558 -0
- package/dist/provider/WdkAppProvider.js.map +1 -0
- package/dist/services/accountService.d.ts +52 -0
- package/dist/services/accountService.js +119 -0
- package/dist/services/accountService.js.map +1 -0
- package/dist/services/addressService.d.ts +22 -0
- package/dist/services/addressService.js +110 -0
- package/dist/services/addressService.js.map +1 -0
- package/dist/services/balanceService.d.ts +114 -0
- package/dist/services/balanceService.js +208 -0
- package/dist/services/balanceService.js.map +1 -0
- package/dist/services/walletSetupService.d.ts +217 -0
- package/dist/services/walletSetupService.js +535 -0
- package/dist/services/walletSetupService.js.map +1 -0
- package/dist/services/walletSwitchingService.d.ts +48 -0
- package/dist/services/walletSwitchingService.js +143 -0
- package/dist/services/walletSwitchingService.js.map +1 -0
- package/dist/services/workletLifecycleService.d.ts +117 -0
- package/dist/services/workletLifecycleService.js +433 -0
- package/dist/services/workletLifecycleService.js.map +1 -0
- package/dist/storage/mmkvStorage.d.ts +44 -0
- package/dist/storage/mmkvStorage.js +348 -0
- package/dist/storage/mmkvStorage.js.map +1 -0
- package/dist/store/walletStore.d.ts +130 -0
- package/dist/store/walletStore.js +204 -0
- package/dist/store/walletStore.js.map +1 -0
- package/dist/store/workletStore.d.ts +121 -0
- package/dist/store/workletStore.js +256 -0
- package/dist/store/workletStore.js.map +1 -0
- package/dist/types/hrpc.d.ts +60 -0
- package/dist/types/hrpc.js +26 -0
- package/dist/types/hrpc.js.map +1 -0
- package/dist/types.d.ts +168 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/balanceUtils.d.ts +30 -0
- package/dist/utils/balanceUtils.js +86 -0
- package/dist/utils/balanceUtils.js.map +1 -0
- package/dist/utils/constants.d.ts +66 -0
- package/dist/utils/constants.js +73 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/errorHandling.d.ts +47 -0
- package/dist/utils/errorHandling.js +54 -0
- package/dist/utils/errorHandling.js.map +1 -0
- package/dist/utils/errorUtils.d.ts +89 -0
- package/dist/utils/errorUtils.js +264 -0
- package/dist/utils/errorUtils.js.map +1 -0
- package/dist/utils/initializationState.d.ts +129 -0
- package/dist/utils/initializationState.js +220 -0
- package/dist/utils/initializationState.js.map +1 -0
- package/dist/utils/jsonUtils.d.ts +21 -0
- package/dist/utils/jsonUtils.js +67 -0
- package/dist/utils/jsonUtils.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.js +50 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mmkvKeyManager.d.ts +57 -0
- package/dist/utils/mmkvKeyManager.js +214 -0
- package/dist/utils/mmkvKeyManager.js.map +1 -0
- package/dist/utils/mnemonicUtils.d.ts +17 -0
- package/dist/utils/mnemonicUtils.js +28 -0
- package/dist/utils/mnemonicUtils.js.map +1 -0
- package/dist/utils/operationMutex.d.ts +69 -0
- package/dist/utils/operationMutex.js +150 -0
- package/dist/utils/operationMutex.js.map +1 -0
- package/dist/utils/result.d.ts +34 -0
- package/dist/utils/result.js +43 -0
- package/dist/utils/result.js.map +1 -0
- package/dist/utils/schemas.d.ts +365 -0
- package/dist/utils/schemas.js +152 -0
- package/dist/utils/schemas.js.map +1 -0
- package/dist/utils/storeHelpers.d.ts +112 -0
- package/dist/utils/storeHelpers.js +198 -0
- package/dist/utils/storeHelpers.js.map +1 -0
- package/dist/utils/typeGuards.d.ts +70 -0
- package/dist/utils/typeGuards.js +95 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/validation.d.ts +53 -0
- package/dist/utils/validation.js +152 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/walletStateHelpers.d.ts +62 -0
- package/dist/utils/walletStateHelpers.js +81 -0
- package/dist/utils/walletStateHelpers.js.map +1 -0
- package/dist/utils/walletUtils.d.ts +38 -0
- package/dist/utils/walletUtils.js +87 -0
- package/dist/utils/walletUtils.js.map +1 -0
- package/package.json +79 -0
- package/src/__mocks__/react.ts +34 -0
- package/src/__mocks__/secureStorage.ts +87 -0
- package/src/__tests__/hooks/useBalance.test.ts +286 -0
- package/src/__tests__/hooks/useWallet.test.ts +122 -0
- package/src/__tests__/hooks/useWalletManager.test.ts +271 -0
- package/src/__tests__/hooks/useWdkApp.test.tsx +59 -0
- package/src/__tests__/hooks/useWorklet.test.ts +195 -0
- package/src/__tests__/provider/WdkAppProvider.test.tsx +67 -0
- package/src/__tests__/services/accountService.test.ts +337 -0
- package/src/__tests__/services/addressService.test.ts +312 -0
- package/src/__tests__/services/balanceService.test.ts +411 -0
- package/src/__tests__/services/walletSetupService.test.ts +463 -0
- package/src/__tests__/services/walletSwitchingService.test.ts +258 -0
- package/src/__tests__/services/workletLifecycleService.test.ts +514 -0
- package/src/__tests__/setup.ts +54 -0
- package/src/__tests__/storage/mmkvStorage.test.ts +325 -0
- package/src/__tests__/store/walletStore.test.ts +101 -0
- package/src/__tests__/store/workletStore.test.ts +329 -0
- package/src/__tests__/types/hrpc.test.ts +125 -0
- package/src/__tests__/utils/balanceUtils.test.ts +151 -0
- package/src/__tests__/utils/errorHandling.test.ts +147 -0
- package/src/__tests__/utils/errorUtils.test.ts +170 -0
- package/src/__tests__/utils/initializationState.test.ts +337 -0
- package/src/__tests__/utils/jsonUtils.test.ts +131 -0
- package/src/__tests__/utils/mmkvKeyManager.test.ts +205 -0
- package/src/__tests__/utils/mnemonicUtils.test.ts +48 -0
- package/src/__tests__/utils/raceConditions.test.ts +292 -0
- package/src/__tests__/utils/result.test.ts +73 -0
- package/src/__tests__/utils/schemas.test.ts +82 -0
- package/src/__tests__/utils/storeHelpers.test.ts +323 -0
- package/src/__tests__/utils/typeGuards.test.ts +209 -0
- package/src/__tests__/utils/validation.test.ts +152 -0
- package/src/__tests__/utils/walletUtils.test.ts +195 -0
- package/src/hooks/useBalance.ts +597 -0
- package/src/hooks/useWallet.ts +288 -0
- package/src/hooks/useWalletManager.ts +654 -0
- package/src/hooks/useWdkApp.ts +78 -0
- package/src/hooks/useWorklet.ts +109 -0
- package/src/index.ts +112 -0
- package/src/provider/WdkAppProvider.tsx +764 -0
- package/src/services/accountService.ts +134 -0
- package/src/services/addressService.ts +125 -0
- package/src/services/balanceService.ts +291 -0
- package/src/services/walletSetupService.ts +695 -0
- package/src/services/walletSwitchingService.ts +157 -0
- package/src/services/workletLifecycleService.ts +561 -0
- package/src/storage/mmkvStorage.ts +417 -0
- package/src/store/walletStore.ts +301 -0
- package/src/store/workletStore.ts +340 -0
- package/src/types/hrpc.ts +78 -0
- package/src/types.ts +188 -0
- package/src/utils/balanceUtils.ts +96 -0
- package/src/utils/constants.ts +84 -0
- package/src/utils/errorHandling.md +163 -0
- package/src/utils/errorHandling.ts +61 -0
- package/src/utils/errorUtils.ts +300 -0
- package/src/utils/initializationState.ts +242 -0
- package/src/utils/jsonUtils.ts +75 -0
- package/src/utils/logger.ts +54 -0
- package/src/utils/mmkvKeyManager.ts +256 -0
- package/src/utils/mnemonicUtils.ts +35 -0
- package/src/utils/operationMutex.ts +181 -0
- package/src/utils/result.ts +57 -0
- package/src/utils/schemas.ts +190 -0
- package/src/utils/storeHelpers.ts +236 -0
- package/src/utils/typeGuards.ts +129 -0
- package/src/utils/validation.ts +174 -0
- package/src/utils/walletStateHelpers.ts +104 -0
- package/src/utils/walletUtils.ts +107 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { SecureStorage } from '@tetherto/wdk-react-native-secure-storage';
|
|
2
|
+
import type { NetworkConfigs } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Wallet setup service
|
|
5
|
+
* Handles creating new wallets and loading existing wallets with biometric authentication
|
|
6
|
+
* Caches credentials in ephemeral memory to avoid repeated biometric prompts
|
|
7
|
+
*
|
|
8
|
+
* ## Biometric Authentication Lifecycle
|
|
9
|
+
*
|
|
10
|
+
* ### When Biometric Authentication is Required
|
|
11
|
+
*
|
|
12
|
+
* 1. **Creating a new wallet** (`createNewWallet`)
|
|
13
|
+
* - Always requires biometric authentication before wallet creation
|
|
14
|
+
* - Ensures only authorized users can create wallets
|
|
15
|
+
* - Credentials are cached after successful authentication
|
|
16
|
+
*
|
|
17
|
+
* 2. **Loading existing wallet** (`loadExistingWallet`)
|
|
18
|
+
* - Requires biometric authentication if credentials are not cached
|
|
19
|
+
* - If credentials are in cache, authentication is skipped (better UX)
|
|
20
|
+
* - Cache is checked first before prompting for biometrics
|
|
21
|
+
*
|
|
22
|
+
* 3. **Importing wallet from mnemonic** (`initializeFromMnemonic`)
|
|
23
|
+
* - Always requires biometric authentication before import
|
|
24
|
+
* - Ensures only authorized users can import wallets
|
|
25
|
+
* - Credentials are cached after successful authentication
|
|
26
|
+
*
|
|
27
|
+
* ### Credential Caching Behavior
|
|
28
|
+
*
|
|
29
|
+
* - **Cache Location**: Ephemeral memory only (Map<string, CachedCredentials>)
|
|
30
|
+
* - Cache is keyed by `identifier` (user email/ID) for multi-wallet support
|
|
31
|
+
* - Cache persists for the lifetime of the app session
|
|
32
|
+
* - Cache is cleared when app is terminated (not persisted to disk)
|
|
33
|
+
*
|
|
34
|
+
* - **Cache Contents**:
|
|
35
|
+
* - `encryptionKey`: Cached after first retrieval (most sensitive, requires biometrics)
|
|
36
|
+
* - `encryptedSeed`: Cached after first retrieval
|
|
37
|
+
* - `encryptedEntropy`: Cached after first retrieval
|
|
38
|
+
*
|
|
39
|
+
* - **Cache Benefits**:
|
|
40
|
+
* - Avoids repeated biometric prompts during the same app session
|
|
41
|
+
* - Improves UX for operations that need credentials multiple times
|
|
42
|
+
* - Reduces security surface (fewer biometric prompts = fewer attack vectors)
|
|
43
|
+
*
|
|
44
|
+
* ### When Cache is Cleared
|
|
45
|
+
*
|
|
46
|
+
* Cache is automatically cleared in the following scenarios:
|
|
47
|
+
*
|
|
48
|
+
* 1. **Explicit cache clearing** (`clearCredentialsCache`)
|
|
49
|
+
* - Called when wallet data is corrupted or invalid
|
|
50
|
+
* - Called during wallet deletion
|
|
51
|
+
* - Can be called manually for security (e.g., on logout)
|
|
52
|
+
*
|
|
53
|
+
* 2. **App termination**
|
|
54
|
+
* - Cache is in-memory only, so it's cleared when app closes
|
|
55
|
+
* - Next app launch will require biometric authentication again
|
|
56
|
+
*
|
|
57
|
+
* 3. **Wallet deletion** (`deleteWallet`)
|
|
58
|
+
* - Cache for the deleted wallet identifier is cleared
|
|
59
|
+
* - Other wallet caches remain intact
|
|
60
|
+
*
|
|
61
|
+
* ### Security Considerations
|
|
62
|
+
*
|
|
63
|
+
* - **Cache Lifetime**: Ephemeral (in-memory only, cleared on app termination)
|
|
64
|
+
* - **Cache Scope**: Per-identifier (multi-wallet support)
|
|
65
|
+
* - **Cache Invalidation**: Manual via `clearCredentialsCache()` or automatic on app termination
|
|
66
|
+
* - **Biometric Prompt Frequency**:
|
|
67
|
+
* - First access per app session: Always required
|
|
68
|
+
* - Subsequent accesses in same session: Cached (no prompt)
|
|
69
|
+
* - After app restart: Always required again
|
|
70
|
+
*
|
|
71
|
+
* ### Best Practices
|
|
72
|
+
*
|
|
73
|
+
* 1. **Clear cache on logout**: Call `clearCredentialsCache(identifier)` when user logs out
|
|
74
|
+
* 2. **Clear cache on errors**: Clear cache if decryption fails (may indicate corrupted data)
|
|
75
|
+
* 3. **Don't persist cache**: Cache is intentionally in-memory only for security
|
|
76
|
+
* 4. **Handle cache misses**: Always handle the case where cache is empty (will prompt for biometrics)
|
|
77
|
+
*
|
|
78
|
+
* ### Example Usage
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Create new wallet (always requires biometrics)
|
|
82
|
+
* await WalletSetupService.createNewWallet(networkConfigs, walletId)
|
|
83
|
+
*
|
|
84
|
+
* // Load existing wallet (biometrics only if not cached)
|
|
85
|
+
* const credentials = await WalletSetupService.loadExistingWallet(walletId)
|
|
86
|
+
*
|
|
87
|
+
* // Clear cache (e.g., on logout)
|
|
88
|
+
* WalletSetupService.clearCredentialsCache(walletId)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare class WalletSetupService {
|
|
92
|
+
/**
|
|
93
|
+
* SecureStorage singleton instance
|
|
94
|
+
* Set by WdkAppProvider during initialization
|
|
95
|
+
*/
|
|
96
|
+
private static secureStorageInstance;
|
|
97
|
+
/**
|
|
98
|
+
* Set the secureStorage singleton instance
|
|
99
|
+
* Called by WdkAppProvider during initialization
|
|
100
|
+
* Also exposed publicly for testing purposes
|
|
101
|
+
*
|
|
102
|
+
* @param secureStorage - SecureStorage instance to use
|
|
103
|
+
* @param allowOverwrite - If false, warns when overwriting existing instance (default: true)
|
|
104
|
+
*/
|
|
105
|
+
static setSecureStorage(secureStorage: SecureStorage, allowOverwrite?: boolean): void;
|
|
106
|
+
/**
|
|
107
|
+
* Get the secureStorage singleton instance
|
|
108
|
+
* Throws error if not initialized (should only happen if called before WdkAppProvider mounts)
|
|
109
|
+
*/
|
|
110
|
+
private static getSecureStorage;
|
|
111
|
+
/**
|
|
112
|
+
* Check if secureStorage is initialized
|
|
113
|
+
* Useful for testing or debugging
|
|
114
|
+
*/
|
|
115
|
+
static isSecureStorageInitialized(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Get cache key for walletId
|
|
118
|
+
*/
|
|
119
|
+
private static getCacheKey;
|
|
120
|
+
/**
|
|
121
|
+
* Cache credentials after retrieval
|
|
122
|
+
*/
|
|
123
|
+
private static cacheCredentials;
|
|
124
|
+
/**
|
|
125
|
+
* Generic helper to retrieve a credential value (checks cache first, then secureStorage)
|
|
126
|
+
*/
|
|
127
|
+
private static getCredential;
|
|
128
|
+
/**
|
|
129
|
+
* Validate that encrypted data can be decrypted with the encryption key
|
|
130
|
+
* Attempts to initialize WDK with the provided credentials to verify compatibility
|
|
131
|
+
*
|
|
132
|
+
* @param networkConfigs - Network configurations for worklet
|
|
133
|
+
* @param encryptionKey - Encryption key to test
|
|
134
|
+
* @param encryptedSeed - Encrypted seed to test
|
|
135
|
+
* @param encryptedEntropy - Optional encrypted entropy to test
|
|
136
|
+
* @throws Error if validation fails (decryption fails)
|
|
137
|
+
*/
|
|
138
|
+
private static validateEncryptionCompatibility;
|
|
139
|
+
/**
|
|
140
|
+
* Create a new wallet
|
|
141
|
+
* Generates entropy, encrypts it, and stores credentials securely
|
|
142
|
+
* Requires biometric authentication to ensure authorized wallet creation
|
|
143
|
+
*/
|
|
144
|
+
static createNewWallet(networkConfigs: NetworkConfigs, walletId?: string): Promise<{
|
|
145
|
+
encryptionKey: string;
|
|
146
|
+
encryptedSeed: string;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Load existing wallet from secure storage
|
|
150
|
+
* Checks cache first, only requires biometric authentication if not cached
|
|
151
|
+
*/
|
|
152
|
+
static loadExistingWallet(walletId?: string): Promise<{
|
|
153
|
+
encryptionKey: string;
|
|
154
|
+
encryptedSeed: string;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Check if a wallet exists
|
|
158
|
+
*/
|
|
159
|
+
static hasWallet(walletId?: string): Promise<boolean>;
|
|
160
|
+
/**
|
|
161
|
+
* Initialize WDK from an existing mnemonic phrase
|
|
162
|
+
* Converts mnemonic to encrypted seed and entropy, stores them securely, and initializes WDK
|
|
163
|
+
* Requires biometric authentication to ensure authorized wallet import
|
|
164
|
+
*/
|
|
165
|
+
static initializeFromMnemonic(networkConfigs: NetworkConfigs, mnemonic: string, walletId?: string): Promise<{
|
|
166
|
+
encryptionKey: string;
|
|
167
|
+
encryptedSeed: string;
|
|
168
|
+
encryptedEntropy: string;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Initialize WDK with wallet credentials
|
|
172
|
+
*/
|
|
173
|
+
static initializeWDK(networkConfigs: NetworkConfigs, credentials: {
|
|
174
|
+
encryptionKey: string;
|
|
175
|
+
encryptedSeed: string;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Complete wallet initialization flow
|
|
179
|
+
* Either creates a new wallet or loads an existing one
|
|
180
|
+
*/
|
|
181
|
+
static initializeWallet(networkConfigs: NetworkConfigs, options: {
|
|
182
|
+
createNew?: boolean;
|
|
183
|
+
walletId?: string;
|
|
184
|
+
}): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Delete wallet and clear all data
|
|
187
|
+
*
|
|
188
|
+
* @param identifier - Optional identifier for multi-wallet support. If provided, deletes wallet for that identifier.
|
|
189
|
+
* If not provided, deletes the default wallet.
|
|
190
|
+
*/
|
|
191
|
+
static deleteWallet(walletId?: string): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Get encryption key (checks cache first, then secureStorage with biometrics)
|
|
194
|
+
*/
|
|
195
|
+
static getEncryptionKey(walletId?: string): Promise<string | null>;
|
|
196
|
+
/**
|
|
197
|
+
* Get encrypted seed (checks cache first, then secureStorage)
|
|
198
|
+
*/
|
|
199
|
+
static getEncryptedSeed(walletId?: string): Promise<string | null>;
|
|
200
|
+
/**
|
|
201
|
+
* Get encrypted entropy (checks cache first, then secureStorage)
|
|
202
|
+
*/
|
|
203
|
+
static getEncryptedEntropy(walletId?: string): Promise<string | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Get mnemonic phrase from wallet
|
|
206
|
+
* Retrieves encrypted entropy and encryption key, then decrypts to get mnemonic
|
|
207
|
+
*
|
|
208
|
+
* @param walletId - Optional walletId for multi-wallet support
|
|
209
|
+
* @returns Promise<string | null> - The mnemonic phrase or null if not found
|
|
210
|
+
*/
|
|
211
|
+
static getMnemonic(walletId?: string): Promise<string | null>;
|
|
212
|
+
/**
|
|
213
|
+
* Clear all cached credentials
|
|
214
|
+
* Should be called on logout or app background for security
|
|
215
|
+
*/
|
|
216
|
+
static clearCredentialsCache(walletId?: string): void;
|
|
217
|
+
}
|