Skip to content

Commit

Permalink
Merge rust-bitcoin#3357: Support impl AsRef<[u8]> in signed_msg_hash
Browse files Browse the repository at this point in the history
70ccd6b signed_msg_hash takes impl AsRef<[u8]> (Liam Aharon)

Pull request description:

  Closes rust-bitcoin#3249

  Seems not required for Kixunil's immediate use case anymore, but figured I'd open a PR anyways.

ACKs for top commit:
  apoelstra:
    ACK 70ccd6b successfully ran local tests
  Kixunil:
    ACK 70ccd6b

Tree-SHA512: b15bafd1af0749cbac36652a4e4c9ab3f91b3980bb6c3cbc1c977d339810fc15075af5d4bc6b210de364bedc496ce3759eaf4539e40d215ab66a122ba69dd56a
  • Loading branch information
apoelstra committed Sep 15, 2024
2 parents fe2985b + 70ccd6b commit 85fa0ce
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 85fa0ce

Please sign in to comment.