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.cjs.js CHANGED
@@ -4,13 +4,12 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
 
5
5
  const algosdk = require('algosdk');
6
6
  const bip39 = require('bip39');
7
+ const uuid = require('uuid');
7
8
  const log = require('loglevel');
8
9
  const cryptoJs = require('crypto-js');
9
10
  const jwtDecode = require('jwt-decode');
10
- const lodash = require('lodash');
11
11
  const WebAuthn = require('@simplewebauthn/browser');
12
12
  const jsBase64 = require('js-base64');
13
- const uuid = require('uuid');
14
13
 
15
14
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
16
15
 
@@ -295,7 +294,6 @@ exports.LocalStorageItems = void 0;
295
294
  LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
296
295
  LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
297
296
  LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
298
- LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
299
297
  LocalStorageItems["ClientAuthToken"] = "republic-jwt";
300
298
  LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
301
299
  LocalStorageItems["Blob"] = "blob";
@@ -601,7 +599,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
601
599
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
602
600
  ];
603
601
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
604
- const currentPackageVersion = "2.3.6" ;
602
+ const currentPackageVersion = "2.3.7" ;
605
603
 
606
604
  /**
607
605
  * Storage keys adapter for Storage interface across different platforms.
@@ -4933,43 +4931,6 @@ class StorageService {
4933
4931
  }
4934
4932
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4935
4933
  }
4936
- /**
4937
- *
4938
- * Stores Wallaby auth public key to local storage
4939
- * @param wallabyAuthPubKey
4940
- */
4941
- async setWallabyAuthPubKey(wallabyAuthPubKey) {
4942
- await this.save(exports.V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4943
- }
4944
- /**
4945
- *
4946
- * Fetches Wallaby auth public key from local storage
4947
- * @returns { string | undefined } Wallaby Auth Public key or undefined.
4948
- */
4949
- async getWallabyAuthPubKey() {
4950
- let wallabyAuthPubKey = await this.fetch(exports.V2KeyNames.WallabyAuthPubKey);
4951
- if (wallabyAuthPubKey) {
4952
- return wallabyAuthPubKey;
4953
- }
4954
- // Legacy key migration
4955
- const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4956
- const legacyPubKey = await this.getItem(legacyKey);
4957
- if (legacyPubKey) {
4958
- wallabyAuthPubKey = legacyPubKey;
4959
- }
4960
- else {
4961
- const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4962
- const v1PubKey = await this.getItem(v1Key);
4963
- if (v1PubKey) {
4964
- wallabyAuthPubKey = v1PubKey;
4965
- }
4966
- }
4967
- if (wallabyAuthPubKey) {
4968
- await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4969
- return wallabyAuthPubKey;
4970
- }
4971
- return undefined;
4972
- }
4973
4934
  /**
4974
4935
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4975
4936
  * Encrypts and stores device auth private key
@@ -5178,7 +5139,15 @@ class StorageService {
5178
5139
  return undefined;
5179
5140
  }
5180
5141
  async clearLocalStorage(walletId) {
5181
- const userKeysToRemove = [exports.LocalStorageItems.AccessToken, exports.V2KeyNames.EncryptedDevicePrivateKey, exports.V2KeyNames.WallabyAuthPubKey];
5142
+ const userKeysToRemove = [
5143
+ exports.LocalStorageItems.AccessToken,
5144
+ exports.V2KeyNames.EncryptedDevicePrivateKey,
5145
+ exports.V2KeyNames.WallabyAuthPubKey,
5146
+ exports.V2KeyNames.PasskeyCredential,
5147
+ exports.V2KeyNames.MigrationVersion,
5148
+ exports.V2KeyNames.LastMigratedAt,
5149
+ exports.V2KeyNames.ClientAuthToken,
5150
+ ];
5182
5151
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5183
5152
  if (walletId) {
5184
5153
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6344,16 +6313,6 @@ class Api {
6344
6313
  * @secure
6345
6314
  */
6346
6315
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6347
- /**
6348
- * No description
6349
- *
6350
- * @tags Transactions, Query
6351
- * @name FetchTransactionByHashOrReference
6352
- * @summary Fetch transaction status data using a reference or transaction hash
6353
- * @request GET:/api/v1/transactions/status
6354
- * @secure
6355
- */
6356
- fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6357
6316
  /**
6358
6317
  * @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
6359
6318
  *
@@ -6364,6 +6323,16 @@ class Api {
6364
6323
  * @secure
6365
6324
  */
6366
6325
  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)),
6326
+ /**
6327
+ * No description
6328
+ *
6329
+ * @tags Transactions, Query
6330
+ * @name FetchTransactionByHashOrReference
6331
+ * @summary Fetch transaction status data using a reference or transaction hash
6332
+ * @request GET:/api/v1/transactions/status
6333
+ * @secure
6334
+ */
6335
+ fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6367
6336
  /**
6368
6337
  * No description
6369
6338
  *
@@ -7400,6 +7369,13 @@ const SwapRoutes = {
7400
7369
  },
7401
7370
  };
7402
7371
 
7372
+ function omit(obj, keys) {
7373
+ if (!obj)
7374
+ return {};
7375
+ const keysSet = new Set(keys);
7376
+ return Object.fromEntries(Object.entries(obj).filter(([k]) => !keysSet.has(k)));
7377
+ }
7378
+
7403
7379
  /* eslint-disable no-useless-catch */
7404
7380
  /**
7405
7381
  * Web Authenticator Implementation
@@ -7539,7 +7515,7 @@ class PasskeyService {
7539
7515
  this.authenticator = new Authenticator();
7540
7516
  }
7541
7517
  preparePasskeyRequestOptions(options) {
7542
- var _a, _b, _c, _d, _e, _f;
7518
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7543
7519
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7544
7520
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7545
7521
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7547,11 +7523,13 @@ class PasskeyService {
7547
7523
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7548
7524
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7549
7525
  : undefined;
7550
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7551
- eval: {
7552
- first: prfExtensionEvaluation,
7553
- },
7554
- } }) });
7526
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
7527
+ ? {
7528
+ eval: {
7529
+ first: prfExtensionEvaluation,
7530
+ },
7531
+ }
7532
+ : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7555
7533
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7556
7534
  // While the authenticator still works with the prf and would return the response (if any),
7557
7535
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7559,7 +7537,7 @@ class PasskeyService {
7559
7537
  return parsedOptions;
7560
7538
  }
7561
7539
  preparePasskeyCreationOptions(options) {
7562
- var _a, _b, _c, _d, _e, _f;
7540
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7563
7541
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7564
7542
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7565
7543
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7567,12 +7545,8 @@ class PasskeyService {
7567
7545
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7568
7546
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7569
7547
  : undefined;
7570
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7571
- eval: {
7572
- first: prfExtensionEvaluation,
7573
- },
7574
- } }) });
7575
- logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7548
+ 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 : {}) }) });
7549
+ logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
7576
7550
  return parsedOptions;
7577
7551
  }
7578
7552
  /**
@@ -7587,7 +7561,10 @@ class PasskeyService {
7587
7561
  let passkeyCredential;
7588
7562
  let signInResponse;
7589
7563
  try {
7590
- const registrationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
7564
+ const registrationChallengeResponse = await getSignature({
7565
+ deviceAuthKeys: deviceKeyPair,
7566
+ passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
7567
+ });
7591
7568
  if (!registrationChallengeResponse.registrationOptions)
7592
7569
  throw new WallabyError({
7593
7570
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7630,7 +7607,10 @@ class PasskeyService {
7630
7607
  catch (error) {
7631
7608
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7632
7609
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7633
- const authenticationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
7610
+ const authenticationChallengeResponse = await getSignature({
7611
+ deviceAuthKeys: deviceKeyPair,
7612
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
7613
+ });
7634
7614
  if (!authenticationChallengeResponse.authenticationOptions)
7635
7615
  throw new WallabyError({
7636
7616
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7701,9 +7681,10 @@ class PasskeyService {
7701
7681
  errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7702
7682
  });
7703
7683
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7704
- const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, lodash.omit(parsedOptions.extensions, 'credProps')), { prf: {
7684
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7685
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7705
7686
  eval: {
7706
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7687
+ first: prfFirst,
7707
7688
  },
7708
7689
  } }) });
7709
7690
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7930,10 +7911,6 @@ class PasskeyService {
7930
7911
  key: exports.LocalStorageItems.AccessToken,
7931
7912
  value: authenticationResponse.accessToken,
7932
7913
  },
7933
- {
7934
- key: exports.LocalStorageItems.WallabyAuthPubKey,
7935
- value: authenticationResponse.user.wallabyAuthPubKey,
7936
- },
7937
7914
  ]);
7938
7915
  }
7939
7916
  /**
@@ -8142,13 +8119,14 @@ class AuthService extends Base {
8142
8119
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8143
8120
  * @returns the messaged, the hash, and the signature using the passed private key.
8144
8121
  */
8145
- async getSignature(deviceAuthKeys, passkeyChallengeType) {
8122
+ async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8146
8123
  try {
8147
8124
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8148
8125
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
8149
8126
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8150
8127
  const response = await this.request(AuthRoutes.signatureMessage, {
8151
8128
  payload: {
8129
+ walletId,
8152
8130
  clientAuthPubKey: deviceAuthKeys.publicKey,
8153
8131
  passkeyChallengeType: challengeType,
8154
8132
  },
@@ -8179,7 +8157,10 @@ class AuthService extends Base {
8179
8157
  logger.info('key pair generated', !!deviceKeyPair);
8180
8158
  let authentication;
8181
8159
  try {
8182
- const signatureMessageResponse = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
8160
+ const signatureMessageResponse = await this.getSignature({
8161
+ deviceAuthKeys: deviceKeyPair,
8162
+ passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
8163
+ });
8183
8164
  logger.info('signature has been generated', !!signatureMessageResponse);
8184
8165
  switch (this.deviceAuthType) {
8185
8166
  case exports.AuthType.Passkey:
@@ -8212,7 +8193,10 @@ class AuthService extends Base {
8212
8193
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8213
8194
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8214
8195
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8215
- const newChallenge = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
8196
+ const newChallenge = await this.getSignature({
8197
+ deviceAuthKeys: deviceKeyPair,
8198
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
8199
+ });
8216
8200
  authentication = await this.passkeyService.authenticate({
8217
8201
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8218
8202
  challengeResponse: newChallenge,
@@ -8249,10 +8233,7 @@ class AuthService extends Base {
8249
8233
  errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
8250
8234
  });
8251
8235
  }
8252
- await this.localStorageService.saveInBulk([
8253
- { key: exports.LocalStorageItems.AccessToken, value: authentication.accessToken },
8254
- { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8255
- ]);
8236
+ await this.localStorageService.save(exports.LocalStorageItems.AccessToken, authentication.accessToken);
8256
8237
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8257
8238
  }
8258
8239
  catch (error) {
@@ -8328,7 +8309,9 @@ class AuthService extends Base {
8328
8309
  },
8329
8310
  credentialsKeyPair,
8330
8311
  });
8331
- const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8312
+ const signatureMessage = await this.getSignature({
8313
+ deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8314
+ });
8332
8315
  const authentication = await this.request(AuthRoutes.signIn, {
8333
8316
  payload: {
8334
8317
  externalUserId: this.userId,
@@ -8452,10 +8435,6 @@ class AuthService extends Base {
8452
8435
  key: exports.LocalStorageItems.AccessToken,
8453
8436
  value: authResponse.accessToken,
8454
8437
  },
8455
- {
8456
- key: exports.LocalStorageItems.WallabyAuthPubKey,
8457
- value: authResponse.user.wallabyAuthPubKey,
8458
- },
8459
8438
  ]);
8460
8439
  return authResponse;
8461
8440
  });
@@ -8540,12 +8519,16 @@ class WalletHandlersService extends Base {
8540
8519
  this.userId = config.userId;
8541
8520
  }
8542
8521
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8543
- var _a, _b, _c, _d;
8522
+ var _a, _b, _c, _d, _e;
8544
8523
  try {
8545
- const { signature, message } = await this.authService.getSignature({
8546
- publicKey: deviceAuthKeys.publicKey,
8547
- privateKey: deviceAuthKeys.privateKey,
8548
- }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
8524
+ // Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
8525
+ // However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
8526
+ // Using the reference as the fallback for the walletId in this case.
8527
+ const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
8528
+ walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
8529
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8530
+ passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
8531
+ });
8549
8532
  if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8550
8533
  importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8551
8534
  !importWalletInput.keyShareOptions) {
@@ -8555,7 +8538,7 @@ class WalletHandlersService extends Base {
8555
8538
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
8556
8539
  });
8557
8540
  }
8558
- const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8541
+ const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8559
8542
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8560
8543
  throw new WallabyError({
8561
8544
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8565,10 +8548,11 @@ class WalletHandlersService extends Base {
8565
8548
  }
8566
8549
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8567
8550
  data: importWalletInput.seedPhrase,
8568
- encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8551
+ encryptionKey: wallabyAuthPubKey,
8569
8552
  });
8570
8553
  const importWalletPayload = {
8571
- reference: uuid.v4(),
8554
+ reference: importWalletInput.reference,
8555
+ walletId: importWalletInput.walletId,
8572
8556
  message,
8573
8557
  signature,
8574
8558
  encryptedSeed: readyForTransportSeedPhrase,
@@ -8577,7 +8561,7 @@ class WalletHandlersService extends Base {
8577
8561
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8578
8562
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8579
8563
  walletOwnershipType: exports.WalletOwnershipType.SingleOwner,
8580
- wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8564
+ wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8581
8565
  };
8582
8566
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8583
8567
  payload: importWalletPayload,
@@ -8615,7 +8599,7 @@ class WalletHandlersService extends Base {
8615
8599
  }
8616
8600
  catch (error) {
8617
8601
  throw new WallabyError({
8618
- message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8602
+ message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8619
8603
  statusCode: error.statusCode,
8620
8604
  errorCode: error.errorCode,
8621
8605
  data: error.data,
@@ -8637,9 +8621,9 @@ class WalletHandlersService extends Base {
8637
8621
  var _a, _b, _c, _d, _e, _f;
8638
8622
  try {
8639
8623
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8640
- publicKey: deviceAuthKeys.publicKey,
8641
- privateKey: deviceAuthKeys.privateKey,
8642
- }, exports.PasskeyChallengeType.AUTHENTICATION);
8624
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8625
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
8626
+ });
8643
8627
  if ((walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8644
8628
  walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8645
8629
  !walletCreationInput.keyShareOptions) {
@@ -8816,36 +8800,6 @@ class WalletHandlersService extends Base {
8816
8800
  });
8817
8801
  }
8818
8802
  }
8819
- /**
8820
- *
8821
- * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8822
- * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8823
- * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8824
- * @description This function constructs the seed phrase from encrypted key shares.
8825
- * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8826
- * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8827
- * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8828
- */
8829
- async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8830
- try {
8831
- const { signature, message } = await this.authService.getSignature(deviceAuthKeys, exports.PasskeyChallengeType.AUTHENTICATION);
8832
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8833
- payload: {
8834
- walletId: walletId,
8835
- signature,
8836
- message,
8837
- clientAuthPubKey: deviceAuthKeys.publicKey,
8838
- recoveryPubKey: deviceAuthKeys.publicKey,
8839
- encryptedShares: encryptedKeyShares,
8840
- },
8841
- });
8842
- return retrieveSeedPhraseResponse.encryptedSeed;
8843
- }
8844
- catch (error) {
8845
- logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8846
- return Promise.reject(error);
8847
- }
8848
- }
8849
8803
  }
8850
8804
 
8851
8805
  class WalletService extends Base {
@@ -8955,7 +8909,6 @@ class WalletService extends Base {
8955
8909
  */
8956
8910
  async export({ walletId, authenticationOptions, exportOptions }) {
8957
8911
  try {
8958
- const { user: { wallabyAuthPubKey }, } = authenticationOptions;
8959
8912
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
8960
8913
  throw new WallabyError({
8961
8914
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9065,10 +9018,20 @@ class WalletService extends Base {
9065
9018
  });
9066
9019
  }
9067
9020
  const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
9021
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9022
+ const deviceAuthKeys = {
9023
+ publicKey: deviceAuthPublicKey,
9024
+ privateKey: decryptedDevicePrivateKey,
9025
+ };
9026
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9027
+ deviceAuthKeys,
9028
+ walletId,
9029
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
9030
+ });
9068
9031
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9069
9032
  storedEncryptedData: parsedPrimaryShare,
9070
9033
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9071
- wallabyPublicKey: wallabyAuthPubKey,
9034
+ wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9072
9035
  options: {
9073
9036
  authType: this.deviceAuthType,
9074
9037
  password: authenticationOptions.password,
@@ -9076,17 +9039,18 @@ class WalletService extends Base {
9076
9039
  prfValue: authenticationOptions.prfValue,
9077
9040
  },
9078
9041
  });
9079
- const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9080
- const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9081
- encryptedKeyShares: [wallabyBoundPrimaryShare],
9082
- walletId,
9083
- deviceAuthKeys: {
9084
- publicKey: deviceAuthPublicKey,
9085
- privateKey: decryptedDevicePrivateKey,
9042
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9043
+ payload: {
9044
+ walletId: walletId,
9045
+ signature,
9046
+ message,
9047
+ clientAuthPubKey: deviceAuthKeys.publicKey,
9048
+ recoveryPubKey: deviceAuthKeys.publicKey,
9049
+ encryptedShares: [wallabyBoundPrimaryShare],
9086
9050
  },
9087
9051
  });
9088
9052
  decryptedSeedPhrase = await this.cipher.decrypt({
9089
- cipherText: encryptedReconstructedSeedPhrase,
9053
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9090
9054
  decryptionKey: decryptedDevicePrivateKey,
9091
9055
  });
9092
9056
  if (exportOptions.algorandSeedPhrase) {
@@ -9124,7 +9088,9 @@ class WalletService extends Base {
9124
9088
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9125
9089
  */
9126
9090
  async import(input) {
9091
+ var _a;
9127
9092
  try {
9093
+ const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : uuid.v4();
9128
9094
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9129
9095
  if (!encryptedDevicePrivateKey) {
9130
9096
  throw new WallabyError({
@@ -9155,7 +9121,7 @@ class WalletService extends Base {
9155
9121
  const importRequest = await this.handlers.handleImportWallet({
9156
9122
  publicKey: clientAuthPubKey,
9157
9123
  privateKey: decryptedDevicePrivateKey,
9158
- }, input);
9124
+ }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9159
9125
  return importRequest;
9160
9126
  }
9161
9127
  catch (error) {
@@ -9169,11 +9135,15 @@ class WalletService extends Base {
9169
9135
  *
9170
9136
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9171
9137
  * @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
9138
+ *
9139
+ * @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
9140
+ * Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
9172
9141
  */
9173
9142
  async recover(input) {
9174
9143
  var _a, _b;
9175
9144
  try {
9176
- const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9145
+ const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9146
+ input.authenticationOptions.user.wallabyAuthPubKey;
9177
9147
  const deviceAuthKeyPair = createIdentity();
9178
9148
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9179
9149
  authType: this.deviceAuthType,
@@ -9213,27 +9183,37 @@ class WalletService extends Base {
9213
9183
  return recoverWithSeedPhraseResponse;
9214
9184
  }
9215
9185
  else if (input.decryptedShares) {
9216
- const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9217
- const encrypted = await this.cipher.encrypt({
9218
- data: decryptedShare,
9219
- encryptionKey: wallabyPublicKey,
9220
- });
9221
- return encrypted;
9222
- }));
9223
- if (!encryptedShares.length) {
9186
+ if (!input.decryptedShares.length) {
9224
9187
  throw new WallabyError({
9225
9188
  message: 'Decrypted shares are required',
9226
9189
  statusCode: 400,
9227
9190
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
9228
9191
  });
9229
9192
  }
9230
- const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9231
- encryptedKeyShares: encryptedShares,
9193
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9232
9194
  deviceAuthKeys: deviceAuthKeyPair,
9233
9195
  walletId: input.walletId,
9196
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
9197
+ });
9198
+ const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9199
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9200
+ return await this.cipher.encrypt({
9201
+ data: decryptedShare,
9202
+ encryptionKey: transportEncryptionKey,
9203
+ });
9204
+ }));
9205
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9206
+ payload: {
9207
+ walletId: input.walletId,
9208
+ signature,
9209
+ message,
9210
+ clientAuthPubKey: deviceAuthKeyPair.publicKey,
9211
+ recoveryPubKey: deviceAuthKeyPair.publicKey,
9212
+ encryptedShares,
9213
+ },
9234
9214
  });
9235
9215
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9236
- cipherText: encryptedSeed,
9216
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9237
9217
  decryptionKey: deviceAuthKeyPair.privateKey,
9238
9218
  encryptionKey: wallabyPublicKey,
9239
9219
  });
@@ -9291,17 +9271,9 @@ class WalletService extends Base {
9291
9271
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9292
9272
  try {
9293
9273
  const signatureMessage = await this.authService.getSignature({
9294
- publicKey: deviceAuthKeys.publicKey,
9295
- privateKey: deviceAuthKeys.privateKey,
9296
- });
9297
- // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9298
- // payload: {
9299
- // walletId,
9300
- // signature: signatureMessage.signature,
9301
- // message: signatureMessage.message,
9302
- // clientAuthPubKey: deviceAuthKeys.publicKey,
9303
- // },
9304
- // });
9274
+ deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9275
+ walletId,
9276
+ });
9305
9277
  const response = await this.api.wallets.retrieveShares({
9306
9278
  walletId: walletId,
9307
9279
  signature: signatureMessage.signature,
@@ -9482,6 +9454,7 @@ class WalletService extends Base {
9482
9454
  */
9483
9455
  async initAddNewDevice(input) {
9484
9456
  const { walletId, backupUrl, authenticationOptions } = input;
9457
+ const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9485
9458
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9486
9459
  if (!encryptedDevicePrivateKey) {
9487
9460
  throw new WallabyError({
@@ -9542,7 +9515,7 @@ class WalletService extends Base {
9542
9515
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9543
9516
  storedEncryptedData: parsedPrimaryShare,
9544
9517
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9545
- wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9518
+ wallabyPublicKey,
9546
9519
  options: {
9547
9520
  authType: this.deviceAuthType,
9548
9521
  password: authenticationOptions.password,
@@ -9601,22 +9574,11 @@ class WalletService extends Base {
9601
9574
  }
9602
9575
  const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9603
9576
  const signatureMessage = await this.authService.getSignature({
9604
- publicKey: devicePublicKey,
9605
- privateKey: decryptedDevicePrivateKey,
9606
- }, exports.PasskeyChallengeType.REGISTRATION);
9607
- // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9608
- // payload: {
9609
- // walletId: input.walletId,
9610
- // message: signatureMessage.message,
9611
- // signature: signatureMessage.signature,
9612
- // clientAuthPubKey: devicePublicKey,
9613
- // share: {
9614
- // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9615
- // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9616
- // type: KeyTypeName.OwnerBackupDeviceShare,
9617
- // },
9618
- // },
9619
- // });
9577
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
9578
+ walletId: input.walletId,
9579
+ passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
9580
+ });
9581
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9620
9582
  const backUpResponse = await this.api.wallets.addNewDevice({
9621
9583
  walletId: input.walletId,
9622
9584
  message: signatureMessage.message,
@@ -9624,7 +9586,7 @@ class WalletService extends Base {
9624
9586
  clientAuthPubKey: devicePublicKey,
9625
9587
  share: {
9626
9588
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9627
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9589
+ wrappingPublicKey: wallabyPublicKey,
9628
9590
  type: exports.KeyTypeName.OwnerBackupDeviceShare,
9629
9591
  },
9630
9592
  });
@@ -9632,7 +9594,8 @@ class WalletService extends Base {
9632
9594
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9633
9595
  {
9634
9596
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9635
- wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9597
+ wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9598
+ input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9636
9599
  type: exports.KeyTypeName.OwnerMainDeviceShare,
9637
9600
  },
9638
9601
  ];
@@ -9689,12 +9652,28 @@ class WalletService extends Base {
9689
9652
  });
9690
9653
  }
9691
9654
  const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
9655
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9656
+ authType: this.deviceAuthType,
9657
+ password: input.authenticationOptions.password,
9658
+ salt: input.authenticationOptions.clientSalt,
9659
+ prfValue: input.authenticationOptions.prfValue,
9660
+ });
9661
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9662
+ cipherText: parsedDevicePrivateKey,
9663
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9664
+ });
9665
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9666
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9667
+ deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
9668
+ walletId,
9669
+ });
9670
+ const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9692
9671
  if (storedSeedPhrase) {
9693
9672
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9694
9673
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9695
9674
  storedEncryptedData: parsedStoredSeedPhrase,
9696
9675
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9697
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9676
+ wallabyPublicKey,
9698
9677
  options: {
9699
9678
  authType: this.deviceAuthType,
9700
9679
  password: input.authenticationOptions.password,
@@ -9708,7 +9687,7 @@ class WalletService extends Base {
9708
9687
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9709
9688
  storedEncryptedData: parsedPrimaryKeyShare,
9710
9689
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9711
- wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9690
+ wallabyPublicKey,
9712
9691
  options: {
9713
9692
  authType: this.deviceAuthType,
9714
9693
  password: input.authenticationOptions.password,
@@ -9724,21 +9703,6 @@ class WalletService extends Base {
9724
9703
  errorCode: 'sdk_private_key_not_found',
9725
9704
  });
9726
9705
  }
9727
- const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9728
- authType: this.deviceAuthType,
9729
- password: input.authenticationOptions.password,
9730
- salt: input.authenticationOptions.clientSalt,
9731
- prfValue: input.authenticationOptions.prfValue,
9732
- });
9733
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9734
- cipherText: parsedDevicePrivateKey,
9735
- decryptionKey: derivedCredentialsKeyPair.privateKey,
9736
- });
9737
- const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9738
- const { signature, message } = await this.authService.getSignature({
9739
- privateKey: decryptedDevicePrivateKey,
9740
- publicKey: devicePublicKey,
9741
- });
9742
9706
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9743
9707
  payload: {
9744
9708
  walletId,
@@ -9930,8 +9894,8 @@ class WalletService extends Base {
9930
9894
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9931
9895
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9932
9896
  const signInSignatureMessage = await this.authService.getSignature({
9933
- publicKey: devicePublicKey,
9934
- privateKey: decryptedPrivateKey,
9897
+ deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9898
+ walletId,
9935
9899
  });
9936
9900
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9937
9901
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -9957,7 +9921,6 @@ class WalletService extends Base {
9957
9921
  // Store authentication tokens
9958
9922
  await this.localStorageService.saveInBulk([
9959
9923
  { key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
9960
- { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
9961
9924
  { key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
9962
9925
  { key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9963
9926
  ]);
@@ -10020,8 +9983,8 @@ class WalletService extends Base {
10020
9983
  throw error;
10021
9984
  }
10022
9985
  }
10023
- async clearDevice() {
10024
- await this.localStorageService.clearLocalStorage();
9986
+ async clearDevice({ walletId }) {
9987
+ await this.localStorageService.clearLocalStorage(walletId);
10025
9988
  }
10026
9989
  /**
10027
9990
  * Prepares authentication data and encrypted payload for any request.
@@ -10058,9 +10021,11 @@ class WalletService extends Base {
10058
10021
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10059
10022
  // Get signature message
10060
10023
  const signatureMessage = await this.authService.getSignature({
10061
- publicKey: deviceAuthPublicKey,
10062
- privateKey: decryptedDevicePrivateKey,
10063
- }, exports.PasskeyChallengeType.AUTHENTICATION);
10024
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
10025
+ walletId,
10026
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
10027
+ });
10028
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10064
10029
  // Prepare encrypted data (seed phrase or key shares)
10065
10030
  const sharesEncryptedWithWallabyPubKey = [];
10066
10031
  let readyForTransportSeedPhrase = undefined;
@@ -10080,7 +10045,7 @@ class WalletService extends Base {
10080
10045
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10081
10046
  storedEncryptedData: parsedSeedPhrase,
10082
10047
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10083
- wallabyPublicKey: user.wallabyAuthPubKey,
10048
+ wallabyPublicKey,
10084
10049
  options: {
10085
10050
  authType: this.deviceAuthType,
10086
10051
  password,
@@ -10095,7 +10060,7 @@ class WalletService extends Base {
10095
10060
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10096
10061
  storedEncryptedData: parsedPrimaryShare,
10097
10062
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10098
- wallabyPublicKey: user.wallabyAuthPubKey,
10063
+ wallabyPublicKey,
10099
10064
  options: {
10100
10065
  authType: this.deviceAuthType,
10101
10066
  password,
@@ -10264,6 +10229,7 @@ class WalletService extends Base {
10264
10229
  seedPhrase: decryptedSeedPhrase,
10265
10230
  storeSeedPhrase: false,
10266
10231
  returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10232
+ walletId: input.walletId,
10267
10233
  keyShareOptions: {
10268
10234
  threshold: 2,
10269
10235
  numberOfKeyShares: 3,
@@ -10314,20 +10280,31 @@ class WalletService extends Base {
10314
10280
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10315
10281
  }
10316
10282
  if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10283
+ const deviceAuthKeys = {
10284
+ publicKey: clientPublicKey,
10285
+ privateKey: decryptedClientAuthPrivKey,
10286
+ };
10287
+ const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
10288
+ deviceAuthKeys,
10289
+ walletId: input.walletId,
10290
+ passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
10291
+ });
10317
10292
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10318
10293
  data: decryptedPrimaryShare,
10319
- encryptionKey: authentication.user.wallabyAuthPubKey,
10294
+ encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10320
10295
  });
10321
- const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10322
- walletId: input.walletId,
10323
- encryptedKeyShares: [flippedEncryptedPrimaryShare],
10324
- deviceAuthKeys: {
10325
- publicKey: clientPublicKey,
10326
- privateKey: decryptedClientAuthPrivKey,
10296
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
10297
+ payload: {
10298
+ walletId: input.walletId,
10299
+ signature,
10300
+ message,
10301
+ clientAuthPubKey: deviceAuthKeys.publicKey,
10302
+ recoveryPubKey: deviceAuthKeys.publicKey,
10303
+ encryptedShares: [flippedEncryptedPrimaryShare],
10327
10304
  },
10328
10305
  });
10329
10306
  decryptedSeedPhrase = await this.cipher.decrypt({
10330
- cipherText: reconstructedSeedPhrase,
10307
+ cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10331
10308
  decryptionKey: decryptedClientAuthPrivKey,
10332
10309
  });
10333
10310
  }
@@ -10434,7 +10411,7 @@ class WalletDataService extends Base {
10434
10411
  * Note: Either chainName or tokenStandard must be provided.
10435
10412
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10436
10413
  */
10437
- async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10414
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10438
10415
  try {
10439
10416
  if (!tokensAndAddressesList.length) {
10440
10417
  throw new WallabyError({
@@ -11191,9 +11168,11 @@ class Swap extends Base {
11191
11168
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11192
11169
  // Get signature message
11193
11170
  const signatureMessage = await this.authService.getSignature({
11194
- publicKey: deviceAuthPublicKey,
11195
- privateKey: decryptedDevicePrivateKey,
11196
- }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11171
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11172
+ passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
11173
+ walletId,
11174
+ });
11175
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11197
11176
  // Prepare encrypted data (seed phrase or key shares)
11198
11177
  const sharesEncryptedWithWallabyPubKey = [];
11199
11178
  let readyForTransportSeedPhrase = undefined;
@@ -11214,7 +11193,7 @@ class Swap extends Base {
11214
11193
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11215
11194
  storedEncryptedData: parsedSeedPhrase,
11216
11195
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11217
- wallabyPublicKey: user.wallabyAuthPubKey,
11196
+ wallabyPublicKey,
11218
11197
  options: {
11219
11198
  authType: this.deviceAuthType,
11220
11199
  password,
@@ -11229,7 +11208,7 @@ class Swap extends Base {
11229
11208
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11230
11209
  storedEncryptedData: parsedPrimaryShare,
11231
11210
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11232
- wallabyPublicKey: user.wallabyAuthPubKey,
11211
+ wallabyPublicKey,
11233
11212
  options: {
11234
11213
  authType: this.deviceAuthType,
11235
11214
  password,
@@ -11484,7 +11463,7 @@ class Transactions extends Base {
11484
11463
  * @param {BlockchainName} blockchain
11485
11464
  * @returns {FeeEstimateRequest}
11486
11465
  */
11487
- async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11466
+ async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11488
11467
  try {
11489
11468
  const response = await this.request(TransactionsRoutes.estimateFee, {
11490
11469
  queryParams: {
@@ -11827,9 +11806,11 @@ class Transactions extends Base {
11827
11806
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11828
11807
  // Get signature message
11829
11808
  const signatureMessage = await this.authService.getSignature({
11830
- publicKey: deviceAuthPublicKey,
11831
- privateKey: decryptedDevicePrivateKey,
11832
- }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11809
+ deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11810
+ walletId,
11811
+ passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
11812
+ });
11813
+ const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11833
11814
  // Prepare encrypted data (seed phrase or key shares)
11834
11815
  const sharesEncryptedWithWallabyPubKey = [];
11835
11816
  let readyForTransportSeedPhrase = undefined;
@@ -11850,7 +11831,7 @@ class Transactions extends Base {
11850
11831
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11851
11832
  storedEncryptedData: parsedSeedPhrase,
11852
11833
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11853
- wallabyPublicKey: user.wallabyAuthPubKey,
11834
+ wallabyPublicKey,
11854
11835
  options: {
11855
11836
  authType: this.deviceAuthType,
11856
11837
  password,
@@ -11865,7 +11846,7 @@ class Transactions extends Base {
11865
11846
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11866
11847
  storedEncryptedData: parsedPrimaryShare,
11867
11848
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11868
- wallabyPublicKey: user.wallabyAuthPubKey,
11849
+ wallabyPublicKey,
11869
11850
  options: {
11870
11851
  authType: this.deviceAuthType,
11871
11852
  password,