verifySignature method
Verifies the signature of this authorization.
Implementation
bool verifySignature(String expectedSigner) {
if (!isSigned) return false;
try {
final messageHash = getMessageHash();
// Reconstruct signature
final rBytes = BytesUtils.bigIntToBytes(r, length: 32);
final sBytes = BytesUtils.bigIntToBytes(s, length: 32);
final signature = BytesUtils.concat([rBytes, sBytes]);
// Recover public key using the yParity as recovery parameter
final recoveredPublicKey =
Secp256k1.recover(signature, messageHash, yParity);
// Derive address from public key
final recoveredAddress =
EthereumAddress.fromPublicKey(recoveredPublicKey, Keccak256.hash);
return recoveredAddress.toString().toLowerCase() ==
expectedSigner.toLowerCase();
} on Exception catch (_) {
return false;
}
}