From e19c8881c0de822ec394399a26db841cb8763d06 Mon Sep 17 00:00:00 2001 From: slush0 Date: Fri, 21 Feb 2014 22:15:48 +0100 Subject: [PATCH] Removed 'version' from HDNodeType & fixed unit tests --- tests/test_msg_getpublickey.py | 22 +++++++++++----------- trezorlib/ckd_public.py | 4 ++-- trezorlib/client.py | 5 ++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/test_msg_getpublickey.py b/tests/test_msg_getpublickey.py index 40547c20d2..3dc74cd04c 100644 --- a/tests/test_msg_getpublickey.py +++ b/tests/test_msg_getpublickey.py @@ -6,23 +6,23 @@ class TestMsgGetpublic_key(common.TrezorTest): def test_btc(self): self.setup_mnemonic_nopin_nopassphrase() - self.assertEqual(bip32.serialize( self.client.get_public_node('Bitcoin', []) ), 'xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy') - self.assertEqual(bip32.serialize( self.client.get_public_node('Bitcoin', [1]) ), 'xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N') - self.assertEqual(bip32.serialize( self.client.get_public_node('Bitcoin', [0, -1]) ), 'xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v') - self.assertEqual(bip32.serialize( self.client.get_public_node('Bitcoin', [-9, 0]) ), 'xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv') - self.assertEqual(bip32.serialize( self.client.get_public_node('Bitcoin', [0, 9999999]) ), 'xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r') + self.assertEqual(bip32.serialize(self.client.get_public_node([]), 0x0488B21E), 'xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy') + self.assertEqual(bip32.serialize(self.client.get_public_node([1]), 0x0488B21E), 'xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N') + self.assertEqual(bip32.serialize(self.client.get_public_node([0, -1]), 0x0488B21E), 'xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v') + self.assertEqual(bip32.serialize(self.client.get_public_node([-9, 0]), 0x0488B21E), 'xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv') + self.assertEqual(bip32.serialize(self.client.get_public_node([0, 9999999]), 0x0488B21E), 'xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r') def test_ltc(self): self.setup_mnemonic_nopin_nopassphrase() - self.assertEqual(bip32.serialize( self.client.get_public_node('Litecoin', []) ), 'Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp') - self.assertEqual(bip32.serialize( self.client.get_public_node('Litecoin', [1]) ), 'Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C') - self.assertEqual(bip32.serialize( self.client.get_public_node('Litecoin', [0, -1]) ), 'Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT') - self.assertEqual(bip32.serialize( self.client.get_public_node('Litecoin', [-9, 0]) ), 'Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu') - self.assertEqual(bip32.serialize( self.client.get_public_node('Litecoin', [0, 9999999]) ), 'Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n') + self.assertEqual(bip32.serialize(self.client.get_public_node([]), 0x019dA462), 'Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp') + self.assertEqual(bip32.serialize(self.client.get_public_node([1]), 0x019dA462), 'Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C') + self.assertEqual(bip32.serialize(self.client.get_public_node([0, -1]), 0x019dA462), 'Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT') + self.assertEqual(bip32.serialize(self.client.get_public_node([-9, 0]), 0x019dA462), 'Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu') + self.assertEqual(bip32.serialize(self.client.get_public_node([0, 9999999]), 0x019dA462), 'Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n') def test_tbtc(self): self.setup_mnemonic_nopin_nopassphrase() - self.assertEqual(bip32.serialize( self.client.get_public_node('Testnet', [111, 42]) ), 'tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz') + self.assertEqual(bip32.serialize(self.client.get_public_node([111, 42]), 0x043587CF), 'tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz') if __name__ == '__main__': unittest.main() diff --git a/trezorlib/ckd_public.py b/trezorlib/ckd_public.py index bec0bad1ad..cfd829139e 100644 --- a/trezorlib/ckd_public.py +++ b/trezorlib/ckd_public.py @@ -91,9 +91,9 @@ def get_subnode(node, i): return node_out -def serialize(node): +def serialize(node, version=0x0488B21E): s = '' - s += struct.pack('>I', node.version) + s += struct.pack('>I', version) s += struct.pack('>B', node.depth) s += struct.pack('>I', node.fingerprint) s += struct.pack('>I', node.child_num) diff --git a/trezorlib/client.py b/trezorlib/client.py index 89fb98dc82..18fb281b11 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -323,9 +323,9 @@ class ProtocolMixin(object): @field('node') @expect(proto.PublicKey) - def get_public_node(self, coin_name, n): + def get_public_node(self, n): n = self._convert_prime(n) - return self.call(proto.GetPublicKey(address_n=n, coin_name=coin_name)) + return self.call(proto.GetPublicKey(address_n=n)) @field('address') @expect(proto.Address) @@ -538,7 +538,6 @@ class ProtocolMixin(object): # privkey 00e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35 # checksum e77e9d71 - node.version = int(data[0:8], 16) node.depth = int(data[8:10], 16) node.fingerprint = int(data[10:18], 16) node.child_num = int(data[18:26], 16)