jmwallet.cli._wallet_selection
jmwallet.cli._wallet_selection
Helpers for resolving a wallet identity (8-char BIP32 fingerprint) for
CLI commands that read unencrypted, per-wallet on-disk data such as
jm-wallet history, jm-wallet list-bonds and
jm-wallet registry-show.
These commands originally required the wallet mnemonic (and, when a BIP39 passphrase was set, the passphrase too) just to recompute the fingerprint that keys the data directory. That hurts usability:
- the user already typed the passphrase elsewhere (
info,send); - knowing the fingerprint at all should be enough to read public data;
- when only one wallet has ever written to the directory, asking for the mnemonic again is needless friction.
This module centralizes the lookup order so every command that needs a wallet fingerprint behaves the same:
--wallet-fingerprint <fp>if given (validated).- Derived from
--mnemonic-file(+ BIP39 passphrase resolution). - Auto-detected when exactly one wallet identity is present on disk.
- Otherwise: a clear error listing the known fingerprints and the
ways to disambiguate (
--mnemonic-file [-passphrase]/--wallet-fingerprint/--all-walletswhere applicable).
Classes
Functions
resolve_wallet_fingerprint(settings: JoinMarketSettings, *, mnemonic_file: Path | None, wallet_fingerprint: str | None, prompt_bip39_passphrase: bool, list_known_fingerprints: Callable[[], list[str]], command_label: str, allow_all_wallets: bool = False, fall_back_to_configured_mnemonic: bool = False) -> str | None
Resolve the active wallet fingerprint for an offline read command.
Args:
settings: CLI settings (used to read configured mnemonic / passphrase).
mnemonic_file: Optional --mnemonic-file value.
wallet_fingerprint: Optional --wallet-fingerprint value (8 hex chars).
prompt_bip39_passphrase: Whether to prompt for a BIP39 passphrase
when the mnemonic is supplied and no passphrase is otherwise
configured.
list_known_fingerprints: Callable returning the fingerprints
already present on disk for this command's data source
(e.g. history.csv rows or fidelity_bonds_*.json
files). Used to auto-detect a single wallet and to render a
helpful error listing the alternatives.
command_label: Human-readable label used in error messages,
e.g. "jm-wallet history".
allow_all_wallets: When True, the error message for the
ambiguous case mentions --all-wallets as an alternative.
fall_back_to_configured_mnemonic: When True and neither
--wallet-fingerprint nor --mnemonic-file was given,
derive the fingerprint from the mnemonic configured in
config.toml / env / the default wallet path (the same
resolution jm-wallet info uses). This makes per-wallet
read commands work out of the box for the configured wallet.
It is opt-in because commands that aggregate across wallets
(e.g. history) must not silently filter to one wallet.
Returns:
The resolved 8-char fingerprint, or raises typer.Exit(1)
when the input is ambiguous or invalid. When no wallet identity
is determinable at all and the data source is empty, returns
None so the caller can fall through to its own
"nothing to show" path.
Source code in jmwallet/src/jmwallet/cli/_wallet_selection.py
56 57 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 95 96 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 145 146 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 178 | |
validate_fingerprint(fingerprint: str) -> str
Normalize and validate an 8-char hex wallet fingerprint.
Raises typer.Exit(1) with a friendly message on invalid input.
Returns the lowercased fingerprint on success.
Source code in jmwallet/src/jmwallet/cli/_wallet_selection.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |