wallaby-cash 2.3.5 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const uuid = require('uuid');
5
+ const algosdk = require('algosdk');
6
+ const bip39 = require('bip39');
6
7
  const log = require('loglevel');
7
8
  const cryptoJs = require('crypto-js');
8
9
  const jwtDecode = require('jwt-decode');
9
10
  const lodash = require('lodash');
10
11
  const WebAuthn = require('@simplewebauthn/browser');
11
12
  const jsBase64 = require('js-base64');
13
+ const uuid = require('uuid');
12
14
 
13
15
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
14
16
 
@@ -30,6 +32,8 @@ n.default = e;
30
32
  return Object.freeze(n);
31
33
  }
32
34
 
35
+ const algosdk__namespace = /*#__PURE__*/_interopNamespaceCompat(algosdk);
36
+ const bip39__namespace = /*#__PURE__*/_interopNamespaceCompat(bip39);
33
37
  const log__default = /*#__PURE__*/_interopDefaultCompat(log);
34
38
  const WebAuthn__namespace = /*#__PURE__*/_interopNamespaceCompat(WebAuthn);
35
39
 
@@ -597,7 +601,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
597
601
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
598
602
  ];
599
603
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
600
- const currentPackageVersion = "2.3.5" ;
604
+ const currentPackageVersion = "2.3.6" ;
601
605
 
602
606
  /**
603
607
  * Storage keys adapter for Storage interface across different platforms.
@@ -7193,8 +7197,8 @@ const WalletRoutes = {
7193
7197
  requiresAccessToken: false,
7194
7198
  },
7195
7199
  getTokenBalance: {
7196
- fullPath: ({ address, symbol, chainName, tokenStandard }) => {
7197
- return (`/query/assets/balance?address=${address}&assetSymbol=${symbol}` +
7200
+ fullPath: ({ address, assetSymbol, chainName, tokenStandard }) => {
7201
+ return (`/query/assets/balance?address=${address}&assetSymbol=${assetSymbol}` +
7198
7202
  `${tokenStandard ? `&tokenType=${tokenStandard}` : ''}` +
7199
7203
  `${chainName ? `&chainName=${chainName}` : ''}`);
7200
7204
  },
@@ -7380,17 +7384,17 @@ const TransactionsRoutes = {
7380
7384
 
7381
7385
  const SwapRoutes = {
7382
7386
  getQuote: {
7383
- fullPath: ({ walletId }) => `/api/v1/wallets/${walletId}/swap/quote`,
7387
+ fullPath: ({ walletId }) => `/wallets/${walletId}/swap/quote`,
7384
7388
  method: exports.RequestMethod.Post,
7385
7389
  requiresAccessToken: true,
7386
7390
  },
7387
7391
  executeSwap: {
7388
- fullPath: ({ walletId }) => `/api/v1/wallets/${walletId}/swap`,
7392
+ fullPath: '/wallets/execute-swap',
7389
7393
  method: exports.RequestMethod.Post,
7390
7394
  requiresAccessToken: true,
7391
7395
  },
7392
7396
  getSwaps: {
7393
- fullPath: ({ walletId }) => `/api/v1/wallets/${walletId}/swaps`,
7397
+ fullPath: ({ walletId }) => `/wallets/${walletId}/swaps`,
7394
7398
  method: exports.RequestMethod.Get,
7395
7399
  requiresAccessToken: true,
7396
7400
  },
@@ -9042,21 +9046,7 @@ class WalletService extends Base {
9042
9046
  },
9043
9047
  });
9044
9048
  if (exportOptions.algorandSeedPhrase) {
9045
- const algorandSeedPhrase = await this.getAlgorandSeedPhrase({
9046
- standardSeedPhrase: decryptedSeedPhrase,
9047
- authenticationOptions,
9048
- walletId,
9049
- });
9050
- decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
9051
- encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
9052
- encryptedDevicePrivateKey: parsedDevicePrivateKey,
9053
- options: {
9054
- authType: this.deviceAuthType,
9055
- password: authenticationOptions.password,
9056
- salt: authenticationOptions.user.clientSalt,
9057
- prfValue: authenticationOptions.prfValue,
9058
- },
9059
- });
9049
+ decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
9060
9050
  if (!decryptedAlgorandSeedPhrase) {
9061
9051
  throw new WallabyError({
9062
9052
  message: 'Something went wrong decrypting algorand seed phrase.',
@@ -9100,21 +9090,7 @@ class WalletService extends Base {
9100
9090
  decryptionKey: decryptedDevicePrivateKey,
9101
9091
  });
9102
9092
  if (exportOptions.algorandSeedPhrase) {
9103
- const algorandSeedPhrase = await this.getAlgorandSeedPhrase({
9104
- standardSeedPhrase: decryptedSeedPhrase,
9105
- authenticationOptions,
9106
- walletId,
9107
- });
9108
- decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
9109
- encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
9110
- encryptedDevicePrivateKey: parsedDevicePrivateKey,
9111
- options: {
9112
- authType: this.deviceAuthType,
9113
- password: authenticationOptions.password,
9114
- salt: authenticationOptions.user.clientSalt,
9115
- prfValue: authenticationOptions.prfValue,
9116
- },
9117
- });
9093
+ decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
9118
9094
  }
9119
9095
  }
9120
9096
  }
@@ -9475,109 +9451,23 @@ class WalletService extends Base {
9475
9451
  *
9476
9452
  * @public
9477
9453
  * Convert BIP39 Standard seed phrase to Algorand fixed 25 words mnemonic phrase
9478
- * @param {ConvertToAlgorandSeedPhraseRequest} input
9479
- * - {string} standardSeedPhrase - The decrypted standard seed phrase (bip32 standard 24 words mnemonic) to be transformed.
9480
- * - {string} walletId - The Wallaby wallet ID.
9481
- * - {AuthenticationResponse} authenticationOptions - The authentication options carried from the authentication request (`signIn` | `signUp`)
9482
- * @returns {ConvertMnemonicSeedPhraseResponse} The mnemonic seed phrase has been converted successfully.
9454
+ * @param {string} bip39Mnemonic - The decrypted standard seed phrase (bip32 standard 24 words mnemonic) to be transformed.
9455
+ * @returns {string} The Algorand fixed 25 words mnemonic phrase.
9483
9456
  */
