keyfork-derive-util: more docs!!!
This commit is contained in:
parent
7817c3514e
commit
0375ce7bdf
|
@ -27,7 +27,6 @@ use keyfork_mnemonic_util::Mnemonic;
|
||||||
use keyfork_derive_util::{*, request::*};
|
use keyfork_derive_util::{*, request::*};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let mnemonic = Mnemonic::from_str(
|
let mnemonic = Mnemonic::from_str(
|
||||||
"enter settle kiwi high shift absorb protect sword talent museum lazy okay"
|
"enter settle kiwi high shift absorb protect sword talent museum lazy okay"
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -1,4 +1,49 @@
|
||||||
|
//! # Extended Key Derivation
|
||||||
|
//!
|
||||||
|
//! Oftentimes, a client will want to create multiple keys. Some examples may include deriving
|
||||||
|
//! non-hardened public keys to see how many wallets have been used, deriving multiple OpenPGP
|
||||||
|
//! keys, or generally avoiding key reuse. While Keyforkd locks the root mnemonic and the
|
||||||
|
//! first-level derivation, any second-level derivations acquired from Keyforkd (for example,
|
||||||
|
//! `"m/44'/0'"`) can be used to derive further keys by converting the key to an Extended Public
|
||||||
|
//! Key or Extended Private Key and calling [`ExtendedPublicKey::derive_child`] or
|
||||||
|
//! [`ExtendedPrivateKey::derive_child`].
|
||||||
|
//!
|
||||||
|
//! # Examples
|
||||||
|
//! ```rust
|
||||||
|
//! use std::str::FromStr;
|
||||||
|
//! use keyfork_mnemonic_util::Mnemonic;
|
||||||
|
//! use keyfork_derive_util::{*, request::*};
|
||||||
|
//! use k256::SecretKey;
|
||||||
|
//!
|
||||||
|
//! # fn check_wallet<T: PublicKey>(_: ExtendedPublicKey<T>) -> Result<(), Box<dyn std::error::Error>> { Ok(()) }
|
||||||
|
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
//! # let mnemonic = Mnemonic::from_str(
|
||||||
|
//! # "enter settle kiwi high shift absorb protect sword talent museum lazy okay"
|
||||||
|
//! # )?;
|
||||||
|
//! let path = DerivationPath::from_str("m/44'/0'/0'/0")?;
|
||||||
|
//! let request = DerivationRequest::new(
|
||||||
|
//! DerivationAlgorithm::Secp256k1, // The algorithm of k256::SecretKey
|
||||||
|
//! &path,
|
||||||
|
//! );
|
||||||
|
//!
|
||||||
|
//! let response = // perform a Keyforkd Client request...
|
||||||
|
//! # request.derive_with_mnemonic(&mnemonic)?;
|
||||||
|
//! let key: ExtendedPrivateKey<SecretKey> = response.try_into()?;
|
||||||
|
//! let pubkey = key.extended_public_key();
|
||||||
|
//! drop(key);
|
||||||
|
//!
|
||||||
|
//! for account in (0..20).map(|i| DerivationIndex::new(i, false).unwrap()) {
|
||||||
|
//! let derived_key = pubkey.derive_child(&account)?;
|
||||||
|
//! check_wallet(derived_key);
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! Ok(())
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
|
||||||
///
|
///
|
||||||
pub mod private_key;
|
pub mod private_key;
|
||||||
///
|
///
|
||||||
pub mod public_key;
|
pub mod public_key;
|
||||||
|
|
||||||
|
pub use {private_key::ExtendedPrivateKey, public_key::ExtendedPublicKey};
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
///
|
|
||||||
pub mod extended_key;
|
pub mod extended_key;
|
||||||
|
|
||||||
///
|
///
|
||||||
pub mod index;
|
pub mod index;
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
// Because all algorithms make use of wildcard matching
|
// Because all algorithms make use of wildcard matching
|
||||||
#![allow(clippy::match_wildcard_for_single_variants)]
|
#![allow(clippy::match_wildcard_for_single_variants)]
|
||||||
|
|
||||||
|
//! # Derivation Requests
|
||||||
|
//!
|
||||||
|
//! Derivation requests can be sent to Keyforkd using Keyforkd Client to request derivation from a
|
||||||
|
//! mnemonic or seed that has been loaded into Keyforkd.
|
||||||
|
//!
|
||||||
|
//! # Examples
|
||||||
|
//! ```rust
|
||||||
|
//! use std::str::FromStr;
|
||||||
|
//! use keyfork_derive_util::{DerivationPath, request::{DerivationRequest, DerivationAlgorithm}};
|
||||||
|
//!
|
||||||
|
//! let path = DerivationPath::from_str("m/44'/0'/0'/0/0").unwrap();
|
||||||
|
//! let request = DerivationRequest::new(
|
||||||
|
//! DerivationAlgorithm::Secp256k1,
|
||||||
|
//! &path
|
||||||
|
//! );
|
||||||
|
//! ```
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
extended_key::private_key::Error as XPrvError,
|
extended_key::private_key::Error as XPrvError,
|
||||||
private_key::{PrivateKey, TestPrivateKey},
|
private_key::{PrivateKey, TestPrivateKey},
|
||||||
|
|
Loading…
Reference in New Issue