verify method

Future<bool> verify(
  1. Map<String, dynamic> publicKeyJwk
)

Implementation

Future<bool> verify(Map<String, dynamic> publicKeyJwk) async {
  var crv = publicKeyJwk['crv'];
  if (crv == null) throw Exception('Jwk without crv parameter');
  bool valid = true;

  if (signatures == null || signatures!.isEmpty) {
    throw Exception('Nothing to verify');
  }

  for (var s in signatures!) {
    var encodedHeader = removePaddingFromBase64(
        base64UrlEncode(utf8.encode(jsonEncode(s.protected))));
    var encodedPayload = _base64Payload ??
        removePaddingFromBase64(
            base64UrlEncode(utf8.encode(payload.toString())));
    var encodedSignature = s.signature;
    valid = await verifyStringSignature(
        '$encodedHeader.$encodedPayload.$encodedSignature',
        jwk: publicKeyJwk);
    if (!valid) {
      throw Exception('A Signature is wrong');
    }
  }
  return valid;
}