@dynamic-labs-wallet/browser 0.0.319 → 0.0.320

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 (53) hide show
  1. package/package.json +2 -2
  2. package/src/backup/encryption/argon2.d.ts +0 -10
  3. package/src/backup/encryption/argon2.d.ts.map +0 -1
  4. package/src/backup/encryption/config.d.ts +0 -39
  5. package/src/backup/encryption/config.d.ts.map +0 -1
  6. package/src/backup/encryption/constants.d.ts +0 -35
  7. package/src/backup/encryption/constants.d.ts.map +0 -1
  8. package/src/backup/encryption/core.d.ts +0 -31
  9. package/src/backup/encryption/core.d.ts.map +0 -1
  10. package/src/backup/encryption/pbkdf2.d.ts +0 -10
  11. package/src/backup/encryption/pbkdf2.d.ts.map +0 -1
  12. package/src/backup/encryption/types.d.ts +0 -46
  13. package/src/backup/encryption/types.d.ts.map +0 -1
  14. package/src/backup/encryption/utils.d.ts +0 -9
  15. package/src/backup/encryption/utils.d.ts.map +0 -1
  16. package/src/backup/providers/googleDrive.d.ts +0 -19
  17. package/src/backup/providers/googleDrive.d.ts.map +0 -1
  18. package/src/backup/providers/iCloud.d.ts +0 -64
  19. package/src/backup/providers/iCloud.d.ts.map +0 -1
  20. package/src/backup/utils.d.ts +0 -14
  21. package/src/backup/utils.d.ts.map +0 -1
  22. package/src/client.d.ts +0 -770
  23. package/src/client.d.ts.map +0 -1
  24. package/src/constants.d.ts +0 -9
  25. package/src/constants.d.ts.map +0 -1
  26. package/src/errorConstants.d.ts +0 -13
  27. package/src/errorConstants.d.ts.map +0 -1
  28. package/src/index.d.ts +0 -14
  29. package/src/index.d.ts.map +0 -1
  30. package/src/mpc/index.d.ts +0 -5
  31. package/src/mpc/index.d.ts.map +0 -1
  32. package/src/mpc/mpc.d.ts +0 -20
  33. package/src/mpc/mpc.d.ts.map +0 -1
  34. package/src/mpc/types.d.ts +0 -6
  35. package/src/mpc/types.d.ts.map +0 -1
  36. package/src/normalizeAddress.d.ts +0 -7
  37. package/src/normalizeAddress.d.ts.map +0 -1
  38. package/src/passwordValidation.d.ts +0 -29
  39. package/src/passwordValidation.d.ts.map +0 -1
  40. package/src/queue.d.ts +0 -96
  41. package/src/queue.d.ts.map +0 -1
  42. package/src/services/encryption.d.ts +0 -19
  43. package/src/services/encryption.d.ts.map +0 -1
  44. package/src/services/localStorage.d.ts +0 -34
  45. package/src/services/localStorage.d.ts.map +0 -1
  46. package/src/services/logger.d.ts +0 -6
  47. package/src/services/logger.d.ts.map +0 -1
  48. package/src/types.d.ts +0 -129
  49. package/src/types.d.ts.map +0 -1
  50. package/src/utils.d.ts +0 -90
  51. package/src/utils.d.ts.map +0 -1
  52. package/src/walletState.d.ts +0 -28
  53. package/src/walletState.d.ts.map +0 -1
