wallaby-cash 3.2.0 → 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/base.d.ts +8 -1
- package/dist/generated/api.d.ts +689 -143
- package/dist/helpers/auth-refresh-error.d.ts +4 -0
- package/dist/helpers/dedupe-manager.service.d.ts +18 -0
- package/dist/index.cjs.js +392 -90
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +392 -90
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +392 -90
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.service.d.ts +7 -0
- package/dist/lib/transactions/index.d.ts +19 -13
- package/dist/lib/utils/is-jwt-expired.d.ts +8 -0
- package/dist/lib/wallet/wallet-handlers.service.d.ts +4 -2
- package/dist/package.json +14 -10
- package/dist/routes/transactions.d.ts +15 -0
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/error-response-codes.d.ts +8 -0
- package/dist/types/wallet.d.ts +3 -3
- package/package.json +11 -7
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ var TransportEnum;
|
|
|
82
82
|
*/
|
|
83
83
|
class WallabyError extends Error {
|
|
84
84
|
constructor(errorPayload) {
|
|
85
|
+
var _a;
|
|
85
86
|
const { message, statusCode, errorCode, data, cause, onError } = errorPayload;
|
|
86
87
|
super(message);
|
|
87
88
|
this.name = 'WallabyError';
|
|
@@ -90,7 +91,17 @@ class WallabyError extends Error {
|
|
|
90
91
|
this.cause = cause;
|
|
91
92
|
this.onError = onError;
|
|
92
93
|
this.data = data;
|
|
93
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Preserve prototype chain when extending built-ins across transpilation targets.
|
|
96
|
+
* Object.setPrototypeOf(this, WallabyError.prototype) forces the prototype to WallabyError even when a consumer subclasses WallabyError,
|
|
97
|
+
* breaking the prototype chain for derived errors (and potentially instanceof DerivedWallabyError).
|
|
98
|
+
* Use new.target.prototype (and new.target for stack capture) so the fix works for subclasses too.
|
|
99
|
+
*
|
|
100
|
+
* Use optional chaining since Error.captureStackTrace isn't available in all runtimes (e.g., Safari).
|
|
101
|
+
*/
|
|
102
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
104
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, new.target);
|
|
94
105
|
}
|
|
95
106
|
static isWallabyError(error) {
|
|
96
107
|
return error instanceof WallabyError;
|
|
@@ -321,6 +332,12 @@ var ErrorResponseCodes;
|
|
|
321
332
|
ErrorResponseCodes["auth_api_jwt_invalid"] = "auth_api_jwt_invalid";
|
|
322
333
|
ErrorResponseCodes["auth_api_jwt_not_active"] = "auth_api_jwt_not_active";
|
|
323
334
|
ErrorResponseCodes["auth_api_jwt_not_provided"] = "auth_api_jwt_not_provided";
|
|
335
|
+
ErrorResponseCodes["auth_api_jwt_expired"] = "auth_api_jwt_expired";
|
|
336
|
+
ErrorResponseCodes["auth_api_unauthorized"] = "auth_api_unauthorized";
|
|
337
|
+
// Auth Refresh Token
|
|
338
|
+
ErrorResponseCodes["auth_refresh_token_not_found"] = "auth_refresh_token_not_found";
|
|
339
|
+
ErrorResponseCodes["auth_refresh_token_expired"] = "auth_refresh_token_expired";
|
|
340
|
+
ErrorResponseCodes["auth_refresh_token_reuse_detected"] = "auth_refresh_token_reuse_detected";
|
|
324
341
|
// Auth Client JWT
|
|
325
342
|
ErrorResponseCodes["auth_client_jwt_invalid"] = "auth_client_jwt_invalid";
|
|
326
343
|
ErrorResponseCodes["auth_client_jwt_missing_external_id_payload"] = "auth_client_jwt_missing_external_id_payload";
|
|
@@ -328,6 +345,8 @@ var ErrorResponseCodes;
|
|
|
328
345
|
ErrorResponseCodes["auth_client_jwt_external_id_not_match"] = "auth_client_jwt_external_id_not_match";
|
|
329
346
|
ErrorResponseCodes["auth_client_jwt_expired"] = "auth_client_jwt_expired";
|
|
330
347
|
ErrorResponseCodes["auth_client_jwt_not_provided"] = "auth_client_jwt_not_provided";
|
|
348
|
+
ErrorResponseCodes["auth_client_jwt_invalid_auth_type"] = "auth_client_jwt_invalid_auth_type";
|
|
349
|
+
ErrorResponseCodes["auth_client_jwt_invalid_passkey"] = "auth_client_jwt_invalid_passkey";
|
|
331
350
|
// Auth Client Transport keys
|
|
332
351
|
ErrorResponseCodes["auth_client_pub_key_and_message_not_match"] = "auth_client_pub_key_and_message_not_match";
|
|
333
352
|
ErrorResponseCodes["auth_client_pub_key_and_message_expired"] = "auth_client_pub_key_and_message_expired";
|
|
@@ -361,6 +380,7 @@ var ErrorResponseCodes;
|
|
|
361
380
|
ErrorResponseCodes["sdk_seed_phrase_not_found"] = "sdk_seed_phrase_not_found";
|
|
362
381
|
ErrorResponseCodes["sdk_private_key_decryption_failed"] = "sdk_private_key_decryption_failed";
|
|
363
382
|
ErrorResponseCodes["sdk_private_key_not_found"] = "sdk_private_key_not_found";
|
|
383
|
+
ErrorResponseCodes["sdk_refresh_token_missing"] = "sdk_refresh_token_missing";
|
|
364
384
|
ErrorResponseCodes["sdk_missing_parameter"] = "sdk_missing_parameter";
|
|
365
385
|
ErrorResponseCodes["sdk_invalid_parameter"] = "sdk_invalid_parameter";
|
|
366
386
|
ErrorResponseCodes["sdk_wrong_password"] = "sdk_wrong_password";
|
|
@@ -574,7 +594,7 @@ const env = {
|
|
|
574
594
|
isNative: false,
|
|
575
595
|
isWeb,
|
|
576
596
|
};
|
|
577
|
-
const currentPackageVersion = "3.
|
|
597
|
+
const currentPackageVersion = "3.3.0" ;
|
|
578
598
|
|
|
579
599
|
/**
|
|
580
600
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4412,14 +4432,19 @@ class Cipher {
|
|
|
4412
4432
|
return AES.encrypt(typeof data === 'string' ? data : JSON.stringify(data), this.getMasterKey().key).toString();
|
|
4413
4433
|
}
|
|
4414
4434
|
decryptWithMasterKey({ cipherText }) {
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
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
|
+
}
|
|
4418
4440
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
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);
|
|
4421
4444
|
return undefined;
|
|
4422
4445
|
}
|
|
4446
|
+
logger.error('Decryption failed with master key');
|
|
4447
|
+
return undefined;
|
|
4423
4448
|
}
|
|
4424
4449
|
/**
|
|
4425
4450
|
* Validate that a public key is the correct length and format.
|
|
@@ -5191,6 +5216,19 @@ function userIsMfaVerified(jwt) {
|
|
|
5191
5216
|
const jwtDecoded = jwtDecode(jwt);
|
|
5192
5217
|
return jwtDecoded.mfaVerified;
|
|
5193
5218
|
}
|
|
5219
|
+
/**
|
|
5220
|
+
* Checks if a given JWT will expire within the given threshold.
|
|
5221
|
+
*
|
|
5222
|
+
* @param jwt - The JWT string to check. If null, the function returns false.
|
|
5223
|
+
* @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
|
|
5224
|
+
* @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
|
|
5225
|
+
*/
|
|
5226
|
+
function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
5227
|
+
if (!jwt) {
|
|
5228
|
+
return false;
|
|
5229
|
+
}
|
|
5230
|
+
return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
|
|
5231
|
+
}
|
|
5194
5232
|
/**
|
|
5195
5233
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
5196
5234
|
*
|
|
@@ -5205,6 +5243,49 @@ function millisecondsToJWTTimeout(jwt) {
|
|
|
5205
5243
|
return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
|
|
5206
5244
|
}
|
|
5207
5245
|
|
|
5246
|
+
const AuthRoutes = {
|
|
5247
|
+
signatureMessage: {
|
|
5248
|
+
fullPath: '/auth/signature-message',
|
|
5249
|
+
method: RequestMethod.Post,
|
|
5250
|
+
requiresAccessToken: false,
|
|
5251
|
+
},
|
|
5252
|
+
signIn: {
|
|
5253
|
+
fullPath: '/auth/sign-in',
|
|
5254
|
+
method: RequestMethod.Post,
|
|
5255
|
+
requiresAccessToken: false,
|
|
5256
|
+
},
|
|
5257
|
+
signUp: {
|
|
5258
|
+
fullPath: '/auth/sign-up',
|
|
5259
|
+
method: RequestMethod.Post,
|
|
5260
|
+
requiresAccessToken: false,
|
|
5261
|
+
},
|
|
5262
|
+
refreshAccessToken: {
|
|
5263
|
+
fullPath: '/auth/refresh-access-token',
|
|
5264
|
+
method: RequestMethod.Post,
|
|
5265
|
+
requiresAccessToken: true,
|
|
5266
|
+
},
|
|
5267
|
+
clientAuthPubKey: {
|
|
5268
|
+
fullPath: 'auth/client-auth-pubkey',
|
|
5269
|
+
method: RequestMethod.Put,
|
|
5270
|
+
requiresAccessToken: true,
|
|
5271
|
+
},
|
|
5272
|
+
wallabyAuthPublicKey: {
|
|
5273
|
+
fullPath: '/auth/wallaby-auth-pubkey',
|
|
5274
|
+
method: RequestMethod.Get,
|
|
5275
|
+
requiresAccessToken: true,
|
|
5276
|
+
},
|
|
5277
|
+
getUserSalt: {
|
|
5278
|
+
fullPath: '/users/salt',
|
|
5279
|
+
method: RequestMethod.Get,
|
|
5280
|
+
requiresAccessToken: true,
|
|
5281
|
+
},
|
|
5282
|
+
getPasskeyCredentials: {
|
|
5283
|
+
fullPath: '/auth/passkey-credentials',
|
|
5284
|
+
method: RequestMethod.Get,
|
|
5285
|
+
requiresAccessToken: true,
|
|
5286
|
+
},
|
|
5287
|
+
};
|
|
5288
|
+
|
|
5208
5289
|
class LockManagerService {
|
|
5209
5290
|
constructor() {
|
|
5210
5291
|
this.activeLocks = new Set();
|
|
@@ -5248,6 +5329,43 @@ class LockManagerService {
|
|
|
5248
5329
|
}
|
|
5249
5330
|
}
|
|
5250
5331
|
|
|
5332
|
+
class DedupeManagerService {
|
|
5333
|
+
constructor() {
|
|
5334
|
+
this.inFlightOperations = new Map();
|
|
5335
|
+
}
|
|
5336
|
+
/**
|
|
5337
|
+
* Executes an operation once per key while returning the same in-flight promise
|
|
5338
|
+
* to all concurrent callers.
|
|
5339
|
+
* @param key - Unique identifier for dedupe scope.
|
|
5340
|
+
* @param operation - The async operation to execute.
|
|
5341
|
+
*/
|
|
5342
|
+
withDedupe(key, operation) {
|
|
5343
|
+
const existingOperation = this.inFlightOperations.get(key);
|
|
5344
|
+
if (existingOperation) {
|
|
5345
|
+
return existingOperation;
|
|
5346
|
+
}
|
|
5347
|
+
const operationPromise = Promise.resolve()
|
|
5348
|
+
.then(operation)
|
|
5349
|
+
.finally(() => {
|
|
5350
|
+
this.inFlightOperations.delete(key);
|
|
5351
|
+
});
|
|
5352
|
+
this.inFlightOperations.set(key, operationPromise);
|
|
5353
|
+
return operationPromise;
|
|
5354
|
+
}
|
|
5355
|
+
/**
|
|
5356
|
+
* Check if a specific operation is currently in flight.
|
|
5357
|
+
*/
|
|
5358
|
+
isInFlight(key) {
|
|
5359
|
+
return this.inFlightOperations.has(key);
|
|
5360
|
+
}
|
|
5361
|
+
/**
|
|
5362
|
+
* Clear all tracked in-flight operations (primarily for tests/cleanup).
|
|
5363
|
+
*/
|
|
5364
|
+
clearAll() {
|
|
5365
|
+
this.inFlightOperations.clear();
|
|
5366
|
+
}
|
|
5367
|
+
}
|
|
5368
|
+
|
|
5251
5369
|
function isValidInput(input) {
|
|
5252
5370
|
// Allow alphanumeric characters, hyphens, and underscores.
|
|
5253
5371
|
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
@@ -5545,6 +5663,16 @@ class Api {
|
|
|
5545
5663
|
* @secure
|
|
5546
5664
|
*/
|
|
5547
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)),
|
|
5548
5676
|
/**
|
|
5549
5677
|
* No description
|
|
5550
5678
|
*
|
|
@@ -6043,6 +6171,20 @@ class Api {
|
|
|
6043
6171
|
if (params === void 0) { params = {}; }
|
|
6044
6172
|
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/assets`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6045
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
|
+
},
|
|
6046
6188
|
/**
|
|
6047
6189
|
* No description
|
|
6048
6190
|
*
|
|
@@ -6242,23 +6384,35 @@ class Api {
|
|
|
6242
6384
|
/**
|
|
6243
6385
|
* No description
|
|
6244
6386
|
*
|
|
6245
|
-
* @tags Transactions, Transactions
|
|
6387
|
+
* @tags Transactions, Transactions
|
|
6246
6388
|
* @name DetectTransferRestriction
|
|
6247
6389
|
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6248
6390
|
* @request GET:/api/v1/transactions/detect-transfers-restrictions
|
|
6391
|
+
* @deprecated
|
|
6249
6392
|
* @secure
|
|
6250
6393
|
*/
|
|
6251
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)),
|
|
6252
6395
|
/**
|
|
6253
6396
|
* No description
|
|
6254
6397
|
*
|
|
6255
|
-
* @tags Transactions, Transactions
|
|
6398
|
+
* @tags Transactions, Transactions
|
|
6256
6399
|
* @name FetchMessageForTransferRestriction
|
|
6257
6400
|
* @summary Request restriction message by providing a restriction code
|
|
6258
6401
|
* @request GET:/api/v1/transactions/transfer-restriction-message
|
|
6402
|
+
* @deprecated
|
|
6259
6403
|
* @secure
|
|
6260
6404
|
*/
|
|
6261
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)),
|
|
6262
6416
|
/**
|
|
6263
6417
|
* No description
|
|
6264
6418
|
*
|
|
@@ -6686,6 +6840,48 @@ function objectToQueryParams(obj) {
|
|
|
6686
6840
|
return params.toString();
|
|
6687
6841
|
}
|
|
6688
6842
|
|
|
6843
|
+
const refreshableAuth401ErrorCodes = new Set([
|
|
6844
|
+
ErrorResponseCodes.auth_api_jwt_invalid,
|
|
6845
|
+
ErrorResponseCodes.auth_api_jwt_not_active,
|
|
6846
|
+
ErrorResponseCodes.auth_api_jwt_not_provided,
|
|
6847
|
+
ErrorResponseCodes.auth_api_jwt_expired,
|
|
6848
|
+
ErrorResponseCodes.auth_api_unauthorized,
|
|
6849
|
+
]);
|
|
6850
|
+
const clearTokensOnRefreshFailureErrorCodes = new Set([
|
|
6851
|
+
ErrorResponseCodes.auth_refresh_token_not_found,
|
|
6852
|
+
ErrorResponseCodes.auth_refresh_token_expired,
|
|
6853
|
+
ErrorResponseCodes.auth_refresh_token_reuse_detected,
|
|
6854
|
+
]);
|
|
6855
|
+
function extractErrorStatus(error) {
|
|
6856
|
+
var _a, _b, _c, _d, _e;
|
|
6857
|
+
return (_d = (_b = (_a = error === null || error === void 0 ? void 0 : error.status) !== null && _a !== void 0 ? _a : error === null || error === void 0 ? void 0 : error.statusCode) !== null && _b !== void 0 ? _b : (_c = error === null || error === void 0 ? void 0 : error.error) === null || _c === void 0 ? void 0 : _c.statusCode) !== null && _d !== void 0 ? _d : (_e = error === null || error === void 0 ? void 0 : error.data) === null || _e === void 0 ? void 0 : _e.statusCode;
|
|
6858
|
+
}
|
|
6859
|
+
function extractErrorCode(error) {
|
|
6860
|
+
var _a, _b, _c, _d;
|
|
6861
|
+
return (_c = (_a = error === null || error === void 0 ? void 0 : error.errorCode) !== null && _a !== void 0 ? _a : (_b = error === null || error === void 0 ? void 0 : error.error) === null || _b === void 0 ? void 0 : _b.errorCode) !== null && _c !== void 0 ? _c : (_d = error === null || error === void 0 ? void 0 : error.data) === null || _d === void 0 ? void 0 : _d.errorCode;
|
|
6862
|
+
}
|
|
6863
|
+
function shouldAttemptTokenRefresh(error) {
|
|
6864
|
+
const status = extractErrorStatus(error);
|
|
6865
|
+
if (status !== 401) {
|
|
6866
|
+
return false;
|
|
6867
|
+
}
|
|
6868
|
+
const errorCode = extractErrorCode(error);
|
|
6869
|
+
if (!errorCode) {
|
|
6870
|
+
// Backward compatibility: some endpoints may not provide explicit errorCode.
|
|
6871
|
+
return true;
|
|
6872
|
+
}
|
|
6873
|
+
return refreshableAuth401ErrorCodes.has(errorCode);
|
|
6874
|
+
}
|
|
6875
|
+
function shouldClearTokensAfterRefreshFailure(error) {
|
|
6876
|
+
const status = extractErrorStatus(error);
|
|
6877
|
+
const errorCode = extractErrorCode(error);
|
|
6878
|
+
// Any 401 clears tokens (preserves prior behavior). The error-code set additionally
|
|
6879
|
+
// covers refresh-token failures that arrive with a non-401 status (e.g. 400/403).
|
|
6880
|
+
return status === 401 || (!!errorCode && clearTokensOnRefreshFailureErrorCodes.has(errorCode));
|
|
6881
|
+
}
|
|
6882
|
+
|
|
6883
|
+
// Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
|
|
6884
|
+
const refreshDedupeManager = new DedupeManagerService();
|
|
6689
6885
|
class Base {
|
|
6690
6886
|
constructor(config) {
|
|
6691
6887
|
var _a, _b;
|
|
@@ -6716,35 +6912,45 @@ class Base {
|
|
|
6716
6912
|
});
|
|
6717
6913
|
/**
|
|
6718
6914
|
* This intercepts all API responses and transforms errors into WallabyError format.
|
|
6915
|
+
* On a 401, it performs a single token refresh then retries (reactive guard).
|
|
6719
6916
|
*/
|
|
6720
6917
|
const originalRequest = httpClient.request.bind(httpClient);
|
|
6721
6918
|
httpClient.request = async (params) => {
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6919
|
+
const attemptRequest = async (retried) => {
|
|
6920
|
+
try {
|
|
6921
|
+
return await originalRequest(params);
|
|
6922
|
+
}
|
|
6923
|
+
catch (error) {
|
|
6924
|
+
// Reactive 401 handling for the generated client: refresh once and retry
|
|
6925
|
+
if (!retried && shouldAttemptTokenRefresh(error)) {
|
|
6926
|
+
await this._performTokenRefresh();
|
|
6927
|
+
// securityWorker will re-fetch the new access token on retry
|
|
6928
|
+
return attemptRequest(true);
|
|
6929
|
+
}
|
|
6930
|
+
// Transform the generated API error format into WallabyError
|
|
6931
|
+
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6932
|
+
const apiError = error.error;
|
|
6933
|
+
throw new WallabyError({
|
|
6934
|
+
message: apiError.message || 'API request failed',
|
|
6935
|
+
statusCode: apiError.statusCode || 500,
|
|
6936
|
+
errorCode: apiError.errorCode,
|
|
6937
|
+
data: apiError,
|
|
6938
|
+
});
|
|
6939
|
+
}
|
|
6940
|
+
// Re-throw if already a WallabyError
|
|
6941
|
+
if (error instanceof WallabyError) {
|
|
6942
|
+
throw error;
|
|
6943
|
+
}
|
|
6944
|
+
// Wrap any other errors
|
|
6729
6945
|
throw new WallabyError({
|
|
6730
|
-
message:
|
|
6731
|
-
statusCode:
|
|
6732
|
-
errorCode:
|
|
6733
|
-
data:
|
|
6946
|
+
message: error.message || 'Unknown error occurred',
|
|
6947
|
+
statusCode: error.statusCode || 500,
|
|
6948
|
+
errorCode: error.errorCode,
|
|
6949
|
+
data: error,
|
|
6734
6950
|
});
|
|
6735
6951
|
}
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
throw error;
|
|
6739
|
-
}
|
|
6740
|
-
// Wrap any other errors
|
|
6741
|
-
throw new WallabyError({
|
|
6742
|
-
message: error.message || 'Unknown error occurred',
|
|
6743
|
-
statusCode: error.statusCode || 500,
|
|
6744
|
-
errorCode: error.errorCode,
|
|
6745
|
-
data: error,
|
|
6746
|
-
});
|
|
6747
|
-
}
|
|
6952
|
+
};
|
|
6953
|
+
return attemptRequest(false);
|
|
6748
6954
|
};
|
|
6749
6955
|
this.api = new Api(httpClient);
|
|
6750
6956
|
this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (_b = this.options) === null || _b === void 0 ? void 0 : _b.headers));
|
|
@@ -6825,15 +7031,51 @@ class Base {
|
|
|
6825
7031
|
environment: this.settings.environment,
|
|
6826
7032
|
});
|
|
6827
7033
|
}
|
|
7034
|
+
/**
|
|
7035
|
+
* Fetches a new access/refresh token pair using the stored refresh token.
|
|
7036
|
+
* All concurrent callers share the same in-flight promise via the module-level
|
|
7037
|
+
* `refreshDedupeManager` so only one network request is issued per user/environment scope.
|
|
7038
|
+
*/
|
|
7039
|
+
async _performTokenRefresh() {
|
|
7040
|
+
const refreshDedupeKey = `refresh:${this.userId}:${this.settings.environment}:${this.settings.network}`;
|
|
7041
|
+
await refreshDedupeManager.withDedupe(refreshDedupeKey, async () => {
|
|
7042
|
+
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
7043
|
+
if (!refreshToken) {
|
|
7044
|
+
return;
|
|
7045
|
+
}
|
|
7046
|
+
try {
|
|
7047
|
+
const response = await this.request(AuthRoutes.refreshAccessToken, {
|
|
7048
|
+
payload: { refreshToken },
|
|
7049
|
+
});
|
|
7050
|
+
await this.localStorageService.save(LocalStorageItems.AccessToken, response.accessToken);
|
|
7051
|
+
await this.localStorageService.save(LocalStorageItems.RefreshToken, response.refreshToken);
|
|
7052
|
+
}
|
|
7053
|
+
catch (error) {
|
|
7054
|
+
if (shouldClearTokensAfterRefreshFailure(error)) {
|
|
7055
|
+
await this.localStorageService.delete(LocalStorageItems.AccessToken);
|
|
7056
|
+
await this.localStorageService.delete(LocalStorageItems.RefreshToken);
|
|
7057
|
+
}
|
|
7058
|
+
throw error;
|
|
7059
|
+
}
|
|
7060
|
+
});
|
|
7061
|
+
}
|
|
6828
7062
|
/**
|
|
6829
7063
|
* Main request method for making API calls to the Wallaby API.
|
|
6830
7064
|
* @param route - Route configuration object containing the endpoint path and HTTP method
|
|
6831
7065
|
* @param options - Optional request options including payload and query parameters
|
|
7066
|
+
* @param retried - Internal flag; set to true when retrying after a 401 to prevent loops
|
|
6832
7067
|
* @returns Promise resolving to the typed response data
|
|
6833
7068
|
* @throws Error if the API returns an error response or network failure occurs
|
|
6834
7069
|
*/
|
|
6835
|
-
async request(route, options) {
|
|
7070
|
+
async request(route, options, retried = false) {
|
|
6836
7071
|
var _a;
|
|
7072
|
+
// Proactive token refresh: if access token is near expiry, refresh before making the request
|
|
7073
|
+
if (route !== AuthRoutes.refreshAccessToken && !retried) {
|
|
7074
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7075
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7076
|
+
await this._performTokenRefresh();
|
|
7077
|
+
}
|
|
7078
|
+
}
|
|
6837
7079
|
const path = typeof route.fullPath === 'string' ? route.fullPath : route.fullPath(options === null || options === void 0 ? void 0 : options.payload);
|
|
6838
7080
|
// Add query parameters to the path if provided
|
|
6839
7081
|
let finalPath = path;
|
|
@@ -6887,6 +7129,11 @@ class Base {
|
|
|
6887
7129
|
return data;
|
|
6888
7130
|
}
|
|
6889
7131
|
catch (error) {
|
|
7132
|
+
// Reactive token refresh: on 401, refresh once and retry the original request
|
|
7133
|
+
if (!retried && route !== AuthRoutes.refreshAccessToken && shouldAttemptTokenRefresh(error)) {
|
|
7134
|
+
await this._performTokenRefresh();
|
|
7135
|
+
return this.request(route, options, true);
|
|
7136
|
+
}
|
|
6890
7137
|
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6891
7138
|
logger.error('SDK::Base::handleApiCall::API Error', { error });
|
|
6892
7139
|
const apiError = error.error;
|
|
@@ -6939,6 +7186,16 @@ class Base {
|
|
|
6939
7186
|
return headers;
|
|
6940
7187
|
}
|
|
6941
7188
|
async securityWorker(securityData) {
|
|
7189
|
+
// Proactive token refresh before building headers for the generated client
|
|
7190
|
+
try {
|
|
7191
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7192
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7193
|
+
await this._performTokenRefresh();
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
7196
|
+
catch (_a) {
|
|
7197
|
+
// Best-effort proactive refresh; proceed even if it fails
|
|
7198
|
+
}
|
|
6942
7199
|
// Start with the security data that contains API key and JWT
|
|
6943
7200
|
const headers = Object.assign({ 'Content-Type': 'application/json' }, (securityData || {}));
|
|
6944
7201
|
// Add access token if available
|
|
@@ -6948,7 +7205,7 @@ class Base {
|
|
|
6948
7205
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
6949
7206
|
}
|
|
6950
7207
|
}
|
|
6951
|
-
catch (
|
|
7208
|
+
catch (_b) {
|
|
6952
7209
|
// Access token is optional, continue without it
|
|
6953
7210
|
}
|
|
6954
7211
|
return {
|
|
@@ -7075,49 +7332,6 @@ const WalletRoutes = {
|
|
|
7075
7332
|
},
|
|
7076
7333
|
};
|
|
7077
7334
|
|
|
7078
|
-
const AuthRoutes = {
|
|
7079
|
-
signatureMessage: {
|
|
7080
|
-
fullPath: '/auth/signature-message',
|
|
7081
|
-
method: RequestMethod.Post,
|
|
7082
|
-
requiresAccessToken: false,
|
|
7083
|
-
},
|
|
7084
|
-
signIn: {
|
|
7085
|
-
fullPath: '/auth/sign-in',
|
|
7086
|
-
method: RequestMethod.Post,
|
|
7087
|
-
requiresAccessToken: false,
|
|
7088
|
-
},
|
|
7089
|
-
signUp: {
|
|
7090
|
-
fullPath: '/auth/sign-up',
|
|
7091
|
-
method: RequestMethod.Post,
|
|
7092
|
-
requiresAccessToken: false,
|
|
7093
|
-
},
|
|
7094
|
-
refreshAccessToken: {
|
|
7095
|
-
fullPath: '/auth/refresh-access-token',
|
|
7096
|
-
method: RequestMethod.Post,
|
|
7097
|
-
requiresAccessToken: true,
|
|
7098
|
-
},
|
|
7099
|
-
clientAuthPubKey: {
|
|
7100
|
-
fullPath: 'auth/client-auth-pubkey',
|
|
7101
|
-
method: RequestMethod.Put,
|
|
7102
|
-
requiresAccessToken: true,
|
|
7103
|
-
},
|
|
7104
|
-
wallabyAuthPublicKey: {
|
|
7105
|
-
fullPath: '/auth/wallaby-auth-pubkey',
|
|
7106
|
-
method: RequestMethod.Get,
|
|
7107
|
-
requiresAccessToken: true,
|
|
7108
|
-
},
|
|
7109
|
-
getUserSalt: {
|
|
7110
|
-
fullPath: '/users/salt',
|
|
7111
|
-
method: RequestMethod.Get,
|
|
7112
|
-
requiresAccessToken: true,
|
|
7113
|
-
},
|
|
7114
|
-
getPasskeyCredentials: {
|
|
7115
|
-
fullPath: '/auth/passkey-credentials',
|
|
7116
|
-
method: RequestMethod.Get,
|
|
7117
|
-
requiresAccessToken: true,
|
|
7118
|
-
},
|
|
7119
|
-
};
|
|
7120
|
-
|
|
7121
7335
|
const SystemRoutes = {
|
|
7122
7336
|
getSupportedBlockchains: {
|
|
7123
7337
|
fullPath: '/chains',
|
|
@@ -7173,7 +7387,22 @@ const TransactionsRoutes = {
|
|
|
7173
7387
|
requiresAccessToken: true,
|
|
7174
7388
|
},
|
|
7175
7389
|
getTransactions: {
|
|
7176
|
-
fullPath: '/
|
|
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',
|
|
7177
7406
|
method: RequestMethod.Get,
|
|
7178
7407
|
requiresAccessToken: true,
|
|
7179
7408
|
},
|
|
@@ -8007,6 +8236,33 @@ class AuthService extends Base {
|
|
|
8007
8236
|
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
8008
8237
|
return (!!accessToken && !jwtHasExpired(accessToken)) || !!refreshToken;
|
|
8009
8238
|
}
|
|
8239
|
+
/**
|
|
8240
|
+
* @description Refreshes auth tokens using the stored refresh token.
|
|
8241
|
+
*/
|
|
8242
|
+
async refreshAuthTokens() {
|
|
8243
|
+
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
8244
|
+
if (!refreshToken) {
|
|
8245
|
+
throw new WallabyError({
|
|
8246
|
+
message: 'Refresh token is required',
|
|
8247
|
+
statusCode: 401,
|
|
8248
|
+
errorCode: ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8249
|
+
});
|
|
8250
|
+
}
|
|
8251
|
+
await this._performTokenRefresh();
|
|
8252
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
8253
|
+
const newRefreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
8254
|
+
if (!accessToken || !newRefreshToken) {
|
|
8255
|
+
throw new WallabyError({
|
|
8256
|
+
message: 'Token refresh failed: tokens not present in storage after refresh',
|
|
8257
|
+
statusCode: 401,
|
|
8258
|
+
errorCode: ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8259
|
+
});
|
|
8260
|
+
}
|
|
8261
|
+
return {
|
|
8262
|
+
accessToken,
|
|
8263
|
+
refreshToken: newRefreshToken,
|
|
8264
|
+
};
|
|
8265
|
+
}
|
|
8010
8266
|
/**
|
|
8011
8267
|
* @description Validates the user's password by decrypting the stored private key.
|
|
8012
8268
|
* @returns { boolean } Returns true if the password is valid, false otherwise.
|
|
@@ -9280,6 +9536,17 @@ class WalletService extends Base {
|
|
|
9280
9536
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9281
9537
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9282
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
|
+
}
|
|
9283
9550
|
await this.localStorageService.save(LocalStorageItems.EncryptedDevicePrivateKey, reWrappedDevicePrivateKey);
|
|
9284
9551
|
if (encryptedSeedPhraseString) {
|
|
9285
9552
|
const parsedSeed = safeJsonParse(encryptedSeedPhraseString);
|
|
@@ -10042,6 +10309,7 @@ class WalletService extends Base {
|
|
|
10042
10309
|
storeSeedPhrase: false,
|
|
10043
10310
|
returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
10044
10311
|
walletId: input.walletId,
|
|
10312
|
+
reference: v4(),
|
|
10045
10313
|
keyShareOptions: {
|
|
10046
10314
|
threshold: 2,
|
|
10047
10315
|
numberOfKeyShares: 3,
|
|
@@ -10926,6 +11194,7 @@ class Swap extends Base {
|
|
|
10926
11194
|
});
|
|
10927
11195
|
}
|
|
10928
11196
|
else {
|
|
11197
|
+
// Unreachable in practice: prepareSwapAuth throws sdk_seed_phrase_not_found before we get here; kept as a defensive guard.
|
|
10929
11198
|
throw new WallabyError({
|
|
10930
11199
|
message: 'No valid seed option found on this device.',
|
|
10931
11200
|
statusCode: 400,
|
|
@@ -11347,27 +11616,54 @@ class Transactions extends Base {
|
|
|
11347
11616
|
/**
|
|
11348
11617
|
*
|
|
11349
11618
|
* @public
|
|
11350
|
-
* @param {
|
|
11351
|
-
* @
|
|
11352
|
-
* @param {TokenStandard} tokenStandard an optional param used when dealing with non native assets
|
|
11353
|
-
* @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
|
|
11354
11621
|
*/
|
|
11355
|
-
async getTransactions(
|
|
11622
|
+
async getTransactions(params) {
|
|
11356
11623
|
try {
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
address,
|
|
11360
|
-
tokenSymbol: symbol,
|
|
11361
|
-
tokenType: tokenStandard,
|
|
11362
|
-
},
|
|
11624
|
+
return await this.request(TransactionsRoutes.getTransactions, {
|
|
11625
|
+
queryParams: params,
|
|
11363
11626
|
});
|
|
11364
|
-
return response;
|
|
11365
11627
|
}
|
|
11366
11628
|
catch (error) {
|
|
11367
11629
|
logger.error('SDK::Transactions::getTransactions::error', error);
|
|
11368
11630
|
throw error;
|
|
11369
11631
|
}
|
|
11370
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
|
+
}
|
|
11371
11667
|
/**
|
|
11372
11668
|
*
|
|
11373
11669
|
* @public
|
|
@@ -11702,6 +11998,12 @@ class Transactions extends Base {
|
|
|
11702
11998
|
});
|
|
11703
11999
|
}
|
|
11704
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);
|
|
11705
12007
|
__decorate([
|
|
11706
12008
|
WithLock('transfer'),
|
|
11707
12009
|
__metadata("design:type", Function),
|