@volr/react 0.1.67 → 0.1.69

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.cjs CHANGED
@@ -9502,6 +9502,52 @@ var PUBKEY_CRED_PARAMS = [
9502
9502
  ];
9503
9503
  var ATTESTATION = "direct";
9504
9504
 
9505
+ // src/errors/passkey-errors.ts
9506
+ var UserCancelledError = class _UserCancelledError extends Error {
9507
+ constructor(message) {
9508
+ super(message || "User cancelled the passkey authentication");
9509
+ this.code = "USER_CANCELLED";
9510
+ this.isUserCancelled = true;
9511
+ this.name = "UserCancelledError";
9512
+ Object.setPrototypeOf(this, _UserCancelledError.prototype);
9513
+ }
9514
+ };
9515
+ var PasskeyNotFoundError = class _PasskeyNotFoundError extends Error {
9516
+ constructor(message) {
9517
+ super(message || "Passkey not found. Please re-enroll your passkey.");
9518
+ this.code = "PASSKEY_NOT_FOUND";
9519
+ this.name = "PasskeyNotFoundError";
9520
+ Object.setPrototypeOf(this, _PasskeyNotFoundError.prototype);
9521
+ }
9522
+ };
9523
+ var PrfNotSupportedError = class _PrfNotSupportedError extends Error {
9524
+ constructor(message) {
9525
+ super(
9526
+ message || "WebAuthn PRF extension is not supported by this browser or device. Please use a browser that supports WebAuthn PRF extension."
9527
+ );
9528
+ this.code = "PRF_NOT_SUPPORTED";
9529
+ this.name = "PrfNotSupportedError";
9530
+ Object.setPrototypeOf(this, _PrfNotSupportedError.prototype);
9531
+ }
9532
+ };
9533
+ function isUserCancelledError(error) {
9534
+ if (error instanceof UserCancelledError) {
9535
+ return true;
9536
+ }
9537
+ if (error instanceof Error) {
9538
+ if (error.name === "NotAllowedError") {
9539
+ return true;
9540
+ }
9541
+ if (error.isUserCancelled === true) {
9542
+ return true;
9543
+ }
9544
+ if (error.message.includes("cancelled") || error.message.includes("denied")) {
9545
+ return true;
9546
+ }
9547
+ }
9548
+ return false;
9549
+ }
9550
+
9505
9551
  // src/adapters/passkey.ts
