From 1c6d2998375dc14eb141260bafe77c53a4917cb7 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Sat, 10 Jun 2023 16:31:11 +0200 Subject: [PATCH] updates simple tdec example for use with alpha 5 --- examples/tdec/simple_tdec.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/tdec/simple_tdec.py b/examples/tdec/simple_tdec.py index bc1bdf6d8..358a4f192 100644 --- a/examples/tdec/simple_tdec.py +++ b/examples/tdec/simple_tdec.py @@ -5,7 +5,10 @@ from nucypher_core.ferveo import DkgPublicKey import nucypher from nucypher.blockchain.eth.agents import CoordinatorAgent -from nucypher.blockchain.eth.registry import LocalContractRegistry +from nucypher.blockchain.eth.registry import ( + InMemoryContractRegistry, + LocalContractRegistry, +) from nucypher.characters.lawful import Bob, Enrico, Ursula from nucypher.policy.conditions.lingo import ConditionLingo from nucypher.utilities.logging import GlobalLoggerSettings @@ -18,11 +21,11 @@ LOG_LEVEL = 'info' GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL) GlobalLoggerSettings.start_console_logging() -provider_uri = os.environ['DEMO_L1_PROVIDER_URI'] -network = 'lynx' -here = Path(nucypher.__file__).parent -path = here / 'blockchain/eth/contract_registry/lynx/contract_registry.json' -registry = LocalContractRegistry(filepath=path) +staking_provider_uri = os.environ["DEMO_L1_PROVIDER_URI"] +network = "lynx" + +coordinator_provider_uri = os.environ["DEMO_L2_PROVIDER_URI"] +coordinator_network = "mumbai" ############### # Enrico @@ -30,10 +33,15 @@ registry = LocalContractRegistry(filepath=path) print('--------- Threshold Encryption ---------') -coordinator_agent = CoordinatorAgent(eth_provider_uri=provider_uri, registry=registry) -ritual_id = 0 # got this from a side channel +coordinator_agent = CoordinatorAgent( + eth_provider_uri=coordinator_provider_uri, + registry=InMemoryContractRegistry.from_latest_publication( + network=coordinator_network + ), +) +ritual_id = 3 # got this from a side channel ritual = coordinator_agent.get_ritual(ritual_id) -enrico = Enrico(encrypting_key=DkgPublicKey.from_bytes(ritual.public_key)) +enrico = Enrico(encrypting_key=DkgPublicKey.from_bytes(bytes(ritual.public_key))) print(f'Fetched DKG public key {bytes(enrico.policy_pubkey).hex()} ' f'for ritual #{ritual_id} ' @@ -60,10 +68,11 @@ print(f'Encrypted message: {bytes(ciphertext).hex()}') print('--------- Threshold Decryption ---------') bob = Bob( - eth_provider_uri=provider_uri, + eth_provider_uri=staking_provider_uri, domain=network, - registry=registry, - known_nodes=[Ursula.from_teacher_uri('https://lynx.nucypher.network:9151', min_stake=0)] + coordinator_provider_uri=coordinator_provider_uri, + coordinator_network=coordinator_network, + registry=InMemoryContractRegistry.from_latest_publication(network=network), ) bob.start_learning_loop(now=True)