mirror of https://github.com/nucypher/nucypher.git
KeyStore -> Datastore
parent
0a2dd3a209
commit
489c048712
|
@ -572,9 +572,9 @@ jobs:
|
|||
steps:
|
||||
- prepare_environment
|
||||
- run:
|
||||
name: Tests for Blockhain interfaces, Crypto functions, Node Configuration and Keystore
|
||||
name: Tests for Blockhain interfaces, Crypto functions, Node Configuration and Datastore
|
||||
command: |
|
||||
pytest $(circleci tests glob "tests/network/**/test_*.py" "tests/config/**/test_*.py" "tests/crypto/**/test_*.py" "tests/keystore/**/test_*.py" "tests/blockchain/eth/interfaces/**/test_*.py" "tests/blockchain/eth/clients/**/test_*.py" | circleci tests split --split-by=timings)
|
||||
pytest $(circleci tests glob "tests/network/**/test_*.py" "tests/config/**/test_*.py" "tests/crypto/**/test_*.py" "tests/datastore/**/test_*.py" "tests/blockchain/eth/interfaces/**/test_*.py" "tests/blockchain/eth/clients/**/test_*.py" | circleci tests split --split-by=timings)
|
||||
- capture_test_results
|
||||
|
||||
character:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
Keystore
|
||||
========
|
||||
|
||||
.. automodule:: nucypher.datastore.keypairs
|
||||
:members:
|
||||
|
||||
.. automodule:: nucypher.datastore.datastore
|
||||
:members:
|
||||
|
||||
.. automodule:: nucypher.datastore.threading
|
||||
:members:
|
|
@ -1,11 +0,0 @@
|
|||
Keystore
|
||||
========
|
||||
|
||||
.. automodule:: nucypher.keystore.keypairs
|
||||
:members:
|
||||
|
||||
.. automodule:: nucypher.keystore.keystore
|
||||
:members:
|
||||
|
||||
.. automodule:: nucypher.keystore.threading
|
||||
:members:
|
|
@ -154,7 +154,7 @@ Whitepapers
|
|||
api/config
|
||||
api/crypto
|
||||
api/keyring
|
||||
api/keystore
|
||||
api/datastore
|
||||
api/network
|
||||
api/policy
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from timeit import default_timer as timer
|
|||
from nucypher.characters.lawful import Bob, Ursula, Enrico
|
||||
from nucypher.crypto.kits import UmbralMessageKit
|
||||
from nucypher.crypto.powers import DecryptingPower, SigningPower
|
||||
from nucypher.keystore.keypairs import DecryptingKeypair, SigningKeypair
|
||||
from nucypher.datastore.keypairs import DecryptingKeypair, SigningKeypair
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
|
||||
from umbral.keys import UmbralPublicKey
|
||||
|
|
|
@ -29,7 +29,7 @@ from nucypher.characters.banners import FELIX_BANNER, NU_BANNER
|
|||
from nucypher.characters.base import Character
|
||||
from nucypher.config.constants import TEMPLATES_DIR
|
||||
from nucypher.crypto.powers import SigningPower, TransactingPower
|
||||
from nucypher.keystore.threading import ThreadedSession
|
||||
from nucypher.datastore.threading import ThreadedSession
|
||||
|
||||
|
||||
class Felix(Character, NucypherTokenActor):
|
||||
|
|
|
@ -57,8 +57,8 @@ from nucypher.crypto.constants import PUBLIC_KEY_LENGTH, PUBLIC_ADDRESS_LENGTH
|
|||
from nucypher.crypto.kits import UmbralMessageKit
|
||||
from nucypher.crypto.powers import SigningPower, DecryptingPower, DelegatingPower, TransactingPower, PowerUpError
|
||||
from nucypher.crypto.signing import InvalidSignature
|
||||
from nucypher.keystore.keypairs import HostingKeypair
|
||||
from nucypher.keystore.threading import ThreadedSession
|
||||
from nucypher.datastore.keypairs import HostingKeypair
|
||||
from nucypher.datastore.threading import ThreadedSession
|
||||
from nucypher.network.exceptions import NodeSeemsToBeDown
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
from nucypher.network.nicknames import nickname_from_seed
|
||||
|
|
|
@ -26,8 +26,8 @@ from umbral import pre
|
|||
from umbral.keys import UmbralPublicKey, UmbralPrivateKey, UmbralKeyingMaterial
|
||||
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.keystore import keypairs
|
||||
from nucypher.keystore.keypairs import SigningKeypair, DecryptingKeypair
|
||||
from nucypher.datastore import keypairs
|
||||
from nucypher.datastore.keypairs import SigningKeypair, DecryptingKeypair
|
||||
|
||||
|
||||
class PowerUpError(TypeError):
|
||||
|
@ -49,7 +49,7 @@ class NoTransactingPower(PowerUpError):
|
|||
class CryptoPower(object):
|
||||
def __init__(self, power_ups: list = None) -> None:
|
||||
self.__power_ups = {} # type: dict
|
||||
# TODO: The keys here will actually be IDs for looking up in a KeyStore.
|
||||
# TODO: The keys here will actually be IDs for looking up in a Datastore.
|
||||
self.public_keys = {} # type: dict
|
||||
|
||||
if power_ups is not None:
|
||||
|
|
|
@ -26,17 +26,17 @@ from umbral.kfrags import KFrag
|
|||
|
||||
from nucypher.crypto.signing import Signature
|
||||
from nucypher.crypto.utils import fingerprint_from_key
|
||||
from nucypher.keystore.db.models import Key, PolicyArrangement, Workorder
|
||||
from nucypher.datastore.db.models import Key, PolicyArrangement, Workorder
|
||||
|
||||
|
||||
class NotFound(Exception):
|
||||
"""
|
||||
Exception class for KeyStore calls for objects that don't exist.
|
||||
Exception class for Datastore calls for objects that don't exist.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class KeyStore(object):
|
||||
class Datastore:
|
||||
"""
|
||||
A storage class of persistent cryptographic entities for use by Ursula.
|
||||
"""
|
||||
|
@ -44,7 +44,7 @@ class KeyStore(object):
|
|||
|
||||
def __init__(self, sqlalchemy_engine=None) -> None:
|
||||
"""
|
||||
Initalizes a KeyStore object.
|
||||
Initalizes a Datastore object.
|
||||
|
||||
:param sqlalchemy_engine: SQLAlchemy engine object to create session
|
||||
"""
|
||||
|
@ -88,7 +88,7 @@ class KeyStore(object):
|
|||
|
||||
def get_key(self, fingerprint: bytes, session=None) -> UmbralPublicKey:
|
||||
"""
|
||||
Returns a key from the KeyStore.
|
||||
Returns a key from the Datastore.
|
||||
|
||||
:param fingerprint: Fingerprint, in bytes, of key to return
|
||||
|
||||
|
@ -105,7 +105,7 @@ class KeyStore(object):
|
|||
|
||||
def del_key(self, fingerprint: bytes, session=None):
|
||||
"""
|
||||
Deletes a key from the KeyStore.
|
||||
Deletes a key from the Datastore.
|
||||
|
||||
:param fingerprint: Fingerprint of key to delete
|
||||
"""
|
|
@ -22,7 +22,7 @@ from sqlalchemy import (
|
|||
from sqlalchemy.orm import relationship
|
||||
|
||||
from nucypher.crypto.utils import fingerprint_from_key
|
||||
from nucypher.keystore.db import Base
|
||||
from nucypher.datastore.db import Base
|
||||
|
||||
|
||||
class Key(Base):
|
|
@ -35,9 +35,9 @@ from nucypher.crypto.kits import UmbralMessageKit
|
|||
from nucypher.crypto.powers import KeyPairBasedPower, PowerUpError
|
||||
from nucypher.crypto.signing import InvalidSignature
|
||||
from nucypher.crypto.utils import canonical_address_from_umbral_key
|
||||
from nucypher.keystore.keypairs import HostingKeypair
|
||||
from nucypher.keystore.keystore import NotFound
|
||||
from nucypher.keystore.threading import ThreadedSession
|
||||
from nucypher.datastore.keypairs import HostingKeypair
|
||||
from nucypher.datastore.datastore import NotFound
|
||||
from nucypher.datastore.threading import ThreadedSession
|
||||
from nucypher.network import LEARNING_LOOP_VERSION
|
||||
from nucypher.network.exceptions import NodeSeemsToBeDown
|
||||
from nucypher.network.protocols import InterfaceInfo
|
||||
|
@ -86,8 +86,8 @@ def make_rest_app(
|
|||
|
||||
forgetful_node_storage = ForgetfulNodeStorage(federated_only=this_node.federated_only)
|
||||
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
from nucypher.datastore import datastore
|
||||
from nucypher.datastore.db import Base
|
||||
from sqlalchemy.engine import create_engine
|
||||
|
||||
log.info("Starting datastore {}".format(db_filepath))
|
||||
|
@ -101,7 +101,7 @@ def make_rest_app(
|
|||
engine = create_engine(db_uri)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
datastore = keystore.KeyStore(engine)
|
||||
datastore = datastore.Datastore(engine)
|
||||
db_engine = engine
|
||||
|
||||
from nucypher.characters.lawful import Alice, Ursula
|
||||
|
|
|
@ -21,7 +21,7 @@ import maya
|
|||
import pytest
|
||||
|
||||
from nucypher.characters.unlawful import Amonia
|
||||
from nucypher.keystore.db.models import PolicyArrangement
|
||||
from nucypher.datastore.db.models import PolicyArrangement
|
||||
|
||||
|
||||
def test_policy_simple_sinpa(blockchain_ursulas, blockchain_alice, blockchain_bob, agency, testerchain):
|
||||
|
|
|
@ -17,61 +17,61 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
from nucypher.keystore import keystore, keypairs
|
||||
from nucypher.datastore import datastore, keypairs
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('testerchain')
|
||||
def test_key_sqlite_keystore(test_keystore, federated_bob):
|
||||
def test_key_sqlite_datastore(test_datastore, federated_bob):
|
||||
|
||||
# Test add pubkey
|
||||
test_keystore.add_key(federated_bob.stamp, is_signing=True)
|
||||
test_datastore.add_key(federated_bob.stamp, is_signing=True)
|
||||
|
||||
# Test get pubkey
|
||||
query_key = test_keystore.get_key(federated_bob.stamp.fingerprint())
|
||||
query_key = test_datastore.get_key(federated_bob.stamp.fingerprint())
|
||||
assert bytes(federated_bob.stamp) == bytes(query_key)
|
||||
|
||||
# Test del pubkey
|
||||
test_keystore.del_key(federated_bob.stamp.fingerprint())
|
||||
with pytest.raises(keystore.NotFound):
|
||||
del_key = test_keystore.get_key(federated_bob.stamp.fingerprint())
|
||||
test_datastore.del_key(federated_bob.stamp.fingerprint())
|
||||
with pytest.raises(datastore.NotFound):
|
||||
del_key = test_datastore.get_key(federated_bob.stamp.fingerprint())
|
||||
|
||||
|
||||
def test_policy_arrangement_sqlite_keystore(test_keystore):
|
||||
def test_policy_arrangement_sqlite_datastore(test_datastore):
|
||||
alice_keypair_sig = keypairs.SigningKeypair(generate_keys_if_needed=True)
|
||||
|
||||
arrangement_id = b'test'
|
||||
|
||||
# Test add PolicyArrangement
|
||||
new_arrangement = test_keystore.add_policy_arrangement(
|
||||
new_arrangement = test_datastore.add_policy_arrangement(
|
||||
datetime.utcnow(), b'test', arrangement_id, alice_verifying_key=alice_keypair_sig.pubkey,
|
||||
alice_signature=b'test'
|
||||
)
|
||||
|
||||
# Test get PolicyArrangement
|
||||
query_arrangement = test_keystore.get_policy_arrangement(arrangement_id)
|
||||
query_arrangement = test_datastore.get_policy_arrangement(arrangement_id)
|
||||
assert new_arrangement == query_arrangement
|
||||
|
||||
# Test del PolicyArrangement
|
||||
test_keystore.del_policy_arrangement(arrangement_id)
|
||||
with pytest.raises(keystore.NotFound):
|
||||
del_key = test_keystore.get_policy_arrangement(arrangement_id)
|
||||
test_datastore.del_policy_arrangement(arrangement_id)
|
||||
with pytest.raises(datastore.NotFound):
|
||||
del_key = test_datastore.get_policy_arrangement(arrangement_id)
|
||||
|
||||
|
||||
def test_workorder_sqlite_keystore(test_keystore):
|
||||
def test_workorder_sqlite_datastore(test_datastore):
|
||||
bob_keypair_sig1 = keypairs.SigningKeypair(generate_keys_if_needed=True)
|
||||
bob_keypair_sig2 = keypairs.SigningKeypair(generate_keys_if_needed=True)
|
||||
|
||||
arrangement_id = b'test'
|
||||
|
||||
# Test add workorder
|
||||
new_workorder1 = test_keystore.save_workorder(bob_keypair_sig1.pubkey, b'test0', arrangement_id)
|
||||
new_workorder2 = test_keystore.save_workorder(bob_keypair_sig2.pubkey, b'test1', arrangement_id)
|
||||
new_workorder1 = test_datastore.save_workorder(bob_keypair_sig1.pubkey, b'test0', arrangement_id)
|
||||
new_workorder2 = test_datastore.save_workorder(bob_keypair_sig2.pubkey, b'test1', arrangement_id)
|
||||
|
||||
# Test get workorder
|
||||
query_workorders = test_keystore.get_workorders(arrangement_id)
|
||||
query_workorders = test_datastore.get_workorders(arrangement_id)
|
||||
assert {new_workorder1, new_workorder2}.issubset(query_workorders)
|
||||
|
||||
# Test del workorder
|
||||
deleted = test_keystore.del_workorders(arrangement_id)
|
||||
deleted = test_datastore.del_workorders(arrangement_id)
|
||||
assert deleted > 0
|
||||
assert len(test_keystore.get_workorders(arrangement_id)) == 0
|
||||
assert len(test_datastore.get_workorders(arrangement_id)) == 0
|
|
@ -19,7 +19,7 @@ import sha3
|
|||
from constant_sorrow.constants import PUBLIC_ONLY
|
||||
from umbral.keys import UmbralPrivateKey
|
||||
|
||||
from nucypher.keystore import keypairs
|
||||
from nucypher.datastore import keypairs
|
||||
|
||||
|
||||
def test_gen_keypair_if_needed():
|
|
@ -66,8 +66,8 @@ from nucypher.config.characters import (
|
|||
)
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.crypto.utils import canonical_address_from_umbral_key
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
from nucypher.datastore import datastore
|
||||
from nucypher.datastore.db import Base
|
||||
from nucypher.policy.collections import IndisputableEvidence, WorkOrder
|
||||
from nucypher.utilities.logging import GlobalLoggerSettings
|
||||
from nucypher.utilities.sandbox.blockchain import token_airdrop, TesterBlockchain
|
||||
|
@ -123,11 +123,11 @@ def temp_dir_path():
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_keystore():
|
||||
def test_datastore():
|
||||
engine = create_engine('sqlite:///:memory:')
|
||||
Base.metadata.create_all(engine)
|
||||
test_keystore = keystore.KeyStore(engine)
|
||||
yield test_keystore
|
||||
test_datastore = datastore.Datastore(engine)
|
||||
yield test_datastore
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
|
|
@ -482,7 +482,7 @@ class NotARestApp:
|
|||
|
||||
def actual_rest_app(self):
|
||||
if self._actual_rest_app is None:
|
||||
self._actual_rest_app, _keystore = make_rest_app(db_filepath="no datastore",
|
||||
self._actual_rest_app, _datastore = make_rest_app(db_filepath="no datastore",
|
||||
this_node=self.this_node,
|
||||
serving_domains=(None,))
|
||||
_new_view_functions = self._ViewFunctions(self._actual_rest_app.view_functions)
|
||||
|
@ -522,7 +522,7 @@ mock_metadata_validation = patch("nucypher.network.nodes.Teacher.validate_metada
|
|||
|
||||
@contextmanager
|
||||
def mock_secret_source(*args, **kwargs):
|
||||
with patch("nucypher.keystore.keypairs.Keypair._private_key_source", new=lambda *args, **kwargs: NotAPrivateKey()):
|
||||
with patch("nucypher.datastore.keypairs.Keypair._private_key_source", new=lambda *args, **kwargs: NotAPrivateKey()):
|
||||
yield
|
||||
NotAPublicKey.reset()
|
||||
|
||||
|
|
Loading…
Reference in New Issue