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

apps.common.signtx: fix p2sh output

This commit is contained in:
Pavol Rusnak 2016-11-15 18:19:32 +01:00
parent ceb4ed8c59
commit e10e20d550
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -299,7 +299,7 @@ def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes:
return script_paytoaddress_new(ra[1:]) return script_paytoaddress_new(ra[1:])
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_paytoaddress_new(ra[1:]) return script_paytoscripthash_new(ra[1:])
else: else:
raise SigningError(FailureType.SyntaxError, raise SigningError(FailureType.SyntaxError,
'Invalid output script type') 'Invalid output script type')
@ -394,6 +394,13 @@ def script_paytoaddress_new(pubkeyhash: bytes) -> bytearray:
s[24] = 0xAC # OP_CHECKSIG s[24] = 0xAC # OP_CHECKSIG
return s return s
def script_paytoscripthash_new(scripthash: bytes) -> bytearray:
s = bytearray(23)
s[0] = 0xA9 # OP_HASH_160
s[1] = 0x14 # pushing 20 bytes
s[2:22] = scripthash
s[22] = 0x87 # OP_EQUAL
return s
def script_spendaddress_new(pubkey: bytes, signature: bytes) -> bytearray: def script_spendaddress_new(pubkey: bytes, signature: bytes) -> bytearray:
w = bytearray() w = bytearray()