import { useStorage } from "@lume/ark"; import { EyeOffIcon, EyeOnIcon, LoaderIcon } from "@lume/icons"; import { getPublicKey, nip19 } from "nostr-tools"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { useNavigate } from "react-router-dom"; import { toast } from "sonner"; export function LoginWithKey() { const storage = useStorage(); const navigate = useNavigate(); const [showKey, setShowKey] = useState(false); const [loading, setLoading] = useState(false); const { register, handleSubmit, setError, formState: { errors, isValid }, } = useForm(); const onSubmit = async (data: { nsec: string }) => { try { if (!data.nsec.startsWith("nsec1")) return toast.error("You need to enter a private key start with nsec1"); setLoading(true); const privkey = nip19.decode(data.nsec).data as string; const pubkey = getPublicKey(privkey); await storage.createAccount({ pubkey: pubkey, privkey: privkey, }); return navigate("/auth/onboarding"); } catch (e) { setLoading(false); setError("nsec", { type: "manual", message: String(e), }); } }; return (

Enter your Private Key

Lume will put your private key to{" "} {storage.platform === "macos" ? "Apple Keychain" : storage.platform === "windows" ? "Credential Manager" : "Secret Service"} .
It will be secured by your OS.

{errors.nsec && (

{errors.nsec.message as string}

)}
); }