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/index.js CHANGED
@@ -79,11 +79,10 @@ var TransportEnum;
79
79
  * @property {string} [errorCode] - Specific error code for categorizing the error.
80
80
  * @property {any} [data] - Additional data related to the error.
81
81
  * @property {number} [status] - Alias for statusCode for compatibility.
82
- * @property {NetworkDiagnosticResult} [networkDiagnostic] - Optional network diagnostic information for network-related errors.
83
82
  */
84
83
  class WallabyError extends Error {
85
84
  constructor(errorPayload) {
86
- const { message, statusCode, errorCode, data, cause, onError, networkDiagnostic } = errorPayload;
85
+ const { message, statusCode, errorCode, data, cause, onError } = errorPayload;
87
86
  super(message);
88
87
  this.name = 'WallabyError';
89
88
  this.status = statusCode;
@@ -91,7 +90,6 @@ class WallabyError extends Error {
91
90
  this.cause = cause;
92
91
  this.onError = onError;
93
92
  this.data = data;
94
- this.networkDiagnostic = networkDiagnostic;
95
93
  Error.captureStackTrace(this, WallabyError);
96
94
  }
97
95
  static isWallabyError(error) {
@@ -371,12 +369,6 @@ var ErrorResponseCodes;
371
369
  ErrorResponseCodes["sdk_passkey_challenge_unavailable"] = "sdk_passkey_challenge_unavailable";
372
370
  ErrorResponseCodes["sdk_passkey_authentication_failed"] = "sdk_passkey_authentication_failed";
373
371
  ErrorResponseCodes["sdk_passkey_registration_failed"] = "sdk_passkey_registration_failed";
374
- // network diagnostic errors
375
- ErrorResponseCodes["sdk_network_offline"] = "sdk_network_offline";
376
- ErrorResponseCodes["sdk_network_connectivity"] = "sdk_network_connectivity";
377
- ErrorResponseCodes["sdk_network_likely_cors_or_auth"] = "sdk_network_likely_cors_or_auth";
378
- ErrorResponseCodes["sdk_network_fast_failure"] = "sdk_network_fast_failure";
379
- ErrorResponseCodes["sdk_network_unknown"] = "sdk_network_unknown";
380
372
  })(ErrorResponseCodes || (ErrorResponseCodes = {}));
381
373
 
382
374
  const UnknownError = {
@@ -533,12 +525,12 @@ const global$1 = (typeof global !== "undefined" ? global :
533
525
  var env$1 = {};
534
526
 
535
527
  // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
536
- var performance$1 = global$1.performance || {};
537
- performance$1.now ||
538
- performance$1.mozNow ||
539
- performance$1.msNow ||
540
- performance$1.oNow ||
541
- performance$1.webkitNow ||
528
+ var performance = global$1.performance || {};
529
+ performance.now ||
530
+ performance.mozNow ||
531
+ performance.msNow ||
532
+ performance.oNow ||
533
+ performance.webkitNow ||
542
534
  function(){ return (new Date()).getTime() };
543
535
 
544
536
  var browser$1 = {
@@ -583,7 +575,7 @@ const env = {
583
575
  isNative: false,
584
576
  isWeb,
585
577
  };
586
- const currentPackageVersion = "2.3.7-alpha.0" ;
578
+ const currentPackageVersion = "2.3.7" ;
587
579
 
588
580
  /**
589
581
  * Storage keys adapter for Storage interface across different platforms.
@@ -5123,7 +5115,15 @@ class StorageService {
5123
5115
  return undefined;
5124
5116
  }
5125
5117
  async clearLocalStorage(walletId) {
5126
- const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5118
+ const userKeysToRemove = [
5119
+ LocalStorageItems.AccessToken,
5120
+ V2KeyNames.EncryptedDevicePrivateKey,
5121
+ V2KeyNames.WallabyAuthPubKey,
5122
+ V2KeyNames.PasskeyCredential,
5123
+ V2KeyNames.MigrationVersion,
5124
+ V2KeyNames.LastMigratedAt,
5125
+ V2KeyNames.ClientAuthToken,
5126
+ ];
5127
5127
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5128
5128
  if (walletId) {
5129
5129
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6820,184 +6820,6 @@ function objectToQueryParams(obj) {
6820
6820
  return params.toString();
6821
6821
  }
6822
6822
 
6823
- var NetworkDiagnosticCategory;
6824
- (function (NetworkDiagnosticCategory) {
6825
- NetworkDiagnosticCategory["OfflineHint"] = "offline_hint";
6826
- NetworkDiagnosticCategory["LikelyCorsOrAuthOrExtension"] = "likely_cors_or_auth_or_extension";
6827
- NetworkDiagnosticCategory["ConnectivityOrDns"] = "connectivity_or_dns";
6828
- NetworkDiagnosticCategory["FastFailureHint"] = "fast_failure_hint";
6829
- NetworkDiagnosticCategory["UnknownNetwork"] = "unknown_network";
6830
- })(NetworkDiagnosticCategory || (NetworkDiagnosticCategory = {}));
6831
-
6832
- const HEALTH_CHECK_TIMEOUT_MS = 5000;
6833
- class NetworkDiagnostic {
6834
- /**
6835
- * Run comprehensive network diagnostics after a fetch failure.
6836
- * Combines multiple signals to determine the likely cause of the failure.
6837
- */
6838
- static async run(context) {
6839
- const { failedUrl, originalError } = context;
6840
- logger.info('Running network diagnostic', { failedUrl, originalError });
6841
- const signals = {
6842
- online: NetworkDiagnostic.getNavigatorOnline(),
6843
- healthCheck: 'unavailable',
6844
- failedRequestUrl: failedUrl,
6845
- };
6846
- const hints = [];
6847
- const resourceTiming = NetworkDiagnostic.getResourceTimingForUrl(failedUrl);
6848
- if (resourceTiming) {
6849
- signals.resourceTiming = {
6850
- nextHopProtocol: resourceTiming.nextHopProtocol,
6851
- duration: resourceTiming.duration,
6852
- transferSize: resourceTiming.transferSize,
6853
- };
6854
- if (resourceTiming.duration < 50) {
6855
- hints.push('Very fast failure may indicate a local blocker or extension.');
6856
- }
6857
- }
6858
- const healthUrl = NetworkDiagnostic.deriveHealthUrl(failedUrl);
6859
- signals.healthCheck = await NetworkDiagnostic.simpleHealthCheck(healthUrl);
6860
- const category = NetworkDiagnostic.determineCategory(signals);
6861
- const message = NetworkDiagnostic.getCategoryMessage(category);
6862
- return {
6863
- category,
6864
- message,
6865
- signals,
6866
- hints: hints.length > 0 ? hints : undefined,
6867
- };
6868
- }
6869
- /**
6870
- * Check if navigator.onLine is available and return its value.
6871
- */
6872
- static getNavigatorOnline() {
6873
- if (typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean') {
6874
- return navigator.onLine;
6875
- }
6876
- return 'unknown';
6877
- }
6878
- /**
6879
- * Get the PerformanceResourceTiming entry for the given URL.
6880
- * Returns the most recent entry if multiple matches exist.
6881
- */
6882
- static getResourceTimingForUrl(url) {
6883
- if (typeof performance === 'undefined' || typeof performance.getEntriesByType !== 'function') {
6884
- return undefined;
6885
- }
6886
- try {
6887
- const entries = performance.getEntriesByType('resource');
6888
- const matchingEntries = entries.filter((entry) => entry.name && entry.name.includes(url));
6889
- if (matchingEntries.length === 0) {
6890
- return undefined;
6891
- }
6892
- return matchingEntries[matchingEntries.length - 1];
6893
- }
6894
- catch (_a) {
6895
- return undefined;
6896
- }
6897
- }
6898
- /**
6899
- * Perform a simple no-cors health check to the `/healthz` endpoint.
6900
- * This uses mode: 'no-cors' to avoid CORS preflight and credential issues.
6901
- */
6902
- static async simpleHealthCheck(healthUrl) {
6903
- if (typeof fetch === 'undefined') {
6904
- return 'unavailable';
6905
- }
6906
- const controller = new AbortController();
6907
- const timeoutId = setTimeout(() => controller.abort(), HEALTH_CHECK_TIMEOUT_MS);
6908
- try {
6909
- const response = await fetch(healthUrl, {
6910
- method: 'HEAD',
6911
- mode: 'no-cors',
6912
- cache: 'no-store',
6913
- signal: controller.signal,
6914
- });
6915
- if (response.type === 'opaque') {
6916
- return 'ok';
6917
- }
6918
- return 'failed';
6919
- }
6920
- catch (_a) {
6921
- return 'failed';
6922
- }
6923
- finally {
6924
- clearTimeout(timeoutId);
6925
- }
6926
- }
6927
- /**
6928
- * Derive the health check URL from the base URL origin and `/healthz`.
6929
- */
6930
- static deriveHealthUrl(baseUrl) {
6931
- try {
6932
- const url = new URL(baseUrl);
6933
- const origin = url.origin;
6934
- return `${origin}/healthz`;
6935
- }
6936
- catch (_a) {
6937
- return `${baseUrl}/healthz`;
6938
- }
6939
- }
6940
- /**
6941
- * Determine the diagnostic category based on collected signals.
6942
- * Order matters - checks are performed in priority order.
6943
- */
6944
- static determineCategory(signals) {
6945
- if (signals.online === false) {
6946
- return NetworkDiagnosticCategory.OfflineHint;
6947
- }
6948
- if (signals.healthCheck === 'ok') {
6949
- return NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension;
6950
- }
6951
- if (signals.resourceTiming && signals.resourceTiming.duration !== undefined && signals.resourceTiming.duration < 50) {
6952
- return NetworkDiagnosticCategory.FastFailureHint;
6953
- }
6954
- if (signals.healthCheck === 'failed') {
6955
- return NetworkDiagnosticCategory.ConnectivityOrDns;
6956
- }
6957
- return NetworkDiagnosticCategory.UnknownNetwork;
6958
- }
6959
- /**
6960
- * Get a user-facing message for the given diagnostic category.
6961
- */
6962
- static getCategoryMessage(category) {
6963
- switch (category) {
6964
- case NetworkDiagnosticCategory.OfflineHint:
6965
- return 'Device reports offline; check Wi-Fi or mobile data.';
6966
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
6967
- return 'Reachability to the API is OK; the failure may be due to CORS, authentication headers, or a browser extension blocking authenticated requests.';
6968
- case NetworkDiagnosticCategory.ConnectivityOrDns:
6969
- return 'Cannot reach the API host; check DNS, VPN, firewall, or ISP filtering.';
6970
- case NetworkDiagnosticCategory.FastFailureHint:
6971
- return 'Very fast failure may indicate a local blocker or extension.';
6972
- case NetworkDiagnosticCategory.UnknownNetwork:
6973
- default:
6974
- return 'Network request failed; see diagnostic details.';
6975
- }
6976
- }
6977
- /**
6978
- * Check if an error is a network-layer failure candidate that should trigger diagnostics.
6979
- * Returns true for TypeErrors with fetch-related messages, or DOMException with NetworkError name.
6980
- */
6981
- static isNetworkFailureCandidate(error) {
6982
- if (!error)
6983
- return false;
6984
- if (error instanceof TypeError) {
6985
- const message = error.message.toLowerCase();
6986
- return (message.includes('failed to fetch') ||
6987
- message.includes('load failed') ||
6988
- message.includes('networkerror') ||
6989
- message.includes('network request failed'));
6990
- }
6991
- if (error instanceof Error && error.name === 'NetworkError') {
6992
- return true;
6993
- }
6994
- if (typeof DOMException !== 'undefined' && error instanceof DOMException && error.name === 'NetworkError') {
6995
- return true;
6996
- }
6997
- return false;
6998
- }
6999
- }
7000
-
7001
6823
  class Base {
7002
6824
  constructor(config) {
7003
6825
  var _a, _b;
@@ -7049,26 +6871,6 @@ class Base {
7049
6871
  if (error instanceof WallabyError) {
7050
6872
  throw error;
7051
6873
  }
7052
- // Handle network-level failures with diagnostics
7053
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7054
- const fullUrl = `${this.baseUrl.replace(/\/api\/v1\/?$/, '')}${params.path || ''}`;
7055
- const diagnostic = await NetworkDiagnostic.run({
7056
- failedUrl: fullUrl,
7057
- originalError: error,
7058
- });
7059
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7060
- throw new WallabyError({
7061
- message: diagnostic.message,
7062
- statusCode: 0,
7063
- errorCode,
7064
- data: {
7065
- originalError: error,
7066
- networkDiagnostic: diagnostic,
7067
- },
7068
- cause: error.cause,
7069
- networkDiagnostic: diagnostic,
7070
- });
7071
- }
7072
6874
  // Wrap any other errors
7073
6875
  throw new WallabyError({
7074
6876
  message: error.message || 'Unknown error occurred',
@@ -7238,25 +7040,6 @@ class Base {
7238
7040
  name: error.name,
7239
7041
  error,
7240
7042
  });
7241
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7242
- const diagnostic = await NetworkDiagnostic.run({
7243
- failedUrl: fullUrl,
7244
- originalError: error,
7245
- });
7246
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7247
- throw new WallabyError({
7248
- message: diagnostic.message,
7249
- statusCode: 0,
7250
- errorCode,
7251
- data: {
7252
- code: error.name,
7253
- originalError: error,
7254
- networkDiagnostic: diagnostic,
7255
- },
7256
- cause: error.cause,
7257
- networkDiagnostic: diagnostic,
7258
- });
7259
- }
7260
7043
  throw new WallabyError({
7261
7044
  message: error.message || 'Network request failed',
7262
7045
  statusCode: 0,
@@ -7269,20 +7052,6 @@ class Base {
7269
7052
  });
7270
7053
  }
7271
7054
  }
7272
- mapCategoryToErrorCode(category) {
7273
- switch (category) {
7274
- case NetworkDiagnosticCategory.OfflineHint:
7275
- return ErrorResponseCodes.sdk_network_offline;
7276
- case NetworkDiagnosticCategory.ConnectivityOrDns:
7277
- return ErrorResponseCodes.sdk_network_connectivity;
7278
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
7279
- return ErrorResponseCodes.sdk_network_likely_cors_or_auth;
7280
- case NetworkDiagnosticCategory.FastFailureHint:
7281
- return ErrorResponseCodes.sdk_network_fast_failure;
7282
- default:
7283
- return ErrorResponseCodes.sdk_network_unknown;
7284
- }
7285
- }
7286
7055
  async _getRequestHeaders() {
7287
7056
  const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
7288
7057
  if (!isTest && jwtHasExpired(this.clientAuthToken)) {
@@ -7993,9 +7762,10 @@ let PasskeyService$1 = class PasskeyService {
7993
7762
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7994
7763
  });
7995
7764
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7765
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7996
7766
  const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7997
7767
  eval: {
7998
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7768
+ first: prfFirst,
7999
7769
  },
8000
7770
  } }) });
