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.cjs.js
CHANGED
|
@@ -111,6 +111,7 @@ exports.TransportEnum = void 0;
|
|
|
111
111
|
*/
|
|
112
112
|
class WallabyError extends Error {
|
|
113
113
|
constructor(errorPayload) {
|
|
114
|
+
var _a;
|
|
114
115
|
const { message, statusCode, errorCode, data, cause, onError } = errorPayload;
|
|
115
116
|
super(message);
|
|
116
117
|
this.name = 'WallabyError';
|
|
@@ -119,7 +120,17 @@ class WallabyError extends Error {
|
|
|
119
120
|
this.cause = cause;
|
|
120
121
|
this.onError = onError;
|
|
121
122
|
this.data = data;
|
|
122
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Preserve prototype chain when extending built-ins across transpilation targets.
|
|
125
|
+
* Object.setPrototypeOf(this, WallabyError.prototype) forces the prototype to WallabyError even when a consumer subclasses WallabyError,
|
|
126
|
+
* breaking the prototype chain for derived errors (and potentially instanceof DerivedWallabyError).
|
|
127
|
+
* Use new.target.prototype (and new.target for stack capture) so the fix works for subclasses too.
|
|
128
|
+
*
|
|
129
|
+
* Use optional chaining since Error.captureStackTrace isn't available in all runtimes (e.g., Safari).
|
|
130
|
+
*/
|
|
131
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
133
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, new.target);
|
|
123
134
|
}
|
|
124
135
|
static isWallabyError(error) {
|
|
125
136
|
return error instanceof WallabyError;
|
|
@@ -350,6 +361,12 @@ exports.ErrorResponseCodes = void 0;
|
|
|
350
361
|
ErrorResponseCodes["auth_api_jwt_invalid"] = "auth_api_jwt_invalid";
|
|
351
362
|
ErrorResponseCodes["auth_api_jwt_not_active"] = "auth_api_jwt_not_active";
|
|
352
363
|
ErrorResponseCodes["auth_api_jwt_not_provided"] = "auth_api_jwt_not_provided";
|
|
364
|
+
ErrorResponseCodes["auth_api_jwt_expired"] = "auth_api_jwt_expired";
|
|
365
|
+
ErrorResponseCodes["auth_api_unauthorized"] = "auth_api_unauthorized";
|
|
366
|
+
// Auth Refresh Token
|
|
367
|
+
ErrorResponseCodes["auth_refresh_token_not_found"] = "auth_refresh_token_not_found";
|
|
368
|
+
ErrorResponseCodes["auth_refresh_token_expired"] = "auth_refresh_token_expired";
|
|
369
|
+
ErrorResponseCodes["auth_refresh_token_reuse_detected"] = "auth_refresh_token_reuse_detected";
|
|
353
370
|
// Auth Client JWT
|
|
354
371
|
ErrorResponseCodes["auth_client_jwt_invalid"] = "auth_client_jwt_invalid";
|
|
355
372
|
ErrorResponseCodes["auth_client_jwt_missing_external_id_payload"] = "auth_client_jwt_missing_external_id_payload";
|
|
@@ -357,6 +374,8 @@ exports.ErrorResponseCodes = void 0;
|
|
|
357
374
|
ErrorResponseCodes["auth_client_jwt_external_id_not_match"] = "auth_client_jwt_external_id_not_match";
|
|
358
375
|
ErrorResponseCodes["auth_client_jwt_expired"] = "auth_client_jwt_expired";
|
|
359
376
|
ErrorResponseCodes["auth_client_jwt_not_provided"] = "auth_client_jwt_not_provided";
|
|
377
|
+
ErrorResponseCodes["auth_client_jwt_invalid_auth_type"] = "auth_client_jwt_invalid_auth_type";
|
|
378
|
+
ErrorResponseCodes["auth_client_jwt_invalid_passkey"] = "auth_client_jwt_invalid_passkey";
|
|
360
379
|
// Auth Client Transport keys
|
|
361
380
|
ErrorResponseCodes["auth_client_pub_key_and_message_not_match"] = "auth_client_pub_key_and_message_not_match";
|
|
362
381
|
ErrorResponseCodes["auth_client_pub_key_and_message_expired"] = "auth_client_pub_key_and_message_expired";
|
|
@@ -390,6 +409,7 @@ exports.ErrorResponseCodes = void 0;
|
|
|
390
409
|
ErrorResponseCodes["sdk_seed_phrase_not_found"] = "sdk_seed_phrase_not_found";
|
|
391
410
|
ErrorResponseCodes["sdk_private_key_decryption_failed"] = "sdk_private_key_decryption_failed";
|
|
392
411
|
ErrorResponseCodes["sdk_private_key_not_found"] = "sdk_private_key_not_found";
|
|
412
|
+
ErrorResponseCodes["sdk_refresh_token_missing"] = "sdk_refresh_token_missing";
|
|
393
413
|
ErrorResponseCodes["sdk_missing_parameter"] = "sdk_missing_parameter";
|
|
394
414
|
ErrorResponseCodes["sdk_invalid_parameter"] = "sdk_invalid_parameter";
|
|
395
415
|
ErrorResponseCodes["sdk_wrong_password"] = "sdk_wrong_password";
|
|
@@ -598,7 +618,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
598
618
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
599
619
|
];
|
|
600
620
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
601
|
-
const currentPackageVersion = "3.
|
|
621
|
+
const currentPackageVersion = "3.3.0" ;
|
|
602
622
|
|
|
603
623
|
/**
|
|
604
624
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4436,14 +4456,19 @@ class Cipher {
|
|
|
4436
4456
|
return cryptoJs.AES.encrypt(typeof data === 'string' ? data : JSON.stringify(data), this.getMasterKey().key).toString();
|
|
4437
4457
|
}
|
|
4438
4458
|
decryptWithMasterKey({ cipherText }) {
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4459
|
+
try {
|
|
4460
|
+
const decrypted = cryptoJs.AES.decrypt(cipherText, this.getMasterKey().key).toString(cryptoJs.enc.Utf8);
|
|
4461
|
+
if (decrypted) {
|
|
4462
|
+
return isJsonString(decrypted) ? safeJsonParse(decrypted) : decrypted;
|
|
4463
|
+
}
|
|
4442
4464
|
}
|
|
4443
|
-
|
|
4444
|
-
|
|
4465
|
+
catch (error) {
|
|
4466
|
+
// crypto-js throws "Malformed UTF-8 data" when the ciphertext can't be decrypted
|
|
4467
|
+
logger.error('Decryption failed with master key', error);
|
|
4445
4468
|
return undefined;
|
|
4446
4469
|
}
|
|
4470
|
+
logger.error('Decryption failed with master key');
|
|
4471
|
+
return undefined;
|
|
4447
4472
|
}
|
|
4448
4473
|
/**
|
|
4449
4474
|
* Validate that a public key is the correct length and format.
|
|
@@ -5215,6 +5240,19 @@ function userIsMfaVerified(jwt) {
|
|
|
5215
5240
|
const jwtDecoded = jwtDecode.jwtDecode(jwt);
|
|
5216
5241
|
return jwtDecoded.mfaVerified;
|
|
5217
5242
|
}
|
|
5243
|
+
/**
|
|
5244
|
+
* Checks if a given JWT will expire within the given threshold.
|
|
5245
|
+
*
|
|
5246
|
+
* @param jwt - The JWT string to check. If null, the function returns false.
|
|
5247
|
+
* @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
|
|
5248
|
+
* @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
|
|
5249
|
+
*/
|
|
5250
|
+
function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
5251
|
+
if (!jwt) {
|
|
5252
|
+
return false;
|
|
5253
|
+
}
|
|
5254
|
+
return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
|
|
5255
|
+
}
|
|
5218
5256
|
/**
|
|
5219
5257
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
5220
5258
|
*
|
|
@@ -5229,6 +5267,49 @@ function millisecondsToJWTTimeout(jwt) {
|
|
|
5229
5267
|
return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
|
|
5230
5268
|
}
|
|
5231
5269
|
|
|
5270
|
+
const AuthRoutes = {
|
|
5271
|
+
signatureMessage: {
|
|
5272
|
+
fullPath: '/auth/signature-message',
|
|
5273
|
+
method: exports.RequestMethod.Post,
|
|
5274
|
+
requiresAccessToken: false,
|
|
5275
|
+
},
|
|
5276
|
+
signIn: {
|
|
5277
|
+
fullPath: '/auth/sign-in',
|
|
5278
|
+
method: exports.RequestMethod.Post,
|
|
5279
|
+
requiresAccessToken: false,
|
|
5280
|
+
},
|
|
5281
|
+
signUp: {
|
|
5282
|
+
fullPath: '/auth/sign-up',
|
|
5283
|
+
method: exports.RequestMethod.Post,
|
|
5284
|
+
requiresAccessToken: false,
|
|
5285
|
+
},
|
|
5286
|
+
refreshAccessToken: {
|
|
5287
|
+
fullPath: '/auth/refresh-access-token',
|
|
5288
|
+
method: exports.RequestMethod.Post,
|
|
5289
|
+
requiresAccessToken: true,
|
|
5290
|
+
},
|
|
5291
|
+
clientAuthPubKey: {
|
|
5292
|
+
fullPath: 'auth/client-auth-pubkey',
|
|
5293
|
+
method: exports.RequestMethod.Put,
|
|
5294
|
+
requiresAccessToken: true,
|
|
5295
|
+
},
|
|
5296
|
+
wallabyAuthPublicKey: {
|
|
5297
|
+
fullPath: '/auth/wallaby-auth-pubkey',
|
|
5298
|
+
method: exports.RequestMethod.Get,
|
|
5299
|
+
requiresAccessToken: true,
|
|
5300
|
+
},
|
|
5301
|
+
getUserSalt: {
|
|
5302
|
+
fullPath: '/users/salt',
|
|
5303
|
+
method: exports.RequestMethod.Get,
|
|
5304
|
+
requiresAccessToken: true,
|
|
5305
|
+
},
|
|
5306
|
+
getPasskeyCredentials: {
|
|
5307
|
+
fullPath: '/auth/passkey-credentials',
|
|
5308
|
+
method: exports.RequestMethod.Get,
|
|
5309
|
+
requiresAccessToken: true,
|
|
5310
|
+
},
|
|
5311
|
+
};
|
|
5312
|
+
|
|
5232
5313
|
class LockManagerService {
|
|
5233
5314
|
constructor() {
|
|
5234
5315
|
this.activeLocks = new Set();
|
|
@@ -5272,6 +5353,43 @@ class LockManagerService {
|
|
|
5272
5353
|
}
|
|
5273
5354
|
}
|
|
5274
5355
|
|
|
5356
|
+
class DedupeManagerService {
|
|
5357
|
+
constructor() {
|
|
5358
|
+
this.inFlightOperations = new Map();
|
|
5359
|
+
}
|
|
5360
|
+
/**
|
|
5361
|
+
* Executes an operation once per key while returning the same in-flight promise
|
|
5362
|
+
* to all concurrent callers.
|
|
5363
|
+
* @param key - Unique identifier for dedupe scope.
|
|
5364
|
+
* @param operation - The async operation to execute.
|
|
5365
|
+
*/
|
|
5366
|
+
withDedupe(key, operation) {
|
|
5367
|
+
const existingOperation = this.inFlightOperations.get(key);
|
|
5368
|
+
if (existingOperation) {
|
|
5369
|
+
return existingOperation;
|
|
5370
|
+
}
|
|
5371
|
+
const operationPromise = Promise.resolve()
|
|
5372
|
+
.then(operation)
|
|
5373
|
+
.finally(() => {
|
|
5374
|
+
this.inFlightOperations.delete(key);
|
|
5375
|
+
});
|
|
5376
|
+
this.inFlightOperations.set(key, operationPromise);
|
|
5377
|
+
return operationPromise;
|
|
5378
|
+
}
|
|
5379
|
+
/**
|
|
5380
|
+
* Check if a specific operation is currently in flight.
|
|
5381
|
+
*/
|
|
5382
|
+
isInFlight(key) {
|
|
5383
|
+
return this.inFlightOperations.has(key);
|
|
5384
|
+
}
|
|
5385
|
+
/**
|
|
5386
|
+
* Clear all tracked in-flight operations (primarily for tests/cleanup).
|
|
5387
|
+
*/
|
|
5388
|
+
clearAll() {
|
|
5389
|
+
this.inFlightOperations.clear();
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5392
|
+
|
|
5275
5393
|
function isValidInput(input) {
|
|
5276
5394
|
// Allow alphanumeric characters, hyphens, and underscores.
|
|
5277
5395
|
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
@@ -5569,6 +5687,16 @@ class Api {
|
|
|
5569
5687
|
* @secure
|
|
5570
5688
|
*/
|
|
5571
5689
|
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)),
|
|
5690
|
+
/**
|
|
5691
|
+
* No description
|
|
5692
|
+
*
|
|
5693
|
+
* @tags Auth
|
|
5694
|
+
* @name IssueJwtToken
|
|
5695
|
+
* @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.
|
|
5696
|
+
* @request POST:/api/v1/auth/issue-jwt-token
|
|
5697
|
+
* @secure
|
|
5698
|
+
*/
|
|
5699
|
+
issueJwtToken: (params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/issue-jwt-token`, method: "POST", secure: true, format: "json" }, params)),
|
|
5572
5700
|
/**
|
|
5573
5701
|
* No description
|
|
5574
5702
|
*
|
|
@@ -6067,6 +6195,20 @@ class Api {
|
|
|
6067
6195
|
if (params === void 0) { params = {}; }
|
|
6068
6196
|
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/assets`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6069
6197
|
},
|
|
6198
|
+
/**
|
|
6199
|
+
* No description
|
|
6200
|
+
*
|
|
6201
|
+
* @tags Wallets
|
|
6202
|
+
* @name GetWalletAddresses
|
|
6203
|
+
* @summary Get all assets that exist in a certain wallet, by specifying a wallet ID
|
|
6204
|
+
* @request GET:/api/v1/wallets/{walletId}/addresses
|
|
6205
|
+
* @secure
|
|
6206
|
+
*/
|
|
6207
|
+
getWalletAddresses: (_a, params) => {
|
|
6208
|
+
var { walletId } = _a, query = __rest(_a, ["walletId"]);
|
|
6209
|
+
if (params === void 0) { params = {}; }
|
|
6210
|
+
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/addresses`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6211
|
+
},
|
|
6070
6212
|
/**
|
|
6071
6213
|
* No description
|
|
6072
6214
|
*
|
|
@@ -6266,23 +6408,35 @@ class Api {
|
|
|
6266
6408
|
/**
|
|
6267
6409
|
* No description
|
|
6268
6410
|
*
|
|
6269
|
-
* @tags Transactions, Transactions
|
|
6411
|
+
* @tags Transactions, Transactions
|
|
6270
6412
|
* @name DetectTransferRestriction
|
|
6271
6413
|
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6272
6414
|
* @request GET:/api/v1/transactions/detect-transfers-restrictions
|
|
6415
|
+
* @deprecated
|
|
6273
6416
|
* @secure
|
|
6274
6417
|
*/
|
|
6275
6418
|
detectTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/detect-transfers-restrictions`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6276
6419
|
/**
|
|
6277
6420
|
* No description
|
|
6278
6421
|
*
|
|
6279
|
-
* @tags Transactions, Transactions
|
|
6422
|
+
* @tags Transactions, Transactions
|
|
6280
6423
|
* @name FetchMessageForTransferRestriction
|
|
6281
6424
|
* @summary Request restriction message by providing a restriction code
|
|
6282
6425
|
* @request GET:/api/v1/transactions/transfer-restriction-message
|
|
6426
|
+
* @deprecated
|
|
6283
6427
|
* @secure
|
|
6284
6428
|
*/
|
|
6285
6429
|
fetchMessageForTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/transfer-restriction-message`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6430
|
+
/**
|
|
6431
|
+
* No description
|
|
6432
|
+
*
|
|
6433
|
+
* @tags Transactions, Transactions
|
|
6434
|
+
* @name GetRestriction
|
|
6435
|
+
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6436
|
+
* @request GET:/api/v1/transactions/restriction
|
|
6437
|
+
* @secure
|
|
6438
|
+
*/
|
|
6439
|
+
getRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/restriction`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6286
6440
|
/**
|
|
6287
6441
|
* No description
|
|
6288
6442
|
*
|
|
@@ -6710,6 +6864,48 @@ function objectToQueryParams(obj) {
|
|
|
6710
6864
|
return params.toString();
|
|
6711
6865
|
}
|
|
6712
6866
|
|
|
6867
|
+
const refreshableAuth401ErrorCodes = new Set([
|
|
6868
|
+
exports.ErrorResponseCodes.auth_api_jwt_invalid,
|
|
6869
|
+
exports.ErrorResponseCodes.auth_api_jwt_not_active,
|
|
6870
|
+
exports.ErrorResponseCodes.auth_api_jwt_not_provided,
|
|
6871
|
+
exports.ErrorResponseCodes.auth_api_jwt_expired,
|
|
6872
|
+
exports.ErrorResponseCodes.auth_api_unauthorized,
|
|
6873
|
+
]);
|
|
6874
|
+
const clearTokensOnRefreshFailureErrorCodes = new Set([
|
|
6875
|
+
exports.ErrorResponseCodes.auth_refresh_token_not_found,
|
|
6876
|
+
exports.ErrorResponseCodes.auth_refresh_token_expired,
|
|
6877
|
+
exports.ErrorResponseCodes.auth_refresh_token_reuse_detected,
|
|
6878
|
+
]);
|
|
6879
|
+
function extractErrorStatus(error) {
|
|
6880
|
+
var _a, _b, _c, _d, _e;
|
|
6881
|
+
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;
|
|
6882
|
+
}
|
|
6883
|
+
function extractErrorCode(error) {
|
|
6884
|
+
var _a, _b, _c, _d;
|
|
6885
|
+
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;
|
|
6886
|
+
}
|
|
6887
|
+
function shouldAttemptTokenRefresh(error) {
|
|
6888
|
+
const status = extractErrorStatus(error);
|
|
6889
|
+
if (status !== 401) {
|
|
6890
|
+
return false;
|
|
6891
|
+
}
|
|
6892
|
+
const errorCode = extractErrorCode(error);
|
|
6893
|
+
if (!errorCode) {
|
|
6894
|
+
// Backward compatibility: some endpoints may not provide explicit errorCode.
|
|
6895
|
+
return true;
|
|
6896
|
+
}
|
|
6897
|
+
return refreshableAuth401ErrorCodes.has(errorCode);
|
|
6898
|
+
}
|
|
6899
|
+
function shouldClearTokensAfterRefreshFailure(error) {
|
|
6900
|
+
const status = extractErrorStatus(error);
|
|
6901
|
+
const errorCode = extractErrorCode(error);
|
|
6902
|
+
// Any 401 clears tokens (preserves prior behavior). The error-code set additionally
|
|
6903
|
+
// covers refresh-token failures that arrive with a non-401 status (e.g. 400/403).
|
|
6904
|
+
return status === 401 || (!!errorCode && clearTokensOnRefreshFailureErrorCodes.has(errorCode));
|
|
6905
|
+
}
|
|
6906
|
+
|
|
6907
|
+
// Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
|
|
6908
|
+
const refreshDedupeManager = new DedupeManagerService();
|
|
6713
6909
|
class Base {
|
|
6714
6910
|
constructor(config) {
|
|
6715
6911
|
var _a, _b;
|
|
@@ -6739,35 +6935,45 @@ class Base {
|
|
|
6739
6935
|
});
|
|
6740
6936
|
/**
|
|
6741
6937
|
* This intercepts all API responses and transforms errors into WallabyError format.
|
|
6938
|
+
* On a 401, it performs a single token refresh then retries (reactive guard).
|
|
6742
6939
|
*/
|
|
6743
6940
|
const originalRequest = httpClient.request.bind(httpClient);
|
|
6744
6941
|
httpClient.request = async (params) => {
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6942
|
+
const attemptRequest = async (retried) => {
|
|
6943
|
+
try {
|
|
6944
|
+
return await originalRequest(params);
|
|
6945
|
+
}
|
|
6946
|
+
catch (error) {
|
|
6947
|
+
// Reactive 401 handling for the generated client: refresh once and retry
|
|
6948
|
+
if (!retried && shouldAttemptTokenRefresh(error)) {
|
|
6949
|
+
await this._performTokenRefresh();
|
|
6950
|
+
// securityWorker will re-fetch the new access token on retry
|
|
6951
|
+
return attemptRequest(true);
|
|
6952
|
+
}
|
|
6953
|
+
// Transform the generated API error format into WallabyError
|
|
6954
|
+
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6955
|
+
const apiError = error.error;
|
|
6956
|
+
throw new WallabyError({
|
|
6957
|
+
message: apiError.message || 'API request failed',
|
|
6958
|
+
statusCode: apiError.statusCode || 500,
|
|
6959
|
+
errorCode: apiError.errorCode,
|
|
6960
|
+
data: apiError,
|
|
6961
|
+
});
|
|
6962
|
+
}
|
|
6963
|
+
// Re-throw if already a WallabyError
|
|
6964
|
+
if (error instanceof WallabyError) {
|
|
6965
|
+
throw error;
|
|
6966
|
+
}
|
|
6967
|
+
// Wrap any other errors
|
|
6752
6968
|
throw new WallabyError({
|
|
6753
|
-
message:
|
|
6754
|
-
statusCode:
|
|
6755
|
-
errorCode:
|
|
6756
|
-
data:
|
|
6969
|
+
message: error.message || 'Unknown error occurred',
|
|
6970
|
+
statusCode: error.statusCode || 500,
|
|
6971
|
+
errorCode: error.errorCode,
|
|
6972
|
+
data: error,
|
|
6757
6973
|
});
|
|
6758
6974
|
}
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
throw error;
|
|
6762
|
-
}
|
|
6763
|
-
// Wrap any other errors
|
|
6764
|
-
throw new WallabyError({
|
|
6765
|
-
message: error.message || 'Unknown error occurred',
|
|
6766
|
-
statusCode: error.statusCode || 500,
|
|
6767
|
-
errorCode: error.errorCode,
|
|
6768
|
-
data: error,
|
|
6769
|
-
});
|
|
6770
|
-
}
|
|
6975
|
+
};
|
|
6976
|
+
return attemptRequest(false);
|
|
6771
6977
|
};
|
|
6772
6978
|
this.api = new Api(httpClient);
|
|
6773
6979
|
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));
|
|
@@ -6848,15 +7054,51 @@ class Base {
|
|
|
6848
7054
|
environment: this.settings.environment,
|
|
6849
7055
|
});
|
|
6850
7056
|
}
|
|
7057
|
+
/**
|
|
7058
|
+
* Fetches a new access/refresh token pair using the stored refresh token.
|
|
7059
|
+
* All concurrent callers share the same in-flight promise via the module-level
|
|
7060
|
+
* `refreshDedupeManager` so only one network request is issued per user/environment scope.
|
|
7061
|
+
*/
|
|
7062
|
+
async _performTokenRefresh() {
|
|
7063
|
+
const refreshDedupeKey = `refresh:${this.userId}:${this.settings.environment}:${this.settings.network}`;
|
|
7064
|
+
await refreshDedupeManager.withDedupe(refreshDedupeKey, async () => {
|
|
7065
|
+
const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
|
|
7066
|
+
if (!refreshToken) {
|
|
7067
|
+
return;
|
|
7068
|
+
}
|
|
7069
|
+
try {
|
|
7070
|
+
const response = await this.request(AuthRoutes.refreshAccessToken, {
|
|
7071
|
+
payload: { refreshToken },
|
|
7072
|
+
});
|
|
7073
|
+
await this.localStorageService.save(exports.LocalStorageItems.AccessToken, response.accessToken);
|
|
7074
|
+
await this.localStorageService.save(exports.LocalStorageItems.RefreshToken, response.refreshToken);
|
|
7075
|
+
}
|
|
7076
|
+
catch (error) {
|
|
7077
|
+
if (shouldClearTokensAfterRefreshFailure(error)) {
|
|
7078
|
+
await this.localStorageService.delete(exports.LocalStorageItems.AccessToken);
|
|
7079
|
+
await this.localStorageService.delete(exports.LocalStorageItems.RefreshToken);
|
|
7080
|
+
}
|
|
7081
|
+
throw error;
|
|
7082
|
+
}
|
|
7083
|
+
});
|
|
7084
|
+
}
|
|
6851
7085
|
/**
|
|
6852
7086
|
* Main request method for making API calls to the Wallaby API.
|
|
6853
7087
|
* @param route - Route configuration object containing the endpoint path and HTTP method
|
|
6854
7088
|
* @param options - Optional request options including payload and query parameters
|
|
7089
|
+
* @param retried - Internal flag; set to true when retrying after a 401 to prevent loops
|
|
6855
7090
|
* @returns Promise resolving to the typed response data
|
|
6856
7091
|
* @throws Error if the API returns an error response or network failure occurs
|
|
6857
7092
|
*/
|
|
6858
|
-
async request(route, options) {
|
|
7093
|
+
async request(route, options, retried = false) {
|
|
6859
7094
|
var _a;
|
|
7095
|
+
// Proactive token refresh: if access token is near expiry, refresh before making the request
|
|
7096
|
+
if (route !== AuthRoutes.refreshAccessToken && !retried) {
|
|
7097
|
+
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7098
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7099
|
+
await this._performTokenRefresh();
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
6860
7102
|
const path = typeof route.fullPath === 'string' ? route.fullPath : route.fullPath(options === null || options === void 0 ? void 0 : options.payload);
|
|
6861
7103
|
// Add query parameters to the path if provided
|
|
6862
7104
|
let finalPath = path;
|
|
@@ -6910,6 +7152,11 @@ class Base {
|
|
|
6910
7152
|
return data;
|
|
6911
7153
|
}
|
|
6912
7154
|
catch (error) {
|
|
7155
|
+
// Reactive token refresh: on 401, refresh once and retry the original request
|
|
7156
|
+
if (!retried && route !== AuthRoutes.refreshAccessToken && shouldAttemptTokenRefresh(error)) {
|
|
7157
|
+
await this._performTokenRefresh();
|
|
7158
|
+
return this.request(route, options, true);
|
|
7159
|
+
}
|
|
6913
7160
|
if (error === null || error === void 0 ? void 0 : error.error) {
|
|
6914
7161
|
logger.error('SDK::Base::handleApiCall::API Error', { error });
|
|
6915
7162
|
const apiError = error.error;
|
|
@@ -6962,6 +7209,16 @@ class Base {
|
|
|
6962
7209
|
return headers;
|
|
6963
7210
|
}
|
|
6964
7211
|
async securityWorker(securityData) {
|
|
7212
|
+
// Proactive token refresh before building headers for the generated client
|
|
7213
|
+
try {
|
|
7214
|
+
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7215
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7216
|
+
await this._performTokenRefresh();
|
|
7217
|
+
}
|
|
7218
|
+
}
|
|
7219
|
+
catch (_a) {
|
|
7220
|
+
// Best-effort proactive refresh; proceed even if it fails
|
|
7221
|
+
}
|
|
6965
7222
|
// Start with the security data that contains API key and JWT
|
|
6966
7223
|
const headers = Object.assign({ 'Content-Type': 'application/json' }, (securityData || {}));
|
|
6967
7224
|
// Add access token if available
|
|
@@ -6971,7 +7228,7 @@ class Base {
|
|
|
6971
7228
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
6972
7229
|
}
|
|
6973
7230
|
}
|
|
6974
|
-
catch (
|
|
7231
|
+
catch (_b) {
|
|
6975
7232
|
// Access token is optional, continue without it
|
|
6976
7233
|
}
|
|
6977
7234
|
return {
|
|
@@ -7098,49 +7355,6 @@ const WalletRoutes = {
|
|
|
7098
7355
|
},
|
|
7099
7356
|
};
|
|
7100
7357
|
|
|
7101
|
-
const AuthRoutes = {
|
|
7102
|
-
signatureMessage: {
|
|
7103
|
-
fullPath: '/auth/signature-message',
|
|
7104
|
-
method: exports.RequestMethod.Post,
|
|
7105
|
-
requiresAccessToken: false,
|
|
7106
|
-
},
|
|
7107
|
-
signIn: {
|
|
7108
|
-
fullPath: '/auth/sign-in',
|
|
7109
|
-
method: exports.RequestMethod.Post,
|
|
7110
|
-
requiresAccessToken: false,
|
|
7111
|
-
},
|
|
7112
|
-
signUp: {
|
|
7113
|
-
fullPath: '/auth/sign-up',
|
|
7114
|
-
method: exports.RequestMethod.Post,
|
|
7115
|
-
requiresAccessToken: false,
|
|
7116
|
-
},
|
|
7117
|
-
refreshAccessToken: {
|
|
7118
|
-
fullPath: '/auth/refresh-access-token',
|
|
7119
|
-
method: exports.RequestMethod.Post,
|
|
7120
|
-
requiresAccessToken: true,
|
|
7121
|
-
},
|
|
7122
|
-
clientAuthPubKey: {
|
|
7123
|
-
fullPath: 'auth/client-auth-pubkey',
|
|
7124
|
-
method: exports.RequestMethod.Put,
|
|
7125
|
-
requiresAccessToken: true,
|
|
7126
|
-
},
|
|
7127
|
-
wallabyAuthPublicKey: {
|
|
7128
|
-
fullPath: '/auth/wallaby-auth-pubkey',
|
|
7129
|
-
method: exports.RequestMethod.Get,
|
|
7130
|
-
requiresAccessToken: true,
|
|
7131
|
-
},
|
|
7132
|
-
getUserSalt: {
|
|
7133
|
-
fullPath: '/users/salt',
|
|
7134
|
-
method: exports.RequestMethod.Get,
|
|
7135
|
-
requiresAccessToken: true,
|
|
7136
|
-
},
|
|
7137
|
-
getPasskeyCredentials: {
|
|
7138
|
-
fullPath: '/auth/passkey-credentials',
|
|
7139
|
-
method: exports.RequestMethod.Get,
|
|
7140
|
-
requiresAccessToken: true,
|
|
7141
|
-
},
|
|
7142
|
-
};
|
|
7143
|
-
|
|
7144
7358
|
const SystemRoutes = {
|
|
7145
7359
|
getSupportedBlockchains: {
|
|
7146
7360
|
fullPath: '/chains',
|
|
@@ -7196,7 +7410,22 @@ const TransactionsRoutes = {
|
|
|
7196
7410
|
requiresAccessToken: true,
|
|
7197
7411
|
},
|
|
7198
7412
|
getTransactions: {
|
|
7199
|
-
fullPath: '/
|
|
7413
|
+
fullPath: '/transactions',
|
|
7414
|
+
method: exports.RequestMethod.Get,
|
|
7415
|
+
requiresAccessToken: true,
|
|
7416
|
+
},
|
|
7417
|
+
detectTransferRestrictions: {
|
|
7418
|
+
fullPath: '/transactions/detect-transfers-restrictions',
|
|
7419
|
+
method: exports.RequestMethod.Get,
|
|
7420
|
+
requiresAccessToken: true,
|
|
7421
|
+
},
|
|
7422
|
+
transferRestrictionMessage: {
|
|
7423
|
+
fullPath: '/transactions/transfer-restriction-message',
|
|
7424
|
+
method: exports.RequestMethod.Get,
|
|
7425
|
+
requiresAccessToken: true,
|
|
7426
|
+
},
|
|
7427
|
+
restriction: {
|
|
7428
|
+
fullPath: '/transactions/restriction',
|
|
7200
7429
|
method: exports.RequestMethod.Get,
|
|
7201
7430
|
requiresAccessToken: true,
|
|
7202
7431
|
},
|
|
@@ -7922,6 +8151,33 @@ class AuthService extends Base {
|
|
|
7922
8151
|
const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
|
|
7923
8152
|
return (!!accessToken && !jwtHasExpired(accessToken)) || !!refreshToken;
|
|
7924
8153
|
}
|
|
8154
|
+
/**
|
|
8155
|
+
* @description Refreshes auth tokens using the stored refresh token.
|
|
8156
|
+
*/
|
|
8157
|
+
async refreshAuthTokens() {
|
|
8158
|
+
const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
|
|
8159
|
+
if (!refreshToken) {
|
|
8160
|
+
throw new WallabyError({
|
|
8161
|
+
message: 'Refresh token is required',
|
|
8162
|
+
statusCode: 401,
|
|
8163
|
+
errorCode: exports.ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8164
|
+
});
|
|
8165
|
+
}
|
|
8166
|
+
await this._performTokenRefresh();
|
|
8167
|
+
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
8168
|
+
const newRefreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
|
|
8169
|
+
if (!accessToken || !newRefreshToken) {
|
|
8170
|
+
throw new WallabyError({
|
|
8171
|
+
message: 'Token refresh failed: tokens not present in storage after refresh',
|
|
8172
|
+
statusCode: 401,
|
|
8173
|
+
errorCode: exports.ErrorResponseCodes.sdk_refresh_token_missing,
|
|
8174
|
+
});
|
|
8175
|
+
}
|
|
8176
|
+
return {
|
|
8177
|
+
accessToken,
|
|
8178
|
+
refreshToken: newRefreshToken,
|
|
8179
|
+
};
|
|
8180
|
+
}
|
|
7925
8181
|
/**
|
|
7926
8182
|
* @description Validates the user's password by decrypting the stored private key.
|
|
7927
8183
|
* @returns { boolean } Returns true if the password is valid, false otherwise.
|
|
@@ -9195,6 +9451,17 @@ class WalletService extends Base {
|
|
|
9195
9451
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9196
9452
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9197
9453
|
});
|
|
9454
|
+
// Guard against persisting an empty/invalid re-wrap, which would lock the user out of
|
|
9455
|
+
// their device private key (the one mandatory item) under the new password. The type says
|
|
9456
|
+
// this is always defined, but we defend against a runtime contract violation regardless.
|
|
9457
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
9458
|
+
if (!reWrappedDevicePrivateKey) {
|
|
9459
|
+
throw new WallabyError({
|
|
9460
|
+
message: 'Failed to re-wrap device private key during password change.',
|
|
9461
|
+
statusCode: 500,
|
|
9462
|
+
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9463
|
+
});
|
|
9464
|
+
}
|
|
9198
9465
|
await this.localStorageService.save(exports.LocalStorageItems.EncryptedDevicePrivateKey, reWrappedDevicePrivateKey);
|
|
9199
9466
|
if (encryptedSeedPhraseString) {
|
|
9200
9467
|
const parsedSeed = safeJsonParse(encryptedSeedPhraseString);
|
|
@@ -9957,6 +10224,7 @@ class WalletService extends Base {
|
|
|
9957
10224
|
storeSeedPhrase: false,
|
|
9958
10225
|
returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
9959
10226
|
walletId: input.walletId,
|
|
10227
|
+
reference: uuid.v4(),
|
|
9960
10228
|
keyShareOptions: {
|
|
9961
10229
|
threshold: 2,
|
|
9962
10230
|
numberOfKeyShares: 3,
|
|
@@ -10841,6 +11109,7 @@ class Swap extends Base {
|
|
|
10841
11109
|
});
|
|
10842
11110
|
}
|
|
10843
11111
|
else {
|
|
11112
|
+
// Unreachable in practice: prepareSwapAuth throws sdk_seed_phrase_not_found before we get here; kept as a defensive guard.
|
|
10844
11113
|
throw new WallabyError({
|
|
10845
11114
|
message: 'No valid seed option found on this device.',
|
|
10846
11115
|
statusCode: 400,
|
|
@@ -11262,27 +11531,54 @@ class Transactions extends Base {
|
|
|
11262
11531
|
/**
|
|
11263
11532
|
*
|
|
11264
11533
|
* @public
|
|
11265
|
-
* @param {
|
|
11266
|
-
* @
|
|
11267
|
-
* @param {TokenStandard} tokenStandard an optional param used when dealing with non native assets
|
|
11268
|
-
* @returns {Promise<{ address: string; transactions: Transaction[] }>}
|
|
11534
|
+
* @param {GetTransactionsParams} params - Query parameters for filtering and paginating transactions
|
|
11535
|
+
* @returns {GetTransactionsResponseDto} Paginated list of transactions matching the given criteria
|
|
11269
11536
|
*/
|
|
11270
|
-
async getTransactions(
|
|
11537
|
+
async getTransactions(params) {
|
|
11271
11538
|
try {
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
address,
|
|
11275
|
-
tokenSymbol: symbol,
|
|
11276
|
-
tokenType: tokenStandard,
|
|
11277
|
-
},
|
|
11539
|
+
return await this.request(TransactionsRoutes.getTransactions, {
|
|
11540
|
+
queryParams: params,
|
|
11278
11541
|
});
|
|
11279
|
-
return response;
|
|
11280
11542
|
}
|
|
11281
11543
|
catch (error) {
|
|
11282
11544
|
logger.error('SDK::Transactions::getTransactions::error', error);
|
|
11283
11545
|
throw error;
|
|
11284
11546
|
}
|
|
11285
11547
|
}
|
|
11548
|
+
/**
|
|
11549
|
+
*
|
|
11550
|
+
* @public
|
|
11551
|
+
* @param {GetRestrictionParams} params - Parameters to detect transfer restrictions (addresses, asset, value)
|
|
11552
|
+
* - {string} fromAddress
|
|
11553
|
+
* - {string} toAddress
|
|
11554
|
+
* - {string} amount
|
|
11555
|
+
* - [string] assetId
|
|
11556
|
+
* - [string] contractAddress
|
|
11557
|
+
* - [BlockchainName] blockchainName
|
|
11558
|
+
* @returns {Promise<DetectRestrictionResponseDto>}
|
|
11559
|
+
* Detection result; when transfer is blocked, also includes the human-readable restriction message and a boolean canTransfer
|
|
11560
|
+
*/
|
|
11561
|
+
async getRestriction(params) {
|
|
11562
|
+
try {
|
|
11563
|
+
const hasAssetId = Boolean(params.assetId);
|
|
11564
|
+
const hasContractAndChain = Boolean(params.contractAddress && params.blockchainName);
|
|
11565
|
+
if (!hasAssetId && !hasContractAndChain) {
|
|
11566
|
+
throw new WallabyError({
|
|
11567
|
+
message: 'Either assetId or both contractAddress and blockchainName must be provided.',
|
|
11568
|
+
statusCode: 400,
|
|
11569
|
+
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
11570
|
+
});
|
|
11571
|
+
}
|
|
11572
|
+
const restrictionData = await this.request(TransactionsRoutes.restriction, {
|
|
11573
|
+
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 })),
|
|
11574
|
+
});
|
|
11575
|
+
return restrictionData;
|
|
11576
|
+
}
|
|
11577
|
+
catch (error) {
|
|
11578
|
+
logger.error('SDK::Transactions::getRestriction::error', error);
|
|
11579
|
+
throw error;
|
|
11580
|
+
}
|
|
11581
|
+
}
|
|
11286
11582
|
/**
|
|
11287
11583
|
*
|
|
11288
11584
|
* @public
|
|
@@ -11617,6 +11913,12 @@ class Transactions extends Base {
|
|
|
11617
11913
|
});
|
|
11618
11914
|
}
|
|
11619
11915
|
}
|
|
11916
|
+
__decorate([
|
|
11917
|
+
WithLock('transaction-restriction-message'),
|
|
11918
|
+
__metadata("design:type", Function),
|
|
11919
|
+
__metadata("design:paramtypes", [Object]),
|
|
11920
|
+
__metadata("design:returntype", Promise)
|
|
11921
|
+
], Transactions.prototype, "getRestriction", null);
|
|
11620
11922
|
__decorate([
|
|
11621
11923
|
WithLock('transfer'),
|
|
11622
11924
|
__metadata("design:type", Function),
|