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.d.ts CHANGED
@@ -7,7 +7,6 @@ import { HttpApi } from './lib/api/api';
7
7
  export * from './types';
8
8
  export * from './eth-crypto-utils';
9
9
  export { Api as WallabyApiClient, HttpClient as WallabyHttpClient } from './generated/api';
10
- export { NetworkDiagnostic } from './lib/network/network-diagnostic';
11
10
  /**
12
11
  * The Wallaby SDK client. This class is the main entry point into Wallaby's
13
12
  * APIs and separates functionality into different domains.
package/dist/index.esm.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 = {};
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 = {
@@ -578,7 +570,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
578
570
  { type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
579
571
  ];
580
572
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
581
- const currentPackageVersion = "2.3.7-alpha.0" ;
573
+ const currentPackageVersion = "2.3.7" ;
582
574
 
583
575
  /**
584
576
  * Storage keys adapter for Storage interface across different platforms.
@@ -5118,7 +5110,15 @@ class StorageService {
5118
5110
  return undefined;
5119
5111
  }
5120
5112
  async clearLocalStorage(walletId) {
5121
- const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
5113
+ const userKeysToRemove = [
5114
+ LocalStorageItems.AccessToken,
5115
+ V2KeyNames.EncryptedDevicePrivateKey,
5116
+ V2KeyNames.WallabyAuthPubKey,
5117
+ V2KeyNames.PasskeyCredential,
5118
+ V2KeyNames.MigrationVersion,
5119
+ V2KeyNames.LastMigratedAt,
5120
+ V2KeyNames.ClientAuthToken,
5121
+ ];
5122
5122
  await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
5123
5123
  if (walletId) {
5124
5124
  await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
@@ -6815,184 +6815,6 @@ function objectToQueryParams(obj) {
6815
6815
  return params.toString();
6816
6816
  }
6817
6817
 
6818
- var NetworkDiagnosticCategory;
6819
- (function (NetworkDiagnosticCategory) {
6820
- NetworkDiagnosticCategory["OfflineHint"] = "offline_hint";
6821
- NetworkDiagnosticCategory["LikelyCorsOrAuthOrExtension"] = "likely_cors_or_auth_or_extension";
6822
- NetworkDiagnosticCategory["ConnectivityOrDns"] = "connectivity_or_dns";
6823
- NetworkDiagnosticCategory["FastFailureHint"] = "fast_failure_hint";
6824
- NetworkDiagnosticCategory["UnknownNetwork"] = "unknown_network";
6825
- })(NetworkDiagnosticCategory || (NetworkDiagnosticCategory = {}));
6826
-
6827
- const HEALTH_CHECK_TIMEOUT_MS = 5000;
6828
- class NetworkDiagnostic {
6829
- /**
6830
- * Run comprehensive network diagnostics after a fetch failure.
6831
- * Combines multiple signals to determine the likely cause of the failure.
6832
- */
6833
- static async run(context) {
6834
- const { failedUrl, originalError } = context;
6835
- logger.info('Running network diagnostic', { failedUrl, originalError });
6836
- const signals = {
6837
- online: NetworkDiagnostic.getNavigatorOnline(),
6838
- healthCheck: 'unavailable',
6839
- failedRequestUrl: failedUrl,
6840
- };
6841
- const hints = [];
6842
- const resourceTiming = NetworkDiagnostic.getResourceTimingForUrl(failedUrl);
6843
- if (resourceTiming) {
6844
- signals.resourceTiming = {
6845
- nextHopProtocol: resourceTiming.nextHopProtocol,
6846
- duration: resourceTiming.duration,
6847
- transferSize: resourceTiming.transferSize,
6848
- };
6849
- if (resourceTiming.duration < 50) {
6850
- hints.push('Very fast failure may indicate a local blocker or extension.');
6851
- }
6852
- }
6853
- const healthUrl = NetworkDiagnostic.deriveHealthUrl(failedUrl);
6854
- signals.healthCheck = await NetworkDiagnostic.simpleHealthCheck(healthUrl);
6855
- const category = NetworkDiagnostic.determineCategory(signals);
6856
- const message = NetworkDiagnostic.getCategoryMessage(category);
6857
- return {
6858
- category,
6859
- message,
6860
- signals,
6861
- hints: hints.length > 0 ? hints : undefined,
6862
- };
6863
- }
6864
- /**
6865
- * Check if navigator.onLine is available and return its value.
6866
- */
6867
- static getNavigatorOnline() {
6868
- if (typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean') {
6869
- return navigator.onLine;
6870
- }
6871
- return 'unknown';
6872
- }
6873
- /**
6874
- * Get the PerformanceResourceTiming entry for the given URL.
6875
- * Returns the most recent entry if multiple matches exist.
6876
- */
6877
- static getResourceTimingForUrl(url) {
6878
- if (typeof performance === 'undefined' || typeof performance.getEntriesByType !== 'function') {
6879
- return undefined;
6880
- }
6881
- try {
6882
- const entries = performance.getEntriesByType('resource');
6883
- const matchingEntries = entries.filter((entry) => entry.name && entry.name.includes(url));
6884
- if (matchingEntries.length === 0) {
6885
- return undefined;
6886
- }
6887
- return matchingEntries[matchingEntries.length - 1];
6888
- }
6889
- catch (_a) {
6890
- return undefined;
6891
- }
6892
- }
6893
- /**
6894
- * Perform a simple no-cors health check to the `/healthz` endpoint.
6895
- * This uses mode: 'no-cors' to avoid CORS preflight and credential issues.
6896
- */
6897
- static async simpleHealthCheck(healthUrl) {
6898
- if (typeof fetch === 'undefined') {
6899
- return 'unavailable';
6900
- }
6901
- const controller = new AbortController();
6902
- const timeoutId = setTimeout(() => controller.abort(), HEALTH_CHECK_TIMEOUT_MS);
6903
- try {
6904
- const response = await fetch(healthUrl, {
6905
- method: 'HEAD',
6906
- mode: 'no-cors',
6907
- cache: 'no-store',
6908
- signal: controller.signal,
6909
- });
6910
- if (response.type === 'opaque') {
6911
- return 'ok';
6912
- }
6913
- return 'failed';
6914
- }
6915
- catch (_a) {
6916
- return 'failed';
6917
- }
6918
- finally {
6919
- clearTimeout(timeoutId);
6920
- }
6921
- }
6922
- /**
6923
- * Derive the health check URL from the base URL origin and `/healthz`.
6924
- */
6925
- static deriveHealthUrl(baseUrl) {
6926
- try {
6927
- const url = new URL(baseUrl);
6928
- const origin = url.origin;
6929
- return `${origin}/healthz`;
6930
- }
6931
- catch (_a) {
6932
- return `${baseUrl}/healthz`;
6933
- }
6934
- }
6935
- /**
6936
- * Determine the diagnostic category based on collected signals.
6937
- * Order matters - checks are performed in priority order.
6938
- */
6939
- static determineCategory(signals) {
6940
- if (signals.online === false) {
6941
- return NetworkDiagnosticCategory.OfflineHint;
6942
- }
6943
- if (signals.healthCheck === 'ok') {
6944
- return NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension;
6945
- }
6946
- if (signals.resourceTiming && signals.resourceTiming.duration !== undefined && signals.resourceTiming.duration < 50) {
6947
- return NetworkDiagnosticCategory.FastFailureHint;
6948
- }
6949
- if (signals.healthCheck === 'failed') {
6950
- return NetworkDiagnosticCategory.ConnectivityOrDns;
6951
- }
6952
- return NetworkDiagnosticCategory.UnknownNetwork;
6953
- }
6954
- /**
6955
- * Get a user-facing message for the given diagnostic category.
6956
- */
6957
- static getCategoryMessage(category) {
6958
- switch (category) {
6959
- case NetworkDiagnosticCategory.OfflineHint:
6960
- return 'Device reports offline; check Wi-Fi or mobile data.';
6961
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
6962
- return 'Reachability to the API is OK; the failure may be due to CORS, authentication headers, or a browser extension blocking authenticated requests.';
6963
- case NetworkDiagnosticCategory.ConnectivityOrDns:
6964
- return 'Cannot reach the API host; check DNS, VPN, firewall, or ISP filtering.';
6965
- case NetworkDiagnosticCategory.FastFailureHint:
6966
- return 'Very fast failure may indicate a local blocker or extension.';
6967
- case NetworkDiagnosticCategory.UnknownNetwork:
6968
- default:
6969
- return 'Network request failed; see diagnostic details.';
6970
- }
6971
- }
6972
- /**
6973
- * Check if an error is a network-layer failure candidate that should trigger diagnostics.
6974
- * Returns true for TypeErrors with fetch-related messages, or DOMException with NetworkError name.
6975
- */
6976
- static isNetworkFailureCandidate(error) {
6977
- if (!error)
6978
- return false;
6979
- if (error instanceof TypeError) {
6980
- const message = error.message.toLowerCase();
6981
- return (message.includes('failed to fetch') ||
6982
- message.includes('load failed') ||
6983
- message.includes('networkerror') ||
6984
- message.includes('network request failed'));
6985
- }
6986
- if (error instanceof Error && error.name === 'NetworkError') {
6987
- return true;
6988
- }
6989
- if (typeof DOMException !== 'undefined' && error instanceof DOMException && error.name === 'NetworkError') {
6990
- return true;
6991
- }
6992
- return false;
6993
- }
6994
- }
6995
-
6996
6818
  class Base {
6997
6819
  constructor(config) {
6998
6820
  var _a, _b;
@@ -7043,26 +6865,6 @@ class Base {
7043
6865
  if (error instanceof WallabyError) {
7044
6866
  throw error;
7045
6867
  }
7046
- // Handle network-level failures with diagnostics
7047
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7048
- const fullUrl = `${this.baseUrl.replace(/\/api\/v1\/?$/, '')}${params.path || ''}`;
7049
- const diagnostic = await NetworkDiagnostic.run({
7050
- failedUrl: fullUrl,
7051
- originalError: error,
7052
- });
7053
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7054
- throw new WallabyError({
7055
- message: diagnostic.message,
7056
- statusCode: 0,
7057
- errorCode,
7058
- data: {
7059
- originalError: error,
7060
- networkDiagnostic: diagnostic,
7061
- },
7062
- cause: error.cause,
7063
- networkDiagnostic: diagnostic,
7064
- });
7065
- }
7066
6868
  // Wrap any other errors
7067
6869
  throw new WallabyError({
7068
6870
  message: error.message || 'Unknown error occurred',
@@ -7232,25 +7034,6 @@ class Base {
7232
7034
  name: error.name,
7233
7035
  error,
7234
7036
  });
7235
- if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
7236
- const diagnostic = await NetworkDiagnostic.run({
7237
- failedUrl: fullUrl,
7238
- originalError: error,
7239
- });
7240
- const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
7241
- throw new WallabyError({
7242
- message: diagnostic.message,
7243
- statusCode: 0,
7244
- errorCode,
7245
- data: {
7246
- code: error.name,
7247
- originalError: error,
7248
- networkDiagnostic: diagnostic,
7249
- },
7250
- cause: error.cause,
7251
- networkDiagnostic: diagnostic,
7252
- });
7253
- }
7254
7037
  throw new WallabyError({
7255
7038
  message: error.message || 'Network request failed',
7256
7039
  statusCode: 0,
@@ -7263,20 +7046,6 @@ class Base {
7263
7046
  });
7264
7047
  }
7265
7048
  }
7266
- mapCategoryToErrorCode(category) {
7267
- switch (category) {
7268
- case NetworkDiagnosticCategory.OfflineHint:
7269
- return ErrorResponseCodes.sdk_network_offline;
7270
- case NetworkDiagnosticCategory.ConnectivityOrDns:
7271
- return ErrorResponseCodes.sdk_network_connectivity;
7272
- case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
7273
- return ErrorResponseCodes.sdk_network_likely_cors_or_auth;
7274
- case NetworkDiagnosticCategory.FastFailureHint:
7275
- return ErrorResponseCodes.sdk_network_fast_failure;
7276
- default:
7277
- return ErrorResponseCodes.sdk_network_unknown;
7278
- }
7279
- }
7280
7049
  async _getRequestHeaders() {
7281
7050
  const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
7282
7051
  if (!isTest && jwtHasExpired(this.clientAuthToken)) {
@@ -7883,9 +7652,10 @@ class PasskeyService {
7883
7652
  errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
7884
7653
  });
7885
7654
  const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
7655
+ const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
7886
7656
  const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
7887
7657
  eval: {
7888
- first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
7658
+ first: prfFirst,
7889
7659
  },
7890
7660
  } }) });
7891
7661
  const passkeyCredential = await this.authenticator.authenticate({
@@ -10184,8 +9954,8 @@ class WalletService extends Base {
10184
9954
  throw error;
10185
9955
  }
10186
9956
  }
10187
- async clearDevice() {
10188
- await this.localStorageService.clearLocalStorage();
9957
+ async clearDevice({ walletId }) {
9958
+ await this.localStorageService.clearLocalStorage(walletId);
10189
9959
  }
10190
9960
  /**
10191
9961
  * Prepares authentication data and encrypted payload for any request.
@@ -12116,5 +11886,5 @@ class Wallaby {
12116
11886
  }
12117
11887
  }
12118
11888
 
12119
- 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 };
11889
+ 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 };
12120
11890
  //# sourceMappingURL=index.esm.js.map