def from_parent(parent_key, i):
        """ Derives a child private key from a parent
        private key. It is not possible to derive a child
        private key from a public parent key.

        Args:
            parent_private_key (HDPrivateKey):
        """
        if not isinstance(parent_key, HDPrivateKey):
            raise TypeError("parent_key must be an HDPrivateKey object.")

        hmac_key = parent_key.chain_code
        if i & 0x80000000:
            hmac_data = b'\x00' + bytes(parent_key._key) + i.to_bytes(length=4, byteorder='big')
        else:
            hmac_data = parent_key.public_key.compressed_bytes + i.to_bytes(length=4, byteorder='big')

        I = hmac.new(hmac_key, hmac_data, hashlib.sha512).digest()
        Il, Ir = I[:32], I[32:]

        parse_Il = int.from_bytes(Il, 'big')
        if parse_Il >= bitcoin_curve.n:
            return None

        child_key = (parse_Il + parent_key._key.key) % bitcoin_curve.n

        if child_key == 0:
            # Incredibly unlucky choice
            return None

        child_depth = parent_key.depth + 1
        return HDPrivateKey(key=child_key,
                            chain_code=Ir,
                            index=i,
                            depth=child_depth,
                            parent_fingerprint=parent_key.fingerprint)
def from_parent ( parent_key , i ) : if not isinstance ( parent_key , HDPrivateKey ) : raise TypeError ( "parent_key must be an HDPrivateKey object." ) hmac_key = parent_key . chain_code if i & 0x80000000 : hmac_data = b'\x00' + bytes ( parent_key . _key ) + i . to_bytes ( length = 4 , byteorder = 'big' ) else : hmac_data = parent_key . public_key . compressed_bytes + i . to_bytes ( length = 4 , byteorder = 'big' ) I = hmac . new ( hmac_key , hmac_data , hashlib . sha512 ) . digest ( ) Il , Ir = I [ : 32 ] , I [ 32 : ] parse_Il = int . from_bytes ( Il , 'big' ) if parse_Il >= bitcoin_curve . n : return None child_key = ( parse_Il + parent_key . _key . key ) % bitcoin_curve . n if child_key == 0 : return None child_depth = parent_key . depth + 1 return HDPrivateKey ( key = child_key , chain_code = Ir , index = i , depth = child_depth , parent_fingerprint = parent_key . fingerprint )
Derives a child private key from a parent
        private key. It is not possible to derive a child
        private key from a public parent key.

        Args:
            parent_private_key (HDPrivateKey):