wallaby-cash 2.3.7 → 2.3.8

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,12 +4,13 @@ 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');
8
7
  const log = require('loglevel');
9
8
  const cryptoJs = require('crypto-js');
10
9
  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');
13
14
 
14
15
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
15
16
 
@@ -294,6 +295,7 @@ exports.LocalStorageItems = void 0;
294
295
  LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
295
296
  LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
296
297
  LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
298
+ LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
297
299
  LocalStorageItems["ClientAuthToken"] = "republic-jwt";
298
300
  LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
299
301
  LocalStorageItems["Blob"] = "blob";
@@ -599,7 +601,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
599
601
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
600
602
  ];
601
603
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
602
- const currentPackageVersion = "2.3.7" ;
604
+ const currentPackageVersion = "2.3.8" ;
603
605
 
604
606
  /**
605
607
  * Storage keys adapter for Storage interface across different platforms.
@@ -4931,6 +4933,43 @@ class StorageService {
4931
4933
  }
4932
4934
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4933
4935
  }
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
+ }
4934
4973
  /**
4935
4974
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4936
4975
  * Encrypts and stores device auth private key
@@ -5139,15 +5178,7 @@ class StorageService {
5139
5178
  return undefined;
5140
5179
  }
5141
5180
  async clearLocalStorage(walletId) {
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
- ];
5181
+ const userKeysToRemove = [exports.LocalStorageItems.AccessToken, exports.V2KeyNames.EncryptedDevicePrivateKey, exports.V2KeyNames.WallabyAuthPubKey];
5151
5182
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5152
5183
  if (walletId) {
5153
5184
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6313,16 +6344,6 @@ class Api {
6313
6344
  * @secure
6314
6345
  */
6315
6346
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6316
- /**
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
6318
- *
6319
- * @tags Transactions, Raw, Transactions
6320
- * @name SignAndBroadcastRawTx
6321
- * @summary Sign and broadcast raw transaction API
6322
- * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6323
- * @secure
6324
- */
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
6347
  /**
6327
6348
  * No description
6328
6349
  *
@@ -6333,6 +6354,16 @@ class Api {
6333
6354
  * @secure
6334
6355
  */
6335
6356
  fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6357
+ /**
6358
+ * @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
+ *
6360
+ * @tags Transactions, Raw, Transactions
6361
+ * @name SignAndBroadcastRawTx
6362
+ * @summary Sign and broadcast raw transaction API
6363
+ * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6364
+ * @secure
6365
+ */
6366
+ 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)),
6336
6367
  /**
6337
6368
  * No description
6338
6369
  *
@@ -7369,13 +7400,6 @@ const SwapRoutes = {
7369
7400
  },
7370
7401
  };
7371
7402
 
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
-
7379
7403
  /* eslint-disable no-useless-catch */
