@babylonlabs-io/ts-sdk 0.38.0 → 0.38.1

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.
Files changed (71) hide show
  1. package/dist/PayoutManager-D29D-K-V.js +250 -0
  2. package/dist/PayoutManager-D29D-K-V.js.map +1 -0
  3. package/dist/PayoutManager-DERMRuUU.cjs +2 -0
  4. package/dist/PayoutManager-DERMRuUU.cjs.map +1 -0
  5. package/dist/{PeginManager-C1en2vwr.js → PeginManager-Cp2Tn5sH.js} +270 -292
  6. package/dist/PeginManager-Cp2Tn5sH.js.map +1 -0
  7. package/dist/PeginManager-DaDs-bGr.cjs +2 -0
  8. package/dist/PeginManager-DaDs-bGr.cjs.map +1 -0
  9. package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs +2 -0
  10. package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs.map +1 -0
  11. package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js +340 -0
  12. package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js.map +1 -0
  13. package/dist/{buildAndBroadcastRefund-vwfVgJeA.js → buildAndBroadcastRefund-B5cOyUzj.js} +138 -132
  14. package/dist/{buildAndBroadcastRefund-vwfVgJeA.js.map → buildAndBroadcastRefund-B5cOyUzj.js.map} +1 -1
  15. package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs +2 -0
  16. package/dist/{buildAndBroadcastRefund-CEKwFY8l.cjs.map → buildAndBroadcastRefund-DVMT-pXQ.cjs.map} +1 -1
  17. package/dist/{challengeAssert-D7OCrDIc.js → challengeAssert-CBp4mEs0.js} +2 -2
  18. package/dist/{challengeAssert-D7OCrDIc.js.map → challengeAssert-CBp4mEs0.js.map} +1 -1
  19. package/dist/{challengeAssert-CMb7r-je.cjs → challengeAssert-CNRdpCzm.cjs} +2 -2
  20. package/dist/{challengeAssert-CMb7r-je.cjs.map → challengeAssert-CNRdpCzm.cjs.map} +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +27 -27
  23. package/dist/noPayout-jtZsoOzY.cjs +2 -0
  24. package/dist/noPayout-jtZsoOzY.cjs.map +1 -0
  25. package/dist/noPayout-qbaSEKGC.js +145 -0
  26. package/dist/noPayout-qbaSEKGC.js.map +1 -0
  27. package/dist/peginInput-BPRB9tUi.js +104 -0
  28. package/dist/peginInput-BPRB9tUi.js.map +1 -0
  29. package/dist/peginInput-DH6X4ITS.cjs +2 -0
  30. package/dist/peginInput-DH6X4ITS.cjs.map +1 -0
  31. package/dist/tbv/core/index.cjs +1 -1
  32. package/dist/tbv/core/index.js +20 -20
  33. package/dist/tbv/core/managers/index.cjs +1 -1
  34. package/dist/tbv/core/managers/index.js +2 -2
  35. package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts +37 -0
  36. package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts.map +1 -1
  37. package/dist/tbv/core/managers/pegin/index.d.ts +1 -1
  38. package/dist/tbv/core/managers/pegin/index.d.ts.map +1 -1
  39. package/dist/tbv/core/primitives/index.cjs +1 -1
  40. package/dist/tbv/core/primitives/index.js +17 -17
  41. package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts +12 -0
  42. package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts.map +1 -0
  43. package/dist/tbv/core/primitives/psbt/pegin.d.ts +5 -0
  44. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  45. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  46. package/dist/tbv/core/services/index.cjs +1 -1
  47. package/dist/tbv/core/services/index.js +2 -2
  48. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  49. package/dist/tbv/index.cjs +1 -1
  50. package/dist/tbv/index.js +20 -20
  51. package/package.json +3 -3
  52. package/dist/PayoutManager-BfT0V-tm.cjs +0 -2
  53. package/dist/PayoutManager-BfT0V-tm.cjs.map +0 -1
  54. package/dist/PayoutManager-Cf51DBcu.js +0 -208
  55. package/dist/PayoutManager-Cf51DBcu.js.map +0 -1
  56. package/dist/PeginManager-BRHJZYmE.cjs +0 -2
  57. package/dist/PeginManager-BRHJZYmE.cjs.map +0 -1
  58. package/dist/PeginManager-C1en2vwr.js.map +0 -1
  59. package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs +0 -2
  60. package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs.map +0 -1
  61. package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js +0 -266
  62. package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js.map +0 -1
  63. package/dist/buildAndBroadcastRefund-CEKwFY8l.cjs +0 -2
  64. package/dist/noPayout-B6s8vrW6.cjs +0 -2
  65. package/dist/noPayout-B6s8vrW6.cjs.map +0 -1
  66. package/dist/noPayout-BhgknZBx.js +0 -141
  67. package/dist/noPayout-BhgknZBx.js.map +0 -1
  68. package/dist/peginInput-57FK2O99.cjs +0 -2
  69. package/dist/peginInput-57FK2O99.cjs.map +0 -1
  70. package/dist/peginInput-CYJzbuwA.js +0 -177
  71. package/dist/peginInput-CYJzbuwA.js.map +0 -1
@@ -2,7 +2,7 @@ import { p as S, s as x, k as y, h as T, T as E } from "./bitcoin-B5aNKtsk.js";
2
2
  import { getPeginPayoutScriptInfo as U, tapInternalPubkey as v, getChallengeAssertScriptInfo as _ } from "@babylonlabs-io/babylon-tbv-rust-wasm";
3
3
  import { Buffer as l } from "buffer";
4
4
  import { Transaction as d, Psbt as O } from "bitcoinjs-lib";
5
- import { D as A, f as m, A as w } from "./assertPsbtUnsignedTxMatches-Dry5dTfl.js";
5
+ import { D as A, h as m, A as w } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
6
6
  function I(n) {
7
7
  return S(n).toLowerCase();
8
8
  }
@@ -125,4 +125,4 @@ export {
125
125
  q as b,
126
126
  N as c
127
127
  };
