wallaby-cash 2.2.2 → 2.2.4

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