@volr/react 0.1.102 → 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.cjs +44 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -18533,21 +18533,53 @@ function useVolr() {
|
|
|
18533
18533
|
const { precheck } = usePrecheck();
|
|
18534
18534
|
const { relay } = useRelay();
|
|
18535
18535
|
const { client: apiClient } = useInternalAuth();
|
|
18536
|
+
const restoringRef = react.useRef(null);
|
|
18536
18537
|
const getRpcUrl = react.useCallback(
|
|
18537
18538
|
createGetRpcUrl({ client: apiClient, rpcOverrides: config.rpcOverrides }),
|
|
18538
18539
|
[apiClient, config.rpcOverrides]
|
|
18539
18540
|
);
|
|
18541
|
+
const ensureProvider = react.useCallback(async () => {
|
|
18542
|
+
if (provider) {
|
|
18543
|
+
return provider;
|
|
18544
|
+
}
|
|
18545
|
+
if (!user?.keyStorageType || user.keyStorageType !== "passkey") {
|
|
18546
|
+
throw new Error(
|
|
18547
|
+
"No wallet provider available. Please complete passkey enrollment first."
|
|
18548
|
+
);
|
|
18549
|
+
}
|
|
18550
|
+
if (!user.blobUrl || !user.prfInput || !user.id) {
|
|
18551
|
+
throw new Error(
|
|
18552
|
+
"Missing passkey data. Please re-enroll your passkey."
|
|
18553
|
+
);
|
|
18554
|
+
}
|
|
18555
|
+
if (restoringRef.current) {
|
|
18556
|
+
return restoringRef.current;
|
|
18557
|
+
}
|
|
18558
|
+
console.log("[useVolr] Auto-restoring passkey provider...");
|
|
18559
|
+
restoringRef.current = restorePasskey({
|
|
18560
|
+
client: apiClient,
|
|
18561
|
+
userId: user.id,
|
|
18562
|
+
blobUrl: user.blobUrl,
|
|
18563
|
+
prfInput: user.prfInput,
|
|
18564
|
+
credentialId: user.credentialId
|
|
18565
|
+
}).then(async ({ provider: restoredProvider }) => {
|
|
18566
|
+
await setProvider(restoredProvider);
|
|
18567
|
+
console.log("[useVolr] Passkey provider restored successfully");
|
|
18568
|
+
restoringRef.current = null;
|
|
18569
|
+
return restoredProvider;
|
|
18570
|
+
}).catch((err) => {
|
|
18571
|
+
restoringRef.current = null;
|
|
18572
|
+
throw err;
|
|
18573
|
+
});
|
|
18574
|
+
return restoringRef.current;
|
|
18575
|
+
}, [provider, user, apiClient, setProvider]);
|
|
18540
18576
|
const signMessage = react.useCallback(
|
|
18541
18577
|
async (message) => {
|
|
18542
|
-
|
|
18543
|
-
throw new Error(
|
|
18544
|
-
"No wallet provider available. Please log in with a Passkey or MPC wallet to sign messages."
|
|
18545
|
-
);
|
|
18546
|
-
}
|
|
18578
|
+
const activeProvider = await ensureProvider();
|
|
18547
18579
|
if (config.onSignRequest) {
|
|
18548
18580
|
await config.onSignRequest({ type: "message", message });
|
|
18549
18581
|
}
|
|
18550
|
-
await
|
|
18582
|
+
await activeProvider.ensureSession({ interactive: true });
|
|
18551
18583
|
const messageHash = hashMessage(
|
|
18552
18584
|
typeof message === "string" ? message : { raw: message }
|
|
18553
18585
|
);
|
|
@@ -18556,28 +18588,25 @@ function useVolr() {
|
|
|
18556
18588
|
for (let i = 0; i < 32; i++) {
|
|
18557
18589
|
hashBytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
18558
18590
|
}
|
|
18559
|
-
const sig = await
|
|
18591
|
+
const sig = await activeProvider.signMessage(hashBytes);
|
|
18560
18592
|
const v = sig.yParity + 27;
|
|
18561
18593
|
const rHex = Array.from(sig.r).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
18562
18594
|
const sHex = Array.from(sig.s).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
18563
18595
|
const vHex = v.toString(16).padStart(2, "0");
|
|
18564
18596
|
return `0x${rHex}${sHex}${vHex}`;
|
|
18565
18597
|
},
|
|
18566
|
-
[
|
|
18598
|
+
[ensureProvider, config.onSignRequest]
|
|
18567
18599
|
);
|
|
18568
18600
|
const signTypedData = react.useCallback(
|
|
18569
18601
|
async (typedData) => {
|
|
18570
|
-
|
|
18571
|
-
throw new Error(
|
|
18572
|
-
"No wallet provider available. Please log in with a Passkey or MPC wallet to sign typed data."
|
|
18573
|
-
);
|
|
18574
|
-
}
|
|
18602
|
+
const activeProvider = await ensureProvider();
|
|
18575
18603
|
if (config.onSignRequest) {
|
|
18576
18604
|
await config.onSignRequest({ type: "typedData", typedData });
|
|
18577
18605
|
}
|
|
18578
|
-
|
|
18606
|
+
await activeProvider.ensureSession({ interactive: true });
|
|
18607
|
+
return activeProvider.signTypedData(typedData);
|
|
18579
18608
|
},
|
|
18580
|
-
[
|
|
18609
|
+
[ensureProvider, config.onSignRequest]
|
|
18581
18610
|
);
|
|
18582
18611
|
const createChainClient = react.useCallback(
|
|
18583
18612
|
(chainId) => {
|