mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Moves EncryptedBlob to common
This commit is contained in:
@@ -11,7 +11,7 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from apps.cli import config, LOG_PREFIX
|
from apps.cli import config, LOG_PREFIX
|
||||||
from apps.cli.help import help_add_appointment, help_get_appointment
|
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
|
import common.cryptographer
|
||||||
from common import constants
|
from common import constants
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
import struct
|
import struct
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
from pisa.encrypted_blob import EncryptedBlob
|
from common.encrypted_blob import EncryptedBlob
|
||||||
|
|
||||||
|
|
||||||
class Appointment:
|
class Appointment:
|
||||||
@@ -16,7 +16,7 @@ class Appointment:
|
|||||||
end_time (:mod:`int`): The block height where the tower will stop watching for breaches.
|
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
|
to_self_delay (:mod:`int`): The ``to_self_delay`` encoded in the ``csv`` of the ``htlc`` that this appointment is
|
||||||
covering.
|
covering.
|
||||||
encrypted_blob (:obj:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>`): An ``EncryptedBlob`` object
|
encrypted_blob (:obj:`EncryptedBlob <common.encrypted_blob.EncryptedBlob>`): An ``EncryptedBlob`` object
|
||||||
containing an encrypted penalty transaction. The tower will decrypt it and broadcast the penalty transaction
|
containing an encrypted penalty transaction. The tower will decrypt it and broadcast the penalty transaction
|
||||||
upon seeing a breach on the blockchain.
|
upon seeing a breach on the blockchain.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ class Cryptographer:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def encrypt(blob, secret, rtype="str"):
|
def encrypt(blob, secret, rtype="str"):
|
||||||
"""
|
"""
|
||||||
Encrypts a given :mod:`Blob <apps.cli.blob.Blob>` data using ``CHACHA20POLY1305``.
|
Encrypts a given :mod:`Blob <common.cli.blob.Blob>` data using ``CHACHA20POLY1305``.
|
||||||
|
|
||||||
``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``.
|
``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
blob (:mod:`Blob <apps.cli.blob.Blob>`): a ``Blob`` object containing a raw penalty transaction.
|
blob (:mod:`Blob <common.cli.blob.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.
|
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'``.
|
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
|
# ToDo: #20-test-tx-decrypting-edge-cases
|
||||||
def decrypt(encrypted_blob, secret, rtype="str"):
|
def decrypt(encrypted_blob, secret, rtype="str"):
|
||||||
"""
|
"""
|
||||||
Decrypts a given :mod:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>` using ``CHACHA20POLY1305``.
|
Decrypts a given :mod:`EncryptedBlob <common.encrypted_blob.EncryptedBlob>` using ``CHACHA20POLY1305``.
|
||||||
|
|
||||||
``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``.
|
``SHA256(secret)`` is used as ``key``, and ``0 (12-byte)`` as ``iv``.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
encrypted_blob(:mod:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>`): an ``EncryptedBlob`` potentially
|
encrypted_blob(:mod:`EncryptedBlob <comnmon.encrypted_blob.EncryptedBlob>`): an ``EncryptedBlob`` potentially
|
||||||
containing a penalty transaction.
|
containing a penalty transaction.
|
||||||
secret (:mod:`str`): a value to used to derive the decryption key. Should be the dispute txid.
|
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'``.
|
rtype(:mod:`str`): the return type for the decrypted value. Can be either ``'str'`` or ``'bytes'``.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class Watcher:
|
|||||||
|
|
||||||
The :class:`Watcher` keeps track of the accepted appointments in ``appointments`` and, for new received block,
|
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
|
checks if any breach has happened by comparing the txids with the appointment locators. If a breach is seen, the
|
||||||
:obj:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>` of the corresponding appointment is decrypted and the data
|
:obj:`EncryptedBlob <common.encrypted_blob.EncryptedBlob>` of the corresponding appointment is decrypted and the data
|
||||||
is passed to the :obj:`Responder <pisa.responder.Responder>`.
|
is passed to the :obj:`Responder <pisa.responder.Responder>`.
|
||||||
|
|
||||||
If an appointment reaches its end with no breach, the data is simply deleted.
|
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.
|
the blockchain (``do_watch``) until ``appointments`` is empty.
|
||||||
|
|
||||||
Once a breach is seen on the blockchain, the :obj:`Watcher` will decrypt the corresponding
|
Once a breach is seen on the blockchain, the :obj:`Watcher` will decrypt the corresponding
|
||||||
:obj:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>` and pass the information to the
|
:obj:`EncryptedBlob <common.encrypted_blob.EncryptedBlob>` and pass the information to the
|
||||||
:obj:`Responder <pisa.responder.Responder>`.
|
:obj:`Responder <pisa.responder.Responder>`.
|
||||||
|
|
||||||
The tower may store multiple appointments with the same ``locator`` to avoid DoS attacks based on data
|
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.
|
Filters what of the found breaches contain valid transaction data.
|
||||||
|
|
||||||
The :obj:`Watcher` cannot if a given :obj:`EncryptedBlob <pisa.encrypted_blob.EncryptedBlob>` contains a valid
|
The :obj:`Watcher` cannot if a given :obj:`EncryptedBlob <common.encrypted_blob.EncryptedBlob>` contains a valid
|
||||||
transaction until a breach if seen. Blobs that contain arbitrary data are dropped and not sent to the
|
transaction until a breach if seen. Blobs that contain arbitrary data are dropped and not sent to the
|
||||||
:obj:`Responder <pisa.responder.Responder>`.
|
:obj:`Responder <pisa.responder.Responder>`.
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from common.tools import compute_locator
|
|||||||
from common.appointment import Appointment
|
from common.appointment import Appointment
|
||||||
from common.cryptographer import Cryptographer
|
from common.cryptographer import Cryptographer
|
||||||
|
|
||||||
from apps.cli.blob import Blob
|
from common.blob import Blob
|
||||||
import apps.cli.wt_cli as wt_cli
|
import apps.cli.wt_cli as wt_cli
|
||||||
from test.apps.cli.unit.conftest import get_random_value_hex
|
from test.apps.cli.unit.conftest import get_random_value_hex
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import binascii
|
|||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
from common.appointment import Appointment
|
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
|
from test.pisa.unit.conftest import get_random_value_hex
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from binascii import unhexlify
|
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
|
from test.pisa.unit.conftest import get_random_value_hex
|
||||||
|
|
||||||
|
|
||||||
@@ -5,10 +5,10 @@ from cryptography.hazmat.primitives.asymmetric import ec
|
|||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
|
|
||||||
import common.cryptographer
|
import common.cryptographer
|
||||||
from apps.cli.blob import Blob
|
from common.blob import Blob
|
||||||
from common.logger import Logger
|
from common.logger import Logger
|
||||||
from common.cryptographer import Cryptographer
|
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
|
from test.common.unit.conftest import get_random_value_hex
|
||||||
|
|
||||||
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
||||||
|
|||||||
@@ -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
|
from test.pisa.unit.conftest import get_random_value_hex
|
||||||
|
|
||||||
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
import binascii
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from riemann.tx import Tx
|
from riemann.tx import Tx
|
||||||
|
|
||||||
from pisa import config
|
from pisa import config
|
||||||
from pisa import HOST, PORT
|
from pisa import HOST, PORT
|
||||||
from apps.cli import wt_cli
|
from apps.cli import wt_cli
|
||||||
from apps.cli.blob import Blob
|
from common.blob import Blob
|
||||||
from apps.cli import config as cli_conf
|
|
||||||
|
|
||||||
import common.cryptographer
|
import common.cryptographer
|
||||||
from common.logger import Logger
|
from common.logger import Logger
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from cryptography.hazmat.backends import default_backend
|
|||||||
from cryptography.hazmat.primitives.asymmetric import ec
|
from cryptography.hazmat.primitives.asymmetric import ec
|
||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
|
|
||||||
from apps.cli.blob import Blob
|
from common.blob import Blob
|
||||||
from pisa.responder import TransactionTracker
|
from pisa.responder import TransactionTracker
|
||||||
from pisa.tools import bitcoin_cli
|
from pisa.tools import bitcoin_cli
|
||||||
from pisa.db_manager import DBManager
|
from pisa.db_manager import DBManager
|
||||||
|
|||||||
Reference in New Issue
Block a user