1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

apps.common.signtx: fix outputs for multibyte address prefixes

This commit is contained in:
Pavol Rusnak 2016-11-16 01:45:18 +01:00
parent ea12087de7
commit cfdd517bf4
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -312,14 +312,25 @@ def get_tx_hash(w, double: bool, reverse: bool=False) -> bytes:
# TX Outputs # TX Outputs
# === # ===
def len_address_type(address_type):
if address_type <= 0xFF:
return 1
if address_type <= 0xFFFF:
return 2
if address_type <= 0xFFFFFF:
return 3
# else
return 4
def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes: def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes:
if o.script_type == OutputScriptType.PAYTOADDRESS: if o.script_type == OutputScriptType.PAYTOADDRESS:
ra = output_paytoaddress_extract_raw_address(o, coin, root) ra = output_paytoaddress_extract_raw_address(o, coin, root)
return script_paytoaddress_new(ra[1:]) at = len_address_type(coin.address_type)
return script_paytoaddress_new(ra[at:])
elif o.script_type == OutputScriptType.PAYTOSCRIPTHASH: elif o.script_type == OutputScriptType.PAYTOSCRIPTHASH:
ra = output_paytoaddress_extract_raw_address(o, coin, root, p2sh=True) ra = output_paytoaddress_extract_raw_address(o, coin, root, p2sh=True)
return script_paytoscripthash_new(ra[1:]) at = len_address_type(coin.address_type_p2sh)
return script_paytoscripthash_new(ra[at:])
elif o.script_type == OutputScriptType.PAYTOOPRETURN: elif o.script_type == OutputScriptType.PAYTOOPRETURN:
if o.amount == 0: if o.amount == 0:
return script_paytoopreturn_new(o.op_return_data) return script_paytoopreturn_new(o.op_return_data)