1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00

crypto: update trezor-crypto, fix crypto.bip32 test

This commit is contained in:
Pavol Rusnak 2017-05-08 17:48:22 +02:00
parent b7c043df66
commit 9e42a45b10
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 156 additions and 153 deletions

View File

@ -43,6 +43,7 @@ endif
ifeq ($(MICROPY_PY_TREZORCRYPTO),1)
CFLAGS_MOD += \
-I$(SRCDIR_FW)/extmod/modtrezorcrypto/trezor-crypto \
-I$(SRCDIR_FW)/extmod/modtrezorcrypto/trezor-crypto/aes \
-I$(SRCDIR_FW)/extmod/modtrezorcrypto/trezor-crypto/ed25519-donna \
-DAES_128 \
-DAES_192 \
@ -53,10 +54,10 @@ OBJ_MOD += $(addprefix $(BUILD_FW)/,\
extmod/modtrezorcrypto/rand.o \
extmod/modtrezorcrypto/ssss.o \
extmod/modtrezorcrypto/trezor-crypto/address.o \
extmod/modtrezorcrypto/trezor-crypto/aescrypt.o \
extmod/modtrezorcrypto/trezor-crypto/aeskey.o \
extmod/modtrezorcrypto/trezor-crypto/aes_modes.o \
extmod/modtrezorcrypto/trezor-crypto/aestab.o \
extmod/modtrezorcrypto/trezor-crypto/aes/aescrypt.o \
extmod/modtrezorcrypto/trezor-crypto/aes/aeskey.o \
extmod/modtrezorcrypto/trezor-crypto/aes/aes_modes.o \
extmod/modtrezorcrypto/trezor-crypto/aes/aestab.o \
extmod/modtrezorcrypto/trezor-crypto/base58.o \
extmod/modtrezorcrypto/trezor-crypto/bignum.o \
extmod/modtrezorcrypto/trezor-crypto/bip32.o \

View File

@ -7,7 +7,7 @@
#include "py/objstr.h"
#include "trezor-crypto/aes.h"
#include "trezor-crypto/aes/aes.h"
typedef struct _mp_obj_AES_t {
mp_obj_base_t base;

View File

@ -75,7 +75,7 @@ STATIC mp_obj_t mod_TrezorCrypto_HDNode_derive_path(mp_obj_t self, mp_obj_t path
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_derive_path_obj, mod_TrezorCrypto_HDNode_derive_path);
STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public) {
STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public, uint32_t version) {
mp_obj_HDNode_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
@ -84,9 +84,9 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public) {
int written;
if (use_public) {
hdnode_fill_public_key(&o->hdnode);
written = hdnode_serialize_public(&o->hdnode, o->fingerprint, vstr.buf, vstr.alloc);
written = hdnode_serialize_public(&o->hdnode, o->fingerprint, version, vstr.buf, vstr.alloc);
} else {
written = hdnode_serialize_private(&o->hdnode, o->fingerprint, vstr.buf, vstr.alloc);
written = hdnode_serialize_private(&o->hdnode, o->fingerprint, version, vstr.buf, vstr.alloc);
}
if (written <= 0) {
mp_raise_ValueError("Failed to serialize");
@ -96,23 +96,25 @@ STATIC mp_obj_t serialize_public_private(mp_obj_t self, bool use_public) {
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
/// def trezor.crypto.HDNode.serialize_public() -> str:
/// def trezor.crypto.HDNode.serialize_public(version: int) -> str:
/// '''
/// Serialize the public info from HD node to base58 string.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_public(mp_obj_t self) {
return serialize_public_private(self, true);
STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_public(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, true, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_serialize_public_obj, mod_TrezorCrypto_HDNode_serialize_public);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_public_obj, mod_TrezorCrypto_HDNode_serialize_public);
/// def trezor.crypto.HDNode.serialize_private() -> str:
/// def trezor.crypto.HDNode.serialize_private(version: int) -> str:
/// '''
/// Serialize the private info HD node to base58 string.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_private(mp_obj_t self) {
return serialize_public_private(self, false);
STATIC mp_obj_t mod_TrezorCrypto_HDNode_serialize_private(mp_obj_t self, mp_obj_t version) {
uint32_t ver = mp_obj_get_int_truncated(version);
return serialize_public_private(self, false, ver);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_HDNode_serialize_private_obj, mod_TrezorCrypto_HDNode_serialize_private);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_HDNode_serialize_private_obj, mod_TrezorCrypto_HDNode_serialize_private);
/// def trezor.crypto.HDNode.clone() -> HDNode:
/// '''
@ -240,24 +242,21 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_make_new(const mp_obj_type_t *type, size_
return MP_OBJ_FROM_PTR(o);
}
/// def trezor.crypto.bip32.deserialize(value: str) -> HDNode:
/// def trezor.crypto.bip32.deserialize(value:str, version_public: int, version_private: int) -> HDNode:
/// '''
/// Construct a BIP0032 HD node from a base58-serialized value.
/// '''
STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(mp_obj_t self, mp_obj_t value) {
mp_buffer_info_t valueb;
mp_get_buffer_raise(value, &valueb, MP_BUFFER_READ);
if (valueb.len == 0) {
STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t value;
mp_get_buffer_raise(args[1], &value, MP_BUFFER_READ);
if (value.len == 0) {
mp_raise_ValueError("Invalid value");
}
vstr_t vstr;
vstr_init_len(&vstr, valueb.len);
memcpy(vstr.buf, valueb.buf, valueb.len);
char *str = vstr_null_terminated_str(&vstr);
uint32_t version_public = mp_obj_get_int_truncated(args[2]);
uint32_t version_private = mp_obj_get_int_truncated(args[3]);
HDNode hdnode;
uint32_t fingerprint;
if (hdnode_deserialize(str, &hdnode, &fingerprint) < 0) {
if (hdnode_deserialize(value.buf, version_public, version_private, &hdnode, &fingerprint) < 0) {
mp_raise_ValueError("Failed to deserialize");
}
@ -267,7 +266,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Bip32_deserialize(mp_obj_t self, mp_obj_t value
o->fingerprint = fingerprint;
return MP_OBJ_FROM_PTR(o);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Bip32_deserialize_obj, mod_TrezorCrypto_Bip32_deserialize);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_Bip32_deserialize_obj, 4, 4, mod_TrezorCrypto_Bip32_deserialize);
/// def trezor.crypto.bip32.from_seed(seed: bytes, curve_name: str) -> HDNode:
/// '''

View File

@ -25,6 +25,7 @@ endif
# OBJ micropython/extmod/modtrezorcrypto
ifeq ($(MICROPY_PY_TREZORCRYPTO),1)
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes
CFLAGS_MOD += -I../$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/ed25519-donna
CFLAGS_MOD += -DAES_128
CFLAGS_MOD += -DAES_192
@ -35,10 +36,10 @@ SRC_MOD += \
$(EXTMOD_DIR)/modtrezorcrypto/rand.c \
$(EXTMOD_DIR)/modtrezorcrypto/ssss.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/address.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aescrypt.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aeskey.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes_modes.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aestab.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes/aescrypt.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes/aeskey.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes/aes_modes.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/aes/aestab.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/base58.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/bignum.c \
$(EXTMOD_DIR)/modtrezorcrypto/trezor-crypto/bip32.c \

View File

@ -4,6 +4,8 @@ from trezor.crypto import bip32
SECP256K1_NAME = 'secp256k1'
HARDENED = 0x80000000
VERSION_PUBLIC = 0x0488b21e
VERSION_PRIVATE = 0x0488ade4
class TestCryptoBip32(unittest.TestCase):
@ -39,15 +41,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508'))
self.assertEqual(n.private_key(), unhexlify('e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35'))
self.assertEqual(n.public_key(), unhexlify('0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0']
@ -56,15 +58,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141'))
self.assertEqual(n.private_key(), unhexlify('edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea'))
self.assertEqual(n.public_key(), unhexlify('035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1]
@ -73,15 +75,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19'))
self.assertEqual(n.private_key(), unhexlify('3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368'))
self.assertEqual(n.public_key(), unhexlify('03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2']
@ -90,15 +92,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f'))
self.assertEqual(n.private_key(), unhexlify('cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca'))
self.assertEqual(n.public_key(), unhexlify('0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2'/2]
@ -107,15 +109,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd'))
self.assertEqual(n.private_key(), unhexlify('0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4'))
self.assertEqual(n.public_key(), unhexlify('02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2'/2/1000000000]
@ -124,15 +126,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e'))
self.assertEqual(n.private_key(), unhexlify('471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8'))
self.assertEqual(n.public_key(), unhexlify('022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
def test_secp256k1_vector_2_derive(self):
@ -147,15 +149,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689'))
self.assertEqual(n.private_key(), unhexlify('4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e'))
self.assertEqual(n.public_key(), unhexlify('03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0]
@ -164,15 +166,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c'))
self.assertEqual(n.private_key(), unhexlify('abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e'))
self.assertEqual(n.public_key(), unhexlify('02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647']
@ -181,15 +183,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9'))
self.assertEqual(n.private_key(), unhexlify('877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93'))
self.assertEqual(n.public_key(), unhexlify('03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1]
@ -198,15 +200,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb'))
self.assertEqual(n.private_key(), unhexlify('704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7'))
self.assertEqual(n.public_key(), unhexlify('03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1/2147483646']
@ -215,15 +217,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29'))
self.assertEqual(n.private_key(), unhexlify('f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d'))
self.assertEqual(n.public_key(), unhexlify('02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1/2147483646'/2]
@ -232,15 +234,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271'))
self.assertEqual(n.private_key(), unhexlify('bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23'))
self.assertEqual(n.public_key(), unhexlify('024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
def test_secp256k1_vector_1_derive_path(self):
@ -256,15 +258,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508'))
self.assertEqual(n.private_key(), unhexlify('e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35'))
self.assertEqual(n.public_key(), unhexlify('0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0']
@ -274,15 +276,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141'))
self.assertEqual(n.private_key(), unhexlify('edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea'))
self.assertEqual(n.public_key(), unhexlify('035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1]
@ -292,15 +294,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19'))
self.assertEqual(n.private_key(), unhexlify('3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368'))
self.assertEqual(n.public_key(), unhexlify('03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2']
@ -310,15 +312,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f'))
self.assertEqual(n.private_key(), unhexlify('cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca'))
self.assertEqual(n.public_key(), unhexlify('0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2'/2]
@ -328,15 +330,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd'))
self.assertEqual(n.private_key(), unhexlify('0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4'))
self.assertEqual(n.public_key(), unhexlify('02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0'/1/2'/2/1000000000]
@ -346,15 +348,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e'))
self.assertEqual(n.private_key(), unhexlify('471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8'))
self.assertEqual(n.public_key(), unhexlify('022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
def test_secp256k1_vector_2_derive_path(self):
@ -370,15 +372,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689'))
self.assertEqual(n.private_key(), unhexlify('4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e'))
self.assertEqual(n.public_key(), unhexlify('03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0]
@ -388,15 +390,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c'))
self.assertEqual(n.private_key(), unhexlify('abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e'))
self.assertEqual(n.public_key(), unhexlify('02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647']
@ -406,15 +408,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9'))
self.assertEqual(n.private_key(), unhexlify('877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93'))
self.assertEqual(n.public_key(), unhexlify('03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1]
@ -424,15 +426,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb'))
self.assertEqual(n.private_key(), unhexlify('704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7'))
self.assertEqual(n.public_key(), unhexlify('03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1/2147483646']
@ -442,15 +444,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29'))
self.assertEqual(n.private_key(), unhexlify('f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d'))
self.assertEqual(n.public_key(), unhexlify('02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
# [Chain m/0/2147483647'/1/2147483646'/2]
@ -460,15 +462,15 @@ class TestCryptoBip32(unittest.TestCase):
self.assertEqual(n.chain_code(), unhexlify('9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271'))
self.assertEqual(n.private_key(), unhexlify('bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23'))
self.assertEqual(n.public_key(), unhexlify('024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c'))
ns = n.serialize_private()
ns = n.serialize_private(VERSION_PRIVATE)
self.assertEqual(ns, 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j')
ns2 = bip32.deserialize(ns).serialize_private()
ns2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE).serialize_private(VERSION_PRIVATE)
self.assertEqual(ns2, ns)
ns = n.serialize_public()
ns = n.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns, 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt')
n2 = bip32.deserialize(ns)
n2 = bip32.deserialize(ns, VERSION_PUBLIC, VERSION_PRIVATE)
self.assertEqual(n2.private_key(), bytes(32))
ns2 = n2.serialize_public()
ns2 = n2.serialize_public(VERSION_PUBLIC)
self.assertEqual(ns2, ns)
if __name__ == '__main__':

@ -1 +1 @@
Subproject commit e15a7bc986667902bf31f2f2cc623e540168f7f0
Subproject commit ea227fd805fb97aa2fa76a89bfd05d44012d153f