Rename NuCypher -> nucypher where appropriate.

pull/270/head
Kieran R Prasch 2018-05-16 18:31:49 -04:00
parent 9b592a0c74
commit 6397fba5f1
19 changed files with 79 additions and 79 deletions

View File

@ -3,7 +3,7 @@ from collections import OrderedDict
from datetime import datetime
from typing import Tuple, List, Union
from nucypher.blockchain.eth.agents import NuCypherTokenAgent
from nucypher.blockchain.eth.agents import NucypherTokenAgent
class TokenActor(ABC):
@ -11,7 +11,7 @@ class TokenActor(ABC):
class ActorError(Exception):
pass
def __init__(self, token_agent: NuCypherTokenAgent, address: Union[bytes, str]):
def __init__(self, token_agent: NucypherTokenAgent, address: Union[bytes, str]):
self.token_agent = token_agent
if isinstance(address, bytes):

View File

@ -5,7 +5,7 @@ from functools import partial
from typing import Set, Generator, List
from nucypher.blockchain.eth import constants
from nucypher.blockchain.eth.constants import NuCypherTokenConfig, NuCypherMinerConfig
from nucypher.blockchain.eth.constants import NucypherTokenConfig, NucypherMinerConfig
from web3.contract import Contract
@ -59,11 +59,11 @@ class EthereumContractAgent(ABC):
return self.contract.functions.balanceOf(address).call()
class NuCypherTokenAgent(EthereumContractAgent, NuCypherTokenConfig):
class NucypherTokenAgent(EthereumContractAgent, NucypherTokenConfig):
_principal_contract_name = "NuCypherToken"
class MinerAgent(EthereumContractAgent, NuCypherMinerConfig):
class MinerAgent(EthereumContractAgent, NucypherMinerConfig):
"""
Wraps NuCypher's Escrow solidity smart contract
@ -84,7 +84,7 @@ class MinerAgent(EthereumContractAgent, NuCypherMinerConfig):
CONFIRMED_PERIOD_1 = 3
CONFIRMED_PERIOD_2 = 4
def __init__(self, token_agent: NuCypherTokenAgent, *args, **kwargs):
def __init__(self, token_agent: NucypherTokenAgent, *args, **kwargs):
super().__init__(blockchain=token_agent.blockchain, *args, **kwargs)
self.token_agent = token_agent
self.miners = list() # Tracks per client

View File

@ -2,7 +2,7 @@ import random
from abc import ABC
from typing import List
from nucypher.blockchain.eth.constants import NuCypherMinerConfig
from nucypher.blockchain.eth.constants import NucypherMinerConfig
from nucypher.blockchain.eth.interfaces import ContractProvider
@ -72,7 +72,7 @@ class TheBlockchain(ABC):
return result
class TesterBlockchain(TheBlockchain, NuCypherMinerConfig):
class TesterBlockchain(TheBlockchain, NucypherMinerConfig):
"""Transient, in-memory, local, private chain"""
_network = 'tester'

View File

@ -1,7 +1,7 @@
NULL_ADDRESS = '0x' + '0' * 40
class NuCypherTokenConfig:
class NucypherTokenConfig:
class TokenConfigError(ValueError):
pass
@ -17,7 +17,7 @@ class NuCypherTokenConfig:
return self.__saturation
class NuCypherMinerConfig:
class NucypherMinerConfig:
class MinerConfigError(ValueError):
pass
@ -26,10 +26,10 @@ class NuCypherMinerConfig:
min_locked_periods = 30 # 720 Hours minimum
max_minting_periods = 365 # Maximum number of periods
min_allowed_locked = 15000 * NuCypherTokenConfig._M
max_allowed_locked = int(4e6) * NuCypherTokenConfig._M
min_allowed_locked = 15000 * NucypherTokenConfig._M
max_allowed_locked = int(4e6) * NucypherTokenConfig._M
__remaining_supply = NuCypherTokenConfig._remaining_supply
__remaining_supply = NucypherTokenConfig._remaining_supply
__mining_coeff = [ # TODO
_hours_per_period,

View File

@ -2,8 +2,8 @@ from typing import Tuple, Dict
from web3.contract import Contract
from nucypher.blockchain.eth.agents import EthereumContractAgent, MinerAgent, NuCypherTokenAgent, PolicyAgent
from nucypher.blockchain.eth.constants import NuCypherTokenConfig, NuCypherMinerConfig
from nucypher.blockchain.eth.agents import EthereumContractAgent, MinerAgent, NucypherTokenAgent, PolicyAgent
from nucypher.blockchain.eth.constants import NucypherTokenConfig, NucypherMinerConfig
from .chains import TheBlockchain
@ -156,10 +156,10 @@ class ContractDeployer:
return agent
class NuCypherTokenDeployer(ContractDeployer, NuCypherTokenConfig):
class NucypherTokenDeployer(ContractDeployer, NucypherTokenConfig):
_contract_name = 'NuCypherToken'
agency = NuCypherTokenAgent
agency = NucypherTokenAgent
def __init__(self, blockchain):
super().__init__(blockchain=blockchain)
@ -206,9 +206,9 @@ class DispatcherDeployer(ContractDeployer):
return txhash
class MinerEscrowDeployer(ContractDeployer, NuCypherMinerConfig):
class MinerEscrowDeployer(ContractDeployer, NucypherMinerConfig):
"""
Deploys the MinerEscrow ethereum contract to the blockchain. Depends on NuCypherTokenAgent
Deploys the MinerEscrow ethereum contract to the blockchain. Depends on NucypherTokenAgent
"""
agency = MinerAgent
@ -290,7 +290,7 @@ class MinerEscrowDeployer(ContractDeployer, NuCypherMinerConfig):
class PolicyManagerDeployer(ContractDeployer):
"""
Depends on MinerAgent and NuCypherTokenAgent
Depends on MinerAgent and NucypherTokenAgent
"""
agency = PolicyAgent

View File

@ -6,7 +6,7 @@ A simple Python script to deploy contracts and then estimate gas for different m
"""
from nucypher.blockchain.eth.agents import NuCypherTokenAgent, MinerAgent
from nucypher.blockchain.eth.agents import NucypherTokenAgent, MinerAgent
import os
from tests.utilities import TesterBlockchain
@ -21,7 +21,7 @@ def main():
# TODO: Updatae to agents and deployers
# Create an ERC20 token
token = NuCypherToken(blockchain=chain)
token = NucypherToken(blockchain=chain)
token.arm()
token.deploy()

