Skip to content

fix: accept tsp recipients on Signet and Testnet4 - #70

Open
kkdao wants to merge 2 commits into
bitcoindevkit:masterfrom
kkdao:fix/tsp-network-group-compat
Open

fix: accept tsp recipients on Signet and Testnet4#70
kkdao wants to merge 2 commits into
bitcoindevkit:masterfrom
kkdao:fix/tsp-network-group-compat

Conversation

@kkdao

@kkdao kkdao commented Aug 21, 2026

Copy link
Copy Markdown

Description

Fixes #68

Every test network encodes to the same tsp prefix, so parsing always returns Network::Testnet. sp-cli2 new-tx --to-sp compared that to the wallet's network with !=, so Signet and Testnet4 wallets rejected valid codes, including their own.

Adds SilentPaymentCode::is_valid_for_network, which compares prefixes instead, and uses it in sp-cli2. The empty bail!("") next to it gets a message.

Notes to the reviewers

Encoding is unchanged — this only changes how compatibility is judged. prefix_assignment_is_unchanged pins that.

The prefix match already in Display::fmt is lifted into hrp_for_network and shared, so the two can't drift.

Groups follow this crate's encoder, not bitcoin::NetworkKind, which groups regtest with the other test networks while this crate gives regtest its own sprt.

Tests are in silentpayments rather than next to the CLI because cli/v2 isn't in default-members and just check/just test exclude it, so a test there would never run. I built and linted cli/v2 directly to check this change.

Changelog notice

Added: SilentPaymentCode::is_valid_for_network and encoding::hrp_for_network.

Fixed: sp-cli2 new-tx --to-sp rejected valid tsp recipients on Signet and Testnet4.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

kkdao added 2 commits August 21, 2026 17:35
BIP 352 assigns one human readable prefix to every test network, so codes
written for Testnet, Testnet4 and Signet are indistinguishable once encoded and
parsing reports `Network::Testnet` for all three. Callers that check a parsed
code against a wallet with `code.network == wallet.network()` consequently
reject valid recipients on Signet and Testnet4.

What the encoding carries is the prefix, not the exact chain, so expose a
predicate that compares prefixes and leave the encoding itself untouched.
`Display` now shares that mapping through `hrp_for_network` instead of repeating
the match, so the two cannot drift apart.

The groups follow this crate's encoder rather than `bitcoin::NetworkKind`:
regtest has its own `sprt` prefix here, while `NetworkKind` groups it with the
other test networks.
`new-tx --to-sp` compared the parsed code's network to the wallet's with `!=`.
Because every test network encodes to the same `tsp` prefix and parsing reports
`Network::Testnet` for all of them, a Signet or Testnet4 wallet rejected codes
that were written for it, including its own.

Compare prefixes through `is_valid_for_network` instead, which is the
distinction the encoding carries. The bail also gains a message; it was empty,
so the rejection surfaced as an error with no text.
@kkdao
kkdao force-pushed the fix/tsp-network-group-compat branch from 01408a9 to ea4cd0c Compare August 21, 2026 21:36
@kkdao
kkdao marked this pull request as draft August 21, 2026 21:48
@kkdao
kkdao marked this pull request as ready for review August 21, 2026 21:56
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.

sp-cli2 --to-sp rejects tsp recipients on Signet and Testnet4

1 participant