7380
7404
  /**
7381
7405
  * Web Authenticator Implementation
@@ -7515,7 +7539,7 @@ class PasskeyService {
7515
7539
  this.authenticator = new Authenticator();
7516
7540
  }
7517
7541
  preparePasskeyRequestOptions(options) {
7518
- var _a, _b, _c, _d, _e, _f, _g, _h;
7542
+ var _a, _b, _c, _d, _e, _f;
7519
7543
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7520
7544
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7521
7545
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7523,13 +7547,11 @@ class PasskeyService {
7523
7547
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7524
7548
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7525
7549
  : undefined;
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 : {}) }) });
7550
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7551
+ eval: {
7552
+ first: prfExtensionEvaluation,
7553
+ },
7554
+ } }) });
7533
7555
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7534
7556
  // While the authenticator still works with the prf and would return the response (if any),
7535
7557
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7537,7 +7559,7 @@ class PasskeyService {
7537
7559
  return parsedOptions;
7538
7560
  }
7539
7561
  preparePasskeyCreationOptions(options) {
7540
- var _a, _b, _c, _d, _e, _f, _g, _h;
7562
+ var _a, _b, _c, _d, _e, _f;
7541
7563
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7542
7564
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7543
7565
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7545,8 +7567,12 @@ class PasskeyService {
7545
7567
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7546
7568
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7547
7569
  : undefined;
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);
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);
7550
7576
  return parsedOptions;
7551
7577
  }
7552
7578
  /**
@@ -7561,10 +7587,7 @@ class PasskeyService {
7561
7587
  let passkeyCredential;
7562
7588
  let signInResponse;
7563
7589
  try {
7564
- const registrationChallengeResponse = await getSignature({
7565
- deviceAuthKeys: deviceKeyPair,
7566
- passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
7567
- });
7590
+ const registrationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
7568
7591
  if (!registrationChallengeResponse.registrationOptions)
7569
7592
  throw new WallabyError({
7570
7593
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7607,10 +7630,7 @@ class PasskeyService {
7607
7630
  catch (error) {
7608
7631
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7609
7632
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7610
- const authenticationChallengeResponse = await getSignature({
7611
- deviceAuthKeys: deviceKeyPair,
7612
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
7613
- });
7633
+ const authenticationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
7614
7634
  if (!authenticationChallengeResponse.authenticationOptions)
7615
7635
  throw new WallabyError({
7616
7636
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7681,10 +7701,9 @@ class PasskeyService {
7681
7701
  errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7682
7702
  });
7683
7703
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
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: {
7704
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, lodash.omit(parsedOptions.extensions, 'credProps')), { prf: {
7686
7705
  eval: {
7687
- first: prfFirst,
7706
+ first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7688
7707
  },
7689
7708
  } }) });
7690
7709
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7911,6 +7930,10 @@ class PasskeyService {
7911
7930
  key: exports.LocalStorageItems.AccessToken,
7912
7931
  value: authenticationResponse.accessToken,
7913
7932
  },
7933
+ {
7934
+ key: exports.LocalStorageItems.WallabyAuthPubKey,
7935
+ value: authenticationResponse.user.wallabyAuthPubKey,
7936
+ },
7914
7937
  ]);
7915
7938
  }
7916
7939
  /**
@@ -8119,14 +8142,13 @@ class AuthService extends Base {
8119
8142
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8120
8143
  * @returns the messaged, the hash, and the signature using the passed private key.
8121
8144
  */
