Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the use of SigHashType::ALL #1886

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions api-server/stack-test-suite/tests/v2/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async fn multiple_outputs_to_single_address(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -195,7 +195,7 @@ async fn multiple_outputs_to_single_address(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -363,7 +363,7 @@ async fn test_unlocking_for_locked_utxos(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -435,7 +435,7 @@ async fn test_unlocking_for_locked_utxos(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -611,7 +611,7 @@ async fn ok(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -666,7 +666,7 @@ async fn ok(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down
8 changes: 4 additions & 4 deletions api-server/stack-test-suite/tests/v2/address_all_utxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -198,7 +198,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -372,7 +372,7 @@ async fn ok(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -450,7 +450,7 @@ async fn ok(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -200,7 +200,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -374,7 +374,7 @@ async fn ok(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -442,7 +442,7 @@ async fn ok(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction,
&[Some(&previous_tx_out)],
Expand Down
6 changes: 3 additions & 3 deletions api-server/stack-test-suite/tests/v2/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async fn spend(#[case] seed: Seed) {

let input_sign = produce_uniparty_signature_for_htlc_input(
&bob_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash((&PublicKey::from_private_key(&bob_sk)).into()),
&tx2,
&[Some(&tx_1.transaction().outputs()[0])],
Expand Down Expand Up @@ -282,7 +282,7 @@ async fn refund(#[case] seed: Seed) {
AuthorizedClassicalMultisigSpend::new_empty(refund_challenge);

let sighash = signature_hash(
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx2,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand All @@ -301,7 +301,7 @@ async fn refund(#[case] seed: Seed) {
let input_sign = produce_classical_multisig_signature_for_htlc_input(
&chain_config,
&authorization,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx2,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async fn ok(#[case] seed: Seed) {
let sig = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&tx,
&[issue_nft_tx.outputs().first()],
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async fn ok_tokens(#[case] seed: Seed) {
let token_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&mint_transaction,
&[Some(&issue_token_transaction.outputs()[0]), None],
Expand Down
4 changes: 2 additions & 2 deletions api-server/stack-test-suite/tests/v2/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async fn multiple_tx_in_same_block(#[case] seed: Seed) {
let mut previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&signed_tx1,
&[Some(&previous_tx_out)],
Expand Down Expand Up @@ -149,7 +149,7 @@ async fn multiple_tx_in_same_block(#[case] seed: Seed) {
previous_witness = InputWitness::Standard(
StandardInputSignature::produce_uniparty_signature_for_input(
&alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
alice_destination.clone(),
&transaction2,
&[Some(&previous_tx_out)],
Expand Down
9 changes: 3 additions & 6 deletions chainstate/test-framework/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ impl KeyManager {
Destination::AnyoneCanSpend => Some(InputWitness::NoSignature(None)),
Destination::PublicKey(pub_key) => {
let private_key = self.public_keys.get(pub_key).unwrap();
let sighash_type =
SigHashType::try_from(SigHashType::ALL).expect("Should not fail");
let sighash_type = SigHashType::all();

let sig = StandardInputSignature::produce_uniparty_signature_for_input(
private_key,
Expand All @@ -174,8 +173,7 @@ impl KeyManager {
}
Destination::PublicKeyHash(pub_key) => {
let private_key = self.public_key_hashes.get(pub_key).unwrap();
let sighash_type =
SigHashType::try_from(SigHashType::ALL).expect("Should not fail");
let sighash_type = SigHashType::all();

let sig = StandardInputSignature::produce_uniparty_signature_for_input(
private_key,
Expand All @@ -195,8 +193,7 @@ impl KeyManager {
let challenge = multisig.challenge(chain_config);
let mut current_signatures =
AuthorizedClassicalMultisigSpend::new_empty(challenge.clone());
let sighash_type =
SigHashType::try_from(SigHashType::ALL).expect("Should not fail");
let sighash_type = SigHashType::all();

let sighash = signature_hash(sighash_type, tx, inputs_utxos, input_num).unwrap();

Expand Down
34 changes: 15 additions & 19 deletions chainstate/test-suite/src/tests/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn spend_htlc_with_secret(#[case] seed: Seed) {

let input_sign = produce_uniparty_signature_for_htlc_input(
&test_fixture.alice_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash(
(&PublicKey::from_private_key(&test_fixture.alice_sk)).into(),
),
Expand Down Expand Up @@ -191,7 +191,7 @@ fn spend_htlc_with_secret(#[case] seed: Seed) {

let input_sign = StandardInputSignature::produce_uniparty_signature_for_input(
&test_fixture.bob_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash(
(&PublicKey::from_private_key(&test_fixture.bob_sk)).into(),
),
Expand Down Expand Up @@ -239,7 +239,7 @@ fn spend_htlc_with_secret(#[case] seed: Seed) {

let input_sign = produce_uniparty_signature_for_htlc_input(
&test_fixture.bob_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash(
(&PublicKey::from_private_key(&test_fixture.bob_sk)).into(),
),
Expand Down Expand Up @@ -283,7 +283,7 @@ fn spend_htlc_with_secret(#[case] seed: Seed) {

let input_sign = produce_uniparty_signature_for_htlc_input(
&test_fixture.bob_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash((&PublicKey::from_private_key(&test_fixture.bob_sk)).into()),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
Expand Down Expand Up @@ -352,7 +352,7 @@ fn refund_htlc(#[case] seed: Seed) {
AuthorizedClassicalMultisigSpend::new_empty(refund_challenge.clone());

let sighash = signature_hash(
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand All @@ -371,7 +371,7 @@ fn refund_htlc(#[case] seed: Seed) {
let input_sign = produce_classical_multisig_signature_for_htlc_input(
&chain_config,
&authorization,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand Down Expand Up @@ -423,7 +423,7 @@ fn refund_htlc(#[case] seed: Seed) {
AuthorizedClassicalMultisigSpend::new_empty(refund_challenge.clone());

let sighash = signature_hash(
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand All @@ -437,10 +437,8 @@ fn refund_htlc(#[case] seed: Seed) {
AuthorizedHashedTimelockContractSpend::Multisig(authorization.encode())
};

let input_sign = StandardInputSignature::new(
SigHashType::try_from(SigHashType::ALL).unwrap(),
authorization.encode(),
);
let input_sign =
StandardInputSignature::new(SigHashType::all(), authorization.encode());

let result = tf
.make_block_builder()
Expand Down Expand Up @@ -480,7 +478,7 @@ fn refund_htlc(#[case] seed: Seed) {
AuthorizedClassicalMultisigSpend::new_empty(refund_challenge.clone());

let sighash = signature_hash(
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand All @@ -494,10 +492,8 @@ fn refund_htlc(#[case] seed: Seed) {
AuthorizedHashedTimelockContractSpend::Multisig(authorization.encode())
};

let input_sign = StandardInputSignature::new(
SigHashType::try_from(SigHashType::ALL).unwrap(),
authorization.encode(),
);
let input_sign =
StandardInputSignature::new(SigHashType::all(), authorization.encode());

let result = tf
.make_block_builder()
Expand Down Expand Up @@ -535,7 +531,7 @@ fn refund_htlc(#[case] seed: Seed) {
let mut authorization = AuthorizedClassicalMultisigSpend::new_empty(refund_challenge);

let sighash = signature_hash(
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand All @@ -554,7 +550,7 @@ fn refund_htlc(#[case] seed: Seed) {
let input_sign = produce_classical_multisig_signature_for_htlc_input(
&chain_config,
&authorization,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
&tx,
&[Some(&tx_1.transaction().outputs()[0])],
0,
Expand Down Expand Up @@ -843,7 +839,7 @@ fn spend_tokens(#[case] seed: Seed) {

let input_sign = produce_uniparty_signature_for_htlc_input(
&test_fixture.bob_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKeyHash((&PublicKey::from_private_key(&test_fixture.bob_sk)).into()),
&tx,
&[Some(&mint_token_v1_tx.transaction().outputs()[0])],
Expand Down
2 changes: 1 addition & 1 deletion chainstate/test-suite/src/tests/pos_processing_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ fn pos_decommission_genesis_pool(#[case] seed: Seed) {

let input_sign = StandardInputSignature::produce_uniparty_signature_for_input(
&genesis_staking_sk,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKey(genesis_staking_pk),
&tx,
&[Some(input_utxo.output())],
Expand Down
6 changes: 3 additions & 3 deletions chainstate/test-suite/src/tests/processing_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ fn spend_timelocked_signed_output(#[case] seed: Seed) {
let tx = {
let input_sign = StandardInputSignature::produce_uniparty_signature_for_input(
&private_key,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKey(public_key.clone()),
&tx_2,
&[Some(&tx_1.transaction().outputs()[0])],
Expand Down Expand Up @@ -1512,7 +1512,7 @@ fn spend_timelocked_signed_output(#[case] seed: Seed) {
PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
let input_sign = StandardInputSignature::produce_uniparty_signature_for_input(
&random_private_key,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKey(random_public_key),
&tx_2,
&[Some(&tx_1.transaction().outputs()[0])],
Expand Down Expand Up @@ -1540,7 +1540,7 @@ fn spend_timelocked_signed_output(#[case] seed: Seed) {
let tx = {
let input_sign = StandardInputSignature::produce_uniparty_signature_for_input(
&private_key,
SigHashType::try_from(SigHashType::ALL).unwrap(),
SigHashType::all(),
Destination::PublicKey(public_key),
&tx_2,
&[Some(&tx_1.transaction().outputs()[0])],
Expand Down
Loading