View File

@ -14,7 +14,7 @@ from umbral.keys import UmbralPublicKey
from constant_sorrow import constants, default_constant_splitter
from nucypher.blockchain.eth.actors import PolicyAuthor
from nucypher.config.configs import NuCypherConfig
from nucypher.config.configs import NucypherConfig
from nucypher.crypto.api import secure_random, keccak_digest, encrypt_and_sign
from nucypher.crypto.constants import PUBLIC_KEY_LENGTH
from nucypher.crypto.kits import UmbralMessageKit
@ -22,7 +22,7 @@ from nucypher.crypto.powers import CryptoPower, SigningPower, EncryptingPower, D
from nucypher.crypto.signature import Signature, signature_splitter, SignatureStamp, StrangerStamp
from nucypher.network import blockchain_client
from nucypher.network.protocols import dht_value_splitter, dht_with_hrac_splitter
from nucypher.network.server import NuCypherDHTServer, NuCypherSeedOnlyDHTServer, ProxyRESTServer
from nucypher.network.server import NucypherDHTServer, NucypherSeedOnlyDHTServer, ProxyRESTServer
class Character(object):
@ -38,7 +38,7 @@ class Character(object):
def __init__(self, attach_server=True, crypto_power: CryptoPower=None,
crypto_power_ups=None, is_me=True, network_middleware=None,
config: "NuCypherConfig"=None) -> None:
config: "NucypherConfig"=None) -> None:
"""
:param attach_server: Whether to attach a Server when this Character is
born.
@ -60,7 +60,7 @@ class Character(object):
Character, but there are scenarios in which its imaginable to be
represented by zero Characters or by more than one Character.
"""
# self.config = config if config is not None else NuCypherConfig.get_config()
# self.config = config if config is not None else NucypherConfig.get_config()
self.known_nodes = {}
self.log = getLogger("characters")
@ -317,7 +317,7 @@ class FakePolicyAgent: # TODO: #192
class Alice(Character, PolicyAuthor):
_server_class = NuCypherSeedOnlyDHTServer
_server_class = NucypherSeedOnlyDHTServer
_default_crypto_powerups = [SigningPower, EncryptingPower, DelegatingPower]
def __init__(self, *args, **kwargs):
@ -389,7 +389,7 @@ class Alice(Character, PolicyAuthor):
class Bob(Character):
_server_class = NuCypherSeedOnlyDHTServer
_server_class = NucypherSeedOnlyDHTServer
_default_crypto_powerups = [SigningPower, EncryptingPower]
def __init__(self, *args, **kwargs):
@ -590,7 +590,7 @@ class Bob(Character):
class Ursula(Character, ProxyRESTServer):
_server_class = NuCypherDHTServer
_server_class = NucypherDHTServer
_alice_class = Alice
_default_crypto_powerups = [SigningPower, EncryptingPower]

