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.esm.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
- import { omit } from 'lodash';
7
7
  import * as WebAuthn from '@simplewebauthn/browser';
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";
@@ -572,7 +570,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
572
570
  { type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
573
571
  ];
574
572
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
575
- const currentPackageVersion = "2.3.6" ;
573
+ const currentPackageVersion = "2.3.7" ;
576
574
 
577
575
  /**
578
576
  * Storage keys adapter for Storage interface across different platforms.
@@ -4904,43 +4902,6 @@ class StorageService {
4904
4902
  }
4905
4903
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4906
4904
  }
4907
- /**
4908
- *
4909
- * Stores Wallaby auth public key to local storage
4910
- * @param wallabyAuthPubKey
4911
- */
4912
- async setWallabyAuthPubKey(wallabyAuthPubKey) {
4913
- await this.save(V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4914
- }
4915
- /**
4916
- *
4917
- * Fetches Wallaby auth public key from local storage
4918
- * @returns { string | undefined } Wallaby Auth Public key or undefined.
4919
- */
4920
- async getWallabyAuthPubKey() {
4921
- let wallabyAuthPubKey = await this.fetch(V2KeyNames.WallabyAuthPubKey);
4922
- if (wallabyAuthPubKey) {
4923
- return wallabyAuthPubKey;
4924
- }
4925
- // Legacy key migration
4926
- const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4927
- const legacyPubKey = await this.getItem(legacyKey);
4928
- if (legacyPubKey) {
4929
- wallabyAuthPubKey = legacyPubKey;
4930
- }
4931
- else {
4932
- const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4933
- const v1PubKey = await this.getItem(v1Key);
4934
- if (v1PubKey) {
4935
- wallabyAuthPubKey = v1PubKey;
4936
- }
4937
- }
4938
- if (wallabyAuthPubKey) {
4939
- await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4940
- return wallabyAuthPubKey;
4941
- }
4942
- return undefined;
4943
- }
4944
4905
  /**
4945
4906
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4946
4907
  * Encrypts and stores device auth private key
@@ -5149,7 +5110,15 @@ class StorageService {
5149
5110
  return undefined;
5150
5111
  }
5151
5112
  async clearLocalStorage(walletId) {
5152
- const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5113
+ const userKeysToRemove = [
5114
+ LocalStorageItems.AccessToken,
5115
+ V2KeyNames.EncryptedDevicePrivateKey,
5116
+ V2KeyNames.WallabyAuthPubKey,
5117
+ V2KeyNames.PasskeyCredential,
5118
+ V2KeyNames.MigrationVersion,
5119
+ V2KeyNames.LastMigratedAt,
5120
+ V2KeyNames.ClientAuthToken,
5121
+ ];
5153
5122
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5154
5123
  if (walletId) {
5155
5124
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6315,16 +6284,6 @@ class Api {
6315
6284
  * @secure
6316
6285
  */
6317
6286
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6318
- /**
6319
- * No description
6320
- *
6321
- * @tags Transactions, Query
6322
- * @name FetchTransactionByHashOrReference
6323
- * @summary Fetch transaction status data using a reference or transaction hash
6324
- * @request GET:/api/v1/transactions/status
6325
- * @secure
6326
- */
6327
- fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6328
6287
  /**
6329
6288
  * @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
6330
6289
  *
@@ -6335,6 +6294,16 @@ class Api {
6335
6294
  * @secure
6336
6295
  */
6337
6296
  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)),
6297
+ /**
6298
+ * No description
6299
+ *
6300
+ * @tags Transactions, Query
6301
+ * @name FetchTransactionByHashOrReference
6302
+ * @summary Fetch transaction status data using a reference or transaction hash
6303
+ * @request GET:/api/v1/transactions/status
6304
+ * @secure
6305
+ */
6306
+ fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6338
6307
  /**
6339
6308
  * No description
6340
6309
  *
@@ -7371,6 +7340,13 @@ const SwapRoutes = {
7371
7340
  },
7372
7341
  };
7373
7342
 
7343
+ function omit(obj, keys) {
7344
+ if (!obj)
7345
+ return {};
7346
+ const keysSet = new Set(keys);
7347
+ return Object.fromEntries(Object.entries(obj).filter(([k]) => !keysSet.has(k)));
7348
+ }
7349
+
7374
7350
  /* eslint-disable no-useless-catch */
