wallaby-cash 2.3.7-alpha.0 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/base.d.ts CHANGED
@@ -42,7 +42,6 @@ export declare abstract class Base {
42
42
  * @throws Error if the API returns an error response or network failure occurs
43
43
  */
44
44
  protected request<T>(route: RequestRoute, options?: RequestOptions): Promise<T>;
45
- private mapCategoryToErrorCode;
46
45
  private _getRequestHeaders;
47
46
  protected securityWorker(securityData: any): Promise<any>;
48
47
  }
package/dist/index.cjs.js CHANGED
@@ -108,11 +108,10 @@ exports.TransportEnum = void 0;
108
108
  * @property {string} [errorCode] - Specific error code for categorizing the error.
109
109
  * @property {any} [data] - Additional data related to the error.
110
110
  * @property {number} [status] - Alias for statusCode for compatibility.
111
- * @property {NetworkDiagnosticResult} [networkDiagnostic] - Optional network diagnostic information for network-related errors.
112
111
  */
113
112
  class WallabyError extends Error {
114
113
  constructor(errorPayload) {
115
- const { message, statusCode, errorCode, data, cause, onError, networkDiagnostic } = errorPayload;
114
+ const { message, statusCode, errorCode, data, cause, onError } = errorPayload;
116
115
  super(message);
117
116
  this.name = 'WallabyError';
118
117
  this.status = statusCode;
@@ -120,7 +119,6 @@ class WallabyError extends Error {
120
119
  this.cause = cause;
121
120
  this.onError = onError;
122
121
  this.data = data;
123
- this.networkDiagnostic = networkDiagnostic;
124
122
  Error.captureStackTrace(this, WallabyError);
125
123
  }
126
124
  static isWallabyError(error) {
@@ -400,12 +398,6 @@ exports.ErrorResponseCodes = void 0;
400
398
  ErrorResponseCodes["sdk_passkey_challenge_unavailable"] = "sdk_passkey_challenge_unavailable";
401
399
  ErrorResponseCodes["sdk_passkey_authentication_failed"] = "sdk_passkey_authentication_failed";
402
400
  ErrorResponseCodes["sdk_passkey_registration_failed"] = "sdk_passkey_registration_failed";
403
- // network diagnostic errors
404
- ErrorResponseCodes["sdk_network_offline"] = "sdk_network_offline";
405
- ErrorResponseCodes["sdk_network_connectivity"] = "sdk_network_connectivity";
406
- ErrorResponseCodes["sdk_network_likely_cors_or_auth"] = "sdk_network_likely_cors_or_auth";
407
- ErrorResponseCodes["sdk_network_fast_failure"] = "sdk_network_fast_failure";
408
- ErrorResponseCodes["sdk_network_unknown"] = "sdk_network_unknown";
409
401
  })(exports.ErrorResponseCodes || (exports.ErrorResponseCodes = {}));
410
402
 
411
403
  const UnknownError = {
@@ -562,12 +554,12 @@ const global$1 = (typeof global !== "undefined" ? global :
562
554
  var env = {};
563
555
 
564
556
  // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
565
- var performance$1 = global$1.performance || {};
566
- performance$1.now ||
567
- performance$1.mozNow ||
568
- performance$1.msNow ||
569
- performance$1.oNow ||
570
- performance$1.webkitNow ||
557
+ var performance = global$1.performance || {};
558
+ performance.now ||
559
+ performance.mozNow ||
560
+ performance.msNow ||
561
+ performance.oNow ||
562
+ performance.webkitNow ||
571
563
  function(){ return (new Date()).getTime() };
572
564
 
573
565
  var browser$1 = {
@@ -607,7 +599,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
607
599
  { type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
608
600
  ];
609
601
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
610
- const currentPackageVersion = "2.3.7-alpha.0" ;
602
+ const currentPackageVersion = "2.3.7" ;
611
603
 
612
604
  /**
613
605
  * Storage keys adapter for Storage interface across different platforms.
@@ -5147,7 +5139,15 @@ class StorageService {
5147
5139
  return undefined;
5148
5140
  }
5149
5141
  async clearLocalStorage(walletId) {
5150
- const userKeysToRemove = [exports.LocalStorageItems.AccessToken, exports.V2KeyNames.EncryptedDevicePrivateKey, exports.V2KeyNames.WallabyAuthPubKey];
5142
+ const userKeysToRemove = [
5143
+ exports.LocalStorageItems.AccessToken,
5144
+ exports.V2KeyNames.EncryptedDevicePrivateKey,
5145
+ exports.V2KeyNames.WallabyAuthPubKey,
5146
+ exports.V2KeyNames.PasskeyCredential,
5147
+ exports.V2KeyNames.MigrationVersion,
5148
+ exports.V2KeyNames.LastMigratedAt,
5149
+ exports.V2KeyNames.ClientAuthToken,
5150
+ ];
5151
5151
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5152
5152
  if (walletId) {
5153
5153
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6844,184 +6844,6 @@ function objectToQueryParams(obj) {
6844
6844
  return params.toString();
6845
6845
  }
6846
6846
 
6847
- var NetworkDiagnosticCategory;
6848
- (function (NetworkDiagnosticCategory) {
6849
- NetworkDiagnosticCategory["OfflineHint"] = "offline_hint";
6850
- NetworkDiagnosticCategory["LikelyCorsOrAuthOrExtension"] = "likely_cors_or_auth_or_extension";
6851
- NetworkDiagnosticCategory["ConnectivityOrDns"] = "connectivity_or_dns";
6852
- NetworkDiagnosticCategory["FastFailureHint"] = "fast_failure_hint";
6853
- NetworkDiagnosticCategory["UnknownNetwork"] = "unknown_network";
6854
- })(NetworkDiagnosticCategory || (NetworkDiagnosticCategory = {}));
6855
-
6856
- const HEALTH_CHECK_TIMEOUT_MS = 5000;
6857
- class NetworkDiagnostic {
6858
- /**
6859
- * Run comprehensive network diagnostics after a fetch failure.
6860
- * Combines multiple signals to determine the likely cause of the failure.
6861
- */
6862
- static async run(context) {
6863
- const { failedUrl, originalError } = context;
6864
- logger.info('Running network diagnostic', { failedUrl, originalError });
6865
- const signals = {
6866
- online: NetworkDiagnostic.getNavigatorOnline(),
6867
- healthCheck: 'unavailable',
6868
- failedRequestUrl: failedUrl,
6869
- };
6870
- const hints = [];
6871
- const resourceTiming = NetworkDiagnostic.getResourceTimingForUrl(failedUrl);
6872
- if (resourceTiming) {
6873
- signals.resourceTiming = {
6874
- nextHopProtocol: resourceTiming.nextHopProtocol,
6875
- duration: resourceTiming.duration,
6876
- transferSize: resourceTiming.transferSize,
6877
- };
6878
- if (resourceTiming.duration < 50) {
6879
- hints.push('Very fast failure may indicate a local blocker or extension.');
6880
- }
6881
- }
6882
- const healthUrl = NetworkDiagnostic.deriveHealthUrl(failedUrl);
6883
- signals.healthCheck = await NetworkDiagnostic.simpleHealthCheck(healthUrl);
6884
- const category = NetworkDiagnostic.determineCategory(signals);
6885
- const message = NetworkDiagnostic.getCategoryMessage(category);
6886
- return {
6887
- category,
6888
- message,
6889
- signals,
6890
- hints: hints.length > 0 ? hints : undefined,
6891
- };
6892
- }
6893
- /**
6894
- * Check if navigator.onLine is available and return its value.
6895
- */
6896
- static getNavigatorOnline() {
6897
- if (typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean') {
6898
- return navigator.onLine;
6899
- }
6900
- return 'unknown';
6901
- }
6902
- /**
6903
- * Get the PerformanceResourceTiming entry for the given URL.
6904
- * Returns the most recent entry if multiple matches exist.
6905
- */
6906
- static getResourceTimingForUrl(url) {
6907
- if (typeof performance === 'undefined' || typeof performance.getEntriesByType !== 'function') {
6908
- return undefined;
6909
- }
6910
- try {
6911
- const entries = performance.getEntriesByType('resource');
6912
- const matchingEntries = entries.filter((entry) => entry.name && entry.name.includes(url));
6913
- if (matchingEntries.length === 0) {
6914
- return undefined;
6915
- }
6916
- return matchingEntries[matchingEntries.length - 1];
6917
- }
6918
- catch (_a) {
6919
- return undefined;
6920
- }
6921
- }
6922
- /**
6923
- * Perform a simple no-cors health check to the `/healthz` endpoint.
6924
- * This uses mode: 'no-cors' to avoid CORS preflight and credential issues.
6925
- */
6926
- static async simpleHealthCheck(healthUrl) {
6927
- if (typeof fetch === 'undefined') {
6928
- return 'unavailable';
6929
- }
6930
- const controller = new AbortController();
6931
- const timeoutId = setTimeout(() => controller.abort(), HEALTH_CHECK_TIMEOUT_MS);
6932
- try {
6933
- const response = await fetch(healthUrl, {
6934
- method: 'HEAD',
6935
- mode: 'no-cors',
6936
- cache: 'no-store',
6937
- signal: controller.signal,
6938
- });
6939
- if (response.type === 'opaque') {
6940
- return 'ok';
6941
- }
6942
- return 'failed';
6943
- }
6944
- catch (_a) {
6945
- return 'failed';
6946
- }
6947
- finally {
6948
- clearTimeout(timeoutId);
6949
- }
6950
- }
6951
- /**
6952
- * Derive the health check URL from the base URL origin and `/healthz`.
6953
- */
6954
- static deriveHealthUrl(baseUrl) {
6955
- try {
6956
- const url = new URL(baseUrl);
6957
- const origin = url.origin;
6958
- return `${origin}/healthz`;
6959
- }
6960
- catch (_a) {
6961
- return `${baseUrl}/healthz`;
6962
- }
6963
- }
6964
- /**
6965
- * Determine the diagnostic category based on collected signals.
6966
- * Order matters - checks are performed in priority order.
6967
- */
6968
- static determineCategory(signals) {
6969
- if (signals.online === false) {
6970
- return NetworkDiagnosticCategory.OfflineHint;
6971
- }
6972
- if (signals.healthCheck === 'ok') {
6973
- return NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension;
6974
- }
6975
- if (signals.resourceTiming && signals.resourceTiming.duration !== undefined && signals.resourceTiming.duration < 50) {
6976
- return NetworkDiagnosticCategory.FastFailureHint;
6977
- }
6978
- if (signals.healthCheck === 'failed') {
6979
- return NetworkDiagnosticCategory.ConnectivityOrDns;
6980
- }
6981
- return NetworkDiagnosticCategory.UnknownNetwork;
6982
- }
6983
- /**
6984
- * Get a user-facing message for the given diagnostic category.
6985
- */
6986
- static getCategoryMessage(category) {
6987
- switch (category) {
6988
- case NetworkDiagnosticCategory.OfflineHint:
6989
- return 'Device reports offline; check Wi-Fi or mobile data.';
6990
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
6991
- return 'Reachability to the API is OK; the failure may be due to CORS, authentication headers, or a browser extension blocking authenticated requests.';
6992
- case NetworkDiagnosticCategory.ConnectivityOrDns:
6993
- return 'Cannot reach the API host; check DNS, VPN, firewall, or ISP filtering.';
6994
- case NetworkDiagnosticCategory.FastFailureHint:
6995
- return 'Very fast failure may indicate a local blocker or extension.';
6996
- case NetworkDiagnosticCategory.UnknownNetwork:
6997
- default:
6998
- return 'Network request failed; see diagnostic details.';
6999
- }
7000
- }
7001
- /**
7002
- * Check if an error is a network-layer failure candidate that should trigger diagnostics.
7003
- * Returns true for TypeErrors with fetch-related messages, or DOMException with NetworkError name.
7004
- */
7005
- static isNetworkFailureCandidate(error) {
7006
- if (!error)
7007
- return false;
7008
- if (error instanceof TypeError) {
7009
- const message = error.message.toLowerCase();
7010
- return (message.includes('failed to fetch') ||
7011
- message.includes('load failed') ||
7012
- message.includes('networkerror') ||
7013
- message.includes('network request failed'));
7014
- }
7015
- if (error instanceof Error && error.name === 'NetworkError') {
7016
- return true;
7017
- }
7018
- if (typeof DOMException !== 'undefined' && error instanceof DOMException && error.name === 'NetworkError') {
7019
- return true;
7020
- }
7021
- return false;
7022
- }
7023
- }
7024
-
7025
6847
  class Base {
7026
6848
  constructor(config) {
7027
6849
  var _a, _b;
@@ -7072,26 +6894,6 @@ class Base {
7072
6894
  if (error instanceof WallabyError) {
7073
6895
  throw error;
7074
6896
  }
7075
- // Handle network-level failures with diagnostics
7076
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7077
- const fullUrl = `${this.baseUrl.replace(/\/api\/v1\/?$/, '')}${params.path || ''}`;
7078
- const diagnostic = await NetworkDiagnostic.run({
7079
- failedUrl: fullUrl,
7080
- originalError: error,
7081
- });
7082
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7083
- throw new WallabyError({
7084
- message: diagnostic.message,
7085
- statusCode: 0,
7086
- errorCode,
7087
- data: {
7088
- originalError: error,
7089
- networkDiagnostic: diagnostic,
7090
- },
7091
- cause: error.cause,
7092
- networkDiagnostic: diagnostic,
7093
- });
7094
- }
7095
6897
  // Wrap any other errors
7096
6898
  throw new WallabyError({
7097
6899
  message: error.message || 'Unknown error occurred',
@@ -7261,25 +7063,6 @@ class Base {
7261
7063
  name: error.name,
7262
7064
  error,
7263
7065
  });
7264
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7265
- const diagnostic = await NetworkDiagnostic.run({
7266
- failedUrl: fullUrl,
7267
- originalError: error,
7268
- });
7269
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7270
- throw new WallabyError({
7271
- message: diagnostic.message,
7272
- statusCode: 0,
7273
- errorCode,
7274
- data: {
7275
- code: error.name,
7276
- originalError: error,
7277
- networkDiagnostic: diagnostic,
7278
- },
7279
- cause: error.cause,
7280
- networkDiagnostic: diagnostic,
7281
- });
7282
- }
7283
7066
  throw new WallabyError({
7284
7067
  message: error.message || 'Network request failed',
7285
7068
  statusCode: 0,
@@ -7292,20 +7075,6 @@ class Base {
7292
7075
  });
7293
7076
  }
7294
7077
  }
7295
- mapCategoryToErrorCode(category) {
7296
- switch (category) {
7297
- case NetworkDiagnosticCategory.OfflineHint:
7298
- return exports.ErrorResponseCodes.sdk_network_offline;
7299
- case NetworkDiagnosticCategory.ConnectivityOrDns:
7300
- return exports.ErrorResponseCodes.sdk_network_connectivity;
7301
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
7302
- return exports.ErrorResponseCodes.sdk_network_likely_cors_or_auth;
7303
- case NetworkDiagnosticCategory.FastFailureHint:
7304
- return exports.ErrorResponseCodes.sdk_network_fast_failure;
7305
- default:
7306
- return exports.ErrorResponseCodes.sdk_network_unknown;
7307
- }
7308
- }
7309
7078
  async _getRequestHeaders() {
7310
7079
  const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
7311
7080
  if (!isTest && jwtHasExpired(this.clientAuthToken)) {
@@ -7912,9 +7681,10 @@ class PasskeyService {
7912
7681
  errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7913
7682
  });
7914
7683
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7684
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7915
7685
  const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7916
7686
  eval: {
7917
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7687
+ first: prfFirst,
7918
7688
  },
7919
7689
  } }) });
7920
7690
  const passkeyCredential = await this.authenticator.authenticate({
@@ -10213,8 +9983,8 @@ class WalletService extends Base {
10213
9983
  throw error;
10214
9984
  }
10215
9985
  }
10216
- async clearDevice() {
10217
- await this.localStorageService.clearLocalStorage();
9986
+ async clearDevice({ walletId }) {
9987
+ await this.localStorageService.clearLocalStorage(walletId);
10218
9988
  }
10219
9989
  /**
10220
9990
  * Prepares authentication data and encrypted payload for any request.
@@ -12165,7 +11935,6 @@ exports.InvalidUserIdError = InvalidUserIdError;
12165
11935
  exports.InvalidUserIdLengthError = InvalidUserIdLengthError;
12166
11936
  exports.MalformedPubKeyCredParamsError = MalformedPubKeyCredParamsError;
12167
11937
  exports.NativeError = NativeError;
12168
- exports.NetworkDiagnostic = NetworkDiagnostic;
12169
11938
  exports.NoCredentialsError = NoCredentialsError;
12170
11939
  exports.NotAllowedError = NotAllowedError;
12171
11940
  exports.PasskeyErrorCodes = PasskeyErrorCodes;