View File

@ -7,7 +7,7 @@ import maya
_DEFAULT_CONFIGURATION_DIR = os.path.join(str(Path.home()), '.nucypher')
class NuCypherConfigurationError(RuntimeError):
class NucypherConfigurationError(RuntimeError):
pass
@ -32,7 +32,7 @@ class StakeConfig:
for rule, failure_message in rules:
if rule is False:
raise NuCypherConfigurationError(failure_message)
raise NucypherConfigurationError(failure_message)
else:
return True
@ -64,7 +64,7 @@ class NetworkConfig:
return self.__db_path
class NuCypherConfig:
class NucypherConfig:
__default_configuration_root = _DEFAULT_CONFIGURATION_DIR
__default_json_config_filepath = os.path.join(__default_configuration_root, 'conf.json')

View File

@ -2,10 +2,10 @@
Public facing client interface
"""
from nucypher.config.keys import NuCypherKeyring
from nucypher.config.keys import NucypherKeyring
def _bootstrap_config():
"""Do not actually use this."""
passphrase = input("Enter passphrase >> ")
return NuCypherKeyring.generate(passphrase=passphrase)
return NucypherKeyring.generate(passphrase=passphrase)

View File

@ -113,7 +113,7 @@ def _generate_transacting_keys(passphrase: str) -> dict:
return encrypted_wallet_data
class NuCypherKeyring:
class NucypherKeyring:
"""
Warning: This class handles private keys!
@ -233,7 +233,7 @@ class NuCypherKeyring:
return new_cryptopower
@classmethod
def generate(cls, passphrase: str, encryption: bool=True, transacting: bool=True, output_path: str=None) -> 'NuCypherKeyring':
def generate(cls, passphrase: str, encryption: bool=True, transacting: bool=True, output_path: str=None) -> 'NucypherKeyring':
"""
Generates new encryption, signing, and transacting keys encrypted with the passphrase,
respectively saving keyfiles on the local filesystem from *default* paths,

View File

@ -2,7 +2,7 @@ import json
import os
import stat
from .configs import _DEFAULT_CONFIGURATION_DIR, NuCypherConfigurationError
from .configs import _DEFAULT_CONFIGURATION_DIR, NucypherConfigurationError
def _save_private_keyfile(keypath: str, key_data: dict) -> str:
@ -87,7 +87,7 @@ def _parse_keyfile(keypath: str):
try:
key_metadata = json.loads(keyfile)
except json.JSONDecodeError:
raise NuCypherConfigurationError("Invalid data in keyfile {}".format(keypath))
raise NucypherConfigurationError("Invalid data in keyfile {}".format(keypath))
else:
return key_metadata
@ -112,7 +112,7 @@ def validate_passphrase(passphrase) -> bool:
for rule, failure_message in rules:
if not rule:
raise NuCypherConfigurationError(failure_message)
raise NucypherConfigurationError(failure_message)
return True

View File

@ -7,7 +7,7 @@ from nucypher.network.capabilities import ServerCapability
from umbral.fragments import CapsuleFrag
class NuCypherNode(Node):
class NucypherNode(Node):
def __init__(self, id, ip=None, port=None, capabilities=None, capabilities_as_strings=[], *args, **kwargs):
self.id = id

View File

@ -7,18 +7,18 @@ from nucypher.crypto.api import keccak_digest
from nucypher.crypto.constants import PUBLIC_KEY_LENGTH, KECCAK_DIGEST_LENGTH
from nucypher.crypto.signature import Signature
from bytestring_splitter import BytestringSplitter
from nucypher.network.node import NuCypherNode
from nucypher.network.routing import NuCypherRoutingTable
from nucypher.network.node import NucypherNode
from nucypher.network.routing import NucypherRoutingTable
from umbral.keys import UmbralPublicKey
dht_value_splitter = default_constant_splitter + BytestringSplitter(Signature, (UmbralPublicKey, PUBLIC_KEY_LENGTH))
dht_with_hrac_splitter = dht_value_splitter + BytestringSplitter((bytes, KECCAK_DIGEST_LENGTH))
class NuCypherHashProtocol(KademliaProtocol):
class NucypherHashProtocol(KademliaProtocol):
def __init__(self, sourceNode, storage, ksize, *args, **kwargs):
super().__init__(sourceNode, storage, ksize, *args, **kwargs)
self.router = NuCypherRoutingTable(self, ksize, sourceNode)
self.router = NucypherRoutingTable(self, ksize, sourceNode)
self.illegal_keys_seen = []
# TODO: This is the wrong way to do this. See #227.
self.treasure_maps = {}
@ -31,13 +31,13 @@ class NuCypherHashProtocol(KademliaProtocol):
return True
def rpc_ping(self, sender, nodeid, node_capabilities=[]):
source = NuCypherNode(nodeid, sender[0], sender[1],
source = NucypherNode(nodeid, sender[0], sender[1],
capabilities_as_strings=node_capabilities)
self.welcomeIfNewNode(source)
return self.sourceNode.id
async def callStore(self, nodeToAsk, key, value):
# nodeToAsk = NuCypherNode
# nodeToAsk = NucypherNode
if self.check_node_for_storage(nodeToAsk):
address = (nodeToAsk.ip, nodeToAsk.port)
# TODO: encrypt `value` with public key of nodeToAsk
@ -72,7 +72,7 @@ class NuCypherHashProtocol(KademliaProtocol):
return True
def rpc_store(self, sender, nodeid, key, value):
source = NuCypherNode(nodeid, sender[0], sender[1])
source = NucypherNode(nodeid, sender[0], sender[1])
self.welcomeIfNewNode(source)
self.log.debug("got a store request from %s" % str(sender))
@ -108,7 +108,7 @@ class NuCypherHashProtocol(KademliaProtocol):
return do_store
class NuCypherSeedOnlyProtocol(NuCypherHashProtocol):
class NucypherSeedOnlyProtocol(NucypherHashProtocol):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -1,7 +1,7 @@
from kademlia.routing import RoutingTable
class NuCypherRoutingTable(RoutingTable):
class NucypherRoutingTable(RoutingTable):
def addContact(self, node, seed_only=False):
if seed_only:

View File

@ -17,20 +17,20 @@ from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import EncryptingPower, SigningPower
from nucypher.keystore.threading import ThreadedSession
from nucypher.network.capabilities import SeedOnly, ServerCapability
from nucypher.network.node import NuCypherNode
from nucypher.network.protocols import NuCypherSeedOnlyProtocol, NuCypherHashProtocol, \
from nucypher.network.node import NucypherNode
from nucypher.network.protocols import NucypherSeedOnlyProtocol, NucypherHashProtocol, \
dht_value_splitter, dht_with_hrac_splitter
from nucypher.network.storage import SeedOnlyStorage
class NuCypherDHTServer(Server):
protocol_class = NuCypherHashProtocol
class NucypherDHTServer(Server):
protocol_class = NucypherHashProtocol
capabilities = ()
digests_set = 0
def __init__(self, ksize=20, alpha=3, id=None, storage=None, *args, **kwargs):
super().__init__(ksize=20, alpha=3, id=None, storage=None, *args, **kwargs)
self.node = NuCypherNode(id or digest(
self.node = NucypherNode(id or digest(
random.getrandbits(255))) # TODO: Assume that this can be attacked to get closer to desired kFrags.
def serialize_capabilities(self):
@ -41,7 +41,7 @@ class NuCypherDHTServer(Server):
Announce node including capabilities
"""
result = await self.protocol.ping(addr, self.node.id, self.serialize_capabilities())
return NuCypherNode(result[1], addr[0], addr[1]) if result[0] else None
return NucypherNode(result[1], addr[0], addr[1]) if result[0] else None
async def set_digest(self, dkey, value):
"""
@ -86,8 +86,8 @@ class NuCypherDHTServer(Server):
return await self.set_digest(key, value)
class NuCypherSeedOnlyDHTServer(NuCypherDHTServer):
protocol_class = NuCypherSeedOnlyProtocol
class NucypherSeedOnlyDHTServer(NucypherDHTServer):
protocol_class = NucypherSeedOnlyProtocol
capabilities = (SeedOnly(),)
def __init__(self, *args, **kwargs):

View File

@ -1,8 +1,8 @@
import pytest
from pytest import raises
from nucypher.blockchain.eth.agents import NuCypherTokenAgent, MinerAgent
from nucypher.blockchain.eth.deployers import NuCypherTokenDeployer, MinerEscrowDeployer, PolicyManagerDeployer
from nucypher.blockchain.eth.agents import NucypherTokenAgent, MinerAgent
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer, MinerEscrowDeployer, PolicyManagerDeployer
from nucypher.blockchain.eth.interfaces import Registrar
@ -10,12 +10,12 @@ def test_token_deployer_and_agent(chain):
# Trying to get token from blockchain before it's been published fails
with pytest.raises(Registrar.UnknownContract):
NuCypherTokenAgent(blockchain=chain)
NucypherTokenAgent(blockchain=chain)
# The big day...
deployer = NuCypherTokenDeployer(blockchain=chain)
deployer = NucypherTokenDeployer(blockchain=chain)
with pytest.raises(NuCypherTokenDeployer.ContractDeploymentError):
with pytest.raises(NucypherTokenDeployer.ContractDeploymentError):
deployer.deploy()
# Token must be armed before deploying to the blockchain
@ -23,10 +23,10 @@ def test_token_deployer_and_agent(chain):
deployer.deploy()
# Create a token instance
token_agent = NuCypherTokenAgent(blockchain=chain)
token_agent = NucypherTokenAgent(blockchain=chain)
# Make sure we got the name right
deployer_contract_identifier = NuCypherTokenDeployer._contract_name
deployer_contract_identifier = NucypherTokenDeployer._contract_name
assert'NuCypherToken' == deployer_contract_identifier
# Ensure the contract is deployed and has a valid blockchain address
@ -37,7 +37,7 @@ def test_token_deployer_and_agent(chain):
# assert token().totalSupply() == int(1e9) * _M # TODO
# Retrieve the token from the blockchain
same_token_agent = NuCypherTokenAgent(blockchain=chain)
same_token_agent = NucypherTokenAgent(blockchain=chain)
# Compare the contract address for equality
assert token_agent.contract_address == same_token_agent.contract_address
@ -54,11 +54,11 @@ def test_deploy_ethereum_contracts(chain):
- Issuer
"""
token_deployer = NuCypherTokenDeployer(blockchain=chain)
token_deployer = NucypherTokenDeployer(blockchain=chain)
token_deployer.arm()
token_deployer.deploy()
token_agent = NuCypherTokenAgent(blockchain=chain)
token_agent = NucypherTokenAgent(blockchain=chain)
miner_escrow_deployer = MinerEscrowDeployer(token_agent=token_agent)
miner_escrow_deployer.arm()

