From b2ccff5b1904fc3142e268f78d58754f9255dd33 Mon Sep 17 00:00:00 2001 From: Harvey Zuccon Date: Tue, 19 May 2026 13:31:01 +0200 Subject: [PATCH] Add random mnemonic generation in seed input screen --- src/tui/screens/SeedInput.tsx | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/tui/screens/SeedInput.tsx b/src/tui/screens/SeedInput.tsx index 6a20c74..ecb1c81 100644 --- a/src/tui/screens/SeedInput.tsx +++ b/src/tui/screens/SeedInput.tsx @@ -19,7 +19,7 @@ import path from 'path'; import { createMnemonicFile } from '../../cli/mnemonic.js'; import { getMnemonicsDir } from '../../utils/paths.js'; import { BCHMnemonicURL } from '../../utils/bch-mnemonic-url.js'; -import { encodeBip39Mnemonic } from '@bitauth/libauth'; +import { encodeBip39Mnemonic, generateBip39Mnemonic } from '@bitauth/libauth'; /** * Status message type. @@ -41,7 +41,7 @@ interface MnemonicFileEntry { * Focus sections the user can tab between. * When saved wallets exist the file list is shown first. */ -type FocusSection = 'files' | 'input' | 'saveCheckbox' | 'button'; +type FocusSection = 'files' | 'input' | 'saveCheckbox' | 'generateRandomSeed' | 'button'; /** * Reads mnemonic-* files from ~/.config/xo-cli/mnemonics/ (same as xo-cli), @@ -117,8 +117,8 @@ export function SeedInputScreen(): React.ReactElement { * The ordered list of focusable sections (files section only when entries exist). */ const focusSections: FocusSection[] = mnemonicFiles.length > 0 - ? ['files', 'input', 'saveCheckbox', 'button'] - : ['input', 'saveCheckbox', 'button']; + ? ['files', 'input', 'generateRandomSeed', 'saveCheckbox', 'button'] + : ['input', 'generateRandomSeed', 'saveCheckbox', 'button']; /** * Shows a status message with the given type. @@ -202,7 +202,7 @@ export function SeedInputScreen(): React.ReactElement { }, [mnemonicFiles, doInitialize]); // Keyboard navigation - useBlockableInput((_input, key) => { + useBlockableInput((input, key) => { if (isSubmitting) return; // Tab / Shift-Tab to cycle focus sections @@ -219,7 +219,7 @@ export function SeedInputScreen(): React.ReactElement { // Space or Enter toggles "save mnemonic" when that row is focused if (focusedSection === 'saveCheckbox') { - if (_input === ' ' || key.return) { + if (input === ' ' || key.return) { setSaveMnemonicChecked((v) => !v); return; } @@ -241,6 +241,18 @@ export function SeedInputScreen(): React.ReactElement { } } + // Ctrl-R generates a random seed phrase and fills it in the input + if (key.ctrl && input === 'r') { + setSeedPhrase(generateBip39Mnemonic()); + return; + } + + // If pressing enter while the generate random seed section is focused, generate a random seed and fill it in the input + if (key.return && focusedSection === 'generateRandomSeed') { + setSeedPhrase(generateBip39Mnemonic()); + return; + } + // Enter on button submits manual seed if (key.return && focusedSection === 'button') { handleSubmit(); @@ -358,6 +370,19 @@ export function SeedInputScreen(): React.ReactElement { /> + {/* Generate random seed phrase and fill in the input */} + + + Generate Random Seed + + + (Ctrl-R) + + {/* Save mnemonic checkbox (manual entry only; applies on Continue) */}