@babylonlabs-io/ts-sdk 0.75.0 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,6 +80,13 @@ pnpm add @babylonlabs-io/babylon-tbv-rust-wasm
80
80
  The source manifest uses `workspace:*` for the WASM peer. The release process
81
81
  replaces it with the exact engine version used in the release rehearsal.
82
82
 
83
+ ### Raw engine access is deprecated
84
+
85
+ `loadRawTbvWasm()` and the engine's `/raw` classes bypass SDK value checks.
86
+ Use the transaction builders in `@babylonlabs-io/ts-sdk/tbv/core/primitives`.
87
+ See the [migration guide](./docs/guides/raw-engine-migration.md) for supported
88
+ paths and remaining compatibility blockers. The raw API remains available.
89
+
83
90
  ### ECC Library Initialization (Bitcoin flows only)
84
91
 
85
92
  ETH-only consumers do not need an ECC library. If your application uses the
@@ -6,7 +6,7 @@
6
6
  * for unauthenticated status reads and polling that must remain usable in an
7
7
  * Ethereum-only application session.
8
8
  *
9
- * @module clients/vault-provider/status
9
+ * @module tbv/core/clients/vault-provider/status
10
10
  */
11
11
  export { VaultProviderRpcClient } from '../api';
12
12
  export type { VaultProviderRpcClientOptions } from '../api';
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load the explicit raw-class entry for the one SDK primitive that must\n * reconstruct a stateful WASM transaction object (refund construction).\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen — owned by btc-vault Rust via the vault-wasm pin (`VAULT_WASM_COMMIT`); rotation breaks VP auth for existing deposits.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen — owned by btc-vault Rust; rotation means affected vaults can never activate.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen — owned by btc-vault Rust; rotation breaks existing `depositorWotsPkHash` → no claim path.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","HEX_CHARS_PER_BYTE","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"2hBAQO,MAAMA,EACX,mEAEIC,EAAqB,EAEdC,EAAoB,WAAW,KAC1C,CAAE,OAAQF,EAAiB,OAASC,CAAA,EACpC,CAACE,EAAGC,IACF,OAAO,SACLJ,EAAiB,MACfI,EAAQH,EACRG,EAAQH,EAAqBA,CAAA,EAE/B,EAAA,CAEN,ECSA,IAAII,EAGAC,EAGG,SAASC,GAAsC,CACpD,OAAAF,MAAsB,OAAO,uCAAuC,EAAE,MACnEG,GAAmB,CAClB,MAAAH,EAAoB,OACd,IAAI,MACR,wOAIA,CAAE,MAAOG,CAAA,CAAM,CAEnB,CAAA,GAEKH,CACT,CAMO,SAASI,GAA4C,CAC1D,OAAAH,MAAyB,OAAO,2CAA2C,EACxE,MAAOE,GAAmB,CACzB,MAAAF,EAAuB,OACjB,IAAI,MACR,6LAGA,CAAE,MAAOE,CAAA,CAAM,CAEnB,CAAC,EACA,KAAK,MAAOE,GAAS,CACpB,GAAI,CACF,MAAMA,EAAK,SAAA,CACb,OAASF,EAAgB,CACvB,MAAAF,EAAuB,OACjB,IAAI,MACR,qFAEA,CAAE,MAAOE,CAAA,CAAM,CAEnB,CACA,OAAOE,CACT,CAAC,GACIJ,CACT,CAkBA,eAAsBK,EACpBC,EACyB,CACzB,OAAQ,MAAML,KAAe,0BAA0BK,CAAM,CAC/D,CAcA,eAAsBC,EACpBD,EACAE,EACAC,EACAC,EACwB,CACxB,OAAQ,MAAMT,KAAe,yBAC3BK,EACAE,EACAC,EACAC,CAAA,CAEJ,CAYA,eAAsBC,EACpBL,EAC4B,CAC5B,OAAQ,MAAML,KAAe,6BAA6BK,CAAM,CAClE,CAQA,eAAsBM,EACpBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACiB,CACjB,OAAQ,MAAMjB,KAAe,qBAC3BY,EACAC,EACAC,EACAC,EACAC,EACAC,CAAA,CAEJ,CAYA,eAAsBC,EACpBN,EACAO,E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
+ {"version":3,"file":"index.cjs","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load and initialize the raw engine classes. This bypasses SDK value checks.\n * The internal refund builder applies equivalent checks at its call site.\n *\n * @deprecated Use buildPrePeginPsbt, buildPeginTxFromFundedPrePegin, or\n * buildRefundPsbt from @babylonlabs-io/ts-sdk/tbv/core/primitives.\n * Raw callers must independently check transaction values and signing data.\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","HEX_CHARS_PER_BYTE","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"2hBAQO,MAAMA,EACX,mEAEIC,EAAqB,EAEdC,EAAoB,WAAW,KAC1C,CAAE,OAAQF,EAAiB,OAASC,CAAA,EACpC,CAACE,EAAGC,IACF,OAAO,SACLJ,EAAiB,MACfI,EAAQH,EACRG,EAAQH,EAAqBA,CAAA,EAE/B,EAAA,CAEN,ECSA,IAAII,EAGAC,EAGG,SAASC,GAAsC,CACpD,OAAAF,MAAsB,OAAO,uCAAuC,EAAE,MACnEG,GAAmB,CAClB,MAAAH,EAAoB,OACd,IAAI,MACR,wOAIA,CAAE,MAAOG,CAAA,CAAM,CAEnB,CAAA,GAEKH,CACT,CAUO,SAASI,GAA4C,CAC1D,OAAAH,MAAyB,OAAO,2CAA2C,EACxE,MAAOE,GAAmB,CACzB,MAAAF,EAAuB,OACjB,IAAI,MACR,6LAGA,CAAE,MAAOE,CAAA,CAAM,CAEnB,CAAC,EACA,KAAK,MAAOE,GAAS,CACpB,GAAI,CACF,MAAMA,EAAK,SAAA,CACb,OAASF,EAAgB,CACvB,MAAAF,EAAuB,OACjB,IAAI,MACR,qFAEA,CAAE,MAAOE,CAAA,CAAM,CAEnB,CACA,OAAOE,CACT,CAAC,GACIJ,CACT,CAkBA,eAAsBK,EACpBC,EACyB,CACzB,OAAQ,MAAML,KAAe,0BAA0BK,CAAM,CAC/D,CAcA,eAAsBC,EACpBD,EACAE,EACAC,EACAC,EACwB,CACxB,OAAQ,MAAMT,KAAe,yBAC3BK,EACAE,EACAC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CACrB,OAAQ,MAAMT,EAAA,GAAe,qBAAqBqC,EAAM5B,CAAQ,CAClE,CAOA,eAAsB8B,EACpBF,EACA5B,EACqB,CACrB,OAAQ,MAAMT,EAAA,GAAe,eAAeqC,EAAM5B,CAAQ,CAC5D,CAYA,eAAsB+B,EACpBC,EACAC,EACiB,CACjB,OAAQ,MAAM1C,EAAA,GAAe,cAAcyC,EAAaC,CAAS,CACnE"}
@@ -5,8 +5,12 @@ type RawTbvWasmModule = typeof import("@babylonlabs-io/babylon-tbv-rust-wasm/raw
5
5
  /** Load the WASM engine on first use and share the in-flight import. */
6
6
  export declare function loadTbvWasm(): Promise<TbvWasmModule>;
7
7
  /**
8
- * Load the explicit raw-class entry for the one SDK primitive that must
9
- * reconstruct a stateful WASM transaction object (refund construction).
8
+ * Load and initialize the raw engine classes. This bypasses SDK value checks.
9
+ * The internal refund builder applies equivalent checks at its call site.
10
+ *
11
+ * @deprecated Use buildPrePeginPsbt, buildPeginTxFromFundedPrePegin, or
12
+ * buildRefundPsbt from @babylonlabs-io/ts-sdk/tbv/core/primitives.
13
+ * Raw callers must independently check transaction values and signing data.
10
14
  */
11
15
  export declare function loadRawTbvWasm(): Promise<RawTbvWasmModule>;
12
16
  /**
@@ -151,29 +155,20 @@ export declare function getAssertNoPayoutScriptInfo(params: AssertPayoutNoPayout
151
155
  export declare function getChallengeAssertScriptInfo(params: ChallengeAssertConnectorParams): Promise<ChallengeAssertScriptInfo>;
152
156
  /**
153
157
  * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).
154
- * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.
155
- */
156
- /**
157
- * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).
158
- * @stability frozen — owned by btc-vault Rust via the vault-wasm pin (`VAULT_WASM_COMMIT`); rotation breaks VP auth for existing deposits.
158
+ * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).
159
+ * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.
159
160
  */
160
161
  export declare function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array>;
161
162
  /**
162
163
  * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).
163
- * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.
164
- */
165
- /**
166
- * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).
167
- * @stability frozen — owned by btc-vault Rust; rotation means affected vaults can never activate.
164
+ * @stability frozen - btc-vault Rust owns this API.
165
+ * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.
168
166
  */
169
167
  export declare function expandHashlockSecret(root: Uint8Array, htlcVout: number): Promise<Uint8Array>;
170
168
  /**
171
169
  * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).
172
- * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.
173
- */
174
- /**
175
- * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).
176
- * @stability frozen — owned by btc-vault Rust; rotation breaks existing `depositorWotsPkHash` → no claim path.
170
+ * @stability frozen - btc-vault Rust owns this API.
171
+ * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.
177
172
  */
178
173
  export declare function expandWotsSeed(root: Uint8Array, htlcVout: number): Promise<Uint8Array>;
179
174
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/wasm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,mCAAmC,EACnC,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAm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;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;GAGG;AACH;;;GAGG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,YAAY,EACV,wBAAwB,EACxB,mCAAmC,EACnC,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/wasm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,mCAAmC,EACnC,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,EACf,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAElE,KAAK,aAAa,GAAG,cAAc,uCAAuC,CAAC,CAAC;AAG5E,KAAK,gBAAgB,GACnB,cAAc,2CAA2C,CAAC,CAAC;AAG7D,wEAAwE;AACxE,wBAAgB,WAAW,IAAI,OAAO,CAAC,aAAa,CAAC,CAcpD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAAC,gBAAgB,CAAC,CA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iB,EACjB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load the explicit raw-class entry for the one SDK primitive that must\n * reconstruct a stateful WASM transaction object (refund construction).\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen — owned by btc-vault Rust via the vault-wasm pin (`VAULT_WASM_COMMIT`); rotation breaks VP auth for existing deposits.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen — owned by btc-vault Rust; rotation means affected vaults can never activate.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen — forwards the frozen expander in `@babylonlabs-io/babylon-tbv-rust-wasm`; see CLAUDE.md §4.\n */\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen — owned by btc-vault Rust; rotation breaks existing `depositorWotsPkHash` → no claim path.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"AAQO,MAAMA,IACX;AAIK,MAAMC,IAAoB,WAAW;AAAA,EAC1C,EAAE,QAAQD,EAAiB,SAAS,EAAA;AAAA,EACpC,CAACE,GAAGC,MACF,OAAO;AAAA,IACLH,EAAiB;AAAA,MACfG,IAAQ;AAAA,MACRA,IAAQ,IAAqB;AAAA,IAAA;AAAA,IAE/B;AAAA,EAAA;AAEN;ACSA,IAAIC,GAGAC;AAGG,SAASC,IAAsC;AACpD,SAAAF,UAAsB,OAAO,uCAAuC,EAAE;AAAA,IACpE,CAACG,MAAmB;AAClB,YAAAH,IAAoB,QACd,IAAI;AAAA,QACR;AAAA,QAIA,EAAE,OAAOG,EAAA;AAAA,MAAM;AAAA,IAEnB;AAAA,EAAA,IAEKH;AACT;AAMO,SAASI,IAA4C;AAC1D,SAAAH,UAAyB,OAAO,2CAA2C,EACxE,MAAM,CAACE,MAAmB;AACzB,UAAAF,IAAuB,QACjB,IAAI;AAAA,MACR;AAAA,M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Z,KAAe,qBAAqBY,CAAc;AAClE;AAQA,eAAsBgB,EACpBhB,GACAiB,GACe;AACf,UAAQ,MAAM7B,EAAA,GAAe,uBAAuBY,GAAgBiB,CAAK;AAC3E;AAYA,eAAsBC,EACpBzB,GACA0B,GAC8B;AAC9B,UAAQ,MAAM/B,EAAA,GAAe,sBAAsBK,GAAQ0B,CAAO;AACpE;AAUA,eAAsBC,EACpB3B,GACiC;AACjC,UAAQ,MAAML,KAAe,0BAA0BK,CAAM;AAC/D;AAYA,eAAsB4B,EACpB5B,GACA6B,GACmC;AACnC,UAAQ,MAAMlC,KAAe;AAAA,IAC3BK;AAAA,IACA6B;AAAA,EAAA;AAEJ;AAYA,eAAsBC,EACpB9B,GACoC;AACpC,UAAQ,MAAML,KAAe,6BAA6BK,CAAM;AAClE;AAUA,eAAsB+B,EAAiBC,GAAuC;AAC5E,UAAQ,MAAMrC,KAAe,iBAAiBqC,CAAI;AACpD;AAUA,eAAsBC,EACpBD,GACA5B,GACqB;AACrB,UAAQ,MAAMT,EAAA,GAAe,qBAAqBqC,GAAM5B,CAAQ;AAClE;AAUA,eAAsB8B,EACpBF,GACA5B,GACqB;AACrB,UAAQ,MAAMT,EAAA,GAAe,eAAeqC,GAAM5B,CAAQ;AAC5D;AAYA,eAAsB+B,EACpBC,GACAC,GACiB;AACjB,UAAQ,MAAM1C,EAAA,GAAe,cAAcyC,GAAaC,CAAS;AACnE;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/tbv/core/wasm/constants.ts","../../../../src/tbv/core/wasm/index.ts"],"sourcesContent":["/**\n * Protocol constants that do not require loading the vault WASM module.\n *\n * Keeping these values local lets Bitcoin builders construct PSBT metadata\n * without resolving or evaluating the WASM engine at module-import\n * time. The hex value is the BIP-341 nothing-up-my-sleeve internal key and is\n * pinned by the vault protocol.\n */\nexport const TAP_INTERNAL_KEY =\n \"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0\";\n\nconst HEX_CHARS_PER_BYTE = 2;\n\nexport const tapInternalPubkey = Uint8Array.from(\n { length: TAP_INTERNAL_KEY.length / HEX_CHARS_PER_BYTE },\n (_, index) =>\n Number.parseInt(\n TAP_INTERNAL_KEY.slice(\n index * HEX_CHARS_PER_BYTE,\n index * HEX_CHARS_PER_BYTE + HEX_CHARS_PER_BYTE,\n ),\n 16,\n ),\n);\n","/**\n * Explicit lazy boundary around the vault-WASM engine package.\n *\n * Importing the SDK (including its legacy root barrels) does not resolve the\n * WASM package or generated binary. The engine is loaded only when a caller\n * invokes an operation that actually needs the Bitcoin transaction graph.\n * ETH-only entry points never import this module.\n *\n * @module tbv/core/wasm\n */\n\nimport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\n\nexport { TAP_INTERNAL_KEY, tapInternalPubkey } from \"./constants\";\n\ntype TbvWasmModule = typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm\");\n\nlet wasmModulePromise: Promise<TbvWasmModule> | undefined;\ntype RawTbvWasmModule =\n typeof import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\");\nlet rawWasmModulePromise: Promise<RawTbvWasmModule> | undefined;\n\n/** Load the WASM engine on first use and share the in-flight import. */\nexport function loadTbvWasm(): Promise<TbvWasmModule> {\n wasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm\").catch(\n (error: unknown) => {\n wasmModulePromise = undefined;\n throw new Error(\n \"The vault-WASM engine @babylonlabs-io/babylon-tbv-rust-wasm failed \" +\n \"to load. The module could not be resolved, or it threw while \" +\n \"evaluating, commonly a missing or stale generated WASM build. \" +\n \"See the cause for the underlying error.\",\n { cause: error },\n );\n },\n );\n return wasmModulePromise;\n}\n\n/**\n * Load and initialize the raw engine classes. This bypasses SDK value checks.\n * The internal refund builder applies equivalent checks at its call site.\n *\n * @deprecated Use buildPrePeginPsbt, buildPeginTxFromFundedPrePegin, or\n * buildRefundPsbt from @babylonlabs-io/ts-sdk/tbv/core/primitives.\n * Raw callers must independently check transaction values and signing data.\n */\nexport function loadRawTbvWasm(): Promise<RawTbvWasmModule> {\n rawWasmModulePromise ??= import(\"@babylonlabs-io/babylon-tbv-rust-wasm/raw\")\n .catch((error: unknown) => {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry @babylonlabs-io/babylon-tbv-rust-wasm/raw \" +\n \"failed to load. The module could not be resolved, or it threw \" +\n \"while evaluating. See the cause for the underlying error.\",\n { cause: error },\n );\n })\n .then(async (wasm) => {\n try {\n await wasm.initWasm();\n } catch (error: unknown) {\n rawWasmModulePromise = undefined;\n throw new Error(\n \"The raw vault-WASM entry resolved but its WebAssembly \" +\n \"binary failed to initialize.\",\n { cause: error },\n );\n }\n return wasm;\n });\n return rawWasmModulePromise;\n}\n\n/**\n * Creates an unfunded Pre-PegIn transaction with no inputs and HTLC output(s).\n *\n * The HTLC output value (htlcValue) covers the peg-in amount, depositor claim value,\n * and minimum pegin fee — all computed internally from the provided contract parameters.\n *\n * After building the Pre-PegIn transaction, the caller must:\n * 1. Select UTXOs covering htlcValue + network fees\n * 2. Fund the transaction (add inputs and change output)\n * 3. Call reconstructFromFundedTx() with the funded tx hex\n * 4. Call buildPeginTx() to derive the PegIn transaction\n * 5. Sign the PegIn input using the HTLC hashlock leaf (leaf 0)\n *\n * @param params - Pre-PegIn parameters from contract and depositor wallet\n * @returns Unfunded transaction details with HTLC output information\n */\nexport async function createPrePeginTransaction(\n params: PrePeginParams,\n): Promise<PrePeginResult> {\n return (await loadTbvWasm()).createPrePeginTransaction(params);\n}\n\n/**\n * Derives the PegIn transaction from a funded Pre-PegIn transaction.\n *\n * The PegIn transaction has a single input spending the Pre-PegIn HTLC output\n * at `htlcVout` via the hashlock + all-party script (leaf 0).\n *\n * @param params - Same PrePeginParams used to create the Pre-PegIn transaction\n * @param timelockPegin - CSV timelock in blocks for the PegIn vault output\n * @param fundedPrePeginTxHex - Hex-encoded funded Pre-PegIn transaction\n * @param htlcVout - Index of the HTLC output to spend\n * @returns PegIn transaction details including vault output information\n */\nexport async function buildPeginTxFromPrePegin(\n params: PrePeginParams,\n timelockPegin: number,\n fundedPrePeginTxHex: string,\n htlcVout: number,\n): Promise<PeginTxResult> {\n return (await loadTbvWasm()).buildPeginTxFromPrePegin(\n params,\n timelockPegin,\n fundedPrePeginTxHex,\n htlcVout,\n );\n}\n\n/**\n * Returns HTLC connector script info for signing the PegIn transaction input.\n *\n * The depositor signs PegIn input 0 using the hashlock leaf (leaf 0) of the\n * Pre-PegIn HTLC output. Use getHashlockScript() and getHashlockControlBlock()\n * to construct the tapLeafScript entry in the PSBT.\n *\n * @param params - HTLC connector parameters (subset of PrePeginParams)\n * @returns Hashlock and refund script info for PSBT construction\n */\nexport async function getPrePeginHtlcConnectorInfo(\n params: HtlcConnectorParams,\n): Promise<HtlcConnectorInfo> {\n return (await loadTbvWasm()).getPrePeginHtlcConnectorInfo(params);\n}\n\n/**\n * Compute the minimum depositor claim value (PegIn output 1) in satoshis.\n *\n * This covers the full downstream tx graph cost (Claim → Assert → Payout)\n * based on the protocol parameters.\n */\nexport async function computeMinClaimValue(\n txGraphVersion: number,\n numLocalChallengers: number,\n numUniversalChallengers: number,\n councilQuorum: number,\n councilSize: number,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinClaimValue(\n txGraphVersion,\n numLocalChallengers,\n numUniversalChallengers,\n councilQuorum,\n councilSize,\n feeRate,\n );\n}\n\n/**\n * Compute the minimum PegIn (activation) transaction fee in satoshis.\n *\n * `minPeginFee = peginTxVsize(numVks, numUcs) × minPeginFeeRate`. Each HTLC\n * the depositor funds in the Pre-PegIn tx must reserve at least this fee\n * inside its value (`htlcValue = peginAmount + depositorClaimValue +\n * minPeginFee`), otherwise the VP cannot afford to broadcast the PegIn at\n * activation. The vsize comes from a Taproot script-path-spend weight\n * prediction whose witness shape depends on the VK + UC signer count.\n */\nexport async function computeMinPeginFee(\n txGraphVersion: number,\n numVks: number,\n numUcs: number,\n minPeginFeeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computeMinPeginFee(\n txGraphVersion,\n numVks,\n numUcs,\n minPeginFeeRate,\n );\n}\n\n/**\n * Floor of the Payout transaction fee under `txGraphVersion`: the minimum of\n * `estimatedVsize * feeRate` across every output-sizing model a deployed\n * vault provider is known to have used (fixed-34, intermediate,\n * script-aware). A VP-built payout paying less than this is provably not\n * produced by any known VP build. `out0Len` must be the TRUSTED length of the\n * pinned outs[0] script (1..=128); `out1Len` is the measured, UNTRUSTED\n * commission-script length — safe here because padding cannot raise the floor\n * (the fixed-34 model saturates the minimum) and shortening only lowers it.\n * Pass `undefined` for `out1Len` on 2-output (non-VP-claimer) payouts.\n * `feeRate` is the vault's version-locked `offchainParams.feeRate`.\n */\nexport async function computePayoutFeeFloor(\n txGraphVersion: number,\n numVaultKeepers: number,\n numUniversalChallengers: number,\n numLocalChallengers: number,\n councilSize: number,\n out0Len: number,\n out1Len: number | null | undefined,\n feeRate: bigint,\n): Promise<bigint> {\n return (await loadTbvWasm()).computePayoutFeeFloor(\n txGraphVersion,\n numVaultKeepers,\n numUniversalChallengers,\n numLocalChallengers,\n councilSize,\n out0Len,\n out1Len,\n feeRate,\n );\n}\n\n/**\n * Tx graph versions the shipped vault-wasm binary can build. Callers must\n * preflight the required version (fresh: active; resume: stamped) against\n * this list and fail closed instead of hitting per-call errors mid-flow.\n *\n * Note: the facade constructors themselves fail closed on unsupported\n * versions, and derived objects carry the version they were built with —\n * value-level cross-checks live in `assertWasmPeginSizing` and the golden\n * byte-parity tests, not in a per-call version echo.\n */\nexport async function supportedTxGraphVersions(): Promise<number[]> {\n return (await loadTbvWasm()).supportedTxGraphVersions();\n}\n\n/**\n * The PegIn transaction's P2A (pay-to-anchor) output for a graph version, or\n * `null` when that version's PegIn carries no anchor (v1). The facade returns\n * one record per version — never a zero-valued placeholder — so an absent\n * anchor can't be mistaken for a real output. For v2/v3: 240 sats at vout 2,\n * script `51024e73`.\n */\nexport async function peginP2aAnchorOutput(\n txGraphVersion: number,\n): Promise<PeginP2aAnchorInfo | null> {\n return (await loadTbvWasm()).peginP2aAnchorOutput(txGraphVersion);\n}\n\n/**\n * Validate a PegIn transaction's P2A anchor against a graph version's rules:\n * v2 and v3 require the exact anchor (240 sats, vout 2, P2A script) and v1\n * requires that NO output carries the P2A script. Throws on any mismatch — a\n * v2 PegIn checked as v1 fails closed, and vice versa.\n */\nexport async function validatePeginP2aAnchor(\n txGraphVersion: number,\n txHex: string,\n): Promise<void> {\n return (await loadTbvWasm()).validatePeginP2aAnchor(txGraphVersion, txHex);\n}\n\n/**\n * Creates a payout connector for vault transactions.\n *\n * The payout connector generates the necessary taproot scripts and information\n * required for signing payout transactions (both optimistic and regular payout paths).\n *\n * @param params - Parameters for creating the payout connector\n * @param network - Bitcoin network\n * @returns Payout connector information including scripts, hashes, and address\n */\nexport async function createPayoutConnector(\n params: PayoutConnectorParams,\n network: Network,\n): Promise<PayoutConnectorInfo> {\n return (await loadTbvWasm()).createPayoutConnector(params, network);\n}\n\n/**\n * Get the Payout script and control block for the depositor's Assert output.\n *\n * Used to build the depositor's Payout PSBT (depositor-as-claimer path).\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @returns Payout script and control block (hex encoded)\n */\nexport async function getAssertPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n): Promise<AssertPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertPayoutScriptInfo(params);\n}\n\n/**\n * Get the NoPayout script and control block for a specific challenger.\n *\n * Used to build the depositor's NoPayout PSBT (depositor-as-claimer path).\n * Each challenger has a distinct NoPayout script.\n *\n * @param params - Assert Payout/NoPayout connector parameters\n * @param challengerPubkey - The challenger's x-only public key (hex encoded)\n * @returns NoPayout script and control block (hex encoded)\n */\nexport async function getAssertNoPayoutScriptInfo(\n params: AssertPayoutNoPayoutConnectorParams,\n challengerPubkey: string,\n): Promise<AssertNoPayoutScriptInfo> {\n return (await loadTbvWasm()).getAssertNoPayoutScriptInfo(\n params,\n challengerPubkey,\n );\n}\n\n/**\n * Get the ChallengeAssert script and control block.\n *\n * Used to build ChallengeAssert PSBTs for the depositor-as-claimer path.\n * Each challenger has 3 ChallengeAssert transactions, and this connector\n * generates the spending scripts using WOTS public keys from the VP.\n *\n * @param params - ChallengeAssert connector parameters\n * @returns Script and control block (hex encoded)\n */\nexport async function getChallengeAssertScriptInfo(\n params: ChallengeAssertConnectorParams,\n): Promise<ChallengeAssertScriptInfo> {\n return (await loadTbvWasm()).getChallengeAssertScriptInfo(params);\n}\n\n/**\n * Derive 32-byte `authAnchor` (OP_RETURN preimage → VP bearer token).\n * @stability frozen - btc-vault Rust owns this API through the vault-wasm pin (`VAULT_WASM_COMMIT`).\n * Changing the derived bytes breaks VP auth for existing deposits. See CLAUDE.md §4.\n */\nexport async function expandAuthAnchor(root: Uint8Array): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandAuthAnchor(root);\n}\n\n/**\n * Derive 32-byte `hashlockSecret` for HTLC `htlcVout` (preimage → `activateVaultWithSecret`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes means affected vaults can never activate. See CLAUDE.md §4.\n */\nexport async function expandHashlockSecret(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandHashlockSecret(root, htlcVout);\n}\n\n/**\n * Derive 64-byte `wotsSeed` for HTLC `htlcVout` (→ WOTS keys, hashed as `depositorWotsPkHash`).\n * @stability frozen - btc-vault Rust owns this API.\n * Changing the derived bytes breaks existing `depositorWotsPkHash` values. No claim path remains. See CLAUDE.md §4.\n */\nexport async function expandWotsSeed(\n root: Uint8Array,\n htlcVout: number,\n): Promise<Uint8Array> {\n return (await loadTbvWasm()).expandWotsSeed(root, htlcVout);\n}\n\n/**\n * Derives the vault ID from a PegIn transaction hash and depositor ETH address.\n *\n * Vault ID = keccak256(abi.encode(peginTxHash, depositor))\n * This matches the Solidity-side derivation in BTCVaultRegistry.\n *\n * @param peginTxHash - 32-byte PegIn tx hash in display order (big-endian), hex encoded\n * @param depositor - 20-byte Ethereum address of the depositor, hex encoded\n * @returns Hex-encoded vault ID (32 bytes)\n */\nexport async function deriveVaultId(\n peginTxHash: string,\n depositor: string,\n): Promise<string> {\n return (await loadTbvWasm()).deriveVaultId(peginTxHash, depositor);\n}\n\nexport type {\n AssertNoPayoutScriptInfo,\n AssertPayoutNoPayoutConnectorParams,\n AssertPayoutScriptInfo,\n ChallengeAssertConnectorParams,\n ChallengeAssertScriptInfo,\n HtlcConnectorInfo,\n HtlcConnectorParams,\n Network,\n PayoutConnectorInfo,\n PayoutConnectorParams,\n PeginP2aAnchorInfo,\n PeginTxResult,\n PrePeginParams,\n PrePeginResult,\n};\n"],"names":["TAP_INTERNAL_KEY","tapInternalPubkey","_","index","wasmModulePromise","rawWasmModulePromise","loadTbvWasm","error","loadRawTbvWasm","wasm","createPrePeginTransaction","params","buildPeginTxFromPrePegin","timelockPegin","fundedPrePeginTxHex","htlcVout","getPrePeginHtlcConnectorInfo","computeMinClaimValue","txGraphVersion","numLocalChallengers","numUniversalChallengers","councilQuorum","councilSize","feeRate","computeMinPeginFee","numVks","numUcs","minPeginFeeRate","computePayoutFeeFloor","numVaultKeepers","out0Len","out1Len","supportedTxGraphVersions","peginP2aAnchorOutput","validatePeginP2aAnchor","txHex","createPayoutConnector","network","getAssertPayoutScriptInfo","getAssertNoPayoutScriptInfo","challengerPubkey","getChallengeAssertScriptInfo","expandAuthAnchor","root","expandHashlockSecret","expandWotsSeed","deriveVaultId","peginTxHash","depositor"],"mappings":"AAQO,MAAMA,IACX;AAIK,MAAMC,IAAoB,WAAW;A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AAOA,eAAsB8B,EACpBF,GACA5B,GACqB;AACrB,UAAQ,MAAMT,EAAA,GAAe,eAAeqC,GAAM5B,CAAQ;AAC5D;AAYA,eAAsB+B,EACpBC,GACAC,GACiB;AACjB,UAAQ,MAAM1C,EAAA,GAAe,cAAcyC,GAAaC,CAAS;AACnE;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonlabs-io/ts-sdk",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -126,7 +126,7 @@
126
126
  "buffer": "6.0.3"
127
127
  },
128
128
  "peerDependencies": {
129
- "@babylonlabs-io/babylon-tbv-rust-wasm": "0.18.0",
129
+ "@babylonlabs-io/babylon-tbv-rust-wasm": "0.19.0",
130
130
  "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
131
131
  "bitcoinjs-lib": "6.1.7",
132
132
  "viem": "^2.38.2"
@@ -143,6 +143,7 @@
143
143
  }
144
144
  },
145
145
  "devDependencies": {
146
+ "@babylonlabs-io/babylon-tbv-rust-wasm": "0.19.0",
146
147
  "@vitest/browser-playwright": "4.0.9",
147
148
  "@vitest/coverage-v8": "^4.0.8",
148
149
  "@vitest/ui": "^4.0.8",
@@ -158,7 +159,6 @@
158
159
  "vite": "^6.4.1",
159
160
  "vite-plugin-dts": "^4.3.0",
160
161
  "vitest": "4.0.9",
161
- "@babylonlabs-io/babylon-tbv-rust-wasm": "0.18.0",
162
162
  "@internal/eslint-config": "0.0.0"
163
163
  },
164
164
  "publishConfig": {