mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 20:38:10 +00:00
core/sign_tx: Use varint length encoding for witness stack items.
This commit is contained in:
parent
0c734dc8fd
commit
e7f230d66e
@ -16,7 +16,12 @@ from .multisig import (
|
|||||||
multisig_get_pubkeys,
|
multisig_get_pubkeys,
|
||||||
multisig_pubkey_index,
|
multisig_pubkey_index,
|
||||||
)
|
)
|
||||||
from .writers import write_bytes_fixed, write_bytes_unchecked, write_op_push
|
from .writers import (
|
||||||
|
write_bytes_fixed,
|
||||||
|
write_bytes_prefixed,
|
||||||
|
write_bytes_unchecked,
|
||||||
|
write_op_push,
|
||||||
|
)
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
@ -245,8 +250,8 @@ def input_script_p2wsh_in_p2sh(script_hash: bytes) -> bytearray:
|
|||||||
def witness_p2wpkh(signature: bytes, pubkey: bytes, sighash: int) -> bytearray:
|
def witness_p2wpkh(signature: bytes, pubkey: bytes, sighash: int) -> bytearray:
|
||||||
w = empty_bytearray(1 + 5 + len(signature) + 1 + 5 + len(pubkey))
|
w = empty_bytearray(1 + 5 + len(signature) + 1 + 5 + len(pubkey))
|
||||||
write_bitcoin_varint(w, 0x02) # num of segwit items, in P2WPKH it's always 2
|
write_bitcoin_varint(w, 0x02) # num of segwit items, in P2WPKH it's always 2
|
||||||
append_signature(w, signature, sighash)
|
write_signature_prefixed(w, signature, sighash)
|
||||||
append_pubkey(w, pubkey)
|
write_bytes_prefixed(w, pubkey)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
||||||
@ -290,7 +295,7 @@ def witness_p2wsh(
|
|||||||
write_bitcoin_varint(w, 0)
|
write_bitcoin_varint(w, 0)
|
||||||
|
|
||||||
for s in signatures:
|
for s in signatures:
|
||||||
append_signature(w, s, sighash) # size of the witness included
|
write_signature_prefixed(w, s, sighash) # size of the witness included
|
||||||
|
|
||||||
# redeem script
|
# redeem script
|
||||||
write_bitcoin_varint(w, redeem_script_length)
|
write_bitcoin_varint(w, redeem_script_length)
|
||||||
@ -389,6 +394,12 @@ def output_script_paytoopreturn(data: bytes) -> bytearray:
|
|||||||
# ===
|
# ===
|
||||||
|
|
||||||
|
|
||||||
|
def write_signature_prefixed(w: Writer, signature: bytes, sighash: int) -> None:
|
||||||
|
write_bitcoin_varint(w, len(signature) + 1)
|
||||||
|
write_bytes_unchecked(w, signature)
|
||||||
|
w.append(sighash)
|
||||||
|
|
||||||
|
|
||||||
def append_signature(w: Writer, signature: bytes, sighash: int) -> None:
|
def append_signature(w: Writer, signature: bytes, sighash: int) -> None:
|
||||||
write_op_push(w, len(signature) + 1)
|
write_op_push(w, len(signature) + 1)
|
||||||
write_bytes_unchecked(w, signature)
|
write_bytes_unchecked(w, signature)
|
||||||
|
Loading…
Reference in New Issue
Block a user