Skip to content

Commit

Permalink
signed_msg_hash takes impl AsRef<[u8]>
Browse files Browse the repository at this point in the history
  • Loading branch information
liamaharon committed Sep 13, 2024
1 parent 7360c3c commit 70ccd6b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bitcoin/src/sign_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ mod message_signing {
}

/// 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();
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");
engine.input(msg.as_bytes());
engine.input(msg_bytes);
sha256d::Hash::from_engine(engine)
}

Expand Down

0 comments on commit 70ccd6b

Please sign in to comment.