def derivation(self, chain_code: bytes,
                child_index: int) -> Tuple["Secp256k1Deriv", bytes]:
     if child_index < 0 or child_index >= 2**31:
         raise Exception("invalid child index")
     I = utils.hmac512(chain_code,
                       self.get_public_bytes() + utils.tb(child_index, 4))
     return (self.__class__(self.derive(Secp256k1Priv(I[0:32]))), I[32:])
 def hardened_derivation(self, chain_code: bytes,
                         child_index: int) -> Tuple["ED25519Priv", bytes]:
     if child_index < 0 or child_index >= 2**31:
         raise Exception("invalid hardened child index")
     I = utils.hmac512(
         chain_code, b"\x00" + self.get_private_bytes() +
         utils.tb(child_index + 0x80000000, 4))
     return (ED25519Priv(I[0:32]), I[32:])
 def _to_bytes(self) -> bytes:
     ret = utils.tb(self.version.value, 4)
     ret += utils.tb(self.depth, 1)
     ret += self.parent_fp
     cn = self.child_number
     if self.hardened:
         cn += 0x80000000
     ret += utils.tb(cn, 4)
     ret += self.chain_code
     if self.version == Version.PUBLIC:
         if isinstance(self.key, ED25519Pub):
             # non standard, invented by this project :(
             ret += b"\xff" + self.key.get_public_bytes()
         else:
             ret += self.key.get_public_bytes()
     elif self.version == Version.PRIVATE:
         if isinstance(self.key, ED25519Priv):
             # non standard, invented by this project :(
             ret += b"\xff" + self.key.get_private_bytes()
         else:
             ret += b"\x00" + self.key.get_private_bytes()
     else:
         raise Exception("Incorrect version while dumping an XKey")
     return ret