package/src/client.d.ts DELETED
@@ -1,770 +0,0 @@
1
- import { EcdsaSignature, MessageHash, type EcdsaPublicKey } from '#internal/web';
2
- import { AuthMode, BackupLocation, DynamicApiClient, ThresholdSignatureScheme, WalletOperation, type BackupLocationWithExternalKeyShareId, type BitcoinConfig, type DynamicWalletClientProps, type FeatureFlags, type GetWalletResponse, type ILogger, type InitializeResult, type KeyShareBackupInfo, type SecureStorageAdapter, type TraceContext, type WalletRecoveryState } from '@dynamic-labs-wallet/core';
3
- import { RoomTypeEnum, type SignMessageContext } from '@dynamic-labs/sdk-api-core';
4
- import type { ClientInitKeygenResult, ClientKeyShare } from './mpc/types.js';
5
- import { type SupportedStorage } from './services/localStorage.js';
6
- import { type Room, type ShareDistribution, type WalletProperties } from './types.js';
7
- type MessageToSign = string | Uint8Array | MessageHash;
8
- /**
9
- * Internal options for DynamicWalletClient constructor.
10
- * This is NOT part of the public API.
11
- */
12
- export interface DynamicWalletClientInternalOptions {
13
- secureStorage?: SecureStorageAdapter;
14
- }
15
- export declare class DynamicWalletClient {
16
- environmentId: string;
17
- storageKey: string;
18
- debug: boolean;
19
- protected userId: string | undefined;
20
- protected sessionId: string | undefined;
21
- protected initializePromise: Promise<InitializeResult> | null;
22
- protected logger: ILogger;
23
- protected apiClient: DynamicApiClient;
24
- protected walletMap: Record<string, WalletProperties>;
25
- protected storage: SupportedStorage;
26
- protected memoryStorage: {
27
- [key: string]: string;
28
- } | null;
29
- protected baseMPCRelayApiUrl?: string;
30
- protected iframe: HTMLIFrameElement | null;
31
- protected forwardMPCEnabled: boolean;
32
- readonly instanceId: string;
33
- readonly iframeDomain: string;
34
- readonly featureFlags: FeatureFlags;
35
- protected authMode: AuthMode;
36
- protected sdkVersion?: string;
37
- protected baseClientKeysharesRelayApiUrl?: string;
38
- protected static rooms: Record<number, Room[]>;
39
- protected static roomsInitializing: Record<number, boolean>;
40
- private static roomsPersistChain;
41
- /**
42
- * Internal secure storage adapter for mobile TEE-backed storage.
43
- * When set, all key share operations use this instead of localStorage.
44
- * This is NOT part of the public API.
45
- */
46
- private readonly secureStorage?;
47
- constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, authToken, backupServiceAuthToken, sdkVersion, forwardMPCClient, baseClientKeysharesRelayApiUrl, iCloudConfig, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
48
- /**
49
- * Check if wallet has heavy operations in progress
50
- */
51
- static isHeavyOpInProgress(accountAddress: string): boolean;
52
- /**
53
- * Check if wallet has operations in any queue (heavy or sign)
54
- */
55
- static isWalletBusy(accountAddress: string): boolean;
56
- /**
57
- * Check if recovery is in progress for a wallet
58
- */
59
- static isRecoveryInProgress(accountAddress: string): boolean;
60
- /**
61
- * Reset static state for testing purposes.
62
- * This clears all wallet queues and in-flight recovery tracking.
63
- * @internal For testing only
64
- */
65
- static resetStaticState(): void;
66
- /**
67
- * Get wallet properties from the wallet map using normalized address.
68
- * Normalizes the address to lowercase for consistent lookups regardless of input casing.
69
- */
70
- protected getWalletFromMap(accountAddress: string): WalletProperties | undefined;
71
- /**
72
- * Get wallet properties from the map, refetching once if not found.
73
- * Uses getWallet (with NO_OPERATION) when signedSessionId is available for a
74
- * more robust fetch, otherwise falls back to getWallets().
75
- */
76
- protected requireWalletFromMap(accountAddress: string, signedSessionId?: string): Promise<WalletProperties>;
77
- /**
78
- * Update wallet properties in the wallet map using normalized address.
79
- * Normalizes the address to lowercase for consistent storage regardless of input casing.
80
- */
81
- protected updateWalletMap(accountAddress: string, updates: Partial<WalletProperties>): void;
82
- getAuthMode(): AuthMode;
83
- /**
84
- * Get environment settings from the API client.
85
- * Used to retrieve configuration like iCloud settings.
86
- */
87
- getEnvironmentSettings(): Promise<any>;
88
- /**
89
- * Check if the SDK version meets the requirement for signed session ID
90
- * Uses namespace-specific version requirements when available
91
- * @returns boolean indicating if requireSignedSessionId should be set to true
92
- */
93
- private requiresSignedSessionId;
94
- initLoggerContext(authToken: string): Promise<void>;
95
- initialize(traceContext?: TraceContext): Promise<InitializeResult>;
96
- /**
97
- * Client initialization logic
98
- */
99
- protected _initialize(traceContext?: TraceContext): Promise<InitializeResult>;
100
- serverInitializeKeyGen({ chainName, clientKeygenIds, dynamicRequestId, thresholdSignatureScheme, bitcoinConfig, onError, onCeremonyComplete, }: {
101
- chainName: string;
102
- clientKeygenIds: string[];
103
- dynamicRequestId: string;
104
- thresholdSignatureScheme: ThresholdSignatureScheme;
105
- bitcoinConfig?: BitcoinConfig;
106
- onError?: (error: Error) => void;
107
- onCeremonyComplete?: (accountAddress: string, walletId: string) => void;
108
- }): Promise<import("@dynamic-labs-wallet/core").KeygenCompleteResponse>;
109
- clientInitializeKeyGen({ chainName, thresholdSignatureScheme, bitcoinConfig, }: {
110
- chainName: string;
111
- thresholdSignatureScheme: ThresholdSignatureScheme;
112
- bitcoinConfig?: BitcoinConfig;
113
- }): Promise<ClientInitKeygenResult[]>;
114
- derivePublicKey({ chainName, keyShare, derivationPath, bitcoinConfig, }: {
115
- chainName: string;
116
- keyShare: ClientKeyShare;
117
- derivationPath: Uint32Array | undefined;
118
- bitcoinConfig?: BitcoinConfig;
119
- }): Promise<EcdsaPublicKey | Uint8Array | string | undefined>;
120
- /**
121
- * Drop-in replacement for clientKeygen that routes to forwardMPC keygen or receiveKey as appropriate,
122
- * using identical params and matching clientKeygen toggling logic based on the chain.
123
- * Returns both the raw public key and the array of new client key shares.
124
- *
125
- * @param chainName The blockchain chain name (e.g., EVM, SVM).
126
- * @param roomId The keygen "room" identifier (usually created by the server).
127
- * @param serverKeygenIds The keygen IDs from server parties.
128
- * @param clientKeygenInitResults The array of initial keygen values from the MPC library.
129
- * @param thresholdSignatureScheme The signature threshold scheme to use for keygen.
130
- * @param bitcoinConfig Optional config for bitcoin keygen.
131
- * @param dynamicRequestId Used for tracing/logging.
132
- * @param traceContext Additional tracing context.
133
- * @returns An object containing the derived rawPublicKey and all clientKeygenResults.
134
- */
135
- forwardMPCClientKeygen({ chainName, roomId, serverKeygenIds, clientKeygenInitResults, thresholdSignatureScheme, bitcoinConfig, dynamicRequestId, traceContext, }: {
136
- chainName: string;
137
- roomId: string;
138
- serverKeygenIds: string[];
139
- clientKeygenInitResults: ClientInitKeygenResult[];
140
- thresholdSignatureScheme: ThresholdSignatureScheme;
141
- bitcoinConfig?: BitcoinConfig;
142
- dynamicRequestId?: string;
143
- traceContext?: TraceContext;
144
- }): Promise<{
145
- rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
146
- clientKeygenResults: ClientKeyShare[];
147
- }>;
148
- clientKeyGen({ chainName, roomId, serverKeygenIds, clientKeygenInitResults, thresholdSignatureScheme, bitcoinConfig, dynamicRequestId, traceContext, }: {
149
- chainName: string;
150
- roomId: string;
151
- serverKeygenIds: string[];
152
- clientKeygenInitResults: ClientInitKeygenResult[];
153
- thresholdSignatureScheme: ThresholdSignatureScheme;
154
- bitcoinConfig?: BitcoinConfig;
155
- dynamicRequestId?: string;
156
- traceContext?: TraceContext;
157
- }): Promise<{
158
- rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
159
- clientKeygenResults: ClientKeyShare[];
160
- }>;
161
- keyGen({ chainName, thresholdSignatureScheme, bitcoinConfig, onError, onCeremonyComplete, traceContext, password, signedSessionId, }: {
162
- chainName: string;
163
- thresholdSignatureScheme: ThresholdSignatureScheme;
164
- bitcoinConfig?: BitcoinConfig;
165
- onError?: (error: Error) => void;
166
- onCeremonyComplete?: (accountAddress: string, walletId: string) => void;
167
- traceContext?: TraceContext;
168
- password?: string;
169
- signedSessionId: string;
170
- }): Promise<{
171
- rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
172
- clientKeyShares: ClientKeyShare[];
173
- }>;
174
- importRawPrivateKey({ chainName, privateKey, thresholdSignatureScheme, bitcoinConfig, onError, onCeremonyComplete, traceContext, legacyWalletId, password, signedSessionId, }: {
175
- chainName: string;
176
- privateKey: string;
177
- thresholdSignatureScheme: ThresholdSignatureScheme;
178
- bitcoinConfig?: BitcoinConfig;
179
- onError?: (error: Error) => void;
180
- onCeremonyComplete?: (accountAddress: string, walletId: string) => void;
181
- traceContext?: TraceContext;
182
- /** ID of the legacy embedded wallet being upgraded to v3 */
183
- legacyWalletId?: string;
184
- password?: string;
185
- signedSessionId: string;
186
- }): Promise<{
187
- rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
188
- clientKeyShares: ClientKeyShare[];
189
- }>;
190
- serverSign({ walletId, message, isFormatted, mfaToken, elevatedAccessToken, roomId, context, onError, dynamicRequestId, traceContext, bitcoinConfig, }: {
191
- walletId: string;
192
- message: string | Uint8Array;
193
- dynamicRequestId: string;
194
- isFormatted?: boolean;
195
- mfaToken?: string;
196
- elevatedAccessToken?: string;
197
- roomId?: string;
198
- context?: SignMessageContext;
199
- onError?: (error: Error) => void;
200
- traceContext?: TraceContext;
201
- bitcoinConfig?: BitcoinConfig;
202
- }): Promise<import("@dynamic-labs-wallet/core").OpenRoomResponse>;
203
- private prepareMessageForForwardMPC;
204
- private convertTweakForBIP340;
205
- private processForwardMPCSignature;
206
- forwardMPCClientSign({ chainName, message, roomId, keyShare, derivationPath, formattedMessage, dynamicRequestId, isFormatted, traceContext, bitcoinConfig, }: {
207
- chainName: string;
208
- message: string | Uint8Array;
209
- roomId: string;
210
- keyShare: ClientKeyShare;
211
- derivationPath: Uint32Array | undefined;
212
- formattedMessage: MessageToSign;
213
- dynamicRequestId: string;
214
- isFormatted?: boolean;
215
- traceContext?: TraceContext;
216
- bitcoinConfig?: BitcoinConfig;
217
- }): Promise<Uint8Array | EcdsaSignature>;
218
- clientSign({ chainName, message, roomId, keyShare, derivationPath, isFormatted, dynamicRequestId, traceContext, bitcoinConfig, }: {
219
- chainName: string;
220
- message: string | Uint8Array;
221
- roomId: string;
222
- dynamicRequestId: string;
223
- keyShare: ClientKeyShare;
224
- derivationPath: Uint32Array | undefined;
225
- isFormatted?: boolean;
226
- traceContext?: TraceContext;
227
- bitcoinConfig?: BitcoinConfig;
228
- }): Promise<Uint8Array | EcdsaSignature>;
229
- /**
230
- * Recovers key shares from backup when a public key mismatch error is detected.
231
- * This is the core recovery logic used by various MPC operations.
232
- *
233
- * @param error - The error to check
234
- * @param recoveryParams - Parameters needed for key share recovery
235
- * @returns The recovered key shares if error was a mismatch, throws otherwise
236
- */
237
- private recoverKeySharesOnMismatch;
238
- sign({ accountAddress, message, chainName, password, isFormatted, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext, bitcoinConfig, }: {
239
- accountAddress: string;
240
- message: string | Uint8Array;
241
- chainName: string;
242
- password?: string;
243
- isFormatted?: boolean;
244
- signedSessionId: string;
245
- mfaToken?: string;
246
- elevatedAccessToken?: string;
247
- context?: SignMessageContext;
248
- onError?: (error: Error) => void;
249
- traceContext?: TraceContext;
250
- bitcoinConfig?: BitcoinConfig;
251
- }): Promise<Uint8Array | EcdsaSignature>;
252
- private internalSign;
253
- refreshWalletAccountShares({ accountAddress, chainName, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext, }: {
254
- accountAddress: string;
255
- chainName: string;
256
- password?: string;
257
- signedSessionId: string;
258
- mfaToken?: string;
259
- elevatedAccessToken?: string;
260
- traceContext?: TraceContext;
261
- }): Promise<void>;
262
- /**
263
- * Gets the Bitcoin config for MPC operations by looking up addressType
264
- * from walletMap, with fallback to deriving it from derivationPath.
265
- */
266
- private getBitcoinConfigForChain;
267
- private internalRefreshWalletAccountShares;
268
- getExportId({ chainName, clientKeyShare, bitcoinConfig, }: {
269
- chainName: string;
270
- clientKeyShare: ClientKeyShare;
271
- bitcoinConfig?: BitcoinConfig;
272
- }): Promise<string>;
273
- /**
274
- * Helper function to create client shares required to complete a reshare ceremony.
275
- * @param {string} chainName - The chain to create shares for
276
- * @param {WalletProperties} wallet - The wallet to reshare
277
- * @param {ThresholdSignatureScheme} oldThresholdSignatureScheme - The current threshold signature scheme
278
- * @param {ThresholdSignatureScheme} newThresholdSignatureScheme - The target threshold signature scheme
279
- * @returns {Promise<{
280
- * newClientInitKeygenResults: ClientInitKeygenResult[],
281
- * newClientKeygenIds: string[],
282
- * existingClientKeygenIds: string[],
283
- * existingClientKeyShares: ClientKeyShare[]
284
- * }>} Object containing new and existing client keygen results, IDs and shares
285
- * @todo Support higher to lower reshare strategies
286
- */
287
- reshareStrategy({ chainName, wallet, accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme, }: {
288
- chainName: string;
289
- wallet: WalletProperties;
290
- accountAddress: string;
291
- oldThresholdSignatureScheme: ThresholdSignatureScheme;
292
- newThresholdSignatureScheme: ThresholdSignatureScheme;
293
- }): Promise<{
294
- newClientInitKeygenResults: ClientInitKeygenResult[];
295
- newClientKeygenIds: string[];
296
- existingClientKeygenIds: string[];
297
- existingClientKeyShares: ClientKeyShare[];
298
- }>;
299
- reshare({ chainName, accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme, password, signedSessionId, cloudProviders, delegateToProjectEnvironment, mfaToken, elevatedAccessToken, revokeDelegation, }: {
300
- chainName: string;
301
- accountAddress: string;
302
- oldThresholdSignatureScheme: ThresholdSignatureScheme;
303
- newThresholdSignatureScheme: ThresholdSignatureScheme;
304
- password?: string;
305
- signedSessionId: string;
306
- cloudProviders?: BackupLocation[];
307
- delegateToProjectEnvironment?: boolean;
308
- mfaToken?: string;
309
- elevatedAccessToken?: string;
310
- revokeDelegation?: boolean;
311
- }): Promise<void>;
312
- private internalReshare;
313
- private performDelegationOperation;
314
- delegateKeyShares({ accountAddress, password, signedSessionId, mfaToken, }: {
315
- accountAddress: string;
316
- password?: string;
317
- signedSessionId: string;
318
- mfaToken?: string;
319
- }): Promise<BackupLocationWithExternalKeyShareId[]>;
320
- revokeDelegation({ accountAddress, password, signedSessionId, mfaToken, }: {
321
- accountAddress: string;
322
- password?: string;
323
- signedSessionId: string;
324
- mfaToken?: string;
325
- }): Promise<void>;
326
- private createKeygenResult;
327
- exportKey({ accountAddress, chainName, bitcoinConfig, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext, }: {
328
- accountAddress: string;
329
- chainName: string;
330
- bitcoinConfig?: BitcoinConfig;
331
- password?: string;
332
- signedSessionId: string;
333
- mfaToken?: string;
334
- elevatedAccessToken?: string;
335
- traceContext?: TraceContext;
336
- }): Promise<{
337
- derivedPrivateKey: string | undefined;
338
- }>;
339
- private getReconstructedKeyShare;
340
- private performMPCExport;
341
- private derivePrivateKeyFromExport;
342
- offlineExportKey({ chainName, keyShares, derivationPath, }: {
343
- chainName: string;
344
- keyShares: ClientKeyShare[];
345
- derivationPath?: string;
346
- }): Promise<{
347
- derivedPrivateKey: string | undefined;
348
- rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
349
- }>;
350
- encryptKeyShare({ keyShare, password }: {
351
- keyShare: ClientKeyShare;
352
- password?: string;
353
- }): Promise<string>;
354
- /**
355
- * helper function to store encrypted backup by wallet from iframe local storage
356
- */
357
- private getClientKeySharesFromLocalStorage;
358
- /**
359
- * Helper function to get client key shares from storage.
360
- * Uses secureStorage when available (mobile), otherwise falls back to localStorage (browser).
361
- */
362
- getClientKeySharesFromStorage({ accountAddress }: {
363
- accountAddress: string;
364
- }): Promise<ClientKeyShare[]>;
365
- /**
366
- * Helper function to initialize a wallet map entry during onCeremonyComplete.
367
- * This is called before any backup has happened, so it initializes with empty backup info.
368
- * The backup info gets updated later in storeEncryptedBackupByWallet.
369
- *
370
- * @param accountAddress - The wallet address
371
- * @param walletId - The wallet ID from the server
372
- * @param chainName - The chain name (e.g., 'EVM', 'SVM', 'BTC')
373
- * @param thresholdSignatureScheme - The TSS scheme used
374
- * @param derivationPath - Optional derivation path (will be computed from chainConfig if not provided)
375
- * @param additionalProps - Any chain-specific additional properties to merge
376
- */
377
- protected initializeWalletMapEntry({ accountAddress, walletId, chainName, thresholdSignatureScheme, derivationPath, additionalProps, }: {
378
- accountAddress: string;
379
- walletId: string;
380
- chainName: string;
381
- thresholdSignatureScheme: ThresholdSignatureScheme;
382
- derivationPath?: string;
383
- additionalProps?: Record<string, unknown>;
384
- }): void;
385
- /**
386
- * Helper function to store client key shares in storage.
387
- * Uses secureStorage when available (mobile), otherwise falls back to localStorage (browser).
388
- */
389
- private setClientKeySharesToLocalStorage;
390
- /**
391
- * Helper function to store client key shares in storage.
392
- * Uses secureStorage when available (mobile), otherwise falls back to localStorage (browser).
393
- */
394
- setClientKeySharesToStorage({ accountAddress, clientKeyShares, overwriteOrMerge, }: {
395
- accountAddress: string;
396
- clientKeyShares: ClientKeyShare[];
397
- overwriteOrMerge?: 'overwrite' | 'merge';
398
- }): Promise<void>;
399
- /**
400
- * Ensures that client key shares exist for the given account address.
401
- * Throws an error if no shares are found.
402
- *
403
- * Note: This method only checks for existing shares in storage.
404
- * Auto-recovery logic has been removed in favor of the queue pattern.
405
- * Callers should handle recovery explicitly if needed.
406
- */
407
- private ensureClientShare;
408
- private backupToDynamicBackend;
409
- private updateEncryptedSharesCache;
410
- /**
411
- * Promotes all pending encrypted-shares cache entries to active.
412
- * Called once the server confirms that a password-update batch is fully activated
413
- * (i.e. markKeySharesAsBackedUp returns passwordUpdateStatus !== 'pending').
414
- * Each wallet wrote its new-password shares to a -pending key during upload;
415
- * this method atomically moves them to the active key so the next unlock/validate
416
- * call finds the correct ciphertext.
417
- */
418
- private promoteEncryptedSharesCaches;
419
- private backupToCloudProvider;
420
- private publishDelegatedShare;
421
- private createPreservedDelegatedLocation;
422
- backupSharesWithDistribution({ accountAddress, password, signedSessionId, distribution, preserveDelegatedLocation, passwordUpdateBatchId, }: {
423
- accountAddress: string;
424
- password?: string;
425
- signedSessionId: string;
426
- distribution: ShareDistribution;
427
- preserveDelegatedLocation?: boolean;
428
- passwordUpdateBatchId?: string;
429
- }): Promise<{
430
- message: string;
431
- walletId: string;
432
- passwordUpdateStatus?: "pending" | "activated";
433
- locationsWithKeyShares: {
434
- location: BackupLocation;
435
- id: string;
436
- keygenId: string;
437
- externalKeyShareId?: string;
438
- }[];
439
- }>;
440
- /**
441
- * Central backup orchestrator that encrypts and stores wallet key shares.
442
- *
443
- * This method serves as the main backup coordinator, handling the distribution of encrypted
444
- * key shares between Dynamic's backend and Google Drive based on the wallet's threshold scheme.
445
- * It is used by multiple operations including reshare, refresh, and manual backup requests.
446
- *
447
- * **Backup Distribution Strategy:**
448
- * - **Single share wallets**: All shares stored on Dynamic's backend only
449
- * - **Multi-share wallets (2+)**: When backing up to Google Drive, N-1 shares on Dynamic's backend, 1 share on Google Drive
450
- * - **Multi-share wallets (2+)**: When not backing up to Google Drive, all shares on Dynamic's backend
451
- *
452
- * **Process Flow:**
453
- * 1. Encrypts all client key shares with the provided password (or environment ID if no password)
454
- * 2. For multi-share wallets (2+): conditionally distributes N-1 to backend, 1 to Google Drive
455
- * 3. For other configurations: stores all shares on Dynamic's backend
456
- * 4. Updates backup metadata and synchronizes wallet state
457
- * 5. Persists the updated wallet map to local storage
458
- *
459
- * **Delegated Key Shares:**
460
- * - When delegatedKeyshare is provided, the method will not store the delegated key share but it will mark the delegated share as backed up on Dynamic's backend
461
- * - and encrypt the delegated key share to publish it to the webhook
462
- *
463
- * @param params - The backup operation parameters
464
- * @param params.accountAddress - The account address of the wallet to backup
465
- * @param params.clientKeyShares - Optional specific key shares to backup (uses localStorage if not provided)
466
- * @param params.password - Optional password for encryption (uses environment ID if not provided)
467
- * @param params.signedSessionId - Optional signed session ID for authentication
468
- * @param params.backupToGoogleDrive - Whether to backup to Google Drive (defaults to false)
469
- * @returns Promise with backup metadata including share locations and IDs
470
- */
471
- storeEncryptedBackupByWallet({ accountAddress, clientKeyShares, password, signedSessionId, cloudProviders, delegatedKeyshare, passwordUpdateBatchId, }: {
472
- accountAddress: string;
473
- clientKeyShares?: ClientKeyShare[];
474
- password?: string;
475
- signedSessionId: string;
476
- cloudProviders?: BackupLocation[];
477
- delegatedKeyshare?: ClientKeyShare;
478
- passwordUpdateBatchId?: string;
479
- }): Promise<{
480
- keyShareIds: string[];
481
- keygenIds: string[];
482
- message: string;
483
- walletId: string;
484
- passwordUpdateStatus?: "pending" | "activated";
485
- locationsWithKeyShares: {
486
- location: BackupLocation;
487
- id: string;
488
- keygenId: string;
489
- externalKeyShareId?: string;
490
- }[];
491
- }>;
492
- updatePassword({ accountAddress, existingPassword, newPassword, signedSessionId, passwordUpdateBatchId, }: {
493
- accountAddress: string;
494
- existingPassword?: string;
495
- newPassword?: string;
496
- signedSessionId: string;
497
- passwordUpdateBatchId?: string;
498
- }): Promise<void>;
499
- setPassword({ accountAddress, newPassword, signedSessionId, passwordUpdateBatchId, }: {
500
- accountAddress: string;
501
- newPassword: string;
502
- signedSessionId: string;
503
- passwordUpdateBatchId?: string;
504
- }): Promise<void>;
505
- decryptKeyShare({ keyShare, password }: {
506
- keyShare: string;
507
- password?: string;
508
- }): Promise<ClientKeyShare>;
509
- /**
510
- * Validates that the provided password is consistent with existing encrypted wallets.
511
- * This prevents users from creating multiple wallets with different passwords.
512
- *
513
- * @param password - User-provided password (optional)
514
- * @param signedSessionId - Signed session ID for API calls
515
- * @throws Error with ERROR_PASSWORD_MISMATCH if password doesn't match existing wallets
516
- */
517
- /**
518
- * Shared helper: fetches encrypted shares (from storage or API) and validates
519
- * the provided password by attempting to decrypt the first credential.
520
- * Throws ERROR_PASSWORD_MISMATCH if the password is incorrect.
521
- */
522
- private validatePasswordAgainstEncryptedShares;
523
- private isPasscodeRequired;
524
- private assertPasswordRequired;
525
- protected validatePasswordConsistencyForNewWallet({ password, signedSessionId, }: {
526
- password?: string;
527
- signedSessionId: string;
528
- }): Promise<void>;
529
- /**
530
- * Validates that the provided password matches the existing encryption for
531
- * a password-encrypted wallet. Must be called before refresh/reshare ceremonies.
532
- * Throws if the wallet is password-encrypted but no password (or wrong password) is provided.
533
- */
534
- protected validatePasswordForExistingWallet({ accountAddress, password, signedSessionId, }: {
535
- accountAddress: string;
536
- password?: string;
537
- signedSessionId: string;
538
- }): Promise<void>;
539
- /**
540
- * Helper function to get Google OAuth Account ID or throw an error if not found.
541
- * @param accountAddress - The account address for logging purposes
542
- * @returns The Google OAuth Account ID
543
- * @throws Error if no Google OAuth account ID is found
544
- */
545
- private getGoogleOauthAccountIdOrThrow;
546
- /**
547
- * Helper function to determine keyshare recovery strategy for dynamic shares.
548
- * For REFRESH operations, retrieves enough shares to meet the client threshold.
549
- * For all other operations, retrieves just 1 share.
550
- *
551
- * @param clientKeyShareBackupInfo - Information about backed up key shares
552
- * @param thresholdSignatureScheme - The signature scheme being used (2-of-2, 2-of-3, etc)
553
- * @param walletOperation - The operation being performed (REFRESH, SIGN_MESSAGE, etc)
554
- * @param shareCount - The number of shares to recover if specified for reshare operations
555
- * @returns @shares: Object mapping backup locations to arrays of share IDs to recover
556
- * @returns @requiredShareCount: The number of shares required to recover
557
- */
558
- recoverStrategy({ clientKeyShareBackupInfo, thresholdSignatureScheme, walletOperation, shareCount, }: {
559
- clientKeyShareBackupInfo: KeyShareBackupInfo;
560
- thresholdSignatureScheme: ThresholdSignatureScheme;
561
- walletOperation: WalletOperation;
562
- shareCount?: number;
563
- }): {
564
- shares: Partial<Record<BackupLocation, string[]>>;
565
- requiredShareCount: number;
566
- };
567
- recoverEncryptedBackupByWallet({ accountAddress, password, walletOperation, signedSessionId, shareCount, storeRecoveredShares, mfaToken, }: {
568
- accountAddress: string;
569
- password?: string;
570
- walletOperation: WalletOperation;
571
- signedSessionId: string;
572
- shareCount?: number;
573
- storeRecoveredShares?: boolean;
574
- mfaToken?: string;
575
- }): Promise<ClientKeyShare[]>;
576
- private internalRecoverEncryptedBackupByWallet;
577
- restoreWallets(): Promise<void>;
578
- /**
579
- * Internal helper method that handles the complete flow for ensuring wallet key shares are backed up to a cloud provider.
580
- * - For 2-of-2 wallets: Automatically reshares to 2-of-3 threshold, then distributes shares (1 to backend, 1 to cloud)
581
- * - For 2-of-3 wallets: Call storeEncryptedBackupByWallet to backup for backend and cloud
582
- */
583
- private backupKeySharesToCloudProvider;
584
- /**
585
- * This method handles the complete flow for ensuring wallet key shares are backed up to Google Drive:
586
- * - For 2-of-2 wallets: Automatically reshares to 2-of-3 threshold, then distributes shares (1 to backend, 1 to Google Drive)
587
- * - For 2-of-3 wallets: Call storeEncryptedBackupByWallet to backup for backend and Google Drive
588
- *
589
- * @param params - The backup parameters
590
- * @param params.accountAddress - The wallet account address to backup
591
- * @param params.password - Optional password for encryption (uses environment ID if not provided)
592
- * @param params.signedSessionId - Optional signed session ID for authentication
593
- */
594
- backupKeySharesToGoogleDrive({ accountAddress, password, signedSessionId, }: {
595
- accountAddress: string;
596
- password?: string;
597
- signedSessionId: string;
598
- }): Promise<void>;
599
- /**
600
- * This method handles the complete flow for ensuring wallet key shares are backed up to iCloud:
601
- * - For 2-of-2 wallets: Automatically reshares to 2-of-3 threshold, then distributes shares (1 to backend, 1 to iCloud)
602
- * - For 2-of-3 wallets: Call storeEncryptedBackupByWallet to backup for backend and iCloud
603
- *
604
- * @param params - The backup parameters
605
- * @param params.accountAddress - The wallet account address to backup
606
- * @param params.password - Optional password for encryption (uses environment ID if not provided)
607
- * @param params.signedSessionId - Optional signed session ID for authentication
608
- */
609
- backupKeySharesToICloud({ accountAddress, password, signedSessionId, }: {
610
- accountAddress: string;
611
- password?: string;
612
- signedSessionId: string;
613
- }): Promise<void>;
614
- /**
615
- * Generic router method that uploads encrypted key shares to the specified cloud provider
616
- * @param provider - The cloud backup provider (GOOGLE_DRIVE, ICLOUD, etc.)
617
- * @param accountAddress - Wallet account address
618
- * @param encryptedKeyShares - Already encrypted key shares to upload
619
- * @returns Promise<void>
620
- */
621
- private uploadToCloudProvider;
622
- /**
623
- * This method handles only the Google Drive upload mechanics without any reshare logic.
624
- * It encrypts the provided key shares, uploads them to Google Drive, and updates the
625
- * backup metadata. This method is intended for internal use by storeEncryptedBackupByWallet
626
- * and should not be called directly from external code.
627
- *
628
- * @param params - The upload parameters
629
- * @param params.accountAddress - The wallet account address
630
- * @param params.password - Optional password for encryption (uses environment ID if not provided)
631
- * @param params.encryptedKeyShares - The specific key shares to upload to Google Drive
632
- * @returns Promise<string[]> - Array of Google Drive key share IDs that were uploaded
633
- */
634
- private uploadKeySharesToGoogleDrive;
635
- /**
636
- * Private method that handles only the iCloud upload mechanics without any reshare logic.
637
- * It takes already encrypted key shares and uploads them to iCloud.
638
- * @param accountAddress - The wallet account address
639
- * @param encryptedKeyShares - Already encrypted key shares to upload
640
- * @returns Promise<void>
641
- */
642
- private uploadKeySharesToICloud;
643
- exportClientKeysharesFromGoogleDrive({ accountAddress, password, signedSessionId, }: {
644
- accountAddress: string;
645
- password?: string;
646
- signedSessionId: string;
647
- }): Promise<void>;
648
- exportClientKeyshares({ accountAddress, password, signedSessionId, }: {
649
- accountAddress: string;
650
- password?: string;
651
- signedSessionId: string;
652
- }): Promise<void>;
653
- getClientKeyShares({ accountAddress, password, signedSessionId, }: {
654
- accountAddress: string;
655
- password?: string;
656
- signedSessionId: string;
657
- }): Promise<ClientKeyShare[]>;
658
- /**
659
- * Helper function to check if the required wallet fields are present and valid
660
- * @param accountAddress - The account address of the wallet to check
661
- * @param walletOperation - The wallet operation that determines required fields
662
- * @returns boolean indicating if wallet needs to be re-fetched and restored from server
663
- */
664
- private checkWalletFields;
665
- /**
666
- * verifyPassword attempts to recover and decrypt a single client key share using the provided password.
667
- * If successful, the key share is encrypted with the new password. This method solely performs the recovery
668
- * and decryption without storing the restored key shares. If unsuccessful, it throws an error.
669
- */
670
- verifyPassword({ accountAddress, password, signedSessionId, }: {
671
- accountAddress: string;
672
- password?: string;
673
- signedSessionId: string;
674
- }): Promise<void>;
675
- isPasswordEncrypted({ accountAddress }: {
676
- accountAddress: string;
677
- }): Promise<boolean>;
678
- /**
679
- * check if the operation requires a password
680
- */
681
- requiresPasswordForOperation({ accountAddress, walletOperation, }: {
682
- accountAddress: string;
683
- walletOperation?: WalletOperation;
684
- }): Promise<boolean>;
685
- /**
686
- * check if the operation requires restoring backup shares
687
- */
688
- requiresRestoreBackupSharesForOperation({ accountAddress, walletOperation, }: {
689
- accountAddress: string;
690
- walletOperation?: WalletOperation;
691
- }): Promise<boolean>;
692
- getWalletClientKeyShareBackupInfo({ accountAddress }: {
693
- accountAddress: string;
694
- }): Promise<KeyShareBackupInfo>;
695
- getWallet({ accountAddress, walletOperation, shareCount, password, signedSessionId, }: {
696
- accountAddress: string;
697
- walletOperation?: WalletOperation;
698
- shareCount?: number;
699
- password?: string;
700
- signedSessionId: string;
701
- }): Promise<WalletProperties>;
702
- /**
703
- * Gets the recovery state of a wallet, optionally recovering shares if not available.
704
- * This method is useful for detecting if a wallet is password-encrypted
705
- * and needs unlocking before use.
706
- *
707
- * If shares are not available locally and recovery parameters are provided,
708
- * this method will call getWallet with RECOVER operation to fetch shares.
709
- * The underlying recoverEncryptedBackupByWallet handles deduplication via
710
- * inFlightRecovery, so concurrent calls won't start multiple recoveries.
711
- *
712
- * @param accountAddress - The account address of the wallet
713
- * @param signedSessionId - Optional signed session ID for triggering recovery if shares not available
714
- * @param password - Optional password for decrypting recovered shares
715
- * @returns WalletRecoveryState indicating the wallet's lock state and share availability
716
- * @throws Error if recovery fails or no shares available after recovery
717
- */
718
- getWalletRecoveryState({ accountAddress, signedSessionId, password, }: {
719
- accountAddress: string;
720
- signedSessionId?: string;
721
- password?: string;
722
- }): Promise<WalletRecoveryState>;
723
- /**
724
- * Unlocks a password-encrypted wallet by decrypting cached encrypted shares.
725
- * This method should be called after getWalletRecoveryState returns LOCKED state.
726
- *
727
- * @param accountAddress - The account address of the wallet
728
- * @param password - The password to decrypt the shares
729
- * @param signedSessionId - The signed session ID for authentication
730
- * @returns The unlocked wallet properties
731
- */
732
- unlockWallet({ accountAddress, password, signedSessionId, }: {
733
- accountAddress: string;
734
- password: string;
735
- signedSessionId: string;
736
- }): Promise<WalletProperties>;
737
- /**
738
- * Decrypts cached encrypted key shares for a wallet and stores them locally.
739
- */
740
- private decryptAndStoreWalletShares;
741
- getAllWallets(): Promise<GetWalletResponse[]>;
742
- getWallets(): Promise<any>;
743
- /**
744
- * sync auth token with api client
745
- * @param authToken - auth token to sync
746
- */
747
- syncAuthToken(authToken: string): void;
748
- createRooms({ roomType, thresholdSignatureScheme, roomCount, }: {
749
- roomType: RoomTypeEnum;
750
- thresholdSignatureScheme: ThresholdSignatureScheme;
751
- roomCount?: number;
752
- }): Promise<void>;
753
- restoreRooms(): Promise<Record<number, Room[]>>;
754
- getRooms(roomType?: RoomTypeEnum, thresholdSignatureScheme?: ThresholdSignatureScheme): Promise<Room[] | Record<number, Room[]>>;
755
- setRooms(numberOfParties: number, rooms: Room[]): Promise<void>;
756
- /**
757
- * Chain localStorage writes sequentially so each write serializes the latest
758
- * in-memory state at execution time, preventing earlier stale snapshots from
759
- * overwriting fresher data when concurrent setRooms calls race.
760
- */
761
- private persistRooms;
762
- getNumberOfParties(roomType: RoomTypeEnum, thresholdSignatureScheme: ThresholdSignatureScheme): number;
763
- getRoom(roomType: RoomTypeEnum, thresholdSignatureScheme: ThresholdSignatureScheme): Promise<Room | undefined>;
764
- getTraceContext(traceContext?: TraceContext): TraceContext & {
765
- now: number;
766
- time: number;
767
- };
768
- }
769
- export {};
770
- //# sourceMappingURL=client.d.ts.map