@babylonlabs-io/ts-sdk 0.56.1 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs +2 -0
  2. package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs.map +1 -0
  3. package/dist/{BTCVaultRegistry.abi-Chs4AFBj.js → BTCVaultRegistry.abi-CixOlp3B.js} +73 -14
  4. package/dist/BTCVaultRegistry.abi-CixOlp3B.js.map +1 -0
  5. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js +111 -0
  6. package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js.map +1 -0
  7. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs +2 -0
  8. package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs.map +1 -0
  9. package/dist/{PeginManager-Ba7Cr51Z.js → PeginManager-CnX3uFb0.js} +5 -5
  10. package/dist/{PeginManager-Ba7Cr51Z.js.map → PeginManager-CnX3uFb0.js.map} +1 -1
  11. package/dist/PeginManager-iDbqXsKD.cjs +2 -0
  12. package/dist/{PeginManager-CcjGRo4O.cjs.map → PeginManager-iDbqXsKD.cjs.map} +1 -1
  13. package/dist/ProtocolParams.abi-C8U7BHCS.cjs +2 -0
  14. package/dist/ProtocolParams.abi-C8U7BHCS.cjs.map +1 -0
  15. package/dist/{ApplicationRegistry.abi-w5prf7Ig.js → ProtocolParams.abi-CV938AYZ.js} +150 -80
  16. package/dist/ProtocolParams.abi-CV938AYZ.js.map +1 -0
  17. package/dist/{buildAndBroadcastRefund-BtXUqBkb.js → buildAndBroadcastRefund-CCb1_z24.js} +627 -452
  18. package/dist/buildAndBroadcastRefund-CCb1_z24.js.map +1 -0
  19. package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs +2 -0
  20. package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +163 -153
  23. package/dist/index.js.map +1 -1
  24. package/dist/{types-CQDRQvV-.js → json-rpc-client-Ehjthcd7.js} +61 -61
  25. package/dist/json-rpc-client-Ehjthcd7.js.map +1 -0
  26. package/dist/{types-WA0LrDk1.cjs → json-rpc-client-fUoK-TzT.cjs} +2 -2
  27. package/dist/json-rpc-client-fUoK-TzT.cjs.map +1 -0
  28. package/dist/mempoolApi-C0olk43O.js +536 -0
  29. package/dist/mempoolApi-C0olk43O.js.map +1 -0
  30. package/dist/mempoolApi-Dsm2VPXp.cjs +2 -0
  31. package/dist/mempoolApi-Dsm2VPXp.cjs.map +1 -0
  32. package/dist/{noPayout-CihCk1HE.js → noPayout-CI4l1qu2.js} +2 -2
  33. package/dist/{noPayout-CihCk1HE.js.map → noPayout-CI4l1qu2.js.map} +1 -1
  34. package/dist/{noPayout-Cb8vFrkY.cjs → noPayout-Djrv31V5.cjs} +2 -2
  35. package/dist/{noPayout-Cb8vFrkY.cjs.map → noPayout-Djrv31V5.cjs.map} +1 -1
  36. package/dist/onChainBtcPubkey-Cd9kpz-S.cjs +2 -0
  37. package/dist/onChainBtcPubkey-Cd9kpz-S.cjs.map +1 -0
  38. package/dist/onChainBtcPubkey-aPY5ib3Q.js +19 -0
  39. package/dist/onChainBtcPubkey-aPY5ib3Q.js.map +1 -0
  40. package/dist/primeVpAuth-BlxUcdBf.cjs +2 -0
  41. package/dist/primeVpAuth-BlxUcdBf.cjs.map +1 -0
  42. package/dist/{primeVpAuth-Caa5J_uv.js → primeVpAuth-DkJbvywo.js} +479 -367
  43. package/dist/primeVpAuth-DkJbvywo.js.map +1 -0
  44. package/dist/signPsbtsWithFallback-C01N6Kdo.cjs +2 -0
  45. package/dist/signPsbtsWithFallback-C01N6Kdo.cjs.map +1 -0
  46. package/dist/{PayoutManager-BVgmuKuK.js → signPsbtsWithFallback-CzZFZf0I.js} +105 -101
  47. package/dist/signPsbtsWithFallback-CzZFZf0I.js.map +1 -0
  48. package/dist/tbv/core/clients/eth/index.d.ts +5 -3
  49. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  50. package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts +16 -0
  51. package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts.map +1 -0
  52. package/dist/tbv/core/clients/eth/operation-key-reader.d.ts +33 -0
  53. package/dist/tbv/core/clients/eth/operation-key-reader.d.ts.map +1 -0
  54. package/dist/tbv/core/clients/eth/types.d.ts +122 -3
  55. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  56. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +25 -1
  57. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  58. package/dist/tbv/core/clients/index.cjs +1 -1
  59. package/dist/tbv/core/clients/index.js +35 -32
  60. package/dist/tbv/core/clients/index.js.map +1 -1
  61. package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts +2 -0
  62. package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts.map +1 -0
  63. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +66 -0
  64. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -1
  65. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +50 -0
  66. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  67. package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts +111 -0
  68. package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts.map +1 -0
  69. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +36 -0
  70. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
  71. package/dist/tbv/core/contracts/index.cjs +1 -1
  72. package/dist/tbv/core/contracts/index.d.ts +2 -1
  73. package/dist/tbv/core/contracts/index.d.ts.map +1 -1
  74. package/dist/tbv/core/contracts/index.js +8 -6
  75. package/dist/tbv/core/contracts/index.js.map +1 -1
  76. package/dist/tbv/core/index.cjs +1 -1
  77. package/dist/tbv/core/index.js +163 -153
  78. package/dist/tbv/core/index.js.map +1 -1
  79. package/dist/tbv/core/managers/PayoutManager.d.ts +8 -0
  80. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  81. package/dist/tbv/core/managers/index.cjs +1 -1
  82. package/dist/tbv/core/managers/index.js +2 -2
  83. package/dist/tbv/core/primitives/index.cjs +1 -1
  84. package/dist/tbv/core/primitives/index.js +2 -2
  85. package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts +2 -0
  86. package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts.map +1 -0
  87. package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +5 -5
  88. package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -1
  89. package/dist/tbv/core/primitives/psbt/payout.d.ts +23 -0
  90. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  91. package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts +41 -0
  92. package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts.map +1 -0
  93. package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts +2 -0
  94. package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts.map +1 -0
  95. package/dist/tbv/core/services/deposit/index.d.ts +7 -6
  96. package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
  97. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +10 -0
  98. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  99. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +9 -0
  100. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  101. package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +38 -1
  102. package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
  103. package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts +42 -0
  104. package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts.map +1 -0
  105. package/dist/tbv/core/services/index.cjs +1 -1
  106. package/dist/tbv/core/services/index.d.ts +1 -0
  107. package/dist/tbv/core/services/index.d.ts.map +1 -1
  108. package/dist/tbv/core/services/index.js +36 -31
  109. package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts +55 -0
  110. package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts.map +1 -0
  111. package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts +2 -0
  112. package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts.map +1 -0
  113. package/dist/tbv/core/services/participants/index.d.ts +8 -0
  114. package/dist/tbv/core/services/participants/index.d.ts.map +1 -0
  115. package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts +26 -0
  116. package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts.map +1 -0
  117. package/dist/tbv/core/services/participants/types.d.ts +62 -0
  118. package/dist/tbv/core/services/participants/types.d.ts.map +1 -0
  119. package/dist/tbv/index.cjs +1 -1
  120. package/dist/tbv/index.js +163 -153
  121. package/dist/tbv/index.js.map +1 -1
  122. package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs +2 -0
  123. package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs.map +1 -0
  124. package/dist/{verifyScriptPathSchnorrSignature-CgrnAjMW.js → verifyScriptPathSchnorrSignature-Xoo9DOHW.js} +359 -301
  125. package/dist/verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map +1 -0
  126. package/package.json +1 -1
  127. package/dist/ApplicationRegistry.abi-CLaa6E99.cjs +0 -2
  128. package/dist/ApplicationRegistry.abi-CLaa6E99.cjs.map +0 -1
  129. package/dist/ApplicationRegistry.abi-w5prf7Ig.js.map +0 -1
  130. package/dist/BTCVaultRegistry.abi-Chs4AFBj.js.map +0 -1
  131. package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs +0 -2
  132. package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs.map +0 -1
  133. package/dist/PayoutManager-BVgmuKuK.js.map +0 -1
  134. package/dist/PayoutManager-Cu4_l-_Y.cjs +0 -2
  135. package/dist/PayoutManager-Cu4_l-_Y.cjs.map +0 -1
  136. package/dist/PeginManager-CcjGRo4O.cjs +0 -2
  137. package/dist/buildAndBroadcastRefund-BtXUqBkb.js.map +0 -1
  138. package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs +0 -2
  139. package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs.map +0 -1
  140. package/dist/mempoolApi-DkyKmmgI.cjs +0 -2
  141. package/dist/mempoolApi-DkyKmmgI.cjs.map +0 -1
  142. package/dist/mempoolApi-lpJdvPkK.js +0 -483
  143. package/dist/mempoolApi-lpJdvPkK.js.map +0 -1
  144. package/dist/primeVpAuth-Caa5J_uv.js.map +0 -1
  145. package/dist/primeVpAuth-y-4A88ah.cjs +0 -2
  146. package/dist/primeVpAuth-y-4A88ah.cjs.map +0 -1
  147. package/dist/types-CQDRQvV-.js.map +0 -1
  148. package/dist/types-WA0LrDk1.cjs.map +0 -1
  149. package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs +0 -2
  150. package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs.map +0 -1
  151. package/dist/verifyScriptPathSchnorrSignature-CgrnAjMW.js.map +0 -1
