Skip to content

Commit 21595bf

Browse files
Merge pull request #24 from BitGo/BTC-2652.p2tr-musig2.finalize.clean
feat(wasm-utxo): add MuSig2 taproot key-path finalization support
2 parents 80e6067 + b35477f commit 21595bf

File tree

53 files changed

+2013
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2013
-114
lines changed

packages/wasm-utxo/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ dist/node/js/wasm/:
4343

4444
.PHONY: dist/browser/js/wasm/
4545
dist/browser/js/wasm/:
46-
$(call BUILD,$@,browser)
46+
$(call BUILD,$@,browser)
47+
48+
.PHONY: lint
49+
lint:
50+
cargo fmt --check
51+
cargo clippy --all-targets --all-features -- -D warnings

packages/wasm-utxo/src/bitgo_psbt/mod.rs

Lines changed: 35 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
//! This module provides PSBT deserialization that works across different
44
//! bitcoin-like networks, including those with non-standard transaction formats.
55
6+
mod p2tr_musig2_input;
7+
mod propkv;
68
mod sighash;
79
mod zcash_psbt;
810

11+
pub use p2tr_musig2_input::{
12+
parse_musig2_nonces, parse_musig2_partial_sigs, parse_musig2_participants, Musig2Error,
13+
Musig2Input, Musig2PartialSig, Musig2Participants, Musig2PubNonce,
14+
};
915
pub use sighash::validate_sighash_type;
1016

1117
use crate::{bitgo_psbt::zcash_psbt::ZcashPsbt, networks::Network};
@@ -184,9 +190,8 @@ mod tests {
184190
}
185191
}
186192

187-
crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, {
188-
test_parse_with_format(fixtures::TxFormat::Psbt, network);
189-
test_parse_with_format(fixtures::TxFormat::PsbtLite, network);
193+
crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, format, {
194+
test_parse_with_format(format, network);
190195
});
191196

192197
#[test]
@@ -242,9 +247,8 @@ mod tests {
242247
}
243248
}
244249

245-
crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, {
246-
test_round_trip_with_format(fixtures::TxFormat::Psbt, network);
247-
test_round_trip_with_format(fixtures::TxFormat::PsbtLite, network);
250+
crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, format, {
251+
test_round_trip_with_format(format, network);
248252
});
249253

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

