-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] how to verify a metamask signed message? #564
Comments
You shouldn't be hashing the signature. Also you should first hex-decode the signature instead of using the string. The signature is expected to be 65 bytes ( Please take a look at https://docs.rs/ethsign/0.8.0/ethsign/struct.Signature.html as well. |
Thank you for the hints. use web3::signing::{keccak256, recover};
pub fn eth_message(message: String) -> [u8; 32] {
keccak256(
format!(
"{}{}{}",
"\x19Ethereum Signed Message:\n",
message.len(),
message
)
.as_bytes(),
)
}
#[test]
fn test_recover() {
let account = "0x63f9a92d8d61b48a9fff8d58080425a3012d05c8".to_string();
let message = "0x63f9a92d8d61b48a9fff8d58080425a3012d05c8igwyk4r1o7o".to_string();
let message = eth_message(message);
let signature = hex::decode("382a3e04daf88f322730f6a2972475fc5646ea8c4a7f3b5e83a90b10ba08a7364cd2f55348f2b6d210fbed7fc485abf19ecb2f3967e410d6349dd7dd1d4487751b").unwrap();
println!("{} {:?} {:?}", account, message, signature);
let pubkey = recover(&message, &signature[..64], 0);
assert!(pubkey.is_ok());
let pubkey = pubkey.unwrap();
let pubkey = format!("{:02X?}", pubkey);
assert_eq!(account, pubkey)
} A very important part is the salted message which is signed by metamask. Thanks, |
The |
For anyone who have this issue, as for Ethereum the v value is [27|28], to calculate the actual
|
This did the trick, this is the whole code for anyone needing it:
|
Hi I fail verifying a signed message.
When signing a message with metamask we get something like:
This can be validated here: https://app.mycrypto.com/sign-message
Now I try to validate this signature in a rust written backend, with no luck.
Here is the simplified test code:
Before I tried hashing the message, I got InvalidMessage.
Two questions come into my mind:
(1) Now I get InvalidSignature, so I think I make something wrong converting the signature.
(2) Where do I get the recover_id from?
Kind regards,
Christian
The text was updated successfully, but these errors were encountered: