diff --git a/examples/andytoshi.ots b/examples/andytoshi.ots index a2ccc3d..15b9c5c 100644 Binary files a/examples/andytoshi.ots and b/examples/andytoshi.ots differ diff --git a/opentimestamps/core/secp256k1.py b/opentimestamps/core/secp256k1.py index e99b8dc..d9d5194 100644 --- a/opentimestamps/core/secp256k1.py +++ b/opentimestamps/core/secp256k1.py @@ -11,19 +11,29 @@ import hashlib -from opentimestamps.core.op import BinaryOp, MsgValueError +from opentimestamps.core.op import UnaryOp, MsgValueError -@BinaryOp._register_op -class OpSecp256k1Commitment(BinaryOp): - """Execute the map commit -> [P + sha256(P||commit)G]_x for a given secp256k1 point P""" +@UnaryOp._register_op +class OpSecp256k1Commitment(UnaryOp): + """Map (P || commit) -> [P + sha256(P||commit)G]_x for a given secp256k1 point P + + This is a unary op rather than a binary op to allow timestamps to also + timestamp the point itself; in the event of an ECC break this might be + relevant. Such a break would not affect the integrity of the commitment, + but knowledge of the underlying key may be interesting in its own right. + """ TAG = b'\x09' TAG_NAME = 'secp256k1commitment' def _do_op_call(self, msg): + if len(msg) < 33: + raise MsgValueError("Missing secp256k1 point") + + pt = Point.decode(msg[0:33]) + hasher = hashlib.sha256() - pt = Point.decode(self[0]) hasher.update(pt.encode()) - hasher.update(msg) + hasher.update(msg[33:]) tweak = int.from_bytes(hasher.digest(), 'big') tweak_pt = SECP256K1_GEN.scalar_mul(tweak) final_pt = pt.add(tweak_pt) diff --git a/opentimestamps/tests/core/test_secp256k1.py b/opentimestamps/tests/core/test_secp256k1.py index 6eaeed5..1b3de11 100644 --- a/opentimestamps/tests/core/test_secp256k1.py +++ b/opentimestamps/tests/core/test_secp256k1.py @@ -104,5 +104,5 @@ def test_op_signtocontract(self): pt_encode = binascii.unhexlify("0308aec434612f56df3f02c4e678260424415882ebd3efc16d52e3f9c1e39afdb0") msg = hashlib.sha256("This is andytoshi on 2017-05-16 21:30 UTC".encode()).digest() result = binascii.unhexlify("d386ef692770fcecad43362cf541858662e4ebe31d3ad04d196f94168897947a") - self.assertEqual(OpSecp256k1Commitment(pt_encode)(msg), result) + self.assertEqual(OpSecp256k1Commitment()(pt_encode + msg), result)