3636 parse_codex32 ,
3737 recover_secret ,
3838)
39- from codex32 .correction import _residue_low_discrimination , correct_worksheet_residue
39+ from codex32 .correction import _best , _residue_low_discrimination , correct_worksheet_residue
4040from codex32 .errors import CodexError , HeaderCollision , InvalidCorrectionInput
4141from codex32 .generation import (
4242 ConfirmationResult ,
@@ -94,9 +94,9 @@ def _secret(artifacts: list[Artifact]) -> Secret:
9494 raise _UsageError (str (error )) from error
9595
9696
97- def _master_seed () -> MasterSeed :
97+ def _master_seed (fingerprint : Callable [[ MasterSeed ], bytes ] | None = None ) -> MasterSeed :
9898 if isinstance (
99- value := _secret (_artifacts (profiles = (Profile .MS ,), initial_prefix = "MS1" )),
99+ value := _secret (_artifacts (profiles = (Profile .MS ,), initial_prefix = "MS1" , fingerprint = fingerprint )),
100100 MasterSeed ,
101101 ):
102102 return value
@@ -520,8 +520,8 @@ def _checksum(plain: bool) -> int:
520520 artifact = complete_checksum (text )
521521 except (CodexError , ValueError ) as error :
522522 raise _UsageError (
523- "The input does not match the expected format of the filled-out "
524- "non-pink bold squares. \n Consult the Codex32 Book and check the worksheet ."
523+ "The worksheet input is not in the expected format. \n "
524+ "Consult the Codex32 Book and check the non-pink bold squares ."
525525 ) from error
526526 clear = "\x1b [3J\x1b [2J\x1b [H" if sys .stderr .isatty () else ""
527527 repeated = _text (clear + "Re-enter the worksheet non-pink bold squares" , prompt_end = ":\n \n > MS1" )
@@ -591,18 +591,22 @@ def _correct(
591591 hrp ,
592592 byte_length ,
593593 value [: separator + 1 ],
594- fingerprint_match = _fingerprint_matcher (core .fingerprint if core is not None else None ),
595594 )
596595 if not complete and not candidates :
597596 raise _CommandError ("The correction search did not complete within ten seconds." )
598597 if ambiguous :
599598 raise _CommandError ("More than one correction is possible; none was selected." )
600599 if not candidates :
601600 raise _CommandError ("No valid correction found. Check the original backup." )
601+ if context .master_seed and len (candidates ) > 1 :
602+ core = core or _connected_core ("correct" )
603+ candidates = _best (candidates , fingerprint_match = _fingerprint_matcher (core .fingerprint ))
602604 if len (candidates ) != 1 :
603605 raise _CommandError ("Several corrections are possible. Check the original backup." )
604606 fixed = candidates [0 ]
605607 _require_recovery (fixed .low_checksum_discrimination )
608+ if context .master_seed :
609+ core = core or _connected_core ("correct" )
606610 warning = (
607611 "Warning: This is only a correction suggestion. Compare it with the original backup before using it."
608612 )
@@ -632,7 +636,7 @@ def _bitcoin_core(account: int, timestamp: int | Literal["now"], testnet: bool,
632636 core = _connected_core ()
633637 if testnet and core .chain == "main" :
634638 raise _UsageError ("The connected Bitcoin Core is mainnet; remove --testnet." )
635- secret = _master_seed ()
639+ secret = _master_seed (core . fingerprint )
636640 return _initialize_wallet (
637641 core ,
638642 secret ,
@@ -648,9 +652,7 @@ def _dispatch(arguments: argparse.Namespace, context: _CliContext) -> int:
648652 command = cast (str , arguments .command )
649653 plain = bool (getattr (arguments , "plain" , False ))
650654 fingerprint_core : BitcoinCore | None = None
651- if context .master_seed and (
652- command in ("secret" , "share" ) or (command == "correct" and not bool (arguments .residue ))
653- ):
655+ if context .master_seed and command in ("secret" , "share" ):
654656 fingerprint_core = _connected_core (command )
655657 if command == "check" :
656658 artifacts = _artifacts (
@@ -712,7 +714,7 @@ def _dispatch(arguments: argparse.Namespace, context: _CliContext) -> int:
712714 raise _UsageError (f"The connected Bitcoin Core is not on the requested { expected } ." )
713715 _print (
714716 multisig_account_xpub (
715- _master_seed (),
717+ _master_seed (core . fingerprint ),
716718 integration = core ,
717719 account = int (arguments .account ),
718720 )
0 commit comments