Skip to main content

BSM

Struct BSM 

Source
pub struct BSM;
Expand description

Bitcoin Signed Messages (BSM) – legacy message signing and verification.

BSM uses a magic prefix to prevent cross-protocol signature attacks. Messages are double-SHA256 hashed with the prefix before signing.

Implementations§

Source§

impl BSM

Source

pub fn magic_hash(message: &[u8]) -> [u8; 32]

Compute the BSM magic hash of a message.

Constructs the prefixed buffer: VarInt(25) || “Bitcoin Signed Message:\n” || VarInt(message.len()) || message

Then returns hash256 (double SHA-256) of the buffer.

Source

pub fn sign( message: &[u8], private_key: &PrivateKey, ) -> Result<Vec<u8>, CompatError>

Sign a message using BSM.

Returns a 65-byte compact BSM signature (recovery byte + 32-byte r + 32-byte s). The magic hash is computed, then ECDSA signing is performed with the hash256 output. Recovery factor is calculated and encoded in the first byte.

Source

pub fn verify( message: &[u8], sig_bytes: &[u8], pub_key: &PublicKey, ) -> Result<bool, CompatError>

Verify a BSM signed message.

The signature must be in 65-byte compact BSM format. Verifies the signature against the provided public key.

Auto Trait Implementations§

§

impl Freeze for BSM

§

impl RefUnwindSafe for BSM

§

impl Send for BSM

§

impl Sync for BSM

§

impl Unpin for BSM

§

impl UnsafeUnpin for BSM

§

impl UnwindSafe for BSM

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.