7375
7351
  /**
7376
7352
  * Web Authenticator Implementation
@@ -7510,7 +7486,7 @@ class PasskeyService {
7510
7486
  this.authenticator = new Authenticator();
7511
7487
  }
7512
7488
  preparePasskeyRequestOptions(options) {
7513
- var _a, _b, _c, _d, _e, _f;
7489
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7514
7490
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7515
7491
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7516
7492
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7518,11 +7494,13 @@ class PasskeyService {
7518
7494
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7519
7495
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7520
7496
  : undefined;
7521
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7522
- eval: {
7523
- first: prfExtensionEvaluation,
7524
- },
7525
- } }) });
7497
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
7498
+ ? {
7499
+ eval: {
7500
+ first: prfExtensionEvaluation,
7501
+ },
7502
+ }
7503
+ : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7526
7504
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7527
7505
  // While the authenticator still works with the prf and would return the response (if any),
7528
7506
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7530,7 +7508,7 @@ class PasskeyService {
7530
7508
  return parsedOptions;
7531
7509
  }
7532
7510
  preparePasskeyCreationOptions(options) {
7533
- var _a, _b, _c, _d, _e, _f;
7511
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7534
7512
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7535
7513
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7536
7514
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7538,12 +7516,8 @@ class PasskeyService {
7538
7516
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7539
7517
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7540
7518
  : undefined;
7541
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7542
- eval: {
7543
- first: prfExtensionEvaluation,
7544
- },
7545
- } }) });
7546
- logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7519
+ 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 : {}) }) });
7520
+ logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
7547
7521
  return parsedOptions;
7548
7522
  }
7549
7523
  /**
@@ -7558,7 +7532,10 @@ class PasskeyService {
7558
7532
  let passkeyCredential;
7559
7533
  let signInResponse;
7560
7534
  try {
7561
- const registrationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
7535
+ const registrationChallengeResponse = await getSignature({
7536
+ deviceAuthKeys: deviceKeyPair,
7537
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
7538
+ });
7562
7539
  if (!registrationChallengeResponse.registrationOptions)
7563
7540
  throw new WallabyError({
7564
7541
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7601,7 +7578,10 @@ class PasskeyService {
7601
7578
  catch (error) {
7602
7579
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7603
7580
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7604
- const authenticationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
7581
+ const authenticationChallengeResponse = await getSignature({
7582
+ deviceAuthKeys: deviceKeyPair,
7583
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
7584
+ });
7605
7585
  if (!authenticationChallengeResponse.authenticationOptions)
7606
7586
  throw new WallabyError({
7607
7587
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7672,9 +7652,10 @@ class PasskeyService {
7672
7652
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7673
7653
  });
7674
7654
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7675
- const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
7655
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7656
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7676
7657
  eval: {
7677
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7658
+ first: prfFirst,
7678
7659
  },
7679
7660
  } }) });
7680
7661
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7901,10 +7882,6 @@ class PasskeyService {
7901
7882
  key: LocalStorageItems.AccessToken,
7902
7883
  value: authenticationResponse.accessToken,
7903
7884
  },
7904
- {
7905
- key: LocalStorageItems.WallabyAuthPubKey,
7906
- value: authenticationResponse.user.wallabyAuthPubKey,
7907
- },
7908
7885
  ]);
7909
7886
  }
7910
7887
  /**
@@ -8113,13 +8090,14 @@ class AuthService extends Base {
8113
8090
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8114
8091
  * @returns the messaged, the hash, and the signature using the passed private key.
8115
8092
  */
8116
- async getSignature(deviceAuthKeys, passkeyChallengeType) {
8093
+ async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8117
8094
  try {
8118
8095
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8119
8096
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : PasskeyChallengeType.REGISTRATION;
8120
8097
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8121
8098
  const response = await this.request(AuthRoutes.signatureMessage, {
8122
8099
  payload: {
8100
+ walletId,
8123
8101
  clientAuthPubKey: deviceAuthKeys.publicKey,
8124
8102
  passkeyChallengeType: challengeType,
8125
8103
  },
@@ -8150,7 +8128,10 @@ class AuthService extends Base {
8150
8128
  logger.info('key pair generated', !!deviceKeyPair);
8151
8129
  let authentication;
8152
8130
  try {
8153
- const signatureMessageResponse = await this.getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
8131
+ const signatureMessageResponse = await this.getSignature({
8132
+ deviceAuthKeys: deviceKeyPair,
8133
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
8134
+ });
8154
8135
  logger.info('signature has been generated', !!signatureMessageResponse);
8155
8136
  switch (this.deviceAuthType) {
8156
8137
  case AuthType.Passkey:
@@ -8183,7 +8164,10 @@ class AuthService extends Base {
8183
8164
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8184
8165
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8185
8166
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8186
- const newChallenge = await this.getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
8167
+ const newChallenge = await this.getSignature({
8168
+ deviceAuthKeys: deviceKeyPair,
8169
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8170
+ });
8187
8171
  authentication = await this.passkeyService.authenticate({
8188
8172
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8189
8173
  challengeResponse: newChallenge,
@@ -8220,10 +8204,7 @@ class AuthService extends Base {
8220
8204
  errorCode: ErrorResponseCodes.sdk_invalid_parameter,
8221
8205
  });
8222
8206
  }
8223
- await this.localStorageService.saveInBulk([
8224
- { key: LocalStorageItems.AccessToken, value: authentication.accessToken },
8225
- { key: LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8226
- ]);
8207
+ await this.localStorageService.save(LocalStorageItems.AccessToken, authentication.accessToken);
8227
8208
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8228
8209
  }
8229
8210
  catch (error) {
@@ -8299,7 +8280,9 @@ class AuthService extends Base {
8299
8280
  },
8300
8281
  credentialsKeyPair,
8301
8282
  });
8302
- const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8283
+ const signatureMessage = await this.getSignature({
8284
+ deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8285
+ });
8303
8286
  const authentication = await this.request(AuthRoutes.signIn, {
8304
8287
  payload: {
8305
8288
  externalUserId: this.userId,
@@ -8423,10 +8406,6 @@ class AuthService extends Base {
8423
8406
  key: LocalStorageItems.AccessToken,
8424
8407
  value: authResponse.accessToken,
8425
8408
  },
8426
- {
8427
- key: LocalStorageItems.WallabyAuthPubKey,
8428
- value: authResponse.user.wallabyAuthPubKey,
8429
- },
8430
8409
  ]);
8431
8410
  return authResponse;
8432
8411
  });
@@ -8511,12 +8490,16 @@ class WalletHandlersService extends Base {
8511
8490
  this.userId = config.userId;
8512
8491
  }
8513
8492
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8514
- var _a, _b, _c, _d;
8493
+ var _a, _b, _c, _d, _e;
8515
8494
  try {
8516
- const { signature, message } = await this.authService.getSignature({
8517
- publicKey: deviceAuthKeys.publicKey,
8518
- privateKey: deviceAuthKeys.privateKey,
8519
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
8495
+ // Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
8496
+ // However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
8497
+ // Using the reference as the fallback for the walletId in this case.
8498
+ const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
8499
+ walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
8500
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8501
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
8502
+ });
8520
8503
  if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8521
8504
  importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8522
8505
  !importWalletInput.keyShareOptions) {
@@ -8526,7 +8509,7 @@ class WalletHandlersService extends Base {
8526
8509
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
8527
8510
  });
8528
8511
  }
8529
- const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8512
+ const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8530
8513
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8531
8514
  throw new WallabyError({
8532
8515
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8536,10 +8519,11 @@ class WalletHandlersService extends Base {
8536
8519
  }
8537
8520
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8538
8521
  data: importWalletInput.seedPhrase,
8539
- encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8522
+ encryptionKey: wallabyAuthPubKey,
8540
8523
  });
8541
8524
  const importWalletPayload = {
8542
- reference: v4(),
8525
+ reference: importWalletInput.reference,
8526
+ walletId: importWalletInput.walletId,
8543
8527
  message,
8544
8528
  signature,
8545
8529
  encryptedSeed: readyForTransportSeedPhrase,
@@ -8548,7 +8532,7 @@ class WalletHandlersService extends Base {
8548
8532
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8549
8533
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8550
8534
  walletOwnershipType: WalletOwnershipType.SingleOwner,
8551
- wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8535
+ wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8552
8536
  };
8553
8537
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8554
8538
  payload: importWalletPayload,
@@ -8586,7 +8570,7 @@ class WalletHandlersService extends Base {
8586
8570
  }
8587
8571
  catch (error) {
8588
8572
  throw new WallabyError({
8589
- message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8573
+ message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8590
8574
  statusCode: error.statusCode,
8591
8575
  errorCode: error.errorCode,
8592
8576
  data: error.data,
@@ -8608,9 +8592,9 @@ class WalletHandlersService extends Base {
8608
8592
  var _a, _b, _c, _d, _e, _f;
8609
8593
  try {
8610
8594
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8611
- publicKey: deviceAuthKeys.publicKey,
8612
- privateKey: deviceAuthKeys.privateKey,
8613
- }, PasskeyChallengeType.AUTHENTICATION);
8595
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8596
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8597
+ });
8614
8598
  if ((walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8615
8599
  walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8616
8600
  !walletCreationInput.keyShareOptions) {
@@ -8787,36 +8771,6 @@ class WalletHandlersService extends Base {
8787
8771
  });
8788
8772
  }
8789
8773
  }
8790
- /**
8791
- *
8792
- * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8793
- * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8794
- * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8795
- * @description This function constructs the seed phrase from encrypted key shares.
8796
- * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8797
- * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8798
- * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8799
- */
8800
- async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8801
- try {
8802
- const { signature, message } = await this.authService.getSignature(deviceAuthKeys, PasskeyChallengeType.AUTHENTICATION);
8803
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8804
- payload: {
8805
- walletId: walletId,
8806
- signature,
8807
- message,
8808
- clientAuthPubKey: deviceAuthKeys.publicKey,
8809
- recoveryPubKey: deviceAuthKeys.publicKey,
8810
- encryptedShares: encryptedKeyShares,
8811
- },
8812
- });
8813
- return retrieveSeedPhraseResponse.encryptedSeed;
8814
- }
8815
- catch (error) {
8816
- logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8817
- return Promise.reject(error);
8818
- }
8819
- }
8820
8774
  }
8821
8775
 
8822
8776
  class WalletService extends Base {
@@ -8926,7 +8880,6 @@ class WalletService extends Base {
8926
8880
  */
8927
8881
  async export({ walletId, authenticationOptions, exportOptions }) {
8928
8882
  try {
8929
- const { user: { wallabyAuthPubKey }, } = authenticationOptions;
8930
8883
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
8931
8884
  throw new WallabyError({
8932
8885
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9036,10 +8989,20 @@ class WalletService extends Base {
9036
8989
  });
9037
8990
  }
9038
8991
  const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
8992
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8993
+ const deviceAuthKeys = {
8994
+ publicKey: deviceAuthPublicKey,
8995
+ privateKey: decryptedDevicePrivateKey,
8996
+ };
8997
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
8998
+ deviceAuthKeys,
8999
+ walletId,
9000
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9001
+ });
9039
9002
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9040
9003
  storedEncryptedData: parsedPrimaryShare,
9041
9004
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9042
- wallabyPublicKey: wallabyAuthPubKey,
9005
+ wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9043
9006
  options: {
9044
9007
  authType: this.deviceAuthType,
9045
9008
  password: authenticationOptions.password,
@@ -9047,17 +9010,18 @@ class WalletService extends Base {
9047
9010
  prfValue: authenticationOptions.prfValue,
9048
9011
  },
9049
9012
  });
9050
- const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9051
- const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9052
- encryptedKeyShares: [wallabyBoundPrimaryShare],
9053
- walletId,
9054
- deviceAuthKeys: {
9055
- publicKey: deviceAuthPublicKey,
9056
- privateKey: decryptedDevicePrivateKey,
9013
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9014
+ payload: {
9015
+ walletId: walletId,
9016
+ signature,
9017
+ message,
9018
+ clientAuthPubKey: deviceAuthKeys.publicKey,
9019
+ recoveryPubKey: deviceAuthKeys.publicKey,
9020
+ encryptedShares: [wallabyBoundPrimaryShare],
9057
9021
  },
9058
9022
  });
9059
9023
  decryptedSeedPhrase = await this.cipher.decrypt({
9060
- cipherText: encryptedReconstructedSeedPhrase,
9024
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9061
9025
  decryptionKey: decryptedDevicePrivateKey,
9062
9026
  });
9063
9027
  if (exportOptions.algorandSeedPhrase) {
@@ -9095,7 +9059,9 @@ class WalletService extends Base {
9095
9059
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9096
9060
  */
9097
9061
  async import(input) {
9062
+ var _a;
9098
9063
  try {
9064
+ const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : v4();
9099
9065
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9100
9066
  if (!encryptedDevicePrivateKey) {
9101
9067
  throw new WallabyError({
@@ -9126,7 +9092,7 @@ class WalletService extends Base {
9126
9092
  const importRequest = await this.handlers.handleImportWallet({
9127
9093
  publicKey: clientAuthPubKey,
9128
9094
  privateKey: decryptedDevicePrivateKey,
9129
- }, input);
9095
+ }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9130
9096
  return importRequest;
9131
9097
  }
9132
9098
  catch (error) {
@@ -9140,11 +9106,15 @@ class WalletService extends Base {
9140
9106
  *
9141
9107
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9142
9108
  * @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
9109
+ *
9110
+ * @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
9111
+ * Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
9143
9112
  */
9144
9113
  async recover(input) {
9145
9114
  var _a, _b;
9146
9115
  try {
9147
- const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9116
+ const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9117
+ input.authenticationOptions.user.wallabyAuthPubKey;
9148
9118
  const deviceAuthKeyPair = createIdentity();
9149
9119
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9150
9120
  authType: this.deviceAuthType,
@@ -9184,27 +9154,37 @@ class WalletService extends Base {
9184
9154
  return recoverWithSeedPhraseResponse;
9185
9155
  }
9186
9156
  else if (input.decryptedShares) {
9187
- const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9188
- const encrypted = await this.cipher.encrypt({
9189
- data: decryptedShare,
9190
- encryptionKey: wallabyPublicKey,
9191
- });
9192
- return encrypted;
9193
- }));
9194
- if (!encryptedShares.length) {
9157
+ if (!input.decryptedShares.length) {
9195
9158
  throw new WallabyError({
9196
9159
  message: 'Decrypted shares are required',
9197
9160
  statusCode: 400,
9198
9161
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
9199
9162
  });
9200
9163
  }
9201
- const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9202
- encryptedKeyShares: encryptedShares,
9164
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9203
9165
  deviceAuthKeys: deviceAuthKeyPair,
9204
9166
  walletId: input.walletId,
9167
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9168
+ });
9169
+ const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9170
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9171
+ return await this.cipher.encrypt({
9172
+ data: decryptedShare,
9173
+ encryptionKey: transportEncryptionKey,
9174
+ });
9175
+ }));
9176
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9177
+ payload: {
9178
+ walletId: input.walletId,
9179
+ signature,
9180
+ message,
9181
+ clientAuthPubKey: deviceAuthKeyPair.publicKey,
9182
+ recoveryPubKey: deviceAuthKeyPair.publicKey,
9183
+ encryptedShares,
9184
+ },
9205
9185
  });
9206
9186
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9207
- cipherText: encryptedSeed,
9187
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9208
9188
  decryptionKey: deviceAuthKeyPair.privateKey,
9209
9189
  encryptionKey: wallabyPublicKey,
9210
9190
  });
@@ -9262,17 +9242,9 @@ class WalletService extends Base {
9262
9242
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9263
9243
  try {
9264
9244
  const signatureMessage = await this.authService.getSignature({
9265
- publicKey: deviceAuthKeys.publicKey,
9266
- privateKey: deviceAuthKeys.privateKey,
9267
- });
9268
- // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9269
- // payload: {
9270
- // walletId,
9271
- // signature: signatureMessage.signature,
9272
- // message: signatureMessage.message,
9273
- // clientAuthPubKey: deviceAuthKeys.publicKey,
9274
- // },
9275
- // });
9245
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9246
+ walletId,
9247
+ });
9276
9248
  const response = await this.api.wallets.retrieveShares({
9277
9249
  walletId: walletId,
9278
9250
  signature: signatureMessage.signature,
@@ -9453,6 +9425,7 @@ class WalletService extends Base {
9453
9425
  */
9454
9426
  async initAddNewDevice(input) {
9455
9427
  const { walletId, backupUrl, authenticationOptions } = input;
9428
+ const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9456
9429
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9457
9430
  if (!encryptedDevicePrivateKey) {
9458
9431
  throw new WallabyError({
@@ -9513,7 +9486,7 @@ class WalletService extends Base {
9513
9486
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9514
9487
  storedEncryptedData: parsedPrimaryShare,
9515
9488
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9516
- wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9489
+ wallabyPublicKey,
9517
9490
  options: {
9518
9491
  authType: this.deviceAuthType,
9519
9492
  password: authenticationOptions.password,
@@ -9572,22 +9545,11 @@ class WalletService extends Base {
9572
9545
  }
9573
9546
  const devicePublicKey = (_a = (await this.localStorageService.fetch(LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9574
9547
  const signatureMessage = await this.authService.getSignature({
9575
- publicKey: devicePublicKey,
9576
- privateKey: decryptedDevicePrivateKey,
9577
- }, PasskeyChallengeType.REGISTRATION);
9578
- // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9579
- // payload: {
9580
- // walletId: input.walletId,
9581
- // message: signatureMessage.message,
9582
- // signature: signatureMessage.signature,
9583
- // clientAuthPubKey: devicePublicKey,
9584
- // share: {
9585
- // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9586
- // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9587
- // type: KeyTypeName.OwnerBackupDeviceShare,
9588
- // },
9589
- // },
9590
- // });
9548
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
9549
+ walletId: input.walletId,
9550
+ passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
9551
+ });
9552
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9591
9553
  const backUpResponse = await this.api.wallets.addNewDevice({
9592
9554
  walletId: input.walletId,
9593
9555
  message: signatureMessage.message,
@@ -9595,7 +9557,7 @@ class WalletService extends Base {
9595
9557
  clientAuthPubKey: devicePublicKey,
9596
9558
  share: {
9597
9559
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9598
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9560
+ wrappingPublicKey: wallabyPublicKey,
9599
9561
  type: KeyTypeName.OwnerBackupDeviceShare,
9600
9562
  },
9601
9563
  });
@@ -9603,7 +9565,8 @@ class WalletService extends Base {
9603
9565
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9604
9566
  {
9605
9567
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9606
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9568
+ wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9569
+ input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9607
9570
  type: KeyTypeName.OwnerMainDeviceShare,
9608
9571
  },
9609
9572
  ];
@@ -9660,12 +9623,28 @@ class WalletService extends Base {
9660
9623
  });
9661
9624
  }
9662
9625
  const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
9626
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9627
+ authType: this.deviceAuthType,
9628
+ password: input.authenticationOptions.password,
9629
+ salt: input.authenticationOptions.clientSalt,
9630
+ prfValue: input.authenticationOptions.prfValue,
9631
+ });
9632
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9633
+ cipherText: parsedDevicePrivateKey,
9634
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9635
+ });
9636
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9637
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9638
+ deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
9639
+ walletId,
9640
+ });
9641
+ const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9663
9642
  if (storedSeedPhrase) {
9664
9643
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9665
9644
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9666
9645
  storedEncryptedData: parsedStoredSeedPhrase,
9667
9646
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9668
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9647
+ wallabyPublicKey,
9669
9648
  options: {
9670
9649
  authType: this.deviceAuthType,
9671
9650
  password: input.authenticationOptions.password,
@@ -9679,7 +9658,7 @@ class WalletService extends Base {
9679
9658
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9680
9659
  storedEncryptedData: parsedPrimaryKeyShare,
9681
9660
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9682
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9661
+ wallabyPublicKey,
9683
9662
  options: {
9684
9663
  authType: this.deviceAuthType,
9685
9664
  password: input.authenticationOptions.password,
@@ -9695,21 +9674,6 @@ class WalletService extends Base {
9695
9674
  errorCode: 'sdk_private_key_not_found',
9696
9675
  });
9697
9676
  }
9698
- const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9699
- authType: this.deviceAuthType,
9700
- password: input.authenticationOptions.password,
9701
- salt: input.authenticationOptions.clientSalt,
9702
- prfValue: input.authenticationOptions.prfValue,
9703
- });
9704
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9705
- cipherText: parsedDevicePrivateKey,
9706
- decryptionKey: derivedCredentialsKeyPair.privateKey,
9707
- });
9708
- const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9709
- const { signature, message } = await this.authService.getSignature({
9710
- privateKey: decryptedDevicePrivateKey,
9711
- publicKey: devicePublicKey,
9712
- });
9713
9677
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9714
9678
  payload: {
9715
9679
  walletId,
@@ -9901,8 +9865,8 @@ class WalletService extends Base {
9901
9865
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9902
9866
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9903
9867
  const signInSignatureMessage = await this.authService.getSignature({
9904
- publicKey: devicePublicKey,
9905
- privateKey: decryptedPrivateKey,
9868
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9869
+ walletId,
9906
9870
  });
9907
9871
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9908
9872
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -9928,7 +9892,6 @@ class WalletService extends Base {
9928
9892
  // Store authentication tokens
9929
9893
  await this.localStorageService.saveInBulk([
9930
9894
  { key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
9931
- { key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
9932
9895
  { key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
9933
9896
  { key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9934
9897
  ]);
@@ -9991,8 +9954,8 @@ class WalletService extends Base {
9991
9954
  throw error;
9992
9955
  }
9993
9956
  }
9994
- async clearDevice() {
9995
- await this.localStorageService.clearLocalStorage();
9957
+ async clearDevice({ walletId }) {
9958
+ await this.localStorageService.clearLocalStorage(walletId);
9996
9959
  }
9997
9960
  /**
9998
9961
  * Prepares authentication data and encrypted payload for any request.
@@ -10029,9 +9992,11 @@ class WalletService extends Base {
10029
9992
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10030
9993
  // Get signature message
10031
9994
  const signatureMessage = await this.authService.getSignature({
10032
- publicKey: deviceAuthPublicKey,
10033
- privateKey: decryptedDevicePrivateKey,
10034
- }, PasskeyChallengeType.AUTHENTICATION);
9995
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
9996
+ walletId,
9997
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9998
+ });
9999
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10035
10000
  // Prepare encrypted data (seed phrase or key shares)
10036
10001
  const sharesEncryptedWithWallabyPubKey = [];
10037
10002
  let readyForTransportSeedPhrase = undefined;
@@ -10051,7 +10016,7 @@ class WalletService extends Base {
10051
10016
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10052
10017
  storedEncryptedData: parsedSeedPhrase,
10053
10018
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10054
- wallabyPublicKey: user.wallabyAuthPubKey,
10019
+ wallabyPublicKey,
10055
10020
  options: {
10056
10021
  authType: this.deviceAuthType,
10057
10022
  password,
@@ -10066,7 +10031,7 @@ class WalletService extends Base {
10066
10031
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10067
10032
  storedEncryptedData: parsedPrimaryShare,
10068
10033
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10069
- wallabyPublicKey: user.wallabyAuthPubKey,
10034
+ wallabyPublicKey,
10070
10035
  options: {
10071
10036
  authType: this.deviceAuthType,
10072
10037
  password,
@@ -10235,6 +10200,7 @@ class WalletService extends Base {
10235
10200
  seedPhrase: decryptedSeedPhrase,
10236
10201
  storeSeedPhrase: false,
10237
10202
  returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10203
+ walletId: input.walletId,
10238
10204
  keyShareOptions: {
10239
10205
  threshold: 2,
10240
10206
  numberOfKeyShares: 3,
@@ -10285,20 +10251,31 @@ class WalletService extends Base {
10285
10251
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10286
10252
  }
10287
10253
  if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10254
+ const deviceAuthKeys = {
10255
+ publicKey: clientPublicKey,
10256
+ privateKey: decryptedClientAuthPrivKey,
10257
+ };
10258
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
10259
+ deviceAuthKeys,
10260
+ walletId: input.walletId,
10261
+ passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10262
+ });
10288
10263
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10289
10264
  data: decryptedPrimaryShare,
10290
- encryptionKey: authentication.user.wallabyAuthPubKey,
10265
+ encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10291
10266
  });
10292
- const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10293
- walletId: input.walletId,
10294
- encryptedKeyShares: [flippedEncryptedPrimaryShare],
10295
- deviceAuthKeys: {
10296
- publicKey: clientPublicKey,
10297
- privateKey: decryptedClientAuthPrivKey,
10267
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
10268
+ payload: {
10269
+ walletId: input.walletId,
10270
+ signature,
10271
+ message,
10272
+ clientAuthPubKey: deviceAuthKeys.publicKey,
10273
+ recoveryPubKey: deviceAuthKeys.publicKey,
10274
+ encryptedShares: [flippedEncryptedPrimaryShare],
10298
10275
  },
10299
10276
  });
10300
10277
  decryptedSeedPhrase = await this.cipher.decrypt({
10301
- cipherText: reconstructedSeedPhrase,
10278
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10302
10279
  decryptionKey: decryptedClientAuthPrivKey,
10303
10280
  });
10304
10281
  }
@@ -10405,7 +10382,7 @@ class WalletDataService extends Base {
10405
10382
  * Note: Either chainName or tokenStandard must be provided.
10406
10383
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10407
10384
  */
10408
- async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10385
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10409
10386
  try {
10410
10387
  if (!tokensAndAddressesList.length) {
10411
10388
  throw new WallabyError({
@@ -11162,9 +11139,11 @@ class Swap extends Base {
11162
11139
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11163
11140
  // Get signature message
11164
11141
  const signatureMessage = await this.authService.getSignature({
11165
- publicKey: deviceAuthPublicKey,
11166
- privateKey: decryptedDevicePrivateKey,
11167
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11142
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11143
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11144
+ walletId,
11145
+ });
11146
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11168
11147
  // Prepare encrypted data (seed phrase or key shares)
11169
11148
  const sharesEncryptedWithWallabyPubKey = [];
11170
11149
  let readyForTransportSeedPhrase = undefined;
@@ -11185,7 +11164,7 @@ class Swap extends Base {
11185
11164
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11186
11165
  storedEncryptedData: parsedSeedPhrase,
11187
11166
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11188
- wallabyPublicKey: user.wallabyAuthPubKey,
11167
+ wallabyPublicKey,
11189
11168
  options: {
11190
11169
  authType: this.deviceAuthType,
11191
11170
  password,
@@ -11200,7 +11179,7 @@ class Swap extends Base {
11200
11179
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11201
11180
  storedEncryptedData: parsedPrimaryShare,
11202
11181
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11203
- wallabyPublicKey: user.wallabyAuthPubKey,
11182
+ wallabyPublicKey,
11204
11183
  options: {
11205
11184
  authType: this.deviceAuthType,
11206
11185
  password,
@@ -11455,7 +11434,7 @@ class Transactions extends Base {
11455
11434
  * @param {BlockchainName} blockchain
11456
11435
  * @returns {FeeEstimateRequest}
11457
11436
  */
11458
- async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11437
+ async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11459
11438
  try {
11460
11439
  const response = await this.request(TransactionsRoutes.estimateFee, {
11461
11440
  queryParams: {
@@ -11798,9 +11777,11 @@ class Transactions extends Base {
11798
11777
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11799
11778
  // Get signature message
11800
11779
  const signatureMessage = await this.authService.getSignature({
11801
- publicKey: deviceAuthPublicKey,
11802
- privateKey: decryptedDevicePrivateKey,
11803
- }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11780
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11781
+ walletId,
11782
+ passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11783
+ });
11784
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11804
11785
  // Prepare encrypted data (seed phrase or key shares)
11805
11786
  const sharesEncryptedWithWallabyPubKey = [];
11806
11787
  let readyForTransportSeedPhrase = undefined;
@@ -11821,7 +11802,7 @@ class Transactions extends Base {
11821
11802
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11822
11803
  storedEncryptedData: parsedSeedPhrase,
11823
11804
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11824
- wallabyPublicKey: user.wallabyAuthPubKey,
11805
+ wallabyPublicKey,
11825
11806
  options: {
11826
11807
  authType: this.deviceAuthType,
11827
11808
  password,
@@ -11836,7 +11817,7 @@ class Transactions extends Base {
11836
11817
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11837
11818
  storedEncryptedData: parsedPrimaryShare,
11838
11819
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11839
- wallabyPublicKey: user.wallabyAuthPubKey,
11820
+ wallabyPublicKey,
11840
11821
  options: {
11841
11822
  authType: this.deviceAuthType,
11842
11823
  password,