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

stellar: better way to handle default path

(maybe do this for other currencies too?)
This commit is contained in:
matejcik 2018-05-28 15:44:43 +02:00
parent aace6577c8
commit c10c3f7fd9
4 changed files with 15 additions and 22 deletions

View File

@ -942,25 +942,24 @@ def cosi_sign(connect, address, data, global_commitment, global_pubkey):
# Stellar functions
#
@cli.command(help='Get Stellar public address')
@click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix")
@click.option('-n', '--address', required=False, help="BIP32 path. Always use hardened paths and the m/44'/148'/ prefix", default=stellar.DEFAULT_BIP32_PATH)
@click.pass_obj
def stellar_get_address(connect, address):
client = connect()
address_n = stellar.expand_path_or_default(client, address)
address_n = tools.parse_path(address)
# StellarPublicKey response
response = client.stellar_get_public_key(address_n)
return stellar.address_from_public_key(response.public_key)
@cli.command(help='Sign a base64-encoded transaction envelope')
@click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix")
@click.option('-n', '--address', required=False, help="BIP32 path. Always use hardened paths and the m/44'/148'/ prefix", default=stellar.DEFAULT_BIP32_PATH)
@click.option('-n', '--network-passphrase', default='Public Global Stellar Network ; September 2015', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'")
@click.argument('b64envelope')
@click.pass_obj
def stellar_sign_transaction(connect, b64envelope, address, network_passphrase):
client = connect()
address_n = stellar.expand_path_or_default(client, address)
address_n = tools.parse_path(address)
tx, operations = stellar.parse_transaction_bytes(base64.b64decode(b64envelope))
resp = client.stellar_sign_transaction(tx, operations, address_n, network_passphrase)

View File

@ -30,14 +30,7 @@ OP_MANAGE_DATA = 10
OP_BUMP_SEQUENCE = 11
def expand_path_or_default(client, address):
"""Uses client to parse address and returns an array of integers
If no address is specified, the default of m/44'/148'/0' is used
"""
if address:
return client.expand_path(address)
else:
return client.expand_path("m/44'/148'/0'")
DEFAULT_BIP32_PATH = "m/44h/148h/0h"
def address_from_public_key(pk_bytes):

View File

@ -12,11 +12,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import pytest
from .common import TrezorTest
from .conftest import TREZOR_VERSION
from trezorlib import stellar
import pytest
from trezorlib.tools import parse_path
@pytest.mark.stellar
@ -27,5 +28,5 @@ class TestMsgStellarGetPublicKey(TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
# GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW
response = self.client.stellar_get_public_key(self.client.expand_path("m/44'/148'/0'"))
response = self.client.stellar_get_public_key(parse_path(stellar.DEFAULT_BIP32_PATH))
assert stellar.address_from_public_key(response.public_key) == b'GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW'

View File

@ -20,8 +20,10 @@
from base64 import b64encode
from .common import TrezorTest
from .conftest import TREZOR_VERSION
from binascii import hexlify, unhexlify
from binascii import unhexlify
from trezorlib import messages as proto
from trezorlib import stellar
from trezorlib.tools import parse_path
import pytest
@ -29,14 +31,12 @@ import pytest
@pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished")
class TestMsgStellarSignTransaction(TrezorTest):
ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH)
def get_network_passphrase(self):
"""Use the same passphrase as the network that generated the test XDR/signatures"""
return "Integration Test Network ; zulucrypto"
def get_address_n(self):
"""BIP32 path of the default account"""
return self.client.expand_path("m/44'/148'/0'")
def test_sign_tx_bump_sequence_op(self):
self.setup_mnemonic_nopin_nopassphrase()
@ -44,7 +44,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
op.bump_to = 0x7fffffffffffffff
tx = self._create_msg()
response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase())
response = self.client.stellar_sign_transaction(tx, [op], self.ADDRESS_N, self.get_network_passphrase())
assert b64encode(response.signature) == b'UAOL4ZPYIOzEgM66kBrhyNjLR66dNXtuNrmvd3m0/pc8qCSoLmYY4TybS0lHiMtb+LFZESTaxrpErMHz1sZ6DQ=='
def test_sign_tx_account_merge_op(self):
@ -55,7 +55,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg()
response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase())
response = self.client.stellar_sign_transaction(tx, [op], self.ADDRESS_N, self.get_network_passphrase())
assert b64encode(response.signature) == b'gjoPRj4sW5o7NAXzYOqPK0uxfPbeKb4Qw48LJiCH/XUZ6YVCiZogePC0Z5ISUlozMh6YO6HoYtuLPbm7jq+eCA=='
def _create_msg(self) -> proto.StellarSignTx: