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.esm.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";
|
|
@@ -569,7 +589,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
569
589
|
{ type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
|
|
570
590
|
];
|
|
571
591
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
572
|
-
const currentPackageVersion = "3.
|
|
592
|
+
const currentPackageVersion = "3.3.0" ;
|
|
573
593
|
|
|
574
594
|
/**
|
|
575
595
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4407,14 +4427,19 @@ class Cipher {
|
|
|
4407
4427
|
return AES.encrypt(typeof data === 'string' ? data : JSON.stringify(data), this.getMasterKey().key).toString();
|
|
4408
4428
|
}
|
|
4409
4429
|
decryptWithMasterKey({ cipherText }) {
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4430
|
+
try {
|
|
4431
|
+
const decrypted = AES.decrypt(cipherText, this.getMasterKey().key).toString(enc.Utf8);
|
|
4432
|
+
if (decrypted) {
|
|
4433
|
+
return isJsonString(decrypted) ? safeJsonParse(decrypted) : decrypted;
|
|
4434
|
+
}
|
|
4413
4435
|
}
|
|
4414
|
-
|
|
4415
|
-
|
|
4436
|
+
catch (error) {
|
|
4437
|
+
// crypto-js throws "Malformed UTF-8 data" when the ciphertext can't be decrypted
|
|
4438
|
+
logger.error('Decryption failed with master key', error);
|
|
4416
4439
|
return undefined;
|
|
4417
4440
|
}
|
|
4441
|
+
logger.error('Decryption failed with master key');
|
|
4442
|
+
return undefined;
|
|
4418
4443
|
}
|
|
4419
4444
|
/**
|
|
4420
4445
|
* Validate that a public key is the correct length and format.
|
|
@@ -5186,6 +5211,19 @@ function userIsMfaVerified(jwt) {
|
|
|
5186
5211
|
const jwtDecoded = jwtDecode(jwt);
|
|
5187
5212
|
return jwtDecoded.mfaVerified;
|
|
5188
5213
|
}
|
|
5214
|
+
/**
|
|
5215
|
+
* Checks if a given JWT will expire within the given threshold.
|
|
5216
|
+
*
|
|
5217
|
+
* @param jwt - The JWT string to check. If null, the function returns false.
|
|
5218
|
+
* @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
|
|
5219
|
+
* @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
|
|
5220
|
+
*/
|
|
5221
|
+
function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
5222
|
+
if (!jwt) {
|
|
5223
|
+
return false;
|
|
5224
|
+
}
|
|
5225
|
+
return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
|
|
5226
|
+
}
|
|
5189
5227
|
/**
|
|
5190
5228
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
5191
5229
|
*
|
|
@@ -5200,6 +5238,49 @@ function millisecondsToJWTTimeout(jwt) {
|
|
|
5200
5238
|
return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
|
|
5201
5239
|
}
|
|
5202
5240
|
|
|
5241
|
+
const AuthRoutes = {
|
|
5242
|
+
signatureMessage: {
|
|
5243
|
+
fullPath: '/auth/signature-message',
|
|
5244
|
+
method: RequestMethod.Post,
|
|
5245
|
+
requiresAccessToken: false,
|
|
5246
|
+
},
|
|
5247
|
+
signIn: {
|
|
5248
|
+
fullPath: '/auth/sign-in',
|
|
5249
|
+
method: RequestMethod.Post,
|
|
5250
|
+
requiresAccessToken: false,
|
|
5251
|
+
},
|
|
5252
|
+
signUp: {
|
|
5253
|
+
fullPath: '/auth/sign-up',
|
|
5254
|
+
method: RequestMethod.Post,
|
|
5255
|
+
requiresAccessToken: false,
|
|
5256
|
+
},
|
|
5257
|
+
refreshAccessToken: {
|
|
5258
|
+
fullPath: '/auth/refresh-access-token',
|
|
5259
|
+
method: RequestMethod.Post,
|
|
5260
|
+
requiresAccessToken: true,
|
|
5261
|
+
},
|
|
5262
|
+
clientAuthPubKey: {
|
|
5263
|
+
fullPath: 'auth/client-auth-pubkey',
|
|
5264
|
+
method: RequestMethod.Put,
|
|
5265
|
+
requiresAccessToken: true,
|
|
5266
|
+
},
|
|
5267
|
+
wallabyAuthPublicKey: {
|
|
5268
|
+
fullPath: '/auth/wallaby-auth-pubkey',
|
|
5269
|
+
method: RequestMethod.Get,
|
|
5270
|
+
requiresAccessToken: true,
|
|
5271
|
+
},
|
|
5272
|
+
getUserSalt: {
|
|
5273
|
+
fullPath: '/users/salt',
|
|
5274
|
+
method: RequestMethod.Get,
|
|
5275
|
+
requiresAccessToken: true,
|
|
5276
|
+
},
|
|
5277
|
+
getPasskeyCredentials: {
|
|
5278
|
+
fullPath: '/auth/passkey-credentials',
|
|
5279
|
+
method: RequestMethod.Get,
|
|
5280
|
+
requiresAccessToken: true,
|
|
5281
|
+
},
|
|
5282
|
+
};
|
|
5283
|
+
|
|
5203
5284
|
class LockManagerService {
|
|
5204
5285
|
constructor() {
|
|
5205
5286
|
this.activeLocks = new Set();
|
|
@@ -5243,6 +5324,43 @@ class LockManagerService {
|
|
|
5243
5324
|
}
|
|
5244
5325
|
}
|
|
5245
5326
|
|
|
5327
|
+
class DedupeManagerService {
|
|
5328
|
+
constructor() {
|
|
5329
|
+
this.inFlightOperations = new Map();
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Executes an operation once per key while returning the same in-flight promise
|
|
5333
|
+
* to all concurrent callers.
|
|
5334
|
+
* @param key - Unique identifier for dedupe scope.
|
|
5335
|
+
* @param operation - The async operation to execute.
|
|
5336
|
+
*/
|
|
5337
|
+
withDedupe(key, operation) {
|
|
5338
|
+
const existingOperation = this.inFlightOperations.get(key);
|
|
5339
|
+
if (existingOperation) {
|
|
5340
|
+
return existingOperation;
|
|
5341
|
+
}
|
|
5342
|
+
const operationPromise = Promise.resolve()
|
|
5343
|
+
.then(operation)
|
|
5344
|
+
.finally(() => {
|
|
5345
|
+
this.inFlightOperations.delete(key);
|
|
5346
|
+
});
|
|
5347
|
+
this.inFlightOperations.set(key, operationPromise);
|
|
5348
|
+
return operationPromise;
|
|
5349
|
+
}
|
|
5350
|
+
/**
|
|
5351
|
+
* Check if a specific operation is currently in flight.
|
|
5352
|
+
*/
|
|
5353
|
+
isInFlight(key) {
|
|
5354
|
+
return this.inFlightOperations.has(key);
|
|
5355
|
+
}
|
|
5356
|
+
/**
|
|
5357
|
+
* Clear all tracked in-flight operations (primarily for tests/cleanup).
|
|
5358
|
+
*/
|
|
5359
|
+
clearAll() {
|
|
5360
|
+
this.inFlightOperations.clear();
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
|
|
5246
5364
|
function isValidInput(input) {
|
|
5247
5365
|
// Allow alphanumeric characters, hyphens, and underscores.
|
|
5248
5366
|
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
@@ -5540,6 +5658,16 @@ class Api {
|
|
|
5540
5658
|
* @secure
|
|
5541
5659
|
*/
|
|
5542
5660
|
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)),
|
|
5661
|
+
/**
|
|
5662
|
+
* No description
|
|
5663
|
+
*
|
|
5664
|
+
* @tags Auth
|
|
5665
|
+
* @name IssueJwtToken
|
|
5666
|
+
* @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.
|
|
5667
|
+
* @request POST:/api/v1/auth/issue-jwt-token
|
|
5668
|
+
* @secure
|
|
5669
|
+
*/
|
|
5670
|
+
issueJwtToken: (params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/issue-jwt-token`, method: "POST", secure: true, format: "json" }, params)),
|
|
5543
5671
|
/**
|
|
5544
5672
|
* No description
|
|
5545
5673
|
*
|
|
@@ -6038,6 +6166,20 @@ class Api {
|
|
|
6038
6166
|
if (params === void 0) { params = {}; }
|
|
6039
6167
|
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/assets`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6040
6168
|
},
|
|
6169
|
+
/**
|
|
6170
|
+
* No description
|
|
6171
|
+
*
|
|
6172
|
+
* @tags Wallets
|
|
6173
|
+
* @name GetWalletAddresses
|
|
6174
|
+
* @summary Get all assets that exist in a certain wallet, by specifying a wallet ID
|
|
6175
|
+
* @request GET:/api/v1/wallets/{walletId}/addresses
|
|
6176
|
+
* @secure
|
|
6177
|
+
*/
|
|
6178
|
+
getWalletAddresses: (_a, params) => {
|
|
6179
|
+
var { walletId } = _a, query = __rest(_a, ["walletId"]);
|
|
6180
|
+
if (params === void 0) { params = {}; }
|
|
6181
|
+
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/addresses`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6182
|
+
},
|
|
6041
6183
|
/**
|
|
6042
6184
|
* No description
|
|
6043
6185
|
*
|
|
@@ -6237,23 +6379,35 @@ class Api {
|
|
|
6237
6379
|
/**
|
|
6238
6380
|
* No description
|
|
6239
6381
|
*
|
|
6240
|
-
* @tags Transactions, Transactions
|
|
6382
|
+
* @tags Transactions, Transactions
|
|
6241
6383
|
* @name DetectTransferRestriction
|
|
6242
6384
|
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6243
6385
|
* @request GET:/api/v1/transactions/detect-transfers-restrictions
|
|
6386
|
+
* @deprecated
|
|
6244
6387
|
* @secure
|
|
6245
6388
|
*/
|
|
6246
6389
|
detectTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/detect-transfers-restrictions`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6247
6390
|
/**
|
|
6248
6391
|
* No description
|
|
6249
6392
|
*
|
|
6250
|
-
* @tags Transactions, Transactions
|
|
6393
|
+
* @tags Transactions, Transactions
|
|
6251
6394
|
* @name FetchMessageForTransferRestriction
|
|
6252
6395
|
* @summary Request restriction message by providing a restriction code
|
|
6253
6396
|
* @request GET:/api/v1/transactions/transfer-restriction-message
|
|
6397
|
+
* @deprecated
|
|
6254
6398
|
* @secure
|
|
6255
6399
|
*/
|
|
6256
6400
|
fetchMessageForTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/transfer-restriction-message`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6401
|
+
/**
|
|
6402
|
+
* No description
|
|
6403
|
+
*
|
|
6404
|
+
* @tags Transactions, Transactions
|
|
6405
|
+
* @name GetRestriction
|
|
6406
|
+
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6407
|
+
* @request GET:/api/v1/transactions/restriction
|
|
6408
|
+
* @secure
|
|
6409
|
+
*/
|
|
6410
|
+
getRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/restriction`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6257
6411
|
/**
|
|
6258
6412
|
* No description
|
|
6259
6413
|
*
|
|
@@ -6681,6 +6835,48 @@ function objectToQueryParams(obj) {
|
|
|
6681
6835
|
return params.toString();
|
|
6682
6836
|
}
|
|
6683
6837
|
|
|
6838
|
+
const refreshableAuth401ErrorCodes = new Set([
|
|
6839
|
+
ErrorResponseCodes.auth_api_jwt_invalid,
|
|
6840
|
+
ErrorResponseCodes.auth_api_jwt_not_active,
|
|
6841
|
+
ErrorResponseCodes.auth_api_jwt_not_provided,
|
|
6842
|
+
ErrorResponseCodes.auth_api_jwt_expired,
|
|
6843
|
+
ErrorResponseCodes.auth_api_unauthorized,
|
|
6844
|
+
]);
|
|
6845
|
+
const clearTokensOnRefreshFailureErrorCodes = new Set([
|
|
6846
|
+
ErrorResponseCodes.auth_refresh_token_not_found,
|
|
6847
|
+
ErrorResponseCodes.auth_refresh_token_expired,
|
|
6848
|
+
ErrorResponseCodes.auth_refresh_token_reuse_detected,
|
|
6849
|
+
]);
|
|
6850
|
+
function extractErrorStatus(error) {
|
|
6851
|
+
var _a, _b, _c, _d, _e;
|
|
6852
|
+
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;
|
|
6853
|
+
}
|
|
6854
|
+
function extractErrorCode(error) {
|
|
6855
|
+
var _a, _b, _c, _d;
|
|
6856
|
+
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;
|
|
6857
|
+
}
|
|
6858
|
+
function shouldAttemptTokenRefresh(error) {
|
|
6859
|
+
const status = extractErrorStatus(error);
|
|
6860
|
+
if (status !== 401) {
|
|
6861
|
+
return false;
|
|
6862
|
+
}
|
|
6863
|
+
const errorCode = extractErrorCode(error);
|
|
6864
|
+
if (!errorCode) {
|
|
6865
|
+
// Backward compatibility: some endpoints may not provide explicit errorCode.
|
|
6866
|
+
return true;
|
|
6867
|
+
}
|
|
6868
|
+
return refreshableAuth401ErrorCodes.has(errorCode);
|
|
6869
|
+
}
|
|
6870
|
+
function shouldClearTokensAfterRefreshFailure(error) {
|
|
6871
|
+
const status = extractErrorStatus(error);
|
|
6872
|
+
const errorCode = extractErrorCode(error);
|
|
6873
|
+
// Any 401 clears tokens (preserves prior behavior). The error-code set additionally
|
|
6874
|
+
// covers refresh-token failures that arrive with a non-401 status (e.g. 400/403).
|
|
6875
|
+
return status === 401 || (!!errorCode && clearTokensOnRefreshFailureErrorCodes.has(errorCode));
|
|
6876
|
+
}
|
|
6877
|
+
|
|
6878
|
+
// Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
|
|
6879
|
+
const refreshDedupeManager = new DedupeManagerService();
|
|
6684
6880
|
class Base {
|
|
6685
6881
|
constructor(config) {
|
|
6686
6882
|
var _a, _b;
|
|
@@ -6710,35 +6906,45 @@ class Base {
|
|
|
6710
6906
|
});
|
|
6711
6907
|
/**
|
|
6712
6908
|
* This intercepts all API responses and transforms errors into WallabyError format.
|
|
6909
|
+
* On a 401, it performs a single token refresh then retries (reactive guard).
|
|
6713
6910
|
*/
|
|
6714
6911
|
const originalRequest = httpClient.request.bind(httpClient);
|
|
6715
6912
|
httpClient.request = async (params) => {
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6913
|
+
const attemptRequest = async (retried) => {
|
|
6914
|
+
try {
|
|
6915
|
+
return await originalRequest(params);
|
|
6916
|
+
}
|
|
6917
|
+
catch (error) {
|
|
6918
|
+
// Reactive 401 handling for the generated client: refresh once and retry
|
|
6919
|
+
if (!retried && shouldAttemptTokenRefresh(error)) {
|
|
6920
|
+
await this._performTokenRefresh();
|
|
6921
|
+
// securityWorker will re-fetch the new access token on retry
|
|
6922
|
+
return attemptRequest(true);
|
|
6923
|
+
}
|
|
6924
|
+
// Transform the generated API error format into WallabyError
|
|
6925
|
+
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6926
|
+
const apiError = error.error;
|
|
6927
|
+
throw new WallabyError({
|
|
6928
|
+
message: apiError.message || 'API request failed',
|
|
6929
|
+
statusCode: apiError.statusCode || 500,
|
|
6930
|
+
errorCode: apiError.errorCode,
|
|
6931
|
+
data: apiError,
|
|
6932
|
+
});
|
|
6933
|
+
}
|
|
6934
|
+
// Re-throw if already a WallabyError
|
|
6935
|
+
if (error instanceof WallabyError) {
|
|
6936
|
+
throw error;
|
|
6937
|
+
}
|
|
6938
|
+
// Wrap any other errors
|
|
6723
6939
|
throw new WallabyError({
|
|
6724
|
-
message:
|
|
6725
|
-
statusCode:
|
|
6726
|
-
errorCode:
|
|
6727
|
-
data:
|
|
6940
|
+
message: error.message || 'Unknown error occurred',
|
|
6941
|
+
statusCode: error.statusCode || 500,
|
|
6942
|
+
errorCode: error.errorCode,
|
|
6943
|
+
data: error,
|
|
6728
6944
|
});
|
|
6729
6945
|
}
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
throw error;
|
|
6733
|
-
}
|
|
6734
|
-
// Wrap any other errors
|
|
6735
|
-
throw new WallabyError({
|
|
6736
|
-
message: error.message || 'Unknown error occurred',
|
|
6737
|
-
statusCode: error.statusCode || 500,
|
|
6738
|
-
errorCode: error.errorCode,
|
|
6739
|
-
data: error,
|
|
6740
|
-
});
|
|
6741
|
-
}
|
|
6946
|
+
};
|
|
6947
|
+
return attemptRequest(false);
|
|
6742
6948
|
};
|
|
6743
6949
|
this.api = new Api(httpClient);
|
|
6744
6950
|
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));
|
|
@@ -6819,15 +7025,51 @@ class Base {
|
|
|
6819
7025
|
environment: this.settings.environment,
|
|
6820
7026
|
});
|
|
6821
7027
|
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Fetches a new access/refresh token pair using the stored refresh token.
|
|
7030
|
+
* All concurrent callers share the same in-flight promise via the module-level
|
|
7031
|
+
* `refreshDedupeManager` so only one network request is issued per user/environment scope.
|
|
7032
|
+
*/
|
|
7033
|
+
async _performTokenRefresh() {
|
|
7034
|
+
const refreshDedupeKey = `refresh:${this.userId}:${this.settings.environment}:${this.settings.network}`;
|
|
7035
|
+
await refreshDedupeManager.withDedupe(refreshDedupeKey, async () => {
|
|
7036
|
+
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
7037
|
+
if (!refreshToken) {
|
|
7038
|
+
return;
|
|
7039
|
+
}
|
|
7040
|
+
try {
|
|
7041
|
+
const response = await this.request(AuthRoutes.refreshAccessToken, {
|
|
7042
|
+
payload: { refreshToken },
|
|
7043
|
+
});
|
|
7044
|
+
await this.localStorageService.save(LocalStorageItems.AccessToken, response.accessToken);
|
|
7045
|
+
await this.localStorageService.save(LocalStorageItems.RefreshToken, response.refreshToken);
|
|
7046
|
+
}
|
|
7047
|
+
catch (error) {
|
|
7048
|
+
if (shouldClearTokensAfterRefreshFailure(error)) {
|
|
7049
|
+
await this.localStorageService.delete(LocalStorageItems.AccessToken);
|
|
7050
|
+
await this.localStorageService.delete(LocalStorageItems.RefreshToken);
|
|
7051
|
+
}
|
|
7052
|
+
throw error;
|
|
7053
|
+
}
|
|
7054
|
+
});
|
|
7055
|
+
}
|
|
6822
7056
|
/**
|
|
6823
7057
|
* Main request method for making API calls to the Wallaby API.
|
|
6824
7058
|
* @param route - Route configuration object containing the endpoint path and HTTP method
|
|
6825
7059
|
* @param options - Optional request options including payload and query parameters
|
|
7060
|
+
* @param retried - Internal flag; set to true when retrying after a 401 to prevent loops
|
|
6826
7061
|
* @returns Promise resolving to the typed response data
|
|
6827
7062
|
* @throws Error if the API returns an error response or network failure occurs
|
|
6828
7063
|
*/
|
|
6829
|
-
async request(route, options) {
|
|
7064
|
+
async request(route, options, retried = false) {
|
|
6830
7065
|
var _a;
|
|
7066
|
+
// Proactive token refresh: if access token is near expiry, refresh before making the request
|
|
7067
|
+
if (route !== AuthRoutes.refreshAccessToken && !retried) {
|
|
7068
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7069
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7070
|
+
await this._performTokenRefresh();
|
|
7071
|
+
}
|
|
7072
|
+
}
|
|
6831
7073
|
const path = typeof route.fullPath === 'string' ? route.fullPath : route.fullPath(options === null || options === void 0 ? void 0 : options.payload);
|
|
6832
7074
|
// Add query parameters to the path if provided
|
|
6833
7075
|
let finalPath = path;
|
|
@@ -6881,6 +7123,11 @@ class Base {
|
|
|
6881
7123
|
return data;
|
|
6882
7124
|
}
|
|
6883
7125
|
catch (error) {
|
|
7126
|
+
// Reactive token refresh: on 401, refresh once and retry the original request
|
|
7127
|
+
if (!retried && route !== AuthRoutes.refreshAccessToken && shouldAttemptTokenRefresh(error)) {
|
|
7128
|
+
await this._performTokenRefresh();
|
|
7129
|
+
return this.request(route, options, true);
|
|
7130
|
+
}
|
|
6884
7131
|
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6885
7132
|
logger.error('SDK::Base::handleApiCall::API Error', { error });
|
|
6886
7133
|
const apiError = error.error;
|
|
@@ -6933,6 +7180,16 @@ class Base {
|
|
|
6933
7180
|
return headers;
|
|
6934
7181
|
}
|
|
6935
7182
|
async securityWorker(securityData) {
|
|
7183
|
+
// Proactive token refresh before building headers for the generated client
|
|
7184
|
+
try {
|
|
7185
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7186
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7187
|
+
await this._performTokenRefresh();
|
|
7188
|
+
}
|
|
7189
|
+
}
|
|
7190
|
+
catch (_a) {
|
|
7191
|
+
// Best-effort proactive refresh; proceed even if it fails
|
|
7192
|
+
}
|
|
6936
7193
|
// Start with the security data that contains API key and JWT
|
|
6937
7194
|
const headers = Object.assign({ 'Content-Type': 'application/json' }, (securityData || {}));
|
|
6938
7195
|
// Add access token if available
|
|
@@ -6942,7 +7199,7 @@ class Base {
|
|
|
6942
7199
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
6943
7200
|
}
|
|
6944
7201
|
}
|
|
6945
|
-
catch (
|
|
7202
|
+
catch (_b) {
|
|
6946
7203
|
// Access token is optional, continue without it
|
|
6947
7204
|
}
|
|
6948
7205
|
return {
|
|
@@ -7069,49 +7326,6 @@ const WalletRoutes = {
|
|
|
7069
7326
|
},
|
|
7070
7327
|
};
|
|
7071
7328
|
|
|
7072
|
-
const AuthRoutes = {
|
|
7073
|
-
signatureMessage: {
|
|
7074
|
-
fullPath: '/auth/signature-message',
|
|
7075
|
-
method: RequestMethod.Post,
|
|
7076
|
-
requiresAccessToken: false,
|
|
7077
|
-
},
|
|
7078
|
-
signIn: {
|
|
7079
|
-
fullPath: '/auth/sign-in',
|
|
7080
|
-
method: RequestMethod.Post,
|
|
7081
|
-
requiresAccessToken: false,
|
|
7082
|
-
},
|
|
7083
|
-
signUp: {
|
|
7084
|
-
fullPath: '/auth/sign-up',
|
|
7085
|
-
method: RequestMethod.Post,
|
|
7086
|
-
requiresAccessToken: false,
|
|
7087
|
-
},
|
|
7088
|
-
refreshAccessToken: {
|
|
7089
|
-
fullPath: '/auth/refresh-access-token',
|
|
7090
|
-
method: RequestMethod.Post,
|
|
7091
|
-
requiresAccessToken: true,
|
|
7092
|
-
},
|
|
7093
|
-
clientAuthPubKey: {
|
|
7094
|
-
fullPath: 'auth/client-auth-pubkey',
|
|
7095
|
-
method: RequestMethod.Put,
|
|
7096
|
-
requiresAccessToken: true,
|
|
7097
|
-
},
|
|
7098
|
-
wallabyAuthPublicKey: {
|
|
7099
|
-
fullPath: '/auth/wallaby-auth-pubkey',
|
|
7100
|
-
method: RequestMethod.Get,
|
|
7101
|
-
requiresAccessToken: true,
|
|
7102
|
-
},
|
|
7103
|
-
getUserSalt: {
|
|
7104
|
-
fullPath: '/users/salt',
|
|
7105
|
-
method: RequestMethod.Get,
|
|
7106
|
-
requiresAccessToken: true,
|
|
7107
|
-
},
|
|
7108
|
-
getPasskeyCredentials: {
|
|
7109
|
-
fullPath: '/auth/passkey-credentials',
|
|
7110
|
-
method: RequestMethod.Get,
|
|
7111
|
-
requiresAccessToken: true,
|
|
7112
|
-
},
|
|
7113
|
-
};
|
|
7114
|
-
|
|
7115
7329
|
const SystemRoutes = {
|
|
7116
7330
|
getSupportedBlockchains: {
|
|
7117
7331
|
fullPath: '/chains',
|
|
@@ -7167,7 +7381,22 @@ const TransactionsRoutes = {
|
|
|
7167
7381
|
requiresAccessToken: true,
|
|
7168
7382
|
},
|
|
7169
7383
|
getTransactions: {
|
|
7170
|
-
fullPath: '/
|
|
7384
|
+
fullPath: '/transactions',
|
|
7385
|
+
method: RequestMethod.Get,
|
|
7386
|
+
requiresAccessToken: true,
|
|
7387
|
+
},
|
|
7388
|
+
detectTransferRestrictions: {
|
|
7389
|
+
fullPath: '/transactions/detect-transfers-restrictions',
|
|
7390
|
+
method: RequestMethod.Get,
|
|
7391
|
+
requiresAccessToken: true,
|
|
7392
|
+
},
|
|
7393
|
+
transferRestrictionMessage: {
|
|
7394
|
+
fullPath: '/transactions/transfer-restriction-message',
|
|
7395
|
+
method: RequestMethod.Get,
|
|
7396
|
+
requiresAccessToken: true,
|
|
7397
|
+
},
|
|
7398
|
+
restriction: {
|
|
7399
|
+
fullPath: '/transactions/restriction',
|
|
7171
7400
|
method: RequestMethod.Get,
|
|
7172
7401
|
requiresAccessToken: true,
|
|
7173
7402
|
},
|
|
@@ -7893,6 +8122,33 @@ class AuthService extends Base {
|
|
|
7893
8122
|
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
7894
8123
|
return (!!accessToken && !jwtHasExpired(accessToken)) || !!refreshToken;
|
|
7895
8124
|
}
|
|
8125
|
+
/**
|
|
8126
|
+
* @description Refreshes auth tokens using the stored refresh token.
|
|
8127
|
+
*/
|
|
8128
|
+
async refreshAuthTokens() {
|
|
8129
|
+
const refreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
8130
|
+
if (!refreshToken) {
|
|
8131
|
+
throw new WallabyError({
|
|
8132
|
+
message: 'Refresh token is required',
|
|
8133
|
+
statusCode: 401,
|
|
8134
|
+
errorCode: ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8135
|
+
});
|
|
8136
|
+
}
|
|
8137
|
+
await this._performTokenRefresh();
|
|
8138
|
+
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
8139
|
+
const newRefreshToken = await this.localStorageService.fetch(LocalStorageItems.RefreshToken);
|
|
8140
|
+
if (!accessToken || !newRefreshToken) {
|
|
8141
|
+
throw new WallabyError({
|
|
8142
|
+
message: 'Token refresh failed: tokens not present in storage after refresh',
|
|
8143
|
+
statusCode: 401,
|
|
8144
|
+
errorCode: ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8145
|
+
});
|
|
8146
|
+
}
|
|
8147
|
+
return {
|
|
8148
|
+
accessToken,
|
|
8149
|
+
refreshToken: newRefreshToken,
|
|
8150
|
+
};
|
|
8151
|
+
}
|
|
7896
8152
|
/**
|
|
7897
8153
|
* @description Validates the user's password by decrypting the stored private key.
|
|
7898
8154
|
* @returns { boolean } Returns true if the password is valid, false otherwise.
|
|
@@ -9166,6 +9422,17 @@ class WalletService extends Base {
|
|
|
9166
9422
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9167
9423
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9168
9424
|
});
|
|
9425
|
+
// Guard against persisting an empty/invalid re-wrap, which would lock the user out of
|
|
9426
|
+
// their device private key (the one mandatory item) under the new password. The type says
|
|
9427
|
+
// this is always defined, but we defend against a runtime contract violation regardless.
|
|
9428
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
9429
|
+
if (!reWrappedDevicePrivateKey) {
|
|
9430
|
+
throw new WallabyError({
|
|
9431
|
+
message: 'Failed to re-wrap device private key during password change.',
|
|
9432
|
+
statusCode: 500,
|
|
9433
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9434
|
+
});
|
|
9435
|
+
}
|
|
9169
9436
|
await this.localStorageService.save(LocalStorageItems.EncryptedDevicePrivateKey, reWrappedDevicePrivateKey);
|
|
9170
9437
|
if (encryptedSeedPhraseString) {
|
|
9171
9438
|
const parsedSeed = safeJsonParse(encryptedSeedPhraseString);
|
|
@@ -9928,6 +10195,7 @@ class WalletService extends Base {
|
|
|
9928
10195
|
storeSeedPhrase: false,
|
|
9929
10196
|
returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
9930
10197
|
walletId: input.walletId,
|
|
10198
|
+
reference: v4(),
|
|
9931
10199
|
keyShareOptions: {
|
|
9932
10200
|
threshold: 2,
|
|
9933
10201
|
numberOfKeyShares: 3,
|
|
@@ -10812,6 +11080,7 @@ class Swap extends Base {
|
|
|
10812
11080
|
});
|
|
10813
11081
|
}
|
|
10814
11082
|
else {
|
|
11083
|
+
// Unreachable in practice: prepareSwapAuth throws sdk_seed_phrase_not_found before we get here; kept as a defensive guard.
|
|
10815
11084
|
throw new WallabyError({
|
|
10816
11085
|
message: 'No valid seed option found on this device.',
|
|
10817
11086
|
statusCode: 400,
|
|
@@ -11233,27 +11502,54 @@ class Transactions extends Base {
|
|
|
11233
11502
|
/**
|
|
11234
11503
|
*
|
|
11235
11504
|
* @public
|
|
11236
|
-
* @param {
|
|
11237
|
-
* @
|
|
11238
|
-
* @param {TokenStandard} tokenStandard an optional param used when dealing with non native assets
|
|
11239
|
-
* @returns {Promise<{ address: string; transactions: Transaction[] }>}
|
|
11505
|
+
* @param {GetTransactionsParams} params - Query parameters for filtering and paginating transactions
|
|
11506
|
+
* @returns {GetTransactionsResponseDto} Paginated list of transactions matching the given criteria
|
|
11240
11507
|
*/
|
|
11241
|
-
async getTransactions(
|
|
11508
|
+
async getTransactions(params) {
|
|
11242
11509
|
try {
|
|
11243
|
-
|
|
11244
|
-
|
|
11245
|
-
address,
|
|
11246
|
-
tokenSymbol: symbol,
|
|
11247
|
-
tokenType: tokenStandard,
|
|
11248
|
-
},
|
|
11510
|
+
return await this.request(TransactionsRoutes.getTransactions, {
|
|
11511
|
+
queryParams: params,
|
|
11249
11512
|
});
|
|
11250
|
-
return response;
|
|
11251
11513
|
}
|
|
11252
11514
|
catch (error) {
|
|
11253
11515
|
logger.error('SDK::Transactions::getTransactions::error', error);
|
|
11254
11516
|
throw error;
|
|
11255
11517
|
}
|
|
11256
11518
|
}
|
|
11519
|
+
/**
|
|
11520
|
+
*
|
|
11521
|
+
* @public
|
|
11522
|
+
* @param {GetRestrictionParams} params - Parameters to detect transfer restrictions (addresses, asset, value)
|
|
11523
|
+
* - {string} fromAddress
|
|
11524
|
+
* - {string} toAddress
|
|
11525
|
+
* - {string} amount
|
|
11526
|
+
* - [string] assetId
|
|
11527
|
+
* - [string] contractAddress
|
|
11528
|
+
* - [BlockchainName] blockchainName
|
|
11529
|
+
* @returns {Promise<DetectRestrictionResponseDto>}
|
|
11530
|
+
* Detection result; when transfer is blocked, also includes the human-readable restriction message and a boolean canTransfer
|
|
11531
|
+
*/
|
|
11532
|
+
async getRestriction(params) {
|
|
11533
|
+
try {
|
|
11534
|
+
const hasAssetId = Boolean(params.assetId);
|
|
11535
|
+
const hasContractAndChain = Boolean(params.contractAddress && params.blockchainName);
|
|
11536
|
+
if (!hasAssetId && !hasContractAndChain) {
|
|
11537
|
+
throw new WallabyError({
|
|
11538
|
+
message: 'Either assetId or both contractAddress and blockchainName must be provided.',
|
|
11539
|
+
statusCode: 400,
|
|
11540
|
+
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
11541
|
+
});
|
|
11542
|
+
}
|
|
11543
|
+
const restrictionData = await this.request(TransactionsRoutes.restriction, {
|
|
11544
|
+
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 })),
|
|
11545
|
+
});
|
|
11546
|
+
return restrictionData;
|
|
11547
|
+
}
|
|
11548
|
+
catch (error) {
|
|
11549
|
+
logger.error('SDK::Transactions::getRestriction::error', error);
|
|
11550
|
+
throw error;
|
|
11551
|
+
}
|
|
11552
|
+
}
|
|
11257
11553
|
/**
|
|
11258
11554
|
*
|
|
11259
11555
|
* @public
|
|
@@ -11588,6 +11884,12 @@ class Transactions extends Base {
|
|
|
11588
11884
|
});
|
|
11589
11885
|
}
|
|
11590
11886
|
}
|
|
11887
|
+
__decorate([
|
|
11888
|
+
WithLock('transaction-restriction-message'),
|
|
11889
|
+
__metadata("design:type", Function),
|
|
11890
|
+
__metadata("design:paramtypes", [Object]),
|
|
11891
|
+
__metadata("design:returntype", Promise)
|
|
11892
|
+
], Transactions.prototype, "getRestriction", null);
|
|
11591
11893
|
__decorate([
|
|
11592
11894
|
WithLock('transfer'),
|
|
11593
11895
|
__metadata("design:type", Function),
|