128
- //# sourceMappingURL=challengeAssert-D7OCrDIc.js.map
128
+ //# sourceMappingURL=challengeAssert-CBp4mEs0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"challengeAssert-D7OCrDIc.js","sources":["../src/tbv/core/primitives/challengers.ts","../src/tbv/core/primitives/psbt/depositorPayout.ts","../src/tbv/core/primitives/psbt/challengeAssert.ts"],"sourcesContent":["/**\n * Challenger counting utilities.\n *\n * Used for UI-level validation (e.g. computing minimum deposit amounts)\n * where the depositor's identity is known. The transaction builders use\n * `vaultKeeperBtcPubkeys.length` to match the VP's current validation.\n */\n\nimport { processPublicKeyToXOnly } from \"./utils/bitcoin\";\n\n/**\n * Normalize a public key to lowercase x-only hex for reliable comparison.\n *\n * Handles `0x` prefixes, compressed (33-byte), and uncompressed (65-byte) keys.\n */\nfunction normalizeKey(key: string): string {\n return processPublicKeyToXOnly(key).toLowerCase();\n}\n\n/**\n * Compute the number of local challengers for a vault.\n *\n * Mirrors the VP's `compute_num_challengers()` logic:\n * local challengers = {vault_provider} ∪ {vault_keepers} − {depositor}\n *\n * Keys are normalized to x-only lowercase hex before comparison, so\n * `0x`-prefixed, compressed, or mixed-case keys are handled correctly.\n *\n * @param vaultProviderPubkey - Vault provider BTC public key\n * @param vaultKeeperPubkeys - Vault keeper BTC public keys\n * @param depositorPubkey - Depositor (claimer) BTC public key\n * @returns Number of local challengers\n */\nexport function computeNumLocalChallengers(\n vaultProviderPubkey: string,\n vaultKeeperPubkeys: string[],\n depositorPubkey: string,\n): number {\n const localSet = new Set<string>();\n localSet.add(normalizeKey(vaultProviderPubkey));\n for (const vk of vaultKeeperPubkeys) {\n localSet.add(normalizeKey(vk));\n }\n localSet.delete(normalizeKey(depositorPubkey));\n return localSet.size;\n}\n","/**\n * Depositor Payout PSBT Builder\n *\n * Builds unsigned PSBTs for the depositor's own Payout transaction\n * (depositor-as-claimer path). The depositor signs input 0 using the\n * payout taproot script from WasmPeginPayoutConnector (PegIn vault UTXO).\n *\n * Input 0 spends PegIn:0 (the vault UTXO) — the same connector used for\n * VP/VK payout signing. The VP verifies this signature using the\n * PeginPayoutConnector's payout script.\n *\n * @module primitives/psbt/depositorPayout\n * @see btc-vault crates/vault/src/sign.rs — verify_depositor_signature / get_payout_tap_leaf_hash\n */\n\nimport {\n type PayoutConnectorParams,\n getPeginPayoutScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\nimport {\n ASSERT_PAYOUT_OUTPUT_INDEX,\n DEPOSITOR_PAYOUT_INPUT_COUNT,\n PEGIN_VAULT_OUTPUT_INDEX,\n} from \"./constants\";\n\n/**\n * Parameters for building a depositor Payout PSBT\n */\nexport interface DepositorPayoutParams {\n /** Payout transaction hex (unsigned) */\n payoutTxHex: string;\n /** Authoritative PegIn transaction hex — input 0 must spend PegIn:0 */\n peginTxHex: string;\n /** Authoritative Assert transaction hex — input 1 must spend Assert:0 */\n assertTxHex: string;\n /** Parameters for the PeginPayout connector (depositor, VP, VKs, UCs, timelock) */\n connectorParams: PayoutConnectorParams;\n}\n\n/**\n * Build unsigned depositor Payout PSBT.\n *\n * The depositor's payout transaction has 2 inputs:\n * - Input 0: PegIn:0 (vault UTXO) — depositor signs using PeginPayoutConnector payout script\n * - Input 1: Assert:0 — NOT signed by depositor\n *\n * Both inputs must be present in the PSBT because Taproot SIGHASH_DEFAULT\n * commits to all input prevouts. Prevout script_pubkey/value are derived\n * from the authoritative parent transactions, not trusted from external input.\n *\n * @param params - Depositor payout parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the payout transaction does not have exactly 2 inputs\n * @throws If input 0 does not reference peginTxHex at output index 0\n * @throws If input 1 does not reference assertTxHex at output index 0\n */\nexport async function buildDepositorPayoutPsbt(\n params: DepositorPayoutParams,\n): Promise<string> {\n const payoutTx = Transaction.fromHex(stripHexPrefix(params.payoutTxHex));\n const peginTx = Transaction.fromHex(stripHexPrefix(params.peginTxHex));\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n\n if (payoutTx.ins.length !== DEPOSITOR_PAYOUT_INPUT_COUNT) {\n throw new Error(\n `Depositor Payout transaction must have exactly ${DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${payoutTx.ins.length}`,\n );\n }\n\n const input0 = payoutTx.ins[0];\n const input1 = payoutTx.ins[1];\n\n const input0Txid = inputTxidHex(input0);\n const peginTxid = peginTx.getId();\n if (input0Txid !== peginTxid || input0.index !== PEGIN_VAULT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 0 must spend PegIn:${PEGIN_VAULT_OUTPUT_INDEX}. ` +\n `Expected ${peginTxid}:${PEGIN_VAULT_OUTPUT_INDEX}, got ${input0Txid}:${input0.index}`,\n );\n }\n\n const input1Txid = inputTxidHex(input1);\n const assertTxid = assertTx.getId();\n if (input1Txid !== assertTxid || input1.index !== ASSERT_PAYOUT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 1 must spend Assert:${ASSERT_PAYOUT_OUTPUT_INDEX}. ` +\n `Expected ${assertTxid}:${ASSERT_PAYOUT_OUTPUT_INDEX}, got ${input1Txid}:${input1.index}`,\n );\n }\n\n const peginPrevOut = peginTx.outs[input0.index];\n const assertPrevOut = assertTx.outs[input1.index];\n\n const { payoutScript, payoutControlBlock } = await getPeginPayoutScriptInfo(\n params.connectorParams,\n );\n const scriptBytes = hexToUint8Array(payoutScript);\n const controlBlock = hexToUint8Array(payoutControlBlock);\n\n const psbt = new Psbt();\n psbt.setVersion(payoutTx.version);\n psbt.setLocktime(payoutTx.locktime);\n\n psbt.addInput({\n hash: input0.hash,\n index: input0.index,\n sequence: input0.sequence,\n witnessUtxo: {\n script: peginPrevOut.script,\n value: peginPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlock),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n\n psbt.addInput({\n hash: input1.hash,\n index: input1.index,\n sequence: input1.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n });\n\n for (const output of payoutTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n","/**\n * ChallengeAssert PSBT Builder\n *\n * Builds an unsigned PSBT for a ChallengeAssert transaction\n * (depositor-as-claimer path, per challenger). The ChallengeAssert tx has\n * NUM_UTXOS_FOR_CHALLENGE_ASSERT (3) inputs, each spending a different Assert\n * output segment. The depositor signs ALL inputs, each with its own taproot\n * script derived from the per-segment connector params.\n *\n * @module primitives/psbt/challengeAssert\n * @see btc-vault crates/vault/docs/btc-transactions-spec.md — ChallengeAssert connector (NUM_UTXOS_FOR_CHALLENGE_ASSERT=3)\n */\n\nimport {\n type ChallengeAssertConnectorParams,\n getChallengeAssertScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\n\n/**\n * Parameters for building a ChallengeAssert PSBT\n */\nexport interface ChallengeAssertParams {\n /** ChallengeAssert transaction hex (unsigned) */\n challengeAssertTxHex: string;\n /** Authoritative Assert transaction hex — every input must spend an Assert output */\n assertTxHex: string;\n /** Per-input connector params (one per input/segment, determines the taproot script) */\n connectorParamsPerInput: ChallengeAssertConnectorParams[];\n}\n\n/**\n * Build unsigned ChallengeAssert PSBT.\n *\n * The ChallengeAssert transaction has 3 inputs (one per Assert output segment).\n * Each input has its own taproot script derived from its connector params.\n * The depositor signs all inputs. Every prevout is derived from the\n * authoritative Assert transaction, never trusted from external input.\n *\n * @param params - ChallengeAssert parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the number of connector params does not match the number of inputs\n * @throws If any input does not reference assertTxHex\n * @throws If any referenced Assert output is missing\n * @throws If two inputs reference the same Assert output index\n */\nexport async function buildChallengeAssertPsbt(\n params: ChallengeAssertParams,\n): Promise<string> {\n const challengeAssertTx = Transaction.fromHex(\n stripHexPrefix(params.challengeAssertTxHex),\n );\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n const assertTxid = assertTx.getId();\n\n if (params.connectorParamsPerInput.length !== challengeAssertTx.ins.length) {\n throw new Error(\n `Expected ${challengeAssertTx.ins.length} connector params, got ${params.connectorParamsPerInput.length}`,\n );\n }\n\n const seenAssertOutputs = new Set<number>();\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const inputTxid = inputTxidHex(input);\n if (inputTxid !== assertTxid) {\n throw new Error(\n `ChallengeAssert input ${i} must spend an Assert output. ` +\n `Expected txid ${assertTxid}, got ${inputTxid}`,\n );\n }\n if (!assertTx.outs[input.index]) {\n throw new Error(\n `Assert output ${input.index} not found for ChallengeAssert input ${i} (txid: ${assertTxid})`,\n );\n }\n if (seenAssertOutputs.has(input.index)) {\n throw new Error(\n `ChallengeAssert input ${i} duplicates Assert output index ${input.index}`,\n );\n }\n seenAssertOutputs.add(input.index);\n }\n\n const scriptInfos = await Promise.all(\n params.connectorParamsPerInput.map((cp) => getChallengeAssertScriptInfo(cp)),\n );\n\n const psbt = new Psbt();\n psbt.setVersion(challengeAssertTx.version);\n psbt.setLocktime(challengeAssertTx.locktime);\n\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const assertPrevOut = assertTx.outs[input.index];\n\n const { script, controlBlock } = scriptInfos[i];\n const scriptBytes = hexToUint8Array(script);\n const controlBlockBytes = hexToUint8Array(controlBlock);\n\n psbt.addInput({\n hash: input.hash,\n index: input.index,\n sequence: input.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlockBytes),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n }\n\n for (const output of challengeAssertTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n"],"names":["normalizeKey","key","processPublicKeyToXOnly","computeNumLocalChallengers","vaultProviderPubkey","vaultKeeperPubkeys","depositorPubkey","localSet","vk","buildDepositorPayoutPsbt","params","payoutTx","Transaction","stripHexPrefix","peginTx","assertTx","DEPOSITOR_PAYOUT_INPUT_COUNT","input0","input1","input0Txid","inputTxidHex","peginTxid","PEGIN_VAULT_OUTPUT_INDEX","input1Txid","assertTxid","ASSERT_PAYOUT_OUTPUT_INDEX","peginPrevOut","assertPrevOut","payoutScript","payoutControlBlock","getPeginPayoutScriptInfo","scriptBytes","hexToUint8Array","controlBlock","psbt","Psbt","TAPSCRIPT_LEAF_VERSION","Buffer","tapInternalPubkey","output","buildChallengeAssertPsbt","challengeAssertTx","seenAssertOutputs","i","input","inputTxid","scriptInfos","cp","getChallengeAssertScriptInfo","script","controlBlockBytes"],"mappings":";;;;;AAeA,SAASA,EAAaC,GAAqB;AACzC,SAAOC,EAAwBD,CAAG,EAAE,YAAA;AACtC;AAgBO,SAASE,EACdC,GACAC,GACAC,GACQ;AACR,QAAMC,wBAAe,IAAA;AACrB,EAAAA,EAAS,IAAIP,EAAaI,CAAmB,CAAC;AAC9C,aAAWI,KAAMH;AACf,IAAAE,EAAS,IAAIP,EAAaQ,CAAE,CAAC;AAE/B,SAAAD,EAAS,OAAOP,EAAaM,CAAe,CAAC,GACtCC,EAAS;AAClB;ACsBA,eAAsBE,EACpBC,GACiB;AACjB,QAAMC,IAAWC,EAAY,QAAQC,EAAeH,EAAO,WAAW,CAAC,G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AAAA,MACf,OAAOA,EAAO;AAAA,IAAA,CACf;AAGH,SAAOL,EAAK,MAAA;AACd;"}
1
+ {"version":3,"file":"challengeAssert-CBp4mEs0.js","sources":["../src/tbv/core/primitives/challengers.ts","../src/tbv/core/primitives/psbt/depositorPayout.ts","../src/tbv/core/primitives/psbt/challengeAssert.ts"],"sourcesContent":["/**\n * Challenger counting utilities.\n *\n * Used for UI-level validation (e.g. computing minimum deposit amounts)\n * where the depositor's identity is known. The transaction builders use\n * `vaultKeeperBtcPubkeys.length` to match the VP's current validation.\n */\n\nimport { processPublicKeyToXOnly } from \"./utils/bitcoin\";\n\n/**\n * Normalize a public key to lowercase x-only hex for reliable comparison.\n *\n * Handles `0x` prefixes, compressed (33-byte), and uncompressed (65-byte) keys.\n */\nfunction normalizeKey(key: string): string {\n return processPublicKeyToXOnly(key).toLowerCase();\n}\n\n/**\n * Compute the number of local challengers for a vault.\n *\n * Mirrors the VP's `compute_num_challengers()` logic:\n * local challengers = {vault_provider} ∪ {vault_keepers} − {depositor}\n *\n * Keys are normalized to x-only lowercase hex before comparison, so\n * `0x`-prefixed, compressed, or mixed-case keys are handled correctly.\n *\n * @param vaultProviderPubkey - Vault provider BTC public key\n * @param vaultKeeperPubkeys - Vault keeper BTC public keys\n * @param depositorPubkey - Depositor (claimer) BTC public key\n * @returns Number of local challengers\n */\nexport function computeNumLocalChallengers(\n vaultProviderPubkey: string,\n vaultKeeperPubkeys: string[],\n depositorPubkey: string,\n): number {\n const localSet = new Set<string>();\n localSet.add(normalizeKey(vaultProviderPubkey));\n for (const vk of vaultKeeperPubkeys) {\n localSet.add(normalizeKey(vk));\n }\n localSet.delete(normalizeKey(depositorPubkey));\n return localSet.size;\n}\n","/**\n * Depositor Payout PSBT Builder\n *\n * Builds unsigned PSBTs for the depositor's own Payout transaction\n * (depositor-as-claimer path). The depositor signs input 0 using the\n * payout taproot script from WasmPeginPayoutConnector (PegIn vault UTXO).\n *\n * Input 0 spends PegIn:0 (the vault UTXO) — the same connector used for\n * VP/VK payout signing. The VP verifies this signature using the\n * PeginPayoutConnector's payout script.\n *\n * @module primitives/psbt/depositorPayout\n * @see btc-vault crates/vault/src/sign.rs — verify_depositor_signature / get_payout_tap_leaf_hash\n */\n\nimport {\n type PayoutConnectorParams,\n getPeginPayoutScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\nimport {\n ASSERT_PAYOUT_OUTPUT_INDEX,\n DEPOSITOR_PAYOUT_INPUT_COUNT,\n PEGIN_VAULT_OUTPUT_INDEX,\n} from \"./constants\";\n\n/**\n * Parameters for building a depositor Payout PSBT\n */\nexport interface DepositorPayoutParams {\n /** Payout transaction hex (unsigned) */\n payoutTxHex: string;\n /** Authoritative PegIn transaction hex — input 0 must spend PegIn:0 */\n peginTxHex: string;\n /** Authoritative Assert transaction hex — input 1 must spend Assert:0 */\n assertTxHex: string;\n /** Parameters for the PeginPayout connector (depositor, VP, VKs, UCs, timelock) */\n connectorParams: PayoutConnectorParams;\n}\n\n/**\n * Build unsigned depositor Payout PSBT.\n *\n * The depositor's payout transaction has 2 inputs:\n * - Input 0: PegIn:0 (vault UTXO) — depositor signs using PeginPayoutConnector payout script\n * - Input 1: Assert:0 — NOT signed by depositor\n *\n * Both inputs must be present in the PSBT because Taproot SIGHASH_DEFAULT\n * commits to all input prevouts. Prevout script_pubkey/value are derived\n * from the authoritative parent transactions, not trusted from external input.\n *\n * @param params - Depositor payout parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the payout transaction does not have exactly 2 inputs\n * @throws If input 0 does not reference peginTxHex at output index 0\n * @throws If input 1 does not reference assertTxHex at output index 0\n */\nexport async function buildDepositorPayoutPsbt(\n params: DepositorPayoutParams,\n): Promise<string> {\n const payoutTx = Transaction.fromHex(stripHexPrefix(params.payoutTxHex));\n const peginTx = Transaction.fromHex(stripHexPrefix(params.peginTxHex));\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n\n if (payoutTx.ins.length !== DEPOSITOR_PAYOUT_INPUT_COUNT) {\n throw new Error(\n `Depositor Payout transaction must have exactly ${DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${payoutTx.ins.length}`,\n );\n }\n\n const input0 = payoutTx.ins[0];\n const input1 = payoutTx.ins[1];\n\n const input0Txid = inputTxidHex(input0);\n const peginTxid = peginTx.getId();\n if (input0Txid !== peginTxid || input0.index !== PEGIN_VAULT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 0 must spend PegIn:${PEGIN_VAULT_OUTPUT_INDEX}. ` +\n `Expected ${peginTxid}:${PEGIN_VAULT_OUTPUT_INDEX}, got ${input0Txid}:${input0.index}`,\n );\n }\n\n const input1Txid = inputTxidHex(input1);\n const assertTxid = assertTx.getId();\n if (input1Txid !== assertTxid || input1.index !== ASSERT_PAYOUT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 1 must spend Assert:${ASSERT_PAYOUT_OUTPUT_INDEX}. ` +\n `Expected ${assertTxid}:${ASSERT_PAYOUT_OUTPUT_INDEX}, got ${input1Txid}:${input1.index}`,\n );\n }\n\n const peginPrevOut = peginTx.outs[input0.index];\n const assertPrevOut = assertTx.outs[input1.index];\n\n const { payoutScript, payoutControlBlock } = await getPeginPayoutScriptInfo(\n params.connectorParams,\n );\n const scriptBytes = hexToUint8Array(payoutScript);\n const controlBlock = hexToUint8Array(payoutControlBlock);\n\n const psbt = new Psbt();\n psbt.setVersion(payoutTx.version);\n psbt.setLocktime(payoutTx.locktime);\n\n psbt.addInput({\n hash: input0.hash,\n index: input0.index,\n sequence: input0.sequence,\n witnessUtxo: {\n script: peginPrevOut.script,\n value: peginPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlock),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n\n psbt.addInput({\n hash: input1.hash,\n index: input1.index,\n sequence: input1.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n });\n\n for (const output of payoutTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n","/**\n * ChallengeAssert PSBT Builder\n *\n * Builds an unsigned PSBT for a ChallengeAssert transaction\n * (depositor-as-claimer path, per challenger). The ChallengeAssert tx has\n * NUM_UTXOS_FOR_CHALLENGE_ASSERT (3) inputs, each spending a different Assert\n * output segment. The depositor signs ALL inputs, each with its own taproot\n * script derived from the per-segment connector params.\n *\n * @module primitives/psbt/challengeAssert\n * @see btc-vault crates/vault/docs/btc-transactions-spec.md — ChallengeAssert connector (NUM_UTXOS_FOR_CHALLENGE_ASSERT=3)\n */\n\nimport {\n type ChallengeAssertConnectorParams,\n getChallengeAssertScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\n\n/**\n * Parameters for building a ChallengeAssert PSBT\n */\nexport interface ChallengeAssertParams {\n /** ChallengeAssert transaction hex (unsigned) */\n challengeAssertTxHex: string;\n /** Authoritative Assert transaction hex — every input must spend an Assert output */\n assertTxHex: string;\n /** Per-input connector params (one per input/segment, determines the taproot script) */\n connectorParamsPerInput: ChallengeAssertConnectorParams[];\n}\n\n/**\n * Build unsigned ChallengeAssert PSBT.\n *\n * The ChallengeAssert transaction has 3 inputs (one per Assert output segment).\n * Each input has its own taproot script derived from its connector params.\n * The depositor signs all inputs. Every prevout is derived from the\n * authoritative Assert transaction, never trusted from external input.\n *\n * @param params - ChallengeAssert parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the number of connector params does not match the number of inputs\n * @throws If any input does not reference assertTxHex\n * @throws If any referenced Assert output is missing\n * @throws If two inputs reference the same Assert output index\n */\nexport async function buildChallengeAssertPsbt(\n params: ChallengeAssertParams,\n): Promise<string> {\n const challengeAssertTx = Transaction.fromHex(\n stripHexPrefix(params.challengeAssertTxHex),\n );\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n const assertTxid = assertTx.getId();\n\n if (params.connectorParamsPerInput.length !== challengeAssertTx.ins.length) {\n throw new Error(\n `Expected ${challengeAssertTx.ins.length} connector params, got ${params.connectorParamsPerInput.length}`,\n );\n }\n\n const seenAssertOutputs = new Set<number>();\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const inputTxid = inputTxidHex(input);\n if (inputTxid !== assertTxid) {\n throw new Error(\n `ChallengeAssert input ${i} must spend an Assert output. ` +\n `Expected txid ${assertTxid}, got ${inputTxid}`,\n );\n }\n if (!assertTx.outs[input.index]) {\n throw new Error(\n `Assert output ${input.index} not found for ChallengeAssert input ${i} (txid: ${assertTxid})`,\n );\n }\n if (seenAssertOutputs.has(input.index)) {\n throw new Error(\n `ChallengeAssert input ${i} duplicates Assert output index ${input.index}`,\n );\n }\n seenAssertOutputs.add(input.index);\n }\n\n const scriptInfos = await Promise.all(\n params.connectorParamsPerInput.map((cp) => getChallengeAssertScriptInfo(cp)),\n );\n\n const psbt = new Psbt();\n psbt.setVersion(challengeAssertTx.version);\n psbt.setLocktime(challengeAssertTx.locktime);\n\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const assertPrevOut = assertTx.outs[input.index];\n\n const { script, controlBlock } = scriptInfos[i];\n const scriptBytes = hexToUint8Array(script);\n const controlBlockBytes = hexToUint8Array(controlBlock);\n\n psbt.addInput({\n hash: input.hash,\n index: input.index,\n sequence: input.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlockBytes),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n }\n\n for (const output of challengeAssertTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n"],"names":["normalizeKey","key","processPublicKeyToXOnly","computeNumLocalChallengers","vaultProviderPubkey","vaultKeeperPubkeys","depositorPubkey","localSet","vk","buildDepositorPayoutPsbt","params","payoutTx","Transaction","stripHexPrefix","peginTx","assertTx","DEPOSITOR_PAYOUT_INPUT_COUNT","input0","input1","input0Txid","inputTxidHex","peginTxid","PEGIN_VAULT_OUTPUT_INDEX","input1Txid","assertTxid","ASSERT_PAYOUT_OUTPUT_INDEX","peginPrevOut","assertPrevOut","payoutScript","payoutControlBlock","getPeginPayoutScriptInfo","scriptBytes","hexToUint8Array","controlBlock","psbt","Psbt","TAPSCRIPT_LEAF_VERSION","Buffer","tapInternalPubkey","output","buildChallengeAssertPsbt","challengeAssertTx","seenAssertOutputs","i","input","inputTxid","scriptInfos","cp","getChallengeAssertScriptInfo","script","controlBlockBytes"],"mappings":";;;;;AAeA,SAASA,EAAaC,GAAqB;AACzC,SAAOC,EAAwBD,CAAG,EAAE,YAAA;AACtC;AAgBO,SAASE,EACdC,GACAC,GACAC,GACQ;AACR,QAAMC,wBAAe,IAAA;AACrB,EAAAA,EAAS,IAAIP,EAAaI,CAAmB,CAAC;AAC9C,aAAWI,KAAMH;AACf,IAAAE,EAAS,IAAIP,EAAaQ,CAAE,CAAC;AAE/B,SAAAD,EAAS,OAAOP,EAAaM,CAAe,CAAC,GACtCC,EAAS;AAClB;ACsBA,eAAsBE,EACpBC,GACiB;AACjB,QAAMC,IAAWC,EAAY,QAAQC,EA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AAAA,MACb,QAAQK,EAAO;AAAA,MACf,OAAOA,EAAO;AAAA,IAAA,CACf;AAGH,SAAOL,EAAK,MAAA;AACd;"}
@@ -1,2 +1,2 @@
1
- "use strict";const n=require("./bitcoin-CHfKAhcI.cjs"),h=require("@babylonlabs-io/babylon-tbv-rust-wasm"),T=require("buffer"),l=require("bitcoinjs-lib"),x=require("./assertPsbtUnsignedTxMatches-CagW7XqW.cjs");function A(s){return n.processPublicKeyToXOnly(s).toLowerCase()}function _(s,t,u){const i=new Set;i.add(A(s));for(const r of t)i.add(A(r));return i.delete(A(u)),i.size}async function O(s){const t=l.Transaction.fromHex(n.stripHexPrefix(s.payoutTxHex)),u=l.Transaction.fromHex(n.stripHexPrefix(s.peginTxHex)),i=l.Transaction.fromHex(n.stripHexPrefix(s.assertTxHex));if(t.ins.length!==x.DEPOSITOR_PAYOUT_INPUT_COUNT)throw new Error(`Depositor Payout transaction must have exactly ${x.DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${t.ins.length}`);const r=t.ins[0],c=t.ins[1],a=n.inputTxidHex(r),e=u.getId();if(a!==e||r.index!==x.PEGIN_VAULT_OUTPUT_INDEX)throw new Error(`Depositor Payout input 0 must spend PegIn:${x.PEGIN_VAULT_OUTPUT_INDEX}. Expected ${e}:${x.PEGIN_VAULT_OUTPUT_INDEX}, got ${a}:${r.index}`);const o=n.inputTxidHex(c),p=i.getId();if(o!==p||c.index!==x.ASSERT_PAYOUT_OUTPUT_INDEX)throw new Error(`Depositor Payout input 1 must spend Assert:${x.ASSERT_PAYOUT_OUTPUT_INDEX}. Expected ${p}:${x.ASSERT_PAYOUT_OUTPUT_INDEX}, got ${o}:${c.index}`);const f=u.outs[r.index],P=i.outs[c.index],{payoutScript:g,payoutControlBlock:I}=await h.getPeginPayoutScriptInfo(s.connectorParams),E=n.hexToUint8Array(g),y=n.hexToUint8Array(I),d=new l.Psbt;d.setVersion(t.version),d.setLocktime(t.locktime),d.addInput({hash:r.hash,index:r.index,sequence:r.sequence,witnessUtxo:{script:f.script,value:f.value},tapLeafScript:[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:T.Buffer.from(E),controlBlock:T.Buffer.from(y)}],tapInternalKey:T.Buffer.from(h.tapInternalPubkey)}),d.addInput({hash:c.hash,index:c.index,sequence:c.sequence,witnessUtxo:{script:P.script,value:P.value}});for(const U of t.outs)d.addOutput({script:U.script,value:U.value});return d.toHex()}async function m(s){const t=l.Transaction.fromHex(n.stripHexPrefix(s.challengeAssertTxHex)),u=l.Transaction.fromHex(n.stripHexPrefix(s.assertTxHex)),i=u.getId();if(s.connectorParamsPerInput.length!==t.ins.length)throw new Error(`Expected ${t.ins.length} connector params, got ${s.connectorParamsPerInput.length}`);const r=new Set;for(let e=0;e<t.ins.length;e++){const o=t.ins[e],p=n.inputTxidHex(o);if(p!==i)throw new Error(`ChallengeAssert input ${e} must spend an Assert output. Expected txid ${i}, got ${p}`);if(!u.outs[o.index])throw new Error(`Assert output ${o.index} not found for ChallengeAssert input ${e} (txid: ${i})`);if(r.has(o.index))throw new Error(`ChallengeAssert input ${e} duplicates Assert output index ${o.index}`);r.add(o.index)}const c=await Promise.all(s.connectorParamsPerInput.map(e=>h.getChallengeAssertScriptInfo(e))),a=new l.Psbt;a.setVersion(t.version),a.setLocktime(t.locktime);for(let e=0;e<t.ins.length;e++){const o=t.ins[e],p=u.outs[o.index],{script:f,controlBlock:P}=c[e],g=n.hexToUint8Array(f),I=n.hexToUint8Array(P);a.addInput({hash:o.hash,index:o.index,sequence:o.sequence,witnessUtxo:{script:p.script,value:p.value},tapLeafScript:[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:T.Buffer.from(g),controlBlock:T.Buffer.from(I)}],tapInternalKey:T.Buffer.from(h.tapInternalPubkey)})}for(const e of t.outs)a.addOutput({script:e.script,value:e.value});return a.toHex()}exports.buildChallengeAssertPsbt=m;exports.buildDepositorPayoutPsbt=O;exports.computeNumLocalChallengers=_;
2
- //# sourceMappingURL=challengeAssert-CMb7r-je.cjs.map
1
+ "use strict";const n=require("./bitcoin-CHfKAhcI.cjs"),h=require("@babylonlabs-io/babylon-tbv-rust-wasm"),T=require("buffer"),l=require("bitcoinjs-lib"),x=require("./assertPsbtUnsignedTxMatches-fNkAaZZm.cjs");function A(s){return n.processPublicKeyToXOnly(s).toLowerCase()}function _(s,t,u){const i=new Set;i.add(A(s));for(const r of t)i.add(A(r));return i.delete(A(u)),i.size}async function O(s){const t=l.Transaction.fromHex(n.stripHexPrefix(s.payoutTxHex)),u=l.Transaction.fromHex(n.stripHexPrefix(s.peginTxHex)),i=l.Transaction.fromHex(n.stripHexPrefix(s.assertTxHex));if(t.ins.length!==x.DEPOSITOR_PAYOUT_INPUT_COUNT)throw new Error(`Depositor Payout transaction must have exactly ${x.DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${t.ins.length}`);const r=t.ins[0],c=t.ins[1],a=n.inputTxidHex(r),e=u.getId();if(a!==e||r.index!==x.PEGIN_VAULT_OUTPUT_INDEX)throw new Error(`Depositor Payout input 0 must spend PegIn:${x.PEGIN_VAULT_OUTPUT_INDEX}. Expected ${e}:${x.PEGIN_VAULT_OUTPUT_INDEX}, got ${a}:${r.index}`);const o=n.inputTxidHex(c),p=i.getId();if(o!==p||c.index!==x.ASSERT_PAYOUT_OUTPUT_INDEX)throw new Error(`Depositor Payout input 1 must spend Assert:${x.ASSERT_PAYOUT_OUTPUT_INDEX}. Expected ${p}:${x.ASSERT_PAYOUT_OUTPUT_INDEX}, got ${o}:${c.index}`);const f=u.outs[r.index],P=i.outs[c.index],{payoutScript:g,payoutControlBlock:I}=await h.getPeginPayoutScriptInfo(s.connectorParams),E=n.hexToUint8Array(g),y=n.hexToUint8Array(I),d=new l.Psbt;d.setVersion(t.version),d.setLocktime(t.locktime),d.addInput({hash:r.hash,index:r.index,sequence:r.sequence,witnessUtxo:{script:f.script,value:f.value},tapLeafScript:[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:T.Buffer.from(E),controlBlock:T.Buffer.from(y)}],tapInternalKey:T.Buffer.from(h.tapInternalPubkey)}),d.addInput({hash:c.hash,index:c.index,sequence:c.sequence,witnessUtxo:{script:P.script,value:P.value}});for(const U of t.outs)d.addOutput({script:U.script,value:U.value});return d.toHex()}async function m(s){const t=l.Transaction.fromHex(n.stripHexPrefix(s.challengeAssertTxHex)),u=l.Transaction.fromHex(n.stripHexPrefix(s.assertTxHex)),i=u.getId();if(s.connectorParamsPerInput.length!==t.ins.length)throw new Error(`Expected ${t.ins.length} connector params, got ${s.connectorParamsPerInput.length}`);const r=new Set;for(let e=0;e<t.ins.length;e++){const o=t.ins[e],p=n.inputTxidHex(o);if(p!==i)throw new Error(`ChallengeAssert input ${e} must spend an Assert output. Expected txid ${i}, got ${p}`);if(!u.outs[o.index])throw new Error(`Assert output ${o.index} not found for ChallengeAssert input ${e} (txid: ${i})`);if(r.has(o.index))throw new Error(`ChallengeAssert input ${e} duplicates Assert output index ${o.index}`);r.add(o.index)}const c=await Promise.all(s.connectorParamsPerInput.map(e=>h.getChallengeAssertScriptInfo(e))),a=new l.Psbt;a.setVersion(t.version),a.setLocktime(t.locktime);for(let e=0;e<t.ins.length;e++){const o=t.ins[e],p=u.outs[o.index],{script:f,controlBlock:P}=c[e],g=n.hexToUint8Array(f),I=n.hexToUint8Array(P);a.addInput({hash:o.hash,index:o.index,sequence:o.sequence,witnessUtxo:{script:p.script,value:p.value},tapLeafScript:[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:T.Buffer.from(g),controlBlock:T.Buffer.from(I)}],tapInternalKey:T.Buffer.from(h.tapInternalPubkey)})}for(const e of t.outs)a.addOutput({script:e.script,value:e.value});return a.toHex()}exports.buildChallengeAssertPsbt=m;exports.buildDepositorPayoutPsbt=O;exports.computeNumLocalChallengers=_;
2
+ //# sourceMappingURL=challengeAssert-CNRdpCzm.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"challengeAssert-CMb7r-je.cjs","sources":["../src/tbv/core/primitives/challengers.ts","../src/tbv/core/primitives/psbt/depositorPayout.ts","../src/tbv/core/primitives/psbt/challengeAssert.ts"],"sourcesContent":["/**\n * Challenger counting utilities.\n *\n * Used for UI-level validation (e.g. computing minimum deposit amounts)\n * where the depositor's identity is known. The transaction builders use\n * `vaultKeeperBtcPubkeys.length` to match the VP's current validation.\n */\n\nimport { processPublicKeyToXOnly } from \"./utils/bitcoin\";\n\n/**\n * Normalize a public key to lowercase x-only hex for reliable comparison.\n *\n * Handles `0x` prefixes, compressed (33-byte), and uncompressed (65-byte) keys.\n */\nfunction normalizeKey(key: string): string {\n return processPublicKeyToXOnly(key).toLowerCase();\n}\n\n/**\n * Compute the number of local challengers for a vault.\n *\n * Mirrors the VP's `compute_num_challengers()` logic:\n * local challengers = {vault_provider} ∪ {vault_keepers} − {depositor}\n *\n * Keys are normalized to x-only lowercase hex before comparison, so\n * `0x`-prefixed, compressed, or mixed-case keys are handled correctly.\n *\n * @param vaultProviderPubkey - Vault provider BTC public key\n * @param vaultKeeperPubkeys - Vault keeper BTC public keys\n * @param depositorPubkey - Depositor (claimer) BTC public key\n * @returns Number of local challengers\n */\nexport function computeNumLocalChallengers(\n vaultProviderPubkey: string,\n vaultKeeperPubkeys: string[],\n depositorPubkey: string,\n): number {\n const localSet = new Set<string>();\n localSet.add(normalizeKey(vaultProviderPubkey));\n for (const vk of vaultKeeperPubkeys) {\n localSet.add(normalizeKey(vk));\n }\n localSet.delete(normalizeKey(depositorPubkey));\n return localSet.size;\n}\n","/**\n * Depositor Payout PSBT Builder\n *\n * Builds unsigned PSBTs for the depositor's own Payout transaction\n * (depositor-as-claimer path). The depositor signs input 0 using the\n * payout taproot script from WasmPeginPayoutConnector (PegIn vault UTXO).\n *\n * Input 0 spends PegIn:0 (the vault UTXO) — the same connector used for\n * VP/VK payout signing. The VP verifies this signature using the\n * PeginPayoutConnector's payout script.\n *\n * @module primitives/psbt/depositorPayout\n * @see btc-vault crates/vault/src/sign.rs — verify_depositor_signature / get_payout_tap_leaf_hash\n */\n\nimport {\n type PayoutConnectorParams,\n getPeginPayoutScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\nimport {\n ASSERT_PAYOUT_OUTPUT_INDEX,\n DEPOSITOR_PAYOUT_INPUT_COUNT,\n PEGIN_VAULT_OUTPUT_INDEX,\n} from \"./constants\";\n\n/**\n * Parameters for building a depositor Payout PSBT\n */\nexport interface DepositorPayoutParams {\n /** Payout transaction hex (unsigned) */\n payoutTxHex: string;\n /** Authoritative PegIn transaction hex — input 0 must spend PegIn:0 */\n peginTxHex: string;\n /** Authoritative Assert transaction hex — input 1 must spend Assert:0 */\n assertTxHex: string;\n /** Parameters for the PeginPayout connector (depositor, VP, VKs, UCs, timelock) */\n connectorParams: PayoutConnectorParams;\n}\n\n/**\n * Build unsigned depositor Payout PSBT.\n *\n * The depositor's payout transaction has 2 inputs:\n * - Input 0: PegIn:0 (vault UTXO) — depositor signs using PeginPayoutConnector payout script\n * - Input 1: Assert:0 — NOT signed by depositor\n *\n * Both inputs must be present in the PSBT because Taproot SIGHASH_DEFAULT\n * commits to all input prevouts. Prevout script_pubkey/value are derived\n * from the authoritative parent transactions, not trusted from external input.\n *\n * @param params - Depositor payout parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the payout transaction does not have exactly 2 inputs\n * @throws If input 0 does not reference peginTxHex at output index 0\n * @throws If input 1 does not reference assertTxHex at output index 0\n */\nexport async function buildDepositorPayoutPsbt(\n params: DepositorPayoutParams,\n): Promise<string> {\n const payoutTx = Transaction.fromHex(stripHexPrefix(params.payoutTxHex));\n const peginTx = Transaction.fromHex(stripHexPrefix(params.peginTxHex));\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n\n if (payoutTx.ins.length !== DEPOSITOR_PAYOUT_INPUT_COUNT) {\n throw new Error(\n `Depositor Payout transaction must have exactly ${DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${payoutTx.ins.length}`,\n );\n }\n\n const input0 = payoutTx.ins[0];\n const input1 = payoutTx.ins[1];\n\n const input0Txid = inputTxidHex(input0);\n const peginTxid = peginTx.getId();\n if (input0Txid !== peginTxid || input0.index !== PEGIN_VAULT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 0 must spend PegIn:${PEGIN_VAULT_OUTPUT_INDEX}. ` +\n `Expected ${peginTxid}:${PEGIN_VAULT_OUTPUT_INDEX}, got ${input0Txid}:${input0.index}`,\n );\n }\n\n const input1Txid = inputTxidHex(input1);\n const assertTxid = assertTx.getId();\n if (input1Txid !== assertTxid || input1.index !== ASSERT_PAYOUT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 1 must spend Assert:${ASSERT_PAYOUT_OUTPUT_INDEX}. ` +\n `Expected ${assertTxid}:${ASSERT_PAYOUT_OUTPUT_INDEX}, got ${input1Txid}:${input1.index}`,\n );\n }\n\n const peginPrevOut = peginTx.outs[input0.index];\n const assertPrevOut = assertTx.outs[input1.index];\n\n const { payoutScript, payoutControlBlock } = await getPeginPayoutScriptInfo(\n params.connectorParams,\n );\n const scriptBytes = hexToUint8Array(payoutScript);\n const controlBlock = hexToUint8Array(payoutControlBlock);\n\n const psbt = new Psbt();\n psbt.setVersion(payoutTx.version);\n psbt.setLocktime(payoutTx.locktime);\n\n psbt.addInput({\n hash: input0.hash,\n index: input0.index,\n sequence: input0.sequence,\n witnessUtxo: {\n script: peginPrevOut.script,\n value: peginPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlock),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n\n psbt.addInput({\n hash: input1.hash,\n index: input1.index,\n sequence: input1.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n });\n\n for (const output of payoutTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n","/**\n * ChallengeAssert PSBT Builder\n *\n * Builds an unsigned PSBT for a ChallengeAssert transaction\n * (depositor-as-claimer path, per challenger). The ChallengeAssert tx has\n * NUM_UTXOS_FOR_CHALLENGE_ASSERT (3) inputs, each spending a different Assert\n * output segment. The depositor signs ALL inputs, each with its own taproot\n * script derived from the per-segment connector params.\n *\n * @module primitives/psbt/challengeAssert\n * @see btc-vault crates/vault/docs/btc-transactions-spec.md — ChallengeAssert connector (NUM_UTXOS_FOR_CHALLENGE_ASSERT=3)\n */\n\nimport {\n type ChallengeAssertConnectorParams,\n getChallengeAssertScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\n\n/**\n * Parameters for building a ChallengeAssert PSBT\n */\nexport interface ChallengeAssertParams {\n /** ChallengeAssert transaction hex (unsigned) */\n challengeAssertTxHex: string;\n /** Authoritative Assert transaction hex — every input must spend an Assert output */\n assertTxHex: string;\n /** Per-input connector params (one per input/segment, determines the taproot script) */\n connectorParamsPerInput: ChallengeAssertConnectorParams[];\n}\n\n/**\n * Build unsigned ChallengeAssert PSBT.\n *\n * The ChallengeAssert transaction has 3 inputs (one per Assert output segment).\n * Each input has its own taproot script derived from its connector params.\n * The depositor signs all inputs. Every prevout is derived from the\n * authoritative Assert transaction, never trusted from external input.\n *\n * @param params - ChallengeAssert parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the number of connector params does not match the number of inputs\n * @throws If any input does not reference assertTxHex\n * @throws If any referenced Assert output is missing\n * @throws If two inputs reference the same Assert output index\n */\nexport async function buildChallengeAssertPsbt(\n params: ChallengeAssertParams,\n): Promise<string> {\n const challengeAssertTx = Transaction.fromHex(\n stripHexPrefix(params.challengeAssertTxHex),\n );\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n const assertTxid = assertTx.getId();\n\n if (params.connectorParamsPerInput.length !== challengeAssertTx.ins.length) {\n throw new Error(\n `Expected ${challengeAssertTx.ins.length} connector params, got ${params.connectorParamsPerInput.length}`,\n );\n }\n\n const seenAssertOutputs = new Set<number>();\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const inputTxid = inputTxidHex(input);\n if (inputTxid !== assertTxid) {\n throw new Error(\n `ChallengeAssert input ${i} must spend an Assert output. ` +\n `Expected txid ${assertTxid}, got ${inputTxid}`,\n );\n }\n if (!assertTx.outs[input.index]) {\n throw new Error(\n `Assert output ${input.index} not found for ChallengeAssert input ${i} (txid: ${assertTxid})`,\n );\n }\n if (seenAssertOutputs.has(input.index)) {\n throw new Error(\n `ChallengeAssert input ${i} duplicates Assert output index ${input.index}`,\n );\n }\n seenAssertOutputs.add(input.index);\n }\n\n const scriptInfos = await Promise.all(\n params.connectorParamsPerInput.map((cp) => getChallengeAssertScriptInfo(cp)),\n );\n\n const psbt = new Psbt();\n psbt.setVersion(challengeAssertTx.version);\n psbt.setLocktime(challengeAssertTx.locktime);\n\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const assertPrevOut = assertTx.outs[input.index];\n\n const { script, controlBlock } = scriptInfos[i];\n const scriptBytes = hexToUint8Array(script);\n const controlBlockBytes = hexToUint8Array(controlBlock);\n\n psbt.addInput({\n hash: input.hash,\n index: input.index,\n sequence: input.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlockBytes),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n }\n\n for (const output of challengeAssertTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n"],"names":["normalizeKey","key","processPublicKeyToXOnly","computeNumLocalChallengers","vaultProviderPubkey","vaultKeeperPubkeys","depositorPubkey","localSet","vk","buildDepositorPayoutPsbt","params","payoutTx","Transaction","stripHexPrefix","peginTx","assertTx","DEPOSITOR_PAYOUT_INPUT_COUNT","input0","input1","input0Txid","inputTxidHex","peginTxid","PEGIN_VAULT_OUTPUT_INDEX","input1Txid","assertTxid","ASSERT_PAYOUT_OUTPUT_INDEX","peginPrevOut","assertPrevOut","payoutScript","payoutControlBlock","getPeginPayoutScriptInfo","scriptBytes","hexToUint8Array","controlBlock","psbt","Psbt","TAPSCRIPT_LEAF_VERSION","Buffer","tapInternalPubkey","output","buildChallengeAssertPsbt","challengeAssertTx","seenAssertOutputs","i","input","inputTxid","scriptInfos","cp","getChallengeAssertScriptInfo","script","controlBlockBytes"],"mappings":"iNAeA,SAASA,EAAaC,EAAqB,CACzC,OAAOC,EAAAA,wBAAwBD,CAAG,EAAE,YAAA,CACtC,CAgBO,SAASE,EACdC,EACAC,EACAC,EACQ,CACR,MAAMC,MAAe,IACrBA,EAAS,IAAIP,EAAaI,CAAmB,CAAC,EAC9C,UAAWI,KAAMH,EACfE,EAAS,IAAIP,EAAaQ,CAAE,CAAC,EAE/B,OAAAD,EAAS,OAAOP,EAAaM,CAAe,CAAC,EACtCC,EAAS,IAClB,CCsBA,eAAsBE,EACpBC,EACiB,CACjB,MAAMC,EAAWC,EAAAA,YAAY,QAAQC,EAAAA,eAAeH,EAAO,WAAW,CAAC,EACjEI,EAAUF,EAAAA,YAAY,QAAQC,EAAAA,eAAeH,EAAO,UAAU,CAAC,EAC/DK,EAAWH,EAAAA,YAAY,QAAQC,EAAAA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G5EF,EAAkB,IAAIE,EAAM,KAAK,CACnC,CAEA,MAAME,EAAc,MAAM,QAAQ,IAChCpC,EAAO,wBAAwB,IAAKqC,GAAOC,EAAAA,6BAA6BD,CAAE,CAAC,CAAA,EAGvEb,EAAO,IAAIC,OACjBD,EAAK,WAAWO,EAAkB,OAAO,EACzCP,EAAK,YAAYO,EAAkB,QAAQ,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAkB,IAAI,OAAQE,IAAK,CACrD,MAAMC,EAAQH,EAAkB,IAAIE,CAAC,EAC/BhB,EAAgBZ,EAAS,KAAK6B,EAAM,KAAK,EAEzC,CAAE,OAAAK,EAAQ,aAAAhB,GAAiBa,EAAYH,CAAC,EACxCZ,EAAcC,EAAAA,gBAAgBiB,CAAM,EACpCC,EAAoBlB,EAAAA,gBAAgBC,CAAY,EAEtDC,EAAK,SAAS,CACZ,KAAMU,EAAM,KACZ,MAAOA,EAAM,MACb,SAAUA,EAAM,SAChB,YAAa,CACX,OAAQjB,EAAc,OACtB,MAAOA,EAAc,KAAA,EAEvB,cAAe,CACb,CACE,YAAaS,EAAAA,uBACb,OAAQC,EAAAA,OAAO,KAAKN,CAAW,EAC/B,aAAcM,EAAAA,OAAO,KAAKa,CAAiB,CAAA,CAC7C,EAEF,eAAgBb,EAAAA,OAAO,KAAKC,EAAAA,iBAAiB,CAAA,CAC9C,CACH,CAEA,UAAWC,KAAUE,EAAkB,KACrCP,EAAK,UAAU,CACb,OAAQK,EAAO,OACf,MAAOA,EAAO,KAAA,CACf,EAGH,OAAOL,EAAK,MAAA,CACd"}
1
+ {"version":3,"file":"challengeAssert-CNRdpCzm.cjs","sources":["../src/tbv/core/primitives/challengers.ts","../src/tbv/core/primitives/psbt/depositorPayout.ts","../src/tbv/core/primitives/psbt/challengeAssert.ts"],"sourcesContent":["/**\n * Challenger counting utilities.\n *\n * Used for UI-level validation (e.g. computing minimum deposit amounts)\n * where the depositor's identity is known. The transaction builders use\n * `vaultKeeperBtcPubkeys.length` to match the VP's current validation.\n */\n\nimport { processPublicKeyToXOnly } from \"./utils/bitcoin\";\n\n/**\n * Normalize a public key to lowercase x-only hex for reliable comparison.\n *\n * Handles `0x` prefixes, compressed (33-byte), and uncompressed (65-byte) keys.\n */\nfunction normalizeKey(key: string): string {\n return processPublicKeyToXOnly(key).toLowerCase();\n}\n\n/**\n * Compute the number of local challengers for a vault.\n *\n * Mirrors the VP's `compute_num_challengers()` logic:\n * local challengers = {vault_provider} ∪ {vault_keepers} − {depositor}\n *\n * Keys are normalized to x-only lowercase hex before comparison, so\n * `0x`-prefixed, compressed, or mixed-case keys are handled correctly.\n *\n * @param vaultProviderPubkey - Vault provider BTC public key\n * @param vaultKeeperPubkeys - Vault keeper BTC public keys\n * @param depositorPubkey - Depositor (claimer) BTC public key\n * @returns Number of local challengers\n */\nexport function computeNumLocalChallengers(\n vaultProviderPubkey: string,\n vaultKeeperPubkeys: string[],\n depositorPubkey: string,\n): number {\n const localSet = new Set<string>();\n localSet.add(normalizeKey(vaultProviderPubkey));\n for (const vk of vaultKeeperPubkeys) {\n localSet.add(normalizeKey(vk));\n }\n localSet.delete(normalizeKey(depositorPubkey));\n return localSet.size;\n}\n","/**\n * Depositor Payout PSBT Builder\n *\n * Builds unsigned PSBTs for the depositor's own Payout transaction\n * (depositor-as-claimer path). The depositor signs input 0 using the\n * payout taproot script from WasmPeginPayoutConnector (PegIn vault UTXO).\n *\n * Input 0 spends PegIn:0 (the vault UTXO) — the same connector used for\n * VP/VK payout signing. The VP verifies this signature using the\n * PeginPayoutConnector's payout script.\n *\n * @module primitives/psbt/depositorPayout\n * @see btc-vault crates/vault/src/sign.rs — verify_depositor_signature / get_payout_tap_leaf_hash\n */\n\nimport {\n type PayoutConnectorParams,\n getPeginPayoutScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\nimport {\n ASSERT_PAYOUT_OUTPUT_INDEX,\n DEPOSITOR_PAYOUT_INPUT_COUNT,\n PEGIN_VAULT_OUTPUT_INDEX,\n} from \"./constants\";\n\n/**\n * Parameters for building a depositor Payout PSBT\n */\nexport interface DepositorPayoutParams {\n /** Payout transaction hex (unsigned) */\n payoutTxHex: string;\n /** Authoritative PegIn transaction hex — input 0 must spend PegIn:0 */\n peginTxHex: string;\n /** Authoritative Assert transaction hex — input 1 must spend Assert:0 */\n assertTxHex: string;\n /** Parameters for the PeginPayout connector (depositor, VP, VKs, UCs, timelock) */\n connectorParams: PayoutConnectorParams;\n}\n\n/**\n * Build unsigned depositor Payout PSBT.\n *\n * The depositor's payout transaction has 2 inputs:\n * - Input 0: PegIn:0 (vault UTXO) — depositor signs using PeginPayoutConnector payout script\n * - Input 1: Assert:0 — NOT signed by depositor\n *\n * Both inputs must be present in the PSBT because Taproot SIGHASH_DEFAULT\n * commits to all input prevouts. Prevout script_pubkey/value are derived\n * from the authoritative parent transactions, not trusted from external input.\n *\n * @param params - Depositor payout parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the payout transaction does not have exactly 2 inputs\n * @throws If input 0 does not reference peginTxHex at output index 0\n * @throws If input 1 does not reference assertTxHex at output index 0\n */\nexport async function buildDepositorPayoutPsbt(\n params: DepositorPayoutParams,\n): Promise<string> {\n const payoutTx = Transaction.fromHex(stripHexPrefix(params.payoutTxHex));\n const peginTx = Transaction.fromHex(stripHexPrefix(params.peginTxHex));\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n\n if (payoutTx.ins.length !== DEPOSITOR_PAYOUT_INPUT_COUNT) {\n throw new Error(\n `Depositor Payout transaction must have exactly ${DEPOSITOR_PAYOUT_INPUT_COUNT} inputs, got ${payoutTx.ins.length}`,\n );\n }\n\n const input0 = payoutTx.ins[0];\n const input1 = payoutTx.ins[1];\n\n const input0Txid = inputTxidHex(input0);\n const peginTxid = peginTx.getId();\n if (input0Txid !== peginTxid || input0.index !== PEGIN_VAULT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 0 must spend PegIn:${PEGIN_VAULT_OUTPUT_INDEX}. ` +\n `Expected ${peginTxid}:${PEGIN_VAULT_OUTPUT_INDEX}, got ${input0Txid}:${input0.index}`,\n );\n }\n\n const input1Txid = inputTxidHex(input1);\n const assertTxid = assertTx.getId();\n if (input1Txid !== assertTxid || input1.index !== ASSERT_PAYOUT_OUTPUT_INDEX) {\n throw new Error(\n `Depositor Payout input 1 must spend Assert:${ASSERT_PAYOUT_OUTPUT_INDEX}. ` +\n `Expected ${assertTxid}:${ASSERT_PAYOUT_OUTPUT_INDEX}, got ${input1Txid}:${input1.index}`,\n );\n }\n\n const peginPrevOut = peginTx.outs[input0.index];\n const assertPrevOut = assertTx.outs[input1.index];\n\n const { payoutScript, payoutControlBlock } = await getPeginPayoutScriptInfo(\n params.connectorParams,\n );\n const scriptBytes = hexToUint8Array(payoutScript);\n const controlBlock = hexToUint8Array(payoutControlBlock);\n\n const psbt = new Psbt();\n psbt.setVersion(payoutTx.version);\n psbt.setLocktime(payoutTx.locktime);\n\n psbt.addInput({\n hash: input0.hash,\n index: input0.index,\n sequence: input0.sequence,\n witnessUtxo: {\n script: peginPrevOut.script,\n value: peginPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlock),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n\n psbt.addInput({\n hash: input1.hash,\n index: input1.index,\n sequence: input1.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n });\n\n for (const output of payoutTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n","/**\n * ChallengeAssert PSBT Builder\n *\n * Builds an unsigned PSBT for a ChallengeAssert transaction\n * (depositor-as-claimer path, per challenger). The ChallengeAssert tx has\n * NUM_UTXOS_FOR_CHALLENGE_ASSERT (3) inputs, each spending a different Assert\n * output segment. The depositor signs ALL inputs, each with its own taproot\n * script derived from the per-segment connector params.\n *\n * @module primitives/psbt/challengeAssert\n * @see btc-vault crates/vault/docs/btc-transactions-spec.md — ChallengeAssert connector (NUM_UTXOS_FOR_CHALLENGE_ASSERT=3)\n */\n\nimport {\n type ChallengeAssertConnectorParams,\n getChallengeAssertScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n hexToUint8Array,\n inputTxidHex,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\n\n/**\n * Parameters for building a ChallengeAssert PSBT\n */\nexport interface ChallengeAssertParams {\n /** ChallengeAssert transaction hex (unsigned) */\n challengeAssertTxHex: string;\n /** Authoritative Assert transaction hex — every input must spend an Assert output */\n assertTxHex: string;\n /** Per-input connector params (one per input/segment, determines the taproot script) */\n connectorParamsPerInput: ChallengeAssertConnectorParams[];\n}\n\n/**\n * Build unsigned ChallengeAssert PSBT.\n *\n * The ChallengeAssert transaction has 3 inputs (one per Assert output segment).\n * Each input has its own taproot script derived from its connector params.\n * The depositor signs all inputs. Every prevout is derived from the\n * authoritative Assert transaction, never trusted from external input.\n *\n * @param params - ChallengeAssert parameters\n * @returns Unsigned PSBT hex ready for signing\n *\n * @throws If the number of connector params does not match the number of inputs\n * @throws If any input does not reference assertTxHex\n * @throws If any referenced Assert output is missing\n * @throws If two inputs reference the same Assert output index\n */\nexport async function buildChallengeAssertPsbt(\n params: ChallengeAssertParams,\n): Promise<string> {\n const challengeAssertTx = Transaction.fromHex(\n stripHexPrefix(params.challengeAssertTxHex),\n );\n const assertTx = Transaction.fromHex(stripHexPrefix(params.assertTxHex));\n const assertTxid = assertTx.getId();\n\n if (params.connectorParamsPerInput.length !== challengeAssertTx.ins.length) {\n throw new Error(\n `Expected ${challengeAssertTx.ins.length} connector params, got ${params.connectorParamsPerInput.length}`,\n );\n }\n\n const seenAssertOutputs = new Set<number>();\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const inputTxid = inputTxidHex(input);\n if (inputTxid !== assertTxid) {\n throw new Error(\n `ChallengeAssert input ${i} must spend an Assert output. ` +\n `Expected txid ${assertTxid}, got ${inputTxid}`,\n );\n }\n if (!assertTx.outs[input.index]) {\n throw new Error(\n `Assert output ${input.index} not found for ChallengeAssert input ${i} (txid: ${assertTxid})`,\n );\n }\n if (seenAssertOutputs.has(input.index)) {\n throw new Error(\n `ChallengeAssert input ${i} duplicates Assert output index ${input.index}`,\n );\n }\n seenAssertOutputs.add(input.index);\n }\n\n const scriptInfos = await Promise.all(\n params.connectorParamsPerInput.map((cp) => getChallengeAssertScriptInfo(cp)),\n );\n\n const psbt = new Psbt();\n psbt.setVersion(challengeAssertTx.version);\n psbt.setLocktime(challengeAssertTx.locktime);\n\n for (let i = 0; i < challengeAssertTx.ins.length; i++) {\n const input = challengeAssertTx.ins[i];\n const assertPrevOut = assertTx.outs[input.index];\n\n const { script, controlBlock } = scriptInfos[i];\n const scriptBytes = hexToUint8Array(script);\n const controlBlockBytes = hexToUint8Array(controlBlock);\n\n psbt.addInput({\n hash: input.hash,\n index: input.index,\n sequence: input.sequence,\n witnessUtxo: {\n script: assertPrevOut.script,\n value: assertPrevOut.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlockBytes),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n }\n\n for (const output of challengeAssertTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n"],"names":["normalizeKey","key","processPublicKeyToXOnly","computeNumLocalChallengers","vaultProviderPubkey","vaultKeeperPubkeys","depositorPubkey","localSet","vk","buildDepositorPayoutPsbt","params","payoutTx","Transaction","stripHexPrefix","peginTx","assertTx","DEPOSITOR_PAYOUT_INPUT_COUNT","input0","input1","input0Txid","inputTxidHex","peginTxid","PEGIN_VAULT_OUTPUT_INDEX","input1Txid","assertTxid","ASSERT_PAYOUT_OUTPUT_INDEX","peginPrevOut","assertPrevOut","payoutScript","payoutControlBlock","getPeginPayoutScriptInfo","scriptBytes","hexToUint8Array","controlBlock","psbt","Psbt","TAPSCRIPT_LEAF_VERSION","Buffer","tapInternalPubkey","output","buildChallengeAssertPsbt","challengeAssertTx","seenAssertOutputs","i","input","inputTxid","scriptInfos","cp","getChallengeAssertScriptInfo","script","controlBlockBytes"],"mappings":"iNAeA,SAASA,EAAaC,EAAqB,CACzC,OAAOC,EAAAA,wBAAwBD,CAAG,EAAE,YAAA,CACtC,CAgBO,SAASE,EACdC,EACAC,EACAC,EACQ,CACR,MAAMC,MAAe,IACrBA,EAAS,IAAIP,EAAaI,CAAmB,CAAC,EAC9C,UAAWI,KAAMH,EACfE,EAAS,IAAIP,EAAaQ,CAAE,CAAC,EAE/B,OAAAD,EAAS,OAAOP,EAAaM,CAAe,CAAC,EACtCC,EAAS,IAClB,CCsBA,eAAsBE,EACpBC,EACiB,CACjB,MAAMC,EAAWC,EAAAA,YAAY,QAAQC,EAAAA,eAAeH,EAAO,WAAW,CAAC,EACjEI,EAAUF,EAAAA,YAAY,QAAQC,EAAAA,eAAeH,EAAO,UAAU,CAAC,EAC/DK,EAAWH,EAAAA,YAAY,QAAQC,EAAAA,eAAeH,EAAO,WAAW,CAAC,EAEvE,GAAIC,EAAS,IAAI,SAAWK,+BAC1B,MAAM,IAAI,MACR,kDAAkDA,EAAAA,4BAA4B,gBAAgBL,EAAS,IAAI,MAAM,EAAA,EAIrH,MAAMM,EAASN,EAAS,IAAI,CAAC,EACvBO,EAAS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AAO,EACzCP,EAAK,YAAYO,EAAkB,QAAQ,EAE3C,QAASE,EAAI,EAAGA,EAAIF,EAAkB,IAAI,OAAQE,IAAK,CACrD,MAAMC,EAAQH,EAAkB,IAAIE,CAAC,EAC/BhB,EAAgBZ,EAAS,KAAK6B,EAAM,KAAK,EAEzC,CAAE,OAAAK,EAAQ,aAAAhB,GAAiBa,EAAYH,CAAC,EACxCZ,EAAcC,EAAAA,gBAAgBiB,CAAM,EACpCC,EAAoBlB,EAAAA,gBAAgBC,CAAY,EAEtDC,EAAK,SAAS,CACZ,KAAMU,EAAM,KACZ,MAAOA,EAAM,MACb,SAAUA,EAAM,SAChB,YAAa,CACX,OAAQjB,EAAc,OACtB,MAAOA,EAAc,KAAA,EAEvB,cAAe,CACb,CACE,YAAaS,EAAAA,uBACb,OAAQC,EAAAA,OAAO,KAAKN,CAAW,EAC/B,aAAcM,EAAAA,OAAO,KAAKa,CAAiB,CAAA,CAC7C,EAEF,eAAgBb,EAAAA,OAAO,KAAKC,EAAAA,iBAAiB,CAAA,CAC9C,CACH,CAEA,UAAWC,KAAUE,EAAkB,KACrCP,EAAK,UAAU,CACb,OAAQK,EAAO,OACf,MAAOA,EAAO,KAAA,CACf,EAGH,OAAOL,EAAK,MAAA,CACd"}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./challengeAssert-CMb7r-je.cjs"),c=require("@babylonlabs-io/babylon-tbv-rust-wasm"),d=require("./peginInput-57FK2O99.cjs"),E=require("./noPayout-B6s8vrW6.cjs"),u=require("./assertPsbtUnsignedTxMatches-CagW7XqW.cjs"),r=require("./bitcoin-CHfKAhcI.cjs"),_=require("./signing-Bnsro0hE.cjs"),P=require("./validation-u8W7Lp2x.cjs"),n=require("./PeginManager-BRHJZYmE.cjs"),g=require("./PayoutManager-BfT0V-tm.cjs"),R=require("./ProtocolParams.abi-DQhcqsNr.cjs"),m=require("./BTCVaultRegistry.abi-CHFGevwa.cjs"),T=require("./errors-BP73_stm.cjs"),b=require("./shared/index.cjs"),i=require("./waitForTransactionReceiptSmartAware-tv1mtSIY.cjs"),a=require("./fundPeginTransaction-BBE3wTjR.cjs"),l=require("./reservation-hjXStM03.cjs"),s=require("./mempoolApi-YNkKjQCU.cjs"),t=require("./vault-registry-reader-CbJHSxVe.cjs"),o=require("./types-D2jcXfm7.cjs"),A=require("./errors-Bu0H-dZD.cjs"),e=require("./buildAndBroadcastRefund-CEKwFY8l.cjs"),p=require("./peginState-BijNNT15.cjs");exports.buildChallengeAssertPsbt=S.buildChallengeAssertPsbt;exports.buildDepositorPayoutPsbt=S.buildDepositorPayoutPsbt;exports.computeNumLocalChallengers=S.computeNumLocalChallengers;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>c.computeMinClaimValue});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>c.deriveVaultId});Object.defineProperty(exports,"expandAuthAnchor",{enumerable:!0,get:()=>c.expandAuthAnchor});Object.defineProperty(exports,"expandHashlockSecret",{enumerable:!0,get:()=>c.expandHashlockSecret});Object.defineProperty(exports,"expandWotsSeed",{enumerable:!0,get:()=>c.expandWotsSeed});exports.buildPeginInputPsbt=d.buildPeginInputPsbt;exports.buildPeginTxFromFundedPrePegin=d.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=d.buildPrePeginPsbt;exports.extractPeginInputSignature=d.extractPeginInputSignature;exports.finalizePeginInputPsbt=d.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=E.buildNoPayoutPsbt;exports.buildRefundPsbt=E.buildRefundPsbt;exports.PsbtSubstitutionError=u.PsbtSubstitutionError;exports.assertPayoutOutputMatchesRegistered=u.assertPayoutOutputMatchesRegistered;exports.assertPsbtUnsignedTxMatches=u.assertPsbtUnsignedTxMatches;exports.buildPayoutPsbt=u.buildPayoutPsbt;exports.createPayoutScript=u.createPayoutScript;exports.extractPayoutSignature=u.extractPayoutSignature;exports.deriveBip86ScriptPubKeyHex=r.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=r.deriveNativeSegwitAddress;exports.deriveTaprootAddress=r.deriveTaprootAddress;exports.ensureHexPrefix=r.ensureHexPrefix;exports.formatSatoshisToBtc=r.formatSatoshisToBtc;exports.getNetwork=r.getNetwork;exports.getSortedXOnlyPubkeys=r.getSortedXOnlyPubkeys;exports.hexToUint8Array=r.hexToUint8Array;exports.isAddressFromPublicKey=r.isAddressFromPublicKey;exports.isValidHex=r.isValidHex;exports.processPublicKeyToXOnly=r.processPublicKeyToXOnly;exports.stripHexPrefix=r.stripHexPrefix;exports.toXOnly=r.toXOnly;exports.uint8ArrayToHex=r.uint8ArrayToHex;exports.validateWalletPubkey=r.validateWalletPubkey;exports.createTaprootScriptPathSignOptions=_.createTaprootScriptPathSignOptions;exports.BITCOIN_ADDRESS_RE=P.BITCOIN_ADDRESS_RE;exports.HEX_RE=P.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=P.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=P.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=P.TXID_RE;exports.PeginManager=n.PeginManager;exports.VAULT_APP_NAME=n.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=n.buildFundingOutpointsCommitment;exports.buildVaultContext=n.buildVaultContext;exports.computeWotsBlockPublicKeysHash=n.computeWotsBlockPublicKeysHash;exports.deriveVaultRoot=n.deriveVaultRoot;exports.deriveWotsBlocksFromSeed=n.deriveWotsBlocksFromSeed;exports.PayoutManager=g.PayoutManager;exports.computeHashlock=g.computeHashlock;exports.validateSecretAgainstHashlock=g.validateSecretAgainstHashlock;exports.ApplicationRegistryABI=R.ApplicationRegistryABI;exports.ProtocolParamsABI=R.ProtocolParamsABI;exports.BTCVaultRegistryABI=m.BTCVaultRegistryABI;exports.CONTRACT_ERRORS=T.CONTRACT_ERRORS;exports.extractErrorData=T.extractErrorData;exports.getContractErrorMessage=T.getContractErrorMessage;exports.handleContractError=T.handleContractError;exports.isKnownContractError=T.isKnownContractError;exports.BitcoinNetworks=b.BitcoinNetworks;exports.BitcoinScriptType=i.BitcoinScriptType;exports.applyChangeOutputPolicy=i.applyChangeOutputPolicy;exports.calculateBtcTxHash=i.calculateBtcTxHash;exports.computeChangeOutputFeeSats=i.computeChangeOutputFeeSats;exports.computeMaxDeposit=i.computeMaxDeposit;exports.computePeginBaseFeeSats=i.computePeginBaseFeeSats;exports.getDustThreshold=i.getDustThreshold;exports.getPsbtInputFields=i.getPsbtInputFields;exports.getScriptType=i.getScriptType;exports.selectUtxosForPegin=i.selectUtxosForPegin;exports.shouldAddChangeOutput=i.shouldAddChangeOutput;exports.waitForTransactionReceiptSmartAware=i.waitForTransactionReceiptSmartAware;exports.BTC_DUST_SAT=a.BTC_DUST_SAT;exports.DUST_THRESHOLD=a.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=a.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=a.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=a.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=a.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=a.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=a.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=a.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=a.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=a.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=a.fundPeginTransaction;exports.parseUnfundedWasmTransaction=a.parseUnfundedWasmTransaction;exports.peginOutputCount=a.peginOutputCount;exports.rateBasedTxBufferFee=a.rateBasedTxBufferFee;exports.UtxoNotAvailableError=l.UtxoNotAvailableError;exports.assertUtxosAvailable=l.assertUtxosAvailable;exports.collectReservedUtxoRefs=l.collectReservedUtxoRefs;exports.extractInputsFromTransaction=l.extractInputsFromTransaction;exports.selectUtxosForDeposit=l.selectUtxosForDeposit;exports.validateUtxosAvailable=l.validateUtxosAvailable;exports.MEMPOOL_API_URLS=s.MEMPOOL_API_URLS;exports.getAddressTxs=s.getAddressTxs;exports.getAddressUtxos=s.getAddressUtxos;exports.getMempoolApiUrl=s.getMempoolApiUrl;exports.getNetworkFees=s.getNetworkFees;exports.getTxHex=s.getTxHex;exports.getTxInfo=s.getTxInfo;exports.getUtxoInfo=s.getUtxoInfo;exports.pushTx=s.pushTx;exports.ServerIdentityError=t.ServerIdentityError;exports.VaultProviderRpcClient=t.VaultProviderRpcClient;exports.ViemProtocolParamsReader=t.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=t.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=t.ViemVaultKeeperReader;exports.ViemVaultRegistryReader=t.ViemVaultRegistryReader;exports.VpResponseValidationError=t.VpResponseValidationError;exports.VpTokenRegistry=t.VpTokenRegistry;exports.batchPollByProvider=t.batchPollByProvider;exports.createAuthenticatedVpClient=t.createAuthenticatedVpClient;exports.primeVpTokenRegistry=t.primeVpTokenRegistry;exports.resolveProtocolAddresses=t.resolveProtocolAddresses;exports.validateOffchainParams=t.validateOffchainParams;exports.validatePegInConfiguration=t.validatePegInConfiguration;exports.validateRequestDepositorClaimerArtifactsResponse=t.validateRequestDepositorClaimerArtifactsResponse;exports.validateTBVProtocolParams=t.validateTBVProtocolParams;exports.verifyServerIdentity=t.verifyServerIdentity;exports.vpTokenRegistry=t.vpTokenRegistry;exports.DaemonStatus=o.DaemonStatus;exports.JSON_RPC_ERROR_CODES=o.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=o.JsonRpcClient;exports.JsonRpcError=o.JsonRpcError;exports.POST_WOTS_STATUSES=o.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=o.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=o.RpcErrorCode;exports.VP_BATCH_MAX_SIZE=o.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=o.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=o.VP_TRANSIENT_STATUSES;exports.isWotsMismatchError=A.isWotsMismatchError;exports.parseFundingOutpointsFromTx=A.parseFundingOutpointsFromTx;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.REFUND_VSIZE=e.REFUND_VSIZE;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.isRegisteredVaultVersionMismatchError=e.isRegisteredVaultVersionMismatchError;exports.runDepositorPresignFlow=e.runDepositorPresignFlow;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateOnChainParticipantKeys=e.validateOnChainParticipantKeys;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.verifyRegisteredVaultVersions=e.verifyRegisteredVaultVersions;exports.waitForPeginStatus=e.waitForPeginStatus;exports.ContractStatus=p.ContractStatus;exports.PeginAction=p.PeginAction;exports.canPerformAction=p.canPerformAction;exports.getPeginProtocolState=p.getPeginProtocolState;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./challengeAssert-CNRdpCzm.cjs"),c=require("@babylonlabs-io/babylon-tbv-rust-wasm"),n=require("./assertPsbtUnsignedTxMatches-fNkAaZZm.cjs"),S=require("./peginInput-DH6X4ITS.cjs"),E=require("./noPayout-jtZsoOzY.cjs"),r=require("./bitcoin-CHfKAhcI.cjs"),_=require("./signing-Bnsro0hE.cjs"),d=require("./validation-u8W7Lp2x.cjs"),u=require("./PeginManager-DaDs-bGr.cjs"),g=require("./PayoutManager-DERMRuUU.cjs"),R=require("./ProtocolParams.abi-DQhcqsNr.cjs"),m=require("./BTCVaultRegistry.abi-CHFGevwa.cjs"),P=require("./errors-BP73_stm.cjs"),b=require("./shared/index.cjs"),i=require("./waitForTransactionReceiptSmartAware-tv1mtSIY.cjs"),a=require("./fundPeginTransaction-BBE3wTjR.cjs"),l=require("./reservation-hjXStM03.cjs"),s=require("./mempoolApi-YNkKjQCU.cjs"),t=require("./vault-registry-reader-CbJHSxVe.cjs"),o=require("./types-D2jcXfm7.cjs"),A=require("./errors-Bu0H-dZD.cjs"),e=require("./buildAndBroadcastRefund-DVMT-pXQ.cjs"),T=require("./peginState-BijNNT15.cjs");exports.buildChallengeAssertPsbt=p.buildChallengeAssertPsbt;exports.buildDepositorPayoutPsbt=p.buildDepositorPayoutPsbt;exports.computeNumLocalChallengers=p.computeNumLocalChallengers;Object.defineProperty(exports,"computeMinClaimValue",{enumerable:!0,get:()=>c.computeMinClaimValue});Object.defineProperty(exports,"deriveVaultId",{enumerable:!0,get:()=>c.deriveVaultId});Object.defineProperty(exports,"expandAuthAnchor",{enumerable:!0,get:()=>c.expandAuthAnchor});Object.defineProperty(exports,"expandHashlockSecret",{enumerable:!0,get:()=>c.expandHashlockSecret});Object.defineProperty(exports,"expandWotsSeed",{enumerable:!0,get:()=>c.expandWotsSeed});exports.PsbtSubstitutionError=n.PsbtSubstitutionError;exports.assertPayoutOutputMatchesRegistered=n.assertPayoutOutputMatchesRegistered;exports.assertPsbtUnsignedTxMatches=n.assertPsbtUnsignedTxMatches;exports.buildPayoutPsbt=n.buildPayoutPsbt;exports.buildPeginTxFromFundedPrePegin=n.buildPeginTxFromFundedPrePegin;exports.buildPrePeginPsbt=n.buildPrePeginPsbt;exports.createPayoutScript=n.createPayoutScript;exports.extractPayoutSignature=n.extractPayoutSignature;exports.buildPeginInputPsbt=S.buildPeginInputPsbt;exports.extractPeginInputSignature=S.extractPeginInputSignature;exports.finalizePeginInputPsbt=S.finalizePeginInputPsbt;exports.buildNoPayoutPsbt=E.buildNoPayoutPsbt;exports.buildRefundPsbt=E.buildRefundPsbt;exports.deriveBip86ScriptPubKeyHex=r.deriveBip86ScriptPubKeyHex;exports.deriveNativeSegwitAddress=r.deriveNativeSegwitAddress;exports.deriveTaprootAddress=r.deriveTaprootAddress;exports.ensureHexPrefix=r.ensureHexPrefix;exports.formatSatoshisToBtc=r.formatSatoshisToBtc;exports.getNetwork=r.getNetwork;exports.getSortedXOnlyPubkeys=r.getSortedXOnlyPubkeys;exports.hexToUint8Array=r.hexToUint8Array;exports.isAddressFromPublicKey=r.isAddressFromPublicKey;exports.isValidHex=r.isValidHex;exports.processPublicKeyToXOnly=r.processPublicKeyToXOnly;exports.stripHexPrefix=r.stripHexPrefix;exports.toXOnly=r.toXOnly;exports.uint8ArrayToHex=r.uint8ArrayToHex;exports.validateWalletPubkey=r.validateWalletPubkey;exports.createTaprootScriptPathSignOptions=_.createTaprootScriptPathSignOptions;exports.BITCOIN_ADDRESS_RE=d.BITCOIN_ADDRESS_RE;exports.HEX_RE=d.HEX_RE;exports.KNOWN_SCRIPT_PREFIXES=d.KNOWN_SCRIPT_PREFIXES;exports.MAX_REASONABLE_FEE_SATS=d.MAX_REASONABLE_FEE_SATS;exports.TXID_RE=d.TXID_RE;exports.PeginManager=u.PeginManager;exports.VAULT_APP_NAME=u.VAULT_APP_NAME;exports.buildFundingOutpointsCommitment=u.buildFundingOutpointsCommitment;exports.buildVaultContext=u.buildVaultContext;exports.computeWotsBlockPublicKeysHash=u.computeWotsBlockPublicKeysHash;exports.deriveVaultRoot=u.deriveVaultRoot;exports.deriveWotsBlocksFromSeed=u.deriveWotsBlocksFromSeed;exports.PayoutManager=g.PayoutManager;exports.computeHashlock=g.computeHashlock;exports.validateSecretAgainstHashlock=g.validateSecretAgainstHashlock;exports.ApplicationRegistryABI=R.ApplicationRegistryABI;exports.ProtocolParamsABI=R.ProtocolParamsABI;exports.BTCVaultRegistryABI=m.BTCVaultRegistryABI;exports.CONTRACT_ERRORS=P.CONTRACT_ERRORS;exports.extractErrorData=P.extractErrorData;exports.getContractErrorMessage=P.getContractErrorMessage;exports.handleContractError=P.handleContractError;exports.isKnownContractError=P.isKnownContractError;exports.BitcoinNetworks=b.BitcoinNetworks;exports.BitcoinScriptType=i.BitcoinScriptType;exports.applyChangeOutputPolicy=i.applyChangeOutputPolicy;exports.calculateBtcTxHash=i.calculateBtcTxHash;exports.computeChangeOutputFeeSats=i.computeChangeOutputFeeSats;exports.computeMaxDeposit=i.computeMaxDeposit;exports.computePeginBaseFeeSats=i.computePeginBaseFeeSats;exports.getDustThreshold=i.getDustThreshold;exports.getPsbtInputFields=i.getPsbtInputFields;exports.getScriptType=i.getScriptType;exports.selectUtxosForPegin=i.selectUtxosForPegin;exports.shouldAddChangeOutput=i.shouldAddChangeOutput;exports.waitForTransactionReceiptSmartAware=i.waitForTransactionReceiptSmartAware;exports.BTC_DUST_SAT=a.BTC_DUST_SAT;exports.DUST_THRESHOLD=a.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=a.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=a.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=a.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=a.P2TR_INPUT_SIZE;exports.PEGIN_AUTH_ANCHOR_OUTPUTS=a.PEGIN_AUTH_ANCHOR_OUTPUTS;exports.PEGIN_FIXED_OUTPUTS=a.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=a.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=a.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=a.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=a.fundPeginTransaction;exports.parseUnfundedWasmTransaction=a.parseUnfundedWasmTransaction;exports.peginOutputCount=a.peginOutputCount;exports.rateBasedTxBufferFee=a.rateBasedTxBufferFee;exports.UtxoNotAvailableError=l.UtxoNotAvailableError;exports.assertUtxosAvailable=l.assertUtxosAvailable;exports.collectReservedUtxoRefs=l.collectReservedUtxoRefs;exports.extractInputsFromTransaction=l.extractInputsFromTransaction;exports.selectUtxosForDeposit=l.selectUtxosForDeposit;exports.validateUtxosAvailable=l.validateUtxosAvailable;exports.MEMPOOL_API_URLS=s.MEMPOOL_API_URLS;exports.getAddressTxs=s.getAddressTxs;exports.getAddressUtxos=s.getAddressUtxos;exports.getMempoolApiUrl=s.getMempoolApiUrl;exports.getNetworkFees=s.getNetworkFees;exports.getTxHex=s.getTxHex;exports.getTxInfo=s.getTxInfo;exports.getUtxoInfo=s.getUtxoInfo;exports.pushTx=s.pushTx;exports.ServerIdentityError=t.ServerIdentityError;exports.VaultProviderRpcClient=t.VaultProviderRpcClient;exports.ViemProtocolParamsReader=t.ViemProtocolParamsReader;exports.ViemUniversalChallengerReader=t.ViemUniversalChallengerReader;exports.ViemVaultKeeperReader=t.ViemVaultKeeperReader;exports.ViemVaultRegistryReader=t.ViemVaultRegistryReader;exports.VpResponseValidationError=t.VpResponseValidationError;exports.VpTokenRegistry=t.VpTokenRegistry;exports.batchPollByProvider=t.batchPollByProvider;exports.createAuthenticatedVpClient=t.createAuthenticatedVpClient;exports.primeVpTokenRegistry=t.primeVpTokenRegistry;exports.resolveProtocolAddresses=t.resolveProtocolAddresses;exports.validateOffchainParams=t.validateOffchainParams;exports.validatePegInConfiguration=t.validatePegInConfiguration;exports.validateRequestDepositorClaimerArtifactsResponse=t.validateRequestDepositorClaimerArtifactsResponse;exports.validateTBVProtocolParams=t.validateTBVProtocolParams;exports.verifyServerIdentity=t.verifyServerIdentity;exports.vpTokenRegistry=t.vpTokenRegistry;exports.DaemonStatus=o.DaemonStatus;exports.JSON_RPC_ERROR_CODES=o.JSON_RPC_ERROR_CODES;exports.JsonRpcClient=o.JsonRpcClient;exports.JsonRpcError=o.JsonRpcError;exports.POST_WOTS_STATUSES=o.POST_WOTS_STATUSES;exports.PRE_DEPOSITOR_SIGNATURES_STATES=o.PRE_DEPOSITOR_SIGNATURES_STATES;exports.RpcErrorCode=o.RpcErrorCode;exports.VP_BATCH_MAX_SIZE=o.VP_BATCH_MAX_SIZE;exports.VP_TERMINAL_FAILURE_STATUSES=o.VP_TERMINAL_FAILURE_STATUSES;exports.VP_TRANSIENT_STATUSES=o.VP_TRANSIENT_STATUSES;exports.isWotsMismatchError=A.isWotsMismatchError;exports.parseFundingOutpointsFromTx=A.parseFundingOutpointsFromTx;exports.BIP68NotMatureError=e.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=e.ClaimerPegoutStatusValue;exports.REFUND_VSIZE=e.REFUND_VSIZE;exports.RegisteredVaultVersionMismatchError=e.RegisteredVaultVersionMismatchError;exports.activateVault=e.activateVault;exports.buildAndBroadcastRefund=e.buildAndBroadcastRefund;exports.estimateRefundFeeSats=e.estimateRefundFeeSats;exports.isDepositAmountValid=e.isDepositAmountValid;exports.isPegoutTerminalStatus=e.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=e.isRecognizedPegoutStatus;exports.isRegisteredVaultVersionMismatchError=e.isRegisteredVaultVersionMismatchError;exports.runDepositorPresignFlow=e.runDepositorPresignFlow;exports.signDepositorGraph=e.signDepositorGraph;exports.submitWotsPublicKey=e.submitWotsPublicKey;exports.validateDepositAmount=e.validateDepositAmount;exports.validateMultiVaultDepositInputs=e.validateMultiVaultDepositInputs;exports.validateOnChainParticipantKeys=e.validateOnChainParticipantKeys;exports.validateProviderSelection=e.validateProviderSelection;exports.validateRemainingCapacity=e.validateRemainingCapacity;exports.validateVaultAmounts=e.validateVaultAmounts;exports.validateVaultProviderPubkey=e.validateVaultProviderPubkey;exports.verifyRegisteredVaultVersions=e.verifyRegisteredVaultVersions;exports.waitForPeginStatus=e.waitForPeginStatus;exports.ContractStatus=T.ContractStatus;exports.PeginAction=T.PeginAction;exports.canPerformAction=T.canPerformAction;exports.getPeginProtocolState=T.getPeginProtocolState;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,31 +1,31 @@
1
- import { a as s, b as t, c as r } from "./challengeAssert-D7OCrDIc.js";
1
+ import { a as s, b as t, c as r } from "./challengeAssert-CBp4mEs0.js";
2
2
  import { computeMinClaimValue as i, deriveVaultId as n, expandAuthAnchor as u, expandHashlockSecret as l, expandWotsSeed as p } from "@babylonlabs-io/babylon-tbv-rust-wasm";
