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.esm.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 WebAuthn from '@simplewebauthn/browser';
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";
@@ -570,7 +571,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
570
571
  { type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
571
572
  ];
572
573
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
573
- const currentPackageVersion = "2.3.7" ;
574
+ const currentPackageVersion = "2.3.9" ;
574
575
 
575
576
  /**
576
577
  * Storage keys adapter for Storage interface across different platforms.
@@ -4902,6 +4903,43 @@ class StorageService {
4902
4903
  }
4903
4904
  throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
4904
4905
  }
4906
+ /**
4907
+ *
4908
+ * Stores Wallaby auth public key to local storage
4909
+ * @param wallabyAuthPubKey
4910
+ */
4911
+ async setWallabyAuthPubKey(wallabyAuthPubKey) {
4912
+ await this.save(V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
4913
+ }
4914
+ /**
4915
+ *
4916
+ * Fetches Wallaby auth public key from local storage
4917
+ * @returns { string | undefined } Wallaby Auth Public key or undefined.
4918
+ */
4919
+ async getWallabyAuthPubKey() {
4920
+ let wallabyAuthPubKey = await this.fetch(V2KeyNames.WallabyAuthPubKey);
4921
+ if (wallabyAuthPubKey) {
4922
+ return wallabyAuthPubKey;
4923
+ }
4924
+ // Legacy key migration
4925
+ const legacyKey = `wallabyAuthPubKey_${this.userId}`;
4926
+ const legacyPubKey = await this.getItem(legacyKey);
4927
+ if (legacyPubKey) {
4928
+ wallabyAuthPubKey = legacyPubKey;
4929
+ }
4930
+ else {
4931
+ const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
4932
+ const v1PubKey = await this.getItem(v1Key);
4933
+ if (v1PubKey) {
4934
+ wallabyAuthPubKey = v1PubKey;
4935
+ }
4936
+ }
4937
+ if (wallabyAuthPubKey) {
4938
+ await this.setWallabyAuthPubKey(wallabyAuthPubKey);
4939
+ return wallabyAuthPubKey;
4940
+ }
4941
+ return undefined;
4942
+ }
4905
4943
  /**
4906
4944
  * @deprecated This function is only used in tests, and should not be used anywhere else.
4907
4945
  * Encrypts and stores device auth private key
@@ -5110,15 +5148,7 @@ class StorageService {
5110
5148
  return undefined;
5111
5149
  }
5112
5150
  async clearLocalStorage(walletId) {
5113
- const userKeysToRemove = [
5114
- LocalStorageItems.AccessToken,
5115
- V2KeyNames.EncryptedDevicePrivateKey,
5116
- V2KeyNames.WallabyAuthPubKey,
5117
- V2KeyNames.PasskeyCredential,
5118
- V2KeyNames.MigrationVersion,
5119
- V2KeyNames.LastMigratedAt,
5120
- V2KeyNames.ClientAuthToken,
5121
- ];
5151
+ const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5122
5152
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5123
5153
  if (walletId) {
5124
5154
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6284,16 +6314,6 @@ class Api {
6284
6314
  * @secure
6285
6315
  */
6286
6316
  getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
6287
- /**
6288
- * @description The sign and broadcast transaction API was designed and implemented specifically for uses cases where the caller has their own custom raw transaction that is not yet currently supported by Wallaby
6289
- *
6290
- * @tags Transactions, Raw, Transactions
6291
- * @name SignAndBroadcastRawTx
6292
- * @summary Sign and broadcast raw transaction API
6293
- * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6294
- * @secure
6295
- */
6296
- signAndBroadcastRawTx: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/sign-broadcast-rawtx`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
6297
6317
  /**
6298
6318
  * No description
6299
6319
  *
@@ -6304,6 +6324,16 @@ class Api {
6304
6324
  * @secure
6305
6325
  */
6306
6326
  fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
6327
+ /**
6328
+ * @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
6329
+ *
6330
+ * @tags Transactions, Raw, Transactions
6331
+ * @name SignAndBroadcastRawTx
6332
+ * @summary Sign and broadcast raw transaction API
6333
+ * @request POST:/api/v1/transactions/sign-broadcast-rawtx
6334
+ * @secure
6335
+ */
6336
+ signAndBroadcastRawTx: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/sign-broadcast-rawtx`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
6307
6337
  /**
6308
6338
  * No description
6309
6339
  *
@@ -7486,7 +7516,7 @@ class PasskeyService {
7486
7516
  this.authenticator = new Authenticator();
7487
7517
  }
7488
7518
  preparePasskeyRequestOptions(options) {
7489
- var _a, _b, _c, _d, _e, _f, _g, _h;
7519
+ var _a, _b, _c, _d, _e, _f;
7490
7520
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7491
7521
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7492
7522
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7494,13 +7524,11 @@ class PasskeyService {
7494
7524
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7495
7525
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7496
7526
  : undefined;
7497
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
7498
- ? {
7499
- eval: {
7500
- first: prfExtensionEvaluation,
7501
- },
7502
- }
7503
- : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7527
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7528
+ eval: {
7529
+ first: prfExtensionEvaluation,
7530
+ },
7531
+ } }) });
7504
7532
  logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7505
7533
  // While the authenticator still works with the prf and would return the response (if any),
7506
7534
  // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
@@ -7508,7 +7536,7 @@ class PasskeyService {
7508
7536
  return parsedOptions;
7509
7537
  }
7510
7538
  preparePasskeyCreationOptions(options) {
7511
- var _a, _b, _c, _d, _e, _f, _g, _h;
7539
+ var _a, _b, _c, _d, _e, _f;
7512
7540
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7513
7541
  ? decodeBase64URL(options.extensions.prf.eval.base64)
7514
7542
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
@@ -7516,8 +7544,12 @@ class PasskeyService {
7516
7544
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
7517
7545
  ? new Uint8Array(Object.values(options.extensions.prf.eval.first))
7518
7546
  : undefined;
7519
- const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined ? { eval: { first: prfExtensionEvaluation } } : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
7520
- logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
7547
+ const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
7548
+ eval: {
7549
+ first: prfExtensionEvaluation,
7550
+ },
7551
+ } }) });
7552
+ logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
7521
7553
  return parsedOptions;
7522
7554
  }
7523
7555
  /**
@@ -7532,10 +7564,7 @@ class PasskeyService {
7532
7564
  let passkeyCredential;
7533
7565
  let signInResponse;
7534
7566
  try {
7535
- const registrationChallengeResponse = await getSignature({
7536
- deviceAuthKeys: deviceKeyPair,
7537
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
7538
- });
7567
+ const registrationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
7539
7568
  if (!registrationChallengeResponse.registrationOptions)
7540
7569
  throw new WallabyError({
7541
7570
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7578,10 +7607,7 @@ class PasskeyService {
7578
7607
  catch (error) {
7579
7608
  logger.error('SDK::PasskeyService::addNewPasskey::error', error);
7580
7609
  if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
7581
- const authenticationChallengeResponse = await getSignature({
7582
- deviceAuthKeys: deviceKeyPair,
7583
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
7584
- });
7610
+ const authenticationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
7585
7611
  if (!authenticationChallengeResponse.authenticationOptions)
7586
7612
  throw new WallabyError({
7587
7613
  message: 'Passkey challenge could not be retrieved, please try again later.',
@@ -7652,10 +7678,9 @@ class PasskeyService {
7652
7678
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7653
7679
  });
7654
7680
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7655
- const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7656
- const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7681
+ const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
7657
7682
  eval: {
7658
- first: prfFirst,
7683
+ first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7659
7684
  },
7660
7685
  } }) });
7661
7686
  const passkeyCredential = await this.authenticator.authenticate({
@@ -7882,6 +7907,10 @@ class PasskeyService {
7882
7907
  key: LocalStorageItems.AccessToken,
7883
7908
  value: authenticationResponse.accessToken,
7884
7909
  },
7910
+ {
7911
+ key: LocalStorageItems.WallabyAuthPubKey,
7912
+ value: authenticationResponse.user.wallabyAuthPubKey,
7913
+ },
7885
7914
  ]);
7886
7915
  }
7887
7916
  /**
@@ -8090,14 +8119,13 @@ class AuthService extends Base {
8090
8119
  * @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
8091
8120
  * @returns the messaged, the hash, and the signature using the passed private key.
8092
8121
  */
8093
- async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
8122
+ async getSignature(deviceAuthKeys, passkeyChallengeType) {
8094
8123
  try {
8095
8124
  logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
8096
8125
  const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : PasskeyChallengeType.REGISTRATION;
8097
8126
  logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
8098
8127
  const response = await this.request(AuthRoutes.signatureMessage, {
8099
8128
  payload: {
8100
- walletId,
8101
8129
  clientAuthPubKey: deviceAuthKeys.publicKey,
8102
8130
  passkeyChallengeType: challengeType,
8103
8131
  },
@@ -8128,10 +8156,7 @@ class AuthService extends Base {
8128
8156
  logger.info('key pair generated', !!deviceKeyPair);
8129
8157
  let authentication;
8130
8158
  try {
8131
- const signatureMessageResponse = await this.getSignature({
8132
- deviceAuthKeys: deviceKeyPair,
8133
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
8134
- });
8159
+ const signatureMessageResponse = await this.getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
8135
8160
  logger.info('signature has been generated', !!signatureMessageResponse);
8136
8161
  switch (this.deviceAuthType) {
8137
8162
  case AuthType.Passkey:
@@ -8164,10 +8189,7 @@ class AuthService extends Base {
8164
8189
  // TODO Add passkey errors to the WallabyError ErrorResponseCodes
8165
8190
  if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
8166
8191
  logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
8167
- const newChallenge = await this.getSignature({
8168
- deviceAuthKeys: deviceKeyPair,
8169
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8170
- });
8192
+ const newChallenge = await this.getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
8171
8193
  authentication = await this.passkeyService.authenticate({
8172
8194
  deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
8173
8195
  challengeResponse: newChallenge,
@@ -8204,7 +8226,10 @@ class AuthService extends Base {
8204
8226
  errorCode: ErrorResponseCodes.sdk_invalid_parameter,
8205
8227
  });
8206
8228
  }
8207
- await this.localStorageService.save(LocalStorageItems.AccessToken, authentication.accessToken);
8229
+ await this.localStorageService.saveInBulk([
8230
+ { key: LocalStorageItems.AccessToken, value: authentication.accessToken },
8231
+ { key: LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
8232
+ ]);
8208
8233
  return Object.freeze(Object.assign(Object.assign({}, authentication), input));
8209
8234
  }
8210
8235
  catch (error) {
@@ -8280,9 +8305,7 @@ class AuthService extends Base {
8280
8305
  },
8281
8306
  credentialsKeyPair,
8282
8307
  });
8283
- const signatureMessage = await this.getSignature({
8284
- deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
8285
- });
8308
+ const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
8286
8309
  const authentication = await this.request(AuthRoutes.signIn, {
8287
8310
  payload: {
8288
8311
  externalUserId: this.userId,
@@ -8406,6 +8429,10 @@ class AuthService extends Base {
8406
8429
  key: LocalStorageItems.AccessToken,
8407
8430
  value: authResponse.accessToken,
8408
8431
  },
8432
+ {
8433
+ key: LocalStorageItems.WallabyAuthPubKey,
8434
+ value: authResponse.user.wallabyAuthPubKey,
8435
+ },
8409
8436
  ]);
8410
8437
  return authResponse;
8411
8438
  });
@@ -8490,16 +8517,12 @@ class WalletHandlersService extends Base {
8490
8517
  this.userId = config.userId;
8491
8518
  }
8492
8519
  async handleImportWallet(deviceAuthKeys, importWalletInput) {
8493
- var _a, _b, _c, _d, _e;
8520
+ var _a, _b, _c, _d;
8494
8521
  try {
8495
- // Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
8496
- // However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
8497
- // Using the reference as the fallback for the walletId in this case.
8498
- const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
8499
- walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
8500
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8501
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
8502
- });
8522
+ const { signature, message } = await this.authService.getSignature({
8523
+ publicKey: deviceAuthKeys.publicKey,
8524
+ privateKey: deviceAuthKeys.privateKey,
8525
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
8503
8526
  if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8504
8527
  importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8505
8528
  !importWalletInput.keyShareOptions) {
@@ -8509,7 +8532,7 @@ class WalletHandlersService extends Base {
8509
8532
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
8510
8533
  });
8511
8534
  }
8512
- const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
8535
+ const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
8513
8536
  if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
8514
8537
  throw new WallabyError({
8515
8538
  message: 'Number of shares must be greater than or equal to the threshold',
@@ -8519,10 +8542,10 @@ class WalletHandlersService extends Base {
8519
8542
  }
8520
8543
  const readyForTransportSeedPhrase = await this.cipher.encrypt({
8521
8544
  data: importWalletInput.seedPhrase,
8522
- encryptionKey: wallabyAuthPubKey,
8545
+ encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
8523
8546
  });
8524
8547
  const importWalletPayload = {
8525
- reference: importWalletInput.reference,
8548
+ reference: v4(),
8526
8549
  walletId: importWalletInput.walletId,
8527
8550
  message,
8528
8551
  signature,
@@ -8532,7 +8555,7 @@ class WalletHandlersService extends Base {
8532
8555
  numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
8533
8556
  threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
8534
8557
  walletOwnershipType: WalletOwnershipType.SingleOwner,
8535
- wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
8558
+ wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
8536
8559
  };
8537
8560
  const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
8538
8561
  payload: importWalletPayload,
@@ -8570,7 +8593,7 @@ class WalletHandlersService extends Base {
8570
8593
  }
8571
8594
  catch (error) {
8572
8595
  throw new WallabyError({
8573
- message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
8596
+ message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
8574
8597
  statusCode: error.statusCode,
8575
8598
  errorCode: error.errorCode,
8576
8599
  data: error.data,
@@ -8592,9 +8615,9 @@ class WalletHandlersService extends Base {
8592
8615
  var _a, _b, _c, _d, _e, _f;
8593
8616
  try {
8594
8617
  const { signature, message, hashedMessage } = await this.authService.getSignature({
8595
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
8596
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
8597
- });
8618
+ publicKey: deviceAuthKeys.publicKey,
8619
+ privateKey: deviceAuthKeys.privateKey,
8620
+ }, PasskeyChallengeType.AUTHENTICATION);
8598
8621
  if ((walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
8599
8622
  walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
8600
8623
  !walletCreationInput.keyShareOptions) {
@@ -8771,6 +8794,36 @@ class WalletHandlersService extends Base {
8771
8794
  });
8772
8795
  }
8773
8796
  }
8797
+ /**
8798
+ *
8799
+ * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
8800
+ * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
8801
+ * @param deviceAuthKeys - The device authentication key pair used to sign the request.
8802
+ * @description This function constructs the seed phrase from encrypted key shares.
8803
+ * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
8804
+ * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
8805
+ * @returns The function returns the encrypted seed phrase wrapped with client device public key.
8806
+ */
8807
+ async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
8808
+ try {
8809
+ const { signature, message } = await this.authService.getSignature(deviceAuthKeys, PasskeyChallengeType.AUTHENTICATION);
8810
+ const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
8811
+ payload: {
8812
+ walletId: walletId,
8813
+ signature,
8814
+ message,
8815
+ clientAuthPubKey: deviceAuthKeys.publicKey,
8816
+ recoveryPubKey: deviceAuthKeys.publicKey,
8817
+ encryptedShares: encryptedKeyShares,
8818
+ },
8819
+ });
8820
+ return retrieveSeedPhraseResponse.encryptedSeed;
8821
+ }
8822
+ catch (error) {
8823
+ logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
8824
+ return Promise.reject(error);
8825
+ }
8826
+ }
8774
8827
  }
8775
8828
 
8776
8829
  class WalletService extends Base {
@@ -8880,6 +8933,7 @@ class WalletService extends Base {
8880
8933
  */
8881
8934
  async export({ walletId, authenticationOptions, exportOptions }) {
8882
8935
  try {
8936
+ const { user: { wallabyAuthPubKey }, } = authenticationOptions;
8883
8937
  if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
8884
8938
  throw new WallabyError({
8885
8939
  message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
@@ -8989,20 +9043,10 @@ class WalletService extends Base {
8989
9043
  });
8990
9044
  }
8991
9045
  const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
8992
- const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8993
- const deviceAuthKeys = {
8994
- publicKey: deviceAuthPublicKey,
8995
- privateKey: decryptedDevicePrivateKey,
8996
- };
8997
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
8998
- deviceAuthKeys,
8999
- walletId,
9000
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9001
- });
9002
9046
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9003
9047
  storedEncryptedData: parsedPrimaryShare,
9004
9048
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9005
- wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
9049
+ wallabyPublicKey: wallabyAuthPubKey,
9006
9050
  options: {
9007
9051
  authType: this.deviceAuthType,
9008
9052
  password: authenticationOptions.password,
@@ -9010,18 +9054,17 @@ class WalletService extends Base {
9010
9054
  prfValue: authenticationOptions.prfValue,
9011
9055
  },
9012
9056
  });
9013
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9014
- payload: {
9015
- walletId: walletId,
9016
- signature,
9017
- message,
9018
- clientAuthPubKey: deviceAuthKeys.publicKey,
9019
- recoveryPubKey: deviceAuthKeys.publicKey,
9020
- encryptedShares: [wallabyBoundPrimaryShare],
9057
+ const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9058
+ const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
9059
+ encryptedKeyShares: [wallabyBoundPrimaryShare],
9060
+ walletId,
9061
+ deviceAuthKeys: {
9062
+ publicKey: deviceAuthPublicKey,
9063
+ privateKey: decryptedDevicePrivateKey,
9021
9064
  },
9022
9065
  });
9023
9066
  decryptedSeedPhrase = await this.cipher.decrypt({
9024
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9067
+ cipherText: encryptedReconstructedSeedPhrase,
9025
9068
  decryptionKey: decryptedDevicePrivateKey,
9026
9069
  });
9027
9070
  if (exportOptions.algorandSeedPhrase) {
@@ -9059,9 +9102,7 @@ class WalletService extends Base {
9059
9102
  * @returns {ImportWalletResponse} The wallet has been created successfully.
9060
9103
  */
9061
9104
  async import(input) {
9062
- var _a;
9063
9105
  try {
9064
- const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : v4();
9065
9106
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9066
9107
  if (!encryptedDevicePrivateKey) {
9067
9108
  throw new WallabyError({
@@ -9092,7 +9133,7 @@ class WalletService extends Base {
9092
9133
  const importRequest = await this.handlers.handleImportWallet({
9093
9134
  publicKey: clientAuthPubKey,
9094
9135
  privateKey: decryptedDevicePrivateKey,
9095
- }, Object.assign(Object.assign({}, input), { reference: requestReference }));
9136
+ }, input);
9096
9137
  return importRequest;
9097
9138
  }
9098
9139
  catch (error) {
@@ -9106,15 +9147,11 @@ class WalletService extends Base {
9106
9147
  *
9107
9148
  * @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
9108
9149
  * @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
9109
- *
9110
- * @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
9111
- * Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
9112
9150
  */
9113
9151
  async recover(input) {
9114
9152
  var _a, _b;
9115
9153
  try {
9116
- const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9117
- input.authenticationOptions.user.wallabyAuthPubKey;
9154
+ const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
9118
9155
  const deviceAuthKeyPair = createIdentity();
9119
9156
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9120
9157
  authType: this.deviceAuthType,
@@ -9154,37 +9191,27 @@ class WalletService extends Base {
9154
9191
  return recoverWithSeedPhraseResponse;
9155
9192
  }
9156
9193
  else if (input.decryptedShares) {
9157
- if (!input.decryptedShares.length) {
9194
+ const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9195
+ const encrypted = await this.cipher.encrypt({
9196
+ data: decryptedShare,
9197
+ encryptionKey: wallabyPublicKey,
9198
+ });
9199
+ return encrypted;
9200
+ }));
9201
+ if (!encryptedShares.length) {
9158
9202
  throw new WallabyError({
9159
9203
  message: 'Decrypted shares are required',
9160
9204
  statusCode: 400,
9161
9205
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
9162
9206
  });
9163
9207
  }
9164
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9208
+ const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
9209
+ encryptedKeyShares: encryptedShares,
9165
9210
  deviceAuthKeys: deviceAuthKeyPair,
9166
9211
  walletId: input.walletId,
9167
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9168
- });
9169
- const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9170
- const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
9171
- return await this.cipher.encrypt({
9172
- data: decryptedShare,
9173
- encryptionKey: transportEncryptionKey,
9174
- });
9175
- }));
9176
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
9177
- payload: {
9178
- walletId: input.walletId,
9179
- signature,
9180
- message,
9181
- clientAuthPubKey: deviceAuthKeyPair.publicKey,
9182
- recoveryPubKey: deviceAuthKeyPair.publicKey,
9183
- encryptedShares,
9184
- },
9185
9212
  });
9186
9213
  const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
9187
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
9214
+ cipherText: encryptedSeed,
9188
9215
  decryptionKey: deviceAuthKeyPair.privateKey,
9189
9216
  encryptionKey: wallabyPublicKey,
9190
9217
  });
@@ -9242,9 +9269,17 @@ class WalletService extends Base {
9242
9269
  async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
9243
9270
  try {
9244
9271
  const signatureMessage = await this.authService.getSignature({
9245
- deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
9246
- walletId,
9247
- });
9272
+ publicKey: deviceAuthKeys.publicKey,
9273
+ privateKey: deviceAuthKeys.privateKey,
9274
+ });
9275
+ // const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
9276
+ // payload: {
9277
+ // walletId,
9278
+ // signature: signatureMessage.signature,
9279
+ // message: signatureMessage.message,
9280
+ // clientAuthPubKey: deviceAuthKeys.publicKey,
9281
+ // },
9282
+ // });
9248
9283
  const response = await this.api.wallets.retrieveShares({
9249
9284
  walletId: walletId,
9250
9285
  signature: signatureMessage.signature,
@@ -9425,7 +9460,6 @@ class WalletService extends Base {
9425
9460
  */
9426
9461
  async initAddNewDevice(input) {
9427
9462
  const { walletId, backupUrl, authenticationOptions } = input;
9428
- const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
9429
9463
  const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
9430
9464
  if (!encryptedDevicePrivateKey) {
9431
9465
  throw new WallabyError({
@@ -9486,7 +9520,7 @@ class WalletService extends Base {
9486
9520
  const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
9487
9521
  storedEncryptedData: parsedPrimaryShare,
9488
9522
  encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9489
- wallabyPublicKey,
9523
+ wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
9490
9524
  options: {
9491
9525
  authType: this.deviceAuthType,
9492
9526
  password: authenticationOptions.password,
@@ -9545,11 +9579,22 @@ class WalletService extends Base {
9545
9579
  }
9546
9580
  const devicePublicKey = (_a = (await this.localStorageService.fetch(LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
9547
9581
  const signatureMessage = await this.authService.getSignature({
9548
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
9549
- walletId: input.walletId,
9550
- passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
9551
- });
9552
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9582
+ publicKey: devicePublicKey,
9583
+ privateKey: decryptedDevicePrivateKey,
9584
+ }, PasskeyChallengeType.REGISTRATION);
9585
+ // const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
9586
+ // payload: {
9587
+ // walletId: input.walletId,
9588
+ // message: signatureMessage.message,
9589
+ // signature: signatureMessage.signature,
9590
+ // clientAuthPubKey: devicePublicKey,
9591
+ // share: {
9592
+ // encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9593
+ // wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9594
+ // type: KeyTypeName.OwnerBackupDeviceShare,
9595
+ // },
9596
+ // },
9597
+ // });
9553
9598
  const backUpResponse = await this.api.wallets.addNewDevice({
9554
9599
  walletId: input.walletId,
9555
9600
  message: signatureMessage.message,
@@ -9557,7 +9602,7 @@ class WalletService extends Base {
9557
9602
  clientAuthPubKey: devicePublicKey,
9558
9603
  share: {
9559
9604
  encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
9560
- wrappingPublicKey: wallabyPublicKey,
9605
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9561
9606
  type: KeyTypeName.OwnerBackupDeviceShare,
9562
9607
  },
9563
9608
  });
@@ -9565,8 +9610,7 @@ class WalletService extends Base {
9565
9610
  backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
9566
9611
  {
9567
9612
  encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
9568
- wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
9569
- input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9613
+ wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
9570
9614
  type: KeyTypeName.OwnerMainDeviceShare,
9571
9615
  },
9572
9616
  ];
@@ -9623,28 +9667,12 @@ class WalletService extends Base {
9623
9667
  });
9624
9668
  }
9625
9669
  const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
9626
- const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9627
- authType: this.deviceAuthType,
9628
- password: input.authenticationOptions.password,
9629
- salt: input.authenticationOptions.clientSalt,
9630
- prfValue: input.authenticationOptions.prfValue,
9631
- });
9632
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9633
- cipherText: parsedDevicePrivateKey,
9634
- decryptionKey: derivedCredentialsKeyPair.privateKey,
9635
- });
9636
- const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9637
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
9638
- deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
9639
- walletId,
9640
- });
9641
- const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
9642
9670
  if (storedSeedPhrase) {
9643
9671
  const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
9644
9672
  transportSeed = await this.cipher.prepareStoredDataForTransport({
9645
9673
  storedEncryptedData: parsedStoredSeedPhrase,
9646
9674
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9647
- wallabyPublicKey,
9675
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9648
9676
  options: {
9649
9677
  authType: this.deviceAuthType,
9650
9678
  password: input.authenticationOptions.password,
@@ -9658,7 +9686,7 @@ class WalletService extends Base {
9658
9686
  transportKeyShare = await this.cipher.prepareStoredDataForTransport({
9659
9687
  storedEncryptedData: parsedPrimaryKeyShare,
9660
9688
  encryptedDevicePrivateKey: parsedDevicePrivateKey,
9661
- wallabyPublicKey,
9689
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
9662
9690
  options: {
9663
9691
  authType: this.deviceAuthType,
9664
9692
  password: input.authenticationOptions.password,
@@ -9674,6 +9702,21 @@ class WalletService extends Base {
9674
9702
  errorCode: 'sdk_private_key_not_found',
9675
9703
  });
9676
9704
  }
9705
+ const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9706
+ authType: this.deviceAuthType,
9707
+ password: input.authenticationOptions.password,
9708
+ salt: input.authenticationOptions.clientSalt,
9709
+ prfValue: input.authenticationOptions.prfValue,
9710
+ });
9711
+ const decryptedDevicePrivateKey = await this.cipher.decrypt({
9712
+ cipherText: parsedDevicePrivateKey,
9713
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
9714
+ });
9715
+ const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9716
+ const { signature, message } = await this.authService.getSignature({
9717
+ privateKey: decryptedDevicePrivateKey,
9718
+ publicKey: devicePublicKey,
9719
+ });
9677
9720
  const response = await this.request(WalletRoutes.generateWalletAddresses, {
9678
9721
  payload: {
9679
9722
  walletId,
@@ -9865,8 +9908,8 @@ class WalletService extends Base {
9865
9908
  // During migration, we need to authenticate but avoid creating conflicting device keypairs
9866
9909
  const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
9867
9910
  const signInSignatureMessage = await this.authService.getSignature({
9868
- deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
9869
- walletId,
9911
+ publicKey: devicePublicKey,
9912
+ privateKey: decryptedPrivateKey,
9870
9913
  });
9871
9914
  // this would ensure the stored public key is consistent with wallaby and can authenticate the user.
9872
9915
  const authResponse = await this.request(AuthRoutes.signIn, {
@@ -9892,6 +9935,7 @@ class WalletService extends Base {
9892
9935
  // Store authentication tokens
9893
9936
  await this.localStorageService.saveInBulk([
9894
9937
  { key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
9938
+ { key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
9895
9939
  { key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
9896
9940
  { key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
9897
9941
  ]);
@@ -9954,8 +9998,8 @@ class WalletService extends Base {
9954
9998
  throw error;
9955
9999
  }
9956
10000
  }
9957
- async clearDevice({ walletId }) {
9958
- await this.localStorageService.clearLocalStorage(walletId);
10001
+ async clearDevice() {
10002
+ await this.localStorageService.clearLocalStorage();
9959
10003
  }
9960
10004
  /**
9961
10005
  * Prepares authentication data and encrypted payload for any request.
@@ -9992,11 +10036,9 @@ class WalletService extends Base {
9992
10036
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9993
10037
  // Get signature message
9994
10038
  const signatureMessage = await this.authService.getSignature({
9995
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
9996
- walletId,
9997
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
9998
- });
9999
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
10039
+ publicKey: deviceAuthPublicKey,
10040
+ privateKey: decryptedDevicePrivateKey,
10041
+ }, PasskeyChallengeType.AUTHENTICATION);
10000
10042
  // Prepare encrypted data (seed phrase or key shares)
10001
10043
  const sharesEncryptedWithWallabyPubKey = [];
10002
10044
  let readyForTransportSeedPhrase = undefined;
@@ -10016,7 +10058,7 @@ class WalletService extends Base {
10016
10058
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
10017
10059
  storedEncryptedData: parsedSeedPhrase,
10018
10060
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10019
- wallabyPublicKey,
10061
+ wallabyPublicKey: user.wallabyAuthPubKey,
10020
10062
  options: {
10021
10063
  authType: this.deviceAuthType,
10022
10064
  password,
@@ -10031,7 +10073,7 @@ class WalletService extends Base {
10031
10073
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
10032
10074
  storedEncryptedData: parsedPrimaryShare,
10033
10075
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10034
- wallabyPublicKey,
10076
+ wallabyPublicKey: user.wallabyAuthPubKey,
10035
10077
  options: {
10036
10078
  authType: this.deviceAuthType,
10037
10079
  password,
@@ -10196,11 +10238,11 @@ class WalletService extends Base {
10196
10238
  publicKey: clientPublicKey,
10197
10239
  privateKey: decryptedClientAuthPrivKey,
10198
10240
  }, {
10241
+ walletId: input.walletId,
10199
10242
  authenticationOptions: authentication,
10200
10243
  seedPhrase: decryptedSeedPhrase,
10201
10244
  storeSeedPhrase: false,
10202
10245
  returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
10203
- walletId: input.walletId,
10204
10246
  keyShareOptions: {
10205
10247
  threshold: 2,
10206
10248
  numberOfKeyShares: 3,
@@ -10251,31 +10293,20 @@ class WalletService extends Base {
10251
10293
  logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
10252
10294
  }
10253
10295
  if (!decryptedSeedPhrase && decryptedPrimaryShare) {
10254
- const deviceAuthKeys = {
10255
- publicKey: clientPublicKey,
10256
- privateKey: decryptedClientAuthPrivKey,
10257
- };
10258
- const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
10259
- deviceAuthKeys,
10260
- walletId: input.walletId,
10261
- passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
10262
- });
10263
10296
  const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
10264
10297
  data: decryptedPrimaryShare,
10265
- encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
10298
+ encryptionKey: authentication.user.wallabyAuthPubKey,
10266
10299
  });
10267
- const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
10268
- payload: {
10269
- walletId: input.walletId,
10270
- signature,
10271
- message,
10272
- clientAuthPubKey: deviceAuthKeys.publicKey,
10273
- recoveryPubKey: deviceAuthKeys.publicKey,
10274
- encryptedShares: [flippedEncryptedPrimaryShare],
10300
+ const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
10301
+ walletId: input.walletId,
10302
+ encryptedKeyShares: [flippedEncryptedPrimaryShare],
10303
+ deviceAuthKeys: {
10304
+ publicKey: clientPublicKey,
10305
+ privateKey: decryptedClientAuthPrivKey,
10275
10306
  },
10276
10307
  });
10277
10308
  decryptedSeedPhrase = await this.cipher.decrypt({
10278
- cipherText: retrieveSeedPhraseResponse.encryptedSeed,
10309
+ cipherText: reconstructedSeedPhrase,
10279
10310
  decryptionKey: decryptedClientAuthPrivKey,
10280
10311
  });
10281
10312
  }
@@ -10382,7 +10413,7 @@ class WalletDataService extends Base {
10382
10413
  * Note: Either chainName or tokenStandard must be provided.
10383
10414
  * @returns { FetchBalanceData } Returns an array of the requested tokens balances.
10384
10415
  */
10385
- async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
10416
+ async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
10386
10417
  try {
10387
10418
  if (!tokensAndAddressesList.length) {
10388
10419
  throw new WallabyError({
@@ -10970,17 +11001,18 @@ class Swap extends Base {
10970
11001
  this.walletService = new WalletService(config);
10971
11002
  }
10972
11003
  /**
10973
- * Gets a swap quote between two assets (from/to), including fees, min output, and slippage limits.
11004
+ * Gets a swap quote between two assets, including fees, min output, and slippage limits.
10974
11005
  *
10975
11006
  * @public
10976
11007
  * @param {SwapQuoteRequest} request - The swap quote request parameters
10977
11008
  * @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
10978
11009
  */
10979
- async getQuote({ walletId, fromAsset, toAsset, fromAmount, toAmount }) {
11010
+ async getQuote(request) {
10980
11011
  try {
10981
- if (!walletId || !fromAsset || !toAsset) {
11012
+ const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
11013
+ if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
10982
11014
  throw new WallabyError({
10983
- message: 'Missing required parameters: walletId, fromAsset, and toAsset are required',
11015
+ message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
10984
11016
  statusCode: 400,
10985
11017
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
10986
11018
  });
@@ -10992,10 +11024,16 @@ class Swap extends Base {
10992
11024
  errorCode: ErrorResponseCodes.sdk_missing_parameter,
10993
11025
  });
10994
11026
  }
10995
- // Build path with walletId, but exclude it from request body
11027
+ if (fromAmount && toAmount) {
11028
+ throw new WallabyError({
11029
+ message: 'Only one of fromAmount or toAmount may be provided, not both',
11030
+ statusCode: 400,
11031
+ errorCode: ErrorResponseCodes.sdk_invalid_parameter,
11032
+ });
11033
+ }
10996
11034
  const routePayload = { walletId };
10997
- const requestBody = Object.assign(Object.assign({ fromAsset,
10998
- toAsset }, (fromAmount && { fromAmount })), (toAmount && { toAmount }));
11035
+ const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
11036
+ toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
10999
11037
  const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
11000
11038
  payload: requestBody,
11001
11039
  });
@@ -11139,11 +11177,9 @@ class Swap extends Base {
11139
11177
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11140
11178
  // Get signature message
11141
11179
  const signatureMessage = await this.authService.getSignature({
11142
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11143
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11144
- walletId,
11145
- });
11146
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11180
+ publicKey: deviceAuthPublicKey,
11181
+ privateKey: decryptedDevicePrivateKey,
11182
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11147
11183
  // Prepare encrypted data (seed phrase or key shares)
11148
11184
  const sharesEncryptedWithWallabyPubKey = [];
11149
11185
  let readyForTransportSeedPhrase = undefined;
@@ -11164,7 +11200,7 @@ class Swap extends Base {
11164
11200
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11165
11201
  storedEncryptedData: parsedSeedPhrase,
11166
11202
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11167
- wallabyPublicKey,
11203
+ wallabyPublicKey: user.wallabyAuthPubKey,
11168
11204
  options: {
11169
11205
  authType: this.deviceAuthType,
11170
11206
  password,
@@ -11179,7 +11215,7 @@ class Swap extends Base {
11179
11215
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11180
11216
  storedEncryptedData: parsedPrimaryShare,
11181
11217
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11182
- wallabyPublicKey,
11218
+ wallabyPublicKey: user.wallabyAuthPubKey,
11183
11219
  options: {
11184
11220
  authType: this.deviceAuthType,
11185
11221
  password,
@@ -11434,7 +11470,7 @@ class Transactions extends Base {
11434
11470
  * @param {BlockchainName} blockchain
11435
11471
  * @returns {FeeEstimateRequest}
11436
11472
  */
11437
- async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
11473
+ async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
11438
11474
  try {
11439
11475
  const response = await this.request(TransactionsRoutes.estimateFee, {
11440
11476
  queryParams: {
@@ -11777,11 +11813,9 @@ class Transactions extends Base {
11777
11813
  const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
11778
11814
  // Get signature message
11779
11815
  const signatureMessage = await this.authService.getSignature({
11780
- deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
11781
- walletId,
11782
- passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
11783
- });
11784
- const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
11816
+ publicKey: deviceAuthPublicKey,
11817
+ privateKey: decryptedDevicePrivateKey,
11818
+ }, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
11785
11819
  // Prepare encrypted data (seed phrase or key shares)
11786
11820
  const sharesEncryptedWithWallabyPubKey = [];
11787
11821
  let readyForTransportSeedPhrase = undefined;
@@ -11802,7 +11836,7 @@ class Transactions extends Base {
11802
11836
  readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
11803
11837
  storedEncryptedData: parsedSeedPhrase,
11804
11838
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11805
- wallabyPublicKey,
11839
+ wallabyPublicKey: user.wallabyAuthPubKey,
11806
11840
  options: {
11807
11841
  authType: this.deviceAuthType,
11808
11842
  password,
@@ -11817,7 +11851,7 @@ class Transactions extends Base {
11817
11851
  const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
11818
11852
  storedEncryptedData: parsedPrimaryShare,
11819
11853
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
11820
- wallabyPublicKey,
11854
+ wallabyPublicKey: user.wallabyAuthPubKey,
11821
11855
  options: {
11822
11856
  authType: this.deviceAuthType,
11823
11857
  password,