Skip to content

Commit 3703207

Browse files
committed
use construct library for easier parsing;
1 parent 37a5c9d commit 3703207

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ name = "pypi"
1313

1414
"ed25519" = "*"
1515
"pyblake2" = "*"
16+
construct = "*"

test.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44
import time, tai64n
55
from pyblake2 import blake2b
66

7+
from construct import Struct, Const, Int8ub, Bytes, Int16ub
8+
9+
_SN_VERSION = Struct(
10+
"magic" / Const(b"SN")
11+
, "version" / Const(1, Int16ub)
12+
)
13+
14+
_SN_SECTION_HEADER = Struct(
15+
"type" / Int8ub
16+
,"flags" / Int8ub
17+
,"length" / Int16ub
18+
);
19+
20+
_SN_SECTION_INIT = Struct(
21+
"version" / _SN_VERSION
22+
,"header" / Struct(
23+
"type" / Int8ub
24+
,"flags" / Int8ub
25+
,"length" / Const(248, Int16ub)
26+
)
27+
,"isocode" / Bytes(3)
28+
,"seqnum" / Bytes(13)
29+
#SN__DENOMINATION_FLAGS, SN__DENOMINATION, SN__DECIMALPLACE
30+
,"denomination_flags" / Int8ub
31+
,"denomination" / Int16ub
32+
,"decimalplace" / Int8ub
33+
#SN__MINT_PK, SN__MINT_PK_CRSIG
34+
,"mint_pk" / Bytes(32)
35+
,"mint_pk_crsig" / Bytes(64)
36+
#nonce, hashkey
37+
,"nonce" / Bytes(4)
38+
,"hashkey" / Bytes(64)
39+
,"signature" / Bytes(64)
40+
);
41+
742
_SIX_MONTH_IN_SECONDS = 15778463
843

944
'''
@@ -12,7 +47,6 @@
1247
[X] Public/Private keypair for central reserve
1348
[X] Public/Private keypair for mint
1449
[X] Signature data from central reserve signing
15-
1650
'''
1751

1852
KEYPAIR__CENTRAL_RESERVE = ed25519.create_keypair()
@@ -49,14 +83,16 @@
4983
#[X] Nonce (UINT32)
5084
SN_NONCE = os.urandom(4) #4 bytes = uint32
5185
#[X] SigNote Hash Key String (64-Bytes) (Ex: "In God We Trust. Copyright The United States Federal Reserve")
52-
SN_HASHKEY = "Bill Gates never said that 640K ought to be enough for anybody!!"
86+
SN_HASHKEY = 'Bill Gates has never said "640K ought to be enough for anybody!"'
5387
#[/] The SigNote's Serial Number (BLAKE2b 64-byte Hash of Initial Data)
5488

5589
def sn__generate_init():
90+
out = []
91+
5692
#Version Header
57-
out = [struct.pack( "!2sI", 'SN', 1)]
93+
out += [struct.pack( "!2sH", 'SN', 1)]
5894
# Start init section
59-
out += [struct.pack( "!BBH", 0, 0, 256)]
95+
out += [struct.pack( "!BBH", 0, 0, 248)]
6096

6197
# [ISO][SQNUM] = 128 bits
6298
out += [SN__ISOCODE, SN__SQNUMBER]
@@ -82,3 +118,8 @@ def sn__generate_init():
82118
print len(snote['data'])
83119
print "SIGNATURE:", snote['signature']
84120
print repr(snote['data'])
121+
122+
print _SN_SECTION_INIT.parse( snote['data'] )
123+
124+
125+

0 commit comments

Comments
 (0)