1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
//! # Usage
//! The main interface for the crate is provided by the [`Address`] and [`WIF`] traits . These
//! traits provide methods for generating addresses and WIFs (serialized private keys)
//! respectively.

use std::fmt;

type Result<T> = std::result::Result<T, Error>;
pub type PubkeyBytes = [u8; 33];
pub type PrvkeyBytes = [u8; 32];

mod address;
pub use address::{AddressFormat, BitcoinFormat, Address};
mod wif;
pub use wif::{WIFFormat, WIF};


#[derive(Debug, PartialEq, Eq)]
/// Error enum describing something that went wrong.
pub enum Error {
    InvalidLength { received: usize, expected: usize },
    ParseFailure(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidLength { received, expected } => write!(
                f,
                "Invalid length detected, expected {}, got {}",
                received, expected
            ),
            Self::ParseFailure(msg) => write!(f, "{}", msg),
        }
    }
}

impl std::error::Error for Error {}

#[cfg(test)]
mod test_vectors;