import { useMutation, useQueryClient } from '@tanstack/react-query'; import { BaseDirectory, writeTextFile } from '@tauri-apps/api/fs'; import { generatePrivateKey, getPublicKey, nip19 } from 'nostr-tools'; import { useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { createAccount } from '@libs/storage'; import { Button } from '@shared/button'; import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; import { useOnboarding } from '@stores/onboarding'; import { useStronghold } from '@stores/stronghold'; export function CreateStep1Screen() { const queryClient = useQueryClient(); const navigate = useNavigate(); const setPrivkey = useStronghold((state) => state.setPrivkey); const setPubkey = useOnboarding((state) => state.setPubkey); const [privkeyInput, setPrivkeyInput] = useState('password'); const [loading, setLoading] = useState(false); const [downloaded, setDownloaded] = useState(false); const privkey = useMemo(() => generatePrivateKey(), []); const pubkey = getPublicKey(privkey); const npub = nip19.npubEncode(pubkey); const nsec = nip19.nsecEncode(privkey); // toggle private key const showPrivateKey = () => { if (privkeyInput === 'password') { setPrivkeyInput('text'); } else { setPrivkeyInput('password'); } }; const download = async () => { await writeTextFile( 'lume-keys.txt', `Public key: ${pubkey}\nPrivate key: ${privkey}`, { dir: BaseDirectory.Download, } ); setDownloaded(true); }; const account = useMutation({ mutationFn: (data: { npub: string; pubkey: string; follows: null | string[][]; is_active: number; }) => { return createAccount(data.npub, data.pubkey, null, 1); }, onSuccess: (data) => { queryClient.setQueryData(['currentAccount'], data); }, }); const submit = () => { setLoading(true); setPubkey(pubkey); setPrivkey(privkey); account.mutate({ npub, pubkey, follows: null, is_active: 1, }); // redirect to next step setTimeout(() => navigate('/auth/create/step-2', { replace: true }), 1200); }; return (

Save your access key!

Public Key
Private Key

Your private key is your password. If you lose this key, you will lose access to your account! Copy it and keep it in a safe place. There is no way to reset your private key.

); }