pub fn ed_verify(
public_key: b256,
signature: B512,
msg_hash: b256,
) -> Result<bool, EcRecoverError>
Expand description
Verifies that a public key derived from the private key was used to sign a message.
Returns a Result
to let the caller choose an error handling strategy.
Additional Information
Follows the edDSA curve25519 verification.
Arguments
public_key
: [b256] - The public key that signed the message.signature
: [B512] - The signature generated by signing a message hash.msg_hash
: [b256] - The hashed signed data.
Returns
- [Result<bool, EcRecoverError>] - A verified result or an error.
Examples
use std::{ecr::ed_verify, b512::B512, constants::ZERO_B256};
fn foo() {
let pub_key = 0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10;
let msg = ZERO_B256;
let msg_hash = sha256(msg);
let hi = 0xf38cef9361894be6c6e0eddec28a663d099d7ddff17c8077a1447d7ecb4e6545;
let lo = 0xf5084560039486d3462dd65a40c80a74709b2f06d450ffc5dc00345c6b2cdd00;
let signature: B512 = B512::from((hi, lo));
// A verified public key with signature
let verified = ed_verify(pub_key, signature, msg_hash).unwrap();
assert(verified);
}