Skip to content

Commit 50a5152

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add version info to PSBT proprietary fields
Add set_version_info method to BitGoPsbt that embeds the wasm-utxo version and git hash into the PSBT's proprietary fields. This allows easy identification of which library version processed the PSBT. Issue: BTC-2992 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 2c1c076 commit 50a5152

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • packages/wasm-utxo/src/fixed_script_wallet/bitgo_psbt

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,17 @@ impl BitGoPsbt {
11781178
}
11791179
}
11801180

1181+
/// Set version information in the PSBT's proprietary fields
1182+
///
1183+
/// This embeds the wasm-utxo version and git hash into the PSBT's global
1184+
/// proprietary fields, allowing identification of which library version
1185+
/// processed the PSBT.
1186+
pub fn set_version_info(&mut self) {
1187+
let version_info = WasmUtxoVersionInfo::from_build_info();
1188+
let (key, value) = version_info.to_proprietary_kv();
1189+
self.psbt_mut().proprietary.insert(key, value);
1190+
}
1191+
11811192
pub fn finalize_input<C: secp256k1::Verification>(
11821193
&mut self,
11831194
secp: &secp256k1::Secp256k1<C>,
@@ -4426,4 +4437,33 @@ mod tests {
44264437
.expect("decode extracted tx");
44274438
assert_eq!(decoded.compute_txid(), extracted_tx.compute_txid());
44284439
}
4440+
4441+
#[test]
4442+
fn test_set_version_info() {
4443+
use crate::fixed_script_wallet::test_utils::get_test_wallet_keys;
4444+
use miniscript::bitcoin::psbt::raw::ProprietaryKey;
4445+
4446+
let wallet_keys =
4447+
crate::fixed_script_wallet::RootWalletKeys::new(get_test_wallet_keys("doge_1e19"));
4448+
4449+
let mut psbt = BitGoPsbt::new(Network::Bitcoin, &wallet_keys, Some(2), Some(0));
4450+
4451+
// Set version info
4452+
psbt.set_version_info();
4453+
4454+
// Verify it was set in the proprietary fields
4455+
let version_key = ProprietaryKey {
4456+
prefix: BITGO.to_vec(),
4457+
subtype: ProprietaryKeySubtype::WasmUtxoVersion as u8,
4458+
key: vec![],
4459+
};
4460+
4461+
assert!(psbt.psbt().proprietary.contains_key(&version_key));
4462+
4463+
// Verify the value is correctly formatted
4464+
let value = psbt.psbt().proprietary.get(&version_key).unwrap();
4465+
let version_info = WasmUtxoVersionInfo::from_bytes(value).unwrap();
4466+
assert!(!version_info.version.is_empty());
4467+
assert!(!version_info.git_hash.is_empty());
4468+
}
44294469
}

0 commit comments

Comments
 (0)