artimonist 0.9.3

A tool for generating mnemonics based on diagrams.
Documentation
#![warn(missing_docs)]
//! # Artimonist
//!
//! `Artimonist` is a chart-based tool for creating mnemonics.
//!
//! Try the live web page: <https://www.artimonist.org>
//!
//! # Examples
//! ```
//! use artimonist::{SimpleDiagram, GenericDiagram, BIP85, Language, Password, Wif};
//!
//! let values = vec!['πŸ”', '🍟', '🌭', '🍦', '🍩'];
//! let indices = vec![(1, 1), (1, 5), (5, 5), (5, 1), (3, 3)];
//! let diagram = SimpleDiagram::from_values(&values, &indices);
//! let master = diagram.bip32_master("πŸš²πŸ€πŸŒˆ".as_bytes())?;
//!
//! let mnemonic = master.bip85_mnemonic(Language::English, 15, 0)?;
//! assert_eq!(&mnemonic, "lady announce wife please settle connect april hour caution split festival genuine logic digital dignity");
//!
//! # #[cfg(not(feature = "testnet"))]
//! assert_eq!(master.bip85_wif(0)?.pk, "L25LxS22MwRpEnnFs81XitJyrkimpZGLjgKHRAikLxJoxWMkVuHd");
//! # #[cfg(not(feature = "testnet"))]
//! assert_eq!(master.bip85_xpriv(0)?, "xprv9s21ZrQH143K47Cxw6R8QnGdAru5BaK7kT5awzC9VvmpXnpCQPdEmPyJeR9w3FeJ3hmEBRCRLGhMNpnkcM9q2w3J3T55bSSqMLRDpJLZU4B");
//! # #[cfg(not(feature = "testnet"))]
//! assert_eq!(master.bip85_pwd(Password::Emoji, 20, 0)?, "πŸ™βœ‹πŸ•πŸŒ»πŸŽ„πŸ™πŸ‘πŸ””πŸ””πŸΊπŸ’ŠπŸ„πŸΊβš‘βœ‹πŸ‘ŒπŸ˜πŸš—πŸŽπŸš—");
//!
//! # Ok::<(), artimonist::Error>(())
//! ```
//! The simple diagram looks like this:
//!
//! |  |  |  |  |  |  |  |
//! |--|--|--|--|--|--|--|  
//! |  |πŸ”|  |  |  |🍟|  |
//! |  |  |  |  |  |  |  |
//! |  |  |  |🍩|  |  |  |
//! |  |  |  |  |  |  |  |
//! |  |🍦|  |  |  |🌭|  |
//! |  |  |  |  |  |  |  |
//!

pub(crate) mod bip39;
pub(crate) mod bip49;
pub(crate) mod bip85;
pub(crate) mod bits;
pub(crate) mod complex;
pub(crate) mod generic;
pub(crate) mod macros;
pub(crate) mod matrix;
pub(crate) mod password;
pub(crate) mod simple;
pub(crate) mod words;

#[doc(no_inline)]
pub use bitcoin::{self, bip32::Xpriv};

pub use bip39::Derivation as BIP39;
pub use bip49::Derivation as BIP49;
pub use bip85::{Derivation as BIP85, Language, Password, Wif};
pub use complex::ComplexDiagram;
pub use generic::GenericDiagram;
pub use matrix::{Matrix, ToMatrix};
pub use simple::SimpleDiagram;

///
/// Global error definition
///
pub mod error {
    use thiserror::Error;

    /// Artimonist Error
    #[derive(Error, Debug)]
    pub enum Error {
        /// Invalid parameter
        #[error("invalid parameter: {0}")]
        InvalidParameter(&'static str),
        /// Bip32 Error
        #[error("bip32 error")]
        Bip32Error(#[from] bitcoin::bip32::Error),
        /// Secp error
        #[error("runtime error")]
        SecpError(#[from] bitcoin::secp256k1::Error),
        /// Hex parse error
        #[error("hex error")]
        HexError(#[from] bitcoin::hex::HexToArrayError),
        /// Address error
        #[error("address error")]
        AddressError(#[from] bitcoin::key::UncompressedPublicKeyError),
        /// serialize error
        #[error("serialize error")]
        Serialize(#[from] rmp_serde::encode::Error),
        /// deserialize eror
        #[error("deserialize error")]
        Deserialize(#[from] rmp_serde::decode::Error),
    }

    /// Artimonist Result
    pub type ArtResult<T = ()> = Result<T, Error>;
}
pub use error::Error;

/// Bitcoin network
#[cfg(not(feature = "testnet"))]
pub const NETWORK: bitcoin::NetworkKind = bitcoin::NetworkKind::Main;
/// Bitcoin network
#[cfg(feature = "testnet")]
pub const NETWORK: bitcoin::NetworkKind = bitcoin::NetworkKind::Test;