Returns a Result
to let the caller choose an error handling strategy.
Follows the Secp256r1 elliptical curve.
signature
: [B512] - The signature generated by signing a message hash.msg_hash
: [b256] - The signed data.use std::{ecr::ec_recover_r1, b512::B512};
fn foo() {
let hi = 0xbd0c9b8792876712afadbff382e1bf31c44437823ed761cc3600d0016de511ac;
let lo = 0x44ac566bd156b4fc71a4a4cb2655d3da360c695edb27dc3b64d621e122fea23d;
let msg_hash = 0x1e45523606c96c98ba970ff7cf9511fab8b25e1bcd52ced30b81df1e4a9c4323;
let pub_hi = 0xD73A188181464CC84AE267E45041AEF6AB938F278E636AA1D02D3014C1BEF74E;
let pub_lo = 0x62660ecce5979493fe5684526e8e00875b948e507a89a47096bc84064a175452;
let signature: B512 = B512::from((hi, lo));
// A recovered public key pair.
let public_key = ec_recover_r1(signature, msg_hash).unwrap();
assert(public_key.bits()[0] == pub_hi);
assert(public_key.bits()[1] == pub_lo);
}