@@ -1,11 +1,11 @@
1
- import { computeMinClaimValue as D, peginP2aAnchorOutput as G, computeMinPeginFee as Z, buildPeginTxFromPrePegin as j, createPrePeginTransaction as J, validatePeginP2aAnchor as ee, tapInternalPubkey as Y, createPayoutConnector as te, computePayoutFeeFloor as ne } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
- import { Buffer as d } from "buffer";
3
- import { Transaction as S, script as oe, opcodes as re, payments as ie, Psbt as A, crypto as se } from "bitcoinjs-lib";
4
- import { c as V, d as ue } from "./fundPeginTransaction-B2wyjqp0.js";
5
- import { s as P, u as _, h as m, c as ce, d as ae, T as I, S as k, X as H } from "./bitcoin-B5aNKtsk.js";
6
- import { D as O, P as R, M as L, b, c as le, A as he, B as de, V as pe, N as U } from "./constants-CDQE812z.js";
7
- import * as Pe from "@bitcoin-js/tiny-secp256k1-asmjs";
8
- async function ge(e, t) {
1
+ import { computeMinClaimValue as Z, peginP2aAnchorOutput as j, computeMinPeginFee as ne, buildPeginTxFromPrePegin as oe, createPrePeginTransaction as re, validatePeginP2aAnchor as ie, tapInternalPubkey as J, createPayoutConnector as se, computePayoutFeeFloor as ue } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
+ import { Buffer as p } from "buffer";
3
+ import { Transaction as m, script as ce, opcodes as ae, payments as le, Psbt as C, crypto as he } from "bitcoinjs-lib";
4
+ import { c as V, d as de } from "./fundPeginTransaction-B2wyjqp0.js";
5
+ import { s as g, u as _, h as y, c as pe, T as A, d as Pe, S as k, X as H } from "./bitcoin-B5aNKtsk.js";
6
+ import { D as L, P as O, M as R, b as U, c as ge, A as fe, B as ve, V as we, N as K } from "./constants-CDQE812z.js";
7
+ import * as $e from "@bitcoin-js/tiny-secp256k1-asmjs";
8
+ async function xe(e, t) {
9
9
  const n = t.pegInAmounts.length;
10
10
  if (e.htlcValues.length !== n)
11
11
  throw new Error(
@@ -19,7 +19,7 @@ async function ge(e, t) {
19
19
  throw new Error(
20
20
  `WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
21
21
  );
22
- const i = await D(
22
+ const r = await Z(
23
23
  // Must price the same graph version the builder constructed.
24
24
  t.vaultCoreVersion,
25
25
  t.numLocalChallengers,
@@ -28,67 +28,67 @@ async function ge(e, t) {
28
28
  t.councilSize,
29
29
  t.feeRate
30
30
  );
31
- if (e.depositorClaimValue !== i)
31
+ if (e.depositorClaimValue !== r)
32
32
  throw new Error(
33
- `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${i} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
33
+ `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${r} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
34
34
  );
35
- const o = await G(t.vaultCoreVersion), r = (o == null ? void 0 : o.value) ?? 0n, s = await Z(
35
+ const o = await j(t.vaultCoreVersion), i = (o == null ? void 0 : o.value) ?? 0n, s = await ne(
36
36
  t.vaultCoreVersion,
37
37
  t.vaultKeeperPubkeys.length,
38
38
  t.universalChallengerPubkeys.length,
39
39
  t.minPeginFeeRate
40
- ), u = s + r, l = t.minPeginFeeRate * V;
40
+ ), u = s + i, h = t.minPeginFeeRate * V;
41
41
  for (let c = 0; c < n; c++) {
42
- const h = t.pegInAmounts[c], p = e.peginAmounts[c], g = e.htlcValues[c];
43
- if (p !== h)
42
+ const l = t.pegInAmounts[c], a = e.peginAmounts[c], f = e.htlcValues[c];
43
+ if (a !== l)
44
44
  throw new Error(
45
- `WASM Pre-PegIn peginAmount[${c}] ${p} does not match the requested amount ${h}; refusing to build a tx whose recorded amount differs from the depositor's request.`
45
+ `WASM Pre-PegIn peginAmount[${c}] ${a} does not match the requested amount ${l}; refusing to build a tx whose recorded amount differs from the depositor's request.`
46
46
  );
47
- if (p <= 0n)
47
+ if (a <= 0n)
48
48
  throw new Error(
49
- `WASM Pre-PegIn peginAmount[${c}] is non-positive (${p}); expected > 0.`
49
+ `WASM Pre-PegIn peginAmount[${c}] is non-positive (${a}); expected > 0.`
50
50
  );
51
- if (g <= 0n)
51
+ if (f <= 0n)
52
52
  throw new Error(
53
- `WASM Pre-PegIn htlcValue[${c}] is non-positive (${g}); expected > 0.`
53
+ `WASM Pre-PegIn htlcValue[${c}] is non-positive (${f}); expected > 0.`
54
54
  );
55
- const a = g - p - e.depositorClaimValue;
56
- if (a <= 0n)
55
+ const d = f - a - e.depositorClaimValue;
56
+ if (d <= 0n)
57
57
  throw new Error(
58
- `WASM Pre-PegIn htlcValue[${c}] ${g} does not strictly cover peginAmount ${p} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${a}).`
58
+ `WASM Pre-PegIn htlcValue[${c}] ${f} does not strictly cover peginAmount ${a} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${d}).`
59
59
  );
60
- if (a > l)
60
+ if (d > h)
61
61
  throw new Error(
62
- `WASM Pre-PegIn implied reserve for HTLC[${c}] (${a} sat) exceeds the plausibility cap ${l} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${V} vbytes); htlcValue ${g} appears grossly inflated.`
62
+ `WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${V} vbytes); htlcValue ${f} appears grossly inflated.`
63
63
  );
64
- if (a !== u)
64
+ if (d !== u)
65
65
  throw new Error(
66
- `WASM Pre-PegIn htlcValue[${c}] ${g} implies a PegIn fee+anchor reserve of ${a} sat, expected exactly ${u} sat (minPeginFee ${s} + p2aAnchor ${r} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
66
+ `WASM Pre-PegIn htlcValue[${c}] ${f} implies a PegIn fee+anchor reserve of ${d} sat, expected exactly ${u} sat (minPeginFee ${s} + p2aAnchor ${i} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
67
67
  );
68
68
  }
69
69
  return s;
70
70
  }
71
- function fe(e, t, n) {
71
+ function Se(e, t, n) {
72
72
  if (e.length < t.length)
73
73
  throw new Error(
74
74
  `Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
75
75
  );
76
- for (let i = 0; i < t.length; i++) {
77
- const o = BigInt(e[i].value);
78
- if (o !== t[i])
76
+ for (let r = 0; r < t.length; r++) {
77
+ const o = BigInt(e[r].value);
78
+ if (o !== t[r])
79
79
  throw new Error(
80
- `Encoded Pre-PegIn HTLC output[${i}] value ${o} does not match the cross-checked htlcValue ${t[i]}; the funded/signed tx would not pay the validated amount.`
80
+ `Encoded Pre-PegIn HTLC output[${r}] value ${o} does not match the cross-checked htlcValue ${t[r]}; the funded/signed tx would not pay the validated amount.`
81
81
  );
82
- const r = e[i].script.toString("hex").toLowerCase(), s = n[i].toLowerCase();
83
- if (r !== s)
82
+ const i = e[r].script.toString("hex").toLowerCase(), s = n[r].toLowerCase();
83
+ if (i !== s)
84
84
  throw new Error(
85
- `Encoded Pre-PegIn HTLC output[${i}] scriptPubKey ${r} does not match the cross-checked htlcScriptPubKey ${s}.`
85
+ `Encoded Pre-PegIn HTLC output[${r}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${s}.`
86
86
  );
87
87
  }
88
88
  }
89
- const B = 64, ve = /^[0-9a-fA-F]+$/;
90
- async function We(e) {
91
- const t = Q(e.authAnchorHash), n = await J({
89
+ const N = 64, me = /^[0-9a-fA-F]+$/;
90
+ async function it(e) {
91
+ const t = ee(e.authAnchorHash), n = await re({
92
92
  txGraphVersion: e.vaultCoreVersion,
93
93
  depositorPubkey: e.depositorPubkey,
94
94
  vaultProviderPubkey: e.vaultProviderPubkey,
@@ -104,39 +104,39 @@ async function We(e) {
104
104
  councilSize: e.councilSize,
105
105
  network: e.network,
106
106
  authAnchorHash: t
107
- }), i = await ge(n, e), o = ue(n.txHex);
108
- fe(
107
+ }), r = await xe(n, e), o = de(n.txHex);
108
+ Se(
109
109
  o.outputs,
110
110
  n.htlcValues,
111
111
  n.htlcScriptPubKeys
112
112
  );
113
- const r = o.outputs.reduce(
114
- (u, l) => u + BigInt(l.value),
113
+ const i = o.outputs.reduce(
114
+ (u, h) => u + BigInt(h.value),
115
115
  0n
116
116
  ), s = t !== void 0 ? n.htlcValues.length : null;
117
117
  return {
118
118
  psbtHex: n.txHex,
119
- totalOutputValue: r,
119
+ totalOutputValue: i,
120
120
  htlcValues: n.htlcValues,
121
121
  htlcScriptPubKeys: n.htlcScriptPubKeys,
122
122
  htlcAddresses: n.htlcAddresses,
123
123
  peginAmounts: n.peginAmounts,
124
124
  depositorClaimValue: n.depositorClaimValue,
125
125
  authAnchorVout: s,
126
- minPeginFee: i
126
+ minPeginFee: r
127
127
  };
128
128
  }
129
- function Q(e) {
129
+ function ee(e) {
130
130
  if (e === void 0) return;
131
131
  const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
132
- if (t.length !== B || !ve.test(t))
132
+ if (t.length !== N || !me.test(t))
133
133
  throw new Error(
134
- `authAnchorHash must be 32-byte hex (${B} chars, no 0x prefix); got length ${t.length}`
134
+ `authAnchorHash must be 32-byte hex (${N} chars, no 0x prefix); got length ${t.length}`
135
135
  );
136
136
  return t.toLowerCase();
137
137
  }
138
- async function Xe(e) {
139
- const t = await j(
138
+ async function st(e) {
139
+ const t = await oe(
140
140
  {
141
141
  txGraphVersion: e.prePeginParams.vaultCoreVersion,
142
142
  depositorPubkey: e.prePeginParams.depositorPubkey,
@@ -152,7 +152,7 @@ async function Xe(e) {
152
152
  councilQuorum: e.prePeginParams.councilQuorum,
153
153
  councilSize: e.prePeginParams.councilSize,
154
154
  network: e.prePeginParams.network,
155
- authAnchorHash: Q(
155
+ authAnchorHash: ee(
156
156
  e.prePeginParams.authAnchorHash
157
157
  )
158
158
  },
@@ -160,87 +160,87 @@ async function Xe(e) {
160
160
  e.fundedPrePeginTxHex,
161
161
  e.htlcVout
162
162
  );
163
- return await xe(t, e), {
163
+ return await Ce(t, e), {
164
164
  txHex: t.txHex,
165
165
  txid: t.txid,
166
166
  vaultScriptPubKey: t.vaultScriptPubKey,
167
167
  vaultValue: t.vaultValue
168
168
  };
169
169
  }
170
- const we = 2, $e = 1;
171
- async function xe(e, t) {
170
+ const ye = 2, Ee = 1;
171
+ async function Ce(e, t) {
172
172
  const n = t.prePeginParams.vaultCoreVersion;
173
- await ee(n, e.txHex);
174
- const i = await G(n), o = we + (i ? 1 : 0), r = S.fromHex(P(e.txHex));
175
- if (r.ins.length !== 1)
173
+ await ie(n, e.txHex);
174
+ const r = await j(n), o = ye + (r ? 1 : 0), i = m.fromHex(g(e.txHex));
175
+ if (i.ins.length !== 1)
176
176
  throw new Error(
177
- `PegIn tx has ${r.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
177
+ `PegIn tx has ${i.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
178
178
  );
179
- const s = S.fromHex(
180
- P(t.fundedPrePeginTxHex)
179
+ const s = m.fromHex(
180
+ g(t.fundedPrePeginTxHex)
181
181
  ).getId(), u = _(
182
- new Uint8Array(r.ins[0].hash).slice().reverse()
182
+ new Uint8Array(i.ins[0].hash).slice().reverse()
183
183
  );
184
184
  if (u !== s)
185
185
  throw new Error(
186
186
  `PegIn input spends txid ${u}, expected the funded Pre-PegIn ${s}.`
187
187
  );
188
- if (r.ins[0].index !== t.htlcVout)
188
+ if (i.ins[0].index !== t.htlcVout)
189
189
  throw new Error(
190
- `PegIn input spends Pre-PegIn output ${r.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
190
+ `PegIn input spends Pre-PegIn output ${i.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
191
191
  );
192
- if (r.outs.length !== o)
192
+ if (i.outs.length !== o)
193
193
  throw new Error(
194
- `PegIn tx has ${r.outs.length} output(s), expected exactly ${o} for vaultCoreVersion ${n} (vault + depositor claim${i ? " + P2A anchor" : ""}).`
194
+ `PegIn tx has ${i.outs.length} output(s), expected exactly ${o} for vaultCoreVersion ${n} (vault + depositor claim${r ? " + P2A anchor" : ""}).`
195
195
  );
196
- const l = t.prePeginParams.pegInAmounts[t.htlcVout];
197
- if (e.vaultValue !== l)
196
+ const h = t.prePeginParams.pegInAmounts[t.htlcVout];
197
+ if (e.vaultValue !== h)
198
198
  throw new Error(
199
- `PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${l} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
199
+ `PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${h} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
200
200
  );
201
- const c = r.outs[0];
201
+ const c = i.outs[0];
202
202
  if (BigInt(c.value) !== e.vaultValue)
203
203
  throw new Error(
204
204
  `Encoded PegIn vault output value ${c.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
205
205
  );
206
- const h = c.script.toString("hex"), p = P(
206
+ const l = c.script.toString("hex"), a = g(
207
207
  e.vaultScriptPubKey
208
208
  ).toLowerCase();
209
- if (h.toLowerCase() !== p)
209
+ if (l.toLowerCase() !== a)
210
210
  throw new Error(
211
- `Encoded PegIn vault output scriptPubKey ${h} does not match the WASM-reported vaultScriptPubKey ${e.vaultScriptPubKey}.`
211
+ `Encoded PegIn vault output scriptPubKey ${l} does not match the WASM-reported vaultScriptPubKey ${e.vaultScriptPubKey}.`
212
212
  );
213
- const g = r.getId();
214
- if (g !== P(e.txid).toLowerCase())
213
+ const f = i.getId();
214
+ if (f !== g(e.txid).toLowerCase())
215
215
  throw new Error(
216
- `Encoded PegIn txid ${g} does not match the WASM-reported txid ${e.txid}.`
216
+ `Encoded PegIn txid ${f} does not match the WASM-reported txid ${e.txid}.`
217
217
  );
218
- const a = await D(
218
+ const d = await Z(
219
219
  n,
220
220
  t.prePeginParams.numLocalChallengers,
221
221
  t.prePeginParams.universalChallengerPubkeys.length,
222
222
  t.prePeginParams.councilQuorum,
223
223
  t.prePeginParams.councilSize,
224
224
  t.prePeginParams.feeRate
225
- ), v = r.outs[$e];
226
- if (BigInt(v.value) !== a)
225
+ ), x = i.outs[Ee];
226
+ if (BigInt(x.value) !== d)
227
227
  throw new Error(
228
- `Encoded PegIn depositor-claim output value ${v.value} does not match the independently computed claim value ${a} for vaultCoreVersion ${n}.`
228
+ `Encoded PegIn depositor-claim output value ${x.value} does not match the independently computed claim value ${d} for vaultCoreVersion ${n}.`
229
229
  );
230
- const $ = Se(
230
+ const v = be(
231
231
  t.prePeginParams.depositorPubkey
232
232
  );
233
- if (!v.script.equals($))
233
+ if (!x.script.equals(v))
234
234
  throw new Error(
235
- `Encoded PegIn depositor-claim output scriptPubKey ${v.script.toString("hex")} does not pay to the depositor's claim script (expected ${$.toString("hex")}).`
235
+ `Encoded PegIn depositor-claim output scriptPubKey ${x.script.toString("hex")} does not pay to the depositor's claim script (expected ${v.toString("hex")}).`
236
236
  );
237
237
  }
238
- function Se(e) {
239
- const t = oe.compile([
240
- d.from(m(e)),
241
- re.OP_CHECKSIG
242
- ]), { output: n } = ie.p2tr({
243
- internalPubkey: d.from(Y),
238
+ function be(e) {
239
+ const t = ce.compile([
240
+ p.from(y(e)),
241
+ ae.OP_CHECKSIG
242
+ ]), { output: n } = le.p2tr({
243
+ internalPubkey: p.from(J),
244
244
  scriptTree: { output: t }
245
245
  });
246
246
  if (!n)
@@ -249,8 +249,8 @@ function Se(e) {
249
249
  );
250
250
  return n;
251
251
  }
252
- async function me(e) {
253
- const t = await te(
252
+ async function Ae(e) {
253
+ const t = await se(
254
254
  {
255
255
  txGraphVersion: e.vaultCoreVersion,
256
256
  depositor: e.depositor,
@@ -269,48 +269,79 @@ async function me(e) {
269
269
  payoutControlBlock: t.payoutControlBlock
270
270
  };
271
271
  }
272
- const ye = 500, Ee = 55, F = 0xffffffffn, K = 32, Ce = 34;
273
- function be(e) {
274
- if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > F)
272
+ const Ie = 500, _e = 55, B = 0xffffffffn, F = 32, Te = 34;
273
+ function Ve(e) {
274
+ if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > B)
275
275
  throw new Error(
276
- `protocolFeeRate must be in [1, ${F}] sat/vB, got ${e.protocolFeeRate}`
276
+ `protocolFeeRate must be in [1, ${B}] sat/vB, got ${e.protocolFeeRate}`
277
277
  );
278
278
  for (const [t, n] of [
279
279
  ["keepers", e.numVaultKeepers],
280
280
  ["challengers", e.numUniversalChallengers]
281
281
  ])
282
- if (!Number.isInteger(n) || n < 1 || n > K)
282
+ if (!Number.isInteger(n) || n < 1 || n > F)
283
283
  throw new Error(
284
- `Participant count for ${t} (${n}) is outside the device range [1, ${K}].`
284
+ `Participant count for ${t} (${n}) is outside the device range [1, ${F}].`
285
285
  );
286
286
  if (!Number.isInteger(e.councilSize) || e.councilSize < 1)
287
287
  throw new Error(
288
288
  `councilSize must be an integer >= 1, got ${e.councilSize}`
289
289
  );
290
290
  }
291
- async function Ae(e, t) {
292
- const { implicitFeeSats: n, out0Len: i, out1Len: o } = t, r = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, i - Ce), l = ye + Ee * r + u, c = e.protocolFeeRate * BigInt(l);
291
+ async function ke(e, t) {
292
+ const { implicitFeeSats: n, out0Len: r, out1Len: o } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, r - Te), h = Ie + _e * i + u, c = e.protocolFeeRate * BigInt(h);
293
293
  if (s > c)
294
294
  throw new Error(
295
- `Payout implicit fee ${n} sats exceeds the safety cap of ${c} sats (${e.protocolFeeRate} sat/vB x ${l} vB for ${r} participants); refusing to sign payout.`
295
+ `Payout implicit fee ${n} sats exceeds the safety cap of ${c} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${i} participants); refusing to sign payout.`
296
296
  );
297
- const h = await ne(
297
+ const l = await ue(
298
298
  e.vaultCoreVersion,
299
299
  e.numVaultKeepers,
300
300
  e.numUniversalChallengers,
301
301
  e.numVaultKeepers,
302
302
  e.councilSize,
303
- i,
303
+ r,
304
304
  o,
305
305
  e.protocolFeeRate
306
306
  );
307
- if (s < h)
307
+ if (s < l)
308
308
  throw new Error(
309
- `Payout implicit fee ${n} sats is below the floor of ${h} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
309
+ `Payout implicit fee ${n} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
310
310
  );
311
311
  }
312
- const N = 3;
313
- async function ze(e) {
312
+ const He = 22, Le = 34, Oe = 34, Re = 25, Ue = 23;
313
+ function Ke(e) {
314
+ return e.length === He * 2 && e.startsWith("0014");
315
+ }
316
+ function Ne(e) {
317
+ return e.length === Le * 2 && e.startsWith("0020");
318
+ }
319
+ function Be(e) {
320
+ return e.length === Oe * 2 && e.startsWith("5120");
321
+ }
322
+ function Fe(e) {
323
+ return e.length === Re * 2 && e.startsWith("76a914") && e.endsWith("88ac");
324
+ }
325
+ function Me(e) {
326
+ return e.length === Ue * 2 && e.startsWith("a914") && e.endsWith("87");
327
+ }
328
+ function M(e, t) {
329
+ const n = g(e).toLowerCase();
330
+ if (n.length === 0)
331
+ throw new Error(`${t} is empty`);
332
+ if (!/^[0-9a-f]+$/.test(n) || n.length % 2 !== 0)
333
+ throw new Error(`${t} is not valid hex`);
334
+ if (n.startsWith("6a"))
335
+ throw new Error(
336
+ `${t} is an OP_RETURN output, which is provably unspendable`
337
+ );
338
+ if (!Be(n) && !Ke(n) && !Ne(n) && !Fe(n) && !Me(n))
339
+ throw new Error(
340
+ `${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${n.length / 2} bytes: ${n})`
341
+ );
342
+ }
343
+ const q = 3;
344
+ async function ut(e) {
314
345
  const t = {
315
346
  vaultCoreVersion: e.vaultCoreVersion,
316
347
  numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
@@ -318,42 +349,42 @@ async function ze(e) {
318
349
  councilSize: e.councilSize,
319
350
  protocolFeeRate: e.protocolFeeRate
320
351
  };
321
- be(t);
322
- const n = S.fromHex(P(e.payoutTxHex)), i = S.fromHex(P(e.peginTxHex)), o = S.fromHex(P(e.assertTxHex));
323
- if (n.ins.length !== O)
352
+ Ve(t);
353
+ const n = m.fromHex(g(e.payoutTxHex)), r = m.fromHex(g(e.peginTxHex)), o = m.fromHex(g(e.assertTxHex));
354
+ if (n.ins.length !== L)
324
355
  throw new Error(
325
- `Payout transaction must have exactly ${O} inputs, got ${n.ins.length}`
356
+ `Payout transaction must have exactly ${L} inputs, got ${n.ins.length}`
326
357
  );
327
- const r = M(
358
+ const i = W(
328
359
  n.ins[0],
329
360
  0,
330
- i,
361
+ r,
331
362
  "PegIn",
332
- le
333
- ), s = M(
363
+ ge
364
+ ), s = W(
334
365
  n.ins[1],
335
366
  1,
336
367
  o,
337
368
  "Assert",
338
- he
339
- ), { out0Len: u, out1Len: l } = Te(
369
+ fe
370
+ ), { out0Len: u, out1Len: h } = We(
340
371
  n,
341
- r.value,
372
+ i.value,
342
373
  e
343
- ), c = r.value + s.value;
344
- let h = 0;
345
- for (const a of n.outs) h += a.value;
346
- if (h > c)
374
+ ), c = i.value + s.value;
375
+ let l = 0;
376
+ for (const d of n.outs) l += d.value;
377
+ if (l > c)
347
378
  throw new Error(
348
- `Payout outputs (${h} sats) exceed inputs (${c} sats); invalid transaction.`
379
+ `Payout outputs (${l} sats) exceed inputs (${c} sats); invalid transaction.`
349
380
  );
350
- const p = c - h;
351
- await Ae(t, {
352
- implicitFeeSats: p,
381
+ const a = c - l;
382
+ await ke(t, {
383
+ implicitFeeSats: a,
353
384
  out0Len: u,
354
- out1Len: l
385
+ out1Len: h
355
386
  });
356
- const g = await me({
387
+ const f = await Ae({
357
388
  vaultCoreVersion: e.vaultCoreVersion,
358
389
  depositor: e.depositorBtcPubkey,
359
390
  vaultProvider: e.vaultProviderBtcPubkey,
@@ -363,51 +394,51 @@ async function ze(e) {
363
394
  network: e.network
364
395
  });
365
396
  return {
366
- psbtHex: Ie(
397
+ psbtHex: qe(
367
398
  n,
368
- r,
399
+ i,
369
400
  s,
370
- g
401
+ f
371
402
  )
372
403
  };
373
404
  }
374
- function M(e, t, n, i, o) {
375
- const r = _(
405
+ function W(e, t, n, r, o) {
406
+ const i = _(
376
407
  new Uint8Array(e.hash).slice().reverse()
377
408
  ), s = n.getId();
378
- if (r !== s || e.index !== o)
409
+ if (i !== s || e.index !== o)
379
410
  throw new Error(
380
- `Input ${t} must spend ${i}:${o}. Expected ${s}:${o}, got ${r}:${e.index}`
411
+ `Input ${t} must spend ${r}:${o}. Expected ${s}:${o}, got ${i}:${e.index}`
381
412
  );
382
413
  const u = n.outs[e.index];
383
414
  if (!u)
384
415
  throw new Error(
385
- `Previous output not found for input ${t} (txid: ${r}, index: ${e.index})`
416
+ `Previous output not found for input ${t} (txid: ${i}, index: ${e.index})`
386
417
  );
387
418
  return u;
388
419
  }
389
- function Ie(e, t, n, i) {
390
- const o = new A();
420
+ function qe(e, t, n, r) {
421
+ const o = new C();
391
422
  o.setVersion(e.version), o.setLocktime(e.locktime);
392
- const [r, s] = e.ins;
423
+ const [i, s] = e.ins;
393
424
  o.addInput({
394
- hash: r.hash,
395
- index: r.index,
396
- sequence: r.sequence,
425
+ hash: i.hash,
426
+ index: i.index,
427
+ sequence: i.sequence,
397
428
  witnessUtxo: {
398
429
  script: t.script,
399
430
  value: t.value
400
431
  },
401
432
  tapLeafScript: [
402
433
  {
403
- leafVersion: I,
404
- script: d.from(m(i.payoutScript)),
405
- controlBlock: d.from(
406
- m(i.payoutControlBlock)
434
+ leafVersion: A,
435
+ script: p.from(y(r.payoutScript)),
436
+ controlBlock: p.from(
437
+ y(r.payoutControlBlock)
407
438
  )
408
439
  }
409
440
  ],
410
- tapInternalKey: d.from(Y)
441
+ tapInternalKey: p.from(J)
411
442
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
412
443
  }), o.addInput({
413
444
  hash: s.hash,
@@ -425,99 +456,126 @@ function Ie(e, t, n, i) {
425
456
  });
426
457
  return o.toHex();
427
458
  }
428
- function Te(e, t, n) {
459
+ function X(e, t) {
460
+ const n = g(e).toLowerCase(), r = g(
461
+ Pe(t)
462
+ ).toLowerCase();
463
+ return n === r ? [n] : [n, r];
464
+ }
465
+ function z(e, t) {
466
+ return t.some((n) => e.equals(p.from(n, "hex")));
467
+ }
468
+ function We(e, t, n) {
429
469
  const {
430
- claimerBtcPubkey: i,
470
+ claimerBtcPubkey: r,
431
471
  vaultProviderBtcPubkey: o,
432
- depositorBtcPubkey: r,
472
+ depositorBtcPubkey: i,
433
473
  vaultKeeperBtcPubkeys: s,
434
474
  registeredPayoutScriptPubKey: u,
435
- commissionBps: l
475
+ commissionBps: h,
476
+ vkClaimerPayoutScriptPubKeys: c,
477
+ vpCommissionScriptPubKey: l
436
478
  } = n;
437
- if (!ce(u))
479
+ if (!pe(u))
438
480
  throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
439
- const c = P(i).toLowerCase(), h = P(o).toLowerCase(), p = P(r).toLowerCase(), g = s.map(
440
- (C) => P(C).toLowerCase()
481
+ const a = g(r).toLowerCase(), f = g(o).toLowerCase(), d = g(i).toLowerCase(), x = s.map(
482
+ (S) => g(S).toLowerCase()
441
483
  );
442
- let a, v, $;
443
- if (c === h)
444
- a = "vp-claimer", v = pe, $ = P(u);
445
- else if (c === p)
446
- a = "depositor-as-claimer", v = U, $ = P(u);
447
- else if (g.includes(c))
448
- a = "vk-claimer", v = U, $ = P(ae(c));
449
- else
484
+ let v, P, w;
485
+ if (a === f)
486
+ v = "vp-claimer", P = we, w = [g(u)];
487
+ else if (a === d)
488
+ v = "depositor-as-claimer", P = K, w = [g(u)];
489
+ else if (x.includes(a)) {
490
+ v = "vk-claimer", P = K;
491
+ const S = c[a];
492
+ if (S === void 0)
493
+ throw new Error(
494
+ `No registered payout script resolved for vault keeper claimer ${a}`
495
+ );
496
+ M(
497
+ S,
498
+ `Vault keeper payout script for claimer ${a}`
499
+ ), w = X(S, a);
500
+ } else
450
501
  throw new Error(
451
- `Unknown claimer pubkey ${c}: not VP, depositor, or a registered vault keeper`
502
+ `Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
452
503
  );
453
- if (e.outs.length !== v)
504
+ if (e.outs.length !== P)
454
505
  throw new Error(
455
- `Payout transaction has ${e.outs.length} output(s), expected exactly ${v} for role ${a}.`
506
+ `Payout transaction has ${e.outs.length} output(s), expected exactly ${P} for role ${v}.`
456
507
  );
457
- const f = d.from($, "hex");
458
- if (!e.outs[0].script.equals(f))
508
+ if (!z(e.outs[0].script, w))
459
509
  throw new Error(
460
- `Payout transaction output 0 does not pay the expected scriptPubKey for role ${a}`
510
+ `Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${w.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
461
511
  );
462
- const x = v - 1;
463
- if (e.outs[x].value !== R)
512
+ const b = P - 1;
513
+ if (e.outs[b].value !== O)
464
514
  throw new Error(
465
- `Payout CPFP anchor (out ${x}) value ${e.outs[x].value} sats must equal ${R} sats`
515
+ `Payout CPFP anchor (out ${b}) value ${e.outs[b].value} sats must equal ${O} sats`
466
516
  );
467
- if (a === "vp-claimer") {
468
- if (!Number.isInteger(l) || l < 0 || l >= L)
517
+ if (v === "vp-claimer") {
518
+ M(
519
+ l,
520
+ "Vault provider commission payout script"
521
+ );
522
+ const S = X(
523
+ l,
524
+ f
525
+ );
526
+ if (!z(e.outs[1].script, S))
527
+ throw new Error(
528
+ `Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
529
+ );
530
+ if (!Number.isInteger(h) || h < 0 || h >= R)
469
531
  throw new Error(
470
- `commissionBps must be an integer in [0, ${L}), got ${l}`
532
+ `commissionBps must be an integer in [0, ${R}), got ${h}`
471
533
  );
472
- const C = Math.floor(
473
- t * l / de
534
+ const T = Math.floor(
535
+ t * h / ve
474
536
  );
475
- if (e.outs[1].value > C)
537
+ if (e.outs[1].value > T)
476
538
  throw new Error(
477
- `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${C} sats (${l} bps of peginValue=${t})`
539
+ `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${T} sats (${h} bps of peginValue=${t})`
478
540
  );
479
541
  }
480
- const E = f.length;
481
- if (E === 0 || E > b)
482
- throw new Error(
483
- `Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${b}]; refusing to sign payout.`
484
- );
485
- const y = a === "vp-claimer" ? e.outs[1].script.length : void 0;
486
- if (y !== void 0 && (y === 0 || y > b))
542
+ const E = e.outs[0].script.length;
543
+ if (E === 0 || E > U)
487
544
  throw new Error(
488
- `Payout commission scriptPubKey length ${y} is outside the contract's registration cap [1, ${b}]; refusing to sign payout.`
545
+ `Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${U}]; refusing to sign payout.`
489
546
  );
490
- return { out0Len: E, out1Len: y };
547
+ const te = v === "vp-claimer" ? e.outs[1].script.length : void 0;
548
+ return { out0Len: E, out1Len: te };
491
549
  }
492
- function De(e, t, n = 0) {
493
- const i = A.fromHex(e);
494
- if (n >= i.data.inputs.length)
550
+ function ct(e, t, n = 0) {
551
+ const r = C.fromHex(e);
552
+ if (n >= r.data.inputs.length)
495
553
  throw new Error(
496
- `Input index ${n} out of range (${i.data.inputs.length} inputs)`
554
+ `Input index ${n} out of range (${r.data.inputs.length} inputs)`
497
555
  );
498
- const o = i.data.inputs[n];
556
+ const o = r.data.inputs[n];
499
557
  if (o.tapScriptSig && o.tapScriptSig.length > 0) {
500
- const r = m(t);
558
+ const i = y(t);
501
559
  for (const s of o.tapScriptSig)
502
- if (s.pubkey.equals(d.from(r)))
503
- return q(s.signature, n);
560
+ if (s.pubkey.equals(p.from(i)))
561
+ return D(s.signature, n);
504
562
  throw new Error(
505
563
  `No signature found for depositor pubkey: ${t} at input ${n}`
506
564
  );
507
565
  }
508
566
  if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
509
- const r = _e(o.finalScriptWitness);
510
- if (r.length !== N)
567
+ const i = Xe(o.finalScriptWitness);
568
+ if (i.length !== q)
511
569
  throw new Error(
512
- `Unexpected finalized witness stack size at input ${n}: expected ${N} items (signature, script, controlBlock), got ${r.length}`
570
+ `Unexpected finalized witness stack size at input ${n}: expected ${q} items (signature, script, controlBlock), got ${i.length}`
513
571
  );
514
- return q(r[0], n);
572
+ return D(i[0], n);
515
573
  }
516
574
  throw new Error(
517
575
  `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
518
576
  );
519
577
  }
520
- function q(e, t) {
578
+ function D(e, t) {
521
579
  if (e.length === 64)
522
580
  return _(new Uint8Array(e));
523
581
  throw e.length === 65 ? new Error(
@@ -526,199 +584,199 @@ function q(e, t) {
526
584
  `Unexpected signature length at input ${t}: ${e.length}`
527
585
  );
528
586
  }
529
- function _e(e) {
587
+ function Xe(e) {
530
588
  const t = [];
531
589
  let n = 0;
532
- const i = (s) => {
590
+ const r = (s) => {
533
591
  if (n + s > e.length)
534
592
  throw new Error(
535
593
  `Malformed witness data: need ${s} byte(s) at offset ${n}, only ${e.length - n} remaining`
536
594
  );
537
595
  }, o = () => {
538
- i(1);
596
+ r(1);
539
597
  const s = e[n++];
540
598
  if (s < 253) return s;
541
599
  if (s === 253) {
542
- i(2);
600
+ r(2);
543
601
  const u = (e[n] | e[n + 1] << 8) >>> 0;
544
602
  return n += 2, u;
545
603
  }
546
604
  if (s === 254) {
547
- i(4);
605
+ r(4);
548
606
  const u = (e[n] | e[n + 1] << 8 | e[n + 2] << 16 | e[n + 3] << 24) >>> 0;
549
607
  return n += 4, u;
550
608
  }
551
609
  throw new Error(
552
610
  `Malformed witness data: 8-byte varint (0xff) not supported at offset ${n - 1}`
553
611
  );
554
- }, r = o();
555
- for (let s = 0; s < r; s++) {
612
+ }, i = o();
613
+ for (let s = 0; s < i; s++) {
556
614
  const u = o();
557
- i(u), t.push(d.from(e.subarray(n, n + u))), n += u;
615
+ r(u), t.push(p.from(e.subarray(n, n + u))), n += u;
558
616
  }
559
617
  if (n !== e.length)
560
618
  throw new Error(
561
- `Malformed witness data: ${e.length - n} trailing byte(s) after parsing ${r} item(s)`
619
+ `Malformed witness data: ${e.length - n} trailing byte(s) after parsing ${i} item(s)`
562
620
  );
563
621
  return t;
564
622
  }
565
- class w extends Error {
623
+ class $ extends Error {
566
624
  constructor(t) {
567
625
  super(
568
626
  `Wallet returned a PSBT for a different transaction: ${t}`
569
627
  ), this.name = "PsbtSubstitutionError";
570
628
  }
571
629
  }
572
- function W(e, t) {
630
+ function G(e, t) {
573
631
  try {
574
- return A.fromHex(t);
632
+ return C.fromHex(t);
575
633
  } catch (n) {
576
- const i = n instanceof Error ? n.message : String(n);
577
- throw new Error(`Failed to parse ${e} PSBT: ${i}`);
634
+ const r = n instanceof Error ? n.message : String(n);
635
+ throw new Error(`Failed to parse ${e} PSBT: ${r}`);
578
636
  }
579
637
  }
580
- const Ve = 8;
581
- function T(e) {
582
- return `${e.toString("hex").slice(0, Ve)}…`;
638
+ const ze = 8;
639
+ function I(e) {
640
+ return `${e.toString("hex").slice(0, ze)}…`;
583
641
  }
584
- function X(e) {
585
- const t = d.from(e).reverse();
586
- return T(t);
642
+ function Y(e) {
643
+ const t = p.from(e).reverse();
644
+ return I(t);
587
645
  }
588
- function Ge(e) {
589
- const t = W("requested", e.requestedPsbtHex), n = W("returned", e.returnedPsbtHex);
646
+ function at(e) {
647
+ const t = G("requested", e.requestedPsbtHex), n = G("returned", e.returnedPsbtHex);
590
648
  if (t.version !== n.version)
591
- throw new w(
649
+ throw new $(
592
650
  `tx version differs (requested=${t.version}, returned=${n.version})`
593
651
  );
594
652
  if (t.locktime !== n.locktime)
595
- throw new w(
653
+ throw new $(
596
654
  `tx locktime differs (requested=${t.locktime}, returned=${n.locktime})`
597
655
  );
598
656
  if (t.txInputs.length !== n.txInputs.length)
599
- throw new w(
657
+ throw new $(
600
658
  `input count differs (requested=${t.txInputs.length}, returned=${n.txInputs.length})`
601
659
  );
602
660
  if (t.txOutputs.length !== n.txOutputs.length)
603
- throw new w(
661
+ throw new $(
604
662
  `output count differs (requested=${t.txOutputs.length}, returned=${n.txOutputs.length})`
605
663
  );
606
- for (let i = 0; i < t.txInputs.length; i++) {
607
- const o = t.txInputs[i], r = n.txInputs[i];
608
- if (!o.hash.equals(r.hash))
609
- throw new w(
610
- `input ${i} prevout txid differs (requested=${X(o.hash)}, returned=${X(r.hash)})`
664
+ for (let r = 0; r < t.txInputs.length; r++) {
665
+ const o = t.txInputs[r], i = n.txInputs[r];
666
+ if (!o.hash.equals(i.hash))
667
+ throw new $(
668
+ `input ${r} prevout txid differs (requested=${Y(o.hash)}, returned=${Y(i.hash)})`
611
669
  );
612
- if (o.index !== r.index)
613
- throw new w(
614
- `input ${i} prevout vout differs (requested=${o.index}, returned=${r.index})`
670
+ if (o.index !== i.index)
671
+ throw new $(
672
+ `input ${r} prevout vout differs (requested=${o.index}, returned=${i.index})`
615
673
  );
616
- if (o.sequence !== r.sequence)
617
- throw new w(
618
- `input ${i} sequence differs (requested=${o.sequence}, returned=${r.sequence})`
674
+ if (o.sequence !== i.sequence)
675
+ throw new $(
676
+ `input ${r} sequence differs (requested=${o.sequence}, returned=${i.sequence})`
619
677
  );
620
678
  }
621
- for (let i = 0; i < t.txOutputs.length; i++) {
622
- const o = t.txOutputs[i], r = n.txOutputs[i];
623
- if (!o.script.equals(r.script))
624
- throw new w(
625
- `output ${i} scriptPubKey differs (requested=${T(o.script)}, returned=${T(r.script)})`
679
+ for (let r = 0; r < t.txOutputs.length; r++) {
680
+ const o = t.txOutputs[r], i = n.txOutputs[r];
681
+ if (!o.script.equals(i.script))
682
+ throw new $(
683
+ `output ${r} scriptPubKey differs (requested=${I(o.script)}, returned=${I(i.script)})`
626
684
  );
627
- if (o.value !== r.value)
628
- throw new w(
629
- `output ${i} value differs (requested=${o.value}, returned=${r.value})`
685
+ if (o.value !== i.value)
686
+ throw new $(
687
+ `output ${r} value differs (requested=${o.value}, returned=${i.value})`
630
688
  );
631
689
  }
632
690
  }
633
- const z = 253, ke = 254, He = 65535, Oe = 4294967295;
634
- function Re(e) {
635
- if (e < z)
636
- return d.from([e]);
637
- if (e <= He) {
638
- const t = d.alloc(2);
639
- return t.writeUInt16LE(e), d.concat([d.from([z]), t]);
691
+ const Q = 253, De = 254, Ge = 65535, Ye = 4294967295;
692
+ function Qe(e) {
693
+ if (e < Q)
694
+ return p.from([e]);
695
+ if (e <= Ge) {
696
+ const t = p.alloc(2);
697
+ return t.writeUInt16LE(e), p.concat([p.from([Q]), t]);
640
698
  }
641
- if (e <= Oe) {
642
- const t = d.alloc(4);
643
- return t.writeUInt32LE(e), d.concat([d.from([ke]), t]);
699
+ if (e <= Ye) {
700
+ const t = p.alloc(4);
701
+ return t.writeUInt32LE(e), p.concat([p.from([De]), t]);
644
702
  }
645
703
  throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
646
704
  }
647
- const Le = "TapLeaf";
648
- function Ue(e, t) {
649
- const n = d.concat([
650
- d.from([e]),
651
- Re(t.length),
652
- d.from(t)
705
+ const Ze = "TapLeaf";
706
+ function je(e, t) {
707
+ const n = p.concat([
708
+ p.from([e]),
709
+ Qe(t.length),
710
+ p.from(t)
653
711
  ]);
654
- return se.taggedHash(Le, n);
712
+ return he.taggedHash(Ze, n);
655
713
  }
656
- function Ye(e) {
657
- const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: i, inputIndex: o } = e, r = P(n);
658
- if (r.length !== k)
714
+ function lt(e) {
715
+ const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: r, inputIndex: o } = e, i = g(n);
716
+ if (i.length !== k)
659
717
  throw new Error(
660
- `Schnorr signature for input ${o} must be ${k} hex chars (64 bytes), got ${r.length}.`
718
+ `Schnorr signature for input ${o} must be ${k} hex chars (64 bytes), got ${i.length}.`
661
719
  );
662
- const s = P(i);
720
+ const s = g(r);
663
721
  if (s.length !== H)
664
722
  throw new Error(
665
723
  `Signer x-only pubkey for input ${o} must be ${H} hex chars (32 bytes), got ${s.length}.`
666
724
  );
667
- const u = A.fromHex(t);
725
+ const u = C.fromHex(t);
668
726
  if (o < 0 || o >= u.data.inputs.length)
669
727
  throw new Error(
670
728
  `Input index ${o} out of range (${u.data.inputs.length} inputs).`
671
729
  );
672
- const l = [], c = [];
673
- for (let f = 0; f < u.data.inputs.length; f++) {
674
- const x = u.data.inputs[f].witnessUtxo;
675
- if (!x)
730
+ const h = [], c = [];
731
+ for (let P = 0; P < u.data.inputs.length; P++) {
732
+ const w = u.data.inputs[P].witnessUtxo;
733
+ if (!w)
676
734
  throw new Error(
677
- `Cannot verify signature: input ${f} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
735
+ `Cannot verify signature: input ${P} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
678
736
  );
679
- l.push(x.script), c.push(x.value);
737
+ h.push(w.script), c.push(w.value);
680
738
  }
681
- const h = u.data.inputs[o].tapLeafScript;
682
- if (!h || h.length !== 1)
739
+ const l = u.data.inputs[o].tapLeafScript;
740
+ if (!l || l.length !== 1)
683
741
  throw new Error(
684
- `Cannot verify signature: input ${o} of the requested PSBT must have exactly one tapLeafScript, got ${(h == null ? void 0 : h.length) ?? 0}.`
742
+ `Cannot verify signature: input ${o} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
685
743
  );
686
- const p = h[0];
687
- if (p.leafVersion !== I)
744
+ const a = l[0];
745
+ if (a.leafVersion !== A)
688
746
  throw new Error(
689
- `Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${p.leafVersion.toString(16)}, expected 0x${I.toString(16)}.`
747
+ `Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${A.toString(16)}.`
690
748
  );
691
- const g = Ue(p.leafVersion, p.script), a = new S();
692
- a.version = u.version, a.locktime = u.locktime;
693
- for (const f of u.txInputs)
694
- a.addInput(f.hash, f.index, f.sequence);
695
- for (const f of u.txOutputs)
696
- a.addOutput(f.script, f.value);
697
- const v = a.hashForWitnessV1(
749
+ const f = je(a.leafVersion, a.script), d = new m();
750
+ d.version = u.version, d.locktime = u.locktime;
751
+ for (const P of u.txInputs)
752
+ d.addInput(P.hash, P.index, P.sequence);
753
+ for (const P of u.txOutputs)
754
+ d.addOutput(P.script, P.value);
755
+ const x = d.hashForWitnessV1(
698
756
  o,
699
- l,
757
+ h,
700
758
  c,
701
- S.SIGHASH_DEFAULT,
702
- g
759
+ m.SIGHASH_DEFAULT,
760
+ f
703
761
  );
704
- if (!Pe.verifySchnorr(
705
- v,
706
- m(s),
707
- m(r)
762
+ if (!$e.verifySchnorr(
763
+ x,
764
+ y(s),
765
+ y(i)
708
766
  ))
709
767
  throw new Error(
710
768
  `Schnorr signature for input ${o} (signer ${s}) does not verify against the expected Taproot script-path sighash. The wallet may have signed with the tweaked key, signed a different transaction, or returned an invalid signature.`
711
769
  );
712
770
  }
713
771
  export {
714
- w as P,
715
- We as a,
716
- Xe as b,
717
- ze as c,
718
- Ge as d,
719
- De as e,
720
- Ye as f,
721
- me as g,
722
- Q as n
772
+ $ as P,
773
+ it as a,
774
+ st as b,
775
+ ut as c,
776
+ at as d,
777
+ ct as e,
778
+ lt as f,
779
+ Ae as g,
780
+ ee as n
723
781
  };
724
- //# sourceMappingURL=verifyScriptPathSchnorrSignature-CgrnAjMW.js.map
782
+ //# sourceMappingURL=verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map