wallaby-cash 2.2.3 → 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/README.md CHANGED
@@ -24,7 +24,6 @@ The SDK currently supports the following blockchains:
24
24
  - Polymesh
25
25
  - Sei
26
26
  - Sui
27
- - Solana
28
27
 
29
28
  ## Install the SDK
30
29
 
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
@@ -199,7 +199,6 @@ exports.BlockchainName = void 0;
199
199
  BlockchainName["Polymesh"] = "POLYMESH";
200
200
  BlockchainName["Sei"] = "SEI";
201
201
  BlockchainName["Sui"] = "SUI";
202
- BlockchainName["Solana"] = "SOLANA";
203
202
  })(exports.BlockchainName || (exports.BlockchainName = {}));
204
203
  exports.RequestMethod = void 0;
205
204
  (function (RequestMethod) {
@@ -325,6 +324,8 @@ exports.V2KeyNames = void 0;
325
324
  V2KeyNames["PasskeyCredential"] = "pass-key-credential";
326
325
  V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
327
326
  V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
327
+ V2KeyNames["MigrationVersion"] = "wsdk_migrated_with_version";
328
+ V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
328
329
  })(exports.V2KeyNames || (exports.V2KeyNames = {}));
329
330
 
330
331
  exports.ErrorResponseCodes = void 0;
@@ -377,6 +378,7 @@ exports.ErrorResponseCodes = void 0;
377
378
  ErrorResponseCodes["sdk_jwt_invalid"] = "sdk_jwt_invalid";
378
379
  ErrorResponseCodes["sdk_jwt_expired"] = "sdk_jwt_expired";
379
380
  ErrorResponseCodes["sdk_unknown_error"] = "sdk_unknown_error";
381
+ ErrorResponseCodes["sdk_too_many_requests"] = "sdk_too_many_requests";
380
382
  ErrorResponseCodes["sdk_seed_phrase_decryption_failed"] = "sdk_seed_phrase_decryption_failed";
381
383
  ErrorResponseCodes["sdk_key_shares_not_found"] = "sdk_key_shares_not_found";
382
384
  ErrorResponseCodes["sdk_key_share_decryption_failed"] = "sdk_key_share_decryption_failed";
@@ -799,6 +801,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
799
801
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.RS256 },
800
802
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
801
803
  ];
804
+ const currentPackageVersion = "2.2.4";
802
805
 
803
806
  const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
804
807
 
@@ -4847,7 +4850,7 @@ class Cipher {
4847
4850
  * @param {string} deviceKeyPair - The public key to encrypt the data with.
4848
4851
  * @returns {Promise<Encrypted>} The encrypted data ready for storage.
4849
4852
  */
4850
- async prepareDecryptedDataForStorage({ decryptedData, credentialsKeyPair, deviceKeyPair, }) {
4853
+ async doubleEncrypt({ decryptedData, credentialsKeyPair, deviceKeyPair, }) {
4851
4854
  try {
4852
4855
  // First layer of encryption using the device public key
4853
4856
  const encryptedOnceData = await this.encrypt({
@@ -4862,7 +4865,7 @@ class Cipher {
4862
4865
  return encryptedTwiceData;
4863
4866
  }
4864
4867
  catch (error) {
4865
- logger.error('SDK::prepareDecryptedDataForStorage::error', error);
4868
+ logger.error('SDK::doubleEncrypt::error', error);
4866
4869
  throw error;
4867
4870
  }
4868
4871
  }
@@ -7064,6 +7067,12 @@ class Base {
7064
7067
  set setClientAuthToken(token) {
7065
7068
  this._initializeClientAuthToken(token);
7066
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
+ }
7067
7076
  _initializeClientAuthToken(token) {
7068
7077
  if (!jwtHasSameUser(token, this.userId)) {
7069
7078
  throw new WallabyError({
@@ -8759,7 +8768,7 @@ class WalletHandlersService extends Base {
8759
8768
  errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
8760
8769
  data: error,
8761
8770
  cause: error.cause,
8762
- onError: () => console.log('Reported the error'),
8771
+ onError: () => logger.log('Reported the error'),
8763
8772
  });
8764
8773
  }
8765
8774
  }));
@@ -8866,6 +8875,8 @@ class WalletHandlersService extends Base {
8866
8875
  class WalletService extends Base {
8867
8876
  constructor(config) {
8868
8877
  super(config);
8878
+ this.passwordResetAttempts = 0;
8879
+ this.migrationAttempts = 0;
8869
8880
  this.authService = new AuthService(config);
8870
8881
  this.handlers = new WalletHandlersService(config);
8871
8882
  this.userId = config.userId;
@@ -8984,9 +8995,12 @@ class WalletService extends Base {
8984
8995
  });
8985
8996
  }
8986
8997
  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);
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
+ });
8990
9004
  }
8991
9005
  }
8992
9006
  const encryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId });
