diff --git a/trezorctl b/trezorctl index c7bb5095e7..edb15fb23d 100755 --- a/trezorctl +++ b/trezorctl @@ -975,6 +975,7 @@ def stellar_get_address(connect, address): response = client.stellar_get_public_key(address_n) return stellar.address_from_public_key(response.public_key) + @cli.command(help='Sign a string with a Stellar key') @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.argument('message') @@ -985,6 +986,7 @@ def stellar_sign_message(connect, address, message): response = client.stellar_sign_message(address_n, message) return base64.b64encode(response.signature) + @cli.command(help='Verify that a signature is valid') @click.option('--message-is-b64/--no-message-is-b64', default=False, required=False, help="If set, the message argument will be interpreted as a base64-encoded string") @click.argument('address') @@ -1008,6 +1010,7 @@ def stellar_verify_message(connect, address, message_is_b64, signatureb64, messa print("ERROR: invalid signature, verification failed") sys.exit(1) + @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'") diff --git a/trezorlib/stellar.py b/trezorlib/stellar.py index 129856ccd8..292dae7c77 100644 --- a/trezorlib/stellar.py +++ b/trezorlib/stellar.py @@ -5,29 +5,30 @@ import xdrlib from . import messages as proto # Memo types -MEMO_TYPE_TEXT = 0 -MEMO_TYPE_ID = 1 -MEMO_TYPE_HASH = 2 +MEMO_TYPE_TEXT = 0 +MEMO_TYPE_ID = 1 +MEMO_TYPE_HASH = 2 MEMO_TYPE_RETURN = 4 # Asset types -ASSET_TYPE_NATIVE = 0 -ASSET_TYPE_ALPHA4 = 1 +ASSET_TYPE_NATIVE = 0 +ASSET_TYPE_ALPHA4 = 1 ASSET_TYPE_ALPHA12 = 2 # Operations -OP_CREATE_ACCOUNT = 0 -OP_PAYMENT = 1 -OP_PATH_PAYMENT = 2 -OP_MANAGE_OFFER = 3 +OP_CREATE_ACCOUNT = 0 +OP_PAYMENT = 1 +OP_PATH_PAYMENT = 2 +OP_MANAGE_OFFER = 3 OP_CREATE_PASSIVE_OFFER = 4 -OP_SET_OPTIONS = 5 -OP_CHANGE_TRUST = 6 -OP_ALLOW_TRUST = 7 -OP_ACCOUNT_MERGE = 8 -OP_INFLATION = 9 # Included for documentation purposes, not supported by Trezor -OP_MANAGE_DATA = 10 -OP_BUMP_SEQUENCE = 11 +OP_SET_OPTIONS = 5 +OP_CHANGE_TRUST = 6 +OP_ALLOW_TRUST = 7 +OP_ACCOUNT_MERGE = 8 +OP_INFLATION = 9 # Included for documentation purposes, not supported by Trezor +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 @@ -53,6 +54,7 @@ def address_from_public_key(pk_bytes): return base64.b32encode(final_bytes) + def address_to_public_key(address_str): """Returns the raw 32 bytes representing a public key by extracting it from the G... string @@ -79,7 +81,7 @@ def parse_transaction_bytes(tx_bytes): # Timebounds is an optional field if unpacker.unpack_bool(): - max_timebound = 2**32-1 # max unsigned 32-bit int (trezor does not support the full 64-bit time value) + max_timebound = 2**32 - 1 # max unsigned 32-bit int (trezor does not support the full 64-bit time value) tx.timebounds_start = unpacker.unpack_uhyper() tx.timebounds_end = unpacker.unpack_uhyper() @@ -109,6 +111,7 @@ def parse_transaction_bytes(tx_bytes): return tx, operations + def _parse_operation_bytes(unpacker): """Returns a protobuf message representing the next operation as read from the byte stream in unpacker @@ -272,6 +275,7 @@ def _parse_operation_bytes(unpacker): raise ValueError("Unknown operation type: " + type) + def _xdr_read_asset(unpacker): """Reads a stellar Asset from unpacker""" asset = proto.StellarAssetType( @@ -300,6 +304,7 @@ def _xdr_read_address(unpacker): return unpacker.unpack_fopaque(32) + def _crc16_checksum(bytes): """Returns the CRC-16 checksum of bytearray bytes diff --git a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py index 91438e5565..c5131d6cac 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py @@ -16,7 +16,8 @@ from .common import TrezorTest from trezorlib import stellar -@pytest.mark.xfail # requires trezor-mcu PR #259 + +@pytest.mark.xfail # requires trezor-mcu PR #259 class TestMsgStellarGetPublicKey(TrezorTest): def test_stellar_get_address(self): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py index 88bc791be8..aaccafef6a 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py @@ -20,7 +20,8 @@ from base64 import b64decode, b64encode from .common import TrezorTest -@pytest.mark.xfail # requires trezor-mcu PR #259 + +@pytest.mark.xfail # requires trezor-mcu PR #259 class TestMsgStellarSignTransaction(TrezorTest): def get_network_passphrase(self): @@ -39,7 +40,6 @@ class TestMsgStellarSignTransaction(TrezorTest): response = self.client.stellar_sign_transaction(xdr, 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()