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

add coin param to get_public_node call; new test for getpublickey message

This commit is contained in:
Pavol Rusnak 2014-02-21 18:56:51 +01:00
parent 640d290129
commit 729fac2077
5 changed files with 47 additions and 4 deletions

3
cmd.py
View File

@ -102,7 +102,7 @@ class Commands(object):
def get_public_node(self, args):
address_n = self.client.expand_path(args.n)
return self.client.get_public_node(address_n)
return self.client.get_public_node(args.coin, address_n)
def set_label(self, args):
return self.client.apply_settings(label=args.label)
@ -238,6 +238,7 @@ class Commands(object):
)
get_public_node.arguments = (
(('-c', '--coin'), {'type': str, 'default': 'Bitcoin'}),
(('-n', '-address'), {'type': str}),
)

View File

@ -1,7 +1,6 @@
import unittest
import common
import trezorlib.ckd_public as bip32
from trezorlib import tools
class TestMsgGetaddress(common.TrezorTest):

View File

@ -0,0 +1,28 @@
import unittest
import common
import trezorlib.ckd_public as bip32
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')
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')
def test_tbtc(self):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(bip32.serialize( self.client.get_public_node('Testnet', [111, 42]) ), 'tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz')
if __name__ == '__main__':
unittest.main()

View File

@ -90,3 +90,17 @@ def get_subnode(node, i):
node_out.public_key = point_to_pubkey(point)
return node_out
def serialize(node):
s = ''
s += struct.pack('>I', node.version)
s += struct.pack('>B', node.depth)
s += struct.pack('>I', node.fingerprint)
s += struct.pack('>I', node.child_num)
s += node.chain_code
if node.private_key:
s += '\x00' + node.private_key
else :
s += node.public_key
s += tools.Hash(s)[:4]
return tools.b58encode(s)

View File

@ -306,8 +306,9 @@ class ProtocolMixin(object):
@field('node')
@expect(proto.PublicKey)
def get_public_node(self, n):
return self.call(proto.GetPublicKey(address_n=n))
def get_public_node(self, coin_name, n):
n = self._convert_prime(n)
return self.call(proto.GetPublicKey(address_n=n, coin_name=coin_name))
@field('address')
@expect(proto.Address)