@volr/react 0.1.101 → 0.1.103

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
@@ -18509,21 +18509,53 @@ function useVolr() {
18509
18509
  const { precheck } = usePrecheck();
18510
18510
  const { relay } = useRelay();
18511
18511
  const { client: apiClient } = useInternalAuth();
18512
+ const restoringRef = useRef(null);
18512
18513
  const getRpcUrl = useCallback(
18513
18514
  createGetRpcUrl({ client: apiClient, rpcOverrides: config.rpcOverrides }),
18514
18515
  [apiClient, config.rpcOverrides]
18515
18516
  );
18517
+ const ensureProvider = useCallback(async () => {
18518
+ if (provider) {
18519
+ return provider;
18520
+ }
18521
+ if (!user?.keyStorageType || user.keyStorageType !== "passkey") {
18522
+ throw new Error(
18523
+ "No wallet provider available. Please complete passkey enrollment first."
18524
+ );
18525
+ }
18526
+ if (!user.blobUrl || !user.prfInput || !user.id) {
18527
+ throw new Error(
18528
+ "Missing passkey data. Please re-enroll your passkey."
18529
+ );
18530
+ }
18531
+ if (restoringRef.current) {
18532
+ return restoringRef.current;
18533
+ }
18534
+ console.log("[useVolr] Auto-restoring passkey provider...");
18535
+ restoringRef.current = restorePasskey({
18536
+ client: apiClient,
18537
+ userId: user.id,
18538
+ blobUrl: user.blobUrl,
18539
+ prfInput: user.prfInput,
18540
+ credentialId: user.credentialId
18541
+ }).then(async ({ provider: restoredProvider }) => {
18542
+ await setProvider(restoredProvider);
18543
+ console.log("[useVolr] Passkey provider restored successfully");
18544
+ restoringRef.current = null;
18545
+ return restoredProvider;
18546
+ }).catch((err) => {
18547
+ restoringRef.current = null;
18548
+ throw err;
18549
+ });
18550
+ return restoringRef.current;
18551
+ }, [provider, user, apiClient, setProvider]);
18516
18552
  const signMessage = useCallback(
18517
18553
  async (message) => {
18518
- if (!provider) {
18519
- throw new Error(
18520
- "No wallet provider available. Please log in with a Passkey or MPC wallet to sign messages."
18521
- );
18522
- }
18554
+ const activeProvider = await ensureProvider();
18523
18555
  if (config.onSignRequest) {
18524
18556
  await config.onSignRequest({ type: "message", message });
18525
18557
  }
18526
- await provider.ensureSession({ interactive: true });
18558
+ await activeProvider.ensureSession({ interactive: true });
18527
18559
  const messageHash = hashMessage(
18528
18560
  typeof message === "string" ? message : { raw: message }
18529
18561
  );
@@ -18532,28 +18564,25 @@ function useVolr() {
18532
18564
  for (let i = 0; i < 32; i++) {
18533
18565
  hashBytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
18534
18566
  }
18535
- const sig = await provider.signMessage(hashBytes);
18567
+ const sig = await activeProvider.signMessage(hashBytes);
18536
18568
  const v = sig.yParity + 27;
18537
18569
  const rHex = Array.from(sig.r).map((b) => b.toString(16).padStart(2, "0")).join("");
18538
18570
  const sHex = Array.from(sig.s).map((b) => b.toString(16).padStart(2, "0")).join("");
18539
18571
  const vHex = v.toString(16).padStart(2, "0");
18540
18572
  return `0x${rHex}${sHex}${vHex}`;
18541
18573
  },
18542
- [provider, config.onSignRequest]
18574
+ [ensureProvider, config.onSignRequest]
18543
18575
  );
18544
18576
  const signTypedData = useCallback(
18545
18577
  async (typedData) => {
18546
- if (!provider) {
18547
- throw new Error(
18548
- "No wallet provider available. Please log in with a Passkey or MPC wallet to sign typed data."
18549
- );
18550
- }
18578
+ const activeProvider = await ensureProvider();
18551
18579
  if (config.onSignRequest) {
18552
18580
  await config.onSignRequest({ type: "typedData", typedData });
18553
18581
  }
18554
- return provider.signTypedData(typedData);
18582
+ await activeProvider.ensureSession({ interactive: true });
18583
+ return activeProvider.signTypedData(typedData);
18555
18584
  },
18556
- [provider, config.onSignRequest]
18585
+ [ensureProvider, config.onSignRequest]
18557
18586
  );
18558
18587
  const createChainClient = useCallback(
18559
18588
  (chainId) => {