8122
- async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8145
+ async getSignature(deviceAuthKeys, passkeyChallengeType) {
8123
8146
  try {
8124
8147
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8125
8148
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
8126
8149
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8127
8150
  const response = await this.request(AuthRoutes.signatureMessage, {
8128
8151
  payload: {
8129
- walletId,
8130
8152
  clientAuthPubKey: deviceAuthKeys.publicKey,
8131
8153
  passkeyChallengeType: challengeType,
8132
8154
  },
@@ -8157,10 +8179,7 @@ class AuthService extends Base {
8157
8179
  logger.info('key pair generated', !!deviceKeyPair);
8158
8180
  let authentication;
8159
8181
  try {
8160
- const signatureMessageResponse = await this.getSignature({
8161
- deviceAuthKeys: deviceKeyPair,
8162
- passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
8163
- });
8182
+ const signatureMessageResponse = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
8164
8183
  logger.info('signature has been generated', !!signatureMessageResponse);
8165
8184
  switch (this.deviceAuthType) {
8166
8185
  case exports.AuthType.Passkey:
@@ -8193,10 +8212,7 @@ class AuthService extends Base {
8193
8212
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8194
8213
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8195
8214
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8196
- const newChallenge = await this.getSignature({
8197
- deviceAuthKeys: deviceKeyPair,
8198
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
8199
- });
8215
+ const newChallenge = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
8200
8216
  authentication = await this.passkeyService.authenticate({
8201
8217
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8202
8218
  challengeResponse: newChallenge,
@@ -8233,7 +8249,10 @@ class AuthService extends Base {
8233
8249
  errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
8234
8250
  });
8235
8251
  }
8236
- await this.localStorageService.save(exports.LocalStorageItems.AccessToken, authentication.accessToken);
8252
+ await this.localStorageService.saveInBulk([
8253
+ { key: exports.LocalStorageItems.AccessToken, value: authentication.accessToken },
8254
+ { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8255
+ ]);
8237
8256
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8238
8257
  }
8239
8258
  catch (error) {
@@ -8309,9 +8328,7 @@ class AuthService extends Base {
8309
8328
  },
8310
8329
  credentialsKeyPair,
8311
8330
  });
8312
- const signatureMessage = await this.getSignature({
8313
- deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8314
- });
8331
+ const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8315
8332
  const authentication = await this.request(AuthRoutes.signIn, {
8316
8333
  payload: {
8317
8334
  externalUserId: this.userId,
@@ -8435,6 +8452,10 @@ class AuthService extends Base {
8435
8452
  key: exports.LocalStorageItems.AccessToken,
8436
8453
  value: authResponse.accessToken,
8437
8454
  },
8455
+ {
8456
+ key: exports.LocalStorageItems.WallabyAuthPubKey,
8457
+ value: authResponse.user.wallabyAuthPubKey,
8458
+ },
8438
8459
  ]);
8439
8460
  return authResponse;
8440
8461
  });
@@ -8519,16 +8540,12 @@ class WalletHandlersService extends Base {
8519
8540
  this.userId = config.userId;
8520
8541
  }
8521
8542
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8522
- var _a, _b, _c, _d, _e;
8543
+ var _a, _b, _c, _d;
8523
8544
  try {
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
- });
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);
8532
8549
  if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8533
8550
  importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8534
8551
  !importWalletInput.keyShareOptions) {
@@ -8538,7 +8555,7 @@ class WalletHandlersService extends Base {
8538
8555
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
8539
8556
  });
8540
8557
  }
8541
- const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8558
+ const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8542
8559
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8543
8560
  throw new WallabyError({
8544
8561
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8548,11 +8565,10 @@ class WalletHandlersService extends Base {
8548
8565
  }
8549
8566
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8550
8567
  data: importWalletInput.seedPhrase,
8551
- encryptionKey: wallabyAuthPubKey,
8568
+ encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8552
8569
  });
8553
8570
  const importWalletPayload = {
8554
- reference: importWalletInput.reference,
8555
- walletId: importWalletInput.walletId,
8571
+ reference: uuid.v4(),
8556
8572
  message,
8557
8573
  signature,
8558
8574
  encryptedSeed: readyForTransportSeedPhrase,
@@ -8561,7 +8577,7 @@ class WalletHandlersService extends Base {
8561
8577
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8562
8578
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8563
8579
  walletOwnershipType: exports.WalletOwnershipType.SingleOwner,
8564
- wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8580
+ wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8565
8581
  };
8566
8582
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8567
8583
  payload: importWalletPayload,
@@ -8599,7 +8615,7 @@ class WalletHandlersService extends Base {
8599
8615
  }
8600
8616
  catch (error) {
8601
8617
  throw new WallabyError({
8602
- message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8618
+ message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8603
8619
  statusCode: error.statusCode,
8604
8620
  errorCode: error.errorCode,
8605
8621
  data: error.data,
@@ -8621,9 +8637,9 @@ class WalletHandlersService extends Base {
8621
8637
  var _a, _b, _c, _d, _e, _f;
8622
8638
  try {
8623
8639
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8624
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8625
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
8626
- });
8640
+ publicKey: deviceAuthKeys.publicKey,
8641
+ privateKey: deviceAuthKeys.privateKey,
8642
+ }, exports.PasskeyChallengeType.AUTHENTICATION);
8627
8643
  if ((walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8628
8644
  walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8629
8645
  !walletCreationInput.keyShareOptions) {
@@ -8800,6 +8816,36 @@ class WalletHandlersService extends Base {
8800
8816
  });
8801
8817
  }
8802
8818
  }
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
+ }
8803
8849
  }
8804
8850
 
8805
8851
  class WalletService extends Base {
@@ -8909,6 +8955,7 @@ class WalletService extends Base {
8909
8955
  */
8910
8956
  async export({ walletId, authenticationOptions, exportOptions }) {
8911
8957
  try {
8958
+ const { user: { wallabyAuthPubKey }, } = authenticationOptions;
8912
8959
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
8913
8960
  throw new WallabyError({
8914
8961
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9018,20 +9065,10 @@ class WalletService extends Base {
9018
9065
  });
9019
9066
  }
9020
9067
  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
- });
9031
9068
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9032
9069
  storedEncryptedData: parsedPrimaryShare,
9033
9070
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9034
- wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9071
+ wallabyPublicKey: wallabyAuthPubKey,
9035
9072
  options: {
9036
9073
  authType: this.deviceAuthType,
9037
9074
  password: authenticationOptions.password,
@@ -9039,18 +9076,17 @@ class WalletService extends Base {
9039
9076
  prfValue: authenticationOptions.prfValue,
9040
9077
  },
9041
9078
  });
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],
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,
9050
9086
  },