3
- import { c, a as P, b as T, e as S, f as g } from "./peginInput-CYJzbuwA.js";
4
- import { a as m, b as R } from "./noPayout-BhgknZBx.js";
5
- import { P as _, a as x, c as f, b, d as v, e as I } from "./assertPsbtUnsignedTxMatches-Dry5dTfl.js";
3
+ import { P, c, f as T, d as S, a as g, b as E, g as m, e as R } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
4
+ import { b as _, e as x, f } from "./peginInput-BPRB9tUi.js";
5
+ import { a as v, b as I } from "./noPayout-qbaSEKGC.js";
6
6
  import { d as V, a as y, b as O, e as h, f as U, j as F, g as B, h as N, i as D, c as M, p as H, s as L, t as k, u as W, v as X } from "./bitcoin-B5aNKtsk.js";
7
7
  import { c as K } from "./signing-DaLvGwQe.js";
8
8
  import { B as Y, H as Z, K as J, M as j, T as z } from "./validation-CxqROCno.js";
9
- import { P as Q, V as $, b as aa, a as ea, c as sa, e as ta, d as ra } from "./PeginManager-C1en2vwr.js";
10
- import { P as ia, c as na, v as ua } from "./PayoutManager-Cf51DBcu.js";
9
+ import { P as Q, V as $, b as aa, a as ea, c as sa, e as ta, d as ra } from "./PeginManager-Cp2Tn5sH.js";
10
+ import { P as ia, c as na, v as ua } from "./PayoutManager-D29D-K-V.js";
11
11
  import { A as pa, P as da } from "./ProtocolParams.abi-C2brDWTI.js";
