jmwallet.cli.mnemonic
jmwallet.cli.mnemonic
Mnemonic generation, validation, encryption, and interactive input.
Functions
decrypt_mnemonic(encrypted_data: bytes, password: str) -> str
Decrypt a mnemonic with a password.
Args: encrypted_data: The encrypted bytes (salt + Fernet token) password: The password for decryption
Returns: The decrypted mnemonic phrase
Raises: ValueError: If decryption fails (wrong password or corrupted data)
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
encrypt_mnemonic(mnemonic: str, password: str) -> bytes
Encrypt a mnemonic with a password using Fernet (AES-128-CBC).
Uses PBKDF2 to derive a key from the password.
Args: mnemonic: The mnemonic phrase to encrypt password: The password for encryption
Returns: Encrypted bytes (base64-encoded internally by Fernet)
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
format_word_suggestions(matches: list[str], max_display: int = 8) -> str
Format word suggestions for display.
Args: matches: List of matching words max_display: Maximum number of words to display
Returns: Formatted suggestion string
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
generate_mnemonic_secure(word_count: int = 24) -> str
Generate a BIP39 mnemonic from secure entropy.
Args: word_count: Number of words (12, 15, 18, 21, or 24)
Returns: BIP39 mnemonic phrase with valid checksum
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
get_bip39_wordlist() -> list[str]
Get the BIP39 English wordlist.
Returns: List of 2048 BIP39 words in order.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
252 253 254 255 256 257 258 259 260 261 262 | |
get_word_completions(prefix: str, wordlist: list[str]) -> list[str]
Get BIP39 words that start with the given prefix.
Args: prefix: The prefix to match (case-insensitive) wordlist: The BIP39 wordlist
Returns: List of matching words
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
265 266 267 268 269 270 271 272 273 274 275 276 277 | |
interactive_mnemonic_input(word_count: int = 24) -> str
Interactively input a BIP39 mnemonic with autocomplete support.
Features: - Real-time suggestions as you type (shows matches when <= 10) - Auto-completes when only one word matches (after 3+ chars typed) - Tab completion for partial matches - Supports pasting all words at once - Validates each word against BIP39 wordlist
Args: word_count: Expected number of words (12, 15, 18, 21, or 24)
Returns: The complete mnemonic phrase
Raises: typer.Exit: If user cancels input (Ctrl+C)
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
load_mnemonic_file(mnemonic_file: Path, password: str | None = None) -> str
Load a mnemonic from a file, decrypting if necessary.
Args: mnemonic_file: Path to the mnemonic file password: Password for decryption (required if file is encrypted)
Returns: The mnemonic phrase
Raises: ValueError: If file is encrypted but no password provided
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
prompt_password_with_confirmation(max_attempts: int = 3) -> str
Prompt for a password with confirmation, retrying on mismatch.
Args: max_attempts: Maximum number of attempts before giving up
Returns: The confirmed password
Raises: typer.Exit: If passwords don't match after max_attempts
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
save_mnemonic_file(mnemonic: str, output_file: Path, password: str | None = None) -> None
Save a mnemonic to a file, optionally encrypted.
Args: mnemonic: The mnemonic phrase to save output_file: The output file path password: Optional password for encryption
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
validate_mnemonic(mnemonic: str) -> bool
Validate a BIP39 mnemonic phrase.
Args: mnemonic: The mnemonic phrase to validate
Returns: True if valid, False otherwise
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |