verifyMessage method

bool verifyMessage(
  1. List<int> message,
  2. String messagePrefix,
  3. List<int> signature
)

Verifies an ECDSA signature against a given message, considering the message prefix.

Implementation

bool verifyMessage(
    List<int> message, String messagePrefix, List<int> signature) {
  if (signature.length != 64 && signature.length != 65) {
    throw const ArgumentException(
        "bitcoin signature must be 64 bytes without recover-id or 65 bytes with recover-id");
  }
  final List<int> messgaeHash = QuickCrypto.sha256Hash(
      BitcoinSignerUtils.magicMessage(message, messagePrefix));
  List<int> correctSignature =
      signature.length == 65 ? signature.sublist(1) : List.from(signature);
  List<int> rBytes = correctSignature.sublist(0, 32);
  List<int> sBytes = correctSignature.sublist(32);
  final ecdsaSignature = ECDSASignature(
      BigintUtils.fromBytes(rBytes), BigintUtils.fromBytes(sBytes));

  return verifyKey.verify(ecdsaSignature, messgaeHash);
}