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
18 changes: 17 additions & 1 deletion packages/wasm-utxo/js/fixedScriptWallet/ZcashBitGoPsbt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BitGoPsbt as WasmBitGoPsbt } from "../wasm/wasm_utxo.js";
import { BitGoPsbt as WasmBitGoPsbt, zcash_branch_id_for_height } from "../wasm/wasm_utxo.js";
import { type WalletKeysArg, RootWalletKeys } from "./RootWalletKeys.js";
import { BitGoPsbt, type CreateEmptyOptions, type HydrationUnspent } from "./BitGoPsbt.js";
import { ZcashTransaction, type ITransaction } from "../transaction.js";
Expand Down Expand Up @@ -264,6 +264,22 @@ export class ZcashBitGoPsbt extends BitGoPsbt {
return this.wasm.expiry_height();
}

/**
* Get the Zcash consensus branch ID stored in the PSBT proprietary map.
* Returns undefined for v5 PSBTs or PSBTs without the key.
*/
get consensusBranchId(): number | undefined {
return this.wasm.consensus_branch_id();
}

/**
* Return the Zcash consensus branch ID active at `height` on `network`.
* Returns undefined if `height` is before Overwinter activation.
*/
static branchIdForHeight(network: ZcashNetworkName, height: number): number | undefined {
return zcash_branch_id_for_height(network, height);
}

/**
* Extract the final Zcash transaction from a finalized PSBT
*
Expand Down
31 changes: 31 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 @@ -961,6 +961,17 @@ impl BitGoPsbt {
}
}

/// Get the Zcash consensus branch ID from the PSBT proprietary map (returns None for non-Zcash PSBTs)
pub fn consensus_branch_id(&self) -> Option<u32> {
use crate::fixed_script_wallet::bitgo_psbt::{
propkv::get_zec_consensus_branch_id, BitGoPsbt as InnerBitGoPsbt,
};
match &self.psbt {
InnerBitGoPsbt::Zcash(z, _) => get_zec_consensus_branch_id(&z.psbt),
_ => None,
}
}

pub fn get_outputs_with_address(&self) -> Result<JsValue, WasmUtxoError> {
crate::wasm::psbt::get_outputs_with_address_from_psbt(self.psbt.psbt(), self.psbt.network())
}
Expand Down Expand Up @@ -1943,3 +1954,23 @@ impl BitGoPsbt {
}

impl_wasm_psbt_ops!(BitGoPsbt, psbt);

/// Return the Zcash consensus branch ID active at `height` on `network`.
///
/// `network`: "zcash" / "zec" for mainnet, "zcashTest" / "tzec" for testnet.
/// Returns `None` if `height` is before Overwinter activation.
/// Throws if `network` is not a recognised Zcash network name.
#[wasm_bindgen]
pub fn zcash_branch_id_for_height(network: &str, height: u32) -> Result<Option<u32>, JsValue> {
let is_mainnet = match network {
"zcash" | "zec" => true,
"zcashTest" | "tzec" => false,
_ => {
return Err(JsValue::from_str(&format!(
"unknown Zcash network {:?}: expected \"zcash\", \"zec\", \"zcashTest\", or \"tzec\"",
network
)))
}
};
Ok(crate::zcash::branch_id_for_height(height, is_mainnet))
}
Loading