Skip to content

Commit 749031e

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add method to get unsigned txid from psbt
Added `unsignedTxid` method to BitGoPsbt class, which returns the transaction ID of the unsigned transaction contained in the PSBT. Added tests to verify the method works correctly. Issue: BTC-2652 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 58ddf16 commit 749031e

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

packages/wasm-utxo/js/fixedScriptWallet.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export class BitGoPsbt {
9494
return new BitGoPsbt(wasm);
9595
}
9696

97+
/**
98+
* Get the unsigned transaction ID
99+
* @returns The unsigned transaction ID
100+
*/
101+
unsignedTxid(): string {
102+
return this.wasm.unsigned_txid();
103+
}
104+
97105
/**
98106
* Parse transaction with wallet keys to identify wallet inputs/outputs
99107
* @param walletKeys - The wallet keys to use for identification

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod sighash;
1313
mod zcash_psbt;
1414

1515
use crate::Network;
16-
use miniscript::bitcoin::{psbt::Psbt, secp256k1, CompressedPublicKey};
16+
use miniscript::bitcoin::{psbt::Psbt, secp256k1, CompressedPublicKey, Txid};
1717
pub use propkv::{BitGoKeyValue, ProprietaryKeySubtype, BITGO};
1818
pub use sighash::validate_sighash_type;
1919
use zcash_psbt::ZcashPsbt;
@@ -319,6 +319,11 @@ impl BitGoPsbt {
319319
}
320320
}
321321

322+
/// Get the unsigned transaction ID
323+
pub fn unsigned_txid(&self) -> Txid {
324+
self.psbt().unsigned_tx.compute_txid()
325+
}
326+
322327
/// Helper function to create a MuSig2 context for an input
323328
///
324329
/// This validates that:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ impl BitGoPsbt {
147147
Ok(BitGoPsbt { psbt })
148148
}
149149

150+
/// Get the unsigned transaction ID
151+
pub fn unsigned_txid(&self) -> String {
152+
self.psbt.unsigned_txid().to_string()
153+
}
154+
150155
/// Parse transaction with wallet keys to identify wallet inputs/outputs
151156
pub fn parse_transaction_with_wallet_keys(
152157
&self,

packages/wasm-utxo/test/fixedScript/parseTransactionWithWalletKeys.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ describe("parseTransactionWithWalletKeys", function () {
8888
rootWalletKeys = loadWalletKeysFromFixture(networkName);
8989
});
9090

91+
it("should have matching unsigned transaction ID", function () {
92+
const unsignedTxid = bitgoPsbt.unsignedTxid();
93+
const expectedUnsignedTxid = utxolib.bitgo
94+
.createPsbtFromBuffer(psbtBytes, network)
95+
.getUnsignedTx()
96+
.getId();
97+
assert.strictEqual(unsignedTxid, expectedUnsignedTxid);
98+
});
99+
91100
it("should parse transaction and identify internal/external outputs", function () {
92101
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
93102
outputScripts: [replayProtectionScript],

0 commit comments

Comments
 (0)