284-
fn find_input_with_script_type(
285-
fixture: &fixtures::PsbtFixture,
286-
script_type: fixtures::ScriptType,
287-
) -> Result<(usize, &fixtures::PsbtInputFixture), String> {
288-
let result = fixture
289-
.psbt_inputs
290-
.iter()
291-
.enumerate()
292-
.filter(|(_, input)| script_type.matches_fixture(input))
293-
.collect::<Vec<_>>();
294-
if result.len() != 1 {
295-
return Err(format!(
296-
"Expected 1 input with script type {}, got {}",
297-
script_type.as_str(),
298-
result.len()
299-
));
300-
}
301-
Ok(result[0])
302-
}
303-
304288
fn get_output_script_from_non_witness_utxo(
305289
input: &fixtures::P2shInput,
306290
index: usize,
@@ -343,7 +327,7 @@ mod tests {
343327

344328
// Check if the script type is supported by the network
345329
let output_script_support = network.output_script_support();
346-
let input_fixture = find_input_with_script_type(&fixture, script_type);
330+
let input_fixture = fixture.find_input_with_script_type(script_type);
347331
if !script_type.is_supported_by(&output_script_support) {
348332
// Script type not supported by network - skip test (no fixture expected)
349333
assert!(
@@ -441,101 +425,47 @@ mod tests {
441425
Ok(())
442426
}
443427

444-
crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, {
445-
test_wallet_script_type(
446-
fixtures::ScriptType::P2sh,
447-
network,
448-
fixtures::TxFormat::Psbt,
449-
)
450-
.unwrap();
451-
test_wallet_script_type(
452-
fixtures::ScriptType::P2sh,
453-
network,
454-
fixtures::TxFormat::PsbtLite,
455-
)
456-
.unwrap();
428+
crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, format, {
429+
test_wallet_script_type(fixtures::ScriptType::P2sh, network, format).unwrap();
457430
});
458431

459-
crate::test_psbt_fixtures!(test_p2sh_p2wsh_script_generation_from_fixture, network, {
460-
test_wallet_script_type(
461-
fixtures::ScriptType::P2shP2wsh,
462-
network,
463-
fixtures::TxFormat::Psbt,
464-
)
465-
.unwrap();
466-
test_wallet_script_type(
467-
fixtures::ScriptType::P2shP2wsh,
468-
network,
469-
fixtures::TxFormat::PsbtLite,
470-
)
471-
.unwrap();
472-
});
432+
crate::test_psbt_fixtures!(
433+
test_p2sh_p2wsh_script_generation_from_fixture,
434+
network,
435+
format,
436+
{
437+
test_wallet_script_type(fixtures::ScriptType::P2shP2wsh, network, format).unwrap();
438+
}
439+
);
473440

474-
crate::test_psbt_fixtures!(test_p2wsh_script_generation_from_fixture, network, {
475-
test_wallet_script_type(
476-
fixtures::ScriptType::P2wsh,
477-
network,
478-
fixtures::TxFormat::Psbt,
479-
)
480-
.unwrap();
481-
test_wallet_script_type(
482-
fixtures::ScriptType::P2wsh,
483-
network,
484-
fixtures::TxFormat::PsbtLite,
485-
)
486-
.unwrap();
487-
});
441+
crate::test_psbt_fixtures!(
442+
test_p2wsh_script_generation_from_fixture,
443+
network,
444+
format,
445+
{
446+
test_wallet_script_type(fixtures::ScriptType::P2wsh, network, format).unwrap();
447+
}
448+
);
488449

489-
crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, {
490-
test_wallet_script_type(
491-
fixtures::ScriptType::P2tr,
492-
network,
493-
fixtures::TxFormat::Psbt,
494-
)
495-
.unwrap();
496-
test_wallet_script_type(
497-
fixtures::ScriptType::P2tr,
498-
network,
499-
fixtures::TxFormat::PsbtLite,
500-
)
501-
.unwrap();
450+
crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, format, {
451+
test_wallet_script_type(fixtures::ScriptType::P2tr, network, format).unwrap();
502452
});
503453

504454
crate::test_psbt_fixtures!(
505455
test_p2tr_musig2_script_path_generation_from_fixture,
506456
network,
457+
format,
507458
{
508-
test_wallet_script_type(
509-
fixtures::ScriptType::P2trMusig2,
510-
network,
511-
fixtures::TxFormat::Psbt,
512-
)
513-
.unwrap();
514-
test_wallet_script_type(
515-
fixtures::ScriptType::P2trMusig2,
516-
network,
517-
fixtures::TxFormat::PsbtLite,
518-
)
519-
.unwrap();
459+
test_wallet_script_type(fixtures::ScriptType::P2trMusig2, network, format).unwrap();
520460
}
521461
);
522462

523463
crate::test_psbt_fixtures!(
524464
test_p2tr_musig2_key_path_spend_script_generation_from_fixture,
525465
network,
466+
format,
526467
{
527-
test_wallet_script_type(
528-
fixtures::ScriptType::TaprootKeypath,
529-
network,
530-
fixtures::TxFormat::Psbt,
531-
)
532-
.unwrap();
533-
test_wallet_script_type(
534-
fixtures::ScriptType::TaprootKeypath,
535-
network,
536-
fixtures::TxFormat::PsbtLite,
537-
)
538-
.unwrap();
468+
test_wallet_script_type(fixtures::ScriptType::TaprootKeypath, network, format).unwrap();
539469
}
540470
);
541471

0 commit comments

Comments
 (0)