View File

@ -1,4 +1,4 @@
from nucypher.blockchain.eth.deployers import NuCypherTokenDeployer
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer
def test_chain_creation(chain):
@ -13,5 +13,5 @@ def test_nucypher_contract_compiled(chain):
# Check that populus paths are set...
# Ensure that solidity smart contacts are available, post-compile.
token_contract_identifier = NuCypherTokenDeployer(blockchain=chain)._contract_name
token_contract_identifier = NucypherTokenDeployer(blockchain=chain)._contract_name
assert token_contract_identifier in chain.provider._ContractProvider__raw_contract_cache

View File

@ -7,18 +7,18 @@ from eth_tester.backends import is_pyevm_available
from eth_tester.backends.pyevm.main import get_default_genesis_params, get_default_account_keys, generate_genesis_state
from web3 import Web3
from nucypher.blockchain.eth.agents import MinerAgent, NuCypherTokenAgent
from nucypher.blockchain.eth.constants import NuCypherMinerConfig
from nucypher.blockchain.eth.deployers import MinerEscrowDeployer, NuCypherTokenDeployer
from nucypher.blockchain.eth.agents import MinerAgent, NucypherTokenAgent
from nucypher.blockchain.eth.constants import NucypherMinerConfig
from nucypher.blockchain.eth.deployers import MinerEscrowDeployer, NucypherTokenDeployer
class MockNuCypherMinerConfig(NuCypherMinerConfig):
class MockNucypherMinerConfig(NucypherMinerConfig):
"""Speed things up a bit"""
# _hours_per_period = 24 # Hours
# min_locked_periods = 1 # Minimum locked periods
class MockTokenAgent(NuCypherTokenAgent):
class MockTokenAgent(NucypherTokenAgent):
def token_airdrop(self, amount: int, addresses: List[str]=None):
"""Airdrops tokens from creator address to all other addresses!"""
@ -38,7 +38,7 @@ class MockTokenAgent(NuCypherTokenAgent):
return receipts
class MockMinerAgent(MinerAgent, MockNuCypherMinerConfig):
class MockMinerAgent(MinerAgent, MockNucypherMinerConfig):
"""MinerAgent with faked config subclass"""
def spawn_random_miners(self, addresses: list) -> list:
@ -66,12 +66,12 @@ class MockMinerAgent(MinerAgent, MockNuCypherMinerConfig):
return miners
class MockNuCypherTokenDeployer(NuCypherTokenDeployer):
class MockNucypherTokenDeployer(NucypherTokenDeployer):
"""Mock deployer with mock agency"""
agency = MockTokenAgent
class MockMinerEscrowDeployer(MinerEscrowDeployer, MockNuCypherMinerConfig):
class MockMinerEscrowDeployer(MinerEscrowDeployer, MockNucypherMinerConfig):
"""Helper class for MockMinerAgent, using a mock miner config"""
agency = MockMinerAgent

View File

@ -18,7 +18,7 @@ from nucypher.blockchain.eth.deployers import PolicyManagerDeployer
from nucypher.blockchain.eth.interfaces import Registrar, ContractProvider
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
from tests.blockchain.eth import contracts, utilities
from tests.blockchain.eth.utilities import MockMinerEscrowDeployer, TesterPyEVMBackend, MockNuCypherTokenDeployer
from tests.blockchain.eth.utilities import MockMinerEscrowDeployer, TesterPyEVMBackend, MockNucypherTokenDeployer
#
@ -171,7 +171,7 @@ def chain(contract_provider, airdrop=False):
@pytest.fixture(scope='module')
def mock_token_deployer(chain):
token_deployer = MockNuCypherTokenDeployer(blockchain=chain)
token_deployer = MockNucypherTokenDeployer(blockchain=chain)
token_deployer.arm()
token_deployer.deploy()
yield token_deployer