9484
- async getAlgorandSeedPhrase(input) {
9457
+ getAlgorandSeedPhrase(bip39Mnemonic) {
9485
9458
  try {
9486
- const { standardSeedPhrase, authenticationOptions: { user, password, clientSalt, prfValue }, } = input;
9487
- const storedEncryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
9488
- if (!storedEncryptedDevicePrivateKey)
9489
- throw new WallabyError({
9490
- message: 'Device private key could not be found',
9491
- statusCode: 404,
9492
- errorCode: exports.ErrorResponseCodes.sdk_private_key_not_found,
9493
- });
9494
- const parsedEncryptedDevicePrivateKey = safeJsonParse(storedEncryptedDevicePrivateKey);
9495
- if (this.deviceAuthType === exports.AuthType.Password && input.authenticationOptions.password) {
9496
- try {
9497
- await this.handleUpdateToV2({
9498
- password: input.authenticationOptions.password,
9499
- walletId: input.walletId,
9500
- });
9501
- }
9502
- catch (error) {
9503
- logger.error('SDK::WalletService::getAlgorandSeedPhrase::handleUpdateToV2::error', error);
9504
- throw new WallabyError({
9505
- message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
9506
- statusCode: 500,
9507
- errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9508
- });
9509
- }
9510
- }
9511
- let wallabyBoundSeedPhrase;
9512
- if (standardSeedPhrase) {
9513
- const encryptedSeed = await this.cipher.encrypt({
9514
- data: standardSeedPhrase,
9515
- encryptionKey: user.wallabyAuthPubKey,
9516
- });
9517
- wallabyBoundSeedPhrase = encryptedSeed;
9518
- }
9519
- else {
9520
- const storedEncryptedStandardSeedPhrase = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, {
9521
- walletId: input.walletId,
9522
- });
9523
- if (!storedEncryptedStandardSeedPhrase) {
9524
- throw new WallabyError({
9525
- message: 'Device is missing required information, please import your wallet on this device before proceeding.',
9526
- statusCode: 404,
9527
- errorCode: exports.ErrorResponseCodes.sdk_seed_phrase_not_found,
9528
- });
9529
- }
9530
- const parsedEncryptedStandardSeedPhrase = safeJsonParse(storedEncryptedStandardSeedPhrase);
9531
- wallabyBoundSeedPhrase = await this.cipher.prepareStoredDataForTransport({
9532
- storedEncryptedData: parsedEncryptedStandardSeedPhrase,
9533
- encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
9534
- wallabyPublicKey: user.wallabyAuthPubKey,
9535
- options: {
9536
- authType: this.deviceAuthType,
9537
- password,
9538
- prfValue,
9539
- salt: clientSalt,
9540
- },
9541
- });
9542
- }
9543
- const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
9544
- authType: this.deviceAuthType,
9545
- password,
9546
- salt: clientSalt,
9547
- prfValue,
9548
- });
9549
- const decryptedDevicePrivateKey = await this.cipher.decrypt({
9550
- cipherText: parsedEncryptedDevicePrivateKey,
9551
- decryptionKey: credentialsKeyPair.privateKey,
9552
- });
9553
- if (!decryptedDevicePrivateKey) {
9554
- throw new WallabyError({
9555
- message: 'Failed to decrypt device private key',
9556
- statusCode: 500,
9557
- errorCode: exports.ErrorResponseCodes.sdk_private_key_decryption_failed,
9558
- });
9559
- }
9560
- const clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9561
- const reference = uuid.v4();
9562
- const signatureMessage = await this.authService.getSignature({
9563
- publicKey: clientAuthPubKey,
9564
- privateKey: decryptedDevicePrivateKey,
9565
- });
9566
- const { message, signature } = signatureMessage;
9567
- const response = await this.request(WalletRoutes.convertMnemonicSeedPhrase, {
9568
- payload: {
9569
- reference,
9570
- signature,
9571
- message,
9572
- clientAuthPubKey,
9573
- encryptedSeed: wallabyBoundSeedPhrase,
9574
- },
9575
- });
9576
- return response;
9459
+ const seedBuffer = bip39__namespace.mnemonicToSeedSync(bip39Mnemonic);
9460
+ const seed = seedBuffer.slice(0, 32);
9461
+ const convertedSeedPhrase = algosdk__namespace.mnemonicFromSeed(seed);
9462
+ return convertedSeedPhrase;
9577
9463
  }
