@dynamic-labs-wallet/browser 0.0.320 → 0.0.322

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/index.cjs.js CHANGED
@@ -1721,6 +1721,17 @@ const readEnvironmentSettings = ()=>{
1721
1721
  const ENCRYPTED_SHARES_PENDING_SUFFIX = `${core.ENCRYPTED_SHARES_STORAGE_SUFFIX}-pending`;
1722
1722
  class DynamicWalletClient {
1723
1723
  /**
1724
+ * Resolves the signed session ID from an explicit value or falls back to the callback.
1725
+ * Throws if neither source provides a value.
1726
+ */ async resolveSignedSessionId(signedSessionId) {
1727
+ const resolved = signedSessionId != null ? signedSessionId : await (this.getSignedSessionIdCallback == null ? void 0 : this.getSignedSessionIdCallback.call(this));
1728
+ if (!resolved) {
1729
+ const errorMsg = signedSessionId === undefined && this.getSignedSessionIdCallback ? 'signedSessionId callback returned an invalid value' : 'signedSessionId is required for backup but was not provided and no callback is configured';
1730
+ throw new Error(errorMsg);
1731
+ }
1732
+ return resolved;
1733
+ }
1734
+ /**
1724
1735
  * Check if wallet has heavy operations in progress
1725
1736
  */ static isHeavyOpInProgress(accountAddress) {
1726
1737
  return WalletQueueManager.isHeavyOpInProgress(accountAddress);
@@ -3560,6 +3571,8 @@ class DynamicWalletClient {
3560
3571
  const dynamicRequestId = uuid.v4();
3561
3572
  try {
3562
3573
  var _backupData_locationsWithKeyShares;
3574
+ // Resolve signed session ID lazily once, so all downstream calls receive a string.
3575
+ const resolvedSignedSessionId = await this.resolveSignedSessionId(signedSessionId);
3563
3576
  const walletData = this.getWalletFromMap(accountAddress);
3564
3577
  if (!(walletData == null ? void 0 : walletData.walletId)) {
3565
3578
  const error = new Error(`WalletId not found for accountAddress ${accountAddress}`);
@@ -3611,7 +3624,7 @@ class DynamicWalletClient {
3611
3624
  walletId: walletData.walletId,
3612
3625
  clientShares: distribution.clientShares,
3613
3626
  password,
3614
- signedSessionId,
3627
+ signedSessionId: resolvedSignedSessionId,
3615
3628
  dynamicRequestId,
3616
3629
  chainName: walletData.chainName,
3617
3630
  bitcoinConfig,
@@ -3641,7 +3654,7 @@ class DynamicWalletClient {
3641
3654
  uploadPromises.push(retryPromise(()=>this.publishDelegatedShare({
3642
3655
  walletId: walletData.walletId,
3643
3656
  delegatedShare: distribution.delegatedShare,
3644
- signedSessionId,
3657
+ signedSessionId: resolvedSignedSessionId,
3645
3658
  dynamicRequestId,
3646
3659
  chainName: walletData.chainName,
3647
3660
  bitcoinConfig,
@@ -4646,7 +4659,10 @@ class DynamicWalletClient {
4646
4659
  }
4647
4660
  // Get backup info from server
4648
4661
  const user = await this.apiClient.getUser(dynamicRequestId);
4649
- const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
4662
+ const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>{
4663
+ var _vc_address;
4664
+ return ((_vc_address = vc.address) == null ? void 0 : _vc_address.toLowerCase()) === accountAddress.toLowerCase();
4665
+ });
4650
4666
  return getClientKeyShareBackupInfo({
4651
4667
  walletProperties: wallet == null ? void 0 : wallet.walletProperties
4652
4668
  });
@@ -5174,6 +5190,7 @@ class DynamicWalletClient {
5174
5190
  return roomType === sdkApiCore.RoomTypeEnum.Threshold ? MPC_SCHEME_CONFIG.threshold : MPC_SCHEME_CONFIG.numberOfParties;
5175
5191
  }
5176
5192
  async getRoom(roomType, thresholdSignatureScheme) {
5193
+ var _DynamicWalletClient_rooms_numberOfParties;
5177
5194
  const numberOfParties = this.getNumberOfParties(roomType, thresholdSignatureScheme);
5178
5195
  const consume = async ()=>{
5179
5196
  // Re-read from localStorage rather than the in-memory static so we see rooms
@@ -5198,7 +5215,17 @@ class DynamicWalletClient {
5198
5215
  // Use the Web Locks API for cross-tab mutual exclusion so that two tabs
5199
5216
  // cannot both consume the same cached room. Falls back to a direct call in
5200
5217
  // environments where navigator.locks is unavailable (e.g. Node.js tests).
5201
- const room = typeof navigator !== 'undefined' && navigator.locks ? await navigator.locks.request(`${this.storageKey}-room-cache`, consume) : await consume();
5218
+ const webLocksAvailable = typeof navigator !== 'undefined' && !!navigator.locks;
5219
+ const room = webLocksAvailable ? await navigator.locks.request(`${this.storageKey}-room-cache`, consume) : await consume();
5220
+ var _DynamicWalletClient_rooms_numberOfParties_length;
5221
+ this.logger.info('[DynamicWaasWalletClient] getRoom result', {
5222
+ key: 'roomCache',
5223
+ operation: 'getRoom',
5224
+ numberOfParties,
5225
+ roomId: room == null ? void 0 : room.roomId,
5226
+ remainingInMemory: (_DynamicWalletClient_rooms_numberOfParties_length = (_DynamicWalletClient_rooms_numberOfParties = DynamicWalletClient.rooms[numberOfParties]) == null ? void 0 : _DynamicWalletClient_rooms_numberOfParties.length) != null ? _DynamicWalletClient_rooms_numberOfParties_length : 0,
5227
+ webLocksAvailable
5228
+ });
5202
5229
  // If less than or only 1 room left after removing one, trigger async creation for more rooms.
5203
5230
  const remainingRooms = DynamicWalletClient.rooms[numberOfParties] || [];
5204
5231
  if (remainingRooms.length <= 1) {
@@ -5240,6 +5267,10 @@ class DynamicWalletClient {
5240
5267
  if (internalOptions == null ? void 0 : internalOptions.secureStorage) {
5241
5268
  this.secureStorage = internalOptions.secureStorage;
5242
5269
  }
5270
+ // Set signed session ID callback if provided (internal use only)
5271
+ if (internalOptions == null ? void 0 : internalOptions.getSignedSessionId) {
5272
+ this.getSignedSessionIdCallback = internalOptions.getSignedSessionId;
5273
+ }
5243
5274
  this.apiClient = new core.DynamicApiClient({
5244
5275
  environmentId,
5245
5276
  authToken,
package/index.esm.js CHANGED
@@ -1722,6 +1722,17 @@ const readEnvironmentSettings = ()=>{
1722
1722
  const ENCRYPTED_SHARES_PENDING_SUFFIX = `${ENCRYPTED_SHARES_STORAGE_SUFFIX}-pending`;
1723
1723
  class DynamicWalletClient {
1724
1724
  /**
1725
+ * Resolves the signed session ID from an explicit value or falls back to the callback.
1726
+ * Throws if neither source provides a value.
1727
+ */ async resolveSignedSessionId(signedSessionId) {
1728
+ const resolved = signedSessionId != null ? signedSessionId : await (this.getSignedSessionIdCallback == null ? void 0 : this.getSignedSessionIdCallback.call(this));
1729
+ if (!resolved) {
1730
+ const errorMsg = signedSessionId === undefined && this.getSignedSessionIdCallback ? 'signedSessionId callback returned an invalid value' : 'signedSessionId is required for backup but was not provided and no callback is configured';
1731
+ throw new Error(errorMsg);
1732
+ }
1733
+ return resolved;
1734
+ }
1735
+ /**
1725
1736
  * Check if wallet has heavy operations in progress
1726
1737
  */ static isHeavyOpInProgress(accountAddress) {
1727
1738
  return WalletQueueManager.isHeavyOpInProgress(accountAddress);
@@ -3561,6 +3572,8 @@ class DynamicWalletClient {
3561
3572
  const dynamicRequestId = v4();
3562
3573
  try {
3563
3574
  var _backupData_locationsWithKeyShares;
3575
+ // Resolve signed session ID lazily once, so all downstream calls receive a string.
3576
+ const resolvedSignedSessionId = await this.resolveSignedSessionId(signedSessionId);
3564
3577
  const walletData = this.getWalletFromMap(accountAddress);
3565
3578
  if (!(walletData == null ? void 0 : walletData.walletId)) {
3566
3579
  const error = new Error(`WalletId not found for accountAddress ${accountAddress}`);
@@ -3612,7 +3625,7 @@ class DynamicWalletClient {
3612
3625
  walletId: walletData.walletId,
3613
3626
  clientShares: distribution.clientShares,
3614
3627
  password,
3615
- signedSessionId,
3628
+ signedSessionId: resolvedSignedSessionId,
3616
3629
  dynamicRequestId,
3617
3630
  chainName: walletData.chainName,
3618
3631
  bitcoinConfig,
@@ -3642,7 +3655,7 @@ class DynamicWalletClient {
3642
3655
  uploadPromises.push(retryPromise(()=>this.publishDelegatedShare({
3643
3656
  walletId: walletData.walletId,
3644
3657
  delegatedShare: distribution.delegatedShare,
3645
- signedSessionId,
3658
+ signedSessionId: resolvedSignedSessionId,
3646
3659
  dynamicRequestId,
3647
3660
  chainName: walletData.chainName,
3648
3661
  bitcoinConfig,
@@ -4647,7 +4660,10 @@ class DynamicWalletClient {
4647
4660
  }
4648
4661
  // Get backup info from server
4649
4662
  const user = await this.apiClient.getUser(dynamicRequestId);
4650
- const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
4663
+ const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>{
4664
+ var _vc_address;
4665
+ return ((_vc_address = vc.address) == null ? void 0 : _vc_address.toLowerCase()) === accountAddress.toLowerCase();
4666
+ });
4651
4667
  return getClientKeyShareBackupInfo({
4652
4668
  walletProperties: wallet == null ? void 0 : wallet.walletProperties
4653
4669
  });
@@ -5175,6 +5191,7 @@ class DynamicWalletClient {
5175
5191
  return roomType === RoomTypeEnum.Threshold ? MPC_SCHEME_CONFIG.threshold : MPC_SCHEME_CONFIG.numberOfParties;
5176
5192
  }
5177
5193
  async getRoom(roomType, thresholdSignatureScheme) {
5194
+ var _DynamicWalletClient_rooms_numberOfParties;
5178
5195
  const numberOfParties = this.getNumberOfParties(roomType, thresholdSignatureScheme);
5179
5196
  const consume = async ()=>{
5180
5197
  // Re-read from localStorage rather than the in-memory static so we see rooms
@@ -5199,7 +5216,17 @@ class DynamicWalletClient {
5199
5216
  // Use the Web Locks API for cross-tab mutual exclusion so that two tabs
5200
5217
  // cannot both consume the same cached room. Falls back to a direct call in
5201
5218
  // environments where navigator.locks is unavailable (e.g. Node.js tests).
5202
- const room = typeof navigator !== 'undefined' && navigator.locks ? await navigator.locks.request(`${this.storageKey}-room-cache`, consume) : await consume();
5219
+ const webLocksAvailable = typeof navigator !== 'undefined' && !!navigator.locks;
5220
+ const room = webLocksAvailable ? await navigator.locks.request(`${this.storageKey}-room-cache`, consume) : await consume();
5221
+ var _DynamicWalletClient_rooms_numberOfParties_length;
5222
+ this.logger.info('[DynamicWaasWalletClient] getRoom result', {
5223
+ key: 'roomCache',
5224
+ operation: 'getRoom',
5225
+ numberOfParties,
5226
+ roomId: room == null ? void 0 : room.roomId,
5227
+ remainingInMemory: (_DynamicWalletClient_rooms_numberOfParties_length = (_DynamicWalletClient_rooms_numberOfParties = DynamicWalletClient.rooms[numberOfParties]) == null ? void 0 : _DynamicWalletClient_rooms_numberOfParties.length) != null ? _DynamicWalletClient_rooms_numberOfParties_length : 0,
5228
+ webLocksAvailable
5229
+ });
5203
5230
  // If less than or only 1 room left after removing one, trigger async creation for more rooms.
5204
5231
  const remainingRooms = DynamicWalletClient.rooms[numberOfParties] || [];
5205
5232
  if (remainingRooms.length <= 1) {
@@ -5241,6 +5268,10 @@ class DynamicWalletClient {
5241
5268
  if (internalOptions == null ? void 0 : internalOptions.secureStorage) {
5242
5269
  this.secureStorage = internalOptions.secureStorage;
5243
5270
  }
5271
+ // Set signed session ID callback if provided (internal use only)
5272
+ if (internalOptions == null ? void 0 : internalOptions.getSignedSessionId) {
5273
+ this.getSignedSessionIdCallback = internalOptions.getSignedSessionId;
5274
+ }
5244
5275
  this.apiClient = new DynamicApiClient({
5245
5276
  environmentId,
5246
5277
  authToken,
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/browser",
3
- "version": "0.0.320",
3
+ "version": "0.0.322",
4
4
  "license": "Licensed under the Dynamic Labs, Inc. Terms Of Service (https://www.dynamic.xyz/terms-conditions)",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/core": "0.0.320",
7
+ "@dynamic-labs-wallet/core": "0.0.322",
8
8
  "@dynamic-labs/sdk-api-core": "^0.0.900",
9
9
  "argon2id": "1.0.1",
10
10
  "axios": "1.13.5",