keyfork-derive-util: cleanup types

This commit is contained in:
Ryan Heywood 2023-08-31 23:57:05 -05:00
parent 96e6c236f0
commit 1006fd9503
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
8 changed files with 12 additions and 27 deletions

View File

@ -1,15 +0,0 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Index is too large, must be less than 0x80000000: {0}")]
IndexTooLarge(u32),
#[error("Unable to parse integer for index")]
IntParseError(#[from] std::num::ParseIntError),
#[error("Unable to parse path due to bad path prefix")]
UnknownPathPrefix,
}
pub type Result<T, E = Error> = std::result::Result<T, E>;

View File

@ -27,8 +27,8 @@ pub enum Error {
Derivation, Derivation,
} }
pub type Result<T, E = Error> = std::result::Result<T, E>; type Result<T, E = Error> = std::result::Result<T, E>;
pub type ChainCode = [u8; 32]; type ChainCode = [u8; 32];
type HmacSha512 = Hmac<Sha512>; type HmacSha512 = Hmac<Sha512>;
/// Extended private keys derived using BIP-0032. /// Extended private keys derived using BIP-0032.
@ -56,7 +56,7 @@ impl<K> ExtendedPrivateKey<K>
where where
K: PrivateKey + Clone, K: PrivateKey + Clone,
{ {
/// Generate a new [`ExtendedPublicKey`] from a seed, ideally from a 12-word or 24-word /// Generate a new [`ExtendedPrivateKey`] from a seed, ideally from a 12-word or 24-word
/// mnemonic, but may take 16-byte seeds. /// mnemonic, but may take 16-byte seeds.
/// ///
/// # Panics /// # Panics

View File

@ -26,8 +26,8 @@ pub enum Error {
Derivation, Derivation,
} }
pub type Result<T, E = Error> = std::result::Result<T, E>; type Result<T, E = Error> = std::result::Result<T, E>;
pub type ChainCode = [u8; 32]; type ChainCode = [u8; 32];
type HmacSha512 = Hmac<Sha512>; type HmacSha512 = Hmac<Sha512>;
/// Extended public keys derived using BIP-0032. /// Extended public keys derived using BIP-0032.

View File

@ -1,17 +1,19 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
/// Errors associated with creating a [`DerivableIndex`]. /// Errors associated with creating a [`DerivationIndex`].
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
/// The index was too large and should be less than 2^31.
#[error("Index is too large, must be less than 0x80000000: {0}")] #[error("Index is too large, must be less than 0x80000000: {0}")]
IndexTooLarge(u32), IndexTooLarge(u32),
/// An integer could not be parsed from the string.
#[error("Unable to parse integer for index")] #[error("Unable to parse integer for index")]
IntParseError(#[from] std::num::ParseIntError), IntParseError(#[from] std::num::ParseIntError),
} }
pub type Result<T, E = Error> = std::result::Result<T, E>; type Result<T, E = Error> = std::result::Result<T, E>;
/// Index for a given extended private key. /// Index for a given extended private key.
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]

View File

@ -2,7 +2,6 @@
//! BIP-0032 derivation utilities. //! BIP-0032 derivation utilities.
pub mod error;
pub mod extended_key; pub mod extended_key;
pub mod index; pub mod index;
pub mod path; pub mod path;
@ -13,7 +12,6 @@ pub mod public_key;
mod tests; mod tests;
pub use crate::{ pub use crate::{
error::{Error, Result},
extended_key::{private_key::ExtendedPrivateKey, public_key::ExtendedPublicKey}, extended_key::{private_key::ExtendedPrivateKey, public_key::ExtendedPublicKey},
index::DerivationIndex, index::DerivationIndex,
path::DerivationPath, path::DerivationPath,

View File

@ -19,7 +19,7 @@ pub enum Error {
UnknownPathPrefix, UnknownPathPrefix,
} }
pub type Result<T, E = Error> = std::result::Result<T, E>; type Result<T, E = Error> = std::result::Result<T, E>;
const PREFIX: &str = "m"; const PREFIX: &str = "m";

View File

@ -2,7 +2,7 @@ use crate::PublicKey;
use thiserror::Error; use thiserror::Error;
pub type PrivateKeyBytes = [u8; 32]; pub(crate) type PrivateKeyBytes = [u8; 32];
/// Functions required to use an `ExtendedPrivateKey`. /// Functions required to use an `ExtendedPrivateKey`.
pub trait PrivateKey: Sized { pub trait PrivateKey: Sized {

View File

@ -5,7 +5,7 @@ use ripemd::Ripemd160;
use sha2::Sha256; use sha2::Sha256;
use thiserror::Error; use thiserror::Error;
pub type PublicKeyBytes = [u8; 33]; pub(crate) type PublicKeyBytes = [u8; 33];
/// Functions required to use an `ExtendedPublicKey`. /// Functions required to use an `ExtendedPublicKey`.
pub trait PublicKey: Sized { pub trait PublicKey: Sized {