def convert(self, value, param, ctx): if self.validate: try: _key = UmbralPublicKey.from_hex(value) except (InternalError, ValueError): self.fail(f"'{value}' is not a valid nucypher public key.") return value
def test_public_key_as_hex(random_ec_curvebn1): pubkey = UmbralPrivateKey(random_ec_curvebn1, default_params()).get_pubkey() hex_string = pubkey.hex() assert set(hex_string).issubset(set(string.hexdigits)) assert len(hex_string) == 2 * UmbralPublicKey.expected_bytes_length() decoded_pubkey = UmbralPublicKey.from_hex(hex_string) assert pubkey == decoded_pubkey hex_string = pubkey.hex(is_compressed=False) assert set(hex_string).issubset(set(string.hexdigits)) assert len(hex_string) == 2 * UmbralPublicKey.expected_bytes_length(is_compressed=False) decoded_pubkey = UmbralPublicKey.from_hex(hex_string) assert pubkey == decoded_pubkey
learn_on_same_thread=True, ) alice_config.initialize(password=passphrase) alice_config.keyring.unlock(password=passphrase) alicia = alice_config.produce() # We will save Alicia’s config to a file for later use alice_config_file = alice_config.to_configuration_file() # Let’s get to learn about the NuCypher network alicia.start_learning_loop(now=True) enc_privkey = UmbralPrivateKey.gen_key() sig_privkey = UmbralPrivateKey.gen_key() print(enc_privkey.to_bytes().hex()) print(enc_privkey.get_pubkey().to_bytes().hex()) verifying_key = UmbralPublicKey.from_hex(enc_privkey.get_pubkey().to_bytes().hex()), encrypting_key = UmbralPublicKey.from_hex(sig_privkey.get_pubkey().to_bytes().hex()) label = "QmVahkTzLmU88CayjyZrRvqX78BmjjqH4iW26tNPvYQ18M" label = label.encode() policy_pubkey = alicia.get_policy_encrypting_key_from_label(label) print("The policy public key for " "label '{}' is {}".format(label.decode("utf-8"), policy_pubkey.to_bytes().hex())) SUBSCRIBER_PUBLIC_JSON = 'subscriber.public.json' SUBSCRIBER_PRIVATE_JSON = 'subscriber.private.json' enc_privkey = UmbralPrivateKey.gen_key() sig_privkey = UmbralPrivateKey.gen_key()