Skip to content
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
7 changes: 6 additions & 1 deletion packages/wasm-utxo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ dist/node/js/wasm/:

.PHONY: dist/browser/js/wasm/
dist/browser/js/wasm/:
$(call BUILD,$@,browser)
$(call BUILD,$@,browser)

.PHONY: lint
lint:
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
140 changes: 35 additions & 105 deletions packages/wasm-utxo/src/bitgo_psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
//! This module provides PSBT deserialization that works across different
//! bitcoin-like networks, including those with non-standard transaction formats.

mod p2tr_musig2_input;
mod propkv;
mod sighash;
mod zcash_psbt;

pub use p2tr_musig2_input::{
parse_musig2_nonces, parse_musig2_partial_sigs, parse_musig2_participants, Musig2Error,
Musig2Input, Musig2PartialSig, Musig2Participants, Musig2PubNonce,
};
pub use sighash::validate_sighash_type;

use crate::{bitgo_psbt::zcash_psbt::ZcashPsbt, networks::Network};
Expand Down Expand Up @@ -184,9 +190,8 @@ mod tests {
}
}

crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, {
test_parse_with_format(fixtures::TxFormat::Psbt, network);
test_parse_with_format(fixtures::TxFormat::PsbtLite, network);
crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, format, {
test_parse_with_format(format, network);
});

#[test]
Expand Down Expand Up @@ -242,9 +247,8 @@ mod tests {
}
}

crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, {
test_round_trip_with_format(fixtures::TxFormat::Psbt, network);
test_round_trip_with_format(fixtures::TxFormat::PsbtLite, network);
crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, format, {
test_round_trip_with_format(format, network);
});

fn parse_derivation_path(path: &str) -> Result<(u32, u32), String> {
Expand Down Expand Up @@ -281,26 +285,6 @@ mod tests {
Ok((chain, index))
}

fn find_input_with_script_type(
fixture: &fixtures::PsbtFixture,
script_type: fixtures::ScriptType,
) -> Result<(usize, &fixtures::PsbtInputFixture), String> {
let result = fixture
.psbt_inputs
.iter()
.enumerate()
.filter(|(_, input)| script_type.matches_fixture(input))
.collect::<Vec<_>>();
if result.len() != 1 {
return Err(format!(
"Expected 1 input with script type {}, got {}",
script_type.as_str(),
result.len()
));
}
Ok(result[0])
}

fn get_output_script_from_non_witness_utxo(
input: &fixtures::P2shInput,
index: usize,
Expand Down Expand Up @@ -343,7 +327,7 @@ mod tests {

// Check if the script type is supported by the network
let output_script_support = network.output_script_support();
let input_fixture = find_input_with_script_type(&fixture, script_type);
let input_fixture = fixture.find_input_with_script_type(script_type);
if !script_type.is_supported_by(&output_script_support) {
// Script type not supported by network - skip test (no fixture expected)
assert!(
Expand Down Expand Up @@ -441,101 +425,47 @@ mod tests {
Ok(())
}

crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, {
test_wallet_script_type(
fixtures::ScriptType::P2sh,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::P2sh,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, format, {
test_wallet_script_type(fixtures::ScriptType::P2sh, network, format).unwrap();
});

crate::test_psbt_fixtures!(test_p2sh_p2wsh_script_generation_from_fixture, network, {
test_wallet_script_type(
fixtures::ScriptType::P2shP2wsh,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::P2shP2wsh,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
});
crate::test_psbt_fixtures!(
test_p2sh_p2wsh_script_generation_from_fixture,
network,
format,
{
test_wallet_script_type(fixtures::ScriptType::P2shP2wsh, network, format).unwrap();
}
);

crate::test_psbt_fixtures!(test_p2wsh_script_generation_from_fixture, network, {
test_wallet_script_type(
fixtures::ScriptType::P2wsh,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::P2wsh,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
});
crate::test_psbt_fixtures!(
test_p2wsh_script_generation_from_fixture,
network,
format,
{
test_wallet_script_type(fixtures::ScriptType::P2wsh, network, format).unwrap();
}
);

crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, {
test_wallet_script_type(
fixtures::ScriptType::P2tr,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::P2tr,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, format, {
test_wallet_script_type(fixtures::ScriptType::P2tr, network, format).unwrap();
});

crate::test_psbt_fixtures!(
test_p2tr_musig2_script_path_generation_from_fixture,
network,
format,
{
test_wallet_script_type(
fixtures::ScriptType::P2trMusig2,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::P2trMusig2,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
test_wallet_script_type(fixtures::ScriptType::P2trMusig2, network, format).unwrap();
}
);

crate::test_psbt_fixtures!(
test_p2tr_musig2_key_path_spend_script_generation_from_fixture,
network,
format,
{
test_wallet_script_type(
fixtures::ScriptType::TaprootKeypath,
network,
fixtures::TxFormat::Psbt,
)
.unwrap();
test_wallet_script_type(
fixtures::ScriptType::TaprootKeypath,
network,
fixtures::TxFormat::PsbtLite,
)
.unwrap();
test_wallet_script_type(fixtures::ScriptType::TaprootKeypath, network, format).unwrap();
}
);

Expand Down
Loading