1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

defs: generate wip coindefs in defs/coins/combine.py

This commit is contained in:
Pavol Rusnak 2018-04-28 15:27:23 +01:00
parent 7e39981133
commit f20e374fcc
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 27 additions and 7 deletions

2
defs/.gitignore vendored
View File

@ -1 +1 @@
coins.json
*.json

View File

@ -3,6 +3,8 @@
import json
import glob
import re
from hashlib import sha256
import ed25519
def check_type(val, types, nullable=False, empty=False, regex=None, choice=None):
@ -78,18 +80,36 @@ def validate_coin(coin):
assert not bc.endswith('/')
def serialize(coin):
# TODO: replace with protobuf serialization
return json.dumps(coin).encode()
def sign(data):
h = sha256(data).digest()
sign_key = ed25519.SigningKey(b'A' * 32)
return sign_key.sign(h)
def process_json(fn):
print(fn, end=' ... ')
j = json.load(open(fn))
validate_coin(j)
ser = serialize(j)
sig = sign(ser)
definition = (sig + ser).hex()
print('OK')
return j
return j, definition
coins = {}
defs = {}
for fn in glob.glob('*.json'):
c = process_json(fn)
c, d = process_json(fn)
n = c['coin_name']
coins[n] = c
defs[n] = d
json.dump(coins, open('../coins.json', 'w'), indent=4, sort_keys=True)
json.dump(defs, open('../coindefs.json', 'w'), indent=4, sort_keys=True)

View File

@ -22,8 +22,8 @@ message CoinDef {
optional uint32 fork_id = 20;
optional bool force_bip143 = 21;
optional uint64 dust_limit = 22;
optional uint32 blocktime_seconds = 23;
optional string address_prefix = 24;
optional uint32 min_address_length = 25;
optional uint32 max_address_length = 26;
optional string address_prefix = 23;
optional uint32 min_address_length = 24;
optional uint32 max_address_length = 25;
optional bytes icon = 26;
}