1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

chore(common/tools): drop outdated and unused CoinDef generator

This commit is contained in:
matejcik 2021-05-31 15:11:05 +02:00 committed by matejcik
parent 9790a338f8
commit 845a66a7de
2 changed files with 3 additions and 195 deletions

View File

@ -1,110 +0,0 @@
from trezorlib import protobuf as p
class CoinDef(p.MessageType):
FIELDS = {
1: ("coin_name", p.UnicodeType, 0),
2: ("coin_shortcut", p.UnicodeType, 0),
3: ("coin_label", p.UnicodeType, 0),
4: ("curve_name", p.UnicodeType, 0),
5: ("address_type", p.UVarintType, 0),
6: ("address_type_p2sh", p.UVarintType, 0),
7: ("maxfee_kb", p.UVarintType, 0),
8: ("minfee_kb", p.UVarintType, 0),
9: ("signed_message_header", p.BytesType, 0),
10: ("hash_genesis_block", p.BytesType, 0),
11: ("xprv_magic", p.UVarintType, 0),
12: ("xpub_magic", p.UVarintType, 0),
13: ("xpub_magic_segwit_p2sh", p.UVarintType, 0),
14: ("xpub_magic_segwit_native", p.UVarintType, 0),
15: ("bech32_prefix", p.UnicodeType, 0),
16: ("cashaddr_prefix", p.UnicodeType, 0),
17: ("slip44", p.UVarintType, 0),
18: ("segwit", p.BoolType, 0),
19: ("decred", p.BoolType, 0),
20: ("fork_id", p.UVarintType, 0),
21: ("force_bip143", p.BoolType, 0),
22: ("dust_limit", p.UVarintType, 0),
23: ("uri_prefix", p.UnicodeType, 0),
24: ("min_address_length", p.UVarintType, 0),
25: ("max_address_length", p.UVarintType, 0),
26: ("icon", p.BytesType, 0),
28: ("website", p.UnicodeType, 0),
29: ("github", p.UnicodeType, 0),
30: ("maintainer", p.UnicodeType, 0),
31: ("blocktime_seconds", p.UVarintType, 0),
33: ("cooldown", p.UVarintType, 0),
}
def __init__(
self,
coin_name: str = None,
coin_shortcut: str = None,
coin_label: str = None,
curve_name: str = None,
address_type: int = None,
address_type_p2sh: int = None,
maxfee_kb: int = None,
minfee_kb: int = None,
signed_message_header: bytes = None,
hash_genesis_block: bytes = None,
xprv_magic: int = None,
xpub_magic: int = None,
xpub_magic_segwit_p2sh: int = None,
xpub_magic_segwit_native: int = None,
bech32_prefix: str = None,
cashaddr_prefix: str = None,
slip44: int = None,
segwit: bool = None,
decred: bool = None,
fork_id: int = None,
force_bip143: bool = None,
dust_limit: int = None,
uri_prefix: str = None,
min_address_length: int = None,
max_address_length: int = None,
icon: bytes = None,
website: str = None,
github: str = None,
maintainer: str = None,
blocktime_seconds: int = None,
default_fee_b: dict = None,
bitcore: dict = None,
blockbook: dict = None,
cooldown: int = None,
):
self.coin_name = coin_name
self.coin_shortcut = coin_shortcut
self.coin_label = coin_label
self.curve_name = curve_name
self.address_type = address_type
self.address_type_p2sh = address_type_p2sh
self.maxfee_kb = maxfee_kb
self.minfee_kb = minfee_kb
self.signed_message_header = signed_message_header
self.hash_genesis_block = hash_genesis_block
self.xprv_magic = xprv_magic
self.xpub_magic = xpub_magic
self.xpub_magic_segwit_p2sh = xpub_magic_segwit_p2sh
self.xpub_magic_segwit_native = xpub_magic_segwit_native
self.bech32_prefix = bech32_prefix
self.cashaddr_prefix = cashaddr_prefix
self.slip44 = slip44
self.segwit = segwit
self.decred = decred
self.fork_id = fork_id
self.force_bip143 = force_bip143
self.dust_limit = dust_limit
self.uri_prefix = uri_prefix
self.min_address_length = min_address_length
self.max_address_length = max_address_length
self.icon = icon
self.website = website
self.github = github
self.maintainer = maintainer
self.blocktime_seconds = blocktime_seconds
self.default_fee_b = default_fee_b
self.bitcore = bitcore
self.blockbook = blockbook
self.cooldown = cooldown
p.MessageType.__init__(self)

