mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
stellar: xdr parse move to trezorctl; client works with messages
This commit is contained in:
parent
277296be90
commit
e656bbf072
@ -1013,14 +1013,15 @@ def stellar_verify_message(connect, address, message_is_b64, signatureb64, messa
|
||||
|
||||
@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', '--network-passphrase', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'")
|
||||
@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)
|
||||
# raw signature bytes
|
||||
resp = client.stellar_sign_transaction(base64.b64decode(b64envelope), address_n, network_passphrase)
|
||||
tx, operations = stellar.parse_transaction_bytes(base64.b64decode(b64envelope))
|
||||
resp = client.stellar_sign_transaction(tx, operations, address_n, network_passphrase)
|
||||
|
||||
return base64.b64encode(resp.signature)
|
||||
|
||||
|
@ -1179,16 +1179,14 @@ class ProtocolMixin(object):
|
||||
def stellar_get_public_key(self, address_n):
|
||||
return self.call(proto.StellarGetPublicKey(address_n=address_n))
|
||||
|
||||
def stellar_sign_transaction(self, tx_envelope, address_n, network_passphrase=None):
|
||||
def stellar_sign_transaction(self, tx, operations, address_n, network_passphrase=None):
|
||||
# default networkPassphrase to the public network
|
||||
if network_passphrase is None:
|
||||
network_passphrase = "Public Global Stellar Network ; September 2015"
|
||||
|
||||
tx, operations = stellar.parse_transaction_bytes(tx_envelope)
|
||||
|
||||
tx.network_passphrase = network_passphrase
|
||||
tx.address_n = address_n
|
||||
|
||||
tx.num_operations = len(operations)
|
||||
# Signing loop works as follows:
|
||||
#
|
||||
# 1. Start with tx (header information for the transaction) and operations (an array of operation protobuf messagess)
|
||||
|
@ -17,9 +17,11 @@
|
||||
# https://www.stellar.org/laboratory/#xdr-viewer
|
||||
#
|
||||
|
||||
from base64 import b64decode, b64encode
|
||||
from base64 import b64encode
|
||||
from .common import TrezorTest
|
||||
from .conftest import TREZOR_VERSION
|
||||
from binascii import hexlify, unhexlify
|
||||
from trezorlib import messages as proto
|
||||
import pytest
|
||||
|
||||
|
||||
@ -37,15 +39,29 @@ class TestMsgStellarSignTransaction(TrezorTest):
|
||||
def test_sign_tx_bump_sequence_op(self):
|
||||
self.setup_mnemonic_nopin_nopassphrase()
|
||||
|
||||
xdr = b64decode("AAAAABXWSL/k028ZbPtXNf/YylTNS4Iz90PyJEnefPMBzbRpAAAAZAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAt//////////wAAAAAAAAAA")
|
||||
op = proto.StellarBumpSequenceOp()
|
||||
op.bump_to = 0x7fffffffffffffff
|
||||
tx = self._create_msg()
|
||||
|
||||
response = self.client.stellar_sign_transaction(xdr, self.get_address_n(), self.get_network_passphrase())
|
||||
response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase())
|
||||
assert b64encode(response.signature) == b'UAOL4ZPYIOzEgM66kBrhyNjLR66dNXtuNrmvd3m0/pc8qCSoLmYY4TybS0lHiMtb+LFZESTaxrpErMHz1sZ6DQ=='
|
||||
|
||||
def test_sign_tx_account_merge_op(self):
|
||||
self.setup_mnemonic_nopin_nopassphrase()
|
||||
|
||||
xdr = b64decode("AAAAABXWSL/k028ZbPtXNf/YylTNS4Iz90PyJEnefPMBzbRpAAAAZAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAgAAAAAXVVkJGaxhbhDFS6eIZFR28WJICfsQBAaUXvtXKAwwuAAAAAAAAAAAQHNtGkAAABAgjoPRj4sW5o7NAXzYOqPK0uxfPbeKb4Qw48LJiCH/XUZ6YVCiZogePC0Z5ISUlozMh6YO6HoYtuLPbm7jq+eCA==")
|
||||
op = proto.StellarAccountMergeOp()
|
||||
op.destination_account = unhexlify('5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0')
|
||||
|
||||
response = self.client.stellar_sign_transaction(xdr, self.get_address_n(), self.get_network_passphrase())
|
||||
tx = self._create_msg()
|
||||
|
||||
response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase())
|
||||
assert b64encode(response.signature) == b'gjoPRj4sW5o7NAXzYOqPK0uxfPbeKb4Qw48LJiCH/XUZ6YVCiZogePC0Z5ISUlozMh6YO6HoYtuLPbm7jq+eCA=='
|
||||
|
||||
def _create_msg(self) -> proto.StellarSignTx:
|
||||
tx = proto.StellarSignTx()
|
||||
tx.protocol_version = 1
|
||||
tx.source_account = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469')
|
||||
tx.fee = 100
|
||||
tx.sequence_number = 0x100000000
|
||||
tx.memo_type = 0
|
||||
return tx
|
||||
|
Loading…
Reference in New Issue
Block a user