pub fn ckd_priv<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>, i: ChildNumber) -> Result<ExtendedPrivKey, Error> {
        let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(&self.chain_code[..]);
        let mut be_n = [0; 4];
        match i {
            ChildNumber::Normal {..} => {
                // Non-hardened key: compute public data and use that
                hmac_engine.input(&PublicKey::from_private_key(secp, &self.private_key).key.serialize()[..]);
            }
            ChildNumber::Hardened {..} => {
                // Hardened key: use only secret data to prevent public derivation
                hmac_engine.input(&[0u8]);
                hmac_engine.input(&self.private_key[..]);
            }
        }
        BigEndian::write_u32(&mut be_n, u32::from(i));

        hmac_engine.input(&be_n);
        let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
        let mut sk = PrivateKey {
            compressed: true,
            network: self.network,
            key: secp256k1::SecretKey::from_slice(&hmac_result[..32]).map_err(Error::Ecdsa)?,
        };
        sk.key.add_assign(&self.private_key[..]).map_err(Error::Ecdsa)?;

        Ok(ExtendedPrivKey {
            network: self.network,
            depth: self.depth + 1,
            parent_fingerprint: self.fingerprint(secp),
            child_number: i,
            private_key: sk,
            chain_code: ChainCode::from(&hmac_result[32..])
        })
    }
/// Private->Private child key derivation
Private->Private child key derivation
Private - > Private child key derivation
pub fn ckd_priv<C: secp256k1::Signing>(&self, secp: &Secp256k1<C>, i: ChildNumber) -> Result<ExtendedPrivKey, Error> {
        let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(&self.chain_code[..]);
        let mut be_n = [0; 4];
        match i {
            ChildNumber::Normal {..} => {
                // Non-hardened key: compute public data and use that
                hmac_engine.input(&PublicKey::from_private_key(secp, &self.private_key).key.serialize()[..]);
            }
            ChildNumber::Hardened {..} => {
                // Hardened key: use only secret data to prevent public derivation
                hmac_engine.input(&[0u8]);
                hmac_engine.input(&self.private_key[..]);
            }
        }
        BigEndian::write_u32(&mut be_n, u32::from(i));
        hmac_engine.input(&be_n);
        let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
        let mut sk = PrivateKey {
            compressed: true,
            network: self.network,
            key: secp256k1::SecretKey::from_slice(&hmac_result[..32]).map_err(Error::Ecdsa)?,
        };
        sk.key.add_assign(&self.private_key[..]).map_err(Error::Ecdsa)?;
        Ok(ExtendedPrivKey {
            network: self.network,
            depth: self.depth + 1,
            parent_fingerprint: self.fingerprint(secp),
            child_number: i,
            private_key: sk,
            chain_code: ChainCode::from(&hmac_result[32..])
        })
    }
pub fn ckd_priv < C : secp256k1 :: Signing > ( & self , secp : & Secp256k1 < C > , i : ChildNumber ) -> Result < ExtendedPrivKey , Error > { let mut hmac_engine : HmacEngine < sha512 :: Hash > = HmacEngine :: new ( & self . chain_code [ .. ] ) ; let mut be_n = [ 0 ; 4 ] ; match i { ChildNumber :: Normal { .. } => { // Non-hardened key: compute public data and use that hmac_engine . input ( & PublicKey :: from_private_key ( secp , & self . private_key ) . key . serialize ( ) [ .. ] ) ; } ChildNumber :: Hardened { .. } => { // Hardened key: use only secret data to prevent public derivation hmac_engine . input ( & [ 0u8 ] ) ; hmac_engine . input ( & self . private_key [ .. ] ) ; } } BigEndian :: write_u32 ( & mut be_n , u32 :: from ( i ) ) ; hmac_engine . input ( & be_n ) ; let hmac_result : Hmac < sha512 :: Hash > = Hmac :: from_engine ( hmac_engine ) ; let mut sk = PrivateKey { compressed : true , network : self . network , key : secp256k1 :: SecretKey :: from_slice ( & hmac_result [ .. 32 ] ) . map_err ( Error :: Ecdsa ) ? , } ; sk . key . add_assign ( & self . private_key [ .. ] ) . map_err ( Error :: Ecdsa ) ? ; Ok ( ExtendedPrivKey { network : self . network , depth : self . depth + 1 , parent_fingerprint : self . fingerprint ( secp ) , child_number : i , private_key : sk , chain_code : ChainCode :: from ( & hmac_result [ 32 .. ] ) } ) }
Private->Private child key derivation
Private - > Private child key derivation
&self
secp
&Secp256k1<C>
i
ChildNumber
&self
secp
&Secp256k1<C>
i
ChildNumber