Skip to content

fix(htnwallet): require a spacing choice for unevenly spaced mnemonics - #134

Merged
MattF42 merged 2 commits into
HoosatNetwork:2.19.2from
Evern00b-fi:fix/htnwallet-mnemonic-spacing-choice
Nov 30, 2026
Merged

MattF42 merged 2 commits into
HoosatNetwork:2.19.2from
Evern00b-fi:fix/htnwallet-mnemonic-spacing-choice

Conversation

@Evern00b-fi

Copy link
Copy Markdown

Depends on: #132, which must be merged first: the tests here use its command-line test helper. Until then this branch also contains that commit; the change of this PR is the last commit.

Problem. Every key of a wallet, the secp256k1 key tree and the ML-DSA-44 keys, is derived from the exact bytes of the mnemonic, while the validity check splits the mnemonic on any run of white space. create --import therefore accepted the words with a doubled space or a tab between two of them and derived a different wallet than the same words written normally: one that a written-down backup of the words does not restore. Nothing told the user.

Change. create --import reads each mnemonic and compares it with the same words joined by single spaces (libhtnwallet.NormalizeMnemonic, which already exists).

  • If they are equal, nothing changes.
  • If not, the import is refused with a message naming both choices: --normalize-mnemonic uses single spaces and therefore other keys than an older wallet created from the uneven text; --raw-mnemonic keeps the separators as typed, the earlier behaviour, to restore such an older wallet. The mnemonic itself is not echoed.
  • With --normalize-mnemonic a notice says that spacing was changed and how to restore an older wallet instead. Giving both flags is an error.

Validation. TestImportedMnemonicSpacing (keys package) checks which text is used in each mode. TestCreateImportMnemonicReportsNormalizedWhitespace, TestRawMnemonicHelpDescribesLegacySpacing and TestLegacyMnemonicReimportRequiresSpacingChoice run create as a child process: the notice, the help text, that a reimport without a choice or with both flags leaves an existing keys file unchanged, and that --raw-mnemonic restores the same keys as before. All four fail with the old code (it imported the uneven text silently and had neither flag) and pass after; they call functions and flags this change adds, so they do not build on the base as written. gofmt -l, go vet ./cmd/htnwallet/... and go test -race -count=1 ./cmd/htnwallet/... pass with Go 1.27.4 on linux/amd64.

Compatibility and limits. Only create --import changes, and only for mnemonics with uneven spacing; normally written mnemonics import as before. A script that imported such a mnemonic must now add one of the two flags. Keys files and the daemon are unaffected. This is older than ML-DSA-44 and independent of the fork.

AI disclosure: prepared with AI assistance (OpenAI Codex and Claude by Anthropic).

Evern00b-fi and others added 2 commits November 29, 2026 12:36
A password, private key or web wallet export password prompt panicked with
a stack trace when standard input was not a terminal. The command now says
which value it could not ask for and which flag supplies it, and exits 1.
Behaviour on a terminal is unchanged.

AI disclosure: prepared with AI assistance (OpenAI Codex and Claude by Anthropic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
create --import accepted a mnemonic with a doubled space or a tab between
words and derived other keys than the same words written normally. Such a
mnemonic is now refused unless --normalize-mnemonic (single spaces) or
--raw-mnemonic (the separators as typed, the earlier behaviour) is given.

AI disclosure: prepared with AI assistance (OpenAI Codex and Claude by Anthropic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a86f751-be21-434f-a96d-f96347bd2d2c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@MattF42
MattF42 merged commit ca6caf6 into HoosatNetwork:2.19.2 Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants