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.js CHANGED
@@ -1,11 +1,11 @@
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';
7
6
  import * as NativeWebAuthn from 'react-native-passkey';
8
7
  import { atob, toUint8Array } from 'js-base64';
8
+ import { v4 } from 'uuid';
9
9
 
10
10
  /******************************************************************************
11
11
  Copyright (c) Microsoft Corporation.
@@ -265,6 +265,7 @@ var LocalStorageItems;
265
265
  LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
266
266
  LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
267
267
  LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
268
+ LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
268
269
  LocalStorageItems["ClientAuthToken"] = "republic-jwt";
269
270
  LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
270
271
  LocalStorageItems["Blob"] = "blob";
@@ -575,7 +576,7 @@ const env = {
575
576
  isNative: false,
576
577
  isWeb,
577
578
  };
578
- const currentPackageVersion = "2.3.7" ;
579
+ const currentPackageVersion = "2.3.9" ;
579
580
 
580
581
  /**
581
582
  * Storage keys adapter for Storage interface across different platforms.
@@ -4907,6 +4908,43 @@ class StorageService {
4907
4908
  }
4908
4909
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4909
4910
  }
4911
+ /**
4912
+ *
4913
+ * Stores Wallaby auth public key to local storage
4914
+ * @param wallabyAuthPubKey
4915
+ */
4916
+ async setWallabyAuthPubKey(wallabyAuthPubKey) {
4917
+ await this.save(V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4918
+ }
4919
+ /**
4920
+ *
4921
+ * Fetches Wallaby auth public key from local storage
4922
+ * @returns { string | undefined } Wallaby Auth Public key or undefined.
4923
+ */
4924
+ async getWallabyAuthPubKey() {
4925
+ let wallabyAuthPubKey = await this.fetch(V2KeyNames.WallabyAuthPubKey);
4926
+ if (wallabyAuthPubKey) {
4927
+ return wallabyAuthPubKey;
4928
+ }
4929
+ // Legacy key migration
4930
+ const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4931
+ const legacyPubKey = await this.getItem(legacyKey);
4932
+ if (legacyPubKey) {
4933
+ wallabyAuthPubKey = legacyPubKey;
4934
+ }
4935
+ else {
4936
+ const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4937
+ const v1PubKey = await this.getItem(v1Key);
4938
+ if (v1PubKey) {
4939
+ wallabyAuthPubKey = v1PubKey;
4940
+ }
4941
+ }
4942
+ if (wallabyAuthPubKey) {
4943
+ await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4944
+ return wallabyAuthPubKey;
4945
+ }
4946
+ return undefined;
4947
+ }
4910
4948
  /**
4911
4949
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4912
4950
  * Encrypts and stores device auth private key
@@ -5115,15 +5153,7 @@ class StorageService {
5115
5153
  return undefined;
5116
5154
  }
5117
5155
  async clearLocalStorage(walletId) {
5118
- const userKeysToRemove = [
5119
- LocalStorageItems.AccessToken,
5120
- V2KeyNames.EncryptedDevicePrivateKey,
5121
- V2KeyNames.WallabyAuthPubKey,
5122
- V2KeyNames.PasskeyCredential,
5123
- V2KeyNames.MigrationVersion,
5124
- V2KeyNames.LastMigratedAt,
5125
- V2KeyNames.ClientAuthToken,
5126
- ];
5156
+ const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5127
5157
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5128
5158
  if (walletId) {
5129
5159
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6289,16 +6319,6 @@ class Api {
6289
6319
  * @secure
6290
6320
  */
6291
6321
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6292
- /**
6293
- * @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
6294
- *
6295
- * @tags Transactions, Raw, Transactions
6296
- * @name SignAndBroadcastRawTx
6297
- * @summary Sign and broadcast raw transaction API
6298
- * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6299
- * @secure
6300
- */
6301
- 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)),
6302
6322
  /**
6303
6323
  * No description
6304
6324
  *
@@ -6309,6 +6329,16 @@ class Api {
6309
6329
  * @secure
6310
6330
  */
6311
6331
  fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6332