12
- import { B as Pa } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
12
+ import { B as ca } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
13
13
  import { C as Sa, e as ga, g as Ea, h as ma, i as Ra } from "./errors-CznAK5NB.js";
14
14
  import { BitcoinNetworks as _a } from "./shared/index.js";
15
15
  import { B as fa, a as ba, f as va, c as Ia, b as Ca, d as Va, g as ya, i as Oa, h as ha, s as Ua, e as Fa, w as Ba } from "./waitForTransactionReceiptSmartAware-CmgFXFza.js";
16
16
  import { B as Da, D as Ma, F as Ha, L as La, M as ka, P as Wa, b as Xa, a as wa, S as Ka, T as Ga, W as Ya, f as Za, c as Ja, p as ja, r as za } from "./fundPeginTransaction-t-6TsHAY.js";
17
17
  import { U as Qa, a as $a, c as ae, e as ee, s as se, v as te } from "./reservation-CB-4FBPk.js";
18
- import { M as oe, g as ie, a as ne, b as ue, c as le, d as pe, e as de, f as ce, p as Pe } from "./mempoolApi-CAIge7Nj.js";
18
+ import { M as oe, g as ie, a as ne, b as ue, c as le, d as pe, e as de, f as Pe, p as ce } from "./mempoolApi-CAIge7Nj.js";
19
19
  import { S as Se, V as ge, j as Ee, k as me, l as Re, m as Ae, a as _e, d as xe, b as fe, f as be, p as ve, r as Ie, g as Ce, h as Ve, v as ye, i as Oe, c as he, e as Ue } from "./vault-registry-reader-BrARgFre.js";
