wallaby-cash 2.2.3 → 2.2.5

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/dist/base.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare abstract class Base {
16
16
  protected api: GeneratedApiClient<any>;
17
17
  constructor(config: WallabyConfig);
18
18
  set setClientAuthToken(token: string);
19
+ get version(): string;
19
20
  private _initializeClientAuthToken;
20
21
  /**
21
22
  * This library uses `localStorage` as the default storage.
package/dist/index.cjs.js CHANGED
@@ -325,6 +325,8 @@ exports.V2KeyNames = void 0;
325
325
  V2KeyNames["PasskeyCredential"] = "pass-key-credential";
326
326
  V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
327
327
  V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
328
+ V2KeyNames["MigrationVersion"] = "wsdk_migrated_with_version";
329
+ V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
328
330
  })(exports.V2KeyNames || (exports.V2KeyNames = {}));
329
331
 
330
332
  exports.ErrorResponseCodes = void 0;
@@ -377,6 +379,7 @@ exports.ErrorResponseCodes = void 0;
377
379
  ErrorResponseCodes["sdk_jwt_invalid"] = "sdk_jwt_invalid";
378
380
  ErrorResponseCodes["sdk_jwt_expired"] = "sdk_jwt_expired";
379
381
  ErrorResponseCodes["sdk_unknown_error"] = "sdk_unknown_error";
382
+ ErrorResponseCodes["sdk_too_many_requests"] = "sdk_too_many_requests";
380
383
  ErrorResponseCodes["sdk_seed_phrase_decryption_failed"] = "sdk_seed_phrase_decryption_failed";
381
384
  ErrorResponseCodes["sdk_key_shares_not_found"] = "sdk_key_shares_not_found";
382
385
  ErrorResponseCodes["sdk_key_share_decryption_failed"] = "sdk_key_share_decryption_failed";
@@ -799,6 +802,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
799
802
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.RS256 },
800
803
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
801
804
  ];
805
+ const currentPackageVersion = "2.2.5";
802
806
 
803
807
  const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
804
808
 
@@ -4847,7 +4851,7 @@ class Cipher {
4847
4851
  * @param {string} deviceKeyPair - The public key to encrypt the data with.
4848
4852
  * @returns {Promise<Encrypted>} The encrypted data ready for storage.
4849
4853
  */
4850
- async prepareDecryptedDataForStorage({ decryptedData, credentialsKeyPair, deviceKeyPair, }) {
4854
+ async doubleEncrypt({ decryptedData, credentialsKeyPair, deviceKeyPair, }) {
4851
4855
  try {
4852
4856
  // First layer of encryption using the device public key
4853
4857
  const encryptedOnceData = await this.encrypt({
@@ -4862,7 +4866,7 @@ class Cipher {
4862
4866
  return encryptedTwiceData;
4863
4867
  }
4864
4868
  catch (error) {
4865
- logger.error('SDK::prepareDecryptedDataForStorage::error', error);
4869
+ logger.error('SDK::doubleEncrypt::error', error);
4866
4870
  throw error;
4867
4871
  }
4868
4872
  }
@@ -7064,6 +7068,12 @@ class Base {
7064
7068
  set setClientAuthToken(token) {
7065
7069
  this._initializeClientAuthToken(token);
7066
7070
  }
7071
+ get version() {
7072
+ // const currentVersion = pkg.version;
7073
+ const currentVersion = currentPackageVersion;
7074
+ logger.log(`wsdk is running v${currentVersion}`);
7075
+ return currentVersion;
7076
+ }
7067
7077
  _initializeClientAuthToken(token) {
7068
7078
  if (!jwtHasSameUser(token, this.userId)) {
7069
7079
  throw new WallabyError({
@@ -8759,7 +8769,7 @@ class WalletHandlersService extends Base {
8759
8769
  errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
8760
8770
  data: error,
8761
8771
  cause: error.cause,
8762
- onError: () => console.log('Reported the error'),
8772
+ onError: () => logger.log('Reported the error'),
8763
8773
  });
8764
8774
  }
8765
8775
  }));
@@ -8866,6 +8876,8 @@ class WalletHandlersService extends Base {
8866
8876
  class WalletService extends Base {
8867
8877
  constructor(config) {
8868
8878
  super(config);
8879
+ this.passwordResetAttempts = 0;
8880
+ this.migrationAttempts = 0;
8869
8881
  this.authService = new AuthService(config);
8870
8882
  this.handlers = new WalletHandlersService(config);
8871
8883
  this.userId = config.userId;
@@ -8984,9 +8996,12 @@ class WalletService extends Base {
8984
8996
  });
8985
8997
  }
8986
8998
  catch (error) {
8987
- // If migration fails, log it but don't block the transaction
8988
- // The original transaction logic will handle missing storage items appropriately
8989
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
8999
+ logger.error('SDK::WalletService::export::handleUpdateToV2::error', error);
9000
+ throw new WallabyError({
9001
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9002
+ statusCode: 500,
9003
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9004
+ });
8990
9005
  }
8991
9006
  }
8992
9007
  const encryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId });
@@ -9375,12 +9390,30 @@ class WalletService extends Base {
9375
9390
  */
9376
9391
  async changePassword({ walletId, oldPassword, newPassword, }) {
9377
9392
  try {
9393
+ this.passwordResetAttempts += 1;
9394
+ if (this.passwordResetAttempts > 5) {
9395
+ throw new WallabyError({
9396
+ message: 'Too many password change attempts. Please try again later.',
9397
+ statusCode: 429,
9398
+ errorCode: exports.ErrorResponseCodes.sdk_too_many_requests,
9399
+ });
9400
+ }
9378
9401
  if (this.deviceAuthType === exports.AuthType.Password && oldPassword) {
9379
9402
  // Handle migration to V2 first then change the password to the new one.
9380
- await this.handleUpdateToV2({
9381
- password: oldPassword,
9382
- walletId,
9383
- });
9403
+ try {
9404
+ await this.handleUpdateToV2({
9405
+ password: oldPassword,
9406
+ walletId,
9407
+ });
9408
+ }
9409
+ catch (error) {
9410
+ logger.error('SDK::WalletService::changePassword::handleUpdateToV2::error', error);
9411
+ throw new WallabyError({
9412
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9413
+ statusCode: 500,
9414
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9415
+ });
9416
+ }
9384
9417
  }
9385
9418
  const encryptedDevicePrivateKeyString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedDevicePrivateKey);
9386
9419
  const encryptedSeedPhraseString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedStandardSeedPhrase, {
@@ -9496,9 +9529,12 @@ class WalletService extends Base {
9496
9529
  });
9497
9530
  }
9498
9531
  catch (error) {
9499
- // If migration fails, log it but don't block the transaction
9500
- // The original transaction logic will handle missing storage items appropriately
9501
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
9532
+ logger.error('SDK::WalletService::getAlgorandSeedPhrase::handleUpdateToV2::error', error);
9533
+ throw new WallabyError({
9534
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9535
+ statusCode: 500,
9536
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9537
+ });
9502
9538
  }
9503
9539
  }
9504
9540
  let wallabyBoundSeedPhrase;
@@ -9602,9 +9638,12 @@ class WalletService extends Base {
9602
9638
  });
9603
9639
  }
9604
9640
  catch (error) {
9605
- // If migration fails, log it but don't block the transaction
9606
- // The original transaction logic will handle missing storage items appropriately
9607
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
9641
+ logger.error('SDK::WalletService::initAddNewDevice::handleUpdateToV2::error', error);
9642
+ throw new WallabyError({
9643
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9644
+ statusCode: 500,
9645
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9646
+ });
9608
9647
  }
9609
9648
  }
