|
|
@ -1,29 +1,51 @@ |
|
|
|
from binascii import hexlify, unhexlify |
|
|
|
import traceback |
|
|
|
import sys |
|
|
|
|
|
|
|
from electrum.util import bfh, bh2u, versiontuple, UserCancelled, UserFacingException |
|
|
|
from electrum.bitcoin import TYPE_ADDRESS, TYPE_SCRIPT |
|
|
|
from electrum.bip32 import deserialize_xpub |
|
|
|
from electrum.bip32 import deserialize_xpub, convert_bip32_path_to_list_of_uint32 as parse_path |
|
|
|
from electrum import constants |
|
|
|
from electrum.i18n import _ |
|
|
|
from electrum.plugin import Device |
|
|
|
from electrum.transaction import deserialize, Transaction |
|
|
|
from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey |
|
|
|
from electrum.base_wizard import ScriptTypeNotSupported |
|
|
|
from electrum.base_wizard import ScriptTypeNotSupported, HWD_SETUP_NEW_WALLET |
|
|
|
|
|
|
|
from ..hw_wallet import HW_PluginBase |
|
|
|
from ..hw_wallet.plugin import is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data |
|
|
|
|
|
|
|
try: |
|
|
|
import trezorlib |
|
|
|
import trezorlib.transport |
|
|
|
|
|
|
|
# TREZOR initialization methods |
|
|
|
TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4) |
|
|
|
RECOVERY_TYPE_SCRAMBLED_WORDS, RECOVERY_TYPE_MATRIX = range(0, 2) |
|
|
|
from .clientbase import TrezorClientBase |
|
|
|
|
|
|
|
from trezorlib.messages import ( |
|
|
|
RecoveryDeviceType, HDNodeType, HDNodePathType, |
|
|
|
InputScriptType, OutputScriptType, MultisigRedeemScriptType, |
|
|
|
TxInputType, TxOutputType, TxOutputBinType, TransactionType, SignTx) |
|
|
|
|
|
|
|
RECOVERY_TYPE_SCRAMBLED_WORDS = RecoveryDeviceType.ScrambledWords |
|
|
|
RECOVERY_TYPE_MATRIX = RecoveryDeviceType.Matrix |
|
|
|
|
|
|
|
TREZORLIB = True |
|
|
|
except Exception as e: |
|
|
|
import traceback |
|
|
|
traceback.print_exc() |
|
|
|
TREZORLIB = False |
|
|
|
|
|
|
|
RECOVERY_TYPE_SCRAMBLED_WORDS, RECOVERY_TYPE_MATRIX = range(2) |
|
|
|
|
|
|
|
|
|
|
|
# Trezor initialization methods |
|
|
|
TIM_NEW, TIM_RECOVER = range(2) |
|
|
|
|
|
|
|
TREZOR_PRODUCT_KEY = 'Trezor' |
|
|
|
|
|
|
|
|
|
|
|
class TrezorKeyStore(Hardware_KeyStore): |
|
|
|
hw_type = 'trezor' |
|
|
|
device = 'TREZOR' |
|
|
|
device = TREZOR_PRODUCT_KEY |
|
|
|
|
|
|
|
def get_derivation(self): |
|
|
|
return self.derivation |
|
|
@ -37,8 +59,7 @@ class TrezorKeyStore(Hardware_KeyStore): |
|
|
|
def sign_message(self, sequence, message, password): |
|
|
|
client = self.get_client() |
|
|
|
address_path = self.get_derivation() + "/%d/%d"%sequence |
|
|
|
address_n = client.expand_path(address_path) |
|
|
|
msg_sig = client.sign_message(self.plugin.get_coin_name(), address_n, message) |
|
|
|
msg_sig = client.sign_message(address_path, message) |
|
|
|
return msg_sig.signature |
|
|
|
|
|
|
|
def sign_transaction(self, tx, password): |
|
|
@ -75,41 +96,35 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
libraries_URL = 'https://github.com/trezor/python-trezor' |
|
|
|
minimum_firmware = (1, 5, 2) |
|
|
|
keystore_class = TrezorKeyStore |
|
|
|
minimum_library = (0, 9, 0) |
|
|
|
minimum_library = (0, 11, 0) |
|
|
|
maximum_library = (0, 12) |
|
|
|
SUPPORTED_XTYPES = ('standard', 'p2wpkh-p2sh', 'p2wpkh', 'p2wsh-p2sh', 'p2wsh') |
|
|
|
DEVICE_IDS = (TREZOR_PRODUCT_KEY,) |
|
|
|
|
|
|
|
MAX_LABEL_LEN = 32 |
|
|
|
|
|
|
|
def __init__(self, parent, config, name): |
|
|
|
HW_PluginBase.__init__(self, parent, config, name) |
|
|
|
super().__init__(parent, config, name) |
|
|
|
|
|
|
|
self.libraries_available = self.check_libraries_available() |
|
|
|
if not self.libraries_available: |
|
|
|
return |
|
|
|
|
|
|
|
from . import client |
|
|
|
from . import transport |
|
|
|
import trezorlib.messages |
|
|
|
self.client_class = client.TrezorClient |
|
|
|
self.types = trezorlib.messages |
|
|
|
self.DEVICE_IDS = ('TREZOR',) |
|
|
|
|
|
|
|
self.transport_handler = transport.TrezorTransport() |
|
|
|
self.device_manager().register_enumerate_func(self.enumerate) |
|
|
|
|
|
|
|
def get_library_version(self): |
|
|
|
import trezorlib |
|
|
|
if not TREZORLIB: |
|
|
|
raise ImportError |
|
|
|
try: |
|
|
|
return trezorlib.__version__ |
|
|
|
except AttributeError: |
|
|
|
except Exception: |
|
|
|
return 'unknown' |
|
|
|
|
|
|
|
def enumerate(self): |
|
|
|
devices = self.transport_handler.enumerate_devices() |
|
|
|
devices = trezorlib.transport.enumerate_devices() |
|
|
|
return [Device(path=d.get_path(), |
|
|
|
interface_number=-1, |
|
|
|
id_=d.get_path(), |
|
|
|
product_key='TREZOR', |
|
|
|
product_key=TREZOR_PRODUCT_KEY, |
|
|
|
usage_page=0, |
|
|
|
transport_ui_string=d.get_path()) |
|
|
|
for d in devices] |
|
|
@ -117,7 +132,7 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
def create_client(self, device, handler): |
|
|
|
try: |
|
|
|
self.print_error("connecting to device at", device.path) |
|
|
|
transport = self.transport_handler.get_transport(device.path) |
|
|
|
transport = trezorlib.transport.get_transport(device.path) |
|
|
|
except BaseException as e: |
|
|
|
self.print_error("cannot connect at", device.path, str(e)) |
|
|
|
return None |
|
|
@ -128,27 +143,7 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
|
|
|
|
self.print_error("connected to device at", device.path) |
|
|
|
# note that this call can still raise! |
|
|
|
client = self.client_class(transport, handler, self) |
|
|
|
|
|
|
|
# Try a ping for device sanity |
|
|
|
try: |
|
|
|
client.ping('t') |
|
|
|
except BaseException as e: |
|
|
|
self.print_error("ping failed", str(e)) |
|
|
|
return None |
|
|
|
|
|
|
|
if not client.atleast_version(*self.minimum_firmware): |
|
|
|
msg = (_('Outdated {} firmware for device labelled {}. Please ' |
|
|
|
'download the updated firmware from {}') |
|
|
|
.format(self.device, client.label(), self.firmware_URL)) |
|
|
|
self.print_error(msg) |
|
|
|
if handler: |
|
|
|
handler.show_error(msg) |
|
|
|
else: |
|
|
|
raise UserFacingException(msg) |
|
|
|
return None |
|
|
|
|
|
|
|
return client |
|
|
|
return TrezorClientBase(transport, handler, self) |
|
|
|
|
|
|
|
def get_client(self, keystore, force_pair=True): |
|
|
|
devmgr = self.device_manager() |
|
|
@ -177,8 +172,6 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
# Must be short as QT doesn't word-wrap radio button text |
|
|
|
(TIM_NEW, _("Let the device generate a completely new seed randomly")), |
|
|
|
(TIM_RECOVER, _("Recover from a seed you have previously written down")), |
|
|
|
(TIM_MNEMONIC, _("Upload a BIP39 mnemonic to generate the seed")), |
|
|
|
(TIM_PRIVKEY, _("Upload a master private key")) |
|
|
|
] |
|
|
|
devmgr = self.device_manager() |
|
|
|
client = devmgr.client_by_id(device_id) |
|
|
@ -222,49 +215,37 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
"the words carefully!"), |
|
|
|
blocking=True) |
|
|
|
|
|
|
|
language = 'english' |
|
|
|
devmgr = self.device_manager() |
|
|
|
client = devmgr.client_by_id(device_id) |
|
|
|
|
|
|
|
if method == TIM_NEW: |
|
|
|
strength = 64 * (item + 2) # 128, 192 or 256 |
|
|
|
u2f_counter = 0 |
|
|
|
skip_backup = False |
|
|
|
client.reset_device(True, strength, passphrase_protection, |
|
|
|
pin_protection, label, language, |
|
|
|
u2f_counter, skip_backup) |
|
|
|
client.reset_device( |
|
|
|
strength=64 * (item + 2), # 128, 192 or 256 |
|
|
|
passphrase_protection=passphrase_protection, |
|
|
|
pin_protection=pin_protection, |
|
|
|
label=label) |
|
|
|
elif method == TIM_RECOVER: |
|
|
|
word_count = 6 * (item + 2) # 12, 18 or 24 |
|
|
|
client.step = 0 |
|
|
|
if recovery_type == RECOVERY_TYPE_SCRAMBLED_WORDS: |
|
|
|
recovery_type_trezor = self.types.RecoveryDeviceType.ScrambledWords |
|
|
|
else: |
|
|
|
recovery_type_trezor = self.types.RecoveryDeviceType.Matrix |
|
|
|
client.recovery_device(word_count, passphrase_protection, |
|
|
|
pin_protection, label, language, |
|
|
|
type=recovery_type_trezor) |
|
|
|
client.recover_device( |
|
|
|
recovery_type=recovery_type, |
|
|
|
word_count=6 * (item + 2), # 12, 18 or 24 |
|
|
|
passphrase_protection=passphrase_protection, |
|
|
|
pin_protection=pin_protection, |
|
|
|
label=label) |
|
|
|
if recovery_type == RECOVERY_TYPE_MATRIX: |
|
|
|
handler.close_matrix_dialog() |
|
|
|
elif method == TIM_MNEMONIC: |
|
|
|
pin = pin_protection # It's the pin, not a boolean |
|
|
|
client.load_device_by_mnemonic(str(item), pin, |
|
|
|
passphrase_protection, |
|
|
|
label, language) |
|
|
|
else: |
|
|
|
pin = pin_protection # It's the pin, not a boolean |
|
|
|
client.load_device_by_xprv(item, pin, passphrase_protection, |
|
|
|
label, language) |
|
|
|
raise RuntimeError("Unsupported recovery method") |
|
|
|
|
|
|
|
def _make_node_path(self, xpub, address_n): |
|
|
|
_, depth, fingerprint, child_num, chain_code, key = deserialize_xpub(xpub) |
|
|
|
node = self.types.HDNodeType( |
|
|
|
node = HDNodeType( |
|
|
|
depth=depth, |
|
|
|
fingerprint=int.from_bytes(fingerprint, 'big'), |
|
|
|
child_num=int.from_bytes(child_num, 'big'), |
|
|
|
chain_code=chain_code, |
|
|
|
public_key=key, |
|
|
|
) |
|
|
|
return self.types.HDNodePathType(node=node, address_n=address_n) |
|
|
|
return HDNodePathType(node=node, address_n=address_n) |
|
|
|
|
|
|
|
def setup_device(self, device_info, wizard, purpose): |
|
|
|
devmgr = self.device_manager() |
|
|
@ -273,11 +254,19 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
if client is None: |
|
|
|
raise UserFacingException(_('Failed to create a client for this device.') + '\n' + |
|
|
|
_('Make sure it is in the correct state.')) |
|
|
|
|
|
|
|
if not client.is_uptodate(): |
|
|
|
msg = (_('Outdated {} firmware for device labelled {}. Please ' |
|
|
|
'download the updated firmware from {}') |
|
|
|
.format(self.device, client.label(), self.firmware_URL)) |
|
|
|
raise UserFacingException(msg) |
|
|
|
|
|
|
|
# fixme: we should use: client.handler = wizard |
|
|
|
client.handler = self.create_handler(wizard) |
|
|
|
if not device_info.initialized: |
|
|
|
self.initialize_device(device_id, wizard, client.handler) |
|
|
|
client.get_xpub('m', 'standard') |
|
|
|
is_creating_wallet = purpose == HWD_SETUP_NEW_WALLET |
|
|
|
client.get_xpub('m', 'standard', creating=is_creating_wallet) |
|
|
|
client.used() |
|
|
|
|
|
|
|
def get_xpub(self, device_id, derivation, xtype, wizard): |
|
|
@ -292,33 +281,33 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
|
|
|
|
def get_trezor_input_script_type(self, electrum_txin_type: str): |
|
|
|
if electrum_txin_type in ('p2wpkh', 'p2wsh'): |
|
|
|
return self.types.InputScriptType.SPENDWITNESS |
|
|
|
return InputScriptType.SPENDWITNESS |
|
|
|
if electrum_txin_type in ('p2wpkh-p2sh', 'p2wsh-p2sh'): |
|
|
|
return self.types.InputScriptType.SPENDP2SHWITNESS |
|
|
|
return InputScriptType.SPENDP2SHWITNESS |
|
|
|
if electrum_txin_type in ('p2pkh', ): |
|
|
|
return self.types.InputScriptType.SPENDADDRESS |
|
|
|
return InputScriptType.SPENDADDRESS |
|
|
|
if electrum_txin_type in ('p2sh', ): |
|
|
|
return self.types.InputScriptType.SPENDMULTISIG |
|
|
|
return InputScriptType.SPENDMULTISIG |
|
|
|
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type)) |
|
|
|
|
|
|
|
def get_trezor_output_script_type(self, electrum_txin_type: str): |
|
|
|
if electrum_txin_type in ('p2wpkh', 'p2wsh'): |
|
|
|
return self.types.OutputScriptType.PAYTOWITNESS |
|
|
|
return OutputScriptType.PAYTOWITNESS |
|
|
|
if electrum_txin_type in ('p2wpkh-p2sh', 'p2wsh-p2sh'): |
|
|
|
return self.types.OutputScriptType.PAYTOP2SHWITNESS |
|
|
|
return OutputScriptType.PAYTOP2SHWITNESS |
|
|
|
if electrum_txin_type in ('p2pkh', ): |
|
|
|
return self.types.OutputScriptType.PAYTOADDRESS |
|
|
|
return OutputScriptType.PAYTOADDRESS |
|
|
|
if electrum_txin_type in ('p2sh', ): |
|
|
|
return self.types.OutputScriptType.PAYTOMULTISIG |
|
|
|
return OutputScriptType.PAYTOMULTISIG |
|
|
|
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type)) |
|
|
|
|
|
|
|
def sign_transaction(self, keystore, tx, prev_tx, xpub_path): |
|
|
|
self.prev_tx = prev_tx |
|
|
|
self.xpub_path = xpub_path |
|
|
|
prev_tx = { bfh(txhash): self.electrum_tx_to_txtype(tx, xpub_path) for txhash, tx in prev_tx.items() } |
|
|
|
client = self.get_client(keystore) |
|
|
|
inputs = self.tx_inputs(tx, True) |
|
|
|
inputs = self.tx_inputs(tx, xpub_path, True) |
|
|
|
outputs = self.tx_outputs(keystore.get_derivation(), tx) |
|
|
|
signatures = client.sign_tx(self.get_coin_name(), inputs, outputs, lock_time=tx.locktime)[0] |
|
|
|
details = SignTx(lock_time=tx.locktime) |
|
|
|
signatures, _ = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details, prev_txes=prev_tx) |
|
|
|
signatures = [(bh2u(x) + '01') for x in signatures] |
|
|
|
tx.update_signatures(signatures) |
|
|
|
|
|
|
@ -327,74 +316,50 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
keystore = wallet.get_keystore() |
|
|
|
if not self.show_address_helper(wallet, address, keystore): |
|
|
|
return |
|
|
|
client = self.get_client(keystore) |
|
|
|
if not client.atleast_version(1, 3): |
|
|
|
keystore.handler.show_error(_("Your device firmware is too old")) |
|
|
|
return |
|
|
|
change, index = wallet.get_address_index(address) |
|
|
|
deriv_suffix = wallet.get_address_index(address) |
|
|
|
derivation = keystore.derivation |
|
|
|
address_path = "%s/%d/%d"%(derivation, change, index) |
|
|
|
address_n = client.expand_path(address_path) |
|
|
|
address_path = "%s/%d/%d"%(derivation, *deriv_suffix) |
|
|
|
script_type = self.get_trezor_input_script_type(wallet.txin_type) |
|
|
|
|
|
|
|
# prepare multisig, if available: |
|
|
|
xpubs = wallet.get_master_public_keys() |
|
|
|
if len(xpubs) == 1: |
|
|
|
script_type = self.get_trezor_input_script_type(wallet.txin_type) |
|
|
|
client.get_address(self.get_coin_name(), address_n, True, script_type=script_type) |
|
|
|
else: |
|
|
|
def f(xpub): |
|
|
|
return self._make_node_path(xpub, [change, index]) |
|
|
|
if len(xpubs) > 1: |
|
|
|
pubkeys = wallet.get_public_keys(address) |
|
|
|
# sort xpubs using the order of pubkeys |
|
|
|
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs))) |
|
|
|
pubkeys = list(map(f, sorted_xpubs)) |
|
|
|
multisig = self.types.MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
|
signatures=[b''] * wallet.n, |
|
|
|
m=wallet.m, |
|
|
|
) |
|
|
|
script_type = self.get_trezor_input_script_type(wallet.txin_type) |
|
|
|
client.get_address(self.get_coin_name(), address_n, True, multisig=multisig, script_type=script_type) |
|
|
|
|
|
|
|
def tx_inputs(self, tx, for_sig=False): |
|
|
|
sorted_pairs = sorted(zip(pubkeys, xpubs)) |
|
|
|
multisig = self._make_multisig( |
|
|
|
wallet.m, |
|
|
|
[(xpub, deriv_suffix) for _, xpub in sorted_pairs]) |
|
|
|
else: |
|
|
|
multisig = None |
|
|
|
|
|
|
|
client = self.get_client(keystore) |
|
|
|
client.show_address(address_path, script_type, multisig) |
|
|
|
|
|
|
|
def tx_inputs(self, tx, xpub_path, for_sig=False): |
|
|
|
inputs = [] |
|
|
|
for txin in tx.inputs(): |
|
|
|
txinputtype = self.types.TxInputType() |
|
|
|
txinputtype = TxInputType() |
|
|
|
if txin['type'] == 'coinbase': |
|
|
|
prev_hash = b"\x00"*32 |
|
|
|
prev_index = 0xffffffff # signed int -1 |
|
|
|
else: |
|
|
|
if for_sig: |
|
|
|
x_pubkeys = txin['x_pubkeys'] |
|
|
|
if len(x_pubkeys) == 1: |
|
|
|
x_pubkey = x_pubkeys[0] |
|
|
|
xpub, s = parse_xpubkey(x_pubkey) |
|
|
|
xpub_n = self.client_class.expand_path(self.xpub_path[xpub]) |
|
|
|
txinputtype._extend_address_n(xpub_n + s) |
|
|
|
txinputtype.script_type = self.get_trezor_input_script_type(txin['type']) |
|
|
|
else: |
|
|
|
def f(x_pubkey): |
|
|
|
xpub, s = parse_xpubkey(x_pubkey) |
|
|
|
return self._make_node_path(xpub, s) |
|
|
|
pubkeys = list(map(f, x_pubkeys)) |
|
|
|
multisig = self.types.MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
|
signatures=list(map(lambda x: bfh(x)[:-1] if x else b'', txin.get('signatures'))), |
|
|
|
m=txin.get('num_sig'), |
|
|
|
) |
|
|
|
script_type = self.get_trezor_input_script_type(txin['type']) |
|
|
|
txinputtype = self.types.TxInputType( |
|
|
|
script_type=script_type, |
|
|
|
multisig=multisig |
|
|
|
) |
|
|
|
# find which key is mine |
|
|
|
for x_pubkey in x_pubkeys: |
|
|
|
if is_xpubkey(x_pubkey): |
|
|
|
xpub, s = parse_xpubkey(x_pubkey) |
|
|
|
if xpub in self.xpub_path: |
|
|
|
xpub_n = self.client_class.expand_path(self.xpub_path[xpub]) |
|
|
|
txinputtype._extend_address_n(xpub_n + s) |
|
|
|
break |
|
|
|
|
|
|
|
prev_hash = unhexlify(txin['prevout_hash']) |
|
|
|
xpubs = [parse_xpubkey(x) for x in x_pubkeys] |
|
|
|
multisig = self._make_multisig(txin.get('num_sig'), xpubs, txin.get('signatures')) |
|
|
|
script_type = self.get_trezor_input_script_type(txin['type']) |
|
|
|
txinputtype = TxInputType( |
|
|
|
script_type=script_type, |
|
|
|
multisig=multisig) |
|
|
|
# find which key is mine |
|
|
|
for xpub, deriv in xpubs: |
|
|
|
if xpub in xpub_path: |
|
|
|
xpub_n = parse_path(xpub_path[xpub]) |
|
|
|
txinputtype.address_n = xpub_n + deriv |
|
|
|
break |
|
|
|
|
|
|
|
prev_hash = bfh(txin['prevout_hash']) |
|
|
|
prev_index = txin['prevout_n'] |
|
|
|
|
|
|
|
if 'value' in txin: |
|
|
@ -412,39 +377,44 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
|
|
|
|
return inputs |
|
|
|
|
|
|
|
def _make_multisig(self, m, xpubs, signatures=None): |
|
|
|
if len(xpubs) == 1: |
|
|
|
return None |
|
|
|
|
|
|
|
pubkeys = [self._make_node_path(xpub, deriv) for xpub, deriv in xpubs] |
|
|
|
if signatures is None: |
|
|
|
signatures = [b''] * len(pubkeys) |
|
|
|
elif len(signatures) != len(pubkeys): |
|
|
|
raise RuntimeError('Mismatched number of signatures') |
|
|
|
else: |
|
|
|
signatures = [bfh(x)[:-1] if x else b'' for x in signatures] |
|
|
|
|
|
|
|
return MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
|
signatures=signatures, |
|
|
|
m=m) |
|
|
|
|
|
|
|
def tx_outputs(self, derivation, tx): |
|
|
|
|
|
|
|
def create_output_by_derivation(): |
|
|
|
script_type = self.get_trezor_output_script_type(info.script_type) |
|
|
|
if len(xpubs) == 1: |
|
|
|
address_n = self.client_class.expand_path(derivation + "/%d/%d" % index) |
|
|
|
txoutputtype = self.types.TxOutputType( |
|
|
|
amount=amount, |
|
|
|
script_type=script_type, |
|
|
|
address_n=address_n, |
|
|
|
) |
|
|
|
else: |
|
|
|
address_n = self.client_class.expand_path("/%d/%d" % index) |
|
|
|
pubkeys = [self._make_node_path(xpub, address_n) for xpub in xpubs] |
|
|
|
multisig = self.types.MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
|
signatures=[b''] * len(pubkeys), |
|
|
|
m=m) |
|
|
|
txoutputtype = self.types.TxOutputType( |
|
|
|
multisig=multisig, |
|
|
|
amount=amount, |
|
|
|
address_n=self.client_class.expand_path(derivation + "/%d/%d" % index), |
|
|
|
script_type=script_type) |
|
|
|
deriv = parse_path("/%d/%d" % index) |
|
|
|
multisig = self._make_multisig(m, [(xpub, deriv) for xpub in xpubs]) |
|
|
|
txoutputtype = TxOutputType( |
|
|
|
multisig=multisig, |
|
|
|
amount=amount, |
|
|
|
address_n=parse_path(derivation + "/%d/%d" % index), |
|
|
|
script_type=script_type) |
|
|
|
return txoutputtype |
|
|
|
|
|
|
|
def create_output_by_address(): |
|
|
|
txoutputtype = self.types.TxOutputType() |
|
|
|
txoutputtype = TxOutputType() |
|
|
|
txoutputtype.amount = amount |
|
|
|
if _type == TYPE_SCRIPT: |
|
|
|
txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN |
|
|
|
txoutputtype.script_type = OutputScriptType.PAYTOOPRETURN |
|
|
|
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(o) |
|
|
|
elif _type == TYPE_ADDRESS: |
|
|
|
txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS |
|
|
|
txoutputtype.script_type = OutputScriptType.PAYTOADDRESS |
|
|
|
txoutputtype.address = address |
|
|
|
return txoutputtype |
|
|
|
|
|
|
@ -476,23 +446,17 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
|
|
|
|
return outputs |
|
|
|
|
|
|
|
def electrum_tx_to_txtype(self, tx): |
|
|
|
t = self.types.TransactionType() |
|
|
|
def electrum_tx_to_txtype(self, tx, xpub_path): |
|
|
|
t = TransactionType() |
|
|
|
if tx is None: |
|
|
|
# probably for segwit input and we don't need this prev txn |
|
|
|
return t |
|
|
|
d = deserialize(tx.raw) |
|
|
|
t.version = d['version'] |
|
|
|
t.lock_time = d['lockTime'] |
|
|
|
inputs = self.tx_inputs(tx) |
|
|
|
t._extend_inputs(inputs) |
|
|
|
for vout in d['outputs']: |
|
|
|
o = t._add_bin_outputs() |
|
|
|
o.amount = vout['value'] |
|
|
|
o.script_pubkey = bfh(vout['scriptPubKey']) |
|
|
|
t.inputs = self.tx_inputs(tx, xpub_path) |
|
|
|
t.bin_outputs = [ |
|
|
|
TxOutputBinType(amount=vout['value'], script_pubkey=bfh(vout['scriptPubKey'])) |
|
|
|
for vout in d['outputs'] |
|
|
|
] |
|
|
|
return t |
|
|
|
|
|
|
|
# This function is called from the TREZOR libraries (via tx_api) |
|
|
|
def get_tx(self, tx_hash): |
|
|
|
tx = self.prev_tx[tx_hash] |
|
|
|
return self.electrum_tx_to_txtype(tx) |
|
|
|