mirror of https://github.com/nucypher/nucypher.git
Merge remote-tracking branch 'upstream/master' into config; Update imports to newer config composition.
commit
03a57bb7f2
13
Pipfile
13
Pipfile
|
@ -7,11 +7,11 @@ name = "pypi"
|
|||
rpcudp = {git = "https://github.com/nucypher/rpcudp", ref = "kms-dependency"}
|
||||
kademlia = {git = "https://github.com/nucypher/kademlia", ref = "kms-dependency"}
|
||||
lmdb = "*"
|
||||
pynacl = "*"
|
||||
PyNaCl = "*"
|
||||
"pysha3" = "*"
|
||||
bidict = "*"
|
||||
py-ecc = "*"
|
||||
sqlalchemy = "*"
|
||||
py_ecc = "*"
|
||||
SQLAlchemy = "*"
|
||||
apistar = "*"
|
||||
mypy = "*"
|
||||
pytest-mypy = "*"
|
||||
|
@ -19,11 +19,12 @@ maya = "*"
|
|||
pyumbral = {git = "https://github.com/nucypher/pyumbral.git"}
|
||||
requests = "*"
|
||||
hendrix = {git = "https://github.com/hendrix/hendrix", ref = "tags/3.0.0rc1"}
|
||||
constantsorrow = {git = "https://github.com/nucypher/constantSorrow.git", ref = "kms-depend"}
|
||||
bytestringsplitter = {git = "https://github.com/nucypher/byteStringSplitter.git", ref = "eaa1df2433362190f30bc6e400570f0331980ebb"}
|
||||
"60a7e00" = {path = "./../pyUmbral"}
|
||||
constantSorrow = {git = "https://github.com/nucypher/constantSorrow.git", ref = "kms-depend"}
|
||||
bytestringSplitter = {git = "https://github.com/nucypher/byteStringSplitter.git", ref = "eaa1df2433362190f30bc6e400570f0331980ebb"}
|
||||
eth-account = "*"
|
||||
"web3" = "*"
|
||||
appdirs = "*"
|
||||
populus = {git = "https://github.com/nucypher/Bropulus.git"}
|
||||
|
||||
[dev-packages]
|
||||
pytest = "*"
|
||||
|
|
|
@ -10,8 +10,8 @@ from kademlia.utils import digest
|
|||
from typing import Dict
|
||||
from typing import Union, List
|
||||
|
||||
from nkms.config.config import KMSConfig
|
||||
from constant_sorrow import constants, default_constant_splitter
|
||||
from nkms.config.config import KMSConfig
|
||||
from nkms.crypto.api import secure_random, keccak_digest
|
||||
from nkms.crypto.constants import PUBLIC_KEY_LENGTH
|
||||
from nkms.crypto.kits import UmbralMessageKit
|
||||
|
@ -21,7 +21,6 @@ from nkms.crypto.splitters import signature_splitter
|
|||
from nkms.network import blockchain_client
|
||||
from nkms.network.protocols import dht_value_splitter
|
||||
from nkms.network.server import NuCypherDHTServer, NuCypherSeedOnlyDHTServer, ProxyRESTServer
|
||||
from nkms.policy.constants import NOT_FROM_ALICE, NON_PAYMENT
|
||||
|
||||
from nkms_eth.actors import PolicyAuthor
|
||||
|
||||
|
@ -39,8 +38,10 @@ class Character(object):
|
|||
_default_crypto_powerups = None
|
||||
_stamp = None
|
||||
|
||||
def __init__(self, attach_server=True, crypto_power: CryptoPower = None,
|
||||
crypto_power_ups=None, is_me=True, config: KMSConfig=None) -> None:
|
||||
address = "This is a fake address." # TODO: #192
|
||||
|
||||
def __init__(self, attach_server=True, crypto_power: CryptoPower=None,
|
||||
crypto_power_ups=None, is_me=True, config: "KMSConfig"=None) -> None:
|
||||
"""
|
||||
:param attach_server: Whether to attach a Server when this Character is
|
||||
born.
|
||||
|
@ -217,7 +218,8 @@ class Character(object):
|
|||
with suppress(AttributeError):
|
||||
if message_kit.alice_pubkey:
|
||||
if not message_kit.alice_pubkey == actor_whom_sender_claims_to_be.public_key(SigningPower):
|
||||
raise ValueError("This MessageKit doesn't appear to have come from {}".format(actor_whom_sender_claims_to_be))
|
||||
raise ValueError(
|
||||
"This MessageKit doesn't appear to have come from {}".format(actor_whom_sender_claims_to_be))
|
||||
|
||||
alice_pubkey = actor_whom_sender_claims_to_be.public_key(SigningPower)
|
||||
signature_from_kit = None
|
||||
|
@ -297,12 +299,17 @@ class Character(object):
|
|||
self.known_nodes[node.interface_dht_key()] = node
|
||||
|
||||
|
||||
class FakePolicyAgent: # TODO: #192
|
||||
_token = "fake token"
|
||||
|
||||
|
||||
class Alice(Character, PolicyAuthor):
|
||||
_server_class = NuCypherSeedOnlyDHTServer
|
||||
_default_crypto_powerups = [SigningPower, EncryptingPower]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
PolicyAuthor.__init__(self, self.address, policy_agent=FakePolicyAgent())
|
||||
|
||||
def generate_kfrags(self, bob, m, n) -> List:
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from nkms.config.keys import KMSKeyring, _CONFIG_ROOT
|
||||
from nkms.config.keys import KMSKeyring
|
||||
|
||||
_CONFIG_ROOT = os.path.join(str(Path.home()), '.nucypher')
|
||||
|
||||
|
||||
class KMSConfigurationError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
class StakeConfig:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
from base64 import urlsafe_b64encode
|
||||
from pathlib import Path
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
|
@ -12,17 +11,12 @@ from nacl.secret import SecretBox
|
|||
from umbral.keys import UmbralPrivateKey
|
||||
from web3.auto import w3
|
||||
|
||||
from nkms.config.configs import KMSConfigurationError, _CONFIG_ROOT
|
||||
from nkms.crypto.powers import SigningPower, EncryptingPower, CryptoPower
|
||||
from nkms.keystore.keypairs import SigningKeypair, EncryptingKeypair
|
||||
|
||||
w3.eth.enable_unaudited_features()
|
||||
|
||||
_CONFIG_ROOT = os.path.join(str(Path.home()), '.nucypher')
|
||||
|
||||
|
||||
class KMSConfigurationError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def validate_passphrase(passphrase) -> str:
|
||||
"""Validate a passphrase and return it or raise"""
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Union
|
|||
from nkms.crypto.constants import KFRAG_LENGTH
|
||||
from nkms.crypto.signature import Signature
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from nkms.keystore.db.models import Key, PolicyContract, Workorder
|
||||
from nkms.keystore.db.models import Key, PolicyArrangement, Workorder
|
||||
from umbral.fragments import KFrag
|
||||
from umbral.keys import UmbralPublicKey
|
||||
from . import keypairs
|
||||
|
|
|
@ -15,7 +15,6 @@ from nkms.crypto.powers import SigningPower
|
|||
from nkms.crypto.signature import Signature
|
||||
from nkms.crypto.splitters import key_splitter
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from nkms.network.constants import BYTESTRING_IS_TREASURE_MAP
|
||||
from nkms_eth.policies import BlockchainArrangement
|
||||
from umbral.pre import Capsule
|
||||
from constant_sorrow import constants
|
||||
|
@ -48,16 +47,16 @@ class Arrangement(BlockchainArrangement):
|
|||
self.kfrag = kfrag
|
||||
self.ursula = ursula
|
||||
|
||||
arrangement_delta = datetime.utcnow() - self.expiration
|
||||
policy_duration = arrangement_delta.hours // 24
|
||||
arrangement_delta = maya.now() - self.expiration
|
||||
policy_duration = arrangement_delta.days
|
||||
|
||||
super().__init__(author=self.alice.address, miner=self.ursula.address,
|
||||
super().__init__(author=self.alice, miner=ursula,
|
||||
value=self.deposit, periods=policy_duration,
|
||||
arrangement_id=self._make_arrangement_id())
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes(self.alice.stamp) + bytes(
|
||||
self.hrac) + self.expiration.isoformat().encode() + bytes(
|
||||
self.hrac) + self.expiration.iso8601().encode() + bytes(
|
||||
self.deposit)
|
||||
|
||||
@staticmethod
|
||||
|
@ -83,7 +82,7 @@ class Arrangement(BlockchainArrangement):
|
|||
# Publish arrangement to blockchain
|
||||
# TODO Determine actual gas price here
|
||||
# TODO Negotiate the receipt of a KFrag per Ursula
|
||||
super().publish(gas_price=0)
|
||||
# super().publish(gas_price=0)
|
||||
|
||||
def encrypt_payload_for_ursula(self):
|
||||
"""
|
||||
|
@ -269,7 +268,7 @@ class Policy(object):
|
|||
for ursula, arrangement, result in found_ursulas:
|
||||
if result.was_accepted: # TODO: Here, we need to assess the result and see if we're actually good to go.
|
||||
kfrag = self.assign_kfrag_to_arrangement(arrangement)
|
||||
arrangement.activate(kfrag, ursula, result)
|
||||
arrangement.publish(kfrag, ursula, result)
|
||||
# TODO: What if there weren't enough Arrangements approved to distribute n kfrags? We need to raise NotEnoughQualifiedUrsulas.
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,12 @@ from bytestring_splitter import BytestringSplitter
|
|||
from tests.utilities import MockNetworkyStuff
|
||||
from umbral.fragments import KFrag
|
||||
from umbral.keys import UmbralPublicKey
|
||||
import maya
|
||||
|
||||
|
||||
def test_grant(alice, bob, ursulas):
|
||||
networky_stuff = MockNetworkyStuff(ursulas)
|
||||
policy_end_datetime = datetime.datetime.now() + datetime.timedelta(days=5)
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
n = 5
|
||||
uri = b"this_is_the_path_to_which_access_is_being_granted"
|
||||
policy = alice.grant(bob, uri, networky_stuff, m=3, n=n,
|
||||
|
|
|
@ -13,6 +13,7 @@ from sqlalchemy.engine import create_engine
|
|||
from nkms.keystore import keystore
|
||||
from nkms.keystore.db import Base
|
||||
from umbral import pre
|
||||
import maya
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
@ -36,7 +37,7 @@ def idle_policy(alice, bob):
|
|||
def enacted_policy(idle_policy, ursulas):
|
||||
# Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them.
|
||||
deposit = constants.NON_PAYMENT
|
||||
contract_end_datetime = datetime.datetime.now() + datetime.timedelta(days=5)
|
||||
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
# contract = Contract(idle_policy.n, deposit, contract_end_datetime)
|
||||
|
||||
networky_stuff = MockNetworkyStuff(ursulas)
|
||||
|
|
|
@ -169,15 +169,15 @@ def test_treaure_map_is_legit(enacted_policy):
|
|||
assert port in legal_ports
|
||||
|
||||
|
||||
# TODO: Have Alice inherit from PolicyAuthor
|
||||
def test_alice_finds_ursulas_from_blockchain(testerchain, mock_miner_agent, mock_token_deployer):
|
||||
mock_token_deployer._global_airdrop(amount=10000)
|
||||
|
||||
# Create some miners to find
|
||||
_, *miner_addresses = testerchain._chain.web3.eth.accounts[1:]
|
||||
spawn_miners(miner_addresses, mock_miner_agent, mock_miner_agent.token_agent._deployer._M, 100)
|
||||
|
||||
testerchain.wait_time(mock_miner_agent._deployer._hours_per_period)
|
||||
|
||||
reenc_nodes = mock_miner_agent.sample(quantity=4)
|
||||
assert len(reenc_nodes) >= 4
|
||||
# # TODO: Have Alice inherit from PolicyAuthor
|
||||
# def test_alice_finds_ursulas_from_blockchain(testerchain, mock_miner_agent, mock_token_deployer):
|
||||
# mock_token_deployer._global_airdrop(amount=10000)
|
||||
#
|
||||
# # Create some miners to find
|
||||
# _, *miner_addresses = testerchain._chain.web3.eth.accounts[1:]
|
||||
# spawn_miners(miner_addresses, mock_miner_agent, mock_miner_agent.token_agent._deployer._M, 100)
|
||||
#
|
||||
# testerchain.wait_time(mock_miner_agent._deployer._hours_per_period)
|
||||
#
|
||||
# reenc_nodes = mock_miner_agent.sample(quantity=4)
|
||||
# assert len(reenc_nodes) >= 4
|
||||
|
|
Loading…
Reference in New Issue