crypto_addr/
lib.rs

1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2#![doc = include_str!("../README.md")]
3//! # Usage
4//! The main interface for the crate is provided by the [`Address`] and [`WIF`] traits . These
5//! traits provide methods for generating addresses and WIFs (serialized private keys)
6//! respectively.
7
8use std::fmt;
9
10type Result<T> = std::result::Result<T, Error>;
11pub type PubkeyBytes = [u8; 33];
12pub type PrvkeyBytes = [u8; 32];
13
14mod address;
15pub use address::{AddressFormat, BitcoinFormat, Address};
16mod wif;
17pub use wif::{WIFFormat, WIF};
18
19
20#[derive(Debug, PartialEq, Eq)]
21/// Error enum describing something that went wrong.
22pub enum Error {
23    InvalidLength { received: usize, expected: usize },
24    ParseFailure(String),
25}
26
27impl fmt::Display for Error {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            Self::InvalidLength { received, expected } => write!(
31                f,
32                "Invalid length detected, expected {}, got {}",
33                received, expected
34            ),
35            Self::ParseFailure(msg) => write!(f, "{}", msg),
36        }
37    }
38}
39
40impl std::error::Error for Error {}
41
42#[cfg(test)]
43mod test_vectors;