@@ -9375,12 +9389,30 @@ class WalletService extends Base {
9375
9389
  */
9376
9390
  async changePassword({ walletId, oldPassword, newPassword, }) {
9377
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
+ }
9378
9400
  if (this.deviceAuthType === exports.AuthType.Password && oldPassword) {
9379
9401
  // Handle migration to V2 first then change the password to the new one.
9380
- await this.handleUpdateToV2({
9381
- password: oldPassword,
9382
- walletId,
9383
- });
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
+ }
9384
9416
  }
9385
9417
  const encryptedDevicePrivateKeyString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedDevicePrivateKey);
9386
9418
  const encryptedSeedPhraseString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedStandardSeedPhrase, {
@@ -9496,9 +9528,12 @@ class WalletService extends Base {
9496
9528
  });
9497
9529
  }
9498
9530
  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);
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
+ });
9502
9537
  }
9503
9538
  }
9504
9539
  let wallabyBoundSeedPhrase;
@@ -9602,9 +9637,12 @@ class WalletService extends Base {
9602
9637
  });
9603
9638
  }
9604
9639
  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);
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
+ });
9608
9646
  }
9609
9647
  }
9610
9648
  const storedEncryptedPrimaryShare = await this.localStorageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare, {
@@ -9767,9 +9805,12 @@ class WalletService extends Base {
9767
9805
  });
9768
9806
  }
9769
9807
  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);
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
+ });
9773
9814
  }
9774
9815
  }
9775
9816
  try {
@@ -9861,19 +9902,15 @@ class WalletService extends Base {
9861
9902
  * decrypt them using appropriate decryption methods, and call wallet.recover() to create new v2 keys.
9862
9903
  */
9863
9904
  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,
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,
9870
9911
  });
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
- }
9912
+ }
9913
+ try {
9877
9914
  if (!password) {
9878
9915
  throw new WallabyError({
9879
9916
  message: 'Password is required for migration to v2',
@@ -9881,24 +9918,90 @@ class WalletService extends Base {
9881
9918
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
9882
9919
  });
9883
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
+ });
9884
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;
9885
9984
  let decryptedSeedPhrase;
9886
9985
  let decryptedPrivateKey;
9887
9986
  // Check for legacy format: `{item}_{userId}`
9888
9987
  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');
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
+ });
9892
9996
  try {
9893
9997
  // Decrypt legacy items using password/salt combination
9894
- const decryptedLegacyKey = cryptoJs.AES.decrypt(legacyEncryptedPrivateKey, `${clientSalt}${password}`);
9895
9998
  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) {
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) {
9900
10003
  throw new WallabyError({
9901
- message: 'Failed to decrypt legacy items with provided password',
10004
+ message: 'Failed to decrypt legacy seed phrase items with provided password',
9902
10005
  statusCode: 500,
9903
10006
  errorCode: exports.ErrorResponseCodes.sdk_seed_phrase_decryption_failed,
9904
10007
  });
@@ -9920,9 +10023,17 @@ class WalletService extends Base {
9920
10023
  const v1EncryptedSeed = await this.localStorageService.getEncryptedSeedPhrase(exports.SeedPhraseType.Standard, walletId);
9921
10024
  const v1EncryptedPrivateKey = await this.localStorageService.getEncryptedPrivateKey();
9922
10025
  if (v1EncryptedSeed && v1EncryptedPrivateKey) {
9923
- 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
+ });
9924
10033
  try {
9925
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 });
9926
10037
  decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(password, clientSalt);
