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 +0 -1
- package/dist/base.d.ts +1 -0
- package/dist/index.cjs.js +240 -82
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +240 -82
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +240 -82
- package/dist/index.js.map +1 -1
- package/dist/lib/utils/cipher.service.d.ts +1 -1
- package/dist/lib/utils/constants.d.ts +1 -0
- package/dist/lib/wallet/wallet.service.d.ts +2 -0
- package/dist/package.json +2 -1
- package/dist/types/common.d.ts +1 -2
- package/dist/types/error-response-codes.d.ts +1 -0
- package/dist/types/storage.d.ts +3 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -172,7 +172,6 @@ var BlockchainName;
|
|
|
172
172
|
BlockchainName["Polymesh"] = "POLYMESH";
|
|
173
173
|
BlockchainName["Sei"] = "SEI";
|
|
174
174
|
BlockchainName["Sui"] = "SUI";
|
|
175
|
-
BlockchainName["Solana"] = "SOLANA";
|
|
176
175
|
})(BlockchainName || (BlockchainName = {}));
|
|
177
176
|
var RequestMethod;
|
|
178
177
|
(function (RequestMethod) {
|
|
@@ -298,6 +297,8 @@ var V2KeyNames;
|
|
|
298
297
|
V2KeyNames["PasskeyCredential"] = "pass-key-credential";
|
|
299
298
|
V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
|
|
300
299
|
V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
300
|
+
V2KeyNames["MigrationVersion"] = "wsdk_migrated_with_version";
|
|
301
|
+
V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
|
|
301
302
|
})(V2KeyNames || (V2KeyNames = {}));
|
|
302
303
|
|
|
303
304
|
var ErrorResponseCodes;
|
|
@@ -350,6 +351,7 @@ var ErrorResponseCodes;
|
|
|
350
351
|
ErrorResponseCodes["sdk_jwt_invalid"] = "sdk_jwt_invalid";
|
|
351
352
|
ErrorResponseCodes["sdk_jwt_expired"] = "sdk_jwt_expired";
|
|
352
353
|
ErrorResponseCodes["sdk_unknown_error"] = "sdk_unknown_error";
|
|
354
|
+
ErrorResponseCodes["sdk_too_many_requests"] = "sdk_too_many_requests";
|
|
353
355
|
ErrorResponseCodes["sdk_seed_phrase_decryption_failed"] = "sdk_seed_phrase_decryption_failed";
|
|
354
356
|
ErrorResponseCodes["sdk_key_shares_not_found"] = "sdk_key_shares_not_found";
|
|
355
357
|
ErrorResponseCodes["sdk_key_share_decryption_failed"] = "sdk_key_share_decryption_failed";
|
|
@@ -772,6 +774,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
772
774
|
{ type: 'public-key', alg: PublicKeyCredentialAlgorithm.RS256 },
|
|
773
775
|
{ type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
|
|
774
776
|
];
|
|
777
|
+
const currentPackageVersion = "2.2.4";
|
|
775
778
|
|
|
776
779
|
const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
777
780
|
|
|
@@ -4820,7 +4823,7 @@ class Cipher {
|
|
|
4820
4823
|
* @param {string} deviceKeyPair - The public key to encrypt the data with.
|
|
4821
4824
|
* @returns {Promise<Encrypted>} The encrypted data ready for storage.
|
|
4822
4825
|
*/
|
|
4823
|
-
async
|
|
4826
|
+
async doubleEncrypt({ decryptedData, credentialsKeyPair, deviceKeyPair, }) {
|
|
4824
4827
|
try {
|
|
4825
4828
|
// First layer of encryption using the device public key
|
|
4826
4829
|
const encryptedOnceData = await this.encrypt({
|
|
@@ -4835,7 +4838,7 @@ class Cipher {
|
|
|
4835
4838
|
return encryptedTwiceData;
|
|
4836
4839
|
}
|
|
4837
4840
|
catch (error) {
|
|
4838
|
-
logger.error('SDK::
|
|
4841
|
+
logger.error('SDK::doubleEncrypt::error', error);
|
|
4839
4842
|
throw error;
|
|
4840
4843
|
}
|
|
4841
4844
|
}
|
|
@@ -7037,6 +7040,12 @@ class Base {
|
|
|
7037
7040
|
set setClientAuthToken(token) {
|
|
7038
7041
|
this._initializeClientAuthToken(token);
|
|
7039
7042
|
}
|
|
7043
|
+
get version() {
|
|
7044
|
+
// const currentVersion = pkg.version;
|
|
7045
|
+
const currentVersion = currentPackageVersion;
|
|
7046
|
+
logger.log(`wsdk is running v${currentVersion}`);
|
|
7047
|
+
return currentVersion;
|
|
7048
|
+
}
|
|
7040
7049
|
_initializeClientAuthToken(token) {
|
|
7041
7050
|
if (!jwtHasSameUser(token, this.userId)) {
|
|
7042
7051
|
throw new WallabyError({
|
|
@@ -8732,7 +8741,7 @@ class WalletHandlersService extends Base {
|
|
|
8732
8741
|
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
8733
8742
|
data: error,
|
|
8734
8743
|
cause: error.cause,
|
|
8735
|
-
onError: () =>
|
|
8744
|
+
onError: () => logger.log('Reported the error'),
|
|
8736
8745
|
});
|
|
8737
8746
|
}
|
|
8738
8747
|
}));
|
|
@@ -8839,6 +8848,8 @@ class WalletHandlersService extends Base {
|
|
|
8839
8848
|
class WalletService extends Base {
|
|
8840
8849
|
constructor(config) {
|
|
8841
8850
|
super(config);
|
|
8851
|
+
this.passwordResetAttempts = 0;
|
|
8852
|
+
this.migrationAttempts = 0;
|
|
8842
8853
|
this.authService = new AuthService(config);
|
|
8843
8854
|
this.handlers = new WalletHandlersService(config);
|
|
8844
8855
|
this.userId = config.userId;
|
|
@@ -8957,9 +8968,12 @@ class WalletService extends Base {
|
|
|
8957
8968
|
});
|
|
8958
8969
|
}
|
|
8959
8970
|
catch (error) {
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8971
|
+
logger.error('SDK::WalletService::export::handleUpdateToV2::error', error);
|
|
8972
|
+
throw new WallabyError({
|
|
8973
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
8974
|
+
statusCode: 500,
|
|
8975
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
8976
|
+
});
|
|
8963
8977
|
}
|
|
8964
8978
|
}
|
|
8965
8979
|
const encryptedSeed = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId });
|
|
@@ -9348,12 +9362,30 @@ class WalletService extends Base {
|
|
|
9348
9362
|
*/
|
|
9349
9363
|
async changePassword({ walletId, oldPassword, newPassword, }) {
|
|
9350
9364
|
try {
|
|
9365
|
+
this.passwordResetAttempts += 1;
|
|
9366
|
+
if (this.passwordResetAttempts > 5) {
|
|
9367
|
+
throw new WallabyError({
|
|
9368
|
+
message: 'Too many password change attempts. Please try again later.',
|
|
9369
|
+
statusCode: 429,
|
|
9370
|
+
errorCode: ErrorResponseCodes.sdk_too_many_requests,
|
|
9371
|
+
});
|
|
9372
|
+
}
|
|
9351
9373
|
if (this.deviceAuthType === AuthType.Password && oldPassword) {
|
|
9352
9374
|
// Handle migration to V2 first then change the password to the new one.
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9375
|
+
try {
|
|
9376
|
+
await this.handleUpdateToV2({
|
|
9377
|
+
password: oldPassword,
|
|
9378
|
+
walletId,
|
|
9379
|
+
});
|
|
9380
|
+
}
|
|
9381
|
+
catch (error) {
|
|
9382
|
+
logger.error('SDK::WalletService::changePassword::handleUpdateToV2::error', error);
|
|
9383
|
+
throw new WallabyError({
|
|
9384
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9385
|
+
statusCode: 500,
|
|
9386
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9387
|
+
});
|
|
9388
|
+
}
|
|
9357
9389
|
}
|
|
9358
9390
|
const encryptedDevicePrivateKeyString = await this.localStorageService.fetch(V2KeyNames.EncryptedDevicePrivateKey);
|
|
9359
9391
|
const encryptedSeedPhraseString = await this.localStorageService.fetch(V2KeyNames.EncryptedStandardSeedPhrase, {
|
|
@@ -9469,9 +9501,12 @@ class WalletService extends Base {
|
|
|
9469
9501
|
});
|
|
9470
9502
|
}
|
|
9471
9503
|
catch (error) {
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9504
|
+
logger.error('SDK::WalletService::getAlgorandSeedPhrase::handleUpdateToV2::error', error);
|
|
9505
|
+
throw new WallabyError({
|
|
9506
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9507
|
+
statusCode: 500,
|
|
9508
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9509
|
+
});
|
|
9475
9510
|
}
|
|
9476
9511
|
}
|
|
9477
9512
|
let wallabyBoundSeedPhrase;
|
|
@@ -9575,9 +9610,12 @@ class WalletService extends Base {
|
|
|
9575
9610
|
});
|
|
9576
9611
|
}
|
|
9577
9612
|
catch (error) {
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9613
|
+
logger.error('SDK::WalletService::initAddNewDevice::handleUpdateToV2::error', error);
|
|
9614
|
+
throw new WallabyError({
|
|
9615
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9616
|
+
statusCode: 500,
|
|
9617
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9618
|
+
});
|
|
9581
9619
|
}
|
|
9582
9620
|
}
|
|
9583
9621
|
const storedEncryptedPrimaryShare = await this.localStorageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare, {
|
|
@@ -9740,9 +9778,12 @@ class WalletService extends Base {
|
|
|
9740
9778
|
});
|
|
9741
9779
|
}
|
|
9742
9780
|
catch (error) {
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9781
|
+
logger.error('SDK::WalletService::generateWalletAddresses::handleUpdateToV2::error', error);
|
|
9782
|
+
throw new WallabyError({
|
|
9783
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9784
|
+
statusCode: 500,
|
|
9785
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9786
|
+
});
|
|
9746
9787
|
}
|
|
9747
9788
|
}
|
|
9748
9789
|
try {
|
|
@@ -9834,19 +9875,15 @@ class WalletService extends Base {
|
|
|
9834
9875
|
* decrypt them using appropriate decryption methods, and call wallet.recover() to create new v2 keys.
|
|
9835
9876
|
*/
|
|
9836
9877
|
async handleUpdateToV2({ password, walletId }) {
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9878
|
+
const migrationStartTime = Date.now();
|
|
9879
|
+
if (this.migrationAttempts > 5) {
|
|
9880
|
+
throw new WallabyError({
|
|
9881
|
+
message: 'Too many migration attempts. Please try again later.',
|
|
9882
|
+
statusCode: 429,
|
|
9883
|
+
errorCode: ErrorResponseCodes.sdk_too_many_requests,
|
|
9843
9884
|
});
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
// If V2 items are present,
|
|
9847
|
-
// we don't need to throw any errors, just continue with rest of flow.
|
|
9848
|
-
return;
|
|
9849
|
-
}
|
|
9885
|
+
}
|
|
9886
|
+
try {
|
|
9850
9887
|
if (!password) {
|
|
9851
9888
|
throw new WallabyError({
|
|
9852
9889
|
message: 'Password is required for migration to v2',
|
|
@@ -9854,24 +9891,90 @@ class WalletService extends Base {
|
|
|
9854
9891
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
9855
9892
|
});
|
|
9856
9893
|
}
|
|
9894
|
+
// Check migration metadata FIRST (lightweight, no network/crypto operations)
|
|
9895
|
+
const currentSdkVersion = this.version;
|
|
9896
|
+
const sdkMigrationVersion = await this.localStorageService.fetch(V2KeyNames.MigrationVersion);
|
|
9897
|
+
const lastMigratedAt = await this.localStorageService.fetch(V2KeyNames.LastMigratedAt);
|
|
9898
|
+
logger.info('SDK::WalletService::handleUpdateToV2::starting migration check', {
|
|
9899
|
+
timestamp: new Date(migrationStartTime).toISOString(),
|
|
9900
|
+
walletId: walletId.substring(0, 8) + '...',
|
|
9901
|
+
lastMigratedAt,
|
|
9902
|
+
currentSdkVersion,
|
|
9903
|
+
sdkMigrationVersion,
|
|
9904
|
+
});
|
|
9905
|
+
// If migration completed successfully before (has a valid timestamp, not 'never')
|
|
9906
|
+
// 'never' indicates a previous failure and allows retry attempts
|
|
9907
|
+
if (lastMigratedAt && lastMigratedAt !== 'never' && sdkMigrationVersion) {
|
|
9908
|
+
logger.info('SDK::WalletService::handleUpdateToV2::Migration already completed successfully, skipping', {
|
|
9909
|
+
migratedVersion: sdkMigrationVersion,
|
|
9910
|
+
migratedAt: lastMigratedAt,
|
|
9911
|
+
});
|
|
9912
|
+
return;
|
|
9913
|
+
}
|
|
9914
|
+
// Migration needed - proceed with V2 existence check and potential migration
|
|
9915
|
+
const v2EncryptedDevicePrivateKey = await this.localStorageService.fetch(V2KeyNames.EncryptedDevicePrivateKey);
|
|
9916
|
+
const v2EncryptedSeed = await this.localStorageService.fetch(V2KeyNames.EncryptedStandardSeedPhrase, { walletId });
|
|
9917
|
+
const v2EncryptedPrimaryDeviceShare = await this.localStorageService.fetch(V2KeyNames.PrimaryDeviceKeyShare, {
|
|
9918
|
+
walletId,
|
|
9919
|
+
});
|
|
9857
9920
|
const clientSalt = await this.authService.getUserSalt();
|
|
9921
|
+
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9922
|
+
authType: AuthType.Password,
|
|
9923
|
+
password,
|
|
9924
|
+
salt: clientSalt,
|
|
9925
|
+
});
|
|
9926
|
+
if (v2EncryptedDevicePrivateKey && (v2EncryptedSeed || v2EncryptedPrimaryDeviceShare)) {
|
|
9927
|
+
try {
|
|
9928
|
+
await this.cipher.decrypt({
|
|
9929
|
+
cipherText: safeJsonParse(v2EncryptedDevicePrivateKey),
|
|
9930
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
9931
|
+
});
|
|
9932
|
+
// Explicitly select the non-empty value between seed and primary device share
|
|
9933
|
+
const v2SeedData = v2EncryptedSeed || v2EncryptedPrimaryDeviceShare;
|
|
9934
|
+
await this.cipher.displayStoredData({
|
|
9935
|
+
storedEncryptedData: safeJsonParse(v2SeedData),
|
|
9936
|
+
encryptedDevicePrivateKey: safeJsonParse(v2EncryptedDevicePrivateKey),
|
|
9937
|
+
options: {
|
|
9938
|
+
authType: AuthType.Password,
|
|
9939
|
+
password,
|
|
9940
|
+
salt: clientSalt,
|
|
9941
|
+
},
|
|
9942
|
+
});
|
|
9943
|
+
logger.info('SDK::WalletService::handleUpdateToV2::V2 items already exist and are valid, no migration needed');
|
|
9944
|
+
// V2 exists and is valid - update metadata to avoid future checks
|
|
9945
|
+
await this.localStorageService.save(V2KeyNames.LastMigratedAt, new Date().toISOString());
|
|
9946
|
+
await this.localStorageService.save(V2KeyNames.MigrationVersion, currentSdkVersion);
|
|
9947
|
+
return;
|
|
9948
|
+
}
|
|
9949
|
+
catch (error) {
|
|
9950
|
+
logger.info('SDK::WalletService::handleUpdateToV2::V2 items exist but decryption failed, proceeding with migration', {
|
|
9951
|
+
error: JSON.stringify(error),
|
|
9952
|
+
});
|
|
9953
|
+
}
|
|
9954
|
+
}
|
|
9955
|
+
// Increment counter after V2 validation to avoid counting when migration not needed
|
|
9956
|
+
this.migrationAttempts += 1;
|
|
9858
9957
|
let decryptedSeedPhrase;
|
|
9859
9958
|
let decryptedPrivateKey;
|
|
9860
9959
|
// Check for legacy format: `{item}_{userId}`
|
|
9861
9960
|
const legacyEncryptedSeed = await this.localStorageService.getFromDeviceStorage(`${LegacyKeyNames.EncryptedSeed}_${this.userId}`);
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9961
|
+
// getDecryptedV1PrivateKey checks for both v1 and legacy formats internally
|
|
9962
|
+
const legacyDecryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
|
|
9963
|
+
if (legacyEncryptedSeed && legacyDecryptedPrivateKey) {
|
|
9964
|
+
const legacyPublicKey = publicKeyByPrivateKey(legacyDecryptedPrivateKey);
|
|
9965
|
+
logger.info('SDK::WalletService::handleUpdateToV2::Found legacy storage items, attempting migration', {
|
|
9966
|
+
storageFormat: 'legacy',
|
|
9967
|
+
devicePublicKey: legacyPublicKey.substring(0, 16) + '...',
|
|
9968
|
+
});
|
|
9865
9969
|
try {
|
|
9866
9970
|
// Decrypt legacy items using password/salt combination
|
|
9867
|
-
const decryptedLegacyKey = AES.decrypt(legacyEncryptedPrivateKey, `${clientSalt}${password}`);
|
|
9868
9971
|
const decryptedOnceSeed = AES.decrypt(legacyEncryptedSeed, `${clientSalt}${password}`);
|
|
9869
|
-
const
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
if (!decryptedSeedPhrase
|
|
9972
|
+
const parsedDecryptedOnceSeed = safeJsonParse(decryptedOnceSeed.toString(enc.Utf8));
|
|
9973
|
+
decryptedSeedPhrase = decryptWithPrivateKey(legacyDecryptedPrivateKey, parsedDecryptedOnceSeed);
|
|
9974
|
+
decryptedPrivateKey = legacyDecryptedPrivateKey; // Assign the decrypted private key
|
|
9975
|
+
if (!decryptedSeedPhrase) {
|
|
9873
9976
|
throw new WallabyError({
|
|
9874
|
-
message: 'Failed to decrypt legacy items with provided password',
|
|
9977
|
+
message: 'Failed to decrypt legacy seed phrase items with provided password',
|
|
9875
9978
|
statusCode: 500,
|
|
9876
9979
|
errorCode: ErrorResponseCodes.sdk_seed_phrase_decryption_failed,
|
|
9877
9980
|
});
|
|
@@ -9893,9 +9996,17 @@ class WalletService extends Base {
|
|
|
9893
9996
|
const v1EncryptedSeed = await this.localStorageService.getEncryptedSeedPhrase(SeedPhraseType.Standard, walletId);
|
|
9894
9997
|
const v1EncryptedPrivateKey = await this.localStorageService.getEncryptedPrivateKey();
|
|
9895
9998
|
if (v1EncryptedSeed && v1EncryptedPrivateKey) {
|
|
9896
|
-
|
|
9999
|
+
// Get public key before decryption for logging
|
|
10000
|
+
decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
|
|
10001
|
+
const v1PublicKey = decryptedPrivateKey ? publicKeyByPrivateKey(decryptedPrivateKey) : 'unknown';
|
|
10002
|
+
logger.info('SDK::WalletService::handleUpdateToV2::Found V1 storage items, attempting migration', {
|
|
10003
|
+
storageFormat: 'v1',
|
|
10004
|
+
devicePublicKey: v1PublicKey.substring(0, 16) + '...',
|
|
10005
|
+
});
|
|
9897
10006
|
try {
|
|
9898
10007
|
// Decrypt V1 items using storage service method (handles double encryption)
|
|
10008
|
+
logger.log('Attempting to decrypt V1 items during migration...');
|
|
10009
|
+
logger.log('getV1DecryptedSeedPhrase should be called with password and clientSalt:', { password, clientSalt });
|
|
9899
10010
|
decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(password, clientSalt);
|
|
9900
10011
|
// For V1 format, private key is encrypted with just the password (not salt+password like legacy)
|
|
9901
10012
|
decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
|
|
@@ -9923,44 +10034,72 @@ class WalletService extends Base {
|
|
|
9923
10034
|
return;
|
|
9924
10035
|
}
|
|
9925
10036
|
}
|
|
9926
|
-
if (decryptedSeedPhrase) {
|
|
10037
|
+
if (decryptedSeedPhrase && decryptedPrivateKey) {
|
|
9927
10038
|
logger.info('SDK::WalletService::handleUpdateToV2::Initiating wallet recovery for V2 migration');
|
|
9928
10039
|
logger.info('SDK::WalletService::handleUpdateToV2::Migration data prepared');
|
|
9929
10040
|
logger.info('SDK::WalletService::handleUpdateToV2::Seed phrase available:', !!decryptedSeedPhrase);
|
|
9930
10041
|
// During migration, we need to authenticate but avoid creating conflicting device keypairs
|
|
9931
|
-
|
|
9932
|
-
const
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
privateKey: tempDeviceKeyPair.privateKey,
|
|
10042
|
+
const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
|
|
10043
|
+
const signInSignatureMessage = await this.authService.getSignature({
|
|
10044
|
+
publicKey: devicePublicKey,
|
|
10045
|
+
privateKey: decryptedPrivateKey,
|
|
9936
10046
|
});
|
|
10047
|
+
// this would ensure the stored public key is consistent with wallaby and can authenticate the user.
|
|
9937
10048
|
const authResponse = await this.request(AuthRoutes.signIn, {
|
|
9938
10049
|
payload: {
|
|
9939
10050
|
externalUserId: this.userId,
|
|
9940
|
-
message:
|
|
9941
|
-
signature:
|
|
9942
|
-
clientAuthPubKey:
|
|
10051
|
+
message: signInSignatureMessage.message,
|
|
10052
|
+
signature: signInSignatureMessage.signature,
|
|
10053
|
+
clientAuthPubKey: devicePublicKey,
|
|
10054
|
+
},
|
|
10055
|
+
});
|
|
10056
|
+
const encryptedV2PrivateKey = await this.cipher.encrypt({
|
|
10057
|
+
data: decryptedPrivateKey,
|
|
10058
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
10059
|
+
});
|
|
10060
|
+
const encryptedV2Seed = await this.cipher.doubleEncrypt({
|
|
10061
|
+
decryptedData: decryptedSeedPhrase,
|
|
10062
|
+
credentialsKeyPair,
|
|
10063
|
+
deviceKeyPair: {
|
|
10064
|
+
publicKey: devicePublicKey,
|
|
10065
|
+
privateKey: decryptedPrivateKey,
|
|
9943
10066
|
},
|
|
9944
10067
|
});
|
|
9945
10068
|
// Store authentication tokens
|
|
9946
10069
|
await this.localStorageService.saveInBulk([
|
|
9947
10070
|
{ key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
|
|
9948
10071
|
{ key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
|
|
10072
|
+
{ key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
|
|
10073
|
+
{ key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
|
|
9949
10074
|
]);
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
storeSeedPhrase: true,
|
|
9956
|
-
returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedSeedPhrase,
|
|
10075
|
+
logger.info('SDK::WalletService::handleUpdateToV2::Migration completed successfully', {
|
|
10076
|
+
timestamp: new Date().toISOString(),
|
|
10077
|
+
duration: Date.now() - migrationStartTime,
|
|
10078
|
+
devicePublicKey: devicePublicKey.substring(0, 16) + '...',
|
|
10079
|
+
migratedKeys: ['EncryptedDevicePrivateKey', 'EncryptedStandardSeedPhrase'],
|
|
9957
10080
|
});
|
|
9958
|
-
|
|
10081
|
+
await this.localStorageService.save(V2KeyNames.LastMigratedAt, new Date().toISOString());
|
|
10082
|
+
await this.localStorageService.save(V2KeyNames.MigrationVersion, this.version);
|
|
9959
10083
|
return;
|
|
9960
10084
|
}
|
|
10085
|
+
else {
|
|
10086
|
+
throw new WallabyError({
|
|
10087
|
+
message: 'Decrypted data required for migration is missing, operation cannot be completed.',
|
|
10088
|
+
statusCode: 500,
|
|
10089
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
10090
|
+
});
|
|
10091
|
+
}
|
|
9961
10092
|
}
|
|
9962
10093
|
catch (error) {
|
|
9963
|
-
logger.error('SDK::WalletService::handleUpdateToV2::Migration failed',
|
|
10094
|
+
logger.error('SDK::WalletService::handleUpdateToV2::Migration failed', {
|
|
10095
|
+
timestamp: new Date().toISOString(),
|
|
10096
|
+
duration: Date.now() - migrationStartTime,
|
|
10097
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
10098
|
+
});
|
|
10099
|
+
// Save 'never' to indicate failure, which still allows retries (checked in early return)
|
|
10100
|
+
// Rate limiting prevents infinite retry attempts
|
|
10101
|
+
await this.localStorageService.save(V2KeyNames.LastMigratedAt, 'never');
|
|
10102
|
+
await this.localStorageService.save(V2KeyNames.MigrationVersion, this.version);
|
|
9964
10103
|
throw error;
|
|
9965
10104
|
}
|
|
9966
10105
|
}
|
|
@@ -9977,15 +10116,6 @@ class WalletService extends Base {
|
|
|
9977
10116
|
try {
|
|
9978
10117
|
const { readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares, signatureMessage, deviceAuthPublicKey } = await this.prepareWalletOperationAuth({ authenticationOptions: input.authenticationOptions, walletId: input.walletId });
|
|
9979
10118
|
const shouldSendSeedPhrase = readyForTransportSeedPhrase && !hasShares;
|
|
9980
|
-
// const accessVerificationResponse = await this.request<{ isAccessVerified: boolean }>(WalletRoutes.verifyAccess, {
|
|
9981
|
-
// payload: {
|
|
9982
|
-
// ...signatureMessage,
|
|
9983
|
-
// clientAuthPubKey: deviceAuthPublicKey,
|
|
9984
|
-
// encryptedSeed: shouldSendSeedPhrase ? readyForTransportSeedPhrase : undefined,
|
|
9985
|
-
// encryptedShares: !shouldSendSeedPhrase ? sharesEncryptedWithWallabyPubKey : undefined,
|
|
9986
|
-
// walletId: input.walletId,
|
|
9987
|
-
// },
|
|
9988
|
-
// });
|
|
9989
10119
|
const accessVerificationResponse = await this.api.wallets.verifyAccess({
|
|
9990
10120
|
message: signatureMessage.message,
|
|
9991
10121
|
signature: signatureMessage.signature,
|
|
@@ -10225,6 +10355,12 @@ __decorate([
|
|
|
10225
10355
|
__metadata("design:paramtypes", [Object]),
|
|
10226
10356
|
__metadata("design:returntype", Promise)
|
|
10227
10357
|
], WalletService.prototype, "changePassword", null);
|
|
10358
|
+
__decorate([
|
|
10359
|
+
WithLock('migrateToV2'),
|
|
10360
|
+
__metadata("design:type", Function),
|
|
10361
|
+
__metadata("design:paramtypes", [Object]),
|
|
10362
|
+
__metadata("design:returntype", Promise)
|
|
10363
|
+
], WalletService.prototype, "handleUpdateToV2", null);
|
|
10228
10364
|
|
|
10229
10365
|
class WalletDataService extends Base {
|
|
10230
10366
|
constructor(config) {
|
|
@@ -10452,10 +10588,20 @@ class WalletDataService extends Base {
|
|
|
10452
10588
|
});
|
|
10453
10589
|
}
|
|
10454
10590
|
if (this.deviceAuthType === AuthType.Password && authenticationOptions.password) {
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10591
|
+
try {
|
|
10592
|
+
await this.walletService.handleUpdateToV2({
|
|
10593
|
+
password: authenticationOptions.password,
|
|
10594
|
+
walletId: walletId,
|
|
10595
|
+
});
|
|
10596
|
+
}
|
|
10597
|
+
catch (error) {
|
|
10598
|
+
logger.error('SDK::WalletDataService::addNewChainAndTokenToWallet::handleUpdateToV2::error', error);
|
|
10599
|
+
throw new WallabyError({
|
|
10600
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
10601
|
+
statusCode: 500,
|
|
10602
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
10603
|
+
});
|
|
10604
|
+
}
|
|
10459
10605
|
}
|
|
10460
10606
|
try {
|
|
10461
10607
|
const addressInfo = await this.walletService.generateWalletAddresses({
|
|
@@ -11139,9 +11285,12 @@ class Transactions extends Base {
|
|
|
11139
11285
|
});
|
|
11140
11286
|
}
|
|
11141
11287
|
catch (error) {
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11288
|
+
logger.error('SDK::Transactions::transfer::handleUpdateToV2::error', error);
|
|
11289
|
+
throw new WallabyError({
|
|
11290
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11291
|
+
statusCode: 500,
|
|
11292
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
11293
|
+
});
|
|
11145
11294
|
}
|
|
11146
11295
|
}
|
|
11147
11296
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
@@ -11216,9 +11365,12 @@ class Transactions extends Base {
|
|
|
11216
11365
|
});
|
|
11217
11366
|
}
|
|
11218
11367
|
catch (error) {
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
|
|
11368
|
+
logger.error('SDK::Transactions::createAllowance::handleUpdateToV2::error', error);
|
|
11369
|
+
throw new WallabyError({
|
|
11370
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11371
|
+
statusCode: 500,
|
|
11372
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
11373
|
+
});
|
|
11222
11374
|
}
|
|
11223
11375
|
}
|
|
11224
11376
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
@@ -11291,9 +11443,12 @@ class Transactions extends Base {
|
|
|
11291
11443
|
});
|
|
11292
11444
|
}
|
|
11293
11445
|
catch (error) {
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11446
|
+
logger.error('SDK::Transactions::resolvePendingTransaction::handleUpdateToV2::error', error);
|
|
11447
|
+
throw new WallabyError({
|
|
11448
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11449
|
+
statusCode: 500,
|
|
11450
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
11451
|
+
});
|
|
11297
11452
|
}
|
|
11298
11453
|
}
|
|
11299
11454
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
@@ -11454,6 +11609,9 @@ class Wallaby {
|
|
|
11454
11609
|
this.merchants = new Merchants(config);
|
|
11455
11610
|
this.httpApi = new HttpApi(config);
|
|
11456
11611
|
}
|
|
11612
|
+
get version() {
|
|
11613
|
+
return currentPackageVersion;
|
|
11614
|
+
}
|
|
11457
11615
|
}
|
|
11458
11616
|
|
|
11459
11617
|
export { AddressType, AndroidVersionNotSupportedError, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, AuthenticatorGeneralError, AuthenticatorMissingDiscoverableCredentialSupportError, AuthenticatorMissingUserVerificationSupportError, AuthenticatorNoSupportedPubKeyCredParamsAlgError, AuthenticatorNotRegisteredError, AuthenticatorPreviouslyRegisteredError, AutoRegisterUserVerificationFailureError, BadConfiguration, BlockchainName, BlockchainSlip44, BlockchainStatus, CeremonyAbortedError, ErrorResponseCodes, IOSVersionNotSupportedError, InterruptedError, InvalidChallengeError, InvalidDomainError, InvalidRpIdError, InvalidStateError, InvalidUserIdError, InvalidUserIdLengthError, KeyTypeName, LegacyKeyNames, LocalStorageItems, MalformedPubKeyCredParamsError, NativeError, NoCredentialsError, NotAllowedError, OwnershipType, PasskeyChallengeType, PasskeyErrorCodes, PassthroughSeeCausePropertyError, PublicKeyCredentialAlgorithm, RequestFailedError, RequestMethod, ReturnWalletOption, SeedPhraseType, TimeoutError, TokenStandard, TransactionEntryType, TransportEnum, UnknownError, UserAssetSource, UserCancelledError, V1KeyNames, V2KeyNames, Wallaby, Api as WallabyApiClient, WallabyError, HttpClient as WallabyHttpClient, WalletAddressTypeName, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
|