Skip to main content

BitcoinSigner

Struct BitcoinSigner 

Source
pub struct BitcoinSigner { /* private fields */ }
Expand description

Bitcoin ECDSA signer.

Uses secp256k1 with double-SHA-256 hashing and RFC 6979 deterministic nonces. Produces strict DER-encoded signatures.

Implementations§

Source§

impl BitcoinSigner

Source

pub fn to_wif(&self) -> Zeroizing<String>

Export the private key in WIF (Wallet Import Format).

Uses version byte 0x80 (mainnet) with compression flag. Result starts with K or L.

§Security

The returned String contains the private key — handle with care.

Source

pub fn to_wif_testnet(&self) -> Zeroizing<String>

Export the private key in testnet WIF format.

Uses version byte 0xEF (testnet). Result starts with c.

§Security

The returned String contains the private key — handle with care.

Source

pub fn from_wif(wif: &str) -> Result<Self, SignerError>

Import a private key from WIF (Wallet Import Format).

Accepts mainnet (5/K/L) and testnet (9/c) WIF strings.

Source

pub fn p2pkh_address(&self) -> String

Generate a P2PKH address (1...) from the compressed public key.

Formula: Base58Check(0x00 || HASH160(compressed_pubkey))

Source

pub fn p2wpkh_address(&self) -> Result<String, SignerError>

Generate a P2WPKH (SegWit) address (bc1...) from the compressed public key.

Formula: Bech32(“bc”, 0, HASH160(compressed_pubkey))

Source

pub fn p2pkh_testnet_address(&self) -> String

Generate a testnet P2PKH address (m... or n...).

Source

pub fn p2wpkh_testnet_address(&self) -> Result<String, SignerError>

Generate a testnet P2WPKH address (tb1q...).

Source

pub fn sign_message( &self, message: &[u8], ) -> Result<BitcoinSignature, SignerError>

BIP-137: Sign a message with the Bitcoin Signed Message prefix.

Computes double_sha256("\x18Bitcoin Signed Message:\n" || varint(len) || message) and signs the resulting 32-byte digest.

Trait Implementations§

Source§

impl KeyPair for BitcoinSigner

Source§

fn generate() -> Result<Self, SignerError>

Generate a new random key pair using OS entropy (CSPRNG).
Source§

fn from_bytes(private_key: &[u8]) -> Result<Self, SignerError>

Reconstruct a key pair from raw private key bytes (32 bytes).
Source§

fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>

Export the private key as auto-zeroizing bytes. The returned Zeroizing<Vec<u8>> will scrub the memory on drop.
Source§

fn from_keypair_bytes(keypair: &[u8]) -> Result<Self, <Self as Signer>::Error>
where Self: Sized,

Reconstruct a key pair from a 64-byte expanded keypair (seed ∥ pubkey). Default impl uses only the first 32 bytes (seed).
Source§

fn keypair_bytes(&self) -> Zeroizing<Vec<u8>>

Export the full keypair as private_key ∥ public_key. Default: 32B seed + compressed pubkey.
Source§

impl Signer for BitcoinSigner

Source§

type Signature = BitcoinSignature

The signature type produced by this signer.
Source§

type Error = SignerError

The error type returned on failure.
Source§

fn sign(&self, message: &[u8]) -> Result<BitcoinSignature, SignerError>

Sign a raw message. The implementation applies chain-specific hashing internally (e.g., Keccak-256 for Ethereum, double-SHA-256 for Bitcoin).
Source§

fn sign_prehashed(&self, digest: &[u8]) -> Result<BitcoinSignature, SignerError>

Sign a pre-hashed digest directly. The caller is responsible for applying the correct hash function. Returns InvalidHashLength if the digest length doesn’t match the expected hash output size.
Source§

fn public_key_bytes(&self) -> Vec<u8>

Return the public key as bytes (compressed format where applicable). Read more
Source§

fn public_key_bytes_uncompressed(&self) -> Vec<u8>

Return the public key in uncompressed format. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.