wallaby-cash 3.1.0 → 3.2.1

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 CHANGED
@@ -34,14 +34,21 @@ export declare abstract class Base {
34
34
  * @protected
35
35
  */
36
36
  get localStorageService(): StorageService;
37
+ /**
38
+ * Fetches a new access/refresh token pair using the stored refresh token.
39
+ * All concurrent callers share the same in-flight promise via the module-level
40
+ * `refreshDedupeManager` so only one network request is issued per user/environment scope.
41
+ */
42
+ protected _performTokenRefresh(): Promise<void>;
37
43
  /**
38
44
  * Main request method for making API calls to the Wallaby API.
39
45
  * @param route - Route configuration object containing the endpoint path and HTTP method
40
46
  * @param options - Optional request options including payload and query parameters
47
+ * @param retried - Internal flag; set to true when retrying after a 401 to prevent loops
41
48
  * @returns Promise resolving to the typed response data
42
49
  * @throws Error if the API returns an error response or network failure occurs
43
50
  */
44
- protected request<T>(route: RequestRoute, options?: RequestOptions): Promise<T>;
51
+ protected request<T>(route: RequestRoute, options?: RequestOptions, retried?: boolean): Promise<T>;
45
52
  private _getRequestHeaders;
46
53
  protected securityWorker(securityData: any): Promise<any>;
47
54
  }
@@ -0,0 +1,4 @@
1
+ export declare function extractErrorStatus(error: any): number | undefined;
2
+ export declare function extractErrorCode(error: any): string | undefined;
3
+ export declare function shouldAttemptTokenRefresh(error: any): boolean;
4
+ export declare function shouldClearTokensAfterRefreshFailure(error: any): boolean;
@@ -0,0 +1,18 @@
1
+ export declare class DedupeManagerService {
2
+ private inFlightOperations;
3
+ /**
4
+ * Executes an operation once per key while returning the same in-flight promise
5
+ * to all concurrent callers.
6
+ * @param key - Unique identifier for dedupe scope.
7
+ * @param operation - The async operation to execute.
8
+ */
9
+ withDedupe<T>(key: string, operation: () => Promise<T>): Promise<T>;
10
+ /**
11
+ * Check if a specific operation is currently in flight.
12
+ */
13
+ isInFlight(key: string): boolean;
14
+ /**
15
+ * Clear all tracked in-flight operations (primarily for tests/cleanup).
16
+ */
17
+ clearAll(): void;
18
+ }
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
- Error.captureStackTrace(this, WallabyError);
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.1.0" ;
621
+ const currentPackageVersion = "3.2.1" ;
602
622
 
