Skip to content

Commit 884fd86

Browse files
committed
Apply checkpoint function;
1 parent 3703207 commit 884fd86

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

test.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,41 @@
3939
,"signature" / Bytes(64)
4040
);
4141

42+
'''
43+
------------- 4-bytes / 32 bits -------------
44+
+------------++-------------++--------------+
45+
|SECTION TYPE||SECTION FLAGS||SECTION LENGTH|
46+
|(UINT8=0xFF)|| (UINT8) || (UINT16) |
47+
+------------++-------------++--------------+
48+
------------ 16-bytes / 128 bits ------------
49+
+------------------++-----------------------+
50+
| TAI64N Timestamp || Random Nonce |
51+
| (12 bytes) || (UINT32) |
52+
+------------------++-----------------------+
53+
------------ 32-bytes / 256-bits ------------
54+
+-------------------------------------------+
55+
| SIGNER PUBLIC KEY |
56+
| Ed25519(256-bits) |
57+
+-------------------------------------------+
58+
------------ 64-bytes / 512-bits ------------
59+
+-------------------------------------------+
60+
| Signature of file up to this point |
61+
| Ed25519(512-bits) |
62+
+-------------------------------------------+
63+
'''
64+
65+
_SN_SECTION_CHECKPOINT = Struct(
66+
"header" / Struct(
67+
"type" / Int8ub
68+
,"flags" / Int8ub
69+
,"length" / Const(112, Int16ub)
70+
)
71+
,"timestamp" / Bytes(12)
72+
,"nonce" / Bytes(4)
73+
,"publickey" / Bytes(32)
74+
,"checkpoint_sig" / Bytes(64)
75+
)
76+
4277
_SIX_MONTH_IN_SECONDS = 15778463
4378

4479
'''
@@ -113,6 +148,18 @@ def sn__generate_init():
113148
return {"data": data + signature.digest(), "signature": signature.hexdigest()}
114149

115150

151+
def sn__checkpoint_apply(blob, skpk):
152+
checkpoint = blob + _SN_SECTION_CHECKPOINT.build(dict(
153+
header=dict(type=0xFF, flags=0x0)
154+
,timestamp="*"*12
155+
,nonce=os.urandom(4)
156+
,publickey=skpk[1].to_bytes()
157+
,checkpoint_sig="\x00"*64
158+
))
159+
160+
signature = skpk[0].sign( checkpoint[:-64] )
161+
return checkpoint[:-64] + signature
162+
116163
snote = sn__generate_init()
117164

118165
print len(snote['data'])
@@ -121,5 +168,6 @@ def sn__generate_init():
121168

122169
print _SN_SECTION_INIT.parse( snote['data'] )
123170

124-
171+
print "CHECKPOINT"
172+
print repr( sn__checkpoint_apply(snote['data'], KEYPAIR__CENTRAL_MINT) )
125173

0 commit comments

Comments
 (0)