File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -347,3 +347,6 @@ def _do_op_call(self, msg):
347347 r = sha3 .keccak_256 (bytes (msg )).digest ()
348348 assert len (r ) == self .DIGEST_LENGTH
349349 return r
350+
351+ from opentimestamps .core .s2c import OpSignToContract
352+
Original file line number Diff line number Diff line change 99# modified, propagated, or distributed except according to the terms contained
1010# in the LICENSE file.
1111
12+ import hashlib
13+
14+ from opentimestamps .core .op import BinaryOp , MsgValueError
15+
16+ @BinaryOp ._register_op
17+ class OpSignToContract (BinaryOp ):
18+ """Execute the map commit -> [P + sha256(P||commit)G]_x for a given secp256k1 point P"""
19+ TAG = b'\x09 '
20+ TAG_NAME = 'signtocontract'
21+
22+ def _do_op_call (self , msg ):
23+ hasher = hashlib .sha256 ()
24+ pt = Point .decode (self [0 ])
25+ hasher .update (pt .encode ())
26+ hasher .update (msg )
27+ tweak = int .from_bytes (hasher .digest (), 'big' )
28+ tweak_pt = SECP256K1_GEN .scalar_mul (tweak )
29+ final_pt = pt .add (tweak_pt )
30+ return final_pt .x .to_bytes (32 , 'big' )
31+
32+
1233## What follows is a lot of inefficient but explicit secp256k1 math
1334class Point (object ):
1435 inf = True
Original file line number Diff line number Diff line change 99# modified, propagated, or distributed except according to the terms contained
1010# in the LICENSE file.
1111
12+ import hashlib
1213import binascii
1314import unittest
1415
@@ -20,7 +21,7 @@ def test_point_rt(self):
2021 gen = SECP256K1_GEN
2122 encode = gen .encode ()
2223 self .assertEqual (encode , binascii .unhexlify ("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" ))
23- gen2 = Point () .decode (encode )
24+ gen2 = Point .decode (encode )
2425 self .assertEqual (gen , gen2 )
2526
2627 def test_pinv (self ):
@@ -99,3 +100,9 @@ def test_scalar_mul(self):
99100 self .assertEqual (p2 .scalar_mul (- 1 ), np2 )
100101 self .assertEqual (p1 .scalar_mul (3 ), p3 )
101102
103+ def test_op_signtocontract (self ):
104+ pt_encode = binascii .unhexlify ("0308aec434612f56df3f02c4e678260424415882ebd3efc16d52e3f9c1e39afdb0" )
105+ msg = hashlib .sha256 ("This is andytoshi on 2017-05-16 21:30 UTC" .encode ()).digest ()
106+ result = binascii .unhexlify ("d386ef692770fcecad43362cf541858662e4ebe31d3ad04d196f94168897947a" )
107+ self .assertEqual (OpSignToContract (pt_encode )(msg ), result )
108+
You can’t perform that action at this time.
0 commit comments