From 603b201ad07eccd24d7126666aa61a0d68f546d1 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 18 Apr 2018 13:47:20 +0200 Subject: [PATCH] tests: create tests.support module for things that should not be part of trezorlib but tests use them --- trezorlib/tests/support/__init__.py | 0 trezorlib/{ => tests/support}/ckd_public.py | 10 +++++----- trezorlib/{ => tests/support}/ed25519cosi.py | 2 +- trezorlib/{ => tests/support}/ed25519raw.py | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 trezorlib/tests/support/__init__.py rename trezorlib/{ => tests/support}/ckd_public.py (96%) rename trezorlib/{ => tests/support}/ed25519cosi.py (96%) rename trezorlib/{ => tests/support}/ed25519raw.py (99%) diff --git a/trezorlib/tests/support/__init__.py b/trezorlib/tests/support/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/trezorlib/ckd_public.py b/trezorlib/tests/support/ckd_public.py similarity index 96% rename from trezorlib/ckd_public.py rename to trezorlib/tests/support/ckd_public.py index 9b187880c..e1ee5d8fa 100644 --- a/trezorlib/ckd_public.py +++ b/trezorlib/tests/support/ckd_public.py @@ -27,8 +27,8 @@ from ecdsa.util import string_to_number, number_to_string from ecdsa.curves import SECP256k1 from ecdsa.ellipticcurve import Point, INFINITY -from . import tools -from . import messages as proto +from trezorlib import tools +from trezorlib import messages PRIME_DERIVATION_FLAG = 0x80000000 @@ -76,7 +76,7 @@ def public_ckd(public_node, n): if not isinstance(n, list): raise ValueError('Parameter must be a list') - node = proto.HDNodeType() + node = messages.HDNodeType() node.CopyFrom(public_node) for i in n: @@ -98,7 +98,7 @@ def get_subnode(node, i): I64 = hmac.HMAC(key=node.chain_code, msg=data, digestmod=hashlib.sha512).digest() I_left_as_exponent = string_to_number(I64[:32]) - node_out = proto.HDNodeType() + node_out = messages.HDNodeType() node_out.depth = node.depth + 1 node_out.child_num = i node_out.chain_code = I64[32:] @@ -138,7 +138,7 @@ def deserialize(xpub): if tools.Hash(data[:-4])[:4] != data[-4:]: raise ValueError("Checksum failed") - node = proto.HDNodeType() + node = messages.HDNodeType() node.depth = struct.unpack('>B', data[4:5])[0] node.fingerprint = struct.unpack('>I', data[5:9])[0] node.child_num = struct.unpack('>I', data[9:13])[0] diff --git a/trezorlib/ed25519cosi.py b/trezorlib/tests/support/ed25519cosi.py similarity index 96% rename from trezorlib/ed25519cosi.py rename to trezorlib/tests/support/ed25519cosi.py index 530718a10..645dc29b5 100644 --- a/trezorlib/ed25519cosi.py +++ b/trezorlib/tests/support/ed25519cosi.py @@ -70,7 +70,7 @@ def self_test(digest): R = commits[i] h = ed25519raw.H(seckey) b = ed25519raw.b - a = 2**(b - 2) + sum(2**i * ed25519raw.bit(h, i) for i in range(3, b - 2)) + a = 2**(b - 2) + sum(2 ** i * ed25519raw.bit(h, i) for i in range(3, b - 2)) S = (r + ed25519raw.Hint(global_R + global_pk + digest) * a) % ed25519raw.l print('Local sig %d: %s' % (i + 1, to_hex(ed25519raw.encodeint(S)))) sigs.append(ed25519raw.encodeint(S)) diff --git a/trezorlib/ed25519raw.py b/trezorlib/tests/support/ed25519raw.py similarity index 99% rename from trezorlib/ed25519raw.py rename to trezorlib/tests/support/ed25519raw.py index 81476396e..5bfa47bff 100644 --- a/trezorlib/ed25519raw.py +++ b/trezorlib/tests/support/ed25519raw.py @@ -1,7 +1,6 @@ # orignal version downloaded from https://ed25519.cr.yp.to/python/ed25519.py # modified for Python 3 by Jochen Hoenicke -import sys import hashlib b = 256