Skip to content

Commit

Permalink
Adds example docs and tests for Keypair::derive_secret_key
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpArtos committed Aug 11, 2024
1 parent a21bade commit f1db728
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ impl Keypair {
///
/// We expect the trait methods of `Keypair as Derivation` to be
/// more useful since signing anything requires the public key too.
///
/// # Example:
///
/// ```
/// use schnorrkel::{Keypair,derive::{CHAIN_CODE_LENGTH, ChainCode}};
/// # use crate::schnorrkel::derive::Derivation;
///
/// let t = merlin::Transcript::new(b"SchnorrRistrettoHDKD");
/// let chaincode = ChainCode([0u8; CHAIN_CODE_LENGTH]); // This is an example. In practice, we should use a random value.
/// let keypair: Keypair = Keypair::generate();
/// # let t1 = t.clone();
/// let (secret_key, chaincode1) = keypair.derive_secret_key(t, chaincode);
/// # let derived_keypair = keypair.derived_key(t1, chaincode).0;
/// # assert_eq!(chaincode.0.len(), chaincode1.0.len());
/// # assert_eq!(secret_key, derived_keypair.secret);
/// ```
pub fn derive_secret_key<T>(&self, mut t: T, cc: ChainCode) -> (SecretKey, ChainCode)
where
T: SigningTranscript,
Expand Down

0 comments on commit f1db728

Please sign in to comment.