import { useState } from 'react'; import { generateSeedPhrase, validateSeedPhrase } from '@dgb-wallet/core'; import { Keystore, LocalStorageAdapter } from '@dgb-wallet/keystore'; import { useActiveSeed } from './ActiveSeed.js'; import { useSessionAuth } from './session-auth.js'; // Create a fresh BIP39 wallet: generate → user writes it down + confirms // → optionally encrypt-save under a label → activate. No paths cross // with import. Kept its own page so users don't accidentally overwrite // something. const keystore = new Keystore(new LocalStorageAdapter()); type Step = 'show' | 'confirm' | 'save'; export function CreateWalletPage({ onBack }: { onBack: () => void }): JSX.Element { const { setActive } = useActiveSeed(); const { masterPassword } = useSessionAuth(); const [phrase] = useState(() => generateSeedPhrase(128)); // 12 words const [step, setStep] = useState('show'); const [ack, setAck] = useState(false); const [confirmPhrase, setConfirmPhrase] = useState(''); const [label, setLabel] = useState('primary'); const [busy, setBusy] = useState(false); const [err, setErr] = useState(null); const words = phrase.split(' '); const confirmOk = confirmPhrase.trim() === phrase && validateSeedPhrase(phrase); async function onSave(): Promise { if (!confirmOk) return; if (!masterPassword) { setErr('Session locked — unlock with the master password first.'); return; } setBusy(true); setErr(null); try { const already = await keystore.exists(label); if (already) { const ok = confirm(`Overwrite existing "${label}"? This can't be undone.`); if (!ok) { setBusy(false); return; } } await keystore.save(label, phrase, masterPassword, true); setActive(phrase, label); onBack(); // returns to dashboard because the seed just became active } catch (e) { setErr((e as Error).message); } finally { setBusy(false); } } function onActivateWithoutSaving(): void { // Advance to the dashboard with the seed loaded in memory only. // Same posture as pasting a throwaway seed via Import. Use the // chosen label anyway so the header can display something better // than a hex hash. setActive(phrase, label); onBack(); } return ( <>

Create a new wallet

A fresh BIP39 seed generated in this browser. It has never been on any server. Write it down before doing anything else — if you lose it and haven't set a passphrase, the funds are gone.

{step === 'show' && ( <>
⚠️ Anyone with these 12 words can spend your funds. Write them on paper, store offline, never take a screenshot, never paste into chat. Nothing on this screen is uploaded anywhere.
{words.map((w, i) => (
{i + 1} {w}
))}
)} {step === 'confirm' && ( <>
One more time. Type the whole phrase back to prove you wrote it down. Copy-paste won't help you later if the paper is gone.