"use client";
import { useState } from "react";
import {
createShhhPasskey,
signShhhMessage,
hasShhhPasskey,
} from "@chipi-stack/chipi-passkey";
import { useCreateWallet } from "@chipi-stack/chipi-react";
import { webauthnPubkeyFelts } from "@chipi-stack/backend";
export function PasskeySignUp() {
const { createWalletAsync, isLoading } = useCreateWallet();
const [wallet, setWallet] = useState<unknown>(null);
async function onSignUp() {
const { credentialId, publicKeyHex } = await createShhhPasskey(
"user-42",
"Alice",
);
const w = await createWalletAsync({
params: {
externalUserId: "user-42",
chain: "STARKNET",
walletType: "SHHH",
signerKind: "WEBAUTHN_P256",
ownerPubkey: publicKeyHex,
},
bearerToken,
});
setWallet(w);
}
async function onSignTx() {
// Compute the SHHH OE hash for the transfer you want to send — your
// existing wallet flow already builds this. Replace `0n` with the
// real `computeOeHash` output for your call.
const messageHash = 0n;
const { authenticatorData, clientDataJSON, signatureDer } =
await signShhhMessage({ messageHash });
// Forward the assertion bytes to your paymaster flow — see step 3
// above for the envelope-wrapping detail.
console.log({ authenticatorData, clientDataJSON, signatureDer });
}
if (hasShhhPasskey()) {
return <button onClick={onSignTx}>Sign a transfer with Touch ID</button>;
}
return (
<button onClick={onSignUp} disabled={isLoading}>
Sign up with Touch ID
</button>
);
}