mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
defs: generate wip coindefs in defs/coins/combine.py
This commit is contained in:
parent
7e39981133
commit
f20e374fcc
2
defs/.gitignore
vendored
2
defs/.gitignore
vendored
@ -1 +1 @@
|
||||
coins.json
|
||||
*.json
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user