wallaby-cash 3.2.1 → 3.3.0

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
@@ -594,7 +594,7 @@ const env = {
594
594
  isNative: false,
595
595
  isWeb,
596
596
  };
597
- const currentPackageVersion = "3.2.1" ;
597
+ const currentPackageVersion = "3.3.0" ;
598
598
 
599
599
  /**
600
600
  * Storage keys adapter for Storage interface across different platforms.
@@ -4432,14 +4432,19 @@ class Cipher {
4432
4432
  return AES.encrypt(typeof data === 'string' ? data : JSON.stringify(data), this.getMasterKey().key).toString();
4433
4433
  }
4434
4434
  decryptWithMasterKey({ cipherText }) {
4435
- const decrypted = AES.decrypt(cipherText, this.getMasterKey().key).toString(enc.Utf8);
4436
- if (decrypted) {
4437
- return isJsonString(decrypted) ? safeJsonParse(decrypted) : decrypted;
4435
+ try {
4436
+ const decrypted = AES.decrypt(cipherText, this.getMasterKey().key).toString(enc.Utf8);
4437
+ if (decrypted) {
4438
+ return isJsonString(decrypted) ? safeJsonParse(decrypted) : decrypted;
4439
+ }
4438
4440
  }
4439
- else {
4440
- logger.error('Decryption failed with master key');
4441
+ catch (error) {
4442
+ // crypto-js throws "Malformed UTF-8 data" when the ciphertext can't be decrypted
4443
+ logger.error('Decryption failed with master key', error);
4441
4444
  return undefined;
4442
4445
  }
4446
+ logger.error('Decryption failed with master key');
4447
+ return undefined;
4443
4448
  }
4444
4449
  /**
4445
4450
  * Validate that a public key is the correct length and format.
@@ -5658,6 +5663,16 @@ class Api {
5658
5663
  * @secure
5659
5664
  */
5660
5665
  signIn: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/sign-in`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
5666
+ /**
5667
+ * No description
5668
+ *
5669
+ * @tags Auth
5670
+ * @name IssueJwtToken
5671
+ * @summary Issue a Wallaby JWT token for a user using only x-api-key and x-client-jwt headers. Requires mfaVerified and that the user belongs to the API key merchant.
5672
+ * @request POST:/api/v1/auth/issue-jwt-token
5673
+ * @secure
5674
+ */
5675
+ issueJwtToken: (params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/issue-jwt-token`, method: "POST", secure: true, format: "json" }, params)),
5661
5676
  /**
5662
5677
  * No description
5663
5678
  *
@@ -6156,6 +6171,20 @@ class Api {
6156
6171
  if (params === void 0) { params = {}; }
6157
6172
  return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/assets`, method: "GET", query: query, secure: true, format: "json" }, params));
6158
6173
  },
6174
+ /**
6175
+ * No description
6176
+ *
6177
+ * @tags Wallets
6178
+ * @name GetWalletAddresses
6179
+ * @summary Get all assets that exist in a certain wallet, by specifying a wallet ID
6180
+ * @request GET:/api/v1/wallets/{walletId}/addresses
6181
+ * @secure
6182
+ */
6183
+ getWalletAddresses: (_a, params) => {
6184
+ var { walletId } = _a, query = __rest(_a, ["walletId"]);
6185
+ if (params === void 0) { params = {}; }
6186
+ return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/addresses`, method: "GET", query: query, secure: true, format: "json" }, params));
6187
+ },
6159
6188
  /**
6160
6189
  * No description
6161
6190
  *
@@ -6355,23 +6384,35 @@ class Api {
6355
6384
  /**
6356
6385
  * No description
6357
6386
  *
6358
- * @tags Transactions, Transactions, ERC1404
6387
+ * @tags Transactions, Transactions
6359
6388
  * @name DetectTransferRestriction
6360
6389
  * @summary Request to detect whether there is a transfer restriction on a particular transaction
6361
6390
  * @request GET:/api/v1/transactions/detect-transfers-restrictions
6391
+ * @deprecated
6362
6392
  * @secure
6363
6393
  */
6364
6394
  detectTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/detect-transfers-restrictions`, method: "GET", query: query, secure: true, format: "json" }, params)),
