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.js CHANGED
@@ -785,7 +785,7 @@ const env = {
785
785
  isServer: false,
786
786
  isWeb,
787
787
  };
788
- const currentPackageVersion = "2.3.0" ;
788
+ const currentPackageVersion = "2.3.2" ;
789
789
 
790
790
  /**
791
791
  * Storage keys adapter for Storage interface across different platforms.
@@ -7540,6 +7540,15 @@ const SwapRoutes = {
7540
7540
  *
7541
7541
  * https://reactnative.dev/docs/platform-specific-code#native-specific-extensions-ie-sharing-code-with-nodejs-and-web
7542
7542
  */
7543
+ var AuthenticatorTransport;
7544
+ (function (AuthenticatorTransport) {
7545
+ AuthenticatorTransport["usb"] = "usb";
7546
+ AuthenticatorTransport["nfc"] = "nfc";
7547
+ AuthenticatorTransport["ble"] = "ble";
7548
+ AuthenticatorTransport["smartCard"] = "smart-card";
7549
+ AuthenticatorTransport["hybrid"] = "hybrid";
7550
+ AuthenticatorTransport["internal"] = "internal";
7551
+ })(AuthenticatorTransport || (AuthenticatorTransport = {}));
7543
7552
  class Authenticator {
7544
7553
  constructor() {
7545
7554
  if (env.platform === 'ios' || env.platform === 'android') {
@@ -7664,16 +7673,21 @@ class Authenticator {
7664
7673
  };
7665
7674
  }
7666
7675
  mapPasskeyCreationResponse(response) {
7667
- var _a, _b, _c, _d, _e;
7668
- const prf = (_b = (_a = response.clientExtensionResults) === null || _a === void 0 ? void 0 : _a.prf) !== null && _b !== void 0 ? _b : (_d = (_c = response.extensions) === null || _c === void 0 ? void 0 : _c.clientExtensionResults) === null || _d === void 0 ? void 0 : _d.prf;
7676
+ var _a, _b, _c;
7677
+ // react-native-passkey returns clientExtensionResults at the top level (actual device behaviour),
7678
+ // despite its own TypeScript types nesting it under `extensions.clientExtensionResults`.
7679
+ // Try the actual (top-level) location first, fall back to the typed path.
7680
+ const topLevel = response.clientExtensionResults;
7681
+ const nested = (_a = response.extensions) === null || _a === void 0 ? void 0 : _a.clientExtensionResults;
7682
+ const prf = (_b = topLevel === null || topLevel === void 0 ? void 0 : topLevel.prf) !== null && _b !== void 0 ? _b : nested === null || nested === void 0 ? void 0 : nested.prf;
7683
+ logger.log('SDK::Authenticator::mapPasskeyCreationResponse', { id: response.id, hasPrf: !!prf });
7669
7684
  return {
7670
- id: response.id, // ensure this is Base64URLString
7671
- rawId: response.rawId, // ensure this is Base64URLString
7672
- type: ((_e = response.type) !== null && _e !== void 0 ? _e : 'public-key'),
7685
+ id: response.id,
7686
+ rawId: response.rawId,
7687
+ type: ((_c = response.type) !== null && _c !== void 0 ? _c : 'public-key'),
7673
7688
  response: response.response,
7674
- // this should satisfy the expected extension response.
7675
7689
  clientExtensionResults: {
7676
- credProps: { rk: false },
7690
+ credProps: { rk: true },
7677
7691
  prf,
7678
7692
  },
7679
7693
  };
@@ -7687,7 +7701,7 @@ class Authenticator {
7687
7701
  response: response.response,
7688
7702
  // this should satisfy the expected extension response.
7689
7703
  clientExtensionResults: {
7690
- credProps: { rk: false },
7704
+ credProps: { rk: true },
7691
7705
  prf: (_b = response.clientExtensionResults) === null || _b === void 0 ? void 0 : _b.prf,
7692
7706
  },
7693
7707
  };
@@ -10473,6 +10487,12 @@ class WalletService extends Base {
10473
10487
  const v2EncryptedSeed = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, {
10474
10488
  walletId: input.walletId,
10475
10489
  });
10490
+ const v2EncryptedPrimaryShare = await this.localStorageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare, {
10491
+ walletId: input.walletId,
10492
+ });
10493
+ const v2EncryptedBackupShare = await this.localStorageService.fetch(LocalStorageItems.BackupDeviceKeyShare, {
10494
+ walletId: input.walletId,
10495
+ });
10476
10496
  const clientSalt = await this.authService.getUserSalt();
10477
10497
  const passwordCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
10478
10498
  password: input.password,
@@ -10518,48 +10538,168 @@ class WalletService extends Base {
10518
10538
  },
10519
10539
  getSignature: this.authService.getSignature.bind(this),
10520
10540
  });
