Skip to content

fix(settings): sanitize pasted descriptor input and reject corrupted keys early - #165

Open
jvsena42 wants to merge 1 commit into
mainfrom
fix/descriptor-input-whitespace
Open

jvsena42 wants to merge 1 commit into
mainfrom
fix/descriptor-input-whitespace

Conversation

@jvsena42

Copy link
Copy Markdown
Owner

Part of #164 (the "app doesn't accept this zpub" report).

What was found

On the current build a clean zpub pasted from BlueWallet's export screen is accepted (converted to wpkh(xpub…/<0;1>/*) and loaded by the node; verified on the emulator). The failing inputs found are keys that arrive with stray whitespace or a typo:

  • A trailing newline or tab (line-wrapped exports, notes, chat messages) was forwarded to the node verbatim: removeSpaces() only dropped spaces, the SLIP-132 conversion silently fell back to the raw zpub, and the node answered with an opaque MiniscriptError(Parse(Tree(Checksum(InvalidCharacter { ch: '\n' … })))).
  • A truncated or mistyped key produced an equally opaque Bip32Xpub(Base58(IncorrectChecksum …)) wallet error.

Changes

  • DescriptorUtils.sanitize drops all whitespace from descriptor input (descriptors and extended keys never contain any); applied while typing and again before wrapping.
  • DescriptorUtils.extendedKeyError checks a bare extended key's Base58Check checksum on the app side and the Settings screen shows a readable message ("This extended key is not valid (bad checksum)…") instead of the wallet error. Full descriptors are still left to the node.

Tests

  • DescriptorUtilsTest: sanitize, wrapping a zpub with a trailing newline, checksum validation (public BIP84 test vector).
  • SettingsViewModelTest: typed text loses whitespace; a corrupted key is rejected without an RPC call.
  • ./gradlew :app:testDebugUnitTest detekt lintDebug pass; the paste-from-BlueWallet flow verified on the emulator.

🤖 Generated with Claude Code

…keys early

A pasted extended key that carries a trailing newline or tab (line-wrapped
exports, notes, chat messages) was forwarded to the node verbatim: the
SLIP-132 conversion silently fell back to the raw zpub and the node answered
with an opaque miniscript checksum error. Descriptors and extended keys never
contain whitespace, so drop all of it from the field and again before
wrapping, and check a bare key's Base58Check checksum on the app side so a
truncated or mistyped key gets a readable message instead of a wallet error.

The key checks and the descriptor wrapping run on an injected default
dispatcher and the RPC on the IO one (`CoroutineDispatchers`), instead of on
the main thread; the Settings tests drive both with a StandardTestDispatcher
under runTest.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jvsena42
jvsena42 force-pushed the fix/descriptor-input-whitespace branch from 6c6938c to 42b0b1c Compare September 25, 2026 21:11
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.

1 participant