6365
6395
  /**
6366
6396
  * No description
6367
6397
  *
6368
- * @tags Transactions, Transactions, ERC1404
6398
+ * @tags Transactions, Transactions
6369
6399
  * @name FetchMessageForTransferRestriction
6370
6400
  * @summary Request restriction message by providing a restriction code
6371
6401
  * @request GET:/api/v1/transactions/transfer-restriction-message
6402
+ * @deprecated
6372
6403
  * @secure
6373
6404
  */
6374
6405
  fetchMessageForTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/transfer-restriction-message`, method: "GET", query: query, secure: true, format: "json" }, params)),
6406
+ /**
6407
+ * No description
6408
+ *
6409
+ * @tags Transactions, Transactions
6410
+ * @name GetRestriction
6411
+ * @summary Request to detect whether there is a transfer restriction on a particular transaction
6412
+ * @request GET:/api/v1/transactions/restriction
6413
+ * @secure
6414
+ */
6415
+ getRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/restriction`, method: "GET", query: query, secure: true, format: "json" }, params)),
6375
6416
  /**
6376
6417
  * No description
6377
6418
  *
@@ -7346,7 +7387,22 @@ const TransactionsRoutes = {
7346
7387
  requiresAccessToken: true,
7347
7388
  },
7348
7389
  getTransactions: {
7349
- fullPath: '/query/transactions',
7390
+ fullPath: '/transactions',
7391
+ method: RequestMethod.Get,
7392
+ requiresAccessToken: true,
7393
+ },
7394
+ detectTransferRestrictions: {
7395
+ fullPath: '/transactions/detect-transfers-restrictions',
7396
+ method: RequestMethod.Get,
7397
+ requiresAccessToken: true,
7398
+ },
7399
+ transferRestrictionMessage: {
7400
+ fullPath: '/transactions/transfer-restriction-message',
7401
+ method: RequestMethod.Get,
7402
+ requiresAccessToken: true,
7403
+ },
7404
+ restriction: {
7405
+ fullPath: '/transactions/restriction',
7350
7406
  method: RequestMethod.Get,
7351
7407
  requiresAccessToken: true,
7352
7408
  },
@@ -9480,6 +9536,17 @@ class WalletService extends Base {
9480
9536
  decryptionKey: oldCredentialsKeyPair.privateKey,
9481
9537
  encryptionKey: newCredentialsKeyPair.publicKey,
9482
9538
  });
9539
+ // Guard against persisting an empty/invalid re-wrap, which would lock the user out of
9540
+ // their device private key (the one mandatory item) under the new password. The type says
9541
+ // this is always defined, but we defend against a runtime contract violation regardless.
9542
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
9543
+ if (!reWrappedDevicePrivateKey) {
9544
+ throw new WallabyError({
9545
+ message: 'Failed to re-wrap device private key during password change.',
9546
+ statusCode: 500,
9547
+ errorCode: ErrorResponseCodes.sdk_unknown_error,
9548
+ });
9549
+ }
9483
9550
  await this.localStorageService.save(LocalStorageItems.EncryptedDevicePrivateKey, reWrappedDevicePrivateKey);
9484
9551
  if (encryptedSeedPhraseString) {
9485
9552
  const parsedSeed = safeJsonParse(encryptedSeedPhraseString);
@@ -11127,6 +11194,7 @@ class Swap extends Base {
11127
11194
  });
11128
11195
  }
11129
11196
  else {
11197
+ // Unreachable in practice: prepareSwapAuth throws sdk_seed_phrase_not_found before we get here; kept as a defensive guard.
11130
11198
  throw new WallabyError({
11131
11199
  message: 'No valid seed option found on this device.',
11132
11200
  statusCode: 400,
@@ -11548,27 +11616,54 @@ class Transactions extends Base {
11548
11616
  /**
11549
11617
  *
11550
11618
  * @public
11551
- * @param {string} address
11552
- * @param {string} symbol
11553
- * @param {TokenStandard} tokenStandard an optional param used when dealing with non native assets
11554
- * @returns {Promise<{ address: string; transactions: Transaction[] }>}
11619
+ * @param {GetTransactionsParams} params - Query parameters for filtering and paginating transactions
11620
+ * @returns {GetTransactionsResponseDto} Paginated list of transactions matching the given criteria
11555
11621
  */
