#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![warn(unused_extern_crates)]
pub use k256::ecdsa;
#[macro_use]
pub(crate) mod macros;
pub mod enc;
pub mod path;
pub mod primitives;
pub mod xkeys;
pub mod derived;
#[doc(hidden)]
#[cfg(any(feature = "mainnet", feature = "testnet"))]
pub mod defaults;
pub mod prelude;
use thiserror::Error;
pub const BIP32_HARDEN: u32 = 0x8000_0000;
#[doc(hidden)]
pub const CURVE_ORDER: [u8; 32] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41,
];
#[derive(Debug, Error)]
pub enum Bip32Error {
#[error("k256 error")]
BackendError( ecdsa::Error),
#[error("elliptic curve error")]
EllipticCurveError( k256::elliptic_curve::Error),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error(transparent)]
SerError(#[from] coins_core::ser::SerError),
#[error("Master key seed generation received <16 bytes")]
SeedTooShort,
#[error("HMAC left segment was 0 or greated than the curve order. How?")]
InvalidKey,
#[error("Attempted to derive the hardened child of an xpub")]
HardenedDerivationFailed,
#[error("Attempted to tweak an xpriv or xpub directly")]
BadTweak,
#[error("Version bytes 0x{0:x?} don't match any network xpriv version bytes")]
BadXPrivVersionBytes([u8; 4]),
#[error("Version bytes 0x{0:x?} don't match any network xpub version bytes")]
BadXPubVersionBytes([u8; 4]),
#[error("Expected 0 padding byte. Got {0}")]
BadPadding(u8),
#[error("Checksum mismatch on b58 deserialization")]
BadB58Checksum,
#[error(transparent)]
B58Error(#[from] bs58::decode::Error),
#[error("Malformatted index during derivation: {0}")]
MalformattedDerivation(String),
#[error("Attempted to deserialize a DER signature to a recoverable signature. Use deserialize_vrs instead")]
NoRecoveryId,
#[error("Invalid Bip32 Path.")]
InvalidBip32Path,
}
impl From<ecdsa::Error> for Bip32Error {
fn from(e: ecdsa::Error) -> Self {
Self::BackendError(e)
}
}
impl From<k256::elliptic_curve::Error> for Bip32Error {
fn from(e: k256::elliptic_curve::Error) -> Self {
Self::EllipticCurveError(e)
}
}
impl From<std::convert::Infallible> for Bip32Error {
fn from(_i: std::convert::Infallible) -> Self {
unimplemented!("unreachable, but required by type system")
}
}