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: 7 additions & 0 deletions packages/wasm-utxo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/wasm-utxo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ miniscript = { git = "https://github.com/BitGo/rust-miniscript", tag = "miniscri
bech32 = "0.11"
musig2 = { version = "0.3.1", default-features = false, features = ["k256"] }
getrandom = { version = "0.2", features = ["js"] }
pastey = "0.1"

[dev-dependencies]
base64 = "0.22.1"
Expand All @@ -28,6 +29,7 @@ serde_json = "1.0"
hex = "0.4"
wasm-bindgen-test = "0.3"
rstest = "0.26.1"
pastey = "0.1"

[profile.release]
# this is required to make webpack happy
Expand Down
155 changes: 143 additions & 12 deletions packages/wasm-utxo/cli/src/parse/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use bitcoin::consensus::Decodable;
use bitcoin::hashes::Hash;
use bitcoin::psbt::Psbt;
use bitcoin::{Network, ScriptBuf, Transaction};
use wasm_utxo::bitgo_psbt::{
BitGoKeyValue, Musig2PartialSig, Musig2Participants, Musig2PubNonce, ProprietaryKeySubtype,
BITGO,
};

pub use crate::node::{Node, Primitive};

Expand Down Expand Up @@ -39,24 +43,151 @@ fn bip32_derivations_to_nodes(
.collect()
}

fn musig2_participants_to_node(participants: &Musig2Participants) -> Node {
let mut node = Node::new("musig2_participants", Primitive::None);
node.add_child(Node::new(
"tap_output_key",
Primitive::Buffer(participants.tap_output_key.serialize().to_vec()),
));
node.add_child(Node::new(
"tap_internal_key",
Primitive::Buffer(participants.tap_internal_key.serialize().to_vec()),
));

let mut participants_node = Node::new("participant_pub_keys", Primitive::U64(2));
for (i, pub_key) in participants.participant_pub_keys.iter().enumerate() {
let pub_key_vec: Vec<u8> = pub_key.to_bytes().to_vec();
participants_node.add_child(Node::new(
format!("participant_{}", i),
Primitive::Buffer(pub_key_vec),
));
}
node.add_child(participants_node);
node
}

fn musig2_pub_nonce_to_node(nonce: &Musig2PubNonce) -> Node {
let mut node = Node::new("musig2_pub_nonce", Primitive::None);
node.add_child(Node::new(
"participant_pub_key",
Primitive::Buffer(nonce.participant_pub_key.to_bytes().to_vec()),
));
node.add_child(Node::new(
"tap_output_key",
Primitive::Buffer(nonce.tap_output_key.serialize().to_vec()),
));
node.add_child(Node::new(
"pub_nonce",
Primitive::Buffer(nonce.pub_nonce.serialize().to_vec()),
));
node
}

fn musig2_partial_sig_to_node(sig: &Musig2PartialSig) -> Node {
let mut node = Node::new("musig2_partial_sig", Primitive::None);
node.add_child(Node::new(
"participant_pub_key",
Primitive::Buffer(sig.participant_pub_key.to_bytes().to_vec()),
));
node.add_child(Node::new(
"tap_output_key",
Primitive::Buffer(sig.tap_output_key.serialize().to_vec()),
));
node.add_child(Node::new(
"partial_sig",
Primitive::Buffer(sig.partial_sig.clone()),
));
node
}

fn bitgo_proprietary_to_node(prop_key: &bitcoin::psbt::raw::ProprietaryKey, v: &[u8]) -> Node {
// Try to parse as BitGo key-value
let v_vec = v.to_vec();
let bitgo_kv_result = BitGoKeyValue::from_key_value(prop_key, &v_vec);

match bitgo_kv_result {
Ok(bitgo_kv) => {
// Parse based on subtype
match bitgo_kv.subtype {
ProprietaryKeySubtype::Musig2ParticipantPubKeys => {
match Musig2Participants::from_key_value(&bitgo_kv) {
Ok(participants) => musig2_participants_to_node(&participants),
Err(_) => {
// Fall back to raw display
raw_proprietary_to_node("musig2_participants_error", prop_key, v)
}
}
}
ProprietaryKeySubtype::Musig2PubNonce => {
match Musig2PubNonce::from_key_value(&bitgo_kv) {
Ok(nonce) => musig2_pub_nonce_to_node(&nonce),
Err(_) => {
// Fall back to raw display
raw_proprietary_to_node("musig2_pub_nonce_error", prop_key, v)
}
}
}
ProprietaryKeySubtype::Musig2PartialSig => {
match Musig2PartialSig::from_key_value(&bitgo_kv) {
Ok(sig) => musig2_partial_sig_to_node(&sig),
Err(_) => {
// Fall back to raw display
raw_proprietary_to_node("musig2_partial_sig_error", prop_key, v)
}
}
}
_ => {
// Other BitGo subtypes - show with name
let subtype_name = match bitgo_kv.subtype {
ProprietaryKeySubtype::ZecConsensusBranchId => "zec_consensus_branch_id",
ProprietaryKeySubtype::PayGoAddressAttestationProof => {
"paygo_address_attestation_proof"
}
ProprietaryKeySubtype::Bip322Message => "bip322_message",
_ => "unknown",
};
raw_proprietary_to_node(subtype_name, prop_key, v)
}
}
}
Err(_) => {
// Not a valid BitGo key-value, show raw
raw_proprietary_to_node("unknown", prop_key, v)
}
}
}

fn raw_proprietary_to_node(
label: &str,
prop_key: &bitcoin::psbt::raw::ProprietaryKey,
v: &[u8],
) -> Node {
let mut prop_node = Node::new(label, Primitive::None);
prop_node.add_child(Node::new(
"prefix",
Primitive::String(String::from_utf8_lossy(&prop_key.prefix).to_string()),
));
prop_node.add_child(Node::new("subtype", Primitive::U8(prop_key.subtype)));
prop_node.add_child(Node::new(
"key_data",
Primitive::Buffer(prop_key.key.to_vec()),
));
prop_node.add_child(Node::new("value", Primitive::Buffer(v.to_vec())));
prop_node
}

fn proprietary_to_nodes(
proprietary: &std::collections::BTreeMap<bitcoin::psbt::raw::ProprietaryKey, Vec<u8>>,
) -> Vec<Node> {
proprietary
.iter()
.map(|(prop_key, v)| {
let mut prop_node = Node::new("key", Primitive::None);
prop_node.add_child(Node::new(
"prefix",
Primitive::String(String::from_utf8_lossy(&prop_key.prefix).to_string()),
));
prop_node.add_child(Node::new("subtype", Primitive::U8(prop_key.subtype)));
prop_node.add_child(Node::new(
"key_data",
Primitive::Buffer(prop_key.key.to_vec()),
));
prop_node.add_child(Node::new("value", Primitive::Buffer(v.to_vec())));
prop_node
// Check if this is a BITGO proprietary key
if prop_key.prefix.as_slice() == BITGO {
bitgo_proprietary_to_node(prop_key, v)
} else {
raw_proprietary_to_node("key", prop_key, v)
}
})
.collect()
}
Expand Down
47 changes: 22 additions & 25 deletions packages/wasm-utxo/cli/test/fixtures/psbt_bitcoin_fullsigned.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,28 @@ psbt: None
│ │ ├─ sighash_type: 0u32
│ │ ├─ sighash_type: SIGHASH_DEFAULT
│ │ └─ proprietary: 5u64
│ │ ├─ key: None
│ │ │ ├─ prefix: BITGO
│ │ │ ├─ subtype: 1u8
│ │ │ ├─ key_data: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16eb5ad29a85aed24de2880e774caaf624f9cb1be09c67ed4aefbb9b7bc12ddf1a (64 bytes)
│ │ │ └─ value: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c53953020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e778171 (66 bytes)
│ │ ├─ key: None
│ │ │ ├─ prefix: BITGO
│ │ │ ├─ subtype: 2u8
│ │ │ ├─ key_data: 020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e77817115c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (65 bytes)
│ │ │ └─ value: 02826949740dff45d408b1f19d94c720f53411e02c525b28ab3c593b6b530fe0370374b8a0ffcaaaee6b772dac5f7c23ef33670b32ec77c6d41efb3c36df2165a094 (66 bytes)
│ │ ├─ key: None
│ │ │ ├─ prefix: BITGO
│ │ │ ├─ subtype: 2u8
│ │ │ ├─ key_data: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c5395315c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (65 bytes)
│ │ │ └─ value: 03a4aaf46f3a0bc39a73855fa875b2f2f04bdb06235afbaedf857b593dddc63cb402cdb7f1a93ec526282198d834423371757e8f43932d03b9f43c3f7378300ae508 (66 bytes)
│ │ ├─ key: None
│ │ │ ├─ prefix: BITGO
│ │ │ ├─ subtype: 3u8
│ │ │ ├─ key_data: 020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e77817115c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (65 bytes)
│ │ │ └─ value: fbdc39c3b8ffca4e6caf3298fa1a4be546b99163c2f21bd374d2254ec5b3c0f4 (32 bytes)
│ │ └─ key: None
│ │ ├─ prefix: BITGO
│ │ ├─ subtype: 3u8
│ │ ├─ key_data: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c5395315c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (65 bytes)
│ │ └─ value: 1cd8a0c0598b0d88f889fdf9a3140f8f088e2187803a2faaee3f13c0163eb76c (32 bytes)
│ │ ├─ musig2_participants: None
│ │ │ ├─ tap_output_key: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (32 bytes)
│ │ │ ├─ tap_internal_key: eb5ad29a85aed24de2880e774caaf624f9cb1be09c67ed4aefbb9b7bc12ddf1a (32 bytes)
│ │ │ └─ participant_pub_keys: 2u64
│ │ │ ├─ participant_0: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c53953 (33 bytes)
│ │ │ └─ participant_1: 020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e778171 (33 bytes)
│ │ ├─ musig2_pub_nonce: None
│ │ │ ├─ participant_pub_key: 020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e778171 (33 bytes)
│ │ │ ├─ tap_output_key: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (32 bytes)
│ │ │ └─ pub_nonce: 02826949740dff45d408b1f19d94c720f53411e02c525b28ab3c593b6b530fe0370374b8a0ffcaaaee6b772dac5f7c23ef33670b32ec77c6d41efb3c36df2165a094 (66 bytes)
│ │ ├─ musig2_pub_nonce: None
│ │ │ ├─ participant_pub_key: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c53953 (33 bytes)
│ │ │ ├─ tap_output_key: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (32 bytes)
│ │ │ └─ pub_nonce: 03a4aaf46f3a0bc39a73855fa875b2f2f04bdb06235afbaedf857b593dddc63cb402cdb7f1a93ec526282198d834423371757e8f43932d03b9f43c3f7378300ae508 (66 bytes)
│ │ ├─ musig2_partial_sig: None
│ │ │ ├─ participant_pub_key: 020fdea69e40a3adef3cdc7fa6f3af02f4c9d9e3254503c96a6a2b4aa66e778171 (33 bytes)
│ │ │ ├─ tap_output_key: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (32 bytes)
│ │ │ └─ partial_sig: fbdc39c3b8ffca4e6caf3298fa1a4be546b99163c2f21bd374d2254ec5b3c0f4 (32 bytes)
│ │ └─ musig2_partial_sig: None
│ │ ├─ participant_pub_key: 021d978a17486ff9e47c82990269e531fc63981419d4ce73ee8bd2c99661c53953 (33 bytes)
│ │ ├─ tap_output_key: 15c5815026f6a54b10194fc6980f1866a02d9ec128533c7997cdb4289bf3ef16 (32 bytes)
│ │ └─ partial_sig: 1cd8a0c0598b0d88f889fdf9a3140f8f088e2187803a2faaee3f13c0163eb76c (32 bytes)
│ └─ input_6: None
│ ├─ non_witness_utxo: 97441d99a8d66f124ab3c9de26b87bd00aeb1547051c842a88165c1b089ee902 (32 bytes)
│ ├─ redeem_script: 210336ef228ffe9b8efffba052c32d334660dd1f8366cf8fe44ae5aa672b6b629095ac (35 bytes)
Expand Down
11 changes: 10 additions & 1 deletion packages/wasm-utxo/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ allow-git = ["https://github.com/BitGo/rust-miniscript"]

# Allow common licenses used in the Rust ecosystem
[licenses]
allow = ["MIT", "Apache-2.0", "CC0-1.0", "MITNFA", "Unicode-DFS-2016", "BSD-3-Clause", "Unlicense"]
allow = [
"MIT",
"Apache-2.0",
"CC0-1.0",
"MITNFA",
"Unicode-DFS-2016",
"Unicode-3.0",
"BSD-3-Clause",
"Unlicense",
]
# Clarify license for unlicensed crate
[[licenses.clarify]]
name = "wasm-utxo"
Expand Down
Loading