mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-17 01:52:02 +00:00
Signing for Segnet Transaction works
see segnet4 txid: aa434a6ef4fcf350e319bacbd725fa7446f797cb3ed0cd0582826a49d3351ffa
This commit is contained in:
parent
e5000fb196
commit
b7b9891cb4
@ -783,6 +783,10 @@ void signing_txack(TransactionType *tx)
|
||||
if (tx->inputs[0].script_type != InputScriptType_SPENDWADDRESS
|
||||
&& tx->inputs[0].script_type != InputScriptType_SPENDWMULTISIG) {
|
||||
// empty witness
|
||||
resp.has_serialized = true;
|
||||
resp.serialized.has_signature_index = false;
|
||||
resp.serialized.has_signature = false;
|
||||
resp.serialized.has_serialized_tx = true;
|
||||
resp.serialized.serialized_tx.bytes[0] = 0;
|
||||
resp.serialized.serialized_tx.size = 1;
|
||||
} else {
|
||||
@ -805,10 +809,12 @@ void signing_txack(TransactionType *tx)
|
||||
tx_prevout_hash(&hashers[0], &tx->inputs[0]);
|
||||
tx_script_hash(&hashers[0], tx->inputs[0].script_sig.size, tx->inputs[0].script_sig.bytes);
|
||||
sha256_Update(&hashers[0], (const uint8_t*) &tx->inputs[0].amount, 8);
|
||||
tx_sequence_hash(&hashers[0], &tx->inputs[0]);
|
||||
sha256_Update(&hashers[0], hash_outputs, 32);
|
||||
sha256_Update(&hashers[0], (const uint8_t*) &lock_time, 4);
|
||||
sha256_Update(&hashers[0], (const uint8_t*) &sighash, 4);
|
||||
sha256_Final(&hashers[0], hash);
|
||||
sha256_Raw(hash, 32, hash);
|
||||
|
||||
resp.has_serialized = true;
|
||||
resp.serialized.has_signature_index = true;
|
||||
@ -825,7 +831,7 @@ void signing_txack(TransactionType *tx)
|
||||
return;
|
||||
}
|
||||
// fill in the signature
|
||||
int pubkey_idx = cryptoMultisigPubkeyIndex(&(input.multisig), pubkey);
|
||||
int pubkey_idx = cryptoMultisigPubkeyIndex(&(input.multisig), node.public_key);
|
||||
if (pubkey_idx < 0) {
|
||||
fsm_sendFailure(FailureType_Failure_Other, "Pubkey not found in multisig script");
|
||||
signing_abort();
|
||||
@ -838,7 +844,8 @@ void signing_txack(TransactionType *tx)
|
||||
r += ser_length(input.multisig.signatures_count + 2, resp.serialized.serialized_tx.bytes + r);
|
||||
resp.serialized.serialized_tx.bytes[r] = 0; r++;
|
||||
for (i = 0; i < input.multisig.signatures_count; i++) {
|
||||
r += tx_serialize_script(input.multisig.signatures[i].size, input.multisig.signatures[i].bytes, resp.serialized.serialized_tx.bytes + r);
|
||||
input.multisig.signatures[i].bytes[input.multisig.signatures[i].size] = 1;
|
||||
r += tx_serialize_script(input.multisig.signatures[i].size + 1, input.multisig.signatures[i].bytes, resp.serialized.serialized_tx.bytes + r);
|
||||
}
|
||||
script_len = compile_script_multisig(&input.multisig, 0);
|
||||
r += ser_length(script_len, resp.serialized.serialized_tx.bytes + r);
|
||||
@ -848,11 +855,17 @@ void signing_txack(TransactionType *tx)
|
||||
} else { // SPENDWADDRESS
|
||||
uint32_t r = 0;
|
||||
r += ser_length(2, resp.serialized.serialized_tx.bytes + r);
|
||||
r += tx_serialize_script(resp.serialized.signature.size, resp.serialized.signature.bytes, resp.serialized.serialized_tx.bytes + r);
|
||||
resp.serialized.signature.bytes[resp.serialized.signature.size] = 1;
|
||||
r += tx_serialize_script(resp.serialized.signature.size + 1, resp.serialized.signature.bytes, resp.serialized.serialized_tx.bytes + r);
|
||||
r += tx_serialize_script(33, node.public_key, resp.serialized.serialized_tx.bytes + r);
|
||||
resp.serialized.serialized_tx.size = r;
|
||||
}
|
||||
}
|
||||
if (idx1 == inputs_count - 1) {
|
||||
uint32_t r = resp.serialized.serialized_tx.size;
|
||||
r += tx_serialize_footer(&to, resp.serialized.serialized_tx.bytes + r);
|
||||
resp.serialized.serialized_tx.size = r;
|
||||
}
|
||||
// since this took a longer time, update progress
|
||||
layoutProgress("Signing transaction", progress);
|
||||
update_ctr = 0;
|
||||
|
@ -444,7 +444,8 @@ uint32_t tx_serialize_output(TxStruct *tx, const TxOutputBinType *output, uint8_
|
||||
memcpy(out + r, &output->amount, 8); r += 8;
|
||||
r += tx_serialize_script(output->script_pubkey.size, output->script_pubkey.bytes, out + r);
|
||||
tx->have_outputs++;
|
||||
if (tx->have_outputs == tx->outputs_len) {
|
||||
if (tx->have_outputs == tx->outputs_len
|
||||
&& !tx->is_segwit) {
|
||||
r += tx_serialize_footer(tx, out + r);
|
||||
}
|
||||
tx->size += r;
|
||||
@ -467,7 +468,8 @@ uint32_t tx_serialize_output_hash(TxStruct *tx, const TxOutputBinType *output)
|
||||
}
|
||||
r += tx_output_hash(&(tx->ctx), output);
|
||||
tx->have_outputs++;
|
||||
if (tx->have_outputs == tx->outputs_len) {
|
||||
if (tx->have_outputs == tx->outputs_len
|
||||
&& !tx->is_segwit) {
|
||||
r += tx_serialize_footer_hash(tx);
|
||||
}
|
||||
tx->size += r;
|
||||
@ -506,6 +508,7 @@ void tx_init(TxStruct *tx, uint32_t inputs_len, uint32_t outputs_len, uint32_t v
|
||||
tx->extra_data_len = extra_data_len;
|
||||
tx->extra_data_received = 0;
|
||||
tx->size = 0;
|
||||
tx->is_segwit = false;
|
||||
sha256_Init(&(tx->ctx));
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ uint32_t tx_sequence_hash(SHA256_CTX *ctx, const TxInputType *input);
|
||||
uint32_t tx_output_hash(SHA256_CTX *ctx, const TxOutputBinType *output);
|
||||
uint32_t tx_serialize_script(uint32_t size, const uint8_t *data, uint8_t *out);
|
||||
|
||||
uint32_t tx_serialize_footer(TxStruct *tx, uint8_t *out);
|
||||
uint32_t tx_serialize_input(TxStruct *tx, const TxInputType *input, uint8_t *out);
|
||||
uint32_t tx_serialize_output(TxStruct *tx, const TxOutputBinType *output, uint8_t *out);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user