import NDK, { NDKNip46Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk'; import { readText } from '@tauri-apps/plugin-clipboard-manager'; import { open } from '@tauri-apps/plugin-shell'; 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 { useArk } from '@libs/ark'; import { ArrowLeftIcon, LoaderIcon } from '@shared/icons'; import { User } from '@shared/user'; export function ImportAccountScreen() { const [npub, setNpub] = useState(''); const [nsec, setNsec] = useState(''); const [pubkey, setPubkey] = useState(undefined); const [loading, setLoading] = useState(false); const [created, setCreated] = useState({ ok: false, remote: false }); const [savedPrivkey, setSavedPrivkey] = useState(false); const { ark } = useArk(); const navigate = useNavigate(); const submitNpub = async () => { if (npub.length < 6) return toast.error('You must enter valid npub'); if (!npub.startsWith('npub1')) return toast.error('npub must be starts with npub1'); try { const pubkey = nip19.decode(npub).data as string; setPubkey(pubkey); } catch (e) { return toast.error(`npub invalid: ${e}`); } }; const connectNsecBunker = async () => { if (npub.length < 6) return toast.error('You must enter valid npub'); if (!npub.startsWith('npub1')) return toast.error('npub must be starts with npub1'); try { const pubkey = nip19.decode(npub.split('#')[0]).data as string; const localSigner = NDKPrivateKeySigner.generate(); await ark.createSetting('nsecbunker', '1'); await ark.createPrivkey(`${pubkey}-nsecbunker`, localSigner.privateKey); // open nsecbunker web app in default browser await open('https://app.nsecbunker.com/keys'); const bunker = new NDK({ explicitRelayUrls: ['wss://relay.nsecbunker.com', 'wss://nostr.vulpem.com'], }); bunker.connect(); const remoteSigner = new NDKNip46Signer(bunker, npub, localSigner); await remoteSigner.blockUntilReady(); ark.updateNostrSigner({ signer: remoteSigner }); setPubkey(pubkey); setCreated({ ok: false, remote: true }); } catch (e) { return toast.error(e); } }; const changeAccount = async () => { setNpub(''); setPubkey(''); }; const createAccount = async () => { try { setLoading(true); // add account to db await ark.createAccount(npub, pubkey); // get account contacts await ark.getUserContacts({ pubkey }); setCreated((prev) => ({ ...prev, ok: true })); setLoading(false); if (created.remote) navigate('/auth/onboarding'); } catch (e) { setLoading(false); return toast.error(e); } }; const pasteNsec = async () => { const tempNsec = await readText(); setNsec(tempNsec); }; const submitNsec = async () => { if (savedPrivkey) return; if (nsec.length > 50 && nsec.startsWith('nsec1')) { try { const privkey = nip19.decode(nsec).data as string; await ark.createPrivkey(pubkey, privkey); ark.updateNostrSigner({ signer: new NDKPrivateKeySigner(privkey) }); setSavedPrivkey(true); } catch (e) { return toast(`nsec invalid: ${e}`); } } }; return (
{!created ? ( ) : null}

Import your account.

setNpub(e.target.value)} spellCheck={false} autoComplete="off" autoCorrect="off" autoCapitalize="off" placeholder="npub1" className="h-11 rounded-lg border-transparent bg-neutral-100 px-3 placeholder:text-neutral-500 focus:border-blue-500 focus:ring focus:ring-blue-200 dark:bg-neutral-900 dark:placeholder:text-neutral-400 dark:focus:ring-blue-800" /> {!pubkey ? (
) : null} {npub.indexOf('#') > -1 ? (

You're using nsecbunker token, keep in mind it only can redeem one-time, you need to login again in the next launch

) : null}
{pubkey ? (
Account found
{!created.ok ? ( ) : null}
) : null} {created.ok ? ( <> {!created.remote ? (
setNsec(e.target.value)} spellCheck={false} autoComplete="off" autoCorrect="off" autoCapitalize="off" placeholder="nsec1" className="h-11 w-full rounded-lg border-transparent bg-neutral-200 px-3 placeholder:text-neutral-500 focus:border-blue-500 focus:ring focus:ring-blue-200 dark:bg-neutral-800 dark:placeholder:text-neutral-400 dark:focus:ring-blue-800" /> {nsec.length < 5 ? (
) : null}
{nsec.length > 5 ? ( ) : null}

Private Key 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 your private key to sign this event.

1. In case you store private key in Lume

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

2. In case you do not store private key in Lume

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

) : null} navigate('/auth/onboarding')} > Continue ) : null}
); }