Add support for witness versions 2–16 (Bech32m parsing) #2407
RonnieAvital1
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
|
We'd accept a PR implementing such a change. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the package only supports witness version 0 (P2WPKH/P2WSH) and witness version 1 (P2TR). Any address with a higher witness version fails with UnsupportedWitnessVerError.
Example (from address.go):
// We currently only support P2WPKH and P2WSH, which is // witness version 0 and P2TR which is witness version // 1. if witnessVer != 0 && witnessVer != 1 { return nil, UnsupportedWitnessVerError(witnessVer) }However, according to BIP173 and BIP350, Bech32/Bech32m addresses support witness versions 0 through 16. While only v0 and v1 have defined semantics today, higher versions are valid encodings and should not be rejected outright.
For example, the following addresses are valid Bech32m encodings, but fail with this library:
bc1vq2qcpt0zqnguh74f9ne3v8sqqz3wxd3teswdls (witness v12)
bc10qyp40l5u7z6zvx055lnyxrqnl3wkwcpjpdtsmkx9mq (witness v15)
Proposal:
Update the address parsing logic to accept all witness versions 0–16.
For unrecognized versions (≥2), return the decoded witness version and program bytes without trying to map them to a script type.
Keep P2WPKH, P2WSH, and P2TR as explicit helpers for v0/v1.
This change will make the library consistent with Bitcoin Core behavior:
Core validates v0–v16 witness addresses syntactically.
Only v0/v1 are interpreted semantically; higher versions are treated as “unknown witness program” but still valid encodings.
Beta Was this translation helpful? Give feedback.
All reactions