Skip to main content

StandardWallet

Struct StandardWallet 

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

A standard Bitcoin wallet with a single private key.

This wallet type generates a random private key directly, without using a mnemonic or HD derivation.

§Example

use kobe_btc::{StandardWallet, Network, AddressType};

let wallet = StandardWallet::generate(Network::Mainnet, AddressType::P2wpkh).unwrap();
println!("Address: {}", wallet.address_string());
println!("Private Key (WIF): {}", wallet.private_key_wif().as_str());

Implementations§

Source§

impl StandardWallet

Source

pub fn from_wif(wif: &str, address_type: AddressType) -> Result<Self, Error>

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

§Errors

Returns an error if the WIF is invalid.

§Panics

This function will not panic under normal circumstances. The internal expect is guaranteed to succeed for valid private keys.

Source

pub fn from_hex( hex_str: &str, network: Network, address_type: AddressType, ) -> Result<Self, Error>

Import a wallet from a hex-encoded secret key.

§Errors

Returns an error if the hex is invalid.

§Panics

This function will not panic under normal circumstances. The internal expect is guaranteed to succeed for valid private keys.

Source

pub fn secret_bytes(&self) -> Zeroizing<[u8; 32]>

Get the secret key as raw bytes (zeroized on drop).

Source

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

Get the secret key in hex format (zeroized on drop).

Source

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

Get the secret key in WIF format (zeroized on drop).

Source

pub fn pubkey_hex(&self) -> String

Get the public key in compressed hex format.

Source

pub fn address(&self) -> String

Get the Bitcoin address as a string.

Source

pub const fn network(&self) -> Network

Get the network.

Source

pub const fn address_type(&self) -> AddressType

Get the address type.

Trait Implementations§

Source§

impl Debug for StandardWallet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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.