Exemple #1
0
# NuCypher Network #
####################

L1_NETWORK = 'mainnet'  # or 'ibex'
L2_NETWORK = 'polygon'  # or 'mumbai'

#####################
# Bob the BUIDLer  ##
#####################

# Then, there was bob. Bob learns about the
# rest of the network from the seednode.
bob = Bob(domain=L1_NETWORK)

# Bob puts his public keys somewhere alice can find them.
verifying_key = bob.public_keys(SigningPower)
encrypting_key = bob.public_keys(DecryptingPower)

######################################
# Alice, the Authority of the Policy #
######################################

# Connect to the ethereum provider.
connect_web3_provider(eth_provider_uri=L1_PROVIDER)
# Connect to the layer 2 provider.
connect_web3_provider(eth_provider_uri=L2_PROVIDER)

# Setup and unlock alice's ethereum wallet.
# WARNING: Never give your mainnet password or mnemonic phrase to anyone.
# Do not use mainnet keys, create a dedicated software wallet to use for this demo.
wallet = Signer.from_signer_uri(SIGNER_URI)
    nucypher_signing_key, alice_nucypher_signing_pub_key).transact()
w3.eth.waitForTransactionReceipt(tx_hash)

#########################
# Bob the data receiver #
#########################

bob = Bob(known_nodes=[ursula],
          domains={TEMPORARY_DOMAIN},
          network_middleware=RestMiddleware(),
          federated_only=True,
          start_learning_now=True,
          learn_on_same_thread=True)
# store public keys on chain
w3.eth.defaultAccount = bob_eth_address
bob_nucypher_decrypting_pub_key = bob.public_keys(DecryptingPower).to_bytes()
tx_hash = bob_proxy_account.functions.setData(
    nucypher_decrypting_key, bob_nucypher_decrypting_pub_key).transact()
w3.eth.waitForTransactionReceipt(tx_hash)
bob_nucypher_signing_pub_key = bob.public_keys(SigningPower).to_bytes()
tx_hash = bob_proxy_account.functions.setData(
    nucypher_signing_key, bob_nucypher_signing_pub_key).transact()
w3.eth.waitForTransactionReceipt(tx_hash)

#####################################################
# Alice creates the policy and grants access to Bob #
#####################################################

# Alice can get the public key even before creating the policy.
# From this moment on, any Data Source like Enrico that knows the public key
# can encrypt data originally intended for Alice, but that can be shared with