Merge rust-bitcoin/rust-bitcoin#3357: Support `impl AsRef<[u8]>` in `signed_msg_hash`
70ccd6b629
signed_msg_hash takes impl AsRef<[u8]> (Liam Aharon) Pull request description: Closes #3249 Seems not required for Kixunil's immediate use case anymore, but figured I'd open a PR anyways. ACKs for top commit: apoelstra: ACK70ccd6b629
successfully ran local tests Kixunil: ACK70ccd6b629
Tree-SHA512: b15bafd1af0749cbac36652a4e4c9ab3f91b3980bb6c3cbc1c977d339810fc15075af5d4bc6b210de364bedc496ce3759eaf4539e40d215ab66a122ba69dd56a
This commit is contained in:
commit
85fa0ce28d
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue