wallaby-cash 2.3.0 → 2.3.2
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/index.cjs.js +169 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +169 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +191 -51
- package/dist/index.js.map +1 -1
- package/dist/lib/wallet/wallet-data.service.d.ts +4 -4
- package/dist/package.json +3 -2
- package/package.json +3 -2
package/dist/index.esm.js
CHANGED
|
@@ -778,7 +778,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
778
778
|
{ type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
|
|
779
779
|
];
|
|
780
780
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
781
|
-
const currentPackageVersion = "2.3.
|
|
781
|
+
const currentPackageVersion = "2.3.2" ;
|
|
782
782
|
|
|
783
783
|
/**
|
|
784
784
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -10364,6 +10364,12 @@ class WalletService extends Base {
|
|
|
10364
10364
|
const v2EncryptedSeed = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
10365
10365
|
walletId: input.walletId,
|
|
10366
10366
|
});
|
|
10367
|
+
const v2EncryptedPrimaryShare = await this.localStorageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare, {
|
|
10368
|
+
walletId: input.walletId,
|
|
10369
|
+
});
|
|
10370
|
+
const v2EncryptedBackupShare = await this.localStorageService.fetch(LocalStorageItems.BackupDeviceKeyShare, {
|
|
10371
|
+
walletId: input.walletId,
|
|
10372
|
+
});
|
|
10367
10373
|
const clientSalt = await this.authService.getUserSalt();
|
|
10368
10374
|
const passwordCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
10369
10375
|
password: input.password,
|
|
@@ -10409,48 +10415,168 @@ class WalletService extends Base {
|
|
|
10409
10415
|
},
|
|
10410
10416
|
getSignature: this.authService.getSignature.bind(this),
|
|
10411
10417
|
});
|
|
10418
|
+
const prfValue = authentication.prfValue;
|
|
10419
|
+
if (!prfValue || !(prfValue instanceof Uint8Array) || prfValue.length === 0) {
|
|
10420
|
+
logger.error('SDK::WalletService::convertToPasskey::prfValue is required and must be a non-empty Uint8Array');
|
|
10421
|
+
throw new WallabyError({
|
|
10422
|
+
message: 'PRF value from passkey is required to derive credentials and could not be obtained',
|
|
10423
|
+
statusCode: 500,
|
|
10424
|
+
errorCode: ErrorResponseCodes.sdk_passkey_prf_not_available,
|
|
10425
|
+
});
|
|
10426
|
+
}
|
|
10412
10427
|
logger.log('SDK::WalletService::convertToPasskey::Received authentication response', !!authentication);
|
|
10413
10428
|
let decryptedSeedPhrase;
|
|
10414
|
-
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
|
|
10420
|
-
|
|
10421
|
-
|
|
10422
|
-
|
|
10423
|
-
|
|
10429
|
+
let decryptedPrimaryShare;
|
|
10430
|
+
let decryptedBackupShare;
|
|
10431
|
+
if (v2EncryptedSeed && v2EncryptedPriv) {
|
|
10432
|
+
try {
|
|
10433
|
+
decryptedSeedPhrase = await this.cipher.displayStoredData({
|
|
10434
|
+
storedEncryptedData: safeJsonParse(v2EncryptedSeed),
|
|
10435
|
+
encryptedDevicePrivateKey: safeJsonParse(v2EncryptedPriv),
|
|
10436
|
+
options: {
|
|
10437
|
+
authType: AuthType.Password,
|
|
10438
|
+
password: input.password,
|
|
10439
|
+
salt: clientSalt,
|
|
10440
|
+
},
|
|
10441
|
+
});
|
|
10442
|
+
}
|
|
10443
|
+
catch (error) {
|
|
10444
|
+
logger.error('SDK::WalletService::convertToPasskey::seed_decryption_error', error);
|
|
10445
|
+
}
|
|
10424
10446
|
}
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10447
|
+
if (!decryptedSeedPhrase) {
|
|
10448
|
+
try {
|
|
10449
|
+
decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(input.password, clientSalt);
|
|
10450
|
+
}
|
|
10451
|
+
catch (error) {
|
|
10452
|
+
logger.error('SDK::WalletService::convertToPasskey::v1_seed_decryption_error', error);
|
|
10453
|
+
}
|
|
10454
|
+
}
|
|
10455
|
+
if (v2EncryptedPrimaryShare && v2EncryptedPriv) {
|
|
10456
|
+
try {
|
|
10457
|
+
const parsedPrimaryShare = safeJsonParse(v2EncryptedPrimaryShare);
|
|
10458
|
+
decryptedPrimaryShare = await this.cipher.displayStoredData({
|
|
10459
|
+
storedEncryptedData: parsedPrimaryShare,
|
|
10460
|
+
encryptedDevicePrivateKey: safeJsonParse(v2EncryptedPriv),
|
|
10461
|
+
options: {
|
|
10462
|
+
authType: AuthType.Password,
|
|
10463
|
+
password: input.password,
|
|
10464
|
+
salt: clientSalt,
|
|
10465
|
+
},
|
|
10433
10466
|
});
|
|
10434
10467
|
}
|
|
10468
|
+
catch (error) {
|
|
10469
|
+
logger.error('SDK::WalletService::convertToPasskey::primary_share_decryption_error', error);
|
|
10470
|
+
}
|
|
10435
10471
|
}
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10472
|
+
if (v2EncryptedBackupShare) {
|
|
10473
|
+
try {
|
|
10474
|
+
const parsedBackupShare = safeJsonParse(v2EncryptedBackupShare);
|
|
10475
|
+
// backup key share is wrapped with credentials public key at the outer layer
|
|
10476
|
+
// and wallaby public key at the inner layer, so only one local unwrap is needed.
|
|
10477
|
+
decryptedBackupShare = await this.cipher.decrypt({
|
|
10478
|
+
cipherText: parsedBackupShare,
|
|
10479
|
+
decryptionKey: passwordCredentialsKeyPair.privateKey,
|
|
10480
|
+
});
|
|
10481
|
+
}
|
|
10482
|
+
catch (error) {
|
|
10483
|
+
logger.error('SDK::WalletService::convertToPasskey::backup_share_decryption_error', error);
|
|
10484
|
+
}
|
|
10485
|
+
}
|
|
10486
|
+
const hasAnyDecryptedShare = !!decryptedPrimaryShare || !!decryptedBackupShare;
|
|
10487
|
+
if (!decryptedSeedPhrase && !hasAnyDecryptedShare) {
|
|
10488
|
+
throw new WallabyError({
|
|
10489
|
+
message: 'Seed phrase or key shares on this device could not be decrypted',
|
|
10490
|
+
statusCode: 500,
|
|
10491
|
+
errorCode: ErrorResponseCodes.sdk_no_valid_seed_option,
|
|
10492
|
+
});
|
|
10493
|
+
}
|
|
10494
|
+
// We only care about the primary share for future local operations.
|
|
10495
|
+
if (decryptedSeedPhrase && !decryptedPrimaryShare) {
|
|
10496
|
+
logger.info('SDK::WalletService::convertToPasskey::No primary share found, importing wallet');
|
|
10497
|
+
await this.handlers.handleImportWallet({
|
|
10498
|
+
publicKey: clientPublicKey,
|
|
10499
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10500
|
+
}, {
|
|
10501
|
+
authenticationOptions: authentication,
|
|
10502
|
+
seedPhrase: decryptedSeedPhrase,
|
|
10503
|
+
storeSeedPhrase: false,
|
|
10504
|
+
returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
10505
|
+
keyShareOptions: {
|
|
10506
|
+
threshold: 2,
|
|
10507
|
+
numberOfKeyShares: 3,
|
|
10508
|
+
numberOfSharesReturned: 2,
|
|
10509
|
+
storeOneKeyShareWithWallaby: true,
|
|
10510
|
+
},
|
|
10511
|
+
});
|
|
10512
|
+
// Delete the old password-encrypted seed phrase since import stored the new passkey-encrypted version
|
|
10513
|
+
await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10514
|
+
logger.info('SDK::WalletService::convertToPasskey::Wallet imported and converted successfully, old seed phrase removed');
|
|
10515
|
+
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
10516
|
+
}
|
|
10517
|
+
const passkeyDerivedKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
10518
|
+
authType: AuthType.Passkey,
|
|
10519
|
+
prfValue,
|
|
10450
10520
|
});
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
|
|
10521
|
+
const convertedShares = [];
|
|
10522
|
+
if (decryptedPrimaryShare) {
|
|
10523
|
+
const encryptedPrimaryShare = await this.cipher.doubleEncrypt({
|
|
10524
|
+
decryptedData: decryptedPrimaryShare,
|
|
10525
|
+
credentialsKeyPair: passkeyDerivedKeyPair,
|
|
10526
|
+
deviceKeyPair: {
|
|
10527
|
+
publicKey: clientPublicKey,
|
|
10528
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10529
|
+
},
|
|
10530
|
+
});
|
|
10531
|
+
convertedShares.push({
|
|
10532
|
+
key: V2KeyNames.PrimaryDeviceKeyShare,
|
|
10533
|
+
value: encryptedPrimaryShare,
|
|
10534
|
+
walletId: input.walletId,
|
|
10535
|
+
});
|
|
10536
|
+
}
|
|
10537
|
+
if (decryptedBackupShare) {
|
|
10538
|
+
// Since this is only decrypted once, we only need passkey credential encryption.
|
|
10539
|
+
const encryptedBackupShare = await this.cipher.encrypt({
|
|
10540
|
+
data: decryptedBackupShare,
|
|
10541
|
+
encryptionKey: passkeyDerivedKeyPair.publicKey,
|
|
10542
|
+
});
|
|
10543
|
+
convertedShares.push({
|
|
10544
|
+
key: V2KeyNames.BackupDeviceKeyShare,
|
|
10545
|
+
value: encryptedBackupShare,
|
|
10546
|
+
walletId: input.walletId,
|
|
10547
|
+
});
|
|
10548
|
+
}
|
|
10549
|
+
await this.localStorageService.saveInBulk(convertedShares);
|
|
10550
|
+
if (v2EncryptedSeed) {
|
|
10551
|
+
await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10552
|
+
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10553
|
+
}
|
|
10554
|
+
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
10555
|
+
const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
|
|
10556
|
+
data: decryptedPrimaryShare,
|
|
10557
|
+
encryptionKey: authentication.user.wallabyAuthPubKey,
|
|
10558
|
+
});
|
|
10559
|
+
const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
|
|
10560
|
+
walletId: input.walletId,
|
|
10561
|
+
encryptedKeyShares: [flippedEncryptedPrimaryShare],
|
|
10562
|
+
deviceAuthKeys: {
|
|
10563
|
+
publicKey: clientPublicKey,
|
|
10564
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10565
|
+
},
|
|
10566
|
+
});
|
|
10567
|
+
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
10568
|
+
cipherText: reconstructedSeedPhrase,
|
|
10569
|
+
decryptionKey: decryptedClientAuthPrivKey,
|
|
10570
|
+
});
|
|
10571
|
+
}
|
|
10572
|
+
if (!decryptedSeedPhrase) {
|
|
10573
|
+
throw new WallabyError({
|
|
10574
|
+
message: 'Seed phrase could not be reconstructed from the provided shares',
|
|
10575
|
+
statusCode: 500,
|
|
10576
|
+
errorCode: ErrorResponseCodes.sdk_no_valid_seed_option,
|
|
10577
|
+
});
|
|
10578
|
+
}
|
|
10579
|
+
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
10454
10580
|
}
|
|
10455
10581
|
catch (error) {
|
|
10456
10582
|
logger.error('SDK::WalletService::convertToPasskey::error', error);
|
|
@@ -10770,7 +10896,7 @@ class WalletDataService extends Base {
|
|
|
10770
10896
|
/**
|
|
10771
10897
|
* Updates a wallet asset.
|
|
10772
10898
|
*
|
|
10773
|
-
* @param {string} params.
|
|
10899
|
+
* @param {string} params.configId - Config ID for the user asset.
|
|
10774
10900
|
* @param {string} params.walletId - Wallet ID to which the asset belongs.
|
|
10775
10901
|
* @param {string} params.assetName - Asset name.
|
|
10776
10902
|
* @param {boolean} params.isVisible - Asset visibility toggle.
|
|
@@ -10781,19 +10907,19 @@ class WalletDataService extends Base {
|
|
|
10781
10907
|
* @throws {Error} If required parameters are missing or invalid.
|
|
10782
10908
|
*/
|
|
10783
10909
|
async updateAsset(_a) {
|
|
10784
|
-
var {
|
|
10910
|
+
var { configId, walletId } = _a, assetConfig = __rest(_a, ["configId", "walletId"]);
|
|
10785
10911
|
try {
|
|
10786
|
-
if (!
|
|
10912
|
+
if (!configId || !walletId) {
|
|
10787
10913
|
throw new WallabyError({
|
|
10788
10914
|
message: 'Missing required parameters',
|
|
10789
10915
|
statusCode: 400,
|
|
10790
10916
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
10791
10917
|
});
|
|
10792
10918
|
}
|
|
10793
|
-
const response = await this.
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
}
|
|
10919
|
+
const response = await this.request(WalletRoutes.updateAsset, {
|
|
10920
|
+
payload: Object.assign({ configId,
|
|
10921
|
+
walletId }, assetConfig),
|
|
10922
|
+
});
|
|
10797
10923
|
return response;
|
|
10798
10924
|
}
|
|
10799
10925
|
catch (error) {
|