コード例 #1
0
# This is an example of Alice setting a Policy on the NuCypher network.
# In this example, Alice uses n=1, which is almost always a bad idea.  Don't do it.

# WIP w/ hendrix@8227c4abcb37ee6d27528a13ec22d55ee106107f

import datetime

import requests

from nkms.characters import Alice, Bob, Ursula
from nkms.network.node import NetworkyStuff

ALICE = Alice()
BOB = Bob()
URSULA = Ursula.from_rest_url("http://localhost:3500/public_keys")

ALICE.learn_about_actor(URSULA)


class SandboxNetworkyStuff(NetworkyStuff):
    def find_ursula(self, contract=None):
        ursula = Ursula.as_discovered_on_network(dhr_port=None,
                                                 dht_interface=None,
                                                 pubkey_sig_bytes=bytes(
                                                     URSULA.stamp),
                                                 rest_address="localhost",
                                                 rest_port=3500)
        response = requests.post("http://localhost:3500/consider_contract",
                                 bytes(contract))
        response.was_accepted = True
        return ursula, response
コード例 #2
0
# WIP w/ hendrix@8227c4abcb37ee6d27528a13ec22d55ee106107f

import datetime
import sys

import requests

from nkms.characters import Alice, Bob, Ursula
from nkms.crypto.kits import MessageKit
from nkms.crypto.powers import SigningPower, EncryptingPower
from nkms.network.node import NetworkyStuff
from umbral import pre

ALICE = Alice()
BOB = Bob()
URSULA = Ursula.from_rest_url(address="https://localhost", port="3550")


class SandboxNetworkyStuff(NetworkyStuff):
    def find_ursula(self, contract=None):
        ursula = Ursula.as_discovered_on_network(
            dht_port=None,
            dht_interface=None,
            rest_address="https://localhost",
            rest_port=3550,
            powers_and_keys={
                SigningPower: URSULA.stamp.as_umbral_pubkey(),
                EncryptingPower: URSULA.public_key(EncryptingPower)
            })
        response = requests.post("https://localhost:3550/consider_contract",
                                 bytes(contract),