verify static method

bool verify(
  1. String message,
  2. Uint8List publicKey,
  3. String signature
)

Verify a raw r||s signature: the first 32 bytes are r, the next 32 are s. Any bytes beyond that are ignored — some callers (e.g. CKB, HNS) append a trailing recovery id that this check doesn't need. Returns false (instead of throwing) for input shorter than 64 bytes or a public key that doesn't decode to a point on the curve, so a malformed signature fails closed rather than crashing the caller.

Implementation

static bool verify(String message, Uint8List publicKey, String signature) {
  final sigBytes = dynamicToUint8List(signature);
  if (sigBytes.length < 64) return false;

  ECPoint? Q;
  try {
    Q = secp256k1.curve.decodePoint(publicKey);
  } catch (_) {
    return false;
  }
  if (Q == null) return false;

  BigInt r = decodeBigInt(sigBytes.sublist(0, 32), endian: Endian.big);
  BigInt s = decodeBigInt(sigBytes.sublist(32, 64), endian: Endian.big);

  final signer = ECDSASigner(null, HMac(SHA256Digest(), 64));
  signer.init(false, PublicKeyParameter(ECPublicKey(Q, secp256k1)));
  return signer.verifySignature(
      dynamicToUint8List(message), ECSignature(r, s));
}