verifyBtcMessageHeader function
BIP-137: the recovery header names the address type a verifier derives before comparing. A header of the wrong range produces a signature that LOOKS fine (65 bytes, valid base64) but fails every verifier downstream — this check is the only place that difference is visible.
Implementation
VerifyResult verifyBtcMessageHeader(VerifyBtcMessageHeaderArgs args) {
if (args.signature.isEmpty) {
return failed('empty signature');
}
final header = args.signature[0];
final range = _headerRangeFor(args.address);
if (range == null) {
return unverifiable(
'address kind has no BIP-137 header range to check against');
}
if (header >= range.low && header <= range.high) return verified;
return failed(
'recovery header $header does not match a ${range.label} address '
'(BIP-137 expects ${range.low}..${range.high}); this signature would not '
'verify against the address it was asked to sign for',
);
}