9506
9552
  function createPasskeyAdapter(options = {}) {
9507
9553
  const rpId = options.rpId || (typeof window !== "undefined" ? window.location.hostname : "localhost");
@@ -9630,16 +9676,18 @@ function createPasskeyAdapter(options = {}) {
9630
9676
  console.error("[PasskeyAdapter] Error name:", error?.name);
9631
9677
  console.error("[PasskeyAdapter] Error message:", error?.message);
9632
9678
  if (error?.name === "NotAllowedError") {
9633
- throw new Error(
9634
- "[PasskeyAdapter] User cancelled the passkey prompt or authentication was denied. Please try again and complete the authentication."
9679
+ throw new UserCancelledError(
9680
+ "User cancelled the passkey prompt or authentication was denied."
9635
9681
  );
9636
- } else if (error?.name === "NotFoundError" || error?.name === "InvalidStateError") {
9637
- throw new Error(
9638
- "[PasskeyAdapter] No passkey found matching the provided credentialId. This may happen if the passkey was deleted or the credentialId is incorrect. Please re-enroll your passkey."
9682
+ }
9683
+ if (error?.name === "NotFoundError" || error?.name === "InvalidStateError") {
9684
+ throw new PasskeyNotFoundError(
9685
+ "No passkey found matching the provided credentialId. This may happen if the passkey was deleted or the credentialId is incorrect."
9639
9686
  );
9640
- } else if (error?.name === "NotSupportedError") {
9641
- throw new Error(
9642
- "[PasskeyAdapter] WebAuthn PRF extension is not supported by this browser or device. Please use a browser that supports WebAuthn PRF extension (Chrome 108+, Edge 108+, Safari 16.4+)."
9687
+ }
9688
+ if (error?.name === "NotSupportedError") {
9689
+ throw new PrfNotSupportedError(
9690
+ "WebAuthn PRF extension is not supported by this browser or device. Please use a browser that supports WebAuthn PRF extension (Chrome 108+, Edge 108+, Safari 16.4+)."
9643
9691
  );
9644
9692
  }
9645
9693
  throw new Error(
@@ -18093,7 +18141,14 @@ async function resolveSigner(input) {
18093
18141
  return { signer: explicitSigner, activeProvider: null };
18094
18142
  }
18095
18143
  if (provider) {
18096
- await provider.ensureSession({ interactive: true, force: true });
18144
+ try {
18145
+ await provider.ensureSession({ interactive: true });
18146
+ } catch (error) {
18147
+ if (isUserCancelledError(error)) {
18148
+ throw error;
18149
+ }
18150
+ throw error;
18151
+ }
18097
18152
  const signerContext = {
18098
18153
  provider,
18099
18154
  chainId,
@@ -18112,7 +18167,14 @@ async function resolveSigner(input) {
18112
18167
  credentialId: user.credentialId
18113
18168
  });
18114
18169
  await setProvider(restoredProvider);
18115
- await restoredProvider.ensureSession({ interactive: true, force: true });
18170
+ try {
18171
+ await restoredProvider.ensureSession({ interactive: true });
18172
+ } catch (error) {
18173
+ if (isUserCancelledError(error)) {
18174
+ throw error;
18175
+ }
18176
+ throw error;
18177
+ }
18116
18178
  const signerContext = {
18117
18179
  provider: restoredProvider,
18118
18180
  chainId,
@@ -18917,6 +18979,16 @@ function detectPlatform() {
18917
18979
  }
18918
18980
  return "Unknown";
18919
18981
  }
18982
+ function buildDisplayName(userEmail, userEvmAddress, userId) {
18983
+ if (userEmail) {
18984
+ return userEmail;
18985
+ }
18986
+ if (userEvmAddress) {
18987
+ const short = `${userEvmAddress.slice(0, 6)}...${userEvmAddress.slice(-4)}`;
18988
+ return `Volr (${short})`;
18989
+ }
18990
+ return userId || "Volr Wallet";
18991
+ }
18920
18992
  async function enrollPasskey(params) {
18921
18993
  const {
18922
18994
  client,
@@ -18955,7 +19027,7 @@ async function enrollPasskey(params) {
18955
19027
  credentialId: tempCredentialId
18956
19028
  };
18957
19029
  const prfSalt = sdkCore.deriveWrapKey(tempPrfInput);
18958
- const displayName = userEmail || userEvmAddress || userId;
19030
+ const displayName = buildDisplayName(userEmail, userEvmAddress, userId);
18959
19031
  const publicKeyCredentialCreationOptions = {
18960
19032
  challenge: challenge2,
18961
19033
  rp: {
@@ -19533,6 +19605,159 @@ async function debugTransactionFailure(publicClient, failingWallet, workingWalle
19533
19605
  analysis
19534
19606
  };
19535
19607
  }
19608
+
19609
+ // src/utils/platform-check.ts
19610
+ function detectPlatform2() {
19611
+ if (typeof navigator === "undefined") return "Unknown";
19612
+ const ua = navigator.userAgent;
19613
+ const platform = navigator.platform || "";
19614
+ if (/iPhone|iPad|iPod/.test(ua) || platform === "MacIntel" && navigator.maxTouchPoints > 1) {
19615
+ return "iOS";
19616
+ }
19617
+ if (/Android/.test(ua)) {
19618
+ return "Android";
19619
+ }
19620
+ if (/Mac/.test(platform)) {
19621
+ return "macOS";
19622
+ }
19623
+ if (/Win/.test(platform)) {
19624
+ return "Windows";
19625
+ }
19626
+ if (/CrOS/.test(ua)) {
19627
+ return "ChromeOS";
19628
+ }
19629
+ if (/Linux/.test(platform)) {
19630
+ return "Linux";
19631
+ }
19632
+ return "Unknown";
19633
+ }
19634
+ function detectBrowser() {
19635
+ if (typeof navigator === "undefined") return "Unknown";
19636
+ const ua = navigator.userAgent;
19637
+ if (/Edg/.test(ua)) return "Edge";
19638
+ if (/Chrome/.test(ua) && !/Chromium/.test(ua)) return "Chrome";
19639
+ if (/Safari/.test(ua) && !/Chrome/.test(ua)) return "Safari";
19640
+ if (/Firefox/.test(ua)) return "Firefox";
19641
+ if (/Opera|OPR/.test(ua)) return "Opera";
19642
+ return "Unknown";
19643
+ }
19644
+ function checkPrfSupport() {
19645
+ const platform = detectPlatform2();
19646
+ const browser = detectBrowser();
19647
+ if (typeof navigator === "undefined" || !navigator.credentials) {
19648
+ return {
19649
+ prfSupported: false,
19650
+ crossDeviceAvailable: false,
19651
+ message: "WebAuthn is not supported in this environment.",
19652
+ platform,
19653
+ browser
19654
+ };
19655
+ }
19656
+ let prfSupported = false;
19657
+ let message;
19658
+ switch (platform) {
19659
+ case "iOS":
19660
+ if (browser === "Safari") {
19661
+ prfSupported = true;
19662
+ } else {
19663
+ prfSupported = true;
19664
+ }
19665
+ break;
19666
+ case "Android":
19667
+ if (browser === "Chrome" || browser === "Edge") {
19668
+ prfSupported = true;
19669
+ } else if (browser === "Firefox") {
19670
+ prfSupported = false;
19671
+ message = "Firefox on Android does not support passkey encryption. Please use Chrome.";
19672
+ } else {
19673
+ prfSupported = true;
19674
+ }
19675
+ break;
19676
+ case "macOS":
19677
+ if (browser === "Safari" || browser === "Chrome" || browser === "Edge") {
19678
+ prfSupported = true;
19679
+ } else if (browser === "Firefox") {
19680
+ prfSupported = false;
19681
+ message = "Firefox may not support passkey encryption. Please use Safari or Chrome.";
19682
+ } else {
19683
+ prfSupported = true;
19684
+ }
19685
+ break;
19686
+ case "Windows":
19687
+ if (browser === "Chrome" || browser === "Edge") {
19688
+ prfSupported = true;
19689
+ message = "If your device does not support passkey encryption, you can use your mobile device by scanning a QR code.";
19690
+ } else {
19691
+ prfSupported = false;
19692
+ message = "Please use Chrome or Edge for passkey encryption support.";
19693
+ }
19694
+ break;
19695
+ case "ChromeOS":
19696
+ prfSupported = true;
19697
+ break;
19698
+ case "Linux":
19699
+ if (browser === "Chrome" || browser === "Edge") {
19700
+ prfSupported = true;
19701
+ message = "If your device does not support passkey encryption, you can use your mobile device by scanning a QR code.";
19702
+ } else {
19703
+ prfSupported = false;
19704
+ message = "Please use Chrome for passkey encryption support.";
19705
+ }
19706
+ break;
19707
+ default:
19708
+ prfSupported = false;
19709
+ message = "Unknown platform. Passkey encryption may not be supported.";
19710
+ }
19711
+ const crossDeviceAvailable = true;
19712
+ return {
19713
+ prfSupported,
19714
+ crossDeviceAvailable,
19715
+ message,
19716
+ platform,
19717
+ browser
19718
+ };
19719
+ }
19720
+ function getPasskeyAuthGuidance(passkeyPlatform) {
19721
+ const { platform: currentPlatform, prfSupported } = checkPrfSupport();
19722
+ if (prfSupported && (!passkeyPlatform || passkeyPlatform === currentPlatform)) {
19723
+ return "";
19724
+ }
19725
+ if (passkeyPlatform && passkeyPlatform !== currentPlatform) {
19726
+ const platformDisplayName = getPlatformDisplayName(passkeyPlatform);
19727
+ return `Your passkey was registered on ${platformDisplayName}. You can use your ${platformDisplayName} device to authenticate by scanning a QR code.`;
19728
+ }
19729
+ if (!prfSupported) {
19730
+ return "This device may not support passkey encryption. You can use your mobile device by scanning a QR code.";
19731
+ }
19732
+ return "";
19733
+ }
19734
+ function getPlatformDisplayName(platform) {
19735
+ const displayNames = {
19736
+ iOS: "iPhone/iPad",
19737
+ Android: "Android",
19738
+ macOS: "Mac",
19739
+ Windows: "Windows PC",
19740
+ ChromeOS: "Chromebook",
19741
+ Linux: "Linux"
19742
+ };
19743
+ return displayNames[platform] || platform;
19744
+ }
19745
+ async function checkPrfExtensionAvailable() {
19746
+ if (typeof PublicKeyCredential === "undefined") {
19747
+ return false;
19748
+ }
19749
+ if ("getClientCapabilities" in PublicKeyCredential) {
19750
+ try {
19751
+ const capabilities = await PublicKeyCredential.getClientCapabilities();
19752
+ if (capabilities && typeof capabilities.extensions?.prf === "boolean") {
19753
+ return capabilities.extensions.prf;
19754
+ }
19755
+ } catch {
19756
+ }
19757
+ }
19758
+ const { prfSupported } = checkPrfSupport();
19759
+ return prfSupported;
19760
+ }
19536
19761
  /*! Bundled license information:
19537
19762
 
19538
19763
  @noble/hashes/esm/utils.js:
@@ -19577,10 +19802,15 @@ Object.defineProperty(exports, "uploadBlob", {
19577
19802
  });
19578
19803
  exports.DEFAULT_EXPIRES_IN_SEC = DEFAULT_EXPIRES_IN_SEC;
19579
19804
  exports.DEFAULT_MODE = DEFAULT_MODE;
19805
+ exports.PasskeyNotFoundError = PasskeyNotFoundError;
19806
+ exports.PrfNotSupportedError = PrfNotSupportedError;
19807
+ exports.UserCancelledError = UserCancelledError;
19580
19808
  exports.VolrProvider = VolrProvider;
19581
19809
  exports.analyzeContractForEIP7702 = analyzeContractForEIP7702;
19582
19810
  exports.buildCall = buildCall;
19583
19811
  exports.buildCalls = buildCalls;
19812
+ exports.checkPrfExtensionAvailable = checkPrfExtensionAvailable;
19813
+ exports.checkPrfSupport = checkPrfSupport;
19584
19814
  exports.compareERC20Balances = compareERC20Balances;
19585
19815
  exports.compareWalletStates = compareWalletStates;
19586
19816
  exports.createGetNetworkInfo = createGetNetworkInfo;
@@ -19589,8 +19819,10 @@ exports.debugTransactionFailure = debugTransactionFailure;
19589
19819
  exports.defaultIdempotencyKey = defaultIdempotencyKey;
19590
19820
  exports.diagnoseTransactionFailure = diagnoseTransactionFailure;
19591
19821
  exports.getERC20Balance = getERC20Balance;
19822
+ exports.getPasskeyAuthGuidance = getPasskeyAuthGuidance;
19592
19823
  exports.getWalletState = getWalletState;
19593
19824
  exports.isEIP7702Delegated = isEIP7702Delegated;
19825
+ exports.isUserCancelledError = isUserCancelledError;
19594
19826
  exports.normalizeHex = normalizeHex;
19595
19827
  exports.normalizeHexArray = normalizeHexArray;
19596
19828
  exports.uploadBlobViaPresign = uploadBlobViaPresign;