9610
9649
  const storedEncryptedPrimaryShare = await this.localStorageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare, {
@@ -9767,9 +9806,12 @@ class WalletService extends Base {
9767
9806
  });
9768
9807
  }
9769
9808
  catch (error) {
9770
- // If migration fails, log it but don't block the transaction
9771
- // The original transaction logic will handle missing storage items appropriately
9772
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
9809
+ logger.error('SDK::WalletService::generateWalletAddresses::handleUpdateToV2::error', error);
9810
+ throw new WallabyError({
9811
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9812
+ statusCode: 500,
9813
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9814
+ });
9773
9815
  }
9774
9816
  }
9775
9817
  try {
@@ -9861,19 +9903,15 @@ class WalletService extends Base {
9861
9903
  * decrypt them using appropriate decryption methods, and call wallet.recover() to create new v2 keys.
9862
9904
  */
9863
9905
  async handleUpdateToV2({ password, walletId }) {
9864
- try {
9865
- logger.info('SDK::WalletService::handleUpdateToV2::starting migration check');
9866
- const v2EncryptedDevicePrivateKey = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedDevicePrivateKey);
9867
- const v2EncryptedSeed = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedStandardSeedPhrase, { walletId });
9868
- const v2EncryptedPrimaryDeviceShare = await this.localStorageService.fetch(exports.V2KeyNames.PrimaryDeviceKeyShare, {
9869
- walletId,
9906
+ const migrationStartTime = Date.now();
9907
+ if (this.migrationAttempts > 5) {
9908
+ throw new WallabyError({
9909
+ message: 'Too many migration attempts. Please try again later.',
9910
+ statusCode: 429,
9911
+ errorCode: exports.ErrorResponseCodes.sdk_too_many_requests,
9870
9912
  });
9871
- if (v2EncryptedDevicePrivateKey && (v2EncryptedSeed || v2EncryptedPrimaryDeviceShare)) {
9872
- logger.info('SDK::WalletService::handleUpdateToV2::V2 items already exist, no migration needed');
9873
- // If V2 items are present,
9874
- // we don't need to throw any errors, just continue with rest of flow.
9875
- return;
9876
- }
9913
+ }
9914
+ try {
9877
9915
  if (!password) {
9878
9916
  throw new WallabyError({
9879
9917
  message: 'Password is required for migration to v2',
@@ -9881,24 +9919,90 @@ class WalletService extends Base {
9881
9919
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
9882
9920
  });
9883
9921
  }
9922
+ // Check migration metadata FIRST (lightweight, no network/crypto operations)
9923
+ const currentSdkVersion = this.version;
9924
+ const sdkMigrationVersion = await this.localStorageService.fetch(exports.V2KeyNames.MigrationVersion);
9925
+ const lastMigratedAt = await this.localStorageService.fetch(exports.V2KeyNames.LastMigratedAt);
9926
+ logger.info('SDK::WalletService::handleUpdateToV2::starting migration check', {
9927
+ timestamp: new Date(migrationStartTime).toISOString(),
9928
+ walletId: walletId.substring(0, 8) + '...',
9929
+ lastMigratedAt,
9930
+ currentSdkVersion,
9931
+ sdkMigrationVersion,
9932
+ });
9933
+ // If migration completed successfully before (has a valid timestamp, not 'never')
9934
+ // 'never' indicates a previous failure and allows retry attempts
9935
+ if (lastMigratedAt && lastMigratedAt !== 'never' && sdkMigrationVersion) {
9936
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration already completed successfully, skipping', {
9937
+ migratedVersion: sdkMigrationVersion,
9938
+ migratedAt: lastMigratedAt,
9939
+ });
9940
+ return;
9941
+ }
9942
+ // Migration needed - proceed with V2 existence check and potential migration
9943
+ const v2EncryptedDevicePrivateKey = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedDevicePrivateKey);
9944
+ const v2EncryptedSeed = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedStandardSeedPhrase, { walletId });
9945
+ const v2EncryptedPrimaryDeviceShare = await this.localStorageService.fetch(exports.V2KeyNames.PrimaryDeviceKeyShare, {
9946
+ walletId,
9947
+ });
9884
9948
  const clientSalt = await this.authService.getUserSalt();
9949
+ const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9950
+ authType: exports.AuthType.Password,
9951
+ password,
9952
+ salt: clientSalt,
9953
+ });
9954
+ if (v2EncryptedDevicePrivateKey && (v2EncryptedSeed || v2EncryptedPrimaryDeviceShare)) {
9955
+ try {
9956
+ await this.cipher.decrypt({
9957
+ cipherText: safeJsonParse(v2EncryptedDevicePrivateKey),
9958
+ decryptionKey: credentialsKeyPair.privateKey,
9959
+ });
9960
+ // Explicitly select the non-empty value between seed and primary device share
9961
+ const v2SeedData = v2EncryptedSeed || v2EncryptedPrimaryDeviceShare;
9962
+ await this.cipher.displayStoredData({
9963
+ storedEncryptedData: safeJsonParse(v2SeedData),
9964
+ encryptedDevicePrivateKey: safeJsonParse(v2EncryptedDevicePrivateKey),
9965
+ options: {
9966
+ authType: exports.AuthType.Password,
9967
+ password,
9968
+ salt: clientSalt,
9969
+ },
9970
+ });
9971
+ logger.info('SDK::WalletService::handleUpdateToV2::V2 items already exist and are valid, no migration needed');
9972
+ // V2 exists and is valid - update metadata to avoid future checks
9973
+ await this.localStorageService.save(exports.V2KeyNames.LastMigratedAt, new Date().toISOString());
9974
+ await this.localStorageService.save(exports.V2KeyNames.MigrationVersion, currentSdkVersion);
9975
+ return;
9976
+ }
9977
+ catch (error) {
9978
+ logger.info('SDK::WalletService::handleUpdateToV2::V2 items exist but decryption failed, proceeding with migration', {
9979
+ error: JSON.stringify(error),
9980
+ });
9981
+ }
9982
+ }
9983
+ // Increment counter after V2 validation to avoid counting when migration not needed
9984
+ this.migrationAttempts += 1;
9885
9985
  let decryptedSeedPhrase;