+ /**
6333
+ * @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
6334
+ *
6335
+ * @tags Transactions, Raw, Transactions
6336
+ * @name SignAndBroadcastRawTx
6337
+ * @summary Sign and broadcast raw transaction API
6338
+ * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6339
+ * @secure
6340
+ */
6341
+ 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)),
6312
6342
  /**
6313
6343
  * No description
6314
6344
  *
@@ -7596,7 +7626,7 @@ let PasskeyService$1 = class PasskeyService {
7596
7626
  this.authenticator = new Authenticator();
7597
7627
  }
7598
7628
  preparePasskeyRequestOptions(options) {
7599
- var _a, _b, _c, _d, _e, _f, _g, _h;
7629
+ var _a, _b, _c, _d, _e, _f;
7600
7630
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7601
7631
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7602
7632
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7604,13 +7634,11 @@ let PasskeyService$1 = class PasskeyService {
7604
7634
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7605
7635
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7606
7636
  : undefined;
7607
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
7608
- ? {
7609
- eval: {
7610
- first: prfExtensionEvaluation,
7611
- },
7612
- }
7613
- : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7637
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7638
+ eval: {
7639
+ first: prfExtensionEvaluation,
7640
+ },
7641
+ } }) });
7614
7642
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7615
7643
  // While the authenticator still works with the prf and would return the response (if any),
7616
7644
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7618,7 +7646,7 @@ let PasskeyService$1 = class PasskeyService {
7618
7646
  return parsedOptions;
7619
7647
  }
7620
7648
  preparePasskeyCreationOptions(options) {
7621
- var _a, _b, _c, _d, _e, _f, _g, _h;
7649
+ var _a, _b, _c, _d, _e, _f;
7622
7650
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7623
7651
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7624
7652
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7626,8 +7654,12 @@ let PasskeyService$1 = class PasskeyService {
7626
7654
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7627
7655
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7628
7656
  : undefined;
7629
- 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 : {}) }) });
7630
- logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
7657
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7658
+ eval: {
7659
+ first: prfExtensionEvaluation,
7660
+ },
7661
+ } }) });
7662
+ logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7631
7663
  return parsedOptions;
7632
7664
  }
7633
7665
  /**
@@ -7642,10 +7674,7 @@ let PasskeyService$1 = class PasskeyService {
7642
7674
  let passkeyCredential;
7643
7675
  let signInResponse;
7644
7676
  try {
7645
- const registrationChallengeResponse = await getSignature({
7646
- deviceAuthKeys: deviceKeyPair,
7647
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
7648
- });
7677
+ const registrationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
7649
7678
  if (!registrationChallengeResponse.registrationOptions)
7650
7679
  throw new WallabyError({
7651
7680
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7688,10 +7717,7 @@ let PasskeyService$1 = class PasskeyService {
7688
7717
  catch (error) {
7689
7718
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7690
7719
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7691
- const authenticationChallengeResponse = await getSignature({
7692
- deviceAuthKeys: deviceKeyPair,
7693
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
7694
- });
7720
+ const authenticationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
7695
7721
  if (!authenticationChallengeResponse.authenticationOptions)
7696
7722
  throw new WallabyError({
7697
7723
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7762,10 +7788,9 @@ let PasskeyService$1 = class PasskeyService {
7762
7788
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7763
7789
  });
7764
7790
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7765
- const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7766
- const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7791
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
7767
7792
  eval: {
7768
- first: prfFirst,
7793
+ first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7769
7794
  },
7770
7795
  } }) });
7771
7796
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7992,6 +8017,10 @@ let PasskeyService$1 = class PasskeyService {
7992
8017
  key: LocalStorageItems.AccessToken,
7993
8018
  value: authenticationResponse.accessToken,
7994
8019
  },
8020
+ {
8021
+ key: LocalStorageItems.WallabyAuthPubKey,
8022
+ value: authenticationResponse.user.wallabyAuthPubKey,
8023
+ },
7995
8024
  ]);
7996
8025
  }
7997
8026
  /**
@@ -8211,14 +8240,13 @@ class AuthService extends Base {
8211
8240
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8212
8241
  * @returns the messaged, the hash, and the signature using the passed private key.
8213
8242
  */
8214
- async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8243
+ async getSignature(deviceAuthKeys, passkeyChallengeType) {
8215
8244
  try {
8216
8245
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8217
8246
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : PasskeyChallengeType.REGISTRATION;
8218
8247
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8219
8248
  const response = await this.request(AuthRoutes.signatureMessage, {
8220
8249
  payload: {
8221
- walletId,
8222
8250
  clientAuthPubKey: deviceAuthKeys.publicKey,
8223
8251
  passkeyChallengeType: challengeType,
8224
8252
  },
@@ -8249,10 +8277,7 @@ class AuthService extends Base {
8249
8277
  logger.info('key pair generated', !!deviceKeyPair);
8250
8278
  let authentication;
8251
8279
  try {
8252
- const signatureMessageResponse = await this.getSignature({
8253
- deviceAuthKeys: deviceKeyPair,
8254
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
8255
- });
8280
+ const signatureMessageResponse = await this.getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
8256
8281
  logger.info('signature has been generated', !!signatureMessageResponse);
8257
8282
  switch (this.deviceAuthType) {
8258
8283
  case AuthType.Passkey:
@@ -8285,10 +8310,7 @@ class AuthService extends Base {
8285
8310
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8286
8311
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8287
8312
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8288
- const newChallenge = await this.getSignature({
8289
- deviceAuthKeys: deviceKeyPair,
8290
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8291
- });
8313
+ const newChallenge = await this.getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
8292
8314
  authentication = await this.passkeyService.authenticate({
8293
8315
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8294
8316
  challengeResponse: newChallenge,
@@ -8325,7 +8347,10 @@ class AuthService extends Base {
8325
8347
  errorCode: ErrorResponseCodes.sdk_invalid_parameter,
8326
8348
  });
8327
8349
  }
8328
- await this.localStorageService.save(LocalStorageItems.AccessToken, authentication.accessToken);
8350
+ await this.localStorageService.saveInBulk([
8351
+ { key: LocalStorageItems.AccessToken, value: authentication.accessToken },
8352
+ { key: LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8353
+ ]);
8329
8354
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8330
8355
  }
8331
8356
  catch (error) {
@@ -8401,9 +8426,7 @@ class AuthService extends Base {
8401
8426
  },
8402
8427
  credentialsKeyPair,
8403
8428
  });
8404
- const signatureMessage = await this.getSignature({
8405
- deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8406
- });
8429
+ const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8407
8430
  const authentication = await this.request(AuthRoutes.signIn, {
8408
8431
  payload: {
8409
8432
  externalUserId: this.userId,
@@ -8527,6 +8550,10 @@ class AuthService extends Base {
8527
8550
  key: LocalStorageItems.AccessToken,
8528
8551
  value: authResponse.accessToken,
8529
8552
  },
8553
+ {
8554
+ key: LocalStorageItems.WallabyAuthPubKey,
8555
+ value: authResponse.user.wallabyAuthPubKey,
8556
+ },
8530
8557
  ]);
8531
8558
  return authResponse;
8532
8559
  });
@@ -8611,16 +8638,12 @@ class WalletHandlersService extends Base {
8611
8638
  this.userId = config.userId;
8612
8639
  }
8613
8640
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8614
- var _a, _b, _c, _d, _e;
8641
+ var _a, _b, _c, _d;
8615
8642
  try {
8616
- // Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
8617
- // However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
8618
- // Using the reference as the fallback for the walletId in this case.
8619
- const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
8620
- walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
8621
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8622
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
8623
- });
8643
+ const { signature, message } = await this.authService.getSignature({
8644
+ publicKey: deviceAuthKeys.publicKey,
8645
+ privateKey: deviceAuthKeys.privateKey,
8646
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
8624
8647
  if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8625
8648
  importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8626
8649
  !importWalletInput.keyShareOptions) {
@@ -8630,7 +8653,7 @@ class WalletHandlersService extends Base {
8630
8653
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
8631
8654
  });
8632
8655
  }
8633
- const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8656
+ const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8634
8657
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8635
8658
  throw new WallabyError({
8636
8659
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8640,10 +8663,10 @@ class WalletHandlersService extends Base {
8640
8663
  }
8641
8664
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8642
8665
  data: importWalletInput.seedPhrase,
8643
- encryptionKey: wallabyAuthPubKey,
8666
+ encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8644
8667
  });
8645
8668
  const importWalletPayload = {
8646
- reference: importWalletInput.reference,
8669
+ reference: v4(),
8647
8670
  walletId: importWalletInput.walletId,
8648
8671
  message,
8649
8672
  signature,
@@ -8653,7 +8676,7 @@ class WalletHandlersService extends Base {
8653
8676
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8654
8677
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8655
8678
  walletOwnershipType: WalletOwnershipType.SingleOwner,
8656
- wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8679
+ wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8657
8680
  };
8658
8681
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8659
8682
  payload: importWalletPayload,
@@ -8691,7 +8714,7 @@ class WalletHandlersService extends Base {
8691
8714
  }
8692
8715
  catch (error) {
8693
8716
  throw new WallabyError({
8694
- message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8717
+ message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8695
8718
  statusCode: error.statusCode,
8696
8719
  errorCode: error.errorCode,
8697
8720
  data: error.data,
@@ -8713,9 +8736,9 @@ class WalletHandlersService extends Base {
8713
8736
  var _a, _b, _c, _d, _e, _f;
8714
8737
  try {
8715
8738
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8716
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8717
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8718
- });
8739
+ publicKey: deviceAuthKeys.publicKey,
8740
+ privateKey: deviceAuthKeys.privateKey,
8741
+ }, PasskeyChallengeType.AUTHENTICATION);
8719
8742
  if ((walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8720
8743
  walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8721
8744
  !walletCreationInput.keyShareOptions) {
@@ -8892,6 +8915,36 @@ class WalletHandlersService extends Base {
8892
8915
  });
8893
8916
  }
8894
8917
  }
8918
+ /**
8919
+ *
8920
+ * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8921
+ * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8922
+ * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8923
+ * @description This function constructs the seed phrase from encrypted key shares.
8924
+ * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8925
+ * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8926
+ * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8927
+ */
8928
+ async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8929
+ try {
8930
+ const { signature, message } = await this.authService.getSignature(deviceAuthKeys, PasskeyChallengeType.AUTHENTICATION);
8931
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8932
+ payload: {
8933
+ walletId: walletId,
8934
+ signature,
8935
+ message,
8936
+ clientAuthPubKey: deviceAuthKeys.publicKey,
8937
+ recoveryPubKey: deviceAuthKeys.publicKey,
8938
+ encryptedShares: encryptedKeyShares,
8939
+ },
8940
+ });
8941
+ return retrieveSeedPhraseResponse.encryptedSeed;
8942
+ }
8943
+ catch (error) {
8944
+ logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8945
+ return Promise.reject(error);
8946
+ }
8947
+ }
8895
8948
  }
8896
8949
 
8897
8950
  class WalletService extends Base {
@@ -9001,6 +9054,7 @@ class WalletService extends Base {
9001
9054
  */
9002
9055
  async export({ walletId, authenticationOptions, exportOptions }) {
9003
9056
  try {
9057
+ const { user: { wallabyAuthPubKey }, } = authenticationOptions;
9004
9058
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
9005
9059
  throw new WallabyError({
9006
9060
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -9110,20 +9164,10 @@ class WalletService extends Base {
9110
9164
  });
9111
9165
  }
9112
9166
  const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
9113
- const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9114
- const deviceAuthKeys = {
9115
- publicKey: deviceAuthPublicKey,
9116
- privateKey: decryptedDevicePrivateKey,
9117
- };
9118
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9119
- deviceAuthKeys,
9120
- walletId,
9121
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9122
- });
9123
9167
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9124
9168
  storedEncryptedData: parsedPrimaryShare,
9125
9169
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9126
- wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9170
+ wallabyPublicKey: wallabyAuthPubKey,
9127
9171
  options: {
9128
9172
  authType: this.deviceAuthType,
9129
9173
  password: authenticationOptions.password,
@@ -9131,18 +9175,17 @@ class WalletService extends Base {
9131
9175
  prfValue: authenticationOptions.prfValue,
9132
9176
  },
9133
9177
  });
9134
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9135
- payload: {
9136
- walletId: walletId,
9137
- signature,
9138
- message,
9139
- clientAuthPubKey: deviceAuthKeys.publicKey,
9140
- recoveryPubKey: deviceAuthKeys.publicKey,
9141
- encryptedShares: [wallabyBoundPrimaryShare],
9178
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9179
+ const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9180
+ encryptedKeyShares: [wallabyBoundPrimaryShare],
9181
+ walletId,
9182
+ deviceAuthKeys: {
9183
+ publicKey: deviceAuthPublicKey,
9184
+ privateKey: decryptedDevicePrivateKey,
9142
9185
  },
9143
9186
  });
9144
9187
  decryptedSeedPhrase = await this.cipher.decrypt({
9145
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9188
+ cipherText: encryptedReconstructedSeedPhrase,
9146
9189
  decryptionKey: decryptedDevicePrivateKey,
9147
9190
  });
9148
9191
  if (exportOptions.algorandSeedPhrase) {
@@ -9180,9 +9223,7 @@ class WalletService extends Base {
9180
9223
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9181
9224
  */
9182
9225
  async import(input) {
9183
- var _a;
9184
9226
  try {
9185
- const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : v4();
9186
9227
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9187
9228
  if (!encryptedDevicePrivateKey) {
9188
9229
  throw new WallabyError({
@@ -9213,7 +9254,7 @@ class WalletService extends Base {
9213
9254
  const importRequest = await this.handlers.handleImportWallet({
9214
9255
  publicKey: clientAuthPubKey,
9215
9256
  privateKey: decryptedDevicePrivateKey,
9216
- }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9257
+ }, input);
9217
9258
  return importRequest;
9218
9259
  }
9219
9260
  catch (error) {
@@ -9227,15 +9268,11 @@ class WalletService extends Base {
9227
9268
  *
9228
9269
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9229
9270
  * @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
9230
- *
9231
- * @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
9232
- * Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
9233
9271
  */
9234
9272
  async recover(input) {
9235
9273
  var _a, _b;
9236
9274
  try {
9237
- const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9238
- input.authenticationOptions.user.wallabyAuthPubKey;
9275
+ const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9239
9276
  const deviceAuthKeyPair = createIdentity();
9240
9277
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9241
9278
  authType: this.deviceAuthType,
@@ -9275,37 +9312,27 @@ class WalletService extends Base {
9275
9312
  return recoverWithSeedPhraseResponse;
9276
9313
  }
9277
9314
  else if (input.decryptedShares) {
9278
- if (!input.decryptedShares.length) {
9315
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9316
+ const encrypted = await this.cipher.encrypt({
9317
+ data: decryptedShare,
9318
+ encryptionKey: wallabyPublicKey,
9319
+ });
9320
+ return encrypted;
9321
+ }));
9322
+ if (!encryptedShares.length) {
9279
9323
  throw new WallabyError({
9280
9324
  message: 'Decrypted shares are required',
9281
9325
  statusCode: 400,
9282
9326
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
9283
9327
  });
9284
9328
  }
9285
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9329
+ const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9330
+ encryptedKeyShares: encryptedShares,
9286
9331
  deviceAuthKeys: deviceAuthKeyPair,
9287
9332
  walletId: input.walletId,
9288
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9289
- });
9290
- const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9291
- const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9292
- return await this.cipher.encrypt({
9293
- data: decryptedShare,
9294
- encryptionKey: transportEncryptionKey,
9295
- });
9296
- }));
9297
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9298
- payload: {
9299
- walletId: input.walletId,
9300
- signature,
9301
- message,
9302
- clientAuthPubKey: deviceAuthKeyPair.publicKey,
9303
- recoveryPubKey: deviceAuthKeyPair.publicKey,
9304
- encryptedShares,
9305
- },
9306
9333
  });
9307
9334
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9308
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9335
+ cipherText: encryptedSeed,
9309
9336
  decryptionKey: deviceAuthKeyPair.privateKey,
9310
9337
  encryptionKey: wallabyPublicKey,
9311
9338
  });
@@ -9363,9 +9390,17 @@ class WalletService extends Base {
9363
9390
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9364
9391
  try {
9365
9392
  const signatureMessage = await this.authService.getSignature({
9366
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9367
- walletId,
9368
- });
9393
+ publicKey: deviceAuthKeys.publicKey,
9394
+ privateKey: deviceAuthKeys.privateKey,
9395
+ });
9396
+ // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9397
+ // payload: {
9398
+ // walletId,
9399
+ // signature: signatureMessage.signature,
9400
+ // message: signatureMessage.message,
9401
+ // clientAuthPubKey: deviceAuthKeys.publicKey,
9402
+ // },
9403
+ // });
9369
9404
  const response = await this.api.wallets.retrieveShares({
9370
9405
  walletId: walletId,
9371
9406
  signature: signatureMessage.signature,
@@ -9546,7 +9581,6 @@ class WalletService extends Base {
9546
9581
  */
9547
9582
  async initAddNewDevice(input) {
9548
9583
  const { walletId, backupUrl, authenticationOptions } = input;
9549
- const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9550
9584
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9551
9585
  if (!encryptedDevicePrivateKey) {
9552
9586
  throw new WallabyError({
@@ -9607,7 +9641,7 @@ class WalletService extends Base {
9607
9641
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9608
9642
  storedEncryptedData: parsedPrimaryShare,
9609
9643
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9610
- wallabyPublicKey,
9644
+ wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9611
9645
  options: {
9612
9646
  authType: this.deviceAuthType,
9613
9647
  password: authenticationOptions.password,
@@ -9666,11 +9700,22 @@ class WalletService extends Base {
9666
9700
  }
9667
9701
  const devicePublicKey = (_a = (await this.localStorageService.fetch(LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9668
9702
  const signatureMessage = await this.authService.getSignature({
9669
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
9670
- walletId: input.walletId,
9671
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
9672
- });
9673
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9703
+ publicKey: devicePublicKey,
9704
+ privateKey: decryptedDevicePrivateKey,
9705
+ }, PasskeyChallengeType.REGISTRATION);
9706
+ // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9707
+ // payload: {
9708
+ // walletId: input.walletId,
9709
+ // message: signatureMessage.message,
9710
+ // signature: signatureMessage.signature,
9711
+ // clientAuthPubKey: devicePublicKey,
9712
+ // share: {
9713
+ // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9714
+ // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9715
+ // type: KeyTypeName.OwnerBackupDeviceShare,
9716
+ // },
9717
+ // },
9718
+ // });
9674
9719
  const backUpResponse = await this.api.wallets.addNewDevice({
9675
9720
  walletId: input.walletId,
9676
9721
  message: signatureMessage.message,
@@ -9678,7 +9723,7 @@ class WalletService extends Base {
9678
9723
  clientAuthPubKey: devicePublicKey,
9679
9724
  share: {
9680
9725
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9681
- wrappingPublicKey: wallabyPublicKey,
9726
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9682
9727
  type: KeyTypeName.OwnerBackupDeviceShare,
9683
9728
  },
9684
9729
  });
@@ -9686,8 +9731,7 @@ class WalletService extends Base {
9686
9731
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9687
9732
  {
9688
9733
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9689
- wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9690
- input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9734
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9691
9735
  type: KeyTypeName.OwnerMainDeviceShare,
9692
9736
  },
9693
9737
  ];
@@ -9744,28 +9788,12 @@ class WalletService extends Base {
9744
9788
  });
9745
9789
  }
9746
9790
  const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
9747
- const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9748
- authType: this.deviceAuthType,
9749
- password: input.authenticationOptions.password,
9750
- salt: input.authenticationOptions.clientSalt,
9751
- prfValue: input.authenticationOptions.prfValue,
9752
- });
9753
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9754
- cipherText: parsedDevicePrivateKey,
9755
- decryptionKey: derivedCredentialsKeyPair.privateKey,
9756
- });
9757
- const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9758
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9759
- deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
9760
- walletId,
9761
- });
9762
- const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9763
9791
  if (storedSeedPhrase) {
9764
9792
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9765
9793
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9766
9794
  storedEncryptedData: parsedStoredSeedPhrase,
9767
9795
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9768
- wallabyPublicKey,
9796
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9769
9797
  options: {
9770
9798
  authType: this.deviceAuthType,
9771
9799
  password: input.authenticationOptions.password,
@@ -9779,7 +9807,7 @@ class WalletService extends Base {
9779
9807
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9780
9808
  storedEncryptedData: parsedPrimaryKeyShare,
9781
9809
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9782
- wallabyPublicKey,
9810
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9783
9811
  options: {
9784
9812
  authType: this.deviceAuthType,
9785
9813
  password: input.authenticationOptions.password,
@@ -9795,6 +9823,21 @@ class WalletService extends Base {
9795
9823
  errorCode: 'sdk_private_key_not_found',
9796
9824
  });
9797
9825
  }
9826
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9827
+ authType: this.deviceAuthType,
9828
+ password: input.authenticationOptions.password,
9829
+ salt: input.authenticationOptions.clientSalt,
9830
+ prfValue: input.authenticationOptions.prfValue,
9831
+ });
9832
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9833
+ cipherText: parsedDevicePrivateKey,
9834
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9835
+ });
9836
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9837
+ const { signature, message } = await this.authService.getSignature({
9838
+ privateKey: decryptedDevicePrivateKey,
9839
+ publicKey: devicePublicKey,
9840
+ });
9798
9841
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9799
9842
  payload: {
9800
9843
  walletId,
@@ -9986,8 +10029,8 @@ class WalletService extends Base {
9986
10029
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9987
10030
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9988
10031
  const signInSignatureMessage = await this.authService.getSignature({
9989
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9990
- walletId,
10032
+ publicKey: devicePublicKey,
10033
+ privateKey: decryptedPrivateKey,
9991
10034
  });
9992
10035
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9993
10036
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -10013,6 +10056,7 @@ class WalletService extends Base {
10013
10056
  // Store authentication tokens
10014
10057
  await this.localStorageService.saveInBulk([
10015
10058
  { key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
10059
+ { key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
10016
10060
  { key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
10017
10061
  { key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
10018
10062
  ]);
@@ -10075,8 +10119,8 @@ class WalletService extends Base {
10075
10119
  throw error;
10076
10120
  }
10077
10121
  }
10078
- async clearDevice({ walletId }) {
10079
- await this.localStorageService.clearLocalStorage(walletId);
10122
+ async clearDevice() {
10123
+ await this.localStorageService.clearLocalStorage();
10080
10124
  }
10081
10125
  /**
10082
10126
  * Prepares authentication data and encrypted payload for any request.
@@ -10113,11 +10157,9 @@ class WalletService extends Base {
10113
10157
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
10114
10158
  // Get signature message
10115
10159
  const signatureMessage = await this.authService.getSignature({
10116
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
10117
- walletId,
10118
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10119
- });
10120
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10160
+ publicKey: deviceAuthPublicKey,
10161
+ privateKey: decryptedDevicePrivateKey,
10162
+ }, PasskeyChallengeType.AUTHENTICATION);
10121
10163
  // Prepare encrypted data (seed phrase or key shares)
10122
10164
  const sharesEncryptedWithWallabyPubKey = [];
10123
10165
  let readyForTransportSeedPhrase = undefined;
@@ -10137,7 +10179,7 @@ class WalletService extends Base {
10137
10179
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10138
10180
  storedEncryptedData: parsedSeedPhrase,
10139
10181
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10140
- wallabyPublicKey,
10182
+ wallabyPublicKey: user.wallabyAuthPubKey,
10141
10183
  options: {
10142
10184
  authType: this.deviceAuthType,
10143
10185
  password,
@@ -10152,7 +10194,7 @@ class WalletService extends Base {
10152
10194
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10153
10195
  storedEncryptedData: parsedPrimaryShare,
10154
10196
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10155
- wallabyPublicKey,
10197
+ wallabyPublicKey: user.wallabyAuthPubKey,
10156
10198
  options: {
10157
10199
  authType: this.deviceAuthType,
10158
10200
  password,
@@ -10317,11 +10359,11 @@ class WalletService extends Base {
10317
10359
  publicKey: clientPublicKey,
10318
10360
  privateKey: decryptedClientAuthPrivKey,
10319
10361
  }, {
10362
+ walletId: input.walletId,
10320
10363
  authenticationOptions: authentication,
10321
10364
  seedPhrase: decryptedSeedPhrase,
10322
10365
  storeSeedPhrase: false,
10323
10366
  returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10324
- walletId: input.walletId,
10325
10367
  keyShareOptions: {
10326
10368
  threshold: 2,
10327
10369
  numberOfKeyShares: 3,
@@ -10372,31 +10414,20 @@ class WalletService extends Base {
10372
10414
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10373
10415
  }
10374
10416
  if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10375
- const deviceAuthKeys = {
10376
- publicKey: clientPublicKey,
10377
- privateKey: decryptedClientAuthPrivKey,
10378
- };
10379
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
10380
- deviceAuthKeys,
10381
- walletId: input.walletId,
10382
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10383
- });
10384
10417
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10385
10418
  data: decryptedPrimaryShare,
10386
- encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10419
+ encryptionKey: authentication.user.wallabyAuthPubKey,
10387
10420
  });
10388
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
10389
- payload: {
10390
- walletId: input.walletId,
10391
- signature,
10392
- message,
10393
- clientAuthPubKey: deviceAuthKeys.publicKey,
10394
- recoveryPubKey: deviceAuthKeys.publicKey,
10395
- encryptedShares: [flippedEncryptedPrimaryShare],
10421
+ const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10422
+ walletId: input.walletId,
10423
+ encryptedKeyShares: [flippedEncryptedPrimaryShare],
10424
+ deviceAuthKeys: {
10425
+ publicKey: clientPublicKey,
10426
+ privateKey: decryptedClientAuthPrivKey,
10396
10427
  },
10397
10428
  });
10398
10429
  decryptedSeedPhrase = await this.cipher.decrypt({
10399
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10430
+ cipherText: reconstructedSeedPhrase,
10400
10431
  decryptionKey: decryptedClientAuthPrivKey,
10401
10432
  });
10402
10433
  }
@@ -10503,7 +10534,7 @@ class WalletDataService extends Base {
10503
10534
  * Note: Either chainName or tokenStandard must be provided.
10504
10535
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10505
10536
  */
10506
- async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10537
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10507
10538
  try {
10508
10539
  if (!tokensAndAddressesList.length) {
10509
10540
  throw new WallabyError({
@@ -11091,17 +11122,18 @@ class Swap extends Base {
11091
11122
  this.walletService = new WalletService(config);
11092
11123
  }
11093
11124
  /**
11094
- * Gets a swap quote between two assets (from/to), including fees, min output, and slippage limits.
11125
+ * Gets a swap quote between two assets, including fees, min output, and slippage limits.
11095
11126
  *
11096
11127
  * @public
11097
11128
  * @param {SwapQuoteRequest} request - The swap quote request parameters
11098
11129
  * @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
11099
11130
  */
11100
- async getQuote({ walletId, fromAsset, toAsset, fromAmount, toAmount }) {
11131
+ async getQuote(request) {
11101
11132
  try {
11102
- if (!walletId || !fromAsset || !toAsset) {
11133
+ const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
11134
+ if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
11103
11135
  throw new WallabyError({
11104
- message: 'Missing required parameters: walletId, fromAsset, and toAsset are required',
11136
+ message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
11105
11137
  statusCode: 400,
11106
11138
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
11107
11139
  });
@@ -11113,10 +11145,16 @@ class Swap extends Base {
11113
11145
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
11114
11146
  });
11115
11147
  }
11116
- // Build path with walletId, but exclude it from request body
11148
+ if (fromAmount && toAmount) {
11149
+ throw new WallabyError({
11150
+ message: 'Only one of fromAmount or toAmount may be provided, not both',
11151
+ statusCode: 400,
11152
+ errorCode: ErrorResponseCodes.sdk_invalid_parameter,
11153
+ });
11154
+ }
11117
11155
  const routePayload = { walletId };
11118
- const requestBody = Object.assign(Object.assign({ fromAsset,
11119
- toAsset }, (fromAmount && { fromAmount })), (toAmount && { toAmount }));
11156
+ const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
11157
+ toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
11120
11158
  const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
11121
11159
  payload: requestBody,
11122
11160
  });
@@ -11260,11 +11298,9 @@ class Swap extends Base {
11260
11298
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11261
11299
  // Get signature message
11262
11300
  const signatureMessage = await this.authService.getSignature({
11263
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11264
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11265
- walletId,
11266
- });
11267
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11301
+ publicKey: deviceAuthPublicKey,
11302
+ privateKey: decryptedDevicePrivateKey,
11303
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11268
11304
  // Prepare encrypted data (seed phrase or key shares)
11269
11305
  const sharesEncryptedWithWallabyPubKey = [];
11270
11306
  let readyForTransportSeedPhrase = undefined;
@@ -11285,7 +11321,7 @@ class Swap extends Base {
11285
11321
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11286
11322
  storedEncryptedData: parsedSeedPhrase,
11287
11323
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11288
- wallabyPublicKey,
11324
+ wallabyPublicKey: user.wallabyAuthPubKey,
11289
11325
  options: {
11290
11326
  authType: this.deviceAuthType,
11291
11327
  password,
@@ -11300,7 +11336,7 @@ class Swap extends Base {
11300
11336
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11301
11337
  storedEncryptedData: parsedPrimaryShare,
11302
11338
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11303
- wallabyPublicKey,
11339
+ wallabyPublicKey: user.wallabyAuthPubKey,
11304
11340
  options: {
11305
11341
  authType: this.deviceAuthType,
11306
11342
  password,
@@ -11555,7 +11591,7 @@ class Transactions extends Base {
11555
11591
  * @param {BlockchainName} blockchain
11556
11592
  * @returns {FeeEstimateRequest}
11557
11593
  */
11558
- async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11594
+ async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11559
11595
  try {
11560
11596
  const response = await this.request(TransactionsRoutes.estimateFee, {
11561
11597
  queryParams: {
@@ -11898,11 +11934,9 @@ class Transactions extends Base {
11898
11934
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11899
11935
  // Get signature message
11900
11936
  const signatureMessage = await this.authService.getSignature({
11901
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11902
- walletId,
11903
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11904
- });
11905
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11937
+ publicKey: deviceAuthPublicKey,
11938
+ privateKey: decryptedDevicePrivateKey,
11939
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11906
11940
  // Prepare encrypted data (seed phrase or key shares)
11907
11941
  const sharesEncryptedWithWallabyPubKey = [];
11908
11942
  let readyForTransportSeedPhrase = undefined;
@@ -11923,7 +11957,7 @@ class Transactions extends Base {
11923
11957
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11924
11958
  storedEncryptedData: parsedSeedPhrase,
11925
11959
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11926
- wallabyPublicKey,
11960
+ wallabyPublicKey: user.wallabyAuthPubKey,
11927
11961
  options: {
11928
11962
  authType: this.deviceAuthType,
11929
11963
  password,
@@ -11938,7 +11972,7 @@ class Transactions extends Base {
11938
11972
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11939
11973
  storedEncryptedData: parsedPrimaryShare,
11940
11974
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11941
- wallabyPublicKey,
11975
+ wallabyPublicKey: user.wallabyAuthPubKey,
11942
11976
  options: {
11943
11977
  authType: this.deviceAuthType,
11944
11978
  password,