Skip to content

fix: route to lightning only on a leading lightning: scheme - #228

Draft
jvsena42 wants to merge 2 commits into
masterfrom
fix/scanner-lightning-prefix
Draft

jvsena42 wants to merge 2 commits into
masterfrom
fix/scanner-lightning-prefix

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #227

Cause

Scanner::decode took the Lightning branch when the lowercased input contained lightning:. A bitcoin: URI with lightning: inside a parameter value, such as bitcoin:<address>?label=pay%20lightning:x or the same in message, went to decode_lightning and failed with InvalidFormat.

The leading lightning: strip at the top of decode was also case-sensitive. LIGHTNING: followed by an LNURL, a node id (pubkey@host:port) or a Lightning address skipped that strip, matched the contains check, and failed in the BOLT11 decoder.

Change

  • The Lightning branch is taken only when the trimmed input (after the lightning: strip and bitkit:// handling) starts with lightning: in any case, or is a bare lnbc/lntb invoice (lnbcrt and lntbs are covered by those prefixes). A bitcoin: URI goes to decode_bitcoin_uri, which already reads its lightning parameter.
  • The leading lightning: strip is now case-insensitive, the same way decode_onchain strips bitcoin:. LIGHTNING:LNURL1…, LIGHTNING:<pubkey>@host:port and LIGHTNING:user@domain now reach the LNURL, node-id and Lightning address paths. LIGHTNING:<BOLT11> decodes as before.
  • Checked the other contains(...) calls in decode. The node-id @ check only fires when the part before the single : contains @, so a bitcoin: URI never matches; contains("onion") only runs inside that branch. Neither has the bug.
  • CHANGELOG entry under Unreleased. No version bump or binding changes; the public API is unchanged.

Known, pre-existing, out of scope

  • Simnet invoices (lnsb) are not recognised as bare invoices.
  • lightning:// (with slashes) is not stripped.
  • BOLT12 offers (lno…) are not decoded.

Tests

New scanner tests:

  • label containing lightning: (percent-encoded, plain, uppercase)
  • message containing lightning: (percent-encoded and plain)
  • uppercase QR form BITCOIN:<ADDR>?LABEL=LIGHTNING:X decodes as on-chain
  • LIGHTNING: prefix with a lowercase invoice still decodes as Lightning
  • LIGHTNING:LNURL1… and Lightning:lnurl1… (LNURL-auth, no network request) decode as LnurlAuth
  • LIGHTNING:<pubkey>@host:port decodes as NodeId
  • bitcoin:?lightning=<bolt11> still decodes as Lightning
  • bitcoin:<address>?...&lightning=<bolt11> decodes as on-chain with the invoice in params

Run locally (CI does not run modules::scanner):

  • cargo test --locked --lib modules::scanner: 87 passed, 0 failed.
  • Same tests against the old implementation.rs: master fails 6 (label, message, address plus lightning, uppercase QR label, uppercase LNURL, uppercase node id); 53e5b18 fails 2 (uppercase LNURL, uppercase node id).
  • cargo fmt --check: clean.
  • cargo clippy --locked --lib --tests: same warning set as before this change (compared with the previous head, 53e5b18, which added none over master).

🤖 Generated with Claude Code

Scanner::decode sent any input containing `lightning:` to the Lightning
decoder, so a bitcoin: URI with `lightning:` in a label or message
failed to decode. Match the scheme at the start only.

Fixes #227

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42 jvsena42 self-assigned this Nov 25, 2026
The leading `lightning:` strip was case-sensitive, so `LIGHTNING:` with
an LNURL, node id or Lightning address reached the BOLT11 decoder and
failed. Also test an uppercase bitcoin: URI with `LIGHTNING:` in its
label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Scanner decodes a bitcoin: URI as Lightning when a value contains lightning:

1 participant