11556
- async getTransactions({ address, symbol, tokenStandard, }) {
11622
+ async getTransactions(params) {
11557
11623
  try {
11558
- const response = await this.request(TransactionsRoutes.getTransactions, {
11559
- payload: {
11560
- address,
11561
- tokenSymbol: symbol,
11562
- tokenType: tokenStandard,
11563
- },
11624
+ return await this.request(TransactionsRoutes.getTransactions, {
11625
+ queryParams: params,
11564
11626
  });
11565
- return response;
11566
11627
  }
11567
11628
  catch (error) {
11568
11629
  logger.error('SDK::Transactions::getTransactions::error', error);
11569
11630
  throw error;
11570
11631
  }
11571
11632
  }
11633
+ /**
11634
+ *
11635
+ * @public
11636
+ * @param {GetRestrictionParams} params - Parameters to detect transfer restrictions (addresses, asset, value)
11637
+ * - {string} fromAddress
11638
+ * - {string} toAddress
11639
+ * - {string} amount
11640
+ * - [string] assetId
11641
+ * - [string] contractAddress
11642
+ * - [BlockchainName] blockchainName
11643
+ * @returns {Promise<DetectRestrictionResponseDto>}
11644
+ * Detection result; when transfer is blocked, also includes the human-readable restriction message and a boolean canTransfer
11645
+ */
11646
+ async getRestriction(params) {
11647
+ try {
11648
+ const hasAssetId = Boolean(params.assetId);
11649
+ const hasContractAndChain = Boolean(params.contractAddress && params.blockchainName);
11650
+ if (!hasAssetId && !hasContractAndChain) {
11651
+ throw new WallabyError({
11652
+ message: 'Either assetId or both contractAddress and blockchainName must be provided.',
11653
+ statusCode: 400,
11654
+ errorCode: ErrorResponseCodes.sdk_missing_parameter,
11655
+ });
11656
+ }
11657
+ const restrictionData = await this.request(TransactionsRoutes.restriction, {
11658
+ queryParams: Object.assign(Object.assign(Object.assign({ fromAddress: params.fromAddress, toAddress: params.toAddress, amount: params.amount }, (params.assetId && { assetId: params.assetId })), (params.contractAddress && { contractAddress: params.contractAddress })), (params.blockchainName && { blockchainName: params.blockchainName })),
11659
+ });
11660
+ return restrictionData;
11661
+ }
11662
+ catch (error) {
11663
+ logger.error('SDK::Transactions::getRestriction::error', error);
11664
+ throw error;
11665
+ }
11666
+ }
11572
11667
  /**
11573
11668
  *
11574
11669
  * @public
@@ -11903,6 +11998,12 @@ class Transactions extends Base {
11903
11998
  });
11904
11999
  }
11905
12000
  }
12001
+ __decorate([
12002
+ WithLock('transaction-restriction-message'),
12003
+ __metadata("design:type", Function),
12004
+ __metadata("design:paramtypes", [Object]),
12005
+ __metadata("design:returntype", Promise)
12006
+ ], Transactions.prototype, "getRestriction", null);
11906
12007
  __decorate([
11907
12008
  WithLock('transfer'),
11908
12009
  __metadata("design:type", Function),