20
20
  import { D as Be, b as Ne, J as De, a as Me, d as He, P as Le, R as ke, e as We, c as Xe, V as we } from "./types-TOmEvvRy.js";
21
21
  import { i as Ge, p as Ye } from "./errors-9AkghWyk.js";
22
- import { B as Je, C as je, p as ze, R as qe, a as Qe, n as $e, o as as, i as es, m as ss, l as ts, j as rs, r as os, b as is, s as ns, v as us, g as ls, h as ps, d as ds, c as cs, e as Ps, f as Ts, k as Ss, w as gs } from "./buildAndBroadcastRefund-vwfVgJeA.js";
22
+ import { B as Je, C as je, p as ze, R as qe, a as Qe, n as $e, o as as, i as es, m as ss, l as ts, j as rs, r as os, b as is, s as ns, v as us, g as ls, h as ps, d as ds, c as Ps, e as cs, f as Ts, k as Ss, w as gs } from "./buildAndBroadcastRefund-B5cOyUzj.js";
23
23
  import { C as ms, P as Rs, c as As, g as _s } from "./peginState-CBAlxgXk.js";
24
24
  export {
25
25
  pa as ApplicationRegistryABI,
26
26
  Je as BIP68NotMatureError,
27
27
  Y as BITCOIN_ADDRESS_RE,
28
- Pa as BTCVaultRegistryABI,
28
+ ca as BTCVaultRegistryABI,
29
29
  Da as BTC_DUST_SAT,
30
30
  _a as BitcoinNetworks,
31
31
  fa as BitcoinScriptType,
@@ -53,7 +53,7 @@ export {
53
53
  Rs as PeginAction,
54
54
  Q as PeginManager,
55
55
  da as ProtocolParamsABI,
56
- _ as PsbtSubstitutionError,
56
+ P as PsbtSubstitutionError,
57
57
  ze as REFUND_VSIZE,
58
58
  qe as RegisteredVaultVersionMismatchError,
59
59
  ke as RpcErrorCode,
@@ -76,20 +76,20 @@ export {
76
76
  Ya as WALLET_RELAY_FEE_RATE_THRESHOLD,
77
77
  Qe as activateVault,
78
78
  ba as applyChangeOutputPolicy,
79
- x as assertPayoutOutputMatchesRegistered,
80
- f as assertPsbtUnsignedTxMatches,
79
+ c as assertPayoutOutputMatchesRegistered,
80
+ T as assertPsbtUnsignedTxMatches,
81
81
  $a as assertUtxosAvailable,
82
82
  fe as batchPollByProvider,
83
83
  $e as buildAndBroadcastRefund,
84
84
  s as buildChallengeAssertPsbt,
85
85
  t as buildDepositorPayoutPsbt,
86
86
  aa as buildFundingOutpointsCommitment,
87
- m as buildNoPayoutPsbt,
88
- b as buildPayoutPsbt,
89
- c as buildPeginInputPsbt,
90
- P as buildPeginTxFromFundedPrePegin,
91
- T as buildPrePeginPsbt,
92
- R as buildRefundPsbt,
87
+ v as buildNoPayoutPsbt,
88
+ S as buildPayoutPsbt,
89
+ _ as buildPeginInputPsbt,
90
+ g as buildPeginTxFromFundedPrePegin,
91
+ E as buildPrePeginPsbt,
92
+ I as buildRefundPsbt,
93
93
  ea as buildVaultContext,
94
94
  va as calculateBtcTxHash,
95
95
  As as canPerformAction,
@@ -102,7 +102,7 @@ export {
102
102
  Va as computePeginBaseFeeSats,
103
103
  sa as computeWotsBlockPublicKeysHash,
104
104
  be as createAuthenticatedVpClient,
105
- v as createPayoutScript,
105
+ m as createPayoutScript,
106
106
  K as createTaprootScriptPathSignOptions,
107
107
  V as deriveBip86ScriptPubKeyHex,
108
108
  y as deriveNativeSegwitAddress,
@@ -117,9 +117,9 @@ export {
117
117
  p as expandWotsSeed,
118
118
  ga as extractErrorData,
119
119
  ee as extractInputsFromTransaction,
120
- I as extractPayoutSignature,
121
- S as extractPeginInputSignature,
122
- g as finalizePeginInputPsbt,
120
+ R as extractPayoutSignature,
121
+ x as extractPeginInputSignature,
122
+ f as finalizePeginInputPsbt,
123
123
  U as formatSatoshisToBtc,
124
124
  Za as fundPeginTransaction,
125
125
  ie as getAddressTxs,
@@ -135,7 +135,7 @@ export {
135
135
  B as getSortedXOnlyPubkeys,
136
136
  pe as getTxHex,
137
137
  de as getTxInfo,
138
- ce as getUtxoInfo,
138
+ Pe as getUtxoInfo,
139
139
  ma as handleContractError,
140
140
  N as hexToUint8Array,
141
141
  D as isAddressFromPublicKey,
@@ -151,7 +151,7 @@ export {
151
151
  ja as peginOutputCount,
152
152
  ve as primeVpTokenRegistry,
153
153
  H as processPublicKeyToXOnly,
154
- Pe as pushTx,
154
+ ce as pushTx,
155
155
  za as rateBasedTxBufferFee,
156
156
  Ie as resolveProtocolAddresses,
157
157
  os as runDepositorPresignFlow,
@@ -169,12 +169,12 @@ export {
169
169
  ps as validateOnChainParticipantKeys,
170
170
  Ve as validatePegInConfiguration,
171
171
  ds as validateProviderSelection,
172
- cs as validateRemainingCapacity,
172
+ Ps as validateRemainingCapacity,
173
173
  ye as validateRequestDepositorClaimerArtifactsResponse,
174
174
  ua as validateSecretAgainstHashlock,
175
175
  Oe as validateTBVProtocolParams,
176
176
  te as validateUtxosAvailable,
177
- Ps as validateVaultAmounts,
177
+ cs as validateVaultAmounts,
178
178
  Ts as validateVaultProviderPubkey,
179
179
  X as validateWalletPubkey,
180
180
  Ss as verifyRegisteredVaultVersions,
@@ -0,0 +1,2 @@
1
+ "use strict";const P=require("@babylonlabs-io/babylon-tbv-rust-wasm"),i=require("buffer"),a=require("bitcoinjs-lib"),n=require("./bitcoin-CHfKAhcI.cjs"),w=require("./assertPsbtUnsignedTxMatches-fNkAaZZm.cjs");async function H(s){await P.initWasm();const{prePeginParams:e,fundedPrePeginTxHex:o,htlcVout:r,refundFee:d,hashlock:c}=s,b=w.normalizeAuthAnchorHash(e.authAnchorHash),u=new P.WasmPrePeginTx(e.depositorPubkey,e.vaultProviderPubkey,e.vaultKeeperPubkeys,e.universalChallengerPubkeys,[...e.hashlocks],new BigUint64Array(e.pegInAmounts),e.timelockRefund,e.feeRate,e.numLocalChallengers,e.councilQuorum,e.councilSize,e.network,b);let t=null;try{t=u.fromFundedTransaction(o);const h=t.buildRefundTx(d,r),l=await P.getPrePeginHtlcConnectorInfo({depositorPubkey:e.depositorPubkey,vaultProviderPubkey:e.vaultProviderPubkey,vaultKeeperPubkeys:e.vaultKeeperPubkeys,universalChallengerPubkeys:e.universalChallengerPubkeys,hashlock:c,timelockRefund:e.timelockRefund,network:e.network}),x=o.startsWith("0x")?o.slice(2):o,k=a.Transaction.fromHex(x),g=k.outs[r];if(!g)throw new Error(`HTLC output at vout ${r} not found in funded Pre-PegIn tx (tx has ${k.outs.length} outputs)`);const f=a.Transaction.fromHex(h);if(f.ins.length!==1)throw new Error(`Refund transaction must have exactly 1 input, got ${f.ins.length}`);const p=f.ins[0],T=k.getId(),v=n.uint8ArrayToHex(new Uint8Array(p.hash).slice().reverse());if(v!==T)throw new Error(`Refund input does not reference the Pre-PegIn transaction. Expected ${T}, got ${v}`);if(p.index!==r)throw new Error(`Refund input index ${p.index} does not match expected htlcVout ${r}`);const y=new a.Psbt;y.setVersion(f.version),y.setLocktime(f.locktime),y.addInput({hash:p.hash,index:p.index,sequence:p.sequence,witnessUtxo:{script:g.script,value:g.value},tapLeafScript:[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:i.Buffer.from(n.hexToUint8Array(l.refundScript)),controlBlock:i.Buffer.from(n.hexToUint8Array(l.refundControlBlock))}],tapInternalKey:i.Buffer.from(P.tapInternalPubkey)});for(const m of f.outs)y.addOutput({script:m.script,value:m.value});return{psbtHex:y.toHex()}}finally{t==null||t.free(),u.free()}}async function A(s){const e=n.stripHexPrefix(s.noPayoutTxHex),o=a.Transaction.fromHex(e),{noPayoutScript:r,noPayoutControlBlock:d}=await P.getAssertNoPayoutScriptInfo(s.connectorParams,s.challengerPubkey),c=n.hexToUint8Array(r),b=n.hexToUint8Array(d),u=new a.Psbt;u.setVersion(o.version),u.setLocktime(o.locktime);for(let t=0;t<o.ins.length;t++){const h=o.ins[t],l=s.prevouts[t];if(!l)throw new Error(`Missing prevout data for input ${t}`);const x={hash:h.hash,index:h.index,sequence:h.sequence,witnessUtxo:{script:i.Buffer.from(n.hexToUint8Array(n.stripHexPrefix(l.script_pubkey))),value:l.value}};t===0&&(x.tapLeafScript=[{leafVersion:n.TAPSCRIPT_LEAF_VERSION,script:i.Buffer.from(c),controlBlock:i.Buffer.from(b)}],x.tapInternalKey=i.Buffer.from(P.tapInternalPubkey)),u.addInput(x)}for(const t of o.outs)u.addOutput({script:t.script,value:t.value});return u.toHex()}function I(s,e,o){const r=a.Transaction.fromHex(n.stripHexPrefix(s));if(r.outs.length!==1)throw new Error(`NoPayout transaction must have exactly 1 output, got ${r.outs.length}`);const d=n.hexToUint8Array(n.processPublicKeyToXOnly(e)),{output:c}=a.payments.p2tr({internalPubkey:i.Buffer.from(d),network:n.getNetwork(o)});if(!c)throw new Error("Failed to derive challenger BIP-86 P2TR scriptPubKey for NoPayout output validation");if(!r.outs[0].script.equals(c))throw new Error("NoPayout transaction does not pay to the expected challenger BIP-86 P2TR address")}exports.assertNoPayoutOutputMatchesChallenger=I;exports.buildNoPayoutPsbt=A;exports.buildRefundPsbt=H;
2
+ //# sourceMappingURL=noPayout-jtZsoOzY.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noPayout-jtZsoOzY.cjs","sources":["../src/tbv/core/primitives/psbt/refund.ts","../src/tbv/core/primitives/psbt/noPayout.ts"],"sourcesContent":["/**\n * Refund PSBT Builder Primitive\n *\n * Builds an unsigned refund PSBT for a depositor to reclaim BTC from\n * a timed-out Pre-PegIn HTLC output via the refund script (leaf 1).\n *\n * The refund script enforces a CSV timelock (timelockRefund blocks) and\n * requires only the depositor's Schnorr signature — no vault provider or\n * keeper involvement.\n *\n * @module primitives/psbt/refund\n */\n\nimport {\n getPrePeginHtlcConnectorInfo,\n initWasm,\n tapInternalPubkey,\n WasmPrePeginTx,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction } from \"bitcoinjs-lib\";\n\nimport { TAPSCRIPT_LEAF_VERSION, hexToUint8Array, uint8ArrayToHex } from \"../utils/bitcoin\";\nimport { normalizeAuthAnchorHash, type PrePeginParams } from \"./pegin\";\n\n/**\n * Parameters for building a refund PSBT\n */\nexport interface BuildRefundPsbtParams {\n /** Same PrePeginParams used when the original Pre-PegIn tx was created */\n prePeginParams: PrePeginParams;\n /** Funded Pre-PegIn transaction hex (the tx whose HTLC output is being refunded) */\n fundedPrePeginTxHex: string;\n /** Index of the HTLC output in the Pre-PegIn transaction */\n htlcVout: number;\n /** Transaction fee in satoshis for the refund transaction */\n refundFee: bigint;\n /** SHA256 hash commitment for the HTLC (64 hex chars, no 0x prefix) */\n hashlock: string;\n}\n\n/**\n * Result of building a refund PSBT\n */\nexport interface BuildRefundPsbtResult {\n /** PSBT hex ready for depositor signing */\n psbtHex: string;\n}\n\n/**\n * Build a PSBT for signing the refund transaction.\n *\n * The refund transaction spends the Pre-PegIn HTLC output via leaf 1\n * (the refund script: `<timelockRefund> CSV DROP <depositorPubkey> CHECKSIG`).\n * The PSBT includes the tapLeafScript entry so the depositor's wallet can\n * sign using Taproot script-path spending.\n *\n * The input's sequence is set to `timelockRefund` by the WASM, enforcing\n * the Bitcoin CSV timelock. The refund broadcast will be rejected by the\n * network if the timelock has not yet expired.\n *\n * @param params - Refund PSBT parameters\n * @returns PSBT hex for depositor signing\n * @throws If the HTLC output at htlcVout is not found\n * @throws If the refund transaction does not have exactly 1 input\n */\nexport async function buildRefundPsbt(\n params: BuildRefundPsbtParams,\n): Promise<BuildRefundPsbtResult> {\n await initWasm();\n\n const { prePeginParams, fundedPrePeginTxHex, htlcVout, refundFee, hashlock } =\n params;\n\n // The 13th positional arg `auth_anchor_hash` is `Option<String>` in\n // the Rust WASM constructor. Production peg-ins (PeginManager) always\n // commit an OP_RETURN <PUSH32 SHA256(authAnchor)> output at\n // `vout = hashlocks.length`; the unfunded template must include it so\n // `fromFundedTransaction` aligns with the funded tx's output shape.\n // Normalize identically to the peg-in primitives (`0x` strip,\n // lowercase, length/charset validation) so a direct primitive caller\n // reusing successful peg-in params doesn't hand unnormalized bytes to\n // WASM. Pass `undefined` for legacy non-auth-anchored Pre-PegIns.\n const normalizedAuthAnchorHash = normalizeAuthAnchorHash(\n prePeginParams.authAnchorHash,\n );\n const unfundedTx = new (WasmPrePeginTx as unknown as new (\n depositor: string,\n vault_provider: string,\n vault_keepers: string[],\n universal_challengers: string[],\n hashlocks: string[],\n pegin_amounts: BigUint64Array,\n timelock_refund: number,\n fee_rate: bigint,\n num_local_challengers: number,\n council_quorum: number,\n council_size: number,\n network: string,\n auth_anchor_hash?: string,\n ) => typeof WasmPrePeginTx.prototype)(\n prePeginParams.depositorPubkey,\n prePeginParams.vaultProviderPubkey,\n prePeginParams.vaultKeeperPubkeys,\n prePeginParams.universalChallengerPubkeys,\n [...prePeginParams.hashlocks],\n new BigUint64Array(prePeginParams.pegInAmounts),\n prePeginParams.timelockRefund,\n prePeginParams.feeRate,\n prePeginParams.numLocalChallengers,\n prePeginParams.councilQuorum,\n prePeginParams.councilSize,\n prePeginParams.network,\n normalizedAuthAnchorHash,\n );\n\n let fundedTx: WasmPrePeginTx | null = null;\n try {\n fundedTx = unfundedTx.fromFundedTransaction(fundedPrePeginTxHex);\n\n const refundTxHex = fundedTx.buildRefundTx(refundFee, htlcVout);\n\n const htlcConnector = await getPrePeginHtlcConnectorInfo({\n depositorPubkey: prePeginParams.depositorPubkey,\n vaultProviderPubkey: prePeginParams.vaultProviderPubkey,\n vaultKeeperPubkeys: prePeginParams.vaultKeeperPubkeys,\n universalChallengerPubkeys: prePeginParams.universalChallengerPubkeys,\n hashlock,\n timelockRefund: prePeginParams.timelockRefund,\n network: prePeginParams.network,\n });\n\n const cleanPrePeginHex = fundedPrePeginTxHex.startsWith(\"0x\")\n ? fundedPrePeginTxHex.slice(2)\n : fundedPrePeginTxHex;\n const prePeginTx = Transaction.fromHex(cleanPrePeginHex);\n\n const htlcOutput = prePeginTx.outs[htlcVout];\n if (!htlcOutput) {\n throw new Error(\n `HTLC output at vout ${htlcVout} not found in funded Pre-PegIn tx ` +\n `(tx has ${prePeginTx.outs.length} outputs)`,\n );\n }\n\n const refundTx = Transaction.fromHex(refundTxHex);\n\n if (refundTx.ins.length !== 1) {\n throw new Error(\n `Refund transaction must have exactly 1 input, got ${refundTx.ins.length}`,\n );\n }\n\n const refundInput = refundTx.ins[0];\n\n // Verify the refund input spends the correct Pre-PegIn HTLC output\n const prePeginTxid = prePeginTx.getId();\n const refundInputTxid = uint8ArrayToHex(\n new Uint8Array(refundInput.hash).slice().reverse(),\n );\n if (refundInputTxid !== prePeginTxid) {\n throw new Error(\n `Refund input does not reference the Pre-PegIn transaction. ` +\n `Expected ${prePeginTxid}, got ${refundInputTxid}`,\n );\n }\n if (refundInput.index !== htlcVout) {\n throw new Error(\n `Refund input index ${refundInput.index} does not match expected htlcVout ${htlcVout}`,\n );\n }\n\n const psbt = new Psbt();\n psbt.setVersion(refundTx.version);\n psbt.setLocktime(refundTx.locktime);\n\n psbt.addInput({\n hash: refundInput.hash,\n index: refundInput.index,\n sequence: refundInput.sequence,\n witnessUtxo: {\n script: htlcOutput.script,\n value: htlcOutput.value,\n },\n tapLeafScript: [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(hexToUint8Array(htlcConnector.refundScript)),\n controlBlock: Buffer.from(\n hexToUint8Array(htlcConnector.refundControlBlock),\n ),\n },\n ],\n tapInternalKey: Buffer.from(tapInternalPubkey),\n });\n\n for (const output of refundTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return { psbtHex: psbt.toHex() };\n } finally {\n fundedTx?.free();\n unfundedTx.free();\n }\n}\n","/**\n * NoPayout PSBT Builder\n *\n * Builds unsigned PSBTs for the depositor's NoPayout transaction\n * (depositor-as-claimer path, per challenger). The depositor signs input 0\n * using the NoPayout taproot script from WasmAssertPayoutNoPayoutConnector.\n *\n * @module primitives/psbt/noPayout\n * @see btc-vault crates/vault/docs/btc-transactions-spec.md — Assert output 0 NoPayout connector\n */\n\nimport {\n type AssertPayoutNoPayoutConnectorParams,\n type Network,\n getAssertNoPayoutScriptInfo,\n tapInternalPubkey,\n} from \"@babylonlabs-io/babylon-tbv-rust-wasm\";\nimport { Buffer } from \"buffer\";\nimport { Psbt, Transaction, payments } from \"bitcoinjs-lib\";\n\nimport {\n TAPSCRIPT_LEAF_VERSION,\n getNetwork,\n hexToUint8Array,\n processPublicKeyToXOnly,\n stripHexPrefix,\n} from \"../utils/bitcoin\";\n\n/**\n * Parameters for building a NoPayout PSBT\n */\nexport interface NoPayoutParams {\n /** NoPayout transaction hex (unsigned) from VP */\n noPayoutTxHex: string;\n /** Challenger's x-only public key (hex encoded) */\n challengerPubkey: string;\n /** Prevouts for all inputs [{script_pubkey, value}] from VP */\n prevouts: Array<{ script_pubkey: string; value: number }>;\n /** Parameters for the Assert Payout/NoPayout connector */\n connectorParams: AssertPayoutNoPayoutConnectorParams;\n}\n\n/**\n * Build unsigned NoPayout PSBT.\n *\n * The NoPayout transaction is specific to each challenger.\n * Input 0 is the one the depositor signs using the NoPayout taproot script path.\n *\n * @param params - NoPayout parameters\n * @returns Unsigned PSBT hex ready for signing\n */\nexport async function buildNoPayoutPsbt(\n params: NoPayoutParams,\n): Promise<string> {\n const noPayoutTxHex = stripHexPrefix(params.noPayoutTxHex);\n const noPayoutTx = Transaction.fromHex(noPayoutTxHex);\n\n // Get NoPayout script and control block for this challenger\n const { noPayoutScript, noPayoutControlBlock } =\n await getAssertNoPayoutScriptInfo(\n params.connectorParams,\n params.challengerPubkey,\n );\n\n const scriptBytes = hexToUint8Array(noPayoutScript);\n const controlBlockBytes = hexToUint8Array(noPayoutControlBlock);\n\n const psbt = new Psbt();\n psbt.setVersion(noPayoutTx.version);\n psbt.setLocktime(noPayoutTx.locktime);\n\n // Add all inputs - depositor signs input 0 only\n for (let i = 0; i < noPayoutTx.ins.length; i++) {\n const input = noPayoutTx.ins[i];\n const prevout = params.prevouts[i];\n\n if (!prevout) {\n throw new Error(`Missing prevout data for input ${i}`);\n }\n\n const inputData: Parameters<typeof psbt.addInput>[0] = {\n hash: input.hash,\n index: input.index,\n sequence: input.sequence,\n witnessUtxo: {\n script: Buffer.from(hexToUint8Array(stripHexPrefix(prevout.script_pubkey))),\n value: prevout.value,\n },\n };\n\n // Input 0: depositor signs using taproot script path\n if (i === 0) {\n inputData.tapLeafScript = [\n {\n leafVersion: TAPSCRIPT_LEAF_VERSION,\n script: Buffer.from(scriptBytes),\n controlBlock: Buffer.from(controlBlockBytes),\n },\n ];\n inputData.tapInternalKey = Buffer.from(tapInternalPubkey);\n }\n\n psbt.addInput(inputData);\n }\n\n // Add outputs\n for (const output of noPayoutTx.outs) {\n psbt.addOutput({\n script: output.script,\n value: output.value,\n });\n }\n\n return psbt.toHex();\n}\n\n/**\n * Validate that a NoPayout transaction pays to the challenger via the\n * protocol-defined output structure: a single BIP-86 P2TR output derived from\n * the challenger's x-only pubkey.\n *\n * Mirrors `assertPayoutOutputMatchesRegistered` for the NoPayout path, where\n * the sink is fixed by the protocol rather than read from on-chain registration\n * (see `crates/vault/src/transactions/nopayout.rs::NoPayoutTx::new`).\n *\n * @param noPayoutTxHex - Raw NoPayout transaction hex\n * @param challengerPubkey - Challenger's x-only public key (hex)\n * @param network - Bitcoin network used to derive the P2TR scriptPubKey\n * @throws If the transaction does not have exactly one output\n * @throws If the single output's scriptPubKey does not equal the BIP-86 P2TR\n * scriptPubKey for the challenger\n */\nexport function assertNoPayoutOutputMatchesChallenger(\n noPayoutTxHex: string,\n challengerPubkey: string,\n network: Network,\n): void {\n const tx = Transaction.fromHex(stripHexPrefix(noPayoutTxHex));\n\n if (tx.outs.length !== 1) {\n throw new Error(\n `NoPayout transaction must have exactly 1 output, got ${tx.outs.length}`,\n );\n }\n\n const xOnly = hexToUint8Array(processPublicKeyToXOnly(challengerPubkey));\n const { output: expectedScript } = payments.p2tr({\n internalPubkey: Buffer.from(xOnly),\n network: getNetwork(network),\n });\n if (!expectedScript) {\n throw new Error(\n \"Failed to derive challenger BIP-86 P2TR scriptPubKey for NoPayout output validation\",\n );\n }\n\n if (!tx.outs[0].script.equals(expectedScript)) {\n throw new Error(\n \"NoPayout transaction does not pay to the expected challenger BIP-86 P2TR address\",\n );\n }\n}\n"],"names":["buildRefundPsbt","params","initWasm","prePeginParams","fundedPrePeginTxHex","htlcVout","refundFee","hashlock","normalizedAuthAnchorHash","normalizeAuthAnchorHash","unfundedTx","WasmPrePeginTx","fundedTx","refundTxHex","htlcConnector","getPrePeginHtlcConnectorInfo","cleanPrePeginHex","prePeginTx","Transaction","htlcOutput","refundTx","refundInput","prePeginTxid","refundInputTxid","uint8ArrayToHex","psbt","Psbt","TAPSCRIPT_LEAF_VERSION","Buffer","hexToUint8Array","tapInternalPubkey","output","buildNoPayoutPsbt","noPayoutTxHex","stripHexPrefix","noPayoutTx","noPayoutScript","noPayoutControlBlock","getAssertNoPayoutScriptInfo","scriptBytes","controlBlockBytes","i","input","prevout","inputData","assertNoPayoutOutputMatchesChallenger","challengerPubkey","network","tx","xOnly","processPublicKeyToXOnly","expectedScript","payments","getNetwork"],"mappings":"iNAkEA,eAAsBA,EACpBC,EACgC,CAChC,MAAMC,WAAA,EAEN,KAAM,CAAE,eAAAC,EAAgB,oBAAAC,EAAqB,SAAAC,EAAU,UAAAC,EAAW,SAAAC,GAChEN,EAWIO,EAA2BC,EAAAA,wBAC/BN,EAAe,cAAA,EAEXO,EAAa,IAAKC,EAAAA,eAetBR,EAAe,gBACfA,EAAe,oBACfA,EAAe,mBACfA,EAAe,2BACf,CAAC,GAAGA,EAAe,SAAS,EAC5B,IAAI,eAAeA,EAAe,YAAY,EAC9CA,EAAe,eACfA,EAAe,QACfA,EAAe,oBACfA,EAAe,cACfA,EAAe,YACfA,EAAe,QACfK,CAAA,EAGF,IAAII,EAAkC,KACtC,GAAI,CACFA,EAAWF,EAAW,sBAAsBN,CAAmB,EAE/D,MAAMS,EAAcD,EAAS,cAAcN,EAAWD,CAAQ,EAExDS,EAAgB,MAAMC,+BAA6B,CACvD,gBAAiBZ,EAAe,gBAChC,oBAAqBA,EAAe,oBACpC,mBAAoBA,EAAe,mBACnC,2BAA4BA,EAAe,2BAC3C,SAAAI,EACA,eAAgBJ,EAAe,eAC/B,QAASA,EAAe,OAAA,CACzB,EAEKa,EAAmBZ,EAAoB,WAAW,IAAI,EACxDA,EAAoB,MAAM,CAAC,EAC3BA,EACEa,EAAaC,EAAAA,YAAY,QAAQF,CAAgB,EAEjDG,EAAaF,EAAW,KAAKZ,CAAQ,EAC3C,GAAI,CAACc,EACH,MAAM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CAAa,CAAC,EAE5D,GAAIe,EAAG,KAAK,SAAW,EACrB,MAAM,IAAI,MACR,wDAAwDA,EAAG,KAAK,MAAM,EAAA,EAI1E,MAAMC,EAAQpB,EAAAA,gBAAgBqB,EAAAA,wBAAwBJ,CAAgB,CAAC,EACjE,CAAE,OAAQK,GAAmBC,EAAAA,SAAS,KAAK,CAC/C,eAAgBxB,EAAAA,OAAO,KAAKqB,CAAK,EACjC,QAASI,EAAAA,WAAWN,CAAO,CAAA,CAC5B,EACD,GAAI,CAACI,EACH,MAAM,IAAI,MACR,qFAAA,EAIJ,GAAI,CAACH,EAAG,KAAK,CAAC,EAAE,OAAO,OAAOG,CAAc,EAC1C,MAAM,IAAI,MACR,kFAAA,CAGN"}
@@ -0,0 +1,145 @@
1
+ import { initWasm as A, WasmPrePeginTx as R, getPrePeginHtlcConnectorInfo as B, tapInternalPubkey as T, getAssertNoPayoutScriptInfo as C } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
+ import { Buffer as u } from "buffer";
3
+ import { Transaction as x, Psbt as H, payments as E } from "bitcoinjs-lib";
4
+ import { u as S, T as I, h as p, s as g, p as $, j as N } from "./bitcoin-B5aNKtsk.js";
5
+ import { n as K } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
6
+ async function F(r) {
7
+ await A();
8
+ const { prePeginParams: e, fundedPrePeginTxHex: o, htlcVout: n, refundFee: f, hashlock: i } = r, y = K(
9
+ e.authAnchorHash
10
+ ), s = new R(
11
+ e.depositorPubkey,
12
+ e.vaultProviderPubkey,
13
+ e.vaultKeeperPubkeys,
14
+ e.universalChallengerPubkeys,
15
+ [...e.hashlocks],
16
+ new BigUint64Array(e.pegInAmounts),
17
+ e.timelockRefund,
18
+ e.feeRate,
19
+ e.numLocalChallengers,
20
+ e.councilQuorum,
21
+ e.councilSize,
22
+ e.network,
23
+ y
24
+ );
25
+ let t = null;
26
+ try {
27
+ t = s.fromFundedTransaction(o);
28
+ const d = t.buildRefundTx(f, n), a = await B({
29
+ depositorPubkey: e.depositorPubkey,
30
+ vaultProviderPubkey: e.vaultProviderPubkey,
31
+ vaultKeeperPubkeys: e.vaultKeeperPubkeys,
32
+ universalChallengerPubkeys: e.universalChallengerPubkeys,
33
+ hashlock: i,
34
+ timelockRefund: e.timelockRefund,
35
+ network: e.network
36
+ }), h = o.startsWith("0x") ? o.slice(2) : o, m = x.fromHex(h), k = m.outs[n];
37
+ if (!k)
38
+ throw new Error(
39
+ `HTLC output at vout ${n} not found in funded Pre-PegIn tx (tx has ${m.outs.length} outputs)`
40
+ );
41
+ const c = x.fromHex(d);
42
+ if (c.ins.length !== 1)
43
+ throw new Error(
44
+ `Refund transaction must have exactly 1 input, got ${c.ins.length}`
45
+ );
46
+ const l = c.ins[0], v = m.getId(), w = S(
47
+ new Uint8Array(l.hash).slice().reverse()
48
+ );
49
+ if (w !== v)
50
+ throw new Error(
51
+ `Refund input does not reference the Pre-PegIn transaction. Expected ${v}, got ${w}`
52
+ );
53
+ if (l.index !== n)
54
+ throw new Error(
55
+ `Refund input index ${l.index} does not match expected htlcVout ${n}`
56
+ );
57
+ const P = new H();
58
+ P.setVersion(c.version), P.setLocktime(c.locktime), P.addInput({
59
+ hash: l.hash,
60
+ index: l.index,
61
+ sequence: l.sequence,
62
+ witnessUtxo: {
63
+ script: k.script,
64
+ value: k.value
65
+ },
66
+ tapLeafScript: [
67
+ {
68
+ leafVersion: I,
69
+ script: u.from(p(a.refundScript)),
70
+ controlBlock: u.from(
71
+ p(a.refundControlBlock)
72
+ )
73
+ }
74
+ ],
75
+ tapInternalKey: u.from(T)
76
+ });
77
+ for (const b of c.outs)
78
+ P.addOutput({
79
+ script: b.script,
80
+ value: b.value
81
+ });
82
+ return { psbtHex: P.toHex() };
83
+ } finally {
84
+ t == null || t.free(), s.free();
85
+ }
86
+ }
87
+ async function z(r) {
88
+ const e = g(r.noPayoutTxHex), o = x.fromHex(e), { noPayoutScript: n, noPayoutControlBlock: f } = await C(
89
+ r.connectorParams,
90
+ r.challengerPubkey
91
+ ), i = p(n), y = p(f), s = new H();
92
+ s.setVersion(o.version), s.setLocktime(o.locktime);
93
+ for (let t = 0; t < o.ins.length; t++) {
94
+ const d = o.ins[t], a = r.prevouts[t];
95
+ if (!a)
96
+ throw new Error(`Missing prevout data for input ${t}`);
97
+ const h = {
98
+ hash: d.hash,
99
+ index: d.index,
100
+ sequence: d.sequence,
101
+ witnessUtxo: {
102
+ script: u.from(p(g(a.script_pubkey))),
103
+ value: a.value
104
+ }
105
+ };
106
+ t === 0 && (h.tapLeafScript = [
107
+ {
108
+ leafVersion: I,
109
+ script: u.from(i),
110
+ controlBlock: u.from(y)
111
+ }
112
+ ], h.tapInternalKey = u.from(T)), s.addInput(h);
113
+ }
114
+ for (const t of o.outs)
115
+ s.addOutput({
116
+ script: t.script,
117
+ value: t.value
118
+ });
119
+ return s.toHex();
120
+ }
121
+ function W(r, e, o) {
122
+ const n = x.fromHex(g(r));
123
+ if (n.outs.length !== 1)
124
+ throw new Error(
125
+ `NoPayout transaction must have exactly 1 output, got ${n.outs.length}`
126
+ );
127
+ const f = p($(e)), { output: i } = E.p2tr({
128
+ internalPubkey: u.from(f),
129
+ network: N(o)
130
+ });
131
+ if (!i)
132
+ throw new Error(
133
+ "Failed to derive challenger BIP-86 P2TR scriptPubKey for NoPayout output validation"
134
+ );
135
+ if (!n.outs[0].script.equals(i))
136
+ throw new Error(
137
+ "NoPayout transaction does not pay to the expected challenger BIP-86 P2TR address"
138
+ );
139
+ }
140
+ export {
141
+ z as a,
142
+ F as b,
143
+ W as c
144
+ };
145
+ //# sourceMappingURL=noPayout-qbaSEKGC.js.map