Add BIP-322 signature variant prefixes - #71
Merged
Conversation
aagbotemi
force-pushed
the
feat/signature-prefix
branch
from
July 18, 2026 01:58
7be8f34 to
afcfb4e
Compare
aagbotemi
force-pushed
the
feat/signature-prefix
branch
4 times, most recently
from
July 30, 2026 14:35
f94273d to
61c3565
Compare
aagbotemi
force-pushed
the
feat/signature-prefix
branch
from
August 4, 2026 06:53
61c3565 to
948187f
Compare
sdmg15
reviewed
Aug 12, 2026
|
|
||
| let to_sign = to_sign | ||
| .strip_prefix(FULL_SIGNATURE_PREFIX) | ||
| .unwrap_or(to_sign); |
There was a problem hiding this comment.
I was thinking of a situation where a user by mistake calls verify_simple_encoded but with a signature prefixed with pof. We could have a better error so the user knows what went wrong?
Contributor
Author
There was a problem hiding this comment.
Thank you for the review. I added SignatureVariantMismatch error.
raphjaph
requested changes
Aug 14, 2026
raphjaph
left a comment
Collaborator
There was a problem hiding this comment.
Change looks correct and matches the finalized BIP-322 prefix scheme.
Could you add explicit tests for:
- The official no-prefix fallback vector from basic-test-vectors.json, so the unprefixed path is deliberate rather than incidental (verify_simple_encoded must return Ok(()).):
address: bc1pss0zhytly75awhm6x2hhvd5lnzv3vssgrf9axfheq8ldyzn88ges79fler
message: "No prefix fallback"
signature: "AUCJYOwOjxYAvatTAGYaVlNXBVyFuc4MwNQkOuK2tl8xhfKDONd0NjfYyNSYcRqeCp8hsAnCEPHAVEkO9h6vbQ/R"
- The official prefix error vectors from the same file. verify_simple_encoded this should produce Error::SignatureVariantMismatch:
"incorrect prefix type": fulAUDZwFXUp+adN+/UZj5dVrGAbB3zKs1Vcalz5fCF9srxS63eSWNGvH1NYbrBkPt1BJDUyWUz9zgUxfc63/QheT6M
message "incorrect prefix"
address: bc1pyrgrm6cu6n54jrvkdjd9rvyd3xfyu84s2623awu2srn6mxhscwpsm5644w
- An unknown prefix must still error later in decoding (any error variant is fine here):
"invalid signature prefix": fooAA==
address: bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l
- Extend verify_rejects_mismatched_variant_prefix to the pof permutations. Right now only simple <-> full mismatch is tested; verify_pof_encoded has the same prefix logic and no mismatch coverage (i.e. pof-sig -> verify_simple_encoded errors, smp/ful sig → verify_pof_encoded errors).
Contributor
Author
sdmg15
approved these changes
Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The BIP-322 spec requires signers to prefix the base64 signature with a variant identifier (
smpfor simple,fulfor full, orpoffor proof of funds) and verifiers may only assume the simple variant when no prefix is present. The crate emitted bare base64 from all threesign_*_encodedfunctions and only accepted bare base64 on verification, so prefixed signatures from spec-compliant implementations failed to decode.This prepends the variant prefix in
sign_simple_encoded,sign_full_encoded, andsign_pof_encoded, and strips it in the corresponding verifiers, falling back to the unprefixed encoding when absent.Rebased on #67.
Changes
SIMPLE_SIGNATURE_PREFIX, FULL_SIGNATURE_PREFIX, and POF_SIGNATURE_PREFIX constantsCloses #70