verify method
Verifies a (detached) JWS
Implementation
@override
FutureOr<bool> verify(String jws,
{String? did, Map<String, dynamic>? jwk, dynamic data}) async {
Map<String, dynamic> signingKey;
if (did != null) {
var ddo =
(await resolveDidDocument(did)).resolveKeyIds().convertAllKeysToJwk();
signingKey = ddo.verificationMethod!.first.publicKeyJwk!;
} else if (jwk != null) {
signingKey = jwk;
} else {
throw Exception('Either did or jwk must be given');
}
var splitted = jws.split('.');
if (splitted.length != 3) throw Exception('maleformed jws');
String encodedPayload;
if (data != null) {
encodedPayload = data is String
? removePaddingFromBase64(base64UrlEncode(utf8.encode(data)))
: removePaddingFromBase64(
base64UrlEncode(utf8.encode(jsonEncode(credentialToMap(data)))));
} else {
encodedPayload = splitted[1];
}
var signingInput = '${splitted[0]}.$encodedPayload';
var pubKey = EcPublicKey(
xCoordinate: web3_crypto.bytesToUnsignedInt(
base64Decode(addPaddingToBase64(signingKey['x']))),
yCoordinate: web3_crypto.bytesToUnsignedInt(
base64Decode(addPaddingToBase64(signingKey['y']))),
curve: curves.p256);
var verifier = pubKey.createVerifier(algorithms.signing.ecdsa.sha256);
return verifier.verify(ascii.encode(signingInput),
Signature(base64Decode(addPaddingToBase64(splitted[2]))));
}