wallaby-cash 2.3.7 → 2.3.9

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,12 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
 
5
5
  const algosdk = require('algosdk');
6
6
  const bip39 = require('bip39');
7
- const uuid = require('uuid');
8
7
  const log = require('loglevel');
9
8
  const cryptoJs = require('crypto-js');
10
9
  const jwtDecode = require('jwt-decode');
11
10
  const WebAuthn = require('@simplewebauthn/browser');
12
11
  const jsBase64 = require('js-base64');
12
+ const uuid = require('uuid');
13
13
 
14
14
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
15
15
 
@@ -294,6 +294,7 @@ exports.LocalStorageItems = void 0;
294
294
  LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
295
295
  LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
296
296
  LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
297
+ LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
297
298
  LocalStorageItems["ClientAuthToken"] = "republic-jwt";
298
299
  LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
299
300
  LocalStorageItems["Blob"] = "blob";
@@ -599,7 +600,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
599
600
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
600
601
  ];
601
602
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
602
- const currentPackageVersion = "2.3.7" ;
603
+ const currentPackageVersion = "2.3.9" ;
603
604
 
604
605
  /**
605
606
  * Storage keys adapter for Storage interface across different platforms.
@@ -4931,6 +4932,43 @@ class StorageService {
4931
4932
  }
4932
4933
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4933
4934
  }
4935
+ /**
4936
+ *
4937
+ * Stores Wallaby auth public key to local storage
4938
+ * @param wallabyAuthPubKey
4939
+ */
4940
+ async setWallabyAuthPubKey(wallabyAuthPubKey) {
4941
+ await this.save(exports.V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4942
+ }
4943
+ /**
4944
+ *
4945
+ * Fetches Wallaby auth public key from local storage
4946
+ * @returns { string | undefined } Wallaby Auth Public key or undefined.
4947
+ */
4948
+ async getWallabyAuthPubKey() {
4949
+ let wallabyAuthPubKey = await this.fetch(exports.V2KeyNames.WallabyAuthPubKey);
4950
+ if (wallabyAuthPubKey) {
4951
+ return wallabyAuthPubKey;
4952
+ }
4953
+ // Legacy key migration
4954
+ const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4955
+ const legacyPubKey = await this.getItem(legacyKey);
4956
+ if (legacyPubKey) {
4957
+ wallabyAuthPubKey = legacyPubKey;
4958
+ }
4959
+ else {
4960
+ const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4961
+ const v1PubKey = await this.getItem(v1Key);
4962
+ if (v1PubKey) {
4963
+ wallabyAuthPubKey = v1PubKey;
4964
+ }
4965
+ }
4966
+ if (wallabyAuthPubKey) {
4967
+ await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4968
+ return wallabyAuthPubKey;
4969
+ }
4970
+ return undefined;
4971
+ }
4934
4972
  /**
4935
4973
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4936
4974
  * Encrypts and stores device auth private key
@@ -5139,15 +5177,7 @@ class StorageService {
5139
5177
  return undefined;
5140
5178
  }
5141
5179
  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
- ];
5180
+ const userKeysToRemove = [exports.LocalStorageItems.AccessToken, exports.V2KeyNames.EncryptedDevicePrivateKey, exports.V2KeyNames.WallabyAuthPubKey];
5151
5181
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5152
5182
  if (walletId) {
5153
5183
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6313,16 +6343,6 @@ class Api {
6313
6343
  * @secure
6314
6344
  */
6315
6345
  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
6346
  /**
6327
6347
  * No description
6328
6348
  *
@@ -6333,6 +6353,16 @@ class Api {
6333
6353
  * @secure
6334
6354
  */
6335
6355
  fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6356
+ /**
6357
+ * @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
6358
+ *
6359
+ * @tags Transactions, Raw, Transactions
6360
+ * @name SignAndBroadcastRawTx
6361
+ * @summary Sign and broadcast raw transaction API
6362
+ * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6363
+ * @secure
6364
+ */
6365
+ 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
6366
  /**
6337
6367
  * No description
6338
6368
  *
@@ -7515,7 +7545,7 @@ class PasskeyService {
7515
7545
  this.authenticator = new Authenticator();
7516
7546
  }
7517
7547
  preparePasskeyRequestOptions(options) {
7518
- var _a, _b, _c, _d, _e, _f, _g, _h;
7548
+ var _a, _b, _c, _d, _e, _f;
7519
7549
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7520
7550
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7521
7551
  : ((_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 +7553,11 @@ class PasskeyService {
7523
7553
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7524
7554
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7525
7555
  : 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 : {}) }) });
7556
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7557
+ eval: {
7558
+ first: prfExtensionEvaluation,
7559
+ },
7560
+ } }) });
7533
7561
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7534
7562
  // While the authenticator still works with the prf and would return the response (if any),
7535
7563
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7537,7 +7565,7 @@ class PasskeyService {
7537
7565
  return parsedOptions;
7538
7566
  }
7539
7567
  preparePasskeyCreationOptions(options) {
7540
- var _a, _b, _c, _d, _e, _f, _g, _h;
7568
+ var _a, _b, _c, _d, _e, _f;
7541
7569
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7542
7570
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7543
7571
  : ((_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 +7573,12 @@ class PasskeyService {
7545
7573
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7546
7574
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7547
7575
  : 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);
7576
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7577
+ eval: {
7578
+ first: prfExtensionEvaluation,
7579
+ },
7580
+ } }) });
7581
+ logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7550
7582
  return parsedOptions;
7551
7583
  }
7552
7584
  /**
@@ -7561,10 +7593,7 @@ class PasskeyService {
7561
7593
  let passkeyCredential;
7562
7594
  let signInResponse;
7563
7595
  try {
7564
- const registrationChallengeResponse = await getSignature({
7565
- deviceAuthKeys: deviceKeyPair,
7566
- passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
7567
- });
7596
+ const registrationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
7568
7597
  if (!registrationChallengeResponse.registrationOptions)
7569
7598
  throw new WallabyError({
7570
7599
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7607,10 +7636,7 @@ class PasskeyService {
7607
7636
  catch (error) {
7608
7637
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7609
7638
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7610
- const authenticationChallengeResponse = await getSignature({
7611
- deviceAuthKeys: deviceKeyPair,
7612
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
7613
- });
7639
+ const authenticationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
7614
7640
  if (!authenticationChallengeResponse.authenticationOptions)
7615
7641
  throw new WallabyError({
7616
7642
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7681,10 +7707,9 @@ class PasskeyService {
7681
7707
  errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7682
7708
  });
7683
7709
  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: {
7710
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
7686
7711
  eval: {
7687
- first: prfFirst,
7712
+ first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7688
7713
  },
7689
7714
  } }) });
7690
7715
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7911,6 +7936,10 @@ class PasskeyService {
7911
7936
  key: exports.LocalStorageItems.AccessToken,
7912
7937
  value: authenticationResponse.accessToken,
7913
7938
  },
7939
+ {
7940
+ key: exports.LocalStorageItems.WallabyAuthPubKey,
7941
+ value: authenticationResponse.user.wallabyAuthPubKey,
7942
+ },
7914
7943
  ]);
7915
7944
  }
7916
7945
  /**
@@ -8119,14 +8148,13 @@ class AuthService extends Base {
8119
8148
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8120
8149
  * @returns the messaged, the hash, and the signature using the passed private key.
8121
8150
  */
8122
- async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8151
+ async getSignature(deviceAuthKeys, passkeyChallengeType) {
8123
8152
  try {
8124
8153
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8125
8154
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
8126
8155
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8127
8156
  const response = await this.request(AuthRoutes.signatureMessage, {
8128
8157
  payload: {
8129
- walletId,
8130
8158
  clientAuthPubKey: deviceAuthKeys.publicKey,
8131
8159
  passkeyChallengeType: challengeType,
8132
8160
  },
@@ -8157,10 +8185,7 @@ class AuthService extends Base {
8157
8185
  logger.info('key pair generated', !!deviceKeyPair);
8158
8186
  let authentication;
8159
8187
  try {
8160
- const signatureMessageResponse = await this.getSignature({
8161
- deviceAuthKeys: deviceKeyPair,
8162
- passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
8163
- });
8188
+ const signatureMessageResponse = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
8164
8189
  logger.info('signature has been generated', !!signatureMessageResponse);
8165
8190
  switch (this.deviceAuthType) {
8166
8191
  case exports.AuthType.Passkey:
@@ -8193,10 +8218,7 @@ class AuthService extends Base {
8193
8218
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8194
8219
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8195
8220
  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
- });
8221
+ const newChallenge = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
8200
8222
  authentication = await this.passkeyService.authenticate({
8201
8223
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8202
8224
  challengeResponse: newChallenge,
@@ -8233,7 +8255,10 @@ class AuthService extends Base {
8233
8255
  errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
8234
8256
  });
8235
8257
  }
8236
- await this.localStorageService.save(exports.LocalStorageItems.AccessToken, authentication.accessToken);
8258
+ await this.localStorageService.saveInBulk([
8259
+ { key: exports.LocalStorageItems.AccessToken, value: authentication.accessToken },
8260
+ { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8261
+ ]);
8237
8262
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8238
8263
  }
8239
8264
  catch (error) {
@@ -8309,9 +8334,7 @@ class AuthService extends Base {
8309
8334
  },
8310
8335
  credentialsKeyPair,
8311
8336
  });
8312
- const signatureMessage = await this.getSignature({
8313
- deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8314
- });
8337
+ const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8315
8338
  const authentication = await this.request(AuthRoutes.signIn, {
8316
8339
  payload: {
8317
8340
  externalUserId: this.userId,
@@ -8435,6 +8458,10 @@ class AuthService extends Base {
8435
8458
  key: exports.LocalStorageItems.AccessToken,
8436
8459
  value: authResponse.accessToken,
8437
8460
  },
8461
+ {
8462
+ key: exports.LocalStorageItems.WallabyAuthPubKey,
8463
+ value: authResponse.user.wallabyAuthPubKey,
8464
+ },
8438
8465
  ]);
8439
8466
  return authResponse;
8440
8467
  });
@@ -8519,16 +8546,12 @@ class WalletHandlersService extends Base {
8519
8546
  this.userId = config.userId;
8520
8547
  }
8521
8548
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8522
- var _a, _b, _c, _d, _e;
8549
+ var _a, _b, _c, _d;
8523
8550
  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
- });
8551
+ const { signature, message } = await this.authService.getSignature({
8552
+ publicKey: deviceAuthKeys.publicKey,
8553
+ privateKey: deviceAuthKeys.privateKey,
8554
+ }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
8532
8555
  if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8533
8556
  importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8534
8557
  !importWalletInput.keyShareOptions) {
@@ -8538,7 +8561,7 @@ class WalletHandlersService extends Base {
8538
8561
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
8539
8562
  });
8540
8563
  }
8541
- const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8564
+ const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8542
8565
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8543
8566
  throw new WallabyError({
8544
8567
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8548,10 +8571,10 @@ class WalletHandlersService extends Base {
8548
8571
  }
8549
8572
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8550
8573
  data: importWalletInput.seedPhrase,
8551
- encryptionKey: wallabyAuthPubKey,
8574
+ encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8552
8575
  });
8553
8576
  const importWalletPayload = {
8554
- reference: importWalletInput.reference,
8577
+ reference: uuid.v4(),
8555
8578
  walletId: importWalletInput.walletId,
8556
8579
  message,
8557
8580
  signature,
@@ -8561,7 +8584,7 @@ class WalletHandlersService extends Base {
8561
8584
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8562
8585
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8563
8586
  walletOwnershipType: exports.WalletOwnershipType.SingleOwner,
8564
- wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8587
+ wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8565
8588
  };
8566
8589
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8567
8590
  payload: importWalletPayload,
@@ -8599,7 +8622,7 @@ class WalletHandlersService extends Base {
8599
8622
  }
8600
8623
  catch (error) {
8601
8624
  throw new WallabyError({
8602
- message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8625
+ message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8603
8626
  statusCode: error.statusCode,
8604
8627
  errorCode: error.errorCode,
8605
8628
  data: error.data,
@@ -8621,9 +8644,9 @@ class WalletHandlersService extends Base {
8621
8644
  var _a, _b, _c, _d, _e, _f;
8622
8645
  try {
8623
8646
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8624
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8625
- passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
8626
- });
8647
+ publicKey: deviceAuthKeys.publicKey,
8648
+ privateKey: deviceAuthKeys.privateKey,
8649
+ }, exports.PasskeyChallengeType.AUTHENTICATION);
8627
8650
  if ((walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
8628
8651
  walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8629
8652
  !walletCreationInput.keyShareOptions) {
@@ -8800,6 +8823,36 @@ class WalletHandlersService extends Base {
8800
8823
  });
8801
8824
  }
8802
8825
  }
8826
+ /**
8827
+ *
8828
+ * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8829
+ * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8830
+ * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8831
+ * @description This function constructs the seed phrase from encrypted key shares.
8832
+ * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8833
+ * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8834
+ * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8835
+ */
8836
+ async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8837
+ try {
8838
+ const { signature, message } = await this.authService.getSignature(deviceAuthKeys, exports.PasskeyChallengeType.AUTHENTICATION);
8839
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8840
+ payload: {
8841
+ walletId: walletId,
8842
+ signature,
8843
+ message,
8844
+ clientAuthPubKey: deviceAuthKeys.publicKey,
8845
+ recoveryPubKey: deviceAuthKeys.publicKey,
8846
+ encryptedShares: encryptedKeyShares,
8847
+ },
8848
+ });
8849
+ return retrieveSeedPhraseResponse.encryptedSeed;
8850
+ }
8851
+ catch (error) {
8852
+ logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8853
+ return Promise.reject(error);
8854
+ }
8855
+ }
8803
8856
  }
8804
8857
 
8805
8858
  class WalletService extends Base {
@@ -8909,6 +8962,7 @@ class WalletService extends Base {
8909
8962
  */
8910
8963
  async export({ walletId, authenticationOptions, exportOptions }) {
8911
8964
  try {
8965
+ const { user: { wallabyAuthPubKey }, } = authenticationOptions;
8912
8966
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
8913
8967
  throw new WallabyError({
8914
8968
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9018,20 +9072,10 @@ class WalletService extends Base {
9018
9072
  });
9019
9073
  }
9020
9074
  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
9075
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9032
9076
  storedEncryptedData: parsedPrimaryShare,
9033
9077
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9034
- wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9078
+ wallabyPublicKey: wallabyAuthPubKey,
9035
9079
  options: {
9036
9080
  authType: this.deviceAuthType,
9037
9081
  password: authenticationOptions.password,
@@ -9039,18 +9083,17 @@ class WalletService extends Base {
9039
9083
  prfValue: authenticationOptions.prfValue,
9040
9084
  },
9041
9085
  });
9042
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9043
- payload: {
9044
- walletId: walletId,
9045
- signature,
9046
- message,
9047
- clientAuthPubKey: deviceAuthKeys.publicKey,
9048
- recoveryPubKey: deviceAuthKeys.publicKey,
9049
- encryptedShares: [wallabyBoundPrimaryShare],
9086
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9087
+ const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9088
+ encryptedKeyShares: [wallabyBoundPrimaryShare],
9089
+ walletId,
9090
+ deviceAuthKeys: {
9091
+ publicKey: deviceAuthPublicKey,
9092
+ privateKey: decryptedDevicePrivateKey,
9050
9093
  },
9051
9094
  });
9052
9095
  decryptedSeedPhrase = await this.cipher.decrypt({
9053
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9096
+ cipherText: encryptedReconstructedSeedPhrase,
9054
9097
  decryptionKey: decryptedDevicePrivateKey,
9055
9098
  });
9056
9099
  if (exportOptions.algorandSeedPhrase) {
@@ -9088,9 +9131,7 @@ class WalletService extends Base {
9088
9131
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9089
9132
  */
9090
9133
  async import(input) {
9091
- var _a;
9092
9134
  try {
9093
- const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : uuid.v4();
9094
9135
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9095
9136
  if (!encryptedDevicePrivateKey) {
9096
9137
  throw new WallabyError({
@@ -9121,7 +9162,7 @@ class WalletService extends Base {
9121
9162
  const importRequest = await this.handlers.handleImportWallet({
9122
9163
  publicKey: clientAuthPubKey,
9123
9164
  privateKey: decryptedDevicePrivateKey,
9124
- }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9165
+ }, input);
9125
9166
  return importRequest;
9126
9167
  }
9127
9168
  catch (error) {
@@ -9135,15 +9176,11 @@ class WalletService extends Base {
9135
9176
  *
9136
9177
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9137
9178
  * @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
9179
  */
9142
9180
  async recover(input) {
9143
9181
  var _a, _b;
9144
9182
  try {
9145
- const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9146
- input.authenticationOptions.user.wallabyAuthPubKey;
9183
+ const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9147
9184
  const deviceAuthKeyPair = createIdentity();
9148
9185
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9149
9186
  authType: this.deviceAuthType,
@@ -9183,37 +9220,27 @@ class WalletService extends Base {
9183
9220
  return recoverWithSeedPhraseResponse;
9184
9221
  }
9185
9222
  else if (input.decryptedShares) {
9186
- if (!input.decryptedShares.length) {
9223
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9224
+ const encrypted = await this.cipher.encrypt({
9225
+ data: decryptedShare,
9226
+ encryptionKey: wallabyPublicKey,
9227
+ });
9228
+ return encrypted;
9229
+ }));
9230
+ if (!encryptedShares.length) {
9187
9231
  throw new WallabyError({
9188
9232
  message: 'Decrypted shares are required',
9189
9233
  statusCode: 400,
9190
9234
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
9191
9235
  });
9192
9236
  }
9193
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9237
+ const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9238
+ encryptedKeyShares: encryptedShares,
9194
9239
  deviceAuthKeys: deviceAuthKeyPair,
9195
9240
  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
9241
  });
9215
9242
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9216
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9243
+ cipherText: encryptedSeed,
9217
9244
  decryptionKey: deviceAuthKeyPair.privateKey,
9218
9245
  encryptionKey: wallabyPublicKey,
9219
9246
  });
@@ -9271,9 +9298,17 @@ class WalletService extends Base {
9271
9298
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9272
9299
  try {
9273
9300
  const signatureMessage = await this.authService.getSignature({
9274
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9275
- walletId,
9276
- });
9301
+ publicKey: deviceAuthKeys.publicKey,
9302
+ privateKey: deviceAuthKeys.privateKey,
9303
+ });
9304
+ // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9305
+ // payload: {
9306
+ // walletId,
9307
+ // signature: signatureMessage.signature,
9308
+ // message: signatureMessage.message,
9309
+ // clientAuthPubKey: deviceAuthKeys.publicKey,
9310
+ // },
9311
+ // });
9277
9312
  const response = await this.api.wallets.retrieveShares({
9278
9313
  walletId: walletId,
9279
9314
  signature: signatureMessage.signature,
@@ -9454,7 +9489,6 @@ class WalletService extends Base {
9454
9489
  */
9455
9490
  async initAddNewDevice(input) {
9456
9491
  const { walletId, backupUrl, authenticationOptions } = input;
9457
- const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9458
9492
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9459
9493
  if (!encryptedDevicePrivateKey) {
9460
9494
  throw new WallabyError({
@@ -9515,7 +9549,7 @@ class WalletService extends Base {
9515
9549
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9516
9550
  storedEncryptedData: parsedPrimaryShare,
9517
9551
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9518
- wallabyPublicKey,
9552
+ wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9519
9553
  options: {
9520
9554
  authType: this.deviceAuthType,
9521
9555
  password: authenticationOptions.password,
@@ -9574,11 +9608,22 @@ class WalletService extends Base {
9574
9608
  }
9575
9609
  const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9576
9610
  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;
9611
+ publicKey: devicePublicKey,
9612
+ privateKey: decryptedDevicePrivateKey,
9613
+ }, exports.PasskeyChallengeType.REGISTRATION);
9614
+ // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9615
+ // payload: {
9616
+ // walletId: input.walletId,
9617
+ // message: signatureMessage.message,
9618
+ // signature: signatureMessage.signature,
9619
+ // clientAuthPubKey: devicePublicKey,
9620
+ // share: {
9621
+ // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9622
+ // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9623
+ // type: KeyTypeName.OwnerBackupDeviceShare,
9624
+ // },
9625
+ // },
9626
+ // });
9582
9627
  const backUpResponse = await this.api.wallets.addNewDevice({
9583
9628
  walletId: input.walletId,
9584
9629
  message: signatureMessage.message,
@@ -9586,7 +9631,7 @@ class WalletService extends Base {
9586
9631
  clientAuthPubKey: devicePublicKey,
9587
9632
  share: {
9588
9633
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9589
- wrappingPublicKey: wallabyPublicKey,
9634
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9590
9635
  type: exports.KeyTypeName.OwnerBackupDeviceShare,
9591
9636
  },
9592
9637
  });
@@ -9594,8 +9639,7 @@ class WalletService extends Base {
9594
9639
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9595
9640
  {
9596
9641
  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.
9642
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9599
9643
  type: exports.KeyTypeName.OwnerMainDeviceShare,
9600
9644
  },
9601
9645
  ];
@@ -9652,28 +9696,12 @@ class WalletService extends Base {
9652
9696
  });
9653
9697
  }
9654
9698
  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
9699
  if (storedSeedPhrase) {
9672
9700
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9673
9701
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9674
9702
  storedEncryptedData: parsedStoredSeedPhrase,
9675
9703
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9676
- wallabyPublicKey,
9704
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9677
9705
  options: {
9678
9706
  authType: this.deviceAuthType,
9679
9707
  password: input.authenticationOptions.password,
@@ -9687,7 +9715,7 @@ class WalletService extends Base {
9687
9715
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9688
9716
  storedEncryptedData: parsedPrimaryKeyShare,
9689
9717
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9690
- wallabyPublicKey,
9718
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9691
9719
  options: {
9692
9720
  authType: this.deviceAuthType,
9693
9721
  password: input.authenticationOptions.password,
@@ -9703,6 +9731,21 @@ class WalletService extends Base {
9703
9731
  errorCode: 'sdk_private_key_not_found',
9704
9732
  });
9705
9733
  }
9734
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9735
+ authType: this.deviceAuthType,
9736
+ password: input.authenticationOptions.password,
9737
+ salt: input.authenticationOptions.clientSalt,
9738
+ prfValue: input.authenticationOptions.prfValue,
9739
+ });
9740
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9741
+ cipherText: parsedDevicePrivateKey,
9742
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9743
+ });
9744
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9745
+ const { signature, message } = await this.authService.getSignature({
9746
+ privateKey: decryptedDevicePrivateKey,
9747
+ publicKey: devicePublicKey,
9748
+ });
9706
9749
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9707
9750
  payload: {
9708
9751
  walletId,
@@ -9894,8 +9937,8 @@ class WalletService extends Base {
9894
9937
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9895
9938
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9896
9939
  const signInSignatureMessage = await this.authService.getSignature({
9897
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9898
- walletId,
9940
+ publicKey: devicePublicKey,
9941
+ privateKey: decryptedPrivateKey,
9899
9942
  });
9900
9943
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9901
9944
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -9921,6 +9964,7 @@ class WalletService extends Base {
9921
9964
  // Store authentication tokens
9922
9965
  await this.localStorageService.saveInBulk([
9923
9966
  { key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
9967
+ { key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
9924
9968
  { key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
9925
9969
  { key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9926
9970
  ]);
@@ -9983,8 +10027,8 @@ class WalletService extends Base {
9983
10027
  throw error;
9984
10028
  }
9985
10029
  }
9986
- async clearDevice({ walletId }) {
9987
- await this.localStorageService.clearLocalStorage(walletId);
10030
+ async clearDevice() {
10031
+ await this.localStorageService.clearLocalStorage();
9988
10032
  }
9989
10033
  /**
9990
10034
  * Prepares authentication data and encrypted payload for any request.
@@ -10021,11 +10065,9 @@ class WalletService extends Base {
10021
10065
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10022
10066
  // Get signature message
10023
10067
  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;
10068
+ publicKey: deviceAuthPublicKey,
10069
+ privateKey: decryptedDevicePrivateKey,
10070
+ }, exports.PasskeyChallengeType.AUTHENTICATION);
10029
10071
  // Prepare encrypted data (seed phrase or key shares)
10030
10072
  const sharesEncryptedWithWallabyPubKey = [];
10031
10073
  let readyForTransportSeedPhrase = undefined;
@@ -10045,7 +10087,7 @@ class WalletService extends Base {
10045
10087
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10046
10088
  storedEncryptedData: parsedSeedPhrase,
10047
10089
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10048
- wallabyPublicKey,
10090
+ wallabyPublicKey: user.wallabyAuthPubKey,
10049
10091
  options: {
10050
10092
  authType: this.deviceAuthType,
10051
10093
  password,
@@ -10060,7 +10102,7 @@ class WalletService extends Base {
10060
10102
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10061
10103
  storedEncryptedData: parsedPrimaryShare,
10062
10104
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10063
- wallabyPublicKey,
10105
+ wallabyPublicKey: user.wallabyAuthPubKey,
10064
10106
  options: {
10065
10107
  authType: this.deviceAuthType,
10066
10108
  password,
@@ -10225,11 +10267,11 @@ class WalletService extends Base {
10225
10267
  publicKey: clientPublicKey,
10226
10268
  privateKey: decryptedClientAuthPrivKey,
10227
10269
  }, {
10270
+ walletId: input.walletId,
10228
10271
  authenticationOptions: authentication,
10229
10272
  seedPhrase: decryptedSeedPhrase,
10230
10273
  storeSeedPhrase: false,
10231
10274
  returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10232
- walletId: input.walletId,
10233
10275
  keyShareOptions: {
10234
10276
  threshold: 2,
10235
10277
  numberOfKeyShares: 3,
@@ -10280,31 +10322,20 @@ class WalletService extends Base {
10280
10322
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10281
10323
  }
10282
10324
  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
10325
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10293
10326
  data: decryptedPrimaryShare,
10294
- encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10327
+ encryptionKey: authentication.user.wallabyAuthPubKey,
10295
10328
  });
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],
10329
+ const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10330
+ walletId: input.walletId,
10331
+ encryptedKeyShares: [flippedEncryptedPrimaryShare],
10332
+ deviceAuthKeys: {
10333
+ publicKey: clientPublicKey,
10334
+ privateKey: decryptedClientAuthPrivKey,
10304
10335
  },
10305
10336
  });
10306
10337
  decryptedSeedPhrase = await this.cipher.decrypt({
10307
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10338
+ cipherText: reconstructedSeedPhrase,
10308
10339
  decryptionKey: decryptedClientAuthPrivKey,
10309
10340
  });
10310
10341
  }
@@ -10411,7 +10442,7 @@ class WalletDataService extends Base {
10411
10442
  * Note: Either chainName or tokenStandard must be provided.
10412
10443
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10413
10444
  */
10414
- async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10445
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10415
10446
  try {
10416
10447
  if (!tokensAndAddressesList.length) {
10417
10448
  throw new WallabyError({
@@ -10999,17 +11030,18 @@ class Swap extends Base {
10999
11030
  this.walletService = new WalletService(config);
11000
11031
  }
11001
11032
  /**
11002
- * Gets a swap quote between two assets (from/to), including fees, min output, and slippage limits.
11033
+ * Gets a swap quote between two assets, including fees, min output, and slippage limits.
11003
11034
  *
11004
11035
  * @public
11005
11036
  * @param {SwapQuoteRequest} request - The swap quote request parameters
11006
11037
  * @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
11007
11038
  */
11008
- async getQuote({ walletId, fromAsset, toAsset, fromAmount, toAmount }) {
11039
+ async getQuote(request) {
11009
11040
  try {
11010
- if (!walletId || !fromAsset || !toAsset) {
11041
+ const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
11042
+ if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
11011
11043
  throw new WallabyError({
11012
- message: 'Missing required parameters: walletId, fromAsset, and toAsset are required',
11044
+ message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
11013
11045
  statusCode: 400,
11014
11046
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
11015
11047
  });
@@ -11021,10 +11053,16 @@ class Swap extends Base {
11021
11053
  errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
11022
11054
  });
11023
11055
  }
11024
- // Build path with walletId, but exclude it from request body
11056
+ if (fromAmount && toAmount) {
11057
+ throw new WallabyError({
11058
+ message: 'Only one of fromAmount or toAmount may be provided, not both',
11059
+ statusCode: 400,
11060
+ errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
11061
+ });
11062
+ }
11025
11063
  const routePayload = { walletId };
11026
- const requestBody = Object.assign(Object.assign({ fromAsset,
11027
- toAsset }, (fromAmount && { fromAmount })), (toAmount && { toAmount }));
11064
+ const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
11065
+ toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
11028
11066
  const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
11029
11067
  payload: requestBody,
11030
11068
  });
@@ -11168,11 +11206,9 @@ class Swap extends Base {
11168
11206
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11169
11207
  // Get signature message
11170
11208
  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;
11209
+ publicKey: deviceAuthPublicKey,
11210
+ privateKey: decryptedDevicePrivateKey,
11211
+ }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11176
11212
  // Prepare encrypted data (seed phrase or key shares)
11177
11213
  const sharesEncryptedWithWallabyPubKey = [];
11178
11214
  let readyForTransportSeedPhrase = undefined;
@@ -11193,7 +11229,7 @@ class Swap extends Base {
11193
11229
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11194
11230
  storedEncryptedData: parsedSeedPhrase,
11195
11231
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11196
- wallabyPublicKey,
11232
+ wallabyPublicKey: user.wallabyAuthPubKey,
11197
11233
  options: {
11198
11234
  authType: this.deviceAuthType,
11199
11235
  password,
@@ -11208,7 +11244,7 @@ class Swap extends Base {
11208
11244
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11209
11245
  storedEncryptedData: parsedPrimaryShare,
11210
11246
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11211
- wallabyPublicKey,
11247
+ wallabyPublicKey: user.wallabyAuthPubKey,
11212
11248
  options: {
11213
11249
  authType: this.deviceAuthType,
11214
11250
  password,
@@ -11463,7 +11499,7 @@ class Transactions extends Base {
11463
11499
  * @param {BlockchainName} blockchain
11464
11500
  * @returns {FeeEstimateRequest}
11465
11501
  */
11466
- async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11502
+ async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11467
11503
  try {
11468
11504
  const response = await this.request(TransactionsRoutes.estimateFee, {
11469
11505
  queryParams: {
@@ -11806,11 +11842,9 @@ class Transactions extends Base {
11806
11842
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11807
11843
  // Get signature message
11808
11844
  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;
11845
+ publicKey: deviceAuthPublicKey,
11846
+ privateKey: decryptedDevicePrivateKey,
11847
+ }, this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined);
11814
11848
  // Prepare encrypted data (seed phrase or key shares)
11815
11849
  const sharesEncryptedWithWallabyPubKey = [];
11816
11850
  let readyForTransportSeedPhrase = undefined;
@@ -11831,7 +11865,7 @@ class Transactions extends Base {
11831
11865
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11832
11866
  storedEncryptedData: parsedSeedPhrase,
11833
11867
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11834
- wallabyPublicKey,
11868
+ wallabyPublicKey: user.wallabyAuthPubKey,
11835
11869
  options: {
11836
11870
  authType: this.deviceAuthType,
11837
11871
  password,
@@ -11846,7 +11880,7 @@ class Transactions extends Base {
11846
11880
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11847
11881
  storedEncryptedData: parsedPrimaryShare,
11848
11882
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11849
- wallabyPublicKey,
11883
+ wallabyPublicKey: user.wallabyAuthPubKey,
11850
11884
  options: {
11851
11885
  authType: this.deviceAuthType,
11852
11886
  password,