wallaby-cash 2.3.6 → 2.3.7

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
@@ -1,12 +1,11 @@
1
1
  import * as algosdk from 'algosdk';
2
2
  import * as bip39 from 'bip39';
3
+ import { v4 } from 'uuid';
3
4
  import log from 'loglevel';
4
5
  import { AES, enc } from 'crypto-js';
5
6
  import { jwtDecode } from 'jwt-decode';
6
7
  import * as NativeWebAuthn from 'react-native-passkey';
7
- import { omit } from 'lodash';
8
8
  import { atob, toUint8Array } from 'js-base64';
9
- import { v4 } from 'uuid';
10
9
 
11
10
  /******************************************************************************
12
11
  Copyright (c) Microsoft Corporation.
@@ -266,7 +265,6 @@ var LocalStorageItems;
266
265
  LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
267
266
  LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
268
267
  LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
269
- LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
270
268
  LocalStorageItems["ClientAuthToken"] = "republic-jwt";
271
269
  LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
272
270
  LocalStorageItems["Blob"] = "blob";
@@ -577,7 +575,7 @@ const env = {
577
575
  isNative: false,
578
576
  isWeb,
579
577
  };
580
- const currentPackageVersion = "2.3.6" ;
578
+ const currentPackageVersion = "2.3.7" ;
581
579
 
582
580
  /**
583
581
  * Storage keys adapter for Storage interface across different platforms.
@@ -4909,43 +4907,6 @@ class StorageService {
4909
4907
  }
4910
4908
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4911
4909
  }
4912
- /**
4913
- *
4914
- * Stores Wallaby auth public key to local storage
4915
- * @param wallabyAuthPubKey
4916
- */
4917
- async setWallabyAuthPubKey(wallabyAuthPubKey) {
4918
- await this.save(V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4919
- }
4920
- /**
4921
- *
4922
- * Fetches Wallaby auth public key from local storage
4923
- * @returns { string | undefined } Wallaby Auth Public key or undefined.
4924
- */
4925
- async getWallabyAuthPubKey() {
4926
- let wallabyAuthPubKey = await this.fetch(V2KeyNames.WallabyAuthPubKey);
4927
- if (wallabyAuthPubKey) {
4928
- return wallabyAuthPubKey;
4929
- }
4930
- // Legacy key migration
4931
- const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4932
- const legacyPubKey = await this.getItem(legacyKey);
4933
- if (legacyPubKey) {
4934
- wallabyAuthPubKey = legacyPubKey;
4935
- }
4936
- else {
4937
- const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4938
- const v1PubKey = await this.getItem(v1Key);
4939
- if (v1PubKey) {
4940
- wallabyAuthPubKey = v1PubKey;
4941
- }
4942
- }
4943
- if (wallabyAuthPubKey) {
4944
- await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4945
- return wallabyAuthPubKey;
4946
- }
4947
- return undefined;
4948
- }
4949
4910
  /**
4950
4911
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4951
4912
  * Encrypts and stores device auth private key
@@ -5154,7 +5115,15 @@ class StorageService {
5154
5115
  return undefined;
5155
5116
  }
5156
5117
  async clearLocalStorage(walletId) {
5157
- const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5118
+ const userKeysToRemove = [
5119
+ LocalStorageItems.AccessToken,
5120
+ V2KeyNames.EncryptedDevicePrivateKey,
5121
+ V2KeyNames.WallabyAuthPubKey,
5122
+ V2KeyNames.PasskeyCredential,
5123
+ V2KeyNames.MigrationVersion,
5124
+ V2KeyNames.LastMigratedAt,
5125
+ V2KeyNames.ClientAuthToken,
5126
+ ];
5158
5127
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5159
5128
  if (walletId) {
5160
5129
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6320,16 +6289,6 @@ class Api {
6320
6289
  * @secure
6321
6290
  */
6322
6291
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6323
- /**
6324
- * No description
6325
- *
6326
- * @tags Transactions, Query
6327
- * @name FetchTransactionByHashOrReference
6328
- * @summary Fetch transaction status data using a reference or transaction hash
6329
- * @request GET:/api/v1/transactions/status
6330
- * @secure
6331
- */
6332
- fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6333
6292
  /**
6334
6293
  * @description The sign and broadcast transaction API was designed and implemented specifically for uses cases where the caller has their own custom raw transaction that is not yet currently supported by Wallaby
6335
6294
  *
@@ -6340,6 +6299,16 @@ class Api {
6340
6299
  * @secure
6341
6300
  */
6342
6301
  signAndBroadcastRawTx: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/sign-broadcast-rawtx`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
6302
+ /**
6303
+ * No description
6304
+ *
6305
+ * @tags Transactions, Query
6306
+ * @name FetchTransactionByHashOrReference
6307
+ * @summary Fetch transaction status data using a reference or transaction hash
6308
+ * @request GET:/api/v1/transactions/status
6309
+ * @secure
6310
+ */
6311
+ fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6343
6312
  /**
6344
6313
  * No description
6345
6314
  *
@@ -7377,6 +7346,13 @@ const SwapRoutes = {
7377
7346
  },
7378
7347
  };
7379
7348
 
7349
+ function omit(obj, keys) {
7350
+ if (!obj)
7351
+ return {};
7352
+ const keysSet = new Set(keys);
7353
+ return Object.fromEntries(Object.entries(obj).filter(([k]) => !keysSet.has(k)));
7354
+ }
7355
+
7380
7356
  /**
7381
7357
  * React Native Authenticator Implementation
7382
7358
  *
@@ -7620,7 +7596,7 @@ let PasskeyService$1 = class PasskeyService {
7620
7596
  this.authenticator = new Authenticator();
7621
7597
  }
7622
7598
  preparePasskeyRequestOptions(options) {
7623
- var _a, _b, _c, _d, _e, _f;
7599
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7624
7600
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7625
7601
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7626
7602
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7628,11 +7604,13 @@ let PasskeyService$1 = class PasskeyService {
7628
7604
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7629
7605
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7630
7606
  : undefined;
7631
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7632
- eval: {
7633
- first: prfExtensionEvaluation,
7634
- },
7635
- } }) });
7607
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
7608
+ ? {
7609
+ eval: {
7610
+ first: prfExtensionEvaluation,
7611
+ },
7612
+ }
7613
+ : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7636
7614
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7637
7615
  // While the authenticator still works with the prf and would return the response (if any),
7638
7616
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7640,7 +7618,7 @@ let PasskeyService$1 = class PasskeyService {
7640
7618
  return parsedOptions;
7641
7619
  }
7642
7620
  preparePasskeyCreationOptions(options) {
7643
- var _a, _b, _c, _d, _e, _f;
7621
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7644
7622
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7645
7623
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7646
7624
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7648,12 +7626,8 @@ let PasskeyService$1 = class PasskeyService {
7648
7626
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7649
7627
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7650
7628
  : undefined;
7651
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7652
- eval: {
7653
- first: prfExtensionEvaluation,
7654
- },
7655
- } }) });
7656
- logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7629
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined ? { eval: { first: prfExtensionEvaluation } } : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7630
+ logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
7657
7631
  return parsedOptions;
7658
7632
  }
7659
7633
  /**
@@ -7668,7 +7642,10 @@ let PasskeyService$1 = class PasskeyService {
7668
7642
  let passkeyCredential;
7669
7643
  let signInResponse;
7670
7644
  try {
7671
- const registrationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
7645
+ const registrationChallengeResponse = await getSignature({
7646
+ deviceAuthKeys: deviceKeyPair,
7647
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
7648
+ });
7672
7649
  if (!registrationChallengeResponse.registrationOptions)
7673
7650
  throw new WallabyError({
7674
7651
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7711,7 +7688,10 @@ let PasskeyService$1 = class PasskeyService {
7711
7688
  catch (error) {
7712
7689
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7713
7690
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7714
- const authenticationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
7691
+ const authenticationChallengeResponse = await getSignature({
7692
+ deviceAuthKeys: deviceKeyPair,
7693
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
7694
+ });
7715
7695
  if (!authenticationChallengeResponse.authenticationOptions)
7716
7696
  throw new WallabyError({
7717
7697
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7782,9 +7762,10 @@ let PasskeyService$1 = class PasskeyService {
7782
7762
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7783
7763
  });
7784
7764
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7785
- const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
7765
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7766
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7786
7767
  eval: {
7787
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7768
+ first: prfFirst,
7788
7769
  },
7789
7770
  } }) });
7790
7771
  const passkeyCredential = await this.authenticator.authenticate({
@@ -8011,10 +7992,6 @@ let PasskeyService$1 = class PasskeyService {
8011
7992
  key: LocalStorageItems.AccessToken,
8012
7993
  value: authenticationResponse.accessToken,
8013
7994
  },
8014
- {
8015
- key: LocalStorageItems.WallabyAuthPubKey,
8016
- value: authenticationResponse.user.wallabyAuthPubKey,
8017
- },
8018
7995
  ]);
8019
7996
  }
8020
7997
  /**
@@ -8234,13 +8211,14 @@ class AuthService extends Base {
8234
8211
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8235
8212
  * @returns the messaged, the hash, and the signature using the passed private key.
8236
8213
  */
8237
- async getSignature(deviceAuthKeys, passkeyChallengeType) {
8214
+ async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8238
8215
  try {
8239
8216
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8240
8217
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : PasskeyChallengeType.REGISTRATION;
8241
8218
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8242
8219
  const response = await this.request(AuthRoutes.signatureMessage, {
8243
8220
  payload: {
8221
+ walletId,
8244
8222
  clientAuthPubKey: deviceAuthKeys.publicKey,
8245
8223
  passkeyChallengeType: challengeType,
8246
8224
  },
@@ -8271,7 +8249,10 @@ class AuthService extends Base {
8271
8249
  logger.info('key pair generated', !!deviceKeyPair);
8272
8250
  let authentication;
8273
8251
  try {
8274
- const signatureMessageResponse = await this.getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
8252
+ const signatureMessageResponse = await this.getSignature({
8253
+ deviceAuthKeys: deviceKeyPair,
8254
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
8255
+ });
8275
8256
  logger.info('signature has been generated', !!signatureMessageResponse);
8276
8257
  switch (this.deviceAuthType) {
8277
8258
  case AuthType.Passkey:
@@ -8304,7 +8285,10 @@ class AuthService extends Base {
8304
8285
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8305
8286
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8306
8287
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8307
- const newChallenge = await this.getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
8288
+ const newChallenge = await this.getSignature({
8289
+ deviceAuthKeys: deviceKeyPair,
8290
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8291
+ });
8308
8292
  authentication = await this.passkeyService.authenticate({
8309
8293
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8310
8294
  challengeResponse: newChallenge,
@@ -8341,10 +8325,7 @@ class AuthService extends Base {
8341
8325
  errorCode: ErrorResponseCodes.sdk_invalid_parameter,
8342
8326
  });
8343
8327
  }
8344
- await this.localStorageService.saveInBulk([
8345
- { key: LocalStorageItems.AccessToken, value: authentication.accessToken },
8346
- { key: LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8347
- ]);
8328
+ await this.localStorageService.save(LocalStorageItems.AccessToken, authentication.accessToken);
8348
8329
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8349
8330
  }
8350
8331
  catch (error) {
@@ -8420,7 +8401,9 @@ class AuthService extends Base {
8420
8401
  },
8421
8402
  credentialsKeyPair,
8422
8403
  });
8423
- const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8404
+ const signatureMessage = await this.getSignature({
8405
+ deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8406
+ });
8424
8407
  const authentication = await this.request(AuthRoutes.signIn, {
8425
8408
  payload: {
8426
8409
  externalUserId: this.userId,
@@ -8544,10 +8527,6 @@ class AuthService extends Base {
8544
8527
  key: LocalStorageItems.AccessToken,
8545
8528
  value: authResponse.accessToken,
8546
8529
  },
8547
- {
8548
- key: LocalStorageItems.WallabyAuthPubKey,
8549
- value: authResponse.user.wallabyAuthPubKey,
8550
- },
8551
8530
  ]);
8552
8531
  return authResponse;
8553
8532
  });
@@ -8632,12 +8611,16 @@ class WalletHandlersService extends Base {
8632
8611
  this.userId = config.userId;
8633
8612
  }
8634
8613
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8635
- var _a, _b, _c, _d;
8614
+ var _a, _b, _c, _d, _e;
8636
8615
  try {
8637
- const { signature, message } = await this.authService.getSignature({
8638
- publicKey: deviceAuthKeys.publicKey,
8639
- privateKey: deviceAuthKeys.privateKey,
8640
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
8616
+ // Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
8617
+ // However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
8618
+ // Using the reference as the fallback for the walletId in this case.
8619
+ const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
8620
+ walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
8621
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8622
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
8623
+ });
8641
8624
  if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8642
8625
  importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8643
8626
  !importWalletInput.keyShareOptions) {
@@ -8647,7 +8630,7 @@ class WalletHandlersService extends Base {
8647
8630
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
8648
8631
  });
8649
8632
  }
8650
- const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8633
+ const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8651
8634
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8652
8635
  throw new WallabyError({
8653
8636
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8657,10 +8640,11 @@ class WalletHandlersService extends Base {
8657
8640
  }
8658
8641
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8659
8642
  data: importWalletInput.seedPhrase,
8660
- encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8643
+ encryptionKey: wallabyAuthPubKey,
8661
8644
  });
8662
8645
  const importWalletPayload = {
8663
- reference: v4(),
8646
+ reference: importWalletInput.reference,
8647
+ walletId: importWalletInput.walletId,
8664
8648
  message,
8665
8649
  signature,
8666
8650
  encryptedSeed: readyForTransportSeedPhrase,
@@ -8669,7 +8653,7 @@ class WalletHandlersService extends Base {
8669
8653
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8670
8654
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8671
8655
  walletOwnershipType: WalletOwnershipType.SingleOwner,
8672
- wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8656
+ wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8673
8657
  };
8674
8658
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8675
8659
  payload: importWalletPayload,
@@ -8707,7 +8691,7 @@ class WalletHandlersService extends Base {
8707
8691
  }
8708
8692
  catch (error) {
8709
8693
  throw new WallabyError({
8710
- message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8694
+ message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8711
8695
  statusCode: error.statusCode,
8712
8696
  errorCode: error.errorCode,
8713
8697
  data: error.data,
@@ -8729,9 +8713,9 @@ class WalletHandlersService extends Base {
8729
8713
  var _a, _b, _c, _d, _e, _f;
8730
8714
  try {
8731
8715
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8732
- publicKey: deviceAuthKeys.publicKey,
8733
- privateKey: deviceAuthKeys.privateKey,
8734
- }, PasskeyChallengeType.AUTHENTICATION);
8716
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8717
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8718
+ });
8735
8719
  if ((walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8736
8720
  walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8737
8721
  !walletCreationInput.keyShareOptions) {
@@ -8908,36 +8892,6 @@ class WalletHandlersService extends Base {
8908
8892
  });
8909
8893
  }
8910
8894
  }
8911
- /**
8912
- *
8913
- * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8914
- * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8915
- * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8916
- * @description This function constructs the seed phrase from encrypted key shares.
8917
- * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8918
- * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8919
- * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8920
- */
8921
- async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8922
- try {
8923
- const { signature, message } = await this.authService.getSignature(deviceAuthKeys, PasskeyChallengeType.AUTHENTICATION);
8924
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8925
- payload: {
8926
- walletId: walletId,
8927
- signature,
8928
- message,
8929
- clientAuthPubKey: deviceAuthKeys.publicKey,
8930
- recoveryPubKey: deviceAuthKeys.publicKey,
8931
- encryptedShares: encryptedKeyShares,
8932
- },
8933
- });
8934
- return retrieveSeedPhraseResponse.encryptedSeed;
8935
- }
8936
- catch (error) {
8937
- logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8938
- return Promise.reject(error);
8939
- }
8940
- }
8941
8895
  }
8942
8896
 
8943
8897
  class WalletService extends Base {
@@ -9047,7 +9001,6 @@ class WalletService extends Base {
9047
9001
  */
9048
9002
  async export({ walletId, authenticationOptions, exportOptions }) {
9049
9003
  try {
9050
- const { user: { wallabyAuthPubKey }, } = authenticationOptions;
9051
9004
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
9052
9005
  throw new WallabyError({
9053
9006
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9157,10 +9110,20 @@ class WalletService extends Base {
9157
9110
  });
9158
9111
  }
9159
9112
  const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
9113
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9114
+ const deviceAuthKeys = {
9115
+ publicKey: deviceAuthPublicKey,
9116
+ privateKey: decryptedDevicePrivateKey,
9117
+ };
9118
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9119
+ deviceAuthKeys,
9120
+ walletId,
9121
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9122
+ });
9160
9123
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9161
9124
  storedEncryptedData: parsedPrimaryShare,
9162
9125
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9163
- wallabyPublicKey: wallabyAuthPubKey,
9126
+ wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9164
9127
  options: {
9165
9128
  authType: this.deviceAuthType,
9166
9129
  password: authenticationOptions.password,
@@ -9168,17 +9131,18 @@ class WalletService extends Base {
9168
9131
  prfValue: authenticationOptions.prfValue,
9169
9132
  },
9170
9133
  });
9171
- const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9172
- const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9173
- encryptedKeyShares: [wallabyBoundPrimaryShare],
9174
- walletId,
9175
- deviceAuthKeys: {
9176
- publicKey: deviceAuthPublicKey,
9177
- privateKey: decryptedDevicePrivateKey,
9134
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9135
+ payload: {
9136
+ walletId: walletId,
9137
+ signature,
9138
+ message,
9139
+ clientAuthPubKey: deviceAuthKeys.publicKey,
9140
+ recoveryPubKey: deviceAuthKeys.publicKey,
9141
+ encryptedShares: [wallabyBoundPrimaryShare],
9178
9142
  },
9179
9143
  });
9180
9144
  decryptedSeedPhrase = await this.cipher.decrypt({
9181
- cipherText: encryptedReconstructedSeedPhrase,
9145
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9182
9146
  decryptionKey: decryptedDevicePrivateKey,
9183
9147
  });
9184
9148
  if (exportOptions.algorandSeedPhrase) {
@@ -9216,7 +9180,9 @@ class WalletService extends Base {
9216
9180
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9217
9181
  */
9218
9182
  async import(input) {
9183
+ var _a;
9219
9184
  try {
9185
+ const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : v4();
9220
9186
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9221
9187
  if (!encryptedDevicePrivateKey) {
9222
9188
  throw new WallabyError({
@@ -9247,7 +9213,7 @@ class WalletService extends Base {
9247
9213
  const importRequest = await this.handlers.handleImportWallet({
9248
9214
  publicKey: clientAuthPubKey,
9249
9215
  privateKey: decryptedDevicePrivateKey,
9250
- }, input);
9216
+ }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9251
9217
  return importRequest;
9252
9218
  }
9253
9219
  catch (error) {
@@ -9261,11 +9227,15 @@ class WalletService extends Base {
9261
9227
  *
9262
9228
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9263
9229
  * @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
9230
+ *
9231
+ * @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
9232
+ * Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
9264
9233
  */
9265
9234
  async recover(input) {
9266
9235
  var _a, _b;
9267
9236
  try {
9268
- const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9237
+ const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9238
+ input.authenticationOptions.user.wallabyAuthPubKey;
9269
9239
  const deviceAuthKeyPair = createIdentity();
9270
9240
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9271
9241
  authType: this.deviceAuthType,
@@ -9305,27 +9275,37 @@ class WalletService extends Base {
9305
9275
  return recoverWithSeedPhraseResponse;
9306
9276
  }
9307
9277
  else if (input.decryptedShares) {
9308
- const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9309
- const encrypted = await this.cipher.encrypt({
9310
- data: decryptedShare,
9311
- encryptionKey: wallabyPublicKey,
9312
- });
9313
- return encrypted;
9314
- }));
9315
- if (!encryptedShares.length) {
9278
+ if (!input.decryptedShares.length) {
9316
9279
  throw new WallabyError({
9317
9280
  message: 'Decrypted shares are required',
9318
9281
  statusCode: 400,
9319
9282
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
9320
9283
  });
9321
9284
  }
9322
- const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9323
- encryptedKeyShares: encryptedShares,
9285
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9324
9286
  deviceAuthKeys: deviceAuthKeyPair,
9325
9287
  walletId: input.walletId,
9288
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9289
+ });
9290
+ const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9291
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9292
+ return await this.cipher.encrypt({
9293
+ data: decryptedShare,
9294
+ encryptionKey: transportEncryptionKey,
9295
+ });
9296
+ }));
9297
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9298
+ payload: {
9299
+ walletId: input.walletId,
9300
+ signature,
9301
+ message,
9302
+ clientAuthPubKey: deviceAuthKeyPair.publicKey,
9303
+ recoveryPubKey: deviceAuthKeyPair.publicKey,
9304
+ encryptedShares,
9305
+ },
9326
9306
  });
9327
9307
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9328
- cipherText: encryptedSeed,
9308
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9329
9309
  decryptionKey: deviceAuthKeyPair.privateKey,
9330
9310
  encryptionKey: wallabyPublicKey,
9331
9311
  });
@@ -9383,17 +9363,9 @@ class WalletService extends Base {
9383
9363
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9384
9364
  try {
9385
9365
  const signatureMessage = await this.authService.getSignature({
9386
- publicKey: deviceAuthKeys.publicKey,
9387
- privateKey: deviceAuthKeys.privateKey,
9388
- });
9389
- // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9390
- // payload: {
9391
- // walletId,
9392
- // signature: signatureMessage.signature,
9393
- // message: signatureMessage.message,
9394
- // clientAuthPubKey: deviceAuthKeys.publicKey,
9395
- // },
9396
- // });
9366
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9367
+ walletId,
9368
+ });
9397
9369
  const response = await this.api.wallets.retrieveShares({
9398
9370
  walletId: walletId,
9399
9371
  signature: signatureMessage.signature,
@@ -9574,6 +9546,7 @@ class WalletService extends Base {
9574
9546
  */
9575
9547
  async initAddNewDevice(input) {
9576
9548
  const { walletId, backupUrl, authenticationOptions } = input;
9549
+ const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9577
9550
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9578
9551
  if (!encryptedDevicePrivateKey) {
9579
9552
  throw new WallabyError({
@@ -9634,7 +9607,7 @@ class WalletService extends Base {
9634
9607
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9635
9608
  storedEncryptedData: parsedPrimaryShare,
9636
9609
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9637
- wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9610
+ wallabyPublicKey,
9638
9611
  options: {
9639
9612
  authType: this.deviceAuthType,
9640
9613
  password: authenticationOptions.password,
@@ -9693,22 +9666,11 @@ class WalletService extends Base {
9693
9666
  }
9694
9667
  const devicePublicKey = (_a = (await this.localStorageService.fetch(LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9695
9668
  const signatureMessage = await this.authService.getSignature({
9696
- publicKey: devicePublicKey,
9697
- privateKey: decryptedDevicePrivateKey,
9698
- }, PasskeyChallengeType.REGISTRATION);
9699
- // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9700
- // payload: {
9701
- // walletId: input.walletId,
9702
- // message: signatureMessage.message,
9703
- // signature: signatureMessage.signature,
9704
- // clientAuthPubKey: devicePublicKey,
9705
- // share: {
9706
- // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9707
- // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9708
- // type: KeyTypeName.OwnerBackupDeviceShare,
9709
- // },
9710
- // },
9711
- // });
9669
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
9670
+ walletId: input.walletId,
9671
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
9672
+ });
9673
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9712
9674
  const backUpResponse = await this.api.wallets.addNewDevice({
9713
9675
  walletId: input.walletId,
9714
9676
  message: signatureMessage.message,
@@ -9716,7 +9678,7 @@ class WalletService extends Base {
9716
9678
  clientAuthPubKey: devicePublicKey,
9717
9679
  share: {
9718
9680
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9719
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9681
+ wrappingPublicKey: wallabyPublicKey,
9720
9682
  type: KeyTypeName.OwnerBackupDeviceShare,
9721
9683
  },
9722
9684
  });
@@ -9724,7 +9686,8 @@ class WalletService extends Base {
9724
9686
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9725
9687
  {
9726
9688
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9727
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9689
+ wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9690
+ input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9728
9691
  type: KeyTypeName.OwnerMainDeviceShare,
9729
9692
  },
9730
9693
  ];
@@ -9781,12 +9744,28 @@ class WalletService extends Base {
9781
9744
  });
9782
9745
  }
9783
9746
  const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
9747
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9748
+ authType: this.deviceAuthType,
9749
+ password: input.authenticationOptions.password,
9750
+ salt: input.authenticationOptions.clientSalt,
9751
+ prfValue: input.authenticationOptions.prfValue,
9752
+ });
9753
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9754
+ cipherText: parsedDevicePrivateKey,
9755
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9756
+ });
9757
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9758
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9759
+ deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
9760
+ walletId,
9761
+ });
9762
+ const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9784
9763
  if (storedSeedPhrase) {
9785
9764
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9786
9765
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9787
9766
  storedEncryptedData: parsedStoredSeedPhrase,
9788
9767
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9789
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9768
+ wallabyPublicKey,
9790
9769
  options: {
9791
9770
  authType: this.deviceAuthType,
9792
9771
  password: input.authenticationOptions.password,
@@ -9800,7 +9779,7 @@ class WalletService extends Base {
9800
9779
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9801
9780
  storedEncryptedData: parsedPrimaryKeyShare,
9802
9781
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9803
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9782
+ wallabyPublicKey,
9804
9783
  options: {
9805
9784
  authType: this.deviceAuthType,
9806
9785
  password: input.authenticationOptions.password,
@@ -9816,21 +9795,6 @@ class WalletService extends Base {
9816
9795
  errorCode: 'sdk_private_key_not_found',
9817
9796
  });
9818
9797
  }
9819
- const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9820
- authType: this.deviceAuthType,
9821
- password: input.authenticationOptions.password,
9822
- salt: input.authenticationOptions.clientSalt,
9823
- prfValue: input.authenticationOptions.prfValue,
9824
- });
9825
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9826
- cipherText: parsedDevicePrivateKey,
9827
- decryptionKey: derivedCredentialsKeyPair.privateKey,
9828
- });
9829
- const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9830
- const { signature, message } = await this.authService.getSignature({
9831
- privateKey: decryptedDevicePrivateKey,
9832
- publicKey: devicePublicKey,
9833
- });
9834
9798
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9835
9799
  payload: {
9836
9800
  walletId,
@@ -10022,8 +9986,8 @@ class WalletService extends Base {
10022
9986
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
10023
9987
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
10024
9988
  const signInSignatureMessage = await this.authService.getSignature({
10025
- publicKey: devicePublicKey,
10026
- privateKey: decryptedPrivateKey,
9989
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9990
+ walletId,
10027
9991
  });
10028
9992
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
10029
9993
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -10049,7 +10013,6 @@ class WalletService extends Base {
10049
10013
  // Store authentication tokens
10050
10014
  await this.localStorageService.saveInBulk([
10051
10015
  { key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
10052
- { key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
10053
10016
  { key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
10054
10017
  { key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
10055
10018
  ]);
@@ -10112,8 +10075,8 @@ class WalletService extends Base {
10112
10075
  throw error;
10113
10076
  }
10114
10077
  }
10115
- async clearDevice() {
10116
- await this.localStorageService.clearLocalStorage();
10078
+ async clearDevice({ walletId }) {
10079
+ await this.localStorageService.clearLocalStorage(walletId);
10117
10080
  }
10118
10081
  /**
10119
10082
  * Prepares authentication data and encrypted payload for any request.
@@ -10150,9 +10113,11 @@ class WalletService extends Base {
10150
10113
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10151
10114
  // Get signature message
10152
10115
  const signatureMessage = await this.authService.getSignature({
10153
- publicKey: deviceAuthPublicKey,
10154
- privateKey: decryptedDevicePrivateKey,
10155
- }, PasskeyChallengeType.AUTHENTICATION);
10116
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
10117
+ walletId,
10118
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10119
+ });
10120
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10156
10121
  // Prepare encrypted data (seed phrase or key shares)
10157
10122
  const sharesEncryptedWithWallabyPubKey = [];
10158
10123
  let readyForTransportSeedPhrase = undefined;
@@ -10172,7 +10137,7 @@ class WalletService extends Base {
10172
10137
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10173
10138
  storedEncryptedData: parsedSeedPhrase,
10174
10139
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10175
- wallabyPublicKey: user.wallabyAuthPubKey,
10140
+ wallabyPublicKey,
10176
10141
  options: {
10177
10142
  authType: this.deviceAuthType,
10178
10143
  password,
@@ -10187,7 +10152,7 @@ class WalletService extends Base {
10187
10152
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10188
10153
  storedEncryptedData: parsedPrimaryShare,
10189
10154
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10190
- wallabyPublicKey: user.wallabyAuthPubKey,
10155
+ wallabyPublicKey,
10191
10156
  options: {
10192
10157
  authType: this.deviceAuthType,
10193
10158
  password,
@@ -10356,6 +10321,7 @@ class WalletService extends Base {
10356
10321
  seedPhrase: decryptedSeedPhrase,
10357
10322
  storeSeedPhrase: false,
10358
10323
  returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10324
+ walletId: input.walletId,
10359
10325
  keyShareOptions: {
10360
10326
  threshold: 2,
10361
10327
  numberOfKeyShares: 3,
@@ -10406,20 +10372,31 @@ class WalletService extends Base {
10406
10372
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10407
10373
  }
10408
10374
  if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10375
+ const deviceAuthKeys = {
10376
+ publicKey: clientPublicKey,
10377
+ privateKey: decryptedClientAuthPrivKey,
10378
+ };
10379
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
10380
+ deviceAuthKeys,
10381
+ walletId: input.walletId,
10382
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10383
+ });
10409
10384
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10410
10385
  data: decryptedPrimaryShare,
10411
- encryptionKey: authentication.user.wallabyAuthPubKey,
10386
+ encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10412
10387
  });
10413
- const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10414
- walletId: input.walletId,
10415
- encryptedKeyShares: [flippedEncryptedPrimaryShare],
10416
- deviceAuthKeys: {
10417
- publicKey: clientPublicKey,
10418
- privateKey: decryptedClientAuthPrivKey,
10388
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
10389
+ payload: {
10390
+ walletId: input.walletId,
10391
+ signature,
10392
+ message,
10393
+ clientAuthPubKey: deviceAuthKeys.publicKey,
10394
+ recoveryPubKey: deviceAuthKeys.publicKey,
10395
+ encryptedShares: [flippedEncryptedPrimaryShare],
10419
10396
  },
10420
10397
  });
10421
10398
  decryptedSeedPhrase = await this.cipher.decrypt({
10422
- cipherText: reconstructedSeedPhrase,
10399
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10423
10400
  decryptionKey: decryptedClientAuthPrivKey,
10424
10401
  });
10425
10402
  }
@@ -10526,7 +10503,7 @@ class WalletDataService extends Base {
10526
10503
  * Note: Either chainName or tokenStandard must be provided.
10527
10504
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10528
10505
  */
10529
- async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10506
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10530
10507
  try {
10531
10508
  if (!tokensAndAddressesList.length) {
10532
10509
  throw new WallabyError({
@@ -11283,9 +11260,11 @@ class Swap extends Base {
11283
11260
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11284
11261
  // Get signature message
11285
11262
  const signatureMessage = await this.authService.getSignature({
11286
- publicKey: deviceAuthPublicKey,
11287
- privateKey: decryptedDevicePrivateKey,
11288
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11263
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11264
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11265
+ walletId,
11266
+ });
11267
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11289
11268
  // Prepare encrypted data (seed phrase or key shares)
11290
11269
  const sharesEncryptedWithWallabyPubKey = [];
11291
11270
  let readyForTransportSeedPhrase = undefined;
@@ -11306,7 +11285,7 @@ class Swap extends Base {
11306
11285
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11307
11286
  storedEncryptedData: parsedSeedPhrase,
11308
11287
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11309
- wallabyPublicKey: user.wallabyAuthPubKey,
11288
+ wallabyPublicKey,
11310
11289
  options: {
11311
11290
  authType: this.deviceAuthType,
11312
11291
  password,
@@ -11321,7 +11300,7 @@ class Swap extends Base {
11321
11300
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11322
11301
  storedEncryptedData: parsedPrimaryShare,
11323
11302
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11324
- wallabyPublicKey: user.wallabyAuthPubKey,
11303
+ wallabyPublicKey,
11325
11304
  options: {
11326
11305
  authType: this.deviceAuthType,
11327
11306
  password,
@@ -11576,7 +11555,7 @@ class Transactions extends Base {
11576
11555
  * @param {BlockchainName} blockchain
11577
11556
  * @returns {FeeEstimateRequest}
11578
11557
  */
11579
- async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11558
+ async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11580
11559
  try {
11581
11560
  const response = await this.request(TransactionsRoutes.estimateFee, {
11582
11561
  queryParams: {
@@ -11919,9 +11898,11 @@ class Transactions extends Base {
11919
11898
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11920
11899
  // Get signature message
11921
11900
  const signatureMessage = await this.authService.getSignature({
11922
- publicKey: deviceAuthPublicKey,
11923
- privateKey: decryptedDevicePrivateKey,
11924
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11901
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11902
+ walletId,
11903
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11904
+ });
11905
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11925
11906
  // Prepare encrypted data (seed phrase or key shares)
11926
11907
  const sharesEncryptedWithWallabyPubKey = [];
11927
11908
  let readyForTransportSeedPhrase = undefined;
@@ -11942,7 +11923,7 @@ class Transactions extends Base {
11942
11923
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11943
11924
  storedEncryptedData: parsedSeedPhrase,
11944
11925
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11945
- wallabyPublicKey: user.wallabyAuthPubKey,
11926
+ wallabyPublicKey,
11946
11927
  options: {
11947
11928
  authType: this.deviceAuthType,
11948
11929
  password,
@@ -11957,7 +11938,7 @@ class Transactions extends Base {
11957
11938
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11958
11939
  storedEncryptedData: parsedPrimaryShare,
11959
11940
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11960
- wallabyPublicKey: user.wallabyAuthPubKey,
11941
+ wallabyPublicKey,
11961
11942
  options: {
11962
11943
  authType: this.deviceAuthType,
11963
11944
  password,