Make signed message prefix a public constant

This commit is contained in:
Steven Roose 2020-12-08 17:31:28 +00:00
parent 02c3d8fca5
commit 874ab8eca6
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
1 changed files with 4 additions and 4 deletions

View File

@ -24,7 +24,8 @@ use consensus::{encode, Encodable};
#[cfg(feature = "secp-recovery")] #[cfg(feature = "secp-recovery")]
pub use self::message_signing::{MessageSignature, MessageSignatureError}; pub use self::message_signing::{MessageSignature, MessageSignatureError};
static MSG_SIGN_PREFIX: &[u8] = b"\x18Bitcoin Signed Message:\n"; /// The prefix for signed messages using Bitcoin's message signing protocol.
pub const BITCOIN_SIGNED_MSG_PREFIX: &[u8] = b"\x18Bitcoin Signed Message:\n";
#[cfg(feature = "secp-recovery")] #[cfg(feature = "secp-recovery")]
mod message_signing { mod message_signing {
@ -230,14 +231,13 @@ pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
n_deleted n_deleted
} }
/// 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: &str) -> sha256d::Hash {
let mut engine = sha256d::Hash::engine(); let mut engine = sha256d::Hash::engine();
engine.input(MSG_SIGN_PREFIX); engine.input(BITCOIN_SIGNED_MSG_PREFIX);
let msg_len = encode::VarInt(msg.len() as u64); let msg_len = encode::VarInt(msg.len() as u64);
msg_len.consensus_encode(&mut engine).unwrap(); msg_len.consensus_encode(&mut engine).unwrap();
engine.input(msg.as_bytes()); engine.input(msg.as_bytes());
sha256d::Hash::from_engine(engine) sha256d::Hash::from_engine(engine)
} }