wallaby-cash 1.7.4 → 1.7.7

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
@@ -5,6 +5,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
5
5
  const ethCryptoJs = require('eth-crypto-js');
6
6
  const axios = require('axios');
7
7
  const cryptoJs = require('crypto-js');
8
+ const jwtDecode = require('jwt-decode');
8
9
  const uuid = require('uuid');
9
10
 
10
11
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
@@ -130,6 +131,9 @@ exports.BlockchainSlip44 = void 0;
130
131
  BlockchainSlip44[BlockchainSlip44["ALGO"] = 283] = "ALGO";
131
132
  BlockchainSlip44[BlockchainSlip44["AVAX"] = 9000] = "AVAX";
132
133
  BlockchainSlip44[BlockchainSlip44["MATIC"] = 966] = "MATIC";
134
+ BlockchainSlip44[BlockchainSlip44["BSC"] = 519] = "BSC";
135
+ BlockchainSlip44[BlockchainSlip44["BASE"] = 8453] = "BASE";
136
+ BlockchainSlip44[BlockchainSlip44["SUI"] = 784] = "SUI";
133
137
  })(exports.BlockchainSlip44 || (exports.BlockchainSlip44 = {}));
134
138
  exports.BlockchainName = void 0;
135
139
  (function (BlockchainName) {
@@ -139,6 +143,8 @@ exports.BlockchainName = void 0;
139
143
  BlockchainName["Ethereum"] = "ETHEREUM";
140
144
  BlockchainName["Polygon"] = "POLYGON";
141
145
  BlockchainName["Bsc"] = "BSC";
146
+ BlockchainName["Base"] = "BASE";
147
+ BlockchainName["Sui"] = "SUI";
142
148
  })(exports.BlockchainName || (exports.BlockchainName = {}));
143
149
  exports.RequestMethod = void 0;
144
150
  (function (RequestMethod) {
@@ -4485,6 +4491,7 @@ var defaultEnvironment = (_a = browser$1$1.env.NODE_ENV) !== null && _a !== void
4485
4491
  * Please pass the network value in the WallabyConfigOptions object to override it for production-mainnet.
4486
4492
  */
4487
4493
  var defaultNetwork = 'testnet';
4494
+ var isTest = browser$1$1.env.NODE_ENV === 'test';
4488
4495
 
4489
4496
  var StorageService = /** @class */ (function () {
4490
4497
  function StorageService(_a) {
@@ -4936,6 +4943,32 @@ function objectToQueryParams(obj) {
4936
4943
  return params.toString();
4937
4944
  }
4938
4945
 
4946
+ /**
4947
+ * Checks if a given JWT has expired.
4948
+ *
4949
+ * @param jwt - The JWT string to check. If null, the function will return true.
4950
+ * @returns `true` if the JWT has expired or is null, otherwise `false`.
4951
+ */
4952
+ function jwtHasExpired(jwt) {
4953
+ if (!jwt) {
4954
+ return true;
4955
+ }
4956
+ return millisecondsToJWTTimeout(jwt) <= 0;
4957
+ }
4958
+ /**
4959
+ * Calculates the remaining time in milliseconds until a given JWT expires.
4960
+ *
4961
+ * @param jwt - The JWT string to decode and check.
4962
+ * @returns The number of milliseconds until the JWT expires. If the JWT has already expired, the returned value will be less than or equal to 0.
4963
+ */
4964
+ function millisecondsToJWTTimeout(jwt) {
4965
+ var jwtDecoded = jwtDecode.jwtDecode(jwt);
4966
+ var jwtExpirationTimeSeconds = jwtDecoded.exp;
4967
+ var jwtExpirationTimeMilliseconds = (jwtExpirationTimeSeconds !== null && jwtExpirationTimeSeconds !== void 0 ? jwtExpirationTimeSeconds : 0) * 1000;
4968
+ var timeNowMilliseconds = Date.now();
4969
+ return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
4970
+ }
4971
+
4939
4972
  var Base = /** @class */ (function () {
4940
4973
  function Base(config) {
4941
4974
  var _a;
@@ -5120,6 +5153,9 @@ var Base = /** @class */ (function () {
5120
5153
  return __generator(this, function (_f) {
5121
5154
  switch (_f.label) {
5122
5155
  case 0:
5156
+ if (!isTest && jwtHasExpired(this.clientAuthToken)) {
5157
+ throw new Error('Auth token has expired - blocking API call.');
5158
+ }
5123
5159
  _d = {
5124
5160
  'Content-Type': 'application/json',
5125
5161
  'x-api-key': this.settings.apiKey