9927
10038
  // For V1 format, private key is encrypted with just the password (not salt+password like legacy)
9928
10039
  decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
@@ -9950,44 +10061,72 @@ class WalletService extends Base {
9950
10061
  return;
9951
10062
  }
9952
10063
  }
9953
- if (decryptedSeedPhrase) {
10064
+ if (decryptedSeedPhrase && decryptedPrivateKey) {
9954
10065
  logger.info('SDK::WalletService::handleUpdateToV2::Initiating wallet recovery for V2 migration');
9955
10066
  logger.info('SDK::WalletService::handleUpdateToV2::Migration data prepared');
9956
10067
  logger.info('SDK::WalletService::handleUpdateToV2::Seed phrase available:', !!decryptedSeedPhrase);
9957
10068
  // 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,
10069
+ const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
10070
+ const signInSignatureMessage = await this.authService.getSignature({
10071
+ publicKey: devicePublicKey,
10072
+ privateKey: decryptedPrivateKey,
9963
10073
  });
10074
+ // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9964
10075
  const authResponse = await this.request(AuthRoutes.signIn, {
9965
10076
  payload: {
9966
10077
  externalUserId: this.userId,
9967
- message: tempSignatureMessage.message,
9968
- signature: tempSignatureMessage.signature,
9969
- 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,
9970
10093
  },
9971
10094
  });
9972
10095
  // Store authentication tokens
9973
10096
  await this.localStorageService.saveInBulk([
9974
10097
  { key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
9975
10098
  { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
10099
+ { key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
10100
+ { key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9976
10101
  ]);
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,
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'],
9984
10107
  });
9985
- 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);
9986
10110
  return;
9987
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
+ }
9988
10119
  }
9989
10120
  catch (error) {
9990
- 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);
9991
10130
  throw error;
9992
10131
  }
9993
10132
  }
@@ -10004,15 +10143,6 @@ class WalletService extends Base {
10004
10143
  try {
10005
10144
  const { readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares, signatureMessage, deviceAuthPublicKey } = await this.prepareWalletOperationAuth({ authenticationOptions: input.authenticationOptions, walletId: input.walletId });
10006
10145
  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
10146
  const accessVerificationResponse = await this.api.wallets.verifyAccess({
10017
10147
  message: signatureMessage.message,
10018
10148
  signature: signatureMessage.signature,
@@ -10252,6 +10382,12 @@ __decorate([
10252
10382
  __metadata("design:paramtypes", [Object]),
10253
10383
  __metadata("design:returntype", Promise)
10254
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);
10255
10391
 
10256
10392
  class WalletDataService extends Base {
10257
10393
  constructor(config) {
@@ -10479,10 +10615,20 @@ class WalletDataService extends Base {
10479
10615
  });
10480
10616
  }
10481
10617
  if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
10482
- await this.walletService.handleUpdateToV2({
10483
- password: authenticationOptions.password,
10484
- walletId: walletId,
10485
- });
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
+ }
10486
10632
  }
10487
10633
  try {
10488
10634
  const addressInfo = await this.walletService.generateWalletAddresses({
@@ -11166,9 +11312,12 @@ class Transactions extends Base {
11166
11312
  });
11167
11313
  }
11168
11314
  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);
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
+ });
11172
11321
  }
11173
11322
  }
11174
11323
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11243,9 +11392,12 @@ class Transactions extends Base {
11243
11392
  });
11244
11393
  }
11245
11394
  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);
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
+ });
11249
11401
  }
11250
11402
  }
11251
11403
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11318,9 +11470,12 @@ class Transactions extends Base {
11318
11470
  });
11319
11471
  }
11320
11472
  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);
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
+ });
11324
11479
  }
11325
11480
  }
11326
11481
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
@@ -11481,6 +11636,9 @@ class Wallaby {
11481
11636
  this.merchants = new Merchants(config);
11482
11637
  this.httpApi = new HttpApi(config);
11483
11638
  }
11639
+ get version() {
11640
+ return currentPackageVersion;
11641
+ }
11484
11642
  }
11485
11643
 
11486
11644
  exports.AndroidVersionNotSupportedError = AndroidVersionNotSupportedError;