verifyCosmosSignature function
Verify a Cosmos/Ethermint reply signature against the SignDoc bytes.
Implementation
VerifyResult verifyCosmosSignature(VerifyCosmosSignatureArgs args) {
if (args.signature.length != 64) {
return failed('signature must be 64 bytes (compact r||s)');
}
if (args.publicKey.length != 33) {
return failed('publicKey must be 33 bytes (compressed)');
}
final expectedPublicKey = args.expectedPublicKey;
if (expectedPublicKey != null &&
!equalBytes(args.publicKey, expectedPublicKey)) {
return failed('the reply public key is not the linked account key');
}
final digest = args.digest == CosmosDigest.keccak256
? keccak256(args.signData)
: sha256(args.signData);
bool ok;
try {
ok = Secp256k1.verify(args.signature, digest, args.publicKey);
} catch (e) {
return failed('Cosmos signature could not be checked: $e');
}
return ok
? verified
: failed('the signature does not belong to this account');
}