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
impl BitcoinSigner
Sourcepub fn to_wif(&self) -> Zeroizing<String>
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.
Sourcepub fn to_wif_testnet(&self) -> Zeroizing<String>
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.
Sourcepub fn from_wif(wif: &str) -> Result<Self, SignerError>
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.
Sourcepub fn p2pkh_address(&self) -> String
pub fn p2pkh_address(&self) -> String
Generate a P2PKH address (1...) from the compressed public key.
Formula: Base58Check(0x00 || HASH160(compressed_pubkey))
Sourcepub fn p2wpkh_address(&self) -> Result<String, SignerError>
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))
Sourcepub fn p2pkh_testnet_address(&self) -> String
pub fn p2pkh_testnet_address(&self) -> String
Generate a testnet P2PKH address (m... or n...).
Sourcepub fn p2wpkh_testnet_address(&self) -> Result<String, SignerError>
pub fn p2wpkh_testnet_address(&self) -> Result<String, SignerError>
Generate a testnet P2WPKH address (tb1q...).
Sourcepub fn sign_message(
&self,
message: &[u8],
) -> Result<BitcoinSignature, SignerError>
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
impl KeyPair for BitcoinSigner
Source§fn generate() -> Result<Self, SignerError>
fn generate() -> Result<Self, SignerError>
Source§fn from_bytes(private_key: &[u8]) -> Result<Self, SignerError>
fn from_bytes(private_key: &[u8]) -> Result<Self, SignerError>
Source§fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
Zeroizing<Vec<u8>> will scrub the memory on drop.Source§impl Signer for BitcoinSigner
impl Signer for BitcoinSigner
Source§type Signature = BitcoinSignature
type Signature = BitcoinSignature
Source§type Error = SignerError
type Error = SignerError
Source§fn sign(&self, message: &[u8]) -> Result<BitcoinSignature, SignerError>
fn sign(&self, message: &[u8]) -> Result<BitcoinSignature, SignerError>
Source§fn sign_prehashed(&self, digest: &[u8]) -> Result<BitcoinSignature, SignerError>
fn sign_prehashed(&self, digest: &[u8]) -> Result<BitcoinSignature, SignerError>
InvalidHashLength if the digest
length doesn’t match the expected hash output size.