9051
9087
  });
9052
9088
  decryptedSeedPhrase = await this.cipher.decrypt({
9053
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9089
+ cipherText: encryptedReconstructedSeedPhrase,
9054
9090
  decryptionKey: decryptedDevicePrivateKey,
9055
9091
  });
9056
9092
  if (exportOptions.algorandSeedPhrase) {
@@ -9088,9 +9124,7 @@ class WalletService extends Base {
9088
9124
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9089
9125
  */
9090
9126
  async import(input) {
9091
- var _a;
9092
9127
  try {
9093
- const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : uuid.v4();
9094
9128
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9095
9129
  if (!encryptedDevicePrivateKey) {
9096
9130
  throw new WallabyError({
@@ -9121,7 +9155,7 @@ class WalletService extends Base {
9121
9155
  const importRequest = await this.handlers.handleImportWallet({
9122
9156
  publicKey: clientAuthPubKey,
9123
9157
  privateKey: decryptedDevicePrivateKey,
9124
- }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9158
+ }, input);
9125
9159
  return importRequest;
9126
9160
  }
9127
9161
  catch (error) {
@@ -9135,15 +9169,11 @@ class WalletService extends Base {
9135
9169
  *
9136
9170
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9137
9171
  * @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.
9141
9172
  */
9142
9173
  async recover(input) {
9143
9174
  var _a, _b;
9144
9175
  try {
9145
- const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9146
- input.authenticationOptions.user.wallabyAuthPubKey;
9176
+ const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9147
9177
  const deviceAuthKeyPair = createIdentity();
9148
9178
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9149
9179
  authType: this.deviceAuthType,
@@ -9183,37 +9213,27 @@ class WalletService extends Base {
9183
9213
  return recoverWithSeedPhraseResponse;
9184
9214
  }
9185
9215
  else if (input.decryptedShares) {
9186
- if (!input.decryptedShares.length) {
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) {
9187
9224
  throw new WallabyError({
9188
9225
  message: 'Decrypted shares are required',
9189
9226
  statusCode: 400,
9190
9227
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
9191
9228
  });
9192
9229
  }
9193
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9230
+ const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9231
+ encryptedKeyShares: encryptedShares,
9194
9232
  deviceAuthKeys: deviceAuthKeyPair,
9195
9233
  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
- },
9214
9234
  });
9215
9235
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9216
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9236
+ cipherText: encryptedSeed,
9217
9237
  decryptionKey: deviceAuthKeyPair.privateKey,
9218
9238
  encryptionKey: wallabyPublicKey,
9219
9239
  });
@@ -9271,9 +9291,17 @@ class WalletService extends Base {
9271
9291
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9272
9292
  try {
9273
9293
  const signatureMessage = await this.authService.getSignature({
9274
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9275
- walletId,
9276
- });
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
+ // });
9277
9305
  const response = await this.api.wallets.retrieveShares({
9278
9306
  walletId: walletId,
9279
9307
  signature: signatureMessage.signature,
@@ -9454,7 +9482,6 @@ class WalletService extends Base {
9454
9482
  */
9455
9483
  async initAddNewDevice(input) {
9456
9484
  const { walletId, backupUrl, authenticationOptions } = input;
9457
- const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9458
9485
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9459
9486
  if (!encryptedDevicePrivateKey) {
9460
9487
  throw new WallabyError({
@@ -9515,7 +9542,7 @@ class WalletService extends Base {
9515
9542
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9516
9543
  storedEncryptedData: parsedPrimaryShare,
9517
9544
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9518
- wallabyPublicKey,
9545
+ wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9519
9546
  options: {
9520
9547
  authType: this.deviceAuthType,
9521
9548
  password: authenticationOptions.password,
@@ -9574,11 +9601,22 @@ class WalletService extends Base {
9574
9601
  }
9575
9602
  const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9576
9603
  const signatureMessage = await this.authService.getSignature({
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;
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
+ // });
9582
9620
  const backUpResponse = await this.api.wallets.addNewDevice({
9583
9621
  walletId: input.walletId,
9584
9622
  message: signatureMessage.message,
@@ -9586,7 +9624,7 @@ class WalletService extends Base {
9586
9624
  clientAuthPubKey: devicePublicKey,
9587
9625
  share: {
9588
9626
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9589
- wrappingPublicKey: wallabyPublicKey,
9627
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9590
9628
  type: exports.KeyTypeName.OwnerBackupDeviceShare,
9591
9629
  },
9592
9630
  });
@@ -9594,8 +9632,7 @@ class WalletService extends Base {
9594
9632
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9595
9633
  {
9596
9634
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9597
- wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9598
- input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9635
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9599
9636
  type: exports.KeyTypeName.OwnerMainDeviceShare,
9600
9637
  },
9601
9638
  ];
@@ -9652,28 +9689,12 @@ class WalletService extends Base {
9652
9689
  });
9653
9690
  }
9654
9691
  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;
9671
9692
  if (storedSeedPhrase) {
9672
9693
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9673
9694
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9674
9695
  storedEncryptedData: parsedStoredSeedPhrase,
9675
9696
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9676
- wallabyPublicKey,
9697
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9677
9698
  options: {
9678
9699
  authType: this.deviceAuthType,
9679
9700
  password: input.authenticationOptions.password,
@@ -9687,7 +9708,7 @@ class WalletService extends Base {
9687
9708
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9688
9709
  storedEncryptedData: parsedPrimaryKeyShare,
9689
9710
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9690
- wallabyPublicKey,
9711
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9691
9712
  options: {
9692
9713
  authType: this.deviceAuthType,
9693
9714
  password: input.authenticationOptions.password,
@@ -9703,6 +9724,21 @@ class WalletService extends Base {
9703
9724
  errorCode: 'sdk_private_key_not_found',
9704
9725
  });
9705
9726
  }
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
+ });
9706
9742
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9707
9743
  payload: {
9708
9744
  walletId,
@@ -9894,8 +9930,8 @@ class WalletService extends Base {
9894
9930
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9895
9931
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9896
9932
  const signInSignatureMessage = await this.authService.getSignature({
9897
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9898
- walletId,
9933
+ publicKey: devicePublicKey,
9934
+ privateKey: decryptedPrivateKey,
9899
9935
  });
9900
9936
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9901
9937
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -9921,6 +9957,7 @@ class WalletService extends Base {
9921
9957
  // Store authentication tokens
9922
9958
  await this.localStorageService.saveInBulk([
9923
9959
  { key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
9960
+ { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
9924
9961
  { key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
9925
9962
  { key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9926
9963
  ]);
@@ -9983,8 +10020,8 @@ class WalletService extends Base {
9983
10020
  throw error;
9984
10021
  }
9985
10022
  }
9986
- async clearDevice({ walletId }) {
9987
- await this.localStorageService.clearLocalStorage(walletId);
10023
+ async clearDevice() {
10024
+ await this.localStorageService.clearLocalStorage();
9988
10025
  }
9989
10026
  /**
9990
10027
  * Prepares authentication data and encrypted payload for any request.
@@ -10021,11 +10058,9 @@ class WalletService extends Base {
10021
10058
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10022
10059
  // Get signature message
10023
10060
  const signatureMessage = await this.authService.getSignature({
10024
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
10025
- walletId,
10026
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
10027
- });
10028
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10061
+ publicKey: deviceAuthPublicKey,
10062
+ privateKey: decryptedDevicePrivateKey,
10063
+ }, exports.PasskeyChallengeType.AUTHENTICATION);
10029
10064
  // Prepare encrypted data (seed phrase or key shares)
10030
10065
  const sharesEncryptedWithWallabyPubKey = [];
10031
10066
  let readyForTransportSeedPhrase = undefined;
@@ -10045,7 +10080,7 @@ class WalletService extends Base {
10045
10080
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10046
10081
  storedEncryptedData: parsedSeedPhrase,
10047
10082
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10048
- wallabyPublicKey,
10083
+ wallabyPublicKey: user.wallabyAuthPubKey,
10049
10084
  options: {
10050
10085
  authType: this.deviceAuthType,
10051
10086
  password,
@@ -10060,7 +10095,7 @@ class WalletService extends Base {
10060
10095
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10061
10096
  storedEncryptedData: parsedPrimaryShare,
10062
10097
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10063
- wallabyPublicKey,
10098
+ wallabyPublicKey: user.wallabyAuthPubKey,
10064
10099
  options: {
10065
10100
  authType: this.deviceAuthType,
10066
10101
  password,
@@ -10229,7 +10264,6 @@ class WalletService extends Base {
10229
10264
  seedPhrase: decryptedSeedPhrase,
10230
10265
  storeSeedPhrase: false,
10231
10266
  returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10232
- walletId: input.walletId,
10233
10267
  keyShareOptions: {
10234
10268
  threshold: 2,
10235
10269
  numberOfKeyShares: 3,
@@ -10280,31 +10314,20 @@ class WalletService extends Base {
10280
10314
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10281
10315
  }
10282
10316
  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
- });
10292
10317
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10293
10318
  data: decryptedPrimaryShare,
10294
- encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10319
+ encryptionKey: authentication.user.wallabyAuthPubKey,
10295
10320
  });
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],
10321
+ const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10322
+ walletId: input.walletId,
10323
+ encryptedKeyShares: [flippedEncryptedPrimaryShare],
10324
+ deviceAuthKeys: {
10325
+ publicKey: clientPublicKey,
10326
+ privateKey: decryptedClientAuthPrivKey,
10304
10327
  },
10305
10328
  });
10306
10329
  decryptedSeedPhrase = await this.cipher.decrypt({
10307
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10330
+ cipherText: reconstructedSeedPhrase,
10308
10331
  decryptionKey: decryptedClientAuthPrivKey,
10309
10332
  });
10310
10333
  }
@@ -10411,7 +10434,7 @@ class WalletDataService extends Base {
10411
10434
  * Note: Either chainName or tokenStandard must be provided.
10412
10435
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10413
10436
  */
10414
- async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10437
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10415
10438
  try {
10416
10439
  if (!tokensAndAddressesList.length) {
10417
10440
  throw new WallabyError({
@@ -10999,17 +11022,18 @@ class Swap extends Base {
10999
11022
  this.walletService = new WalletService(config);
11000
11023
  }
11001
11024
  /**
11002
- * Gets a swap quote between two assets (from/to), including fees, min output, and slippage limits.
11025
+ * Gets a swap quote between two assets, including fees, min output, and slippage limits.
11003
11026
  *
11004
11027
  * @public
11005
11028
  * @param {SwapQuoteRequest} request - The swap quote request parameters
11006
11029
  * @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
11007
11030
  */
11008
- async getQuote({ walletId, fromAsset, toAsset, fromAmount, toAmount }) {
11031
+ async getQuote(request) {
11009
11032
  try {
11010
- if (!walletId || !fromAsset || !toAsset) {
11033
+ const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
11034
+ if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
11011
11035
  throw new WallabyError({
11012
- message: 'Missing required parameters: walletId, fromAsset, and toAsset are required',
11036
+ message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
11013
11037
  statusCode: 400,
11014
11038
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
11015
11039
  });
@@ -11021,10 +11045,16 @@ class Swap extends Base {
11021
11045
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
11022
11046
  });
11023
11047
  }
11024
- // Build path with walletId, but exclude it from request body
11048
+ if (fromAmount && toAmount) {
11049
+ throw new WallabyError({
11050
+ message: 'Only one of fromAmount or toAmount may be provided, not both',
11051
+ statusCode: 400,
11052
+ errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
11053
+ });
11054
+ }
11025
11055
  const routePayload = { walletId };
11026
- const requestBody = Object.assign(Object.assign({ fromAsset,
11027
- toAsset }, (fromAmount && { fromAmount })), (toAmount && { toAmount }));
11056
+ const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
11057
+ toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
11028
11058
  const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
11029
11059
  payload: requestBody,
11030
11060
  });
@@ -11168,11 +11198,9 @@ class Swap extends Base {
11168
11198
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11169
11199
  // Get signature message
11170
11200
  const signatureMessage = await this.authService.getSignature({
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;
11201
+ publicKey: deviceAuthPublicKey,
11202
+ privateKey: decryptedDevicePrivateKey,
11203
+ }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11176
11204
  // Prepare encrypted data (seed phrase or key shares)
11177
11205
  const sharesEncryptedWithWallabyPubKey = [];
11178
11206
  let readyForTransportSeedPhrase = undefined;
@@ -11193,7 +11221,7 @@ class Swap extends Base {
11193
11221
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11194
11222
  storedEncryptedData: parsedSeedPhrase,
11195
11223
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11196
- wallabyPublicKey,
11224
+ wallabyPublicKey: user.wallabyAuthPubKey,
11197
11225
  options: {
11198
11226
  authType: this.deviceAuthType,
11199
11227
  password,
@@ -11208,7 +11236,7 @@ class Swap extends Base {
11208
11236
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11209
11237
  storedEncryptedData: parsedPrimaryShare,
11210
11238
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11211
- wallabyPublicKey,
11239
+ wallabyPublicKey: user.wallabyAuthPubKey,
11212
11240
  options: {
11213
11241
  authType: this.deviceAuthType,
11214
11242
  password,
@@ -11463,7 +11491,7 @@ class Transactions extends Base {
11463
11491
  * @param {BlockchainName} blockchain
11464
11492
  * @returns {FeeEstimateRequest}
11465
11493
  */
11466
- async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11494
+ async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11467
11495
  try {
11468
11496
  const response = await this.request(TransactionsRoutes.estimateFee, {
11469
11497
  queryParams: {
@@ -11806,11 +11834,9 @@ class Transactions extends Base {
11806
11834
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11807
11835
  // Get signature message
11808
11836
  const signatureMessage = await this.authService.getSignature({
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;
11837
+ publicKey: deviceAuthPublicKey,
11838
+ privateKey: decryptedDevicePrivateKey,
11839
+ }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11814
11840
  // Prepare encrypted data (seed phrase or key shares)
11815
11841
  const sharesEncryptedWithWallabyPubKey = [];
11816
11842
  let readyForTransportSeedPhrase = undefined;
@@ -11831,7 +11857,7 @@ class Transactions extends Base {
11831
11857
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11832
11858
  storedEncryptedData: parsedSeedPhrase,
11833
11859
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11834
- wallabyPublicKey,
11860
+ wallabyPublicKey: user.wallabyAuthPubKey,
11835
11861
  options: {
11836
11862
  authType: this.deviceAuthType,
11837
11863
  password,
@@ -11846,7 +11872,7 @@ class Transactions extends Base {
11846
11872
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11847
11873
  storedEncryptedData: parsedPrimaryShare,
11848
11874
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11849
- wallabyPublicKey,
11875
+ wallabyPublicKey: user.wallabyAuthPubKey,
11850
11876
  options: {
11851
11877
  authType: this.deviceAuthType,
11852
11878
  password,