pub fn ckd_pub_tweak(&self, i: ChildNumber) -> Result<(PrivateKey, ChainCode), Error> {
        match i {
            ChildNumber::Hardened {..} => {
                Err(Error::CannotDeriveFromHardenedKey)
            }
            ChildNumber::Normal { index: n } => {
                let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(&self.chain_code[..]);
                hmac_engine.input(&self.public_key.key.serialize()[..]);
                let mut be_n = [0; 4];
                BigEndian::write_u32(&mut be_n, n);
                hmac_engine.input(&be_n);

                let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);

                let private_key = PrivateKey {
                    compressed: true,
                    network: self.network,
                    key: secp256k1::SecretKey::from_slice(&hmac_result[..32])?,
                };
                let chain_code = ChainCode::from(&hmac_result[32..]);
                Ok((private_key, chain_code))
            }
        }
    }
/// Compute the scalar tweak added to this key to get a child key
Compute the scalar tweak added to this key to get a child key
Compute the scalar tweak added to this key to get a child key
pub fn ckd_pub_tweak(&self, i: ChildNumber) -> Result<(PrivateKey, ChainCode), Error> {
        match i {
            ChildNumber::Hardened {..} => {
                Err(Error::CannotDeriveFromHardenedKey)
            }
            ChildNumber::Normal { index: n } => {
                let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(&self.chain_code[..]);
                hmac_engine.input(&self.public_key.key.serialize()[..]);
                let mut be_n = [0; 4];
                BigEndian::write_u32(&mut be_n, n);
                hmac_engine.input(&be_n);
                let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
                let private_key = PrivateKey {
                    compressed: true,
                    network: self.network,
                    key: secp256k1::SecretKey::from_slice(&hmac_result[..32])?,
                };
                let chain_code = ChainCode::from(&hmac_result[32..]);
                Ok((private_key, chain_code))
            }
        }
    }
pub fn ckd_pub_tweak ( & self , i : ChildNumber ) -> Result < ( PrivateKey , ChainCode ) , Error > { match i { ChildNumber :: Hardened { .. } => { Err ( Error :: CannotDeriveFromHardenedKey ) } ChildNumber :: Normal { index : n } => { let mut hmac_engine : HmacEngine < sha512 :: Hash > = HmacEngine :: new ( & self . chain_code [ .. ] ) ; hmac_engine . input ( & self . public_key . key . serialize ( ) [ .. ] ) ; let mut be_n = [ 0 ; 4 ] ; BigEndian :: write_u32 ( & mut be_n , n ) ; hmac_engine . input ( & be_n ) ; let hmac_result : Hmac < sha512 :: Hash > = Hmac :: from_engine ( hmac_engine ) ; let private_key = PrivateKey { compressed : true , network : self . network , key : secp256k1 :: SecretKey :: from_slice ( & hmac_result [ .. 32 ] ) ? , } ; let chain_code = ChainCode :: from ( & hmac_result [ 32 .. ] ) ; Ok ( ( private_key , chain_code ) ) } } }
Compute the scalar tweak added to this key to get a child key
Compute the scalar tweak added to this key to get a child key
&self
i
ChildNumber
&self
i
ChildNumber