verify method

  1. @override
Future<bool> verify(
  1. List<int> message, {
  2. required Signature signature,
})
override

Verifies the signature.

Implementation

@override
Future<bool> verify(List<int> message, {required Signature signature}) async {
  // Check that parameters appear valid
  final publicKeyBytes = (signature.publicKey as SimplePublicKey).bytes;
  final signatureBytes = signature.bytes;
  if (publicKeyBytes.length != 32) {
    throw ArgumentError.value(
      signature,
      'signature',
      'Invalid public key length',
    );
  }
  if (signatureBytes.length != 64) {
    throw ArgumentError.value(
      signature,
      'signature',
      'Invalid signature length',
    );
  }

  // Decompress `a`
  final a = _pointDecompress(publicKeyBytes);
  if (a == null) {
    return false;
  }

  // Decompress `r`
  final rBytes = signatureBytes.sublist(0, 32);
  final r = _pointDecompress(rBytes);
  if (r == null) {
    return false;
  }

  // Get `s`
  final s = bigIntFromBytes(signatureBytes.sublist(32));
  if (s >= RegisterL.constantL) {
    return false;
  }

  // Calculate `h`
  final hh = await _sha512.hash(_join([rBytes, publicKeyBytes, message]));
  final h = RegisterL();
  h.readBytes(hh.bytes);

  // Calculate: s * basePoint
  final sB = _pointMul(Register25519()..setBigInt(s), Ed25519Point.base);

  // Calculate: h * a + r
  final rhA = Ed25519Point.zero();
  _pointAdd(
    rhA,
    _pointMul(h.toRegister25519(), a),
    r,
  );

  // Compare
  return sB.equals(rhA);
}