mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-01 12:44:25 +01:00
Moves EncryptedBlob to common
This commit is contained in:
@@ -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 <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
|
||||
upon seeing a breach on the blockchain.
|
||||
"""
|
||||
|
||||
9
common/blob.py
Normal file
9
common/blob.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import re
|
||||
|
||||
|
||||
class Blob:
|
||||
def __init__(self, data):
|
||||
if type(data) is not str or re.search(r"^[0-9A-Fa-f]+$", data) is None:
|
||||
raise ValueError("Non-Hex character found in transaction.")
|
||||
|
||||
self.data = data
|
||||
@@ -49,12 +49,12 @@ class Cryptographer:
|
||||
@staticmethod
|
||||
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``.
|
||||
|
||||
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.
|
||||
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 <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``.
|
||||
|
||||
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.
|
||||
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'``.
|
||||
|
||||
6
common/encrypted_blob.py
Normal file
6
common/encrypted_blob.py
Normal file
@@ -0,0 +1,6 @@
|
||||
class EncryptedBlob:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, EncryptedBlob) and self.data == other.data
|
||||
Reference in New Issue
Block a user