9578
9464
  catch (error) {
9579
9465
  logger.error('SDK::Wallet::getAlgorandSeedPhrase::error', error);
9580
- throw error;
9466
+ throw new WallabyError({
9467
+ message: error instanceof Error ? error.message : 'Failed to convert seed phrase to Algorand mnemonic.',
9468
+ statusCode: 500,
9469
+ errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
9470
+ });
9581
9471
  }
9582
9472
  }
9583
9473
  /**
@@ -11196,11 +11086,10 @@ class Swap extends Base {
11196
11086
  }
11197
11087
  const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareSwapAuth(authenticationOptions, walletId);
11198
11088
  let swapResponse;
11199
- // Build path with walletId, but exclude it from request body
11200
- const routePayload = { walletId };
11201
11089
  if (readyForTransportSeedPhrase) {
11202
- swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath(routePayload) }), {
11090
+ swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
11203
11091
  payload: {
11092
+ walletId,
11204
11093
  quoteId,
11205
11094
  message: signatureMessage.message,
11206
11095
  signature: signatureMessage.signature,
@@ -11210,8 +11099,9 @@ class Swap extends Base {
11210
11099
  });
11211
11100
  }
11212
11101
  else if (hasShares) {
11213
- swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath(routePayload) }), {
11102
+ swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
11214
11103
  payload: {
11104
+ walletId,
11215
11105
  quoteId,
11216
11106
  message: signatureMessage.message,
11217
11107
  signature: signatureMessage.signature,
@@ -11699,6 +11589,7 @@ class Transactions extends Base {
11699
11589
  if (readyForTransportSeedPhrase) {
11700
11590
  transferResponse = await this.request(TransactionsRoutes.transfer, {
11701
11591
  payload: {
11592
+ walletId,
11702
11593
  message: signatureMessage.message,
11703
11594
  signature: signatureMessage.signature,
11704
11595
  clientAuthPubKey: deviceAuthPublicKey,
@@ -11716,6 +11607,7 @@ class Transactions extends Base {
11716
11607
  else if (hasShares) {
11717
11608
  transferResponse = await this.request(TransactionsRoutes.transferWithShares, {
11718
11609
  payload: {
11610
+ walletId,
11719
11611
  message: signatureMessage.message,
11720
11612
  signature: signatureMessage.signature,
11721
11613
  clientAuthPubKey: deviceAuthPublicKey,