603
623
  /**
604
624
  * Storage keys adapter for Storage interface across different platforms.
@@ -5215,6 +5235,19 @@ function userIsMfaVerified(jwt) {
5215
5235
  const jwtDecoded = jwtDecode.jwtDecode(jwt);
5216
5236
  return jwtDecoded.mfaVerified;
5217
5237
  }
5238
+ /**
5239
+ * Checks if a given JWT will expire within the given threshold.
5240
+ *
5241
+ * @param jwt - The JWT string to check. If null, the function returns false.
5242
+ * @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
5243
+ * @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
5244
+ */
5245
+ function isJwtNearExpiry(jwt, thresholdSeconds) {
5246
+ if (!jwt) {
5247
+ return false;
5248
+ }
5249
+ return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
5250
+ }
5218
5251
  /**
5219
5252
  * Calculates the remaining time in milliseconds until a given JWT expires.
5220
5253
  *
@@ -5229,6 +5262,49 @@ function millisecondsToJWTTimeout(jwt) {
5229
5262
  return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
5230
5263
  }
5231
5264
 
5265
+ const AuthRoutes = {
5266
+ signatureMessage: {
5267
+ fullPath: '/auth/signature-message',
5268
+ method: exports.RequestMethod.Post,
5269
+ requiresAccessToken: false,
5270
+ },
5271
+ signIn: {
5272
+ fullPath: '/auth/sign-in',
5273
+ method: exports.RequestMethod.Post,
5274
+ requiresAccessToken: false,
5275
+ },
5276
+ signUp: {
5277
+ fullPath: '/auth/sign-up',
5278
+ method: exports.RequestMethod.Post,
5279
+ requiresAccessToken: false,
5280
+ },
5281
+ refreshAccessToken: {
5282
+ fullPath: '/auth/refresh-access-token',
5283
+ method: exports.RequestMethod.Post,
5284
+ requiresAccessToken: true,
5285
+ },
5286
+ clientAuthPubKey: {
5287
+ fullPath: 'auth/client-auth-pubkey',
5288
+ method: exports.RequestMethod.Put,
5289
+ requiresAccessToken: true,
5290
+ },
5291
+ wallabyAuthPublicKey: {
5292
+ fullPath: '/auth/wallaby-auth-pubkey',
5293
+ method: exports.RequestMethod.Get,
5294
+ requiresAccessToken: true,
5295
+ },
5296
+ getUserSalt: {
5297
+ fullPath: '/users/salt',
5298
+ method: exports.RequestMethod.Get,
5299
+ requiresAccessToken: true,
5300
+ },
5301
+ getPasskeyCredentials: {
5302
+ fullPath: '/auth/passkey-credentials',
5303
+ method: exports.RequestMethod.Get,
5304
+ requiresAccessToken: true,
5305
+ },
5306
+ };
5307
+
5232
5308
  class LockManagerService {
5233
5309
  constructor() {
5234
5310
  this.activeLocks = new Set();
@@ -5272,6 +5348,43 @@ class LockManagerService {
5272
5348
  }
5273
5349
  }
5274
5350
 
5351
+ class DedupeManagerService {
5352
+ constructor() {
5353
+ this.inFlightOperations = new Map();
5354
+ }
5355
+ /**
5356
+ * Executes an operation once per key while returning the same in-flight promise
5357
+ * to all concurrent callers.
5358
+ * @param key - Unique identifier for dedupe scope.
5359
+ * @param operation - The async operation to execute.
5360
+ */
5361
+ withDedupe(key, operation) {
5362
+ const existingOperation = this.inFlightOperations.get(key);
5363
+ if (existingOperation) {
5364
+ return existingOperation;
5365
+ }
5366
+ const operationPromise = Promise.resolve()
5367
+ .then(operation)
5368
+ .finally(() => {
5369
+ this.inFlightOperations.delete(key);
5370
+ });
5371
+ this.inFlightOperations.set(key, operationPromise);
5372
+ return operationPromise;
5373
+ }
5374
+ /**
5375
+ * Check if a specific operation is currently in flight.
5376
+ */
5377
+ isInFlight(key) {
5378
+ return this.inFlightOperations.has(key);
5379
+ }
5380
+ /**
5381
+ * Clear all tracked in-flight operations (primarily for tests/cleanup).
5382
+ */
5383
+ clearAll() {
5384
+ this.inFlightOperations.clear();
5385
+ }
5386
+ }
5387
+
5275
5388
  function isValidInput(input) {
5276
5389
  // Allow alphanumeric characters, hyphens, and underscores.
5277
5390
  const regex = /^[a-zA-Z0-9-_]+$/;
@@ -6710,6 +6823,48 @@ function objectToQueryParams(obj) {
6710
6823
  return params.toString();
6711
6824
  }
6712
6825
 
6826
+ const refreshableAuth401ErrorCodes = new Set([
6827
+ exports.ErrorResponseCodes.auth_api_jwt_invalid,
6828
+ exports.ErrorResponseCodes.auth_api_jwt_not_active,
6829
+ exports.ErrorResponseCodes.auth_api_jwt_not_provided,
6830
+ exports.ErrorResponseCodes.auth_api_jwt_expired,
6831
+ exports.ErrorResponseCodes.auth_api_unauthorized,
6832
+ ]);
6833
+ const clearTokensOnRefreshFailureErrorCodes = new Set([
6834
+ exports.ErrorResponseCodes.auth_refresh_token_not_found,
6835
+ exports.ErrorResponseCodes.auth_refresh_token_expired,
6836
+ exports.ErrorResponseCodes.auth_refresh_token_reuse_detected,
6837
+ ]);
6838
+ function extractErrorStatus(error) {
6839
+ var _a, _b, _c, _d, _e;
6840
+ 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;
6841
+ }
6842
+ function extractErrorCode(error) {
6843
+ var _a, _b, _c, _d;
6844
+ 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;
6845
+ }
6846
+ function shouldAttemptTokenRefresh(error) {
6847
+ const status = extractErrorStatus(error);
6848
+ if (status !== 401) {
6849
+ return false;
6850
+ }
6851
+ const errorCode = extractErrorCode(error);
6852
+ if (!errorCode) {
6853
+ // Backward compatibility: some endpoints may not provide explicit errorCode.
6854
+ return true;
6855
+ }
6856
+ return refreshableAuth401ErrorCodes.has(errorCode);
6857
+ }
6858
+ function shouldClearTokensAfterRefreshFailure(error) {
6859
+ const status = extractErrorStatus(error);
6860
+ const errorCode = extractErrorCode(error);
6861
+ // Any 401 clears tokens (preserves prior behavior). The error-code set additionally
6862
+ // covers refresh-token failures that arrive with a non-401 status (e.g. 400/403).
6863
+ return status === 401 || (!!errorCode && clearTokensOnRefreshFailureErrorCodes.has(errorCode));
6864
+ }
6865
+
6866
+ // Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
6867
+ const refreshDedupeManager = new DedupeManagerService();
6713
6868
  class Base {
6714
6869
  constructor(config) {
6715
6870
  var _a, _b;
@@ -6739,35 +6894,45 @@ class Base {
6739
6894
  });
6740
6895
  /**
6741
6896
  * This intercepts all API responses and transforms errors into WallabyError format.
6897
+ * On a 401, it performs a single token refresh then retries (reactive guard).
6742
6898
  */
6743
6899
  const originalRequest = httpClient.request.bind(httpClient);
6744
6900
  httpClient.request = async (params) => {
6745
- try {
6746
- return await originalRequest(params);
6747
- }
6748
- catch (error) {
6749
- // Transform the generated API error format into WallabyError
6750
- if (error === null || error === void 0 ? void 0 : error.error) {
6751
- const apiError = error.error;
6901
+ const attemptRequest = async (retried) => {
6902
+ try {
6903
+ return await originalRequest(params);
6904
+ }
6905
+ catch (error) {
6906
+ // Reactive 401 handling for the generated client: refresh once and retry
6907
+ if (!retried && shouldAttemptTokenRefresh(error)) {
6908
+ await this._performTokenRefresh();
6909
+ // securityWorker will re-fetch the new access token on retry
6910
+ return attemptRequest(true);
6911
+ }
6912
+ // Transform the generated API error format into WallabyError
6913
+ if (error === null || error === void 0 ? void 0 : error.error) {
6914
+ const apiError = error.error;
6915
+ throw new WallabyError({
6916
+ message: apiError.message || 'API request failed',
6917
+ statusCode: apiError.statusCode || 500,
6918
+ errorCode: apiError.errorCode,
6919
+ data: apiError,
6920
+ });
6921
+ }
6922
+ // Re-throw if already a WallabyError
6923
+ if (error instanceof WallabyError) {
6924
+ throw error;
6925
+ }
6926
+ // Wrap any other errors
6752
6927
  throw new WallabyError({
6753
- message: apiError.message || 'API request failed',
6754
- statusCode: apiError.statusCode || 500,
6755
- errorCode: apiError.errorCode,
6756
- data: apiError,
6928
+ message: error.message || 'Unknown error occurred',
6929
+ statusCode: error.statusCode || 500,
6930
+ errorCode: error.errorCode,
6931
+ data: error,
6757
6932
  });
6758
6933
  }
6759
- // Re-throw if already a WallabyError
6760
- if (error instanceof WallabyError) {
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
- }
6934
+ };
6935
+ return attemptRequest(false);
6771
6936
  };
6772
6937
  this.api = new Api(httpClient);
6773
6938
  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 +7013,51 @@ class Base {
6848
7013
  environment: this.settings.environment,
6849
7014
  });
6850
7015
  }
7016
+ /**
7017
+ * Fetches a new access/refresh token pair using the stored refresh token.
7018
+ * All concurrent callers share the same in-flight promise via the module-level
7019
+ * `refreshDedupeManager` so only one network request is issued per user/environment scope.
7020
+ */
7021
+ async _performTokenRefresh() {
7022
+ const refreshDedupeKey = `refresh:${this.userId}:${this.settings.environment}:${this.settings.network}`;
7023
+ await refreshDedupeManager.withDedupe(refreshDedupeKey, async () => {
7024
+ const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
7025
+ if (!refreshToken) {
7026
+ return;
7027
+ }
7028
+ try {
7029
+ const response = await this.request(AuthRoutes.refreshAccessToken, {
7030
+ payload: { refreshToken },
7031
+ });
7032
+ await this.localStorageService.save(exports.LocalStorageItems.AccessToken, response.accessToken);
7033
+ await this.localStorageService.save(exports.LocalStorageItems.RefreshToken, response.refreshToken);
7034
+ }
7035
+ catch (error) {
7036
+ if (shouldClearTokensAfterRefreshFailure(error)) {
7037
+ await this.localStorageService.delete(exports.LocalStorageItems.AccessToken);
7038
+ await this.localStorageService.delete(exports.LocalStorageItems.RefreshToken);
7039
+ }
7040
+ throw error;
7041
+ }
7042
+ });
7043
+ }
6851
7044
  /**
6852
7045
  * Main request method for making API calls to the Wallaby API.
6853
7046
  * @param route - Route configuration object containing the endpoint path and HTTP method
6854
7047
  * @param options - Optional request options including payload and query parameters
7048
+ * @param retried - Internal flag; set to true when retrying after a 401 to prevent loops
6855
7049
  * @returns Promise resolving to the typed response data
6856
7050
  * @throws Error if the API returns an error response or network failure occurs
6857
7051
  */
6858
- async request(route, options) {
7052
+ async request(route, options, retried = false) {
6859
7053
  var _a;
7054
+ // Proactive token refresh: if access token is near expiry, refresh before making the request
7055
+ if (route !== AuthRoutes.refreshAccessToken && !retried) {
7056
+ const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
7057
+ if (accessToken && isJwtNearExpiry(accessToken, 60)) {
7058
+ await this._performTokenRefresh();
7059
+ }
7060
+ }
6860
7061
  const path = typeof route.fullPath === 'string' ? route.fullPath : route.fullPath(options === null || options === void 0 ? void 0 : options.payload);
6861
7062
  // Add query parameters to the path if provided
6862
7063
  let finalPath = path;
@@ -6910,6 +7111,11 @@ class Base {
6910
7111
  return data;
6911
7112
  }
6912
7113
  catch (error) {
7114
+ // Reactive token refresh: on 401, refresh once and retry the original request
7115
+ if (!retried && route !== AuthRoutes.refreshAccessToken && shouldAttemptTokenRefresh(error)) {
7116
+ await this._performTokenRefresh();
7117
+ return this.request(route, options, true);
7118
+ }
6913
7119
  if (error === null || error === void 0 ? void 0 : error.error) {
6914
7120
  logger.error('SDK::Base::handleApiCall::API Error', { error });
6915
7121
  const apiError = error.error;
@@ -6962,6 +7168,16 @@ class Base {
6962
7168
  return headers;
6963
7169
  }
6964
7170
  async securityWorker(securityData) {
7171
+ // Proactive token refresh before building headers for the generated client
7172
+ try {
7173
+ const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
7174
+ if (accessToken && isJwtNearExpiry(accessToken, 60)) {
7175
+ await this._performTokenRefresh();
7176
+ }
7177
+ }
7178
+ catch (_a) {
7179
+ // Best-effort proactive refresh; proceed even if it fails
7180
+ }
6965
7181
  // Start with the security data that contains API key and JWT
6966
7182
  const headers = Object.assign({ 'Content-Type': 'application/json' }, (securityData || {}));
6967
7183
  // Add access token if available
@@ -6971,7 +7187,7 @@ class Base {
6971
7187
  headers.Authorization = `Bearer ${accessToken}`;
6972
7188
  }
6973
7189
  }
6974
- catch (_a) {
7190
+ catch (_b) {
6975
7191
  // Access token is optional, continue without it
6976
7192
  }
6977
7193
  return {
@@ -7098,49 +7314,6 @@ const WalletRoutes = {
7098
7314
  },
7099
7315
  };
7100
7316
 
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
7317
  const SystemRoutes = {
7145
7318
  getSupportedBlockchains: {
7146
7319
  fullPath: '/chains',
@@ -7922,6 +8095,33 @@ class AuthService extends Base {
7922
8095
  const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
7923
8096
  return (!!accessToken && !jwtHasExpired(accessToken)) || !!refreshToken;
7924
8097
  }
8098
+ /**
8099
+ * @description Refreshes auth tokens using the stored refresh token.
8100
+ */
8101
+ async refreshAuthTokens() {
8102
+ const refreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
8103
+ if (!refreshToken) {
8104
+ throw new WallabyError({
8105
+ message: 'Refresh token is required',
8106
+ statusCode: 401,
8107
+ errorCode: exports.ErrorResponseCodes.sdk_refresh_token_missing,
8108
+ });
8109
+ }
8110
+ await this._performTokenRefresh();
8111
+ const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
8112
+ const newRefreshToken = await this.localStorageService.fetch(exports.LocalStorageItems.RefreshToken);
8113
+ if (!accessToken || !newRefreshToken) {
8114
+ throw new WallabyError({
8115
+ message: 'Token refresh failed: tokens not present in storage after refresh',
8116
+ statusCode: 401,
8117
+ errorCode: exports.ErrorResponseCodes.sdk_refresh_token_missing,
8118
+ });
8119
+ }
8120
+ return {
8121
+ accessToken,
8122
+ refreshToken: newRefreshToken,
8123
+ };
8124
+ }
7925
8125
  /**
7926
8126
  * @description Validates the user's password by decrypting the stored private key.
7927
8127
  * @returns { boolean } Returns true if the password is valid, false otherwise.
@@ -9957,6 +10157,7 @@ class WalletService extends Base {
9957
10157
  storeSeedPhrase: false,
9958
10158
  returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
9959
10159
  walletId: input.walletId,
10160
+ reference: uuid.v4(),
9960
10161
  keyShareOptions: {
9961
10162
  threshold: 2,
9962
10163
  numberOfKeyShares: 3,