Skip to content

feat: accept bare extended public keys as scan input - #31

Merged
LORDBABUINO merged 4 commits into
mainfrom
feat/xpub-scan-input
Sep 5, 2026
Merged

feat: accept bare extended public keys as scan input#31
LORDBABUINO merged 4 commits into
mainfrom
feat/xpub-scan-input

Conversation

@LORDBABUINO

Copy link
Copy Markdown
Collaborator

Descriptors are precise but hostile as a user input: most wallets only export an extended public key. This makes a bare xpub (or any SLIP-132 variant) a first-class scan input across engine, CLI and API, entering through the existing descriptor fields with no schema change.

How it works:

  1. model gains expand_input: base58check-decode plus version-byte dispatch. SLIP-132 keys map deterministically (zpub to wpkh, ypub to sh(wpkh), vpub/upub for testnet) and are re-encoded with canonical version bytes. Ambiguous xpub/tpub expand to four script-type candidates (pkh, sh(wpkh), wpkh, tr); candidates without history are harmless, the rescan simply finds nothing for them. A derivation suffix like xpub.../0/* (common in wallet exports) is honored. The existing /0/* to /1/* change-chain inference then applies, so receive and change are both covered.
  2. Pasting a private key is now a hard, safe error. Extended private keys (all ten variants, multisig SLIP-132 included) are detected by version bytes before any expansion or RPC and rejected with guidance, without ever echoing the input. As defense in depth, the descriptor-normalization error display redacts anything that looks like an extended private key, covering even a corrupted-checksum xprv that slips past detection. For a privacy tool, key material in stderr or an API response body is not acceptable, so this path is tested at three layers.
  3. CLI help documents the new input; the API accepts it through the descriptor field, covered by a contract test.

Tests: round-trip unit tests against the BIP-32 vector-1 xpub for every SLIP-132 conversion, rejection tests for all private variants asserting the key never appears in the error text, and an end-to-end regtest test that feeds a bare tpub and finds the wallet's activity through the ambiguous-expansion path. Verified on mainnet: a bare xpub scan derived and recognized 8000 addresses across the four candidates in about two seconds; a real LND account zpub produced a full, correct wallet audit. Suite 57/57 with clippy -D warnings clean.

expand_input() detects bare xpub/tpub/ypub/zpub/upub/vpub inputs via
base58check version bytes. SLIP-132 keys are re-encoded with canonical
version bytes and mapped to their script type; ambiguous xpub/tpub
expand to pkh, sh(wpkh), wpkh, and tr candidates. Everything else
passes through untouched.
analyze_descriptors expands each raw input through expand_input before
normalization, so a bare xpub/tpub (or SLIP-132 key) becomes importable
descriptor candidates. Candidates without activity are harmless watch-
only imports. Covered by a regtest e2e test feeding a bare tpub with
history into the engine.
The CLI --descriptor flag and the API descriptor/descriptors fields
accept bare extended public keys through the engine's expand_input;
help text updated and an HTTP test pins the API contract.
Review follow-ups on xpub scan input:

- expand_input now returns Result and rejects extended PRIVATE keys
  (xprv/tprv/yprv/zprv/uprv/vprv and SLIP-132 multisig Yprv/Zprv/
  Uprv/Vprv) with a dedicated error that never echoes the input;
  previously a pasted xprv travelled to getdescriptorinfo and came
  back verbatim inside DescriptorNormalization, which the CLI prints
  and the API returns.
- Defence in depth: the DescriptorNormalization Display now redacts
  any [xtyzuvYZUV]prv-prefixed alphanumeric run.
- A derivation suffix on a bare key (xpub.../0/*) is now split off
  before decoding and re-attached inside the wrappers, matching what
  the frontend already sends.
- SLIP-132 multisig public keys (Ypub/Zpub/Upub/Vpub) are rejected
  with guidance to provide the wallet descriptor instead.
- xpub integration tests use expect over bare unwrap.
@LORDBABUINO
LORDBABUINO merged commit c12ded4 into main Sep 5, 2026
3 checks passed
@LORDBABUINO
LORDBABUINO deleted the feat/xpub-scan-input branch September 5, 2026 10:15
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