mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
core/sign_tx: Move header prepending up by one level.
This commit is contained in:
parent
2ceb091d68
commit
987b70f1f5
@ -80,8 +80,6 @@ class Bitcoinlike(signing.Bitcoin):
|
||||
txi_sign.script_sig = self.input_derive_script(
|
||||
txi_sign, key_sign_pub, signature
|
||||
)
|
||||
if i_sign == 0: # serializing first input => prepend headers
|
||||
self.write_sign_tx_header(self.serialized_tx, True in self.segwit.values())
|
||||
writers.write_tx_input(self.serialized_tx, txi_sign)
|
||||
self.tx_req.serialized.signature_index = i_sign
|
||||
self.tx_req.serialized.signature = signature
|
||||
|
@ -70,7 +70,13 @@ class Decred(Bitcoin):
|
||||
def create_hash_writer(self) -> HashWriter:
|
||||
return HashWriter(blake256())
|
||||
|
||||
async def step1_process_inputs(self) -> None:
|
||||
self.write_sign_tx_header(self.serialized_tx, False)
|
||||
await super().step1_process_inputs()
|
||||
|
||||
async def step2_confirm_outputs(self) -> None:
|
||||
writers.write_varint(self.serialized_tx, self.tx.outputs_count)
|
||||
self.hash143.add_output_count(self.tx)
|
||||
await super().step2_confirm_outputs()
|
||||
self.hash143.add_locktime_expiry(self.tx)
|
||||
|
||||
@ -78,9 +84,6 @@ class Decred(Bitcoin):
|
||||
await super().process_input(i, txi)
|
||||
|
||||
# Decred serializes inputs early.
|
||||
if i == 0: # serializing first input => prepend headers
|
||||
self.write_sign_tx_header(self.serialized_tx, False)
|
||||
|
||||
self.write_tx_input(self.serialized_tx, txi)
|
||||
|
||||
async def confirm_output(
|
||||
@ -92,16 +95,15 @@ class Decred(Bitcoin):
|
||||
"Cannot send to output with script version != 0",
|
||||
)
|
||||
txo_bin.decred_script_version = txo.decred_script_version
|
||||
|
||||
if i == 0: # serializing first output => prepend outputs count
|
||||
writers.write_varint(self.serialized_tx, self.tx.outputs_count)
|
||||
self.hash143.add_output_count(self.tx)
|
||||
|
||||
writers.write_tx_output(self.serialized_tx, txo_bin)
|
||||
|
||||
await super().confirm_output(i, txo, txo_bin)
|
||||
|
||||
async def step4_serialize_inputs(self) -> None:
|
||||
writers.write_uint32(self.serialized_tx, self.tx.lock_time)
|
||||
writers.write_uint32(self.serialized_tx, self.tx.expiry)
|
||||
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
|
||||
|
||||
prefix_hash = self.hash143.get_prefix_hash()
|
||||
|
||||
for i_sign in range(self.tx.inputs_count):
|
||||
@ -157,11 +159,6 @@ class Decred(Bitcoin):
|
||||
txi_sign, key_sign_pub, signature
|
||||
)
|
||||
|
||||
if i_sign == 0:
|
||||
writers.write_uint32(self.serialized_tx, self.tx.lock_time)
|
||||
writers.write_uint32(self.serialized_tx, self.tx.expiry)
|
||||
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
|
||||
|
||||
writers.write_tx_input_decred_witness(self.serialized_tx, txi_sign)
|
||||
|
||||
self.tx_req.serialized.signature_index = i_sign
|
||||
|
@ -167,6 +167,7 @@ class Bitcoin:
|
||||
raise SigningError(FailureType.ActionCancelled, "Total cancelled")
|
||||
|
||||
async def step4_serialize_inputs(self) -> None:
|
||||
self.write_sign_tx_header(self.serialized_tx, True in self.segwit.values())
|
||||
for i in range(self.tx.inputs_count):
|
||||
progress.advance()
|
||||
if self.segwit[i]:
|
||||
@ -175,6 +176,7 @@ class Bitcoin:
|
||||
await self.sign_nonsegwit_input(i)
|
||||
|
||||
async def step5_serialize_outputs(self) -> None:
|
||||
writers.write_varint(self.serialized_tx, self.tx.outputs_count)
|
||||
for i in range(self.tx.outputs_count):
|
||||
progress.advance()
|
||||
await self.serialize_output(i)
|
||||
@ -265,8 +267,6 @@ class Bitcoin:
|
||||
key_sign_pub = key_sign.public_key()
|
||||
txi_sign.script_sig = self.input_derive_script(txi_sign, key_sign_pub)
|
||||
|
||||
if i_sign == 0: # serializing first input => prepend headers
|
||||
self.write_sign_tx_header(self.serialized_tx, True)
|
||||
self.write_tx_input(self.serialized_tx, txi_sign)
|
||||
|
||||
async def sign_segwit_input(self, i: int) -> None:
|
||||
@ -378,8 +378,6 @@ class Bitcoin:
|
||||
txi_sign.script_sig = self.input_derive_script(
|
||||
txi_sign, key_sign_pub, signature
|
||||
)
|
||||
if i_sign == 0: # serializing first input => prepend headers
|
||||
self.write_sign_tx_header(self.serialized_tx, True in self.segwit.values())
|
||||
self.write_tx_input(self.serialized_tx, txi_sign)
|
||||
|
||||
self.tx_req.serialized.signature_index = i_sign
|
||||
@ -391,9 +389,6 @@ class Bitcoin:
|
||||
txo_bin = TxOutputBinType()
|
||||
txo_bin.amount = txo.amount
|
||||
txo_bin.script_pubkey = self.output_derive_script(txo)
|
||||
|
||||
if i == 0: # serializing first output => prepend outputs count
|
||||
writers.write_varint(self.serialized_tx, self.tx.outputs_count)
|
||||
writers.write_tx_output(self.serialized_tx, txo_bin)
|
||||
|
||||
async def get_prevtx_output_value(self, prev_hash: bytes, prev_index: int) -> int:
|
||||
|
Loading…
Reference in New Issue
Block a user