8001
7771
  const passkeyCredential = await this.authenticator.authenticate({
@@ -10305,8 +10075,8 @@ class WalletService extends Base {
10305
10075
  throw error;
10306
10076
  }
10307
10077
  }
10308
- async clearDevice() {
10309
- await this.localStorageService.clearLocalStorage();
10078
+ async clearDevice({ walletId }) {
10079
+ await this.localStorageService.clearLocalStorage(walletId);
10310
10080
  }
10311
10081
  /**
10312
10082
  * Prepares authentication data and encrypted payload for any request.
@@ -12237,5 +12007,5 @@ class Wallaby {
12237
12007
  }
12238
12008
  }
12239
12009
 
12240
- export { AddressType, AndroidVersionNotSupportedError, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, AuthenticatorGeneralError, AuthenticatorMissingDiscoverableCredentialSupportError, AuthenticatorMissingUserVerificationSupportError, AuthenticatorNoSupportedPubKeyCredParamsAlgError, AuthenticatorNotRegisteredError, AuthenticatorPreviouslyRegisteredError, AutoRegisterUserVerificationFailureError, BadConfiguration, BlockchainName, BlockchainSlip44, BlockchainStatus, CeremonyAbortedError, ErrorResponseCodes, IOSVersionNotSupportedError, InterruptedError, InvalidChallengeError, InvalidDomainError, InvalidRpIdError, InvalidStateError, InvalidUserIdError, InvalidUserIdLengthError, KeyTypeName, LegacyKeyNames, LocalStorageItems, MalformedPubKeyCredParamsError, NativeError, NetworkDiagnostic, NoCredentialsError, NotAllowedError, OwnershipType, PasskeyChallengeType, PasskeyErrorCodes, PassthroughSeeCausePropertyError, PublicKeyCredentialAlgorithm, RequestFailedError, RequestMethod, ReturnWalletOption, SeedPhraseType, TimeoutError, TokenStandard, TransactionEntryType, TransportEnum, UnknownError, UserAssetSource, UserCancelledError, V1KeyNames, V2KeyNames, Wallaby, Api as WallabyApiClient, WallabyError, HttpClient as WallabyHttpClient, WalletAddressTypeName, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
12010
+ export { AddressType, AndroidVersionNotSupportedError, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, AuthenticatorGeneralError, AuthenticatorMissingDiscoverableCredentialSupportError, AuthenticatorMissingUserVerificationSupportError, AuthenticatorNoSupportedPubKeyCredParamsAlgError, AuthenticatorNotRegisteredError, AuthenticatorPreviouslyRegisteredError, AutoRegisterUserVerificationFailureError, BadConfiguration, BlockchainName, BlockchainSlip44, BlockchainStatus, CeremonyAbortedError, ErrorResponseCodes, IOSVersionNotSupportedError, InterruptedError, InvalidChallengeError, InvalidDomainError, InvalidRpIdError, InvalidStateError, InvalidUserIdError, InvalidUserIdLengthError, KeyTypeName, LegacyKeyNames, LocalStorageItems, MalformedPubKeyCredParamsError, NativeError, NoCredentialsError, NotAllowedError, OwnershipType, PasskeyChallengeType, PasskeyErrorCodes, PassthroughSeeCausePropertyError, PublicKeyCredentialAlgorithm, RequestFailedError, RequestMethod, ReturnWalletOption, SeedPhraseType, TimeoutError, TokenStandard, TransactionEntryType, TransportEnum, UnknownError, UserAssetSource, UserCancelledError, V1KeyNames, V2KeyNames, Wallaby, Api as WallabyApiClient, WallabyError, HttpClient as WallabyHttpClient, WalletAddressTypeName, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
12241
12011
  //# sourceMappingURL=index.js.map