[docs]@staticmethoddefget_root_key_from_seed(seed:bytes):""" Derive the HD root/master key from a seed entropy in bytes format. :param seed: The seed entropy in bytes format. :return: The root/master key. """returnBIP32Key.fromEntropy(seed)
[docs]defget_private_key_from_seed(self,seed:bytes,path=BIP_44_PATHS.CONSTELLATION_PATH.value):""" Derive the private key from a seed entropy using derived path. :param seed: The seed in bytes format. :param path: The derivation path. :return: The private key as a hexadecimal string. """INDEX=0path=parse_path(path)root_key=self.get_root_key_from_seed(seed=seed)return(root_key.ChildKey(path["purpose"]).ChildKey(path["coin_type"]).ChildKey(path["account"]).ChildKey(path["change"]).ChildKey(INDEX).PrivateKey())
[docs]@staticmethoddefget_public_key_from_private_hex(private_key:bytes)->str:""" Derive the public key from a private key using secp256k1. :param private_key: The private key in hexadecimal format. :return: The uncompressed public key as a hexadecimal string with 04 prefix. """# Convert hex private key to cryptography objectprivate_key_int=int.from_bytes(private_key,byteorder="big")private_key=ec.derive_private_key(private_key_int,ec.SECP256K1(),default_backend())public_key=private_key.public_key()public_bytes=public_key.public_bytes(encoding=serialization.Encoding.X962,format=serialization.PublicFormat.UncompressedPoint,)returnpublic_bytes.hex()# has 04 prefix