10541
+ const prfValue = authentication.prfValue;
10542
+ if (!prfValue || !(prfValue instanceof Uint8Array) || prfValue.length === 0) {
10543
+ logger.error('SDK::WalletService::convertToPasskey::prfValue is required and must be a non-empty Uint8Array');
10544
+ throw new WallabyError({
10545
+ message: 'PRF value from passkey is required to derive credentials and could not be obtained',
10546
+ statusCode: 500,
10547
+ errorCode: ErrorResponseCodes.sdk_passkey_prf_not_available,
10548
+ });
10549
+ }
10521
10550
  logger.log('SDK::WalletService::convertToPasskey::Received authentication response', !!authentication);
10522
10551
  let decryptedSeedPhrase;
10523
- try {
10524
- decryptedSeedPhrase = await this.cipher.displayStoredData({
10525
- storedEncryptedData: safeJsonParse(v2EncryptedSeed),
10526
- encryptedDevicePrivateKey: safeJsonParse(v2EncryptedPriv),
10527
- options: {
10528
- authType: AuthType.Password,
10529
- password: input.password,
10530
- salt: clientSalt,
10531
- },
10532
- });
10552
+ let decryptedPrimaryShare;
10553
+ let decryptedBackupShare;
10554
+ if (v2EncryptedSeed && v2EncryptedPriv) {
10555
+ try {
10556
+ decryptedSeedPhrase = await this.cipher.displayStoredData({
10557
+ storedEncryptedData: safeJsonParse(v2EncryptedSeed),
10558
+ encryptedDevicePrivateKey: safeJsonParse(v2EncryptedPriv),
10559
+ options: {
10560
+ authType: AuthType.Password,
10561
+ password: input.password,
10562
+ salt: clientSalt,
10563
+ },
10564
+ });
10565
+ }
10566
+ catch (error) {
10567
+ logger.error('SDK::WalletService::convertToPasskey::seed_decryption_error', error);
10568
+ }
10533
10569
  }
10534
- catch (error) {
10535
- logger.error('SDK::WalletService::convertToPasskey::error', error);
10536
- decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(input.password, clientSalt);
10537
- if (!decryptedSeedPhrase) {
10538
- throw new WallabyError({
10539
- message: 'Seed phrase on this device could not be decrypted',
10540
- statusCode: 500,
10541
- errorCode: ErrorResponseCodes.sdk_seed_phrase_decryption_failed,
10570
+ if (!decryptedSeedPhrase) {
10571
+ try {
10572
+ decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(input.password, clientSalt);
10573
+ }
10574
+ catch (error) {
10575
+ logger.error('SDK::WalletService::convertToPasskey::v1_seed_decryption_error', error);
10576
+ }
10577
+ }
10578
+ if (v2EncryptedPrimaryShare && v2EncryptedPriv) {
10579
+ try {
10580
+ const parsedPrimaryShare = safeJsonParse(v2EncryptedPrimaryShare);
10581
+ decryptedPrimaryShare = await this.cipher.displayStoredData({
10582
+ storedEncryptedData: parsedPrimaryShare,
10583
+ encryptedDevicePrivateKey: safeJsonParse(v2EncryptedPriv),
10584
+ options: {
10585
+ authType: AuthType.Password,
10586
+ password: input.password,
10587
+ salt: clientSalt,
10588
+ },
10589
+ });
10590
+ }
10591
+ catch (error) {
10592
+ logger.error('SDK::WalletService::convertToPasskey::primary_share_decryption_error', error);
10593
+ }
10594
+ }
10595
+ if (v2EncryptedBackupShare) {
10596
+ try {
10597
+ const parsedBackupShare = safeJsonParse(v2EncryptedBackupShare);
10598
+ // backup key share is wrapped with credentials public key at the outer layer
10599
+ // and wallaby public key at the inner layer, so only one local unwrap is needed.
10600
+ decryptedBackupShare = await this.cipher.decrypt({
10601
+ cipherText: parsedBackupShare,
10602
+ decryptionKey: passwordCredentialsKeyPair.privateKey,
10542
10603
  });
10543
10604
  }
10605
+ catch (error) {
10606
+ logger.error('SDK::WalletService::convertToPasskey::backup_share_decryption_error', error);
10607
+ }
10544
10608
  }
10545
- const importResult = await this.handlers.handleImportWallet({
10546
- publicKey: clientPublicKey,
10547
- privateKey: decryptedClientAuthPrivKey,
10548
- }, {
10549
- authenticationOptions: authentication,
10550
- seedPhrase: decryptedSeedPhrase,
10551
- storeSeedPhrase: false,
10552
- returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10553
- keyShareOptions: {
10554
- threshold: 2,
10555
- numberOfKeyShares: 3,
10556
- numberOfSharesReturned: 2,
10557
- storeOneKeyShareWithWallaby: true,
10558
- },
10609
+ const hasAnyDecryptedShare = !!decryptedPrimaryShare || !!decryptedBackupShare;
10610
+ if (!decryptedSeedPhrase && !hasAnyDecryptedShare) {
10611
+ throw new WallabyError({
10612
+ message: 'Seed phrase or key shares on this device could not be decrypted',
10613
+ statusCode: 500,
10614
+ errorCode: ErrorResponseCodes.sdk_no_valid_seed_option,
10615
+ });
10616
+ }
10617
+ // We only care about the primary share for future local operations.
10618
+ if (decryptedSeedPhrase && !decryptedPrimaryShare) {
10619
+ logger.info('SDK::WalletService::convertToPasskey::No primary share found, importing wallet');
10620
+ await this.handlers.handleImportWallet({
10621
+ publicKey: clientPublicKey,
10622
+ privateKey: decryptedClientAuthPrivKey,
10623
+ }, {
10624
+ authenticationOptions: authentication,
10625
+ seedPhrase: decryptedSeedPhrase,
10626
+ storeSeedPhrase: false,
10627
+ returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10628
+ keyShareOptions: {
10629
+ threshold: 2,
10630
+ numberOfKeyShares: 3,
10631
+ numberOfSharesReturned: 2,
10632
+ storeOneKeyShareWithWallaby: true,
10633
+ },
10634
+ });
10635
+ // Delete the old password-encrypted seed phrase since import stored the new passkey-encrypted version
10636
+ await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
10637
+ logger.info('SDK::WalletService::convertToPasskey::Wallet imported and converted successfully, old seed phrase removed');
10638
+ return { authentication, seedPhrase: decryptedSeedPhrase };
10639
+ }
10640
+ const passkeyDerivedKeyPair = await this.cipher.getCredentialsKeyPair({
10641
+ authType: AuthType.Passkey,
10642
+ prfValue,
10559
10643
  });
10560
- await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
10561
- logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10562
- return Object.assign(Object.assign({}, importResult), { authentication, seedPhrase: decryptedSeedPhrase });
10644
+ const convertedShares = [];
10645
+ if (decryptedPrimaryShare) {
10646
+ const encryptedPrimaryShare = await this.cipher.doubleEncrypt({
10647
+ decryptedData: decryptedPrimaryShare,
10648
+ credentialsKeyPair: passkeyDerivedKeyPair,
10649
+ deviceKeyPair: {
10650
+ publicKey: clientPublicKey,
10651
+ privateKey: decryptedClientAuthPrivKey,
10652
+ },
10653
+ });
10654
+ convertedShares.push({
10655
+ key: V2KeyNames.PrimaryDeviceKeyShare,
10656
+ value: encryptedPrimaryShare,
10657
+ walletId: input.walletId,
10658
+ });
10659
+ }
10660
+ if (decryptedBackupShare) {
10661
+ // Since this is only decrypted once, we only need passkey credential encryption.
10662
+ const encryptedBackupShare = await this.cipher.encrypt({
10663
+ data: decryptedBackupShare,
10664
+ encryptionKey: passkeyDerivedKeyPair.publicKey,
10665
+ });
10666
+ convertedShares.push({
10667
+ key: V2KeyNames.BackupDeviceKeyShare,
10668
+ value: encryptedBackupShare,
10669
+ walletId: input.walletId,
10670
+ });
10671
+ }
10672
+ await this.localStorageService.saveInBulk(convertedShares);
10673
+ if (v2EncryptedSeed) {
10674
+ await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
10675
+ logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10676
+ }
10677
+ if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10678
+ const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10679
+ data: decryptedPrimaryShare,
10680
+ encryptionKey: authentication.user.wallabyAuthPubKey,
10681
+ });
10682
+ const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10683
+ walletId: input.walletId,
10684
+ encryptedKeyShares: [flippedEncryptedPrimaryShare],
10685
+ deviceAuthKeys: {
10686
+ publicKey: clientPublicKey,
10687
+ privateKey: decryptedClientAuthPrivKey,
10688
+ },
10689
+ });
10690
+ decryptedSeedPhrase = await this.cipher.decrypt({
10691
+ cipherText: reconstructedSeedPhrase,
10692
+ decryptionKey: decryptedClientAuthPrivKey,
10693
+ });
10694
+ }
10695
+ if (!decryptedSeedPhrase) {
10696
+ throw new WallabyError({
10697
+ message: 'Seed phrase could not be reconstructed from the provided shares',
10698
+ statusCode: 500,
10699
+ errorCode: ErrorResponseCodes.sdk_no_valid_seed_option,
10700
+ });
10701
+ }
10702
+ return { authentication, seedPhrase: decryptedSeedPhrase };
10563
10703
  }
10564
10704
  catch (error) {
10565
10705
  logger.error('SDK::WalletService::convertToPasskey::error', error);
@@ -10879,7 +11019,7 @@ class WalletDataService extends Base {
10879
11019
  /**
10880
11020
  * Updates a wallet asset.
10881
11021
  *
10882
- * @param {string} params.assetConfigId - Config ID for the user asset.
11022
+ * @param {string} params.configId - Config ID for the user asset.
10883
11023
  * @param {string} params.walletId - Wallet ID to which the asset belongs.
10884
11024
  * @param {string} params.assetName - Asset name.
10885
11025
  * @param {boolean} params.isVisible - Asset visibility toggle.
@@ -10890,19 +11030,19 @@ class WalletDataService extends Base {
10890
11030
  * @throws {Error} If required parameters are missing or invalid.
10891
11031
  */
10892
11032
  async updateAsset(_a) {
10893
- var { assetConfigId, walletId } = _a, assetConfig = __rest(_a, ["assetConfigId", "walletId"]);
11033
+ var { configId, walletId } = _a, assetConfig = __rest(_a, ["configId", "walletId"]);
10894
11034
  try {
10895
- if (!assetConfig.configId || !walletId) {
11035
+ if (!configId || !walletId) {
10896
11036
  throw new WallabyError({
10897
11037
  message: 'Missing required parameters',
10898
11038
  statusCode: 400,
10899
11039
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
10900
11040
  });
10901
11041
  }
10902
- const response = await this.api.wallets.updateUserAsset({
10903
- configId: assetConfig.configId || assetConfigId,
10904
- walletId: walletId,
10905
- }, Object.assign({ walletId }, assetConfig));
11042
+ const response = await this.request(WalletRoutes.updateAsset, {
11043
+ payload: Object.assign({ configId,
11044
+ walletId }, assetConfig),
11045
+ });
10906
11046
  return response;
10907
11047
  }
10908
11048
  catch (error) {