recoverPublicKey static method
Recover the 64-byte uncompressed public key (X‖Y, no 0x04 prefix) that
produced r/s over messageHash for the given recoveryId (0/1),
or null if recoveryId doesn't yield a valid point. This lets a
verifier check a signature against a known address/pubkey instead of
only checking r/s/v are in range.
Implementation
static Uint8List? recoverPublicKey(
BigInt r, BigInt s, int recoveryId, Uint8List messageHash) {
try {
final pubKeyBigInt = _recoverFromSignature(
recoveryId, ECSignature(r, s), messageHash, secp256k1);
if (pubKeyBigInt == null) return null;
return encodeBigInt(pubKeyBigInt, endian: Endian.big, bitLength: 512);
} catch (_) {
// Invalid points, non-invertible scalars, and infinity are all
// untrusted-signature failures, not verifier errors.
return null;
}
}