jmwallet.cli.mnemonic
jmwallet.cli.mnemonic
Mnemonic generation, validation, encryption, and interactive input.
Attributes
FIDELITY_BOND_RECOVERY_COMPLETE = 'complete'
module-attribute
FIDELITY_BOND_RECOVERY_NOT_REQUIRED = 'not_required'
module-attribute
FIDELITY_BOND_RECOVERY_PENDING = 'pending'
module-attribute
MnemonicMetaValue = int | str
module-attribute
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
97 98 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 | |
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
58 59 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 | |
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
494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
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
466 467 468 469 470 471 472 473 474 475 476 | |
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
479 480 481 482 483 484 485 486 487 488 489 490 491 | |
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
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
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
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 245 | |
load_mnemonic_meta(mnemonic_file: Path) -> dict[str, MnemonicMetaValue]
Load wallet metadata from a companion .meta file.
Returns an empty dict if the file does not exist (backward-compatible with mnemonics created before this feature was added).
Args: mnemonic_file: Path to the mnemonic file.
Returns:
Dict with metadata fields (creation_height, fingerprint).
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
load_mnemonic_meta_fingerprint(mnemonic_file: Path) -> str | None
Return the stored wallet fingerprint from a .meta file, if valid.
Returns None when the file is missing, has no fingerprint field,
or the value is not a valid 8-char hex string. This lets per-wallet read
commands resolve the active wallet without decrypting the mnemonic.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
mark_fidelity_bond_recovery_complete(mnemonic_file: Path, wallet_fingerprint: str) -> None
Persist successful completion of the imported-wallet bond scan.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
413 414 415 416 417 418 419 420 | |
mnemonic_requires_fidelity_bond_recovery(mnemonic_file: Path, wallet_fingerprint: str) -> bool
Return whether a file-backed wallet still needs canonical bond recovery.
New imports are explicitly marked pending, while generated wallets are marked not-required. For wallets created by older releases, a valid creation height identifies a generated wallet; metadata without one is treated as a restored wallet and receives one recovery scan.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
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
147 148 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 175 176 177 | |
reset_mnemonic_meta(mnemonic_file: Path) -> None
Remove metadata that belongs to mnemonic contents being replaced.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
275 276 277 | |
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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
save_mnemonic_meta(mnemonic_file: Path, *, creation_height: int | None = None, fingerprint: str | None = None, fidelity_bond_recovery: str | None = None) -> None
Persist wallet metadata alongside a mnemonic file.
The metadata is stored as a small JSON file (<mnemonic_file>.meta)
next to the mnemonic file. Existing fields are preserved: only the
fields passed here are added/updated, so writing creation_height
does not drop a previously stored fingerprint and vice versa.
Args:
mnemonic_file: Path to the mnemonic file (the .meta suffix is added).
creation_height: Block height at the time the wallet was created.
fingerprint: 8-char hex BIP32 m/0 wallet fingerprint. Stored so
per-wallet read commands (history, list-bonds, registry-show)
can resolve the active wallet's identity without decrypting the
mnemonic.
fidelity_bond_recovery: Durable state for the one-time canonical bond
scan performed after mnemonic import.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
update_mnemonic_meta_fingerprint(mnemonic_file: Path, fingerprint: str) -> None
Backfill the wallet fingerprint into the .meta file if not already set.
No-op when the stored fingerprint already matches, avoiding needless rewrites. Failures are swallowed (best-effort cache) so a read-only data directory never breaks the calling command.
Source code in jmwallet/src/jmwallet/cli/mnemonic.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
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
45 46 47 48 49 50 51 52 53 54 55 | |