9886
9986
  let decryptedPrivateKey;
9887
9987
  // Check for legacy format: `{item}_{userId}`
9888
9988
  const legacyEncryptedSeed = await this.localStorageService.getFromDeviceStorage(`${exports.LegacyKeyNames.EncryptedSeed}_${this.userId}`);
9889
- const legacyEncryptedPrivateKey = await this.localStorageService.getFromDeviceStorage(`${exports.LegacyKeyNames.EncryptedPrivateKey}_${this.userId}`);
9890
- if (legacyEncryptedSeed && legacyEncryptedPrivateKey) {
9891
- logger.info('SDK::WalletService::handleUpdateToV2::Found legacy storage items, attempting migration');
9989
+ // getDecryptedV1PrivateKey checks for both v1 and legacy formats internally
9990
+ const legacyDecryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
9991
+ if (legacyEncryptedSeed && legacyDecryptedPrivateKey) {
9992
+ const legacyPublicKey = publicKeyByPrivateKey(legacyDecryptedPrivateKey);
9993
+ logger.info('SDK::WalletService::handleUpdateToV2::Found legacy storage items, attempting migration', {
9994
+ storageFormat: 'legacy',
9995
+ devicePublicKey: legacyPublicKey.substring(0, 16) + '...',
9996
+ });
9892
9997
  try {
9893
9998
  // Decrypt legacy items using password/salt combination
9894
- const decryptedLegacyKey = cryptoJs.AES.decrypt(legacyEncryptedPrivateKey, `${clientSalt}${password}`);
9895
9999
  const decryptedOnceSeed = cryptoJs.AES.decrypt(legacyEncryptedSeed, `${clientSalt}${password}`);
9896
- const parsedDecryptedSeed = safeJsonParse(decryptedOnceSeed.toString(cryptoJs.enc.Utf8));
9897
- decryptedPrivateKey = decryptedLegacyKey.toString(cryptoJs.enc.Utf8);
9898
- decryptedSeedPhrase = decryptWithPrivateKey(decryptedPrivateKey, parsedDecryptedSeed);
9899
- if (!decryptedSeedPhrase || !decryptedPrivateKey) {
10000
+ const parsedDecryptedOnceSeed = safeJsonParse(decryptedOnceSeed.toString(cryptoJs.enc.Utf8));
10001
+ decryptedSeedPhrase = decryptWithPrivateKey(legacyDecryptedPrivateKey, parsedDecryptedOnceSeed);
10002
+ decryptedPrivateKey = legacyDecryptedPrivateKey; // Assign the decrypted private key
10003
+ if (!decryptedSeedPhrase) {
9900
10004
  throw new WallabyError({
9901
- message: 'Failed to decrypt legacy items with provided password',
10005
+ message: 'Failed to decrypt legacy seed phrase items with provided password',
9902
10006
  statusCode: 500,
9903
10007
  errorCode: exports.ErrorResponseCodes.sdk_seed_phrase_decryption_failed,
9904
10008
  });
@@ -9920,9 +10024,17 @@ class WalletService extends Base {
9920
10024
  const v1EncryptedSeed = await this.localStorageService.getEncryptedSeedPhrase(exports.SeedPhraseType.Standard, walletId);
9921
10025
  const v1EncryptedPrivateKey = await this.localStorageService.getEncryptedPrivateKey();
9922
10026
  if (v1EncryptedSeed && v1EncryptedPrivateKey) {
9923
- logger.info('SDK::WalletService::handleUpdateToV2::Found V1 storage items, attempting migration');
10027
+ // Get public key before decryption for logging
10028
+ decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
10029
+ const v1PublicKey = decryptedPrivateKey ? publicKeyByPrivateKey(decryptedPrivateKey) : 'unknown';
10030
+ logger.info('SDK::WalletService::handleUpdateToV2::Found V1 storage items, attempting migration', {
10031
+ storageFormat: 'v1',
10032
+ devicePublicKey: v1PublicKey.substring(0, 16) + '...',
10033
+ });
9924
10034
  try {
9925
10035
  // Decrypt V1 items using storage service method (handles double encryption)
10036
+ logger.log('Attempting to decrypt V1 items during migration...');
10037
+ logger.log('getV1DecryptedSeedPhrase should be called with password and clientSalt:', { password, clientSalt });
9926
10038
  decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(password, clientSalt);
9927
10039
  // For V1 format, private key is encrypted with just the password (not salt+password like legacy)
9928
10040
  decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
@@ -9950,44 +10062,72 @@ class WalletService extends Base {
9950
10062
  return;
9951
10063
  }
9952
10064
  }
9953
- if (decryptedSeedPhrase) {
10065
+ if (decryptedSeedPhrase && decryptedPrivateKey) {
9954
10066
  logger.info('SDK::WalletService::handleUpdateToV2::Initiating wallet recovery for V2 migration');
9955
10067
  logger.info('SDK::WalletService::handleUpdateToV2::Migration data prepared');
9956
10068
  logger.info('SDK::WalletService::handleUpdateToV2::Seed phrase available:', !!decryptedSeedPhrase);
9957
10069
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9958
- // We'll create a temporary device keypair just for authentication, then let recover() create the final one
9959
- const tempDeviceKeyPair = createIdentity();
9960
- const tempSignatureMessage = await this.authService.getSignature({
9961
- publicKey: tempDeviceKeyPair.publicKey,
9962
- privateKey: tempDeviceKeyPair.privateKey,
10070
+ const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
10071
+ const signInSignatureMessage = await this.authService.getSignature({
10072
+ publicKey: devicePublicKey,
10073
+ privateKey: decryptedPrivateKey,
9963
10074
  });
10075
+ // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9964
10076
  const authResponse = await this.request(AuthRoutes.signIn, {
9965
10077
  payload: {
9966
10078
  externalUserId: this.userId,
9967
- message: tempSignatureMessage.message,
9968
- signature: tempSignatureMessage.signature,
9969
- clientAuthPubKey: tempDeviceKeyPair.publicKey,
10079
+ message: signInSignatureMessage.message,
10080
+ signature: signInSignatureMessage.signature,
10081
+ clientAuthPubKey: devicePublicKey,
10082
+ },
10083
+ });
10084
+ const encryptedV2PrivateKey = await this.cipher.encrypt({
10085
+ data: decryptedPrivateKey,
10086
+ encryptionKey: credentialsKeyPair.publicKey,
10087
+ });
10088
+ const encryptedV2Seed = await this.cipher.doubleEncrypt({
10089
+ decryptedData: decryptedSeedPhrase,
10090
+ credentialsKeyPair,
10091
+ deviceKeyPair: {
10092
+ publicKey: devicePublicKey,
10093
+ privateKey: decryptedPrivateKey,
9970
10094
  },
9971
10095
  });
9972
10096
  // Store authentication tokens
9973
10097
  await this.localStorageService.saveInBulk([
9974
10098
  { key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
9975
10099
  { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
10100
+ { key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
10101
+ { key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9976
10102
  ]);
9977
- await this.recover({
9978
- authenticationOptions: Object.assign(Object.assign({}, authResponse), { signatureMessageResponse: tempSignatureMessage, password,
9979
- clientSalt }),
9980
- walletId,
9981
- seedPhrase: decryptedSeedPhrase,
9982
- storeSeedPhrase: true,
9983
- returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedSeedPhrase,
10103
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration completed successfully', {
10104
+ timestamp: new Date().toISOString(),
10105
+ duration: Date.now() - migrationStartTime,
10106
+ devicePublicKey: devicePublicKey.substring(0, 16) + '...',
10107
+ migratedKeys: ['EncryptedDevicePrivateKey', 'EncryptedStandardSeedPhrase'],
9984
10108
  });
9985
- logger.info('SDK::WalletService::handleUpdateToV2::Migration completed successfully');
10109
+ await this.localStorageService.save(exports.V2KeyNames.LastMigratedAt, new Date().toISOString());
10110
+ await this.localStorageService.save(exports.V2KeyNames.MigrationVersion, this.version);
9986
10111
  return;
9987
10112
  }
10113
+ else {
10114
+ throw new WallabyError({
10115
+ message: 'Decrypted data required for migration is missing, operation cannot be completed.',
10116
+ statusCode: 500,
10117
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
10118
+ });
10119
+ }
9988
10120
  }
9989
10121
  catch (error) {
9990
- logger.error('SDK::WalletService::handleUpdateToV2::Migration failed', error);
10122
+ logger.error('SDK::WalletService::handleUpdateToV2::Migration failed', {
10123
+ timestamp: new Date().toISOString(),
10124
+ duration: Date.now() - migrationStartTime,
10125
+ error: error instanceof Error ? error.message : 'Unknown error',
10126
+ });
10127
+ // Save 'never' to indicate failure, which still allows retries (checked in early return)
10128
+ // Rate limiting prevents infinite retry attempts
10129
+ await this.localStorageService.save(exports.V2KeyNames.LastMigratedAt, 'never');
10130
+ await this.localStorageService.save(exports.V2KeyNames.MigrationVersion, this.version);
9991
10131
  throw error;
9992
10132
  }
9993
10133
  }
@@ -10004,15 +10144,6 @@ class WalletService extends Base {
10004
10144
  try {
10005
10145
  const { readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares, signatureMessage, deviceAuthPublicKey } = await this.prepareWalletOperationAuth({ authenticationOptions: input.authenticationOptions, walletId: input.walletId });
10006
10146
  const shouldSendSeedPhrase = readyForTransportSeedPhrase && !hasShares;
10007
- // const accessVerificationResponse = await this.request<{ isAccessVerified: boolean }>(WalletRoutes.verifyAccess, {
10008
- // payload: {
10009
- // ...signatureMessage,
10010
- // clientAuthPubKey: deviceAuthPublicKey,
10011
- // encryptedSeed: shouldSendSeedPhrase ? readyForTransportSeedPhrase : undefined,
10012
- // encryptedShares: !shouldSendSeedPhrase ? sharesEncryptedWithWallabyPubKey : undefined,
10013
- // walletId: input.walletId,
10014
- // },
10015
- // });
10016
10147
  const accessVerificationResponse = await this.api.wallets.verifyAccess({
10017
10148
  message: signatureMessage.message,
10018
10149
  signature: signatureMessage.signature,
@@ -10252,6 +10383,12 @@ __decorate([
10252
10383
  __metadata("design:paramtypes", [Object]),
10253
10384
  __metadata("design:returntype", Promise)
10254
10385
  ], WalletService.prototype, "changePassword", null);
10386
+ __decorate([
10387
+ WithLock('migrateToV2'),
10388
+ __metadata("design:type", Function),
10389
+ __metadata("design:paramtypes", [Object]),
10390
+ __metadata("design:returntype", Promise)
10391
+ ], WalletService.prototype, "handleUpdateToV2", null);
10255
10392
 
10256
10393
  class WalletDataService extends Base {
10257
10394
  constructor(config) {
@@ -10479,10 +10616,20 @@ class WalletDataService extends Base {
10479
10616
  });
10480
10617
  }
10481
10618
  if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
10482
- await this.walletService.handleUpdateToV2({
10483
- password: authenticationOptions.password,
10484
- walletId: walletId,
10485
- });
10619
+ try {
10620
+ await this.walletService.handleUpdateToV2({
10621
+ password: authenticationOptions.password,
10622
+ walletId: walletId,
10623
+ });
10624
+ }
10625
+ catch (error) {
10626
+ logger.error('SDK::WalletDataService::addNewChainAndTokenToWallet::handleUpdateToV2::error', error);
10627
+ throw new WallabyError({
10628
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
10629
+ statusCode: 500,
10630
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
10631
+ });
10632
+ }
10486
10633
  }
10487
10634
  try {
10488
10635
  const addressInfo = await this.walletService.generateWalletAddresses({
@@ -11166,9 +11313,12 @@ class Transactions extends Base {
11166
11313
  });
11167
11314
  }
11168
11315
  catch (error) {
11169
- // If migration fails, log it but don't block the transaction
11170
- // The original transaction logic will handle missing storage items appropriately
11171
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
11316
+ logger.error('SDK::Transactions::transfer::handleUpdateToV2::error', error);
11317
+ throw new WallabyError({
11318
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
11319
+ statusCode: 500,
11320
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
11321
+ });
11172
11322
  }
11173
11323
  }
11174
11324
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11243,9 +11393,12 @@ class Transactions extends Base {
11243
11393
  });
11244
11394
  }
11245
11395
  catch (error) {
11246
- // If migration fails, log it but don't block the transaction
11247
- // The original transaction logic will handle missing storage items appropriately
11248
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
11396
+ logger.error('SDK::Transactions::createAllowance::handleUpdateToV2::error', error);
11397
+ throw new WallabyError({
11398
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
11399
+ statusCode: 500,
11400
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
11401
+ });
11249
11402
  }
11250
11403
  }
11251
11404
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11318,9 +11471,12 @@ class Transactions extends Base {
11318
11471
  });
11319
11472
  }
11320
11473
  catch (error) {
11321
- // If migration fails, log it but don't block the transaction
11322
- // The original transaction logic will handle missing storage items appropriately
11323
- logger.debug('Migration to V2 failed, continuing with original flow:', error);
11474
+ logger.error('SDK::Transactions::resolvePendingTransaction::handleUpdateToV2::error', error);
11475
+ throw new WallabyError({
11476
+ message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
11477
+ statusCode: 500,
11478
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
11479
+ });
11324
11480
  }
11325
11481
  }
11326
11482
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11481,6 +11637,9 @@ class Wallaby {
11481
11637
  this.merchants = new Merchants(config);
11482
11638
  this.httpApi = new HttpApi(config);
11483
11639
  }
11640
+ get version() {
11641
+ return currentPackageVersion;
11642
+ }
11484
11643
  }
11485
11644
 
11486
11645
  exports.AndroidVersionNotSupportedError = AndroidVersionNotSupportedError;