View File

@ -1,21 +1,17 @@
#!/usr/bin/env python3
import fnmatch
import glob
import io
import json
import logging
import os
import re
import struct
import sys
import zlib
from collections import defaultdict
from hashlib import sha256
import click
import coin_info
from coindef import CoinDef
try:
import termcolor
@ -37,13 +33,11 @@ except ImportError:
requests = None
try:
import ed25519
from PIL import Image
from trezorlib import protobuf
CAN_BUILD_DEFS = True
CAN_CHECK_ICONS = True
except ImportError:
CAN_BUILD_DEFS = False
CAN_CHECK_ICONS = False
# ======= Crayon colors ======
@ -579,59 +573,6 @@ def check_fido(apps):
return check_passed
# ====== coindefs generators ======
def convert_icon(icon):
"""Convert PIL icon to TOIF format"""
# TODO: move this to python-trezor at some point
DIM = 32
icon = icon.resize((DIM, DIM), Image.LANCZOS)
# remove alpha channel, replace with black
bg = Image.new("RGBA", icon.size, (0, 0, 0, 255))
icon = Image.alpha_composite(bg, icon)
# process pixels
pix = icon.load()
data = bytes()
for y in range(DIM):
for x in range(DIM):
r, g, b, _ = pix[x, y]
c = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3)
data += struct.pack(">H", c)
z = zlib.compressobj(level=9, wbits=10)
zdata = z.compress(data) + z.flush()
zdata = zdata[2:-4] # strip header and checksum
return zdata
def coindef_from_dict(coin):
proto = CoinDef()
for fname, _, fflags in CoinDef.FIELDS.values():
val = coin.get(fname)
if val is None and fflags & protobuf.FLAG_REPEATED:
val = []
elif fname == "signed_message_header":
val = val.encode()
elif fname == "hash_genesis_block":
val = bytes.fromhex(val)
setattr(proto, fname, val)
return proto
def serialize_coindef(proto, icon):
proto.icon = icon
buf = io.BytesIO()
protobuf.dump_message(buf, proto)
return buf.getvalue()
def sign(data):
h = sha256(data).digest()
sign_key = ed25519.SigningKey(b"A" * 32)
return sign_key.sign(h)
# ====== click command handlers ======
@ -689,7 +630,7 @@ def check(backend, icons, show_duplicates):
if backend and requests is None:
raise click.ClickException("You must install requests for backend check")
if icons and not CAN_BUILD_DEFS:
if icons and not CAN_CHECK_ICONS:
raise click.ClickException("Missing requirements for icon check")
defs, buckets = coin_info.coin_info_with_duplicates()
@ -883,29 +824,6 @@ def dump(
outfile.write("\n")
@cli.command()
@click.option("-o", "--outfile", type=click.File(mode="w"), default="./coindefs.json")
def coindefs(outfile):
"""Generate signed coin definitions for python-trezor and others
This is currently unused but should enable us to add new coins without having to
update firmware.
"""
coins = coin_info.coin_info().bitcoin
coindefs = {}
for coin in coins:
key = coin["key"]
icon = Image.open(coin["icon"])
ser = serialize_coindef(coindef_from_dict(coin), convert_icon(icon))
sig = sign(ser)
definition = (sig + ser).hex()
coindefs[key] = definition
with outfile:
json.dump(coindefs, outfile, indent=4, sort_keys=True)
outfile.write("\n")
@cli.command()
# fmt: off
@click.argument("paths", metavar="[path]...", nargs=-1)