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