"use client";
import { useTurnkey } from "@turnkey/react-wallet-kit";
import { OtpType } from "@turnkey/core";
export default function AuthPage() {
const {
initOtp,
completeOtp,
createApiKeyPair,
user,
wallets,
signMessage,
} = useTurnkey();
async function handleSignup(email: string, name: string) {
// 1. Send a verification code to the user's email
const otpId = await initOtp({
otpType: OtpType.Email,
contact: email,
});
// 2. After the user enters the code, verify and create the wallet
const publicKey = await createApiKeyPair();
await completeOtp({
otpId,
otpCode: "<user-entered-code>",
contact: email,
otpType: OtpType.Email,
publicKey,
createSubOrgParams: {
userName: name,
userEmail: email,
subOrgName: email,
customWallet: {
walletName: `${name} Wallet`,
walletAccounts: [
{
curve: "CURVE_SECP256K1",
pathFormat: "PATH_FORMAT_BIP32",
path: "m/44'/60'/0'/0",
addressFormat: "ADDRESS_FORMAT_ETHEREUM",
},
],
},
},
});
// wallets[0].accounts[0].address now contains the new wallet address
}
}