signed_msg_hash takes impl AsRef<[u8]>

This commit is contained in:
Liam Aharon 2024-09-14 00:19:05 +02:00
parent 7360c3ce9a
commit 70ccd6b629
No known key found for this signature in database
GPG Key ID: EDD5DC32959D341F
1 changed files with 4 additions and 3 deletions

View File

@ -205,12 +205,13 @@ mod message_signing {
} }
/// Hash message for signature using Bitcoin's message signing format. /// Hash message for signature using Bitcoin's message signing format.
pub fn signed_msg_hash(msg: &str) -> sha256d::Hash { pub fn signed_msg_hash(msg: impl AsRef<[u8]>) -> sha256d::Hash {
let msg_bytes = msg.as_ref();
let mut engine = sha256d::Hash::engine(); let mut engine = sha256d::Hash::engine();
engine.input(BITCOIN_SIGNED_MSG_PREFIX); engine.input(BITCOIN_SIGNED_MSG_PREFIX);
let msg_len = encode::VarInt::from(msg.len()); let msg_len = encode::VarInt::from(msg_bytes.len());
msg_len.consensus_encode(&mut engine).expect("engines don't error"); msg_len.consensus_encode(&mut engine).expect("engines don't error");
engine.input(msg.as_bytes()); engine.input(msg_bytes);
sha256d::Hash::from_engine(engine) sha256d::Hash::from_engine(engine)
} }