diff --git a/apps/cli/wt_cli.py b/apps/cli/wt_cli.py index 5f7f2d5..0ecc013 100644 --- a/apps/cli/wt_cli.py +++ b/apps/cli/wt_cli.py @@ -11,7 +11,7 @@ from uuid import uuid4 from apps.cli import config, LOG_PREFIX from apps.cli.help import help_add_appointment, help_get_appointment -from apps.cli.blob import Blob +from common.blob import Blob import common.cryptographer from common import constants diff --git a/common/appointment.py b/common/appointment.py index 7b21471..e376668 100644 --- a/common/appointment.py +++ b/common/appointment.py @@ -2,7 +2,7 @@ import json import struct from binascii import unhexlify -from pisa.encrypted_blob import EncryptedBlob +from common.encrypted_blob import EncryptedBlob class Appointment: @@ -16,7 +16,7 @@ class Appointment: end_time (:mod:`int`): The block height where the tower will stop watching for breaches. to_self_delay (:mod:`int`): The ``to_self_delay`` encoded in the ``csv`` of the ``htlc`` that this appointment is covering. - encrypted_blob (:obj:`EncryptedBlob `): An ``EncryptedBlob`` object + encrypted_blob (:obj:`EncryptedBlob `): An ``EncryptedBlob`` object containing an encrypted penalty transaction. The tower will decrypt it and broadcast the penalty transaction upon seeing a breach on the blockchain. """ diff --git a/apps/cli/blob.py b/common/blob.py similarity index 100% rename from apps/cli/blob.py rename to common/blob.py diff --git a/common/cryptographer.py b/common/cryptographer.py index 6519620..8cac45f 100644 --- a/common/cryptographer.py +++ b/common/cryptographer.py @@ -49,12 +49,12 @@ class Cryptographer: @staticmethod def encrypt(blob, secret, rtype="str"): """ - Encrypts a given :mod:`Blob ` data using ``CHACHA20POLY1305``. + Encrypts a given :mod:`Blob ` data using ``CHACHA20POLY1305``. ``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``. Args: - blob (:mod:`Blob `): a ``Blob`` object containing a raw penalty transaction. + blob (:mod:`Blob `): a ``Blob`` object containing a raw penalty transaction. secret (:mod:`str`): a value to used to derive the encryption key. Should be the dispute txid. rtype(:mod:`str`): the return type for the encrypted value. Can be either ``'str'`` or ``'bytes'``. @@ -93,12 +93,12 @@ class Cryptographer: # ToDo: #20-test-tx-decrypting-edge-cases def decrypt(encrypted_blob, secret, rtype="str"): """ - Decrypts a given :mod:`EncryptedBlob ` using ``CHACHA20POLY1305``. + Decrypts a given :mod:`EncryptedBlob ` using ``CHACHA20POLY1305``. ``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``. Args: - encrypted_blob(:mod:`EncryptedBlob `): an ``EncryptedBlob`` potentially + encrypted_blob(:mod:`EncryptedBlob `): an ``EncryptedBlob`` potentially containing a penalty transaction. secret (:mod:`str`): a value to used to derive the decryption key. Should be the dispute txid. rtype(:mod:`str`): the return type for the decrypted value. Can be either ``'str'`` or ``'bytes'``. diff --git a/pisa/encrypted_blob.py b/common/encrypted_blob.py similarity index 100% rename from pisa/encrypted_blob.py rename to common/encrypted_blob.py diff --git a/pisa/watcher.py b/pisa/watcher.py index 281de92..c06bee3 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -24,7 +24,7 @@ class Watcher: The :class:`Watcher` keeps track of the accepted appointments in ``appointments`` and, for new received block, checks if any breach has happened by comparing the txids with the appointment locators. If a breach is seen, the - :obj:`EncryptedBlob ` of the corresponding appointment is decrypted and the data + :obj:`EncryptedBlob ` of the corresponding appointment is decrypted and the data is passed to the :obj:`Responder `. If an appointment reaches its end with no breach, the data is simply deleted. @@ -81,7 +81,7 @@ class Watcher: the blockchain (``do_watch``) until ``appointments`` is empty. Once a breach is seen on the blockchain, the :obj:`Watcher` will decrypt the corresponding - :obj:`EncryptedBlob ` and pass the information to the + :obj:`EncryptedBlob ` and pass the information to the :obj:`Responder `. The tower may store multiple appointments with the same ``locator`` to avoid DoS attacks based on data @@ -232,7 +232,7 @@ class Watcher: """ Filters what of the found breaches contain valid transaction data. - The :obj:`Watcher` cannot if a given :obj:`EncryptedBlob ` contains a valid + The :obj:`Watcher` cannot if a given :obj:`EncryptedBlob ` contains a valid transaction until a breach if seen. Blobs that contain arbitrary data are dropped and not sent to the :obj:`Responder `. diff --git a/test/apps/cli/unit/test_wt_cli.py b/test/apps/cli/unit/test_wt_cli.py index b05164e..3545eef 100644 --- a/test/apps/cli/unit/test_wt_cli.py +++ b/test/apps/cli/unit/test_wt_cli.py @@ -14,7 +14,7 @@ from common.tools import compute_locator from common.appointment import Appointment from common.cryptographer import Cryptographer -from apps.cli.blob import Blob +from common.blob import Blob import apps.cli.wt_cli as wt_cli from test.apps.cli.unit.conftest import get_random_value_hex diff --git a/test/common/unit/test_appointment.py b/test/common/unit/test_appointment.py index 8087138..f83538f 100644 --- a/test/common/unit/test_appointment.py +++ b/test/common/unit/test_appointment.py @@ -4,7 +4,7 @@ import binascii from pytest import fixture from common.appointment import Appointment -from pisa.encrypted_blob import EncryptedBlob +from common.encrypted_blob import EncryptedBlob from test.pisa.unit.conftest import get_random_value_hex diff --git a/test/pisa/unit/test_blob.py b/test/common/unit/test_blob.py similarity index 92% rename from test/pisa/unit/test_blob.py rename to test/common/unit/test_blob.py index a12de8b..7172330 100644 --- a/test/pisa/unit/test_blob.py +++ b/test/common/unit/test_blob.py @@ -1,6 +1,6 @@ from binascii import unhexlify -from apps.cli.blob import Blob +from common.blob import Blob from test.pisa.unit.conftest import get_random_value_hex diff --git a/test/common/unit/test_cryptographer.py b/test/common/unit/test_cryptographer.py index 728e1fd..02b2727 100644 --- a/test/common/unit/test_cryptographer.py +++ b/test/common/unit/test_cryptographer.py @@ -5,10 +5,10 @@ from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import serialization import common.cryptographer -from apps.cli.blob import Blob +from common.blob import Blob from common.logger import Logger from common.cryptographer import Cryptographer -from pisa.encrypted_blob import EncryptedBlob +from common.encrypted_blob import EncryptedBlob from test.common.unit.conftest import get_random_value_hex common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="") diff --git a/test/pisa/unit/test_encrypted_blob.py b/test/common/unit/test_encrypted_blob.py similarity index 89% rename from test/pisa/unit/test_encrypted_blob.py rename to test/common/unit/test_encrypted_blob.py index 64add70..b977dbc 100644 --- a/test/pisa/unit/test_encrypted_blob.py +++ b/test/common/unit/test_encrypted_blob.py @@ -1,4 +1,4 @@ -from pisa.encrypted_blob import EncryptedBlob +from common.encrypted_blob import EncryptedBlob from test.pisa.unit.conftest import get_random_value_hex diff --git a/test/pisa/e2e/test_basic_e2e.py b/test/pisa/e2e/test_basic_e2e.py index 3124e7c..8fea9c7 100644 --- a/test/pisa/e2e/test_basic_e2e.py +++ b/test/pisa/e2e/test_basic_e2e.py @@ -1,13 +1,11 @@ import json -import binascii from time import sleep from riemann.tx import Tx from pisa import config from pisa import HOST, PORT from apps.cli import wt_cli -from apps.cli.blob import Blob -from apps.cli import config as cli_conf +from common.blob import Blob import common.cryptographer from common.logger import Logger diff --git a/test/pisa/unit/conftest.py b/test/pisa/unit/conftest.py index 6766faa..28d282d 100644 --- a/test/pisa/unit/conftest.py +++ b/test/pisa/unit/conftest.py @@ -11,7 +11,7 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import serialization -from apps.cli.blob import Blob +from common.blob import Blob from pisa.responder import TransactionTracker from pisa.tools import bitcoin_cli from pisa.db_manager import DBManager