import { motion } from 'framer-motion'; import { nip19 } from 'nostr-tools'; import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { toast } from 'sonner'; import { twMerge } from 'tailwind-merge'; import { useStorage } from '@libs/storage/provider'; import { ArrowLeftIcon } from '@shared/icons'; import { User } from '@shared/user'; export function ImportAccountScreen() { const { db } = useStorage(); const navigate = useNavigate(); const [npub, setNpub] = useState(''); const [nsec, setNsec] = useState(''); const [pubkey, setPubkey] = useState(undefined); const [created, setCreated] = useState(false); const [savedPrivkey, setSavedPrivkey] = useState(false); const submitNpub = async () => { if (npub.length < 6) return toast('You must enter valid npub'); if (!npub.startsWith('npub1')) return toast('npub must be starts with npub1'); try { const pubkey = nip19.decode(npub).data as string; setPubkey(pubkey); } catch (e) { return toast(`npub invalid: ${e}`); } }; const changeAccount = async () => { setNpub(''); setPubkey(''); }; const createAccount = async () => { try { await db.createAccount(npub, pubkey); setCreated(true); } catch (e) { return toast(`Create account failed: ${e}`); } }; const submitNsec = async () => { if (savedPrivkey) return; if (nsec.length > 50 && nsec.startsWith('nsec1')) { try { const privkey = nip19.decode(nsec).data as string; await db.secureSave(pubkey, privkey); setSavedPrivkey(true); } catch (e) { return toast(`nsec invalid: ${e}`); } } }; return (
{!created ? ( ) : null}

Import your Nostr account.

setNpub(e.target.value)} spellCheck={false} autoComplete="off" autoCorrect="off" autoCapitalize="off" placeholder="npub1" className="h-11 flex-1 rounded-lg bg-neutral-200 px-3 placeholder:text-neutral-500 dark:bg-neutral-800 dark:placeholder:text-neutral-400" /> {!pubkey ? ( ) : null}
{pubkey ? (
Account found
{!created ? (
) : null}
) : null} {created ? ( <>
setNsec(e.target.value)} spellCheck={false} autoComplete="off" autoCorrect="off" autoCapitalize="off" placeholder="nsec1" className="h-11 flex-1 rounded-lg bg-neutral-200 px-3 placeholder:text-neutral-500 dark:bg-neutral-800 dark:placeholder:text-neutral-400" />

nsec is used to sign your event. For example, if you want to make a new post or send a message to your contact, you need to use nsec to sign this event.

1. In case you store nsec in Lume

Lume will put your nsec to{' '} {db.platform === 'macos' ? 'Apple Keychain (macOS)' : db.platform === 'windows' ? 'Credential Manager (Windows)' : 'Secret Service (Linux)'} , it will be secured by your OS

2. In case you do not store nsec in Lume

When you make an event that requires a sign by your nsec, Lume will show a prompt popup for you to enter nsec. It will be cleared after signing and not stored anywhere.

navigate('/auth/onboarding', { state: { newuser: false } }) } > Finish ) : null}
); }