Skip to content
Draft
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
54 changes: 54 additions & 0 deletions packages/wasm-utxo/js/fixedScriptWallet/BitGoPsbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
lockTime?: number;
};

/**
* Version information embedded in PSBTs by wasm-utxo
*/
export type WasmUtxoVersionInfo = {
/** The semantic version of wasm-utxo (e.g., "0.0.2") */
version: string;
/** The git commit hash at build time */
gitHash: string;
};

export type AddInputOptions = {
/** Previous transaction ID (hex string) */
txid: string;
Expand Down Expand Up @@ -409,6 +419,50 @@
return this._wasm.lock_time();
}

/**
* Set wasm-utxo version information in the PSBT's proprietary fields
*
* This embeds the wasm-utxo version and git hash into the PSBT's global
* proprietary fields, allowing identification of which library version
* processed the PSBT. The version info is automatically embedded during
* serialization by default, but this method can be called explicitly
* if needed.
*
* @example
* ```typescript
* psbt.setVersionInfo();
* const info = psbt.getVersionInfo();
* console.log(`Built with wasm-utxo ${info?.version} (${info?.gitHash})`);
* ```
*/
setVersionInfo(): void {
this._wasm.set_version_info();
}

/**
* Get wasm-utxo version information from the PSBT's proprietary fields
*
* Returns the version and git hash that was embedded in the PSBT by
* wasm-utxo during processing. Returns undefined if no version info
* is present (e.g., PSBT was created by another library).
*
* @returns Version info object with `version` and `gitHash`, or undefined
*
* @example
* ```typescript
* const info = psbt.getVersionInfo();
* if (info) {
* console.log(`PSBT created by wasm-utxo ${info.version}`);
* } else {
* console.log("PSBT was not processed by wasm-utxo");
* }
* ```
*/
getVersionInfo(): WasmUtxoVersionInfo | undefined {
const info = this._wasm.get_version_info();

Check failure on line 462 in packages/wasm-utxo/js/fixedScriptWallet/BitGoPsbt.ts

View workflow job for this annotation

GitHub Actions / test / Test wasm-utxo

Unsafe assignment of an `any` value
return info === undefined ? undefined : (info as WasmUtxoVersionInfo);
}

/**
* Parse transaction with wallet keys to identify wallet inputs/outputs
* @param walletKeys - The wallet keys to use for identification
Expand Down
1 change: 1 addition & 0 deletions packages/wasm-utxo/js/fixedScriptWallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
type AddOutputOptions,
type AddWalletInputOptions,
type AddWalletOutputOptions,
type WasmUtxoVersionInfo,
} from "./BitGoPsbt.js";

// Zcash-specific PSBT subclass
Expand Down
17 changes: 17 additions & 0 deletions packages/wasm-utxo/src/fixed_script_wallet/bitgo_psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,23 @@ impl BitGoPsbt {
self.psbt_mut().proprietary.insert(key, value);
}

/// Get version information from the PSBT's proprietary fields
///
/// Returns the wasm-utxo version and git hash that was embedded in the PSBT,
/// or None if no version info is present.
pub fn get_version_info(&self) -> Option<WasmUtxoVersionInfo> {
use miniscript::bitcoin::psbt::raw::ProprietaryKey;
let key = ProprietaryKey {
prefix: BITGO.to_vec(),
subtype: ProprietaryKeySubtype::WasmUtxoVersion as u8,
key: vec![],
};
self.psbt()
.proprietary
.get(&key)
.and_then(|value| WasmUtxoVersionInfo::from_bytes(value).ok())
}

pub fn finalize_input<C: secp256k1::Verification>(
&mut self,
secp: &secp256k1::Secp256k1<C>,
Expand Down
25 changes: 25 additions & 0 deletions packages/wasm-utxo/src/wasm/fixed_script_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,31 @@ impl BitGoPsbt {
}
}

/// Set wasm-utxo version information in the PSBT's proprietary fields
///
/// This embeds the wasm-utxo version and git hash into the PSBT's global
/// proprietary fields, allowing identification of which library version
/// processed the PSBT.
pub fn set_version_info(&mut self) {
self.psbt.set_version_info();
}

/// Get wasm-utxo version information from the PSBT's proprietary fields
///
/// Returns an object with `version` and `gitHash` fields, or undefined
/// if no version info is present in the PSBT.
pub fn get_version_info(&self) -> JsValue {
match self.psbt.get_version_info() {
Some(info) => {
let obj = js_sys::Object::new();
js_sys::Reflect::set(&obj, &"version".into(), &info.version.into()).unwrap();
js_sys::Reflect::set(&obj, &"gitHash".into(), &info.git_hash.into()).unwrap();
obj.into()
}
None => JsValue::UNDEFINED,
}
}

/// Parse transaction with wallet keys to identify wallet inputs/outputs
pub fn parse_transaction_with_wallet_keys(
&self,
Expand Down
Loading