@babylonlabs-io/ts-sdk 0.79.1 → 1.1.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 (187) hide show
  1. package/README.md +11 -5
  2. package/dist/{signPsbtsWithFallback-f7QLp0q8.js → PayoutManager-CHTOwj0E.js} +26 -26
  3. package/dist/PayoutManager-CHTOwj0E.js.map +1 -0
  4. package/dist/PayoutManager-CpfQjtL0.cjs +2 -0
  5. package/dist/PayoutManager-CpfQjtL0.cjs.map +1 -0
  6. package/dist/PeginManager-6tjlGd0t.cjs +2 -0
  7. package/dist/PeginManager-6tjlGd0t.cjs.map +1 -0
  8. package/dist/{PeginManager-BXlh3ar0.js → PeginManager-DEldv_Ro.js} +23 -22
  9. package/dist/PeginManager-DEldv_Ro.js.map +1 -0
  10. package/dist/buildAndBroadcastReclaim-BwT6Jxp5.cjs +2 -0
  11. package/dist/buildAndBroadcastReclaim-BwT6Jxp5.cjs.map +1 -0
  12. package/dist/buildAndBroadcastReclaim-CqO2DoP8.js +1919 -0
  13. package/dist/buildAndBroadcastReclaim-CqO2DoP8.js.map +1 -0
  14. package/dist/challengeAssert-Cp_GeRg8.js.map +1 -1
  15. package/dist/challengeAssert-Z7_YULBb.cjs.map +1 -1
  16. package/dist/deriveVaultRoot-BwbXmN0x.js +79 -0
  17. package/dist/deriveVaultRoot-BwbXmN0x.js.map +1 -0
  18. package/dist/deriveVaultRoot-DvhkHzNb.cjs +2 -0
  19. package/dist/deriveVaultRoot-DvhkHzNb.cjs.map +1 -0
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.js +286 -268
  22. package/dist/index.js.map +1 -1
  23. package/dist/noPayout-DAWBQ0eG.cjs +2 -0
  24. package/dist/noPayout-DAWBQ0eG.cjs.map +1 -0
  25. package/dist/{noPayout-DiGr4eas.js → noPayout-qBXWKwav.js} +3 -3
  26. package/dist/noPayout-qBXWKwav.js.map +1 -0
  27. package/dist/onChainBtcPubkey-BXry_CM4.cjs +2 -0
  28. package/dist/onChainBtcPubkey-BXry_CM4.cjs.map +1 -0
  29. package/dist/onChainBtcPubkey-C1WqyxPM.js +159 -0
  30. package/dist/onChainBtcPubkey-C1WqyxPM.js.map +1 -0
  31. package/dist/parseFundingOutpoints-C_-PT9BT.cjs +2 -0
  32. package/dist/parseFundingOutpoints-C_-PT9BT.cjs.map +1 -0
  33. package/dist/parseFundingOutpoints-GSM-IaaK.js +17 -0
  34. package/dist/parseFundingOutpoints-GSM-IaaK.js.map +1 -0
  35. package/dist/{pegin-registration-client-pcczkzMg.js → pegin-registration-client-1sZ-74UC.js} +260 -383
  36. package/dist/pegin-registration-client-1sZ-74UC.js.map +1 -0
  37. package/dist/pegin-registration-client-BNV44jzw.cjs +2 -0
  38. package/dist/pegin-registration-client-BNV44jzw.cjs.map +1 -0
  39. package/dist/shared/index.cjs.map +1 -1
  40. package/dist/shared/index.js.map +1 -1
  41. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +6 -3
  42. package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
  43. package/dist/signing-3l5Aqd-H.cjs +2 -0
  44. package/dist/signing-3l5Aqd-H.cjs.map +1 -0
  45. package/dist/signing-Dhr2t0Z6.js +39 -0
  46. package/dist/signing-Dhr2t0Z6.js.map +1 -0
  47. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  48. package/dist/tbv/core/clients/eth/index.js +8 -8
  49. package/dist/tbv/core/clients/index.cjs +1 -1
  50. package/dist/tbv/core/clients/index.js +8 -8
  51. package/dist/tbv/core/index.cjs +1 -1
  52. package/dist/tbv/core/index.d.ts +1 -1
  53. package/dist/tbv/core/index.js +284 -266
  54. package/dist/tbv/core/index.js.map +1 -1
  55. package/dist/tbv/core/managers/PayoutManager.d.ts +1 -1
  56. package/dist/tbv/core/managers/PeginManager.d.ts +1 -1
  57. package/dist/tbv/core/managers/index.cjs +1 -1
  58. package/dist/tbv/core/managers/index.js +2 -2
  59. package/dist/tbv/core/primitives/index.cjs +1 -1
  60. package/dist/tbv/core/primitives/index.d.ts +1 -1
  61. package/dist/tbv/core/primitives/index.js +3 -3
  62. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -3
  63. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
  64. package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts +8 -0
  65. package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts.map +1 -0
  66. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +6 -0
  67. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  68. package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +2 -2
  69. package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
  70. package/dist/tbv/core/primitives/psbt/noPayout.d.ts +1 -1
  71. package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
  72. package/dist/tbv/core/primitives/psbt/payout.d.ts +13 -7
  73. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  74. package/dist/tbv/core/primitives/psbt/pegin.d.ts +4 -1
  75. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  76. package/dist/tbv/core/recovery/recoveryErrors.d.ts +1 -1
  77. package/dist/tbv/core/services/delegated-claim/__tests__/assembleWatchtowerArtifacts.test.d.ts +15 -0
  78. package/dist/tbv/core/services/delegated-claim/__tests__/assembleWatchtowerArtifacts.test.d.ts.map +1 -0
  79. package/dist/tbv/core/services/delegated-claim/__tests__/deriveClaimerWotsKeypair.test.d.ts +11 -0
  80. package/dist/tbv/core/services/delegated-claim/__tests__/deriveClaimerWotsKeypair.test.d.ts.map +1 -0
  81. package/dist/tbv/core/services/delegated-claim/__tests__/readWatchtowerArtifacts.test.d.ts +10 -0
  82. package/dist/tbv/core/services/delegated-claim/__tests__/readWatchtowerArtifacts.test.d.ts.map +1 -0
  83. package/dist/tbv/core/services/delegated-claim/__tests__/vaultIdBinding.test.d.ts +10 -0
  84. package/dist/tbv/core/services/delegated-claim/__tests__/vaultIdBinding.test.d.ts.map +1 -0
  85. package/dist/tbv/core/services/delegated-claim/__tests__/wotsKeypair.golden.test.d.ts +11 -0
  86. package/dist/tbv/core/services/delegated-claim/__tests__/wotsKeypair.golden.test.d.ts.map +1 -0
  87. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +46 -0
  88. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -0
  89. package/dist/tbv/core/services/delegated-claim/challengerBinding.d.ts +72 -0
  90. package/dist/tbv/core/services/delegated-claim/challengerBinding.d.ts.map +1 -0
  91. package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts +63 -0
  92. package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts.map +1 -0
  93. package/dist/tbv/core/services/delegated-claim/index.d.ts +55 -0
  94. package/dist/tbv/core/services/delegated-claim/index.d.ts.map +1 -0
  95. package/dist/tbv/core/services/delegated-claim/payoutBinding.d.ts +65 -0
  96. package/dist/tbv/core/services/delegated-claim/payoutBinding.d.ts.map +1 -0
  97. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +70 -0
  98. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -0
  99. package/dist/tbv/core/services/delegated-claim/types.d.ts +105 -0
  100. package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -0
  101. package/dist/tbv/core/services/delegated-claim/vaultIdBinding.d.ts +44 -0
  102. package/dist/tbv/core/services/delegated-claim/vaultIdBinding.d.ts.map +1 -0
  103. package/dist/tbv/core/services/index.cjs +1 -1
  104. package/dist/tbv/core/services/index.d.ts +1 -0
  105. package/dist/tbv/core/services/index.d.ts.map +1 -1
  106. package/dist/tbv/core/services/index.js +73 -56
  107. package/dist/tbv/core/services/index.js.map +1 -1
  108. package/dist/tbv/core/utils/index.cjs +1 -1
  109. package/dist/tbv/core/utils/index.js +44 -43
  110. package/dist/tbv/core/utils/signing.d.ts +24 -0
  111. package/dist/tbv/core/utils/signing.d.ts.map +1 -1
  112. package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts +4 -4
  113. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts +1 -2
  114. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts.map +1 -1
  115. package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts +40 -0
  116. package/dist/tbv/core/vault-secrets/__tests__/deriveContextHash.vectors.test.d.ts.map +1 -0
  117. package/dist/tbv/core/vault-secrets/context.d.ts +2 -2
  118. package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts +5 -6
  119. package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts.map +1 -1
  120. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  121. package/dist/tbv/core/vault-secrets/index.d.ts +2 -2
  122. package/dist/tbv/core/vault-secrets/index.js +9 -8
  123. package/dist/tbv/core/vault-secrets/index.js.map +1 -1
  124. package/dist/tbv/core/wasm/index.cjs +1 -1
  125. package/dist/tbv/core/wasm/index.cjs.map +1 -1
  126. package/dist/tbv/core/wasm/index.d.ts +113 -14
  127. package/dist/tbv/core/wasm/index.d.ts.map +1 -1
  128. package/dist/tbv/core/wasm/index.js +180 -94
  129. package/dist/tbv/core/wasm/index.js.map +1 -1
  130. package/dist/tbv/index.cjs +1 -1
  131. package/dist/tbv/index.js +284 -266
  132. package/dist/tbv/index.js.map +1 -1
  133. package/dist/tbv/integrations/aave/types.d.ts +1 -1
  134. package/dist/testing/MockBitcoinWallet.d.ts +1 -1
  135. package/dist/testing/index.cjs.map +1 -1
  136. package/dist/testing/index.js.map +1 -1
  137. package/dist/toRefundInputs-BaN9XluU.cjs +2 -0
  138. package/dist/toRefundInputs-BaN9XluU.cjs.map +1 -0
  139. package/dist/{toRefundInputs-9inv4Ai4.js → toRefundInputs-mtuuYezp.js} +24 -23
  140. package/dist/toRefundInputs-mtuuYezp.js.map +1 -0
  141. package/dist/{types-B9YhlXe8.js → types-BdCEoANP.js} +2 -2
  142. package/dist/{types-B9YhlXe8.js.map → types-BdCEoANP.js.map} +1 -1
  143. package/dist/{types-C1tpDycc.cjs → types-BuxreSq4.cjs} +2 -2
  144. package/dist/{types-C1tpDycc.cjs.map → types-BuxreSq4.cjs.map} +1 -1
  145. package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js → verifyKeyPathSchnorrSignature-BQHNhRj6.js} +2 -2
  146. package/dist/{verifyKeyPathSchnorrSignature-BVtNwgK6.js.map → verifyKeyPathSchnorrSignature-BQHNhRj6.js.map} +1 -1
  147. package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs} +2 -2
  148. package/dist/{verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map → verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs.map} +1 -1
  149. package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs +2 -0
  150. package/dist/verifyScriptPathSchnorrSignature-BKZihCjk.cjs.map +1 -0
  151. package/dist/{verifyScriptPathSchnorrSignature-D_epga4j.js → verifyScriptPathSchnorrSignature-CpjSTfMj.js} +371 -330
  152. package/dist/verifyScriptPathSchnorrSignature-CpjSTfMj.js.map +1 -0
  153. package/package.json +3 -3
  154. package/dist/PeginManager-BXlh3ar0.js.map +0 -1
  155. package/dist/PeginManager-BuVSknB0.cjs +0 -2
  156. package/dist/PeginManager-BuVSknB0.cjs.map +0 -1
  157. package/dist/buildAndBroadcastReclaim-N9dXH9dm.cjs +0 -2
  158. package/dist/buildAndBroadcastReclaim-N9dXH9dm.cjs.map +0 -1
  159. package/dist/buildAndBroadcastReclaim-O6z9kvc4.js +0 -1545
  160. package/dist/buildAndBroadcastReclaim-O6z9kvc4.js.map +0 -1
  161. package/dist/noPayout-4RZB2g1e.cjs +0 -2
  162. package/dist/noPayout-4RZB2g1e.cjs.map +0 -1
  163. package/dist/noPayout-DiGr4eas.js.map +0 -1
  164. package/dist/onChainBtcPubkey-BbxRrbvg.cjs +0 -2
  165. package/dist/onChainBtcPubkey-BbxRrbvg.cjs.map +0 -1
  166. package/dist/onChainBtcPubkey-C-6UWpD8.js +0 -34
  167. package/dist/onChainBtcPubkey-C-6UWpD8.js.map +0 -1
  168. package/dist/parseFundingOutpoints-B4iQeX6q.cjs +0 -2
  169. package/dist/parseFundingOutpoints-B4iQeX6q.cjs.map +0 -1
  170. package/dist/parseFundingOutpoints-BQWvINfm.js +0 -93
  171. package/dist/parseFundingOutpoints-BQWvINfm.js.map +0 -1
  172. package/dist/pegin-registration-client-CZgcU2_0.cjs +0 -2
  173. package/dist/pegin-registration-client-CZgcU2_0.cjs.map +0 -1
  174. package/dist/pegin-registration-client-pcczkzMg.js.map +0 -1
  175. package/dist/signPsbtsWithFallback-DtwzL5AA.cjs +0 -2
  176. package/dist/signPsbtsWithFallback-DtwzL5AA.cjs.map +0 -1
  177. package/dist/signPsbtsWithFallback-f7QLp0q8.js.map +0 -1
  178. package/dist/signing-BJ3X66b-.cjs +0 -2
  179. package/dist/signing-BJ3X66b-.cjs.map +0 -1
  180. package/dist/signing-Cm-McVR2.js +0 -22
  181. package/dist/signing-Cm-McVR2.js.map +0 -1
  182. package/dist/toRefundInputs-9inv4Ai4.js.map +0 -1
  183. package/dist/toRefundInputs-DitGWAnz.cjs +0 -2
  184. package/dist/toRefundInputs-DitGWAnz.cjs.map +0 -1
  185. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +0 -1
  186. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +0 -2
  187. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +0 -1
@@ -1,24 +1,24 @@
1
- import { script as _, opcodes as E, payments as R, Transaction as b, crypto as H, Psbt as V } from "bitcoinjs-lib";
2
- import { computeMinClaimValue as Ee, peginP2aAnchorOutput as ye, computeMinPeginFee as _e, tapInternalPubkey as k, buildPeginTxFromPrePegin as ke, createPrePeginTransaction as Ie, validatePeginP2aAnchor as Ae, createPayoutConnector as Te, computePayoutFeeFloor as Oe, getAssertPayoutScriptInfo as Ve } from "./tbv/core/wasm/index.js";
3
- import { c as M, p as Le, d as Re } from "./fundPeginTransaction-CwhRbCQC.js";
4
- import { p as He, s as f, d as $e, m as Ke, T as y, h as x, u as U, j as Ne, S as F } from "./bitcoin-C-TuHb-v.js";
5
- import { s as Ue } from "./secp256k1-D-H9jmd7.js";
1
+ import { script as x, opcodes as E, payments as L, Transaction as k, crypto as U, Psbt as H } from "bitcoinjs-lib";
2
+ import { computeMinClaimValue as ye, peginP2aAnchorOutput as me, computeMinPeginFee as Ie, tapInternalPubkey as _, buildPeginTxFromPrePegin as Ae, createPrePeginTransaction as Te, validatePeginP2aAnchor as Oe, createPayoutConnector as Ve, computePayoutFeeFloor as Le, getAssertPayoutScriptInfo as Re } from "./tbv/core/wasm/index.js";
3
+ import { c as q, p as Ke, d as He } from "./fundPeginTransaction-CwhRbCQC.js";
4
+ import { p as Ne, s as f, d as $e, m as Se, T as y, h as C, u as M, j as Ue, S as W } from "./bitcoin-C-TuHb-v.js";
5
+ import { s as Be } from "./secp256k1-D-H9jmd7.js";
6
6
  import { Buffer as c } from "buffer";
7
- import { P as q, c as W, d as X, e as G, f as Be, g as z, h as Me, i as Fe, j as Y, k as D, l as Q, m as Z, n as j, o as J, M as ee, b as te, p as qe, A as me, B as We, V as Xe, N as oe } from "./constants-D5vORbQE.js";
8
- import * as Se from "@bitcoin-js/tiny-secp256k1-asmjs";
9
- import { X as ne } from "./validation-OSC0xTHB.js";
10
- function C(e) {
11
- return He(e).toLowerCase();
7
+ import { P as X, c as G, d as z, e as Y, f as Me, g as D, h as Fe, i as qe, j as Q, k as Z, l as j, m as J, n as ee, o as te, M as oe, b as ne, p as We, A as xe, B as Xe, V as Ge, N as re } from "./constants-D5vORbQE.js";
8
+ import * as Ce from "@bitcoin-js/tiny-secp256k1-asmjs";
9
+ import { X as ie } from "./validation-OSC0xTHB.js";
10
+ function b(e) {
11
+ return Ne(e).toLowerCase();
12
12
  }
13
- function Yt(e, t, o) {
13
+ function Qt(e, t, o) {
14
14
  const n = /* @__PURE__ */ new Set();
15
- n.add(C(e));
15
+ n.add(b(e));
16
16
  for (const i of t)
17
- n.add(C(i));
18
- return n.delete(C(o)), n.size;
17
+ n.add(b(i));
18
+ return n.delete(b(o)), n.size;
19
19
  }
20
- function Ge(e) {
21
- const t = C(e.claimerBtcPubkey), o = C(e.depositorBtcPubkey), n = e.vaultKeeperBtcPubkeys.map(C);
20
+ function ze(e) {
21
+ const t = b(e.claimerBtcPubkey), o = b(e.depositorBtcPubkey), n = e.vaultKeeperBtcPubkeys.map(b);
22
22
  if (t === o) {
23
23
  const r = n.filter((u) => u !== o);
24
24
  if (r.length === 0)
@@ -32,7 +32,7 @@ function Ge(e) {
32
32
  return r;
33
33
  }
34
34
  const s = [
35
- .../* @__PURE__ */ new Set([C(e.vaultProviderBtcPubkey), ...n])
35
+ .../* @__PURE__ */ new Set([b(e.vaultProviderBtcPubkey), ...n])
36
36
  ].sort().filter((r) => r !== t);
37
37
  if (s.length === 0)
38
38
  throw new Error(
@@ -40,15 +40,15 @@ function Ge(e) {
40
40
  );
41
41
  return s;
42
42
  }
43
- const ze = 32, Ye = 65535, De = 2;
44
- function K(e, t) {
43
+ const Ye = 32, De = 65535, Qe = 2;
44
+ function I(e, t) {
45
45
  const o = f(e).toLowerCase();
46
46
  if (!/^[0-9a-f]{64}$/.test(o))
47
47
  throw new Error(`${t} must be a 32-byte x-only public key.`);
48
48
  try {
49
- Ue.Point.fromBytes(
49
+ Be.Point.fromBytes(
50
50
  c.concat([
51
- c.from([De]),
51
+ c.from([Qe]),
52
52
  c.from(o, "hex")
53
53
  ])
54
54
  );
@@ -57,15 +57,15 @@ function K(e, t) {
57
57
  }
58
58
  return o;
59
59
  }
60
- function re(e, t) {
60
+ function R(e, t) {
61
61
  if (e.length === 0)
62
62
  throw new Error(`${t} must not be empty.`);
63
- const o = e.map((n, i) => K(n, `${t}[${i}]`)).sort();
63
+ const o = e.map((n, i) => I(n, `${t}[${i}]`)).sort();
64
64
  if (new Set(o).size !== o.length)
65
65
  throw new Error(`${t} must not contain duplicate keys.`);
66
66
  return o;
67
67
  }
68
- function ie(e, t) {
68
+ function K(e, t) {
69
69
  const o = [];
70
70
  return e.forEach((n, i) => {
71
71
  o.push(
@@ -73,33 +73,33 @@ function ie(e, t) {
73
73
  i === 0 ? E.OP_CHECKSIG : E.OP_CHECKSIGADD
74
74
  );
75
75
  }), o.push(
76
- _.number.encode(e.length),
76
+ x.number.encode(e.length),
77
77
  t ? E.OP_NUMEQUALVERIFY : E.OP_NUMEQUAL
78
78
  ), o;
79
79
  }
80
- function Qe(e, t) {
80
+ function Ze(e, t) {
81
81
  var g;
82
- Ke();
83
- const o = K(
82
+ Se();
83
+ const o = I(
84
84
  e.depositorPubkey,
85
85
  "depositorPubkey"
86
- ), n = K(
86
+ ), n = I(
87
87
  e.vaultProviderPubkey,
88
88
  "vaultProviderPubkey"
89
- ), i = re(
89
+ ), i = R(
90
90
  e.vaultKeeperPubkeys,
91
91
  "vaultKeeperPubkeys"
92
- ), s = re(
92
+ ), s = R(
93
93
  e.universalChallengerPubkeys,
94
94
  "universalChallengerPubkeys"
95
95
  ), r = f(t).toLowerCase();
96
96
  if (!/^[0-9a-f]{64}$/.test(r))
97
97
  throw new Error("hashlock must be 32 bytes.");
98
- if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > Ye)
98
+ if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > De)
99
99
  throw new Error("timelockRefund must be an integer from 1 to 65535.");
100
- const u = _.compile([
100
+ const u = x.compile([
101
101
  E.OP_SIZE,
102
- _.number.encode(ze),
102
+ x.number.encode(Ye),
103
103
  E.OP_EQUALVERIFY,
104
104
  E.OP_SHA256,
105
105
  c.from(r, "hex"),
@@ -108,43 +108,74 @@ function Qe(e, t) {
108
108
  E.OP_CHECKSIGVERIFY,
109
109
  c.from(n, "hex"),
110
110
  E.OP_CHECKSIGVERIFY,
111
- ...ie(i, !0),
112
- ...ie(s, !1)
113
- ]), h = _.compile([
111
+ ...K(i, !0),
112
+ ...K(s, !1)
113
+ ]), h = x.compile([
114
114
  c.from(o, "hex"),
115
115
  E.OP_CHECKSIGVERIFY,
116
- _.number.encode(e.timelockRefund),
116
+ x.number.encode(e.timelockRefund),
117
117
  E.OP_CHECKSEQUENCEVERIFY
118
- ]), a = [
118
+ ]), l = [
119
119
  { output: u, version: y },
120
120
  { output: h, version: y }
121
- ], { hash: d, output: l, witness: P } = R.p2tr({
122
- internalPubkey: c.from(k),
123
- scriptTree: a,
121
+ ], { hash: d, output: a, witness: P } = L.p2tr({
122
+ internalPubkey: c.from(_),
123
+ scriptTree: l,
124
124
  redeem: {
125
125
  output: u,
126
126
  redeemVersion: y
127
127
  }
128
- }), p = P == null ? void 0 : P[P.length - 1], v = R.p2tr({
129
- internalPubkey: c.from(k),
130
- scriptTree: a,
128
+ }), p = P == null ? void 0 : P[P.length - 1], v = L.p2tr({
129
+ internalPubkey: c.from(_),
130
+ scriptTree: l,
131
131
  redeem: {
132
132
  output: h,
133
133
  redeemVersion: y
134
134
  }
135
135
  }), w = (g = v.witness) == null ? void 0 : g[v.witness.length - 1];
136
- if (!d || !l || !p || !w)
136
+ if (!d || !a || !p || !w)
137
137
  throw new Error("Failed to derive the expected Pre-PegIn HTLC output.");
138
138
  return {
139
139
  hashlockScript: u,
140
140
  hashlockControlBlock: p,
141
141
  refundScript: h,
142
142
  refundControlBlock: w,
143
- scriptPubKey: l,
143
+ scriptPubKey: a,
144
144
  tapMerkleRoot: d
145
145
  };
146
146
  }
147
- async function Ze(e, t) {
147
+ function je(e, t) {
148
+ Se();
149
+ const o = I(
150
+ e.depositorPubkey,
151
+ "depositorPubkey"
152
+ ), n = I(
153
+ e.vaultProviderPubkey,
154
+ "vaultProviderPubkey"
155
+ ), i = R(
156
+ e.vaultKeeperPubkeys,
157
+ "vaultKeeperPubkeys"
158
+ ), s = R(
159
+ e.universalChallengerPubkeys,
160
+ "universalChallengerPubkeys"
161
+ ), r = x.compile([
162
+ c.from(o, "hex"),
163
+ E.OP_CHECKSIGVERIFY,
164
+ c.from(n, "hex"),
165
+ E.OP_CHECKSIGVERIFY,
166
+ ...K(i, !0),
167
+ ...K(s, !0),
168
+ x.number.encode(t),
169
+ E.OP_CHECKSEQUENCEVERIFY
170
+ ]), { output: u } = L.p2tr({
171
+ internalPubkey: c.from(_),
172
+ scriptTree: { output: r, version: y }
173
+ });
174
+ if (!u)
175
+ throw new Error("Failed to derive the expected PegIn payout output.");
176
+ return u;
177
+ }
178
+ async function Je(e, t) {
148
179
  const o = t.pegInAmounts.length;
149
180
  if (t.hashlocks.length !== o)
150
181
  throw new Error(
@@ -162,7 +193,7 @@ async function Ze(e, t) {
162
193
  throw new Error(
163
194
  `WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
164
195
  );
165
- const n = await Ee(
196
+ const n = await ye(
166
197
  // Must price the same graph version the builder constructed.
167
198
  t.vaultCoreVersion,
168
199
  t.numLocalChallengers,
@@ -175,133 +206,133 @@ async function Ze(e, t) {
175
206
  throw new Error(
176
207
  `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${n} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
177
208
  );
178
- const i = await ye(t.vaultCoreVersion), s = (i == null ? void 0 : i.value) ?? 0n, r = await _e(
209
+ const i = await me(t.vaultCoreVersion), s = (i == null ? void 0 : i.value) ?? 0n, r = await Ie(
179
210
  t.vaultCoreVersion,
180
211
  t.vaultKeeperPubkeys.length,
181
212
  t.universalChallengerPubkeys.length,
182
213
  t.minPeginFeeRate
183
- ), u = r + s, h = t.minPeginFeeRate * M;
184
- for (let a = 0; a < o; a++) {
185
- const d = t.pegInAmounts[a], l = e.peginAmounts[a], P = e.htlcValues[a];
186
- if (l !== d)
214
+ ), u = r + s, h = t.minPeginFeeRate * q;
215
+ for (let l = 0; l < o; l++) {
216
+ const d = t.pegInAmounts[l], a = e.peginAmounts[l], P = e.htlcValues[l];
217
+ if (a !== d)
187
218
  throw new Error(
188
- `WASM Pre-PegIn peginAmount[${a}] ${l} does not match the requested amount ${d}; refusing to build a tx whose recorded amount differs from the depositor's request.`
219
+ `WASM Pre-PegIn peginAmount[${l}] ${a} does not match the requested amount ${d}; refusing to build a tx whose recorded amount differs from the depositor's request.`
189
220
  );
190
- if (l <= 0n)
221
+ if (a <= 0n)
191
222
  throw new Error(
192
- `WASM Pre-PegIn peginAmount[${a}] is non-positive (${l}); expected > 0.`
223
+ `WASM Pre-PegIn peginAmount[${l}] is non-positive (${a}); expected > 0.`
193
224
  );
194
225
  if (P <= 0n)
195
226
  throw new Error(
196
- `WASM Pre-PegIn htlcValue[${a}] is non-positive (${P}); expected > 0.`
227
+ `WASM Pre-PegIn htlcValue[${l}] is non-positive (${P}); expected > 0.`
197
228
  );
198
- const p = P - l - e.depositorClaimValue;
229
+ const p = P - a - e.depositorClaimValue;
199
230
  if (p <= 0n)
200
231
  throw new Error(
201
- `WASM Pre-PegIn htlcValue[${a}] ${P} does not strictly cover peginAmount ${l} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${p}).`
232
+ `WASM Pre-PegIn htlcValue[${l}] ${P} does not strictly cover peginAmount ${a} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${p}).`
202
233
  );
203
234
  if (p > h)
204
235
  throw new Error(
205
- `WASM Pre-PegIn implied reserve for HTLC[${a}] (${p} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${M} vbytes); htlcValue ${P} appears grossly inflated.`
236
+ `WASM Pre-PegIn implied reserve for HTLC[${l}] (${p} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${q} vbytes); htlcValue ${P} appears grossly inflated.`
206
237
  );
207
238
  if (p !== u)
208
239
  throw new Error(
209
- `WASM Pre-PegIn htlcValue[${a}] ${P} implies a PegIn fee+anchor reserve of ${p} sat, expected exactly ${u} sat (minPeginFee ${r} + p2aAnchor ${s} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
240
+ `WASM Pre-PegIn htlcValue[${l}] ${P} implies a PegIn fee+anchor reserve of ${p} sat, expected exactly ${u} sat (minPeginFee ${r} + p2aAnchor ${s} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
210
241
  );
211
242
  }
212
243
  return r;
213
244
  }
214
- class O extends Error {
245
+ class V extends Error {
215
246
  constructor(t) {
216
247
  super(t), this.name = "HtlcOutputMismatchError";
217
248
  }
218
249
  }
219
- function je(e, t, o) {
250
+ function et(e, t, o) {
220
251
  if (e.length < t.length)
221
- throw new O(
252
+ throw new V(
222
253
  `Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
223
254
  );
224
255
  for (let n = 0; n < t.length; n++) {
225
256
  const i = BigInt(e[n].value);
226
257
  if (i !== t[n])
227
- throw new O(
258
+ throw new V(
228
259
  `Encoded Pre-PegIn HTLC output[${n}] value ${i} does not match the cross-checked htlcValue ${t[n]}; the funded/signed tx would not pay the validated amount.`
229
260
  );
230
261
  const s = e[n].script.toString("hex").toLowerCase(), r = o[n].toLowerCase();
231
262
  if (s !== r)
232
- throw new O(
263
+ throw new V(
233
264
  `Encoded Pre-PegIn HTLC output[${n}] scriptPubKey ${s} does not match the cross-checked htlcScriptPubKey ${r}.`
234
265
  );
235
266
  }
236
267
  }
237
- function Je(e, t, o, n, i, s, r) {
238
- if (s !== q)
268
+ function tt(e, t, o, n, i, s, r) {
269
+ if (s !== X)
239
270
  throw new Error(
240
- `WASM Pre-PegIn transaction version ${s}; expected ${q}.`
271
+ `WASM Pre-PegIn transaction version ${s}; expected ${X}.`
241
272
  );
242
- if (r !== W)
273
+ if (r !== G)
243
274
  throw new Error(
244
- `WASM Pre-PegIn transaction locktime ${r}; expected ${W}.`
275
+ `WASM Pre-PegIn transaction locktime ${r}; expected ${G}.`
245
276
  );
246
- if (t.length < X)
277
+ if (t.length < z)
247
278
  throw new Error(
248
- `WASM Pre-PegIn output layout has ${t.length} HTLC output(s); expected at least ${X}.`
279
+ `WASM Pre-PegIn output layout has ${t.length} HTLC output(s); expected at least ${z}.`
249
280
  );
250
- const u = t.length, h = u + +(i !== void 0), a = Le(
281
+ const u = t.length, h = u + +(i !== void 0), l = Ke(
251
282
  t.length,
252
283
  i !== void 0
253
284
  );
254
- if (e.length !== a)
285
+ if (e.length !== l)
255
286
  throw new Error(
256
- `WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${a}.`
287
+ `WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${l}.`
257
288
  );
258
- je(e, t, o);
289
+ et(e, t, o);
259
290
  for (let p = 0; p < t.length; p++) {
260
- const v = Qe(
291
+ const v = Ze(
261
292
  n,
262
293
  n.hashlocks[p]
263
294
  ).scriptPubKey;
264
295
  if (!e[p].script.equals(v))
265
- throw new O(
296
+ throw new V(
266
297
  `Pre-PegIn HTLC output[${p}] does not match the independently derived scriptPubKey.`
267
298
  );
268
299
  }
269
300
  if (i !== void 0) {
270
301
  const p = e[u];
271
- if (p.value !== G)
302
+ if (p.value !== Y)
272
303
  throw new Error(
273
- `WASM Pre-PegIn auth output[${u}] value ${p.value} sat; expected exactly ${G} sat.`
304
+ `WASM Pre-PegIn auth output[${u}] value ${p.value} sat; expected exactly ${Y} sat.`
274
305
  );
275
- const v = p.script.toString("hex").toLowerCase(), w = Be + i.toLowerCase();
306
+ const v = p.script.toString("hex").toLowerCase(), w = Me + i.toLowerCase();
276
307
  if (v !== w)
277
308
  throw new Error(
278
309
  `WASM Pre-PegIn auth output[${u}] scriptPubKey ${v}; expected ${w}.`
279
310
  );
280
311
  }
281
312
  const d = e[h];
282
- if (d.value !== z)
313
+ if (d.value !== D)
283
314
  throw new Error(
284
- `WASM Pre-PegIn CPFP output[${h}] value ${d.value} sat; expected exactly ${z} sat.`
315
+ `WASM Pre-PegIn CPFP output[${h}] value ${d.value} sat; expected exactly ${D} sat.`
285
316
  );
286
- const l = d.script.toString("hex").toLowerCase(), P = f(
317
+ const a = d.script.toString("hex").toLowerCase(), P = f(
287
318
  $e(n.depositorPubkey)
288
319
  ).toLowerCase();
289
- if (l !== P)
320
+ if (a !== P)
290
321
  throw new Error(
291
- `WASM Pre-PegIn CPFP output[${h}] scriptPubKey ${l}; expected depositor BIP-86 script ${P}.`
322
+ `WASM Pre-PegIn CPFP output[${h}] scriptPubKey ${a}; expected depositor BIP-86 script ${P}.`
292
323
  );
293
324
  }
294
- const et = 1;
295
- function tt(e) {
325
+ const ot = 1;
326
+ function nt(e) {
296
327
  const t = f(e);
297
328
  if (!/^[0-9a-fA-F]{64}$/.test(t))
298
329
  throw new Error(
299
330
  "Invalid depositor pubkey for the depositor-claim script: must be an x-only key of 64 hex characters (32 bytes)."
300
331
  );
301
- const o = _.compile([
302
- c.from(x(t)),
332
+ const o = x.compile([
333
+ c.from(C(t)),
303
334
  E.OP_CHECKSIG
304
- ]), n = c.from(k), i = { output: o, redeemVersion: y }, { output: s, witness: r } = R.p2tr({
335
+ ]), n = c.from(_), i = { output: o, redeemVersion: y }, { output: s, witness: r } = L.p2tr({
305
336
  internalPubkey: n,
306
337
  scriptTree: { output: o },
307
338
  redeem: i
@@ -317,12 +348,12 @@ function tt(e) {
317
348
  );
318
349
  return { scriptPubKey: s, leafScript: o, controlBlock: u, internalKey: n };
319
350
  }
320
- function ot(e) {
321
- return tt(e).scriptPubKey;
351
+ function rt(e) {
352
+ return nt(e).scriptPubKey;
322
353
  }
323
- const se = 64, nt = /^[0-9a-fA-F]+$/;
324
- async function Dt(e) {
325
- const t = xe(e.authAnchorHash), o = await Ie({
354
+ const se = 64, it = /^[0-9a-fA-F]+$/, ue = 65535;
355
+ async function Zt(e) {
356
+ const t = be(e.authAnchorHash), o = await Te({
326
357
  txGraphVersion: e.vaultCoreVersion,
327
358
  depositorPubkey: e.depositorPubkey,
328
359
  vaultProviderPubkey: e.vaultProviderPubkey,
@@ -338,8 +369,8 @@ async function Dt(e) {
338
369
  councilSize: e.councilSize,
339
370
  network: e.network,
340
371
  authAnchorHash: t
341
- }), n = await Ze(o, e), i = Re(o.txHex);
342
- Je(
372
+ }), n = await Je(o, e), i = He(o.txHex);
373
+ tt(
343
374
  i.outputs,
344
375
  o.htlcValues,
345
376
  o.htlcScriptPubKeys,
@@ -364,17 +395,21 @@ async function Dt(e) {
364
395
  minPeginFee: n
365
396
  };
366
397
  }
367
- function xe(e) {
398
+ function be(e) {
368
399
  if (e === void 0) return;
369
400
  const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
370
- if (t.length !== se || !nt.test(t))
401
+ if (t.length !== se || !it.test(t))
371
402
  throw new Error(
372
403
  `authAnchorHash must be 32-byte hex (${se} chars, no 0x prefix); got length ${t.length}`
373
404
  );
374
405
  return t.toLowerCase();
375
406
  }
376
- async function Qt(e) {
377
- const t = await ke(
407
+ async function jt(e) {
408
+ if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin > ue)
409
+ throw new Error(
410
+ `PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${ue}.`
411
+ );
412
+ const t = await Ae(
378
413
  {
379
414
  txGraphVersion: e.prePeginParams.vaultCoreVersion,
380
415
  depositorPubkey: e.prePeginParams.depositorPubkey,
@@ -390,7 +425,7 @@ async function Qt(e) {
390
425
  councilQuorum: e.prePeginParams.councilQuorum,
391
426
  councilSize: e.prePeginParams.councilSize,
392
427
  network: e.prePeginParams.network,
393
- authAnchorHash: xe(
428
+ authAnchorHash: be(
394
429
  e.prePeginParams.authAnchorHash
395
430
  )
396
431
  },
@@ -398,35 +433,35 @@ async function Qt(e) {
398
433
  e.fundedPrePeginTxHex,
399
434
  e.htlcVout
400
435
  );
401
- return await it(t, e), {
436
+ return await ut(t, e), {
402
437
  txHex: t.txHex,
403
438
  txid: t.txid,
404
439
  vaultScriptPubKey: t.vaultScriptPubKey,
405
440
  vaultValue: t.vaultValue
406
441
  };
407
442
  }
408
- const rt = 2;
409
- async function it(e, t) {
410
- const o = t.prePeginParams.vaultCoreVersion, n = o === 1 ? Me : o === 2 || o === 3 ? Fe : void 0;
443
+ const st = 2;
444
+ async function ut(e, t) {
445
+ const o = t.prePeginParams.vaultCoreVersion, n = o === 1 ? Fe : o === 2 || o === 3 ? qe : void 0;
411
446
  if (n === void 0)
412
447
  throw new Error(`Unsupported vaultCoreVersion ${o} for PegIn tx.`);
413
- await Ae(o, e.txHex);
414
- const i = await ye(o), s = rt + (i ? 1 : 0), r = b.fromHex(f(e.txHex));
448
+ await Oe(o, e.txHex);
449
+ const i = await me(o), s = st + (i ? 1 : 0), r = k.fromHex(f(e.txHex));
415
450
  if (r.version !== n)
416
451
  throw new Error(
417
452
  `PegIn tx version ${r.version} does not match vaultCoreVersion ${o}; expected ${n}.`
418
453
  );
419
- if (r.locktime !== Y)
454
+ if (r.locktime !== Q)
420
455
  throw new Error(
421
- `PegIn tx locktime ${r.locktime} does not match the canonical locktime ${Y}.`
456
+ `PegIn tx locktime ${r.locktime} does not match the canonical locktime ${Q}.`
422
457
  );
423
458
  if (r.ins.length !== 1)
424
459
  throw new Error(
425
460
  `PegIn tx has ${r.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
426
461
  );
427
- const u = b.fromHex(
462
+ const u = k.fromHex(
428
463
  f(t.fundedPrePeginTxHex)
429
- ).getId(), h = U(
464
+ ).getId(), h = M(
430
465
  new Uint8Array(r.ins[0].hash).slice().reverse()
431
466
  );
432
467
  if (h !== u)
@@ -437,9 +472,9 @@ async function it(e, t) {
437
472
  throw new Error(
438
473
  `PegIn input spends Pre-PegIn output ${r.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
439
474
  );
440
- if (r.ins[0].sequence !== D)
475
+ if (r.ins[0].sequence !== Z)
441
476
  throw new Error(
442
- `PegIn input sequence ${r.ins[0].sequence} does not match the canonical sequence ${D}.`
477
+ `PegIn input sequence ${r.ins[0].sequence} does not match the canonical sequence ${Z}.`
443
478
  );
444
479
  if (r.ins[0].script.length !== 0)
445
480
  throw new Error("PegIn input scriptSig must be empty.");
@@ -449,41 +484,47 @@ async function it(e, t) {
449
484
  throw new Error(
450
485
  `PegIn tx has ${r.outs.length} output(s), expected exactly ${s} for vaultCoreVersion ${o} (vault + depositor claim${i ? " + P2A anchor" : ""}).`
451
486
  );
452
- const a = t.prePeginParams.pegInAmounts[t.htlcVout];
453
- if (e.vaultValue !== a)
487
+ const l = t.prePeginParams.pegInAmounts[t.htlcVout];
488
+ if (e.vaultValue !== l)
454
489
  throw new Error(
455
- `PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${a} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
490
+ `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.`
456
491
  );
457
492
  const d = r.outs[0];
458
493
  if (BigInt(d.value) !== e.vaultValue)
459
494
  throw new Error(
460
495
  `Encoded PegIn vault output value ${d.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
461
496
  );
462
- const l = d.script.toString("hex"), P = f(
463
- e.vaultScriptPubKey
464
- ).toLowerCase();
465
- if (l.toLowerCase() !== P)
497
+ const a = je(
498
+ t.prePeginParams,
499
+ t.timelockPegin
500
+ ).toString("hex");
501
+ if (f(e.vaultScriptPubKey).toLowerCase() !== a)
466
502
  throw new Error(
467
- `Encoded PegIn vault output scriptPubKey ${l} does not match the WASM-reported vaultScriptPubKey ${e.vaultScriptPubKey}.`
503
+ `WASM-reported PegIn vaultScriptPubKey ${e.vaultScriptPubKey} does not match the independently derived payout scriptPubKey ${a}.`
504
+ );
505
+ const P = d.script.toString("hex");
506
+ if (P !== a)
507
+ throw new Error(
508
+ `Encoded PegIn vault output scriptPubKey ${P} does not match the independently derived payout scriptPubKey ${a}.`
468
509
  );
469
510
  const p = r.getId();
470
511
  if (p !== f(e.txid).toLowerCase())
471
512
  throw new Error(
472
513
  `Encoded PegIn txid ${p} does not match the WASM-reported txid ${e.txid}.`
473
514
  );
474
- const v = await Ee(
515
+ const v = await ye(
475
516
  o,
476
517
  t.prePeginParams.numLocalChallengers,
477
518
  t.prePeginParams.universalChallengerPubkeys.length,
478
519
  t.prePeginParams.councilQuorum,
479
520
  t.prePeginParams.councilSize,
480
521
  t.prePeginParams.feeRate
481
- ), w = r.outs[et];
522
+ ), w = r.outs[ot];
482
523
  if (BigInt(w.value) !== v)
483
524
  throw new Error(
484
525
  `Encoded PegIn depositor-claim output value ${w.value} does not match the independently computed claim value ${v} for vaultCoreVersion ${o}.`
485
526
  );
486
- const g = ot(
527
+ const g = rt(
487
528
  t.prePeginParams.depositorPubkey
488
529
  );
489
530
  if (!w.script.equals(g))
@@ -491,8 +532,8 @@ async function it(e, t) {
491
532
  `Encoded PegIn depositor-claim output scriptPubKey ${w.script.toString("hex")} does not pay to the depositor's claim script (expected ${g.toString("hex")}).`
492
533
  );
493
534
  }
494
- async function st(e) {
495
- const t = await Te(
535
+ async function ct(e) {
536
+ const t = await Ve(
496
537
  {
497
538
  txGraphVersion: e.vaultCoreVersion,
498
539
  depositor: e.depositor,
@@ -511,87 +552,87 @@ async function st(e) {
511
552
  payoutControlBlock: t.payoutControlBlock
512
553
  };
513
554
  }
514
- const ue = 253, ut = 254, ct = 65535, at = 4294967295, lt = "TapLeaf", ht = "TapBranch", dt = "TapTweak", A = 33, T = 32, ce = 128, pt = 1, Pt = 254, ft = c.from([81, 32]);
515
- function gt(e) {
516
- if (e < ue)
555
+ const ce = 253, at = 254, lt = 65535, ht = 4294967295, dt = "TapLeaf", pt = "TapBranch", Pt = "TapTweak", T = 33, O = 32, ae = 128, ft = 1, gt = 254, wt = c.from([81, 32]);
556
+ function vt(e) {
557
+ if (e < ce)
517
558
  return c.from([e]);
518
- if (e <= ct) {
559
+ if (e <= lt) {
519
560
  const t = c.alloc(2);
520
- return t.writeUInt16LE(e), c.concat([c.from([ue]), t]);
561
+ return t.writeUInt16LE(e), c.concat([c.from([ce]), t]);
521
562
  }
522
- if (e <= at) {
563
+ if (e <= ht) {
523
564
  const t = c.alloc(4);
524
- return t.writeUInt32LE(e), c.concat([c.from([ut]), t]);
565
+ return t.writeUInt32LE(e), c.concat([c.from([at]), t]);
525
566
  }
526
567
  throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
527
568
  }
528
- function Ce(e, t) {
569
+ function ke(e, t) {
529
570
  const o = c.concat([
530
571
  c.from([e]),
531
- gt(t.length),
572
+ vt(t.length),
532
573
  c.from(t)
533
574
  ]);
534
- return H.taggedHash(lt, o);
575
+ return U.taggedHash(dt, o);
535
576
  }
536
- function wt(e) {
537
- const { leafVersion: t, script: o, controlBlock: n } = e, i = n.length - A;
538
- if (i < 0 || i % T !== 0 || i / T > ce)
577
+ function Et(e) {
578
+ const { leafVersion: t, script: o, controlBlock: n } = e, i = n.length - T;
579
+ if (i < 0 || i % O !== 0 || i / O > ae)
539
580
  throw new Error(
540
- `Malformed Taproot control block: length ${n.length} must be ${A} + 32*m with 0 <= m <= ${ce}`
581
+ `Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${ae}`
541
582
  );
542
- const s = n[0] & Pt;
583
+ const s = n[0] & gt;
543
584
  if (s !== t)
544
585
  throw new Error(
545
586
  `Taproot control block leaf version 0x${s.toString(16)} does not match the tapLeafScript leaf version 0x${t.toString(16)}`
546
587
  );
547
588
  const r = c.from(
548
- n.subarray(1, A)
589
+ n.subarray(1, T)
549
590
  );
550
- let u = Ce(t, o);
551
- for (let l = A; l < n.length; l += T) {
591
+ let u = ke(t, o);
592
+ for (let a = T; a < n.length; a += O) {
552
593
  const P = c.from(
553
- n.subarray(l, l + T)
594
+ n.subarray(a, a + O)
554
595
  );
555
- u = H.taggedHash(
556
- ht,
596
+ u = U.taggedHash(
597
+ pt,
557
598
  c.compare(u, P) <= 0 ? c.concat([u, P]) : c.concat([P, u])
558
599
  );
559
600
  }
560
- const h = H.taggedHash(
561
- dt,
601
+ const h = U.taggedHash(
602
+ Pt,
562
603
  c.concat([r, u])
563
- ), a = Se.xOnlyPointAddTweak(r, h);
564
- if (a === null)
604
+ ), l = Ce.xOnlyPointAddTweak(r, h);
605
+ if (l === null)
565
606
  throw new Error(
566
607
  "Taproot control block does not yield a valid output key (tweak is off-curve)"
567
608
  );
568
- const d = n[0] & pt;
569
- if (a.parity !== d)
609
+ const d = n[0] & ft;
610
+ if (l.parity !== d)
570
611
  throw new Error(
571
- `Taproot output key parity ${a.parity} contradicts the control block's parity bit ${d}`
612
+ `Taproot output key parity ${l.parity} contradicts the control block's parity bit ${d}`
572
613
  );
573
614
  return c.concat([
574
- ft,
575
- c.from(a.xOnlyPubkey)
615
+ wt,
616
+ c.from(l.xOnlyPubkey)
576
617
  ]);
577
618
  }
578
- const vt = 256, Et = 1500, ae = 256, le = 0xffffffffn, yt = 500, $t = 55, mt = 34;
579
- function St(e) {
580
- if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > le)
619
+ const yt = 256, mt = 1500, le = 256, he = 0xffffffffn, $t = 500, St = 55, xt = 34;
620
+ function Ct(e) {
621
+ if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > he)
581
622
  throw new Error(
582
- `protocolFeeRate must be in [1, ${le}] sat/vB, got ${e.protocolFeeRate}`
623
+ `protocolFeeRate must be in [1, ${he}] sat/vB, got ${e.protocolFeeRate}`
583
624
  );
584
625
  for (const [t, o, n, i] of [
585
626
  [
586
627
  "keepers",
587
628
  e.numVaultKeepers,
588
- vt,
629
+ yt,
589
630
  "fee-floor model limit"
590
631
  ],
591
632
  [
592
633
  "challengers",
593
634
  e.numUniversalChallengers,
594
- Et,
635
+ mt,
595
636
  "protocol maximum"
596
637
  ]
597
638
  ])
@@ -599,18 +640,18 @@ function St(e) {
599
640
  throw new Error(
600
641
  `Participant count for ${t} (${o}) is outside the supported range [1, ${n}]${o > n ? ` (${i})` : ""}.`
601
642
  );
602
- if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > ae)
643
+ if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > le)
603
644
  throw new Error(
604
- `councilSize must be an integer in [1, ${ae}], got ${e.councilSize}`
645
+ `councilSize must be an integer in [1, ${le}], got ${e.councilSize}`
605
646
  );
606
647
  }
607
- async function xt(e, t) {
608
- const { implicitFeeSats: o, out0Len: n, out1Len: i } = t, s = e.numVaultKeepers + e.numUniversalChallengers, r = BigInt(o), u = Math.max(0, n - mt), h = yt + $t * s + u, a = e.protocolFeeRate * BigInt(h);
609
- if (r > a)
648
+ async function bt(e, t) {
649
+ const { implicitFeeSats: o, out0Len: n, out1Len: i } = t, s = e.numVaultKeepers + e.numUniversalChallengers, r = BigInt(o), u = Math.max(0, n - xt), h = $t + St * s + u, l = e.protocolFeeRate * BigInt(h);
650
+ if (r > l)
610
651
  throw new Error(
611
- `Payout implicit fee ${o} sats exceeds the safety cap of ${a} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${s} participants); refusing to sign payout.`
652
+ `Payout implicit fee ${o} sats exceeds the safety cap of ${l} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${s} participants); refusing to sign payout.`
612
653
  );
613
- const d = await Oe(
654
+ const d = await Le(
614
655
  e.vaultCoreVersion,
615
656
  e.numVaultKeepers,
616
657
  e.numUniversalChallengers,
@@ -625,23 +666,23 @@ async function xt(e, t) {
625
666
  `Payout implicit fee ${o} sats is below the floor of ${d} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
626
667
  );
627
668
  }
628
- const Ct = 22, bt = 34, _t = 34, kt = 25, It = 23;
629
- function At(e) {
630
- return e.length === Ct * 2 && e.startsWith("0014");
631
- }
632
- function Tt(e) {
633
- return e.length === bt * 2 && e.startsWith("0020");
634
- }
669
+ const kt = 22, _t = 34, It = 34, At = 25, Tt = 23;
635
670
  function Ot(e) {
636
- return e.length === _t * 2 && e.startsWith("5120");
671
+ return e.length === kt * 2 && e.startsWith("0014");
637
672
  }
638
673
  function Vt(e) {
639
- return e.length === kt * 2 && e.startsWith("76a914") && e.endsWith("88ac");
674
+ return e.length === _t * 2 && e.startsWith("0020");
640
675
  }
641
676
  function Lt(e) {
642
- return e.length === It * 2 && e.startsWith("a914") && e.endsWith("87");
677
+ return e.length === It * 2 && e.startsWith("5120");
643
678
  }
644
- function he(e, t) {
679
+ function Rt(e) {
680
+ return e.length === At * 2 && e.startsWith("76a914") && e.endsWith("88ac");
681
+ }
682
+ function Kt(e) {
683
+ return e.length === Tt * 2 && e.startsWith("a914") && e.endsWith("87");
684
+ }
685
+ function de(e, t) {
645
686
  const o = f(e).toLowerCase();
646
687
  if (o.length === 0)
647
688
  throw new Error(`${t} is empty`);
@@ -651,13 +692,13 @@ function he(e, t) {
651
692
  throw new Error(
652
693
  `${t} is an OP_RETURN output, which is provably unspendable`
653
694
  );
654
- if (!Ot(o) && !At(o) && !Tt(o) && !Vt(o) && !Lt(o))
695
+ if (!Lt(o) && !Ot(o) && !Vt(o) && !Rt(o) && !Kt(o))
655
696
  throw new Error(
656
697
  `${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${o.length / 2} bytes: ${o})`
657
698
  );
658
699
  }
659
- const de = 3;
660
- async function Zt(e) {
700
+ const pe = 3;
701
+ async function Jt(e) {
661
702
  const t = {
662
703
  vaultCoreVersion: e.vaultCoreVersion,
663
704
  numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
@@ -665,60 +706,60 @@ async function Zt(e) {
665
706
  councilSize: e.councilMembers.length,
666
707
  protocolFeeRate: e.protocolFeeRate
667
708
  };
668
- St(t);
669
- const o = b.fromHex(f(e.payoutTxHex)), n = b.fromHex(f(e.peginTxHex)), i = b.fromHex(f(e.assertTxHex));
670
- if (o.ins.length !== Q)
709
+ Ct(t);
710
+ const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)), i = k.fromHex(f(e.assertTxHex));
711
+ if (o.ins.length !== j)
671
712
  throw new Error(
672
- `Payout transaction must have exactly ${Q} inputs, got ${o.ins.length}`
713
+ `Payout transaction must have exactly ${j} inputs, got ${o.ins.length}`
673
714
  );
674
- if (o.version !== Z)
715
+ if (o.version !== J)
675
716
  throw new Error(
676
- `Payout transaction version ${o.version} must be ${Z}; refusing to sign payout.`
717
+ `Payout transaction version ${o.version} must be ${J}; refusing to sign payout.`
677
718
  );
678
- if (o.locktime !== j)
719
+ if (o.locktime !== ee)
679
720
  throw new Error(
680
- `Payout transaction locktime ${o.locktime} must be ${j}; refusing to sign payout.`
721
+ `Payout transaction locktime ${o.locktime} must be ${ee}; refusing to sign payout.`
681
722
  );
682
- const s = pe(
723
+ const s = Pe(
683
724
  o.ins[0],
684
725
  0,
685
726
  n,
686
727
  "PegIn",
687
- qe
728
+ We
688
729
  );
689
730
  if (o.ins[0].sequence !== e.timelockPegin)
690
731
  throw new Error(
691
732
  `Payout input 0 sequence ${o.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
692
733
  );
693
- const r = pe(
734
+ const r = Pe(
694
735
  o.ins[1],
695
736
  1,
696
737
  i,
697
738
  "Assert",
698
- me
739
+ xe
699
740
  );
700
741
  if (o.ins[1].sequence !== e.timelockAssert)
701
742
  throw new Error(
702
743
  `Payout input 1 sequence ${o.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
703
744
  );
704
- const { out0Len: u, out1Len: h } = Kt(
745
+ const { out0Len: u, out1Len: h } = Ut(
705
746
  o,
706
747
  s.value,
707
748
  e
708
- ), a = s.value + r.value;
749
+ ), l = s.value + r.value;
709
750
  let d = 0;
710
751
  for (const v of o.outs) d += v.value;
711
- if (d > a)
752
+ if (d > l)
712
753
  throw new Error(
713
- `Payout outputs (${d} sats) exceed inputs (${a} sats); invalid transaction.`
754
+ `Payout outputs (${d} sats) exceed inputs (${l} sats); invalid transaction.`
714
755
  );
715
- const l = a - d;
716
- await xt(t, {
717
- implicitFeeSats: l,
756
+ const a = l - d;
757
+ await bt(t, {
758
+ implicitFeeSats: a,
718
759
  out0Len: u,
719
760
  out1Len: h
720
761
  });
721
- const P = await st({
762
+ const P = await ct({
722
763
  vaultCoreVersion: e.vaultCoreVersion,
723
764
  depositor: e.depositorBtcPubkey,
724
765
  vaultProvider: e.vaultProviderBtcPubkey,
@@ -726,9 +767,9 @@ async function Zt(e) {
726
767
  universalChallengers: e.universalChallengerBtcPubkeys,
727
768
  timelockPegin: e.timelockPegin,
728
769
  network: e.network
729
- }), p = await Rt(e, r);
770
+ }), p = await Ht(e, r);
730
771
  return {
731
- psbtHex: Ht(
772
+ psbtHex: Nt(
732
773
  o,
733
774
  s,
734
775
  r,
@@ -737,11 +778,11 @@ async function Zt(e) {
737
778
  )
738
779
  };
739
780
  }
740
- async function Rt(e, t) {
741
- const { payoutScript: o, payoutControlBlock: n } = await Ve({
781
+ async function Ht(e, t) {
782
+ const { payoutScript: o, payoutControlBlock: n } = await Re({
742
783
  txGraphVersion: e.vaultCoreVersion,
743
784
  claimer: f(e.claimerBtcPubkey).toLowerCase(),
744
- localChallengers: Ge({
785
+ localChallengers: ze({
745
786
  claimerBtcPubkey: e.claimerBtcPubkey,
746
787
  depositorBtcPubkey: e.depositorBtcPubkey,
747
788
  vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
@@ -755,19 +796,19 @@ async function Rt(e, t) {
755
796
  (u) => f(u).toLowerCase()
756
797
  ),
757
798
  councilQuorum: e.councilQuorum
758
- }), i = x(o), s = x(n), r = wt({
799
+ }), i = C(o), s = C(n), r = Et({
759
800
  leafVersion: y,
760
801
  script: i,
761
802
  controlBlock: s
762
803
  });
763
804
  if (!t.script.equals(r))
764
805
  throw new Error(
765
- `Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${r.toString("hex")}, Assert:${me} pays ${t.script.toString("hex")}; refusing to sign payout.`
806
+ `Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${r.toString("hex")}, Assert:${xe} pays ${t.script.toString("hex")}; refusing to sign payout.`
766
807
  );
767
808
  return { script: i, controlBlock: s };
768
809
  }
769
- function pe(e, t, o, n, i) {
770
- const s = U(
810
+ function Pe(e, t, o, n, i) {
811
+ const s = M(
771
812
  new Uint8Array(e.hash).slice().reverse()
772
813
  ), r = o.getId();
773
814
  if (s !== r || e.index !== i)
@@ -781,8 +822,8 @@ function pe(e, t, o, n, i) {
781
822
  );
782
823
  return u;
783
824
  }
784
- function Ht(e, t, o, n, i) {
785
- const s = new V();
825
+ function Nt(e, t, o, n, i) {
826
+ const s = new H();
786
827
  s.setVersion(e.version), s.setLocktime(e.locktime);
787
828
  const [r, u] = e.ins;
788
829
  s.addInput({
@@ -796,13 +837,13 @@ function Ht(e, t, o, n, i) {
796
837
  tapLeafScript: [
797
838
  {
798
839
  leafVersion: y,
799
- script: c.from(x(n.payoutScript)),
840
+ script: c.from(C(n.payoutScript)),
800
841
  controlBlock: c.from(
801
- x(n.payoutControlBlock)
842
+ C(n.payoutControlBlock)
802
843
  )
803
844
  }
804
845
  ],
805
- tapInternalKey: c.from(k)
846
+ tapInternalKey: c.from(_)
806
847
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
807
848
  }), s.addInput({
808
849
  hash: u.hash,
@@ -819,7 +860,7 @@ function Ht(e, t, o, n, i) {
819
860
  controlBlock: c.from(i.controlBlock)
820
861
  }
821
862
  ],
822
- tapInternalKey: c.from(k)
863
+ tapInternalKey: c.from(_)
823
864
  });
824
865
  for (const h of e.outs)
825
866
  s.addOutput({
@@ -828,16 +869,16 @@ function Ht(e, t, o, n, i) {
828
869
  });
829
870
  return s.toHex();
830
871
  }
831
- function Pe(e, t) {
872
+ function fe(e, t) {
832
873
  const o = f(e).toLowerCase(), n = f(
833
874
  $e(t)
834
875
  ).toLowerCase();
835
876
  return o === n ? [o] : [o, n];
836
877
  }
837
- function fe(e, t) {
878
+ function ge(e, t) {
838
879
  return t.some((o) => e.equals(c.from(o, "hex")));
839
880
  }
840
- function Kt(e, t, o) {
881
+ function Ut(e, t, o) {
841
882
  const {
842
883
  claimerBtcPubkey: n,
843
884
  vaultProviderBtcPubkey: i,
@@ -845,118 +886,118 @@ function Kt(e, t, o) {
845
886
  vaultKeeperBtcPubkeys: r,
846
887
  registeredPayoutScriptPubKey: u,
847
888
  commissionBps: h,
848
- vkClaimerPayoutScriptPubKeys: a,
889
+ vkClaimerPayoutScriptPubKeys: l,
849
890
  vpCommissionScriptPubKey: d
850
891
  } = o;
851
- if (!Ne(u))
892
+ if (!Ue(u))
852
893
  throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
853
- const l = f(n).toLowerCase(), P = f(i).toLowerCase(), p = f(s).toLowerCase(), v = r.map(
894
+ const a = f(n).toLowerCase(), P = f(i).toLowerCase(), p = f(s).toLowerCase(), v = r.map(
854
895
  (S) => f(S).toLowerCase()
855
896
  );
856
- let w, g, $;
857
- if (l === P)
858
- w = "vp-claimer", g = Xe, $ = [f(u)];
859
- else if (l === p)
860
- w = "depositor-as-claimer", g = oe, $ = [f(u)];
861
- else if (v.includes(l)) {
862
- w = "vk-claimer", g = oe;
863
- const S = a[l];
897
+ let w, g, m;
898
+ if (a === P)
899
+ w = "vp-claimer", g = Ge, m = [f(u)];
900
+ else if (a === p)
901
+ w = "depositor-as-claimer", g = re, m = [f(u)];
902
+ else if (v.includes(a)) {
903
+ w = "vk-claimer", g = re;
904
+ const S = l[a];
864
905
  if (S === void 0)
865
906
  throw new Error(
866
- `No registered payout script resolved for vault keeper claimer ${l}`
907
+ `No registered payout script resolved for vault keeper claimer ${a}`
867
908
  );
868
- he(
909
+ de(
869
910
  S,
870
- `Vault keeper payout script for claimer ${l}`
871
- ), $ = Pe(S, l);
911
+ `Vault keeper payout script for claimer ${a}`
912
+ ), m = fe(S, a);
872
913
  } else
873
914
  throw new Error(
874
- `Unknown claimer pubkey ${l}: not VP, depositor, or a registered vault keeper`
915
+ `Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
875
916
  );
876
917
  if (e.outs.length !== g)
877
918
  throw new Error(
878
919
  `Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${w}.`
879
920
  );
880
- if (!fe(e.outs[0].script, $))
921
+ if (!ge(e.outs[0].script, m))
881
922
  throw new Error(
882
- `Payout transaction output 0 does not pay the expected scriptPubKey for role ${w}. Accepted: ${$.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
923
+ `Payout transaction output 0 does not pay the expected scriptPubKey for role ${w}. Accepted: ${m.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
883
924
  );
884
- const L = g - 1;
885
- if (e.outs[L].value !== J)
925
+ const N = g - 1;
926
+ if (e.outs[N].value !== te)
886
927
  throw new Error(
887
- `Payout CPFP anchor (out ${L}) value ${e.outs[L].value} sats must equal ${J} sats`
928
+ `Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${te} sats`
888
929
  );
889
930
  if (w === "vp-claimer") {
890
- he(
931
+ de(
891
932
  d,
892
933
  "Vault provider commission payout script"
893
934
  );
894
- const S = Pe(
935
+ const S = fe(
895
936
  d,
896
937
  P
897
938
  );
898
- if (!fe(e.outs[1].script, S))
939
+ if (!ge(e.outs[1].script, S))
899
940
  throw new Error(
900
941
  `Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
901
942
  );
902
- if (!Number.isInteger(h) || h < 0 || h >= ee)
943
+ if (!Number.isInteger(h) || h < 0 || h >= oe)
903
944
  throw new Error(
904
- `commissionBps must be an integer in [0, ${ee}), got ${h}`
945
+ `commissionBps must be an integer in [0, ${oe}), got ${h}`
905
946
  );
906
- const B = Math.floor(
907
- t * h / We
947
+ const F = Math.floor(
948
+ t * h / Xe
908
949
  );
909
- if (e.outs[1].value > B)
950
+ if (e.outs[1].value > F)
910
951
  throw new Error(
911
- `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${B} sats (${h} bps of peginValue=${t})`
952
+ `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${F} sats (${h} bps of peginValue=${t})`
912
953
  );
913
954
  }
914
- const I = e.outs[0].script.length;
915
- if (I === 0 || I > te)
955
+ const A = e.outs[0].script.length;
956
+ if (A === 0 || A > ne)
916
957
  throw new Error(
917
- `Payout receiver scriptPubKey length ${I} is outside the contract's registration cap [1, ${te}]; refusing to sign payout.`
958
+ `Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${ne}]; refusing to sign payout.`
918
959
  );
919
- const be = w === "vp-claimer" ? e.outs[1].script.length : void 0;
920
- return { out0Len: I, out1Len: be };
960
+ const _e = w === "vp-claimer" ? e.outs[1].script.length : void 0;
961
+ return { out0Len: A, out1Len: _e };
921
962
  }
922
- function jt(e, t, o = 0) {
923
- const n = V.fromHex(e);
963
+ function eo(e, t, o = 0) {
964
+ const n = H.fromHex(e);
924
965
  if (o >= n.data.inputs.length)
925
966
  throw new Error(
926
967
  `Input index ${o} out of range (${n.data.inputs.length} inputs)`
927
968
  );
928
969
  const i = n.data.inputs[o];
929
970
  if (i.tapScriptSig && i.tapScriptSig.length > 0) {
930
- const s = x(t);
971
+ const s = C(t);
931
972
  for (const r of i.tapScriptSig)
932
973
  if (r.pubkey.equals(c.from(s)))
933
- return ge(r.signature, o);
974
+ return we(r.signature, o);
934
975
  throw new Error(
935
976
  `No signature found for depositor pubkey: ${t} at input ${o}`
936
977
  );
937
978
  }
938
979
  if (i.finalScriptWitness && i.finalScriptWitness.length > 0) {
939
- const s = Nt(i.finalScriptWitness);
940
- if (s.length !== de)
980
+ const s = Bt(i.finalScriptWitness);
981
+ if (s.length !== pe)
941
982
  throw new Error(
942
- `Unexpected finalized witness stack size at input ${o}: expected ${de} items (signature, script, controlBlock), got ${s.length}`
983
+ `Unexpected finalized witness stack size at input ${o}: expected ${pe} items (signature, script, controlBlock), got ${s.length}`
943
984
  );
944
- return ge(s[0], o);
985
+ return we(s[0], o);
945
986
  }
946
987
  throw new Error(
947
988
  `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${o}`
948
989
  );
949
990
  }
950
- function ge(e, t) {
991
+ function we(e, t) {
951
992
  if (e.length === 64)
952
- return U(new Uint8Array(e));
993
+ return M(new Uint8Array(e));
953
994
  throw e.length === 65 ? new Error(
954
995
  `Unexpected sighash byte 0x${e[64].toString(16).padStart(2, "0")} at input ${t}. Expected implicit SIGHASH_DEFAULT as a 64-byte signature.`
955
996
  ) : new Error(
956
997
  `Unexpected signature length at input ${t}: ${e.length}`
957
998
  );
958
999
  }
959
- function Nt(e) {
1000
+ function Bt(e) {
960
1001
  const t = [];
961
1002
  let o = 0;
962
1003
  const n = (r) => {
@@ -992,110 +1033,110 @@ function Nt(e) {
992
1033
  );
993
1034
  return t;
994
1035
  }
995
- class m extends Error {
1036
+ class $ extends Error {
996
1037
  constructor(t) {
997
1038
  super(
998
1039
  `Wallet returned a PSBT for a different transaction: ${t}`
999
1040
  ), this.name = "PsbtSubstitutionError";
1000
1041
  }
1001
1042
  }
1002
- function we(e, t) {
1043
+ function ve(e, t) {
1003
1044
  try {
1004
- return V.fromHex(t);
1045
+ return H.fromHex(t);
1005
1046
  } catch (o) {
1006
1047
  const n = o instanceof Error ? o.message : String(o);
1007
1048
  throw new Error(`Failed to parse ${e} PSBT: ${n}`);
1008
1049
  }
1009
1050
  }
1010
- const Ut = 8;
1011
- function N(e) {
1012
- return `${e.toString("hex").slice(0, Ut)}…`;
1051
+ const Mt = 8;
1052
+ function B(e) {
1053
+ return `${e.toString("hex").slice(0, Mt)}…`;
1013
1054
  }
1014
- function ve(e) {
1055
+ function Ee(e) {
1015
1056
  const t = c.from(e).reverse();
1016
- return N(t);
1057
+ return B(t);
1017
1058
  }
1018
- function Jt(e) {
1019
- const t = we("requested", e.requestedPsbtHex), o = we("returned", e.returnedPsbtHex);
1059
+ function to(e) {
1060
+ const t = ve("requested", e.requestedPsbtHex), o = ve("returned", e.returnedPsbtHex);
1020
1061
  if (t.version !== o.version)
1021
- throw new m(
1062
+ throw new $(
1022
1063
  `tx version differs (requested=${t.version}, returned=${o.version})`
1023
1064
  );
1024
1065
  if (t.locktime !== o.locktime)
1025
- throw new m(
1066
+ throw new $(
1026
1067
  `tx locktime differs (requested=${t.locktime}, returned=${o.locktime})`
1027
1068
  );
1028
1069
  if (t.txInputs.length !== o.txInputs.length)
1029
- throw new m(
1070
+ throw new $(
1030
1071
  `input count differs (requested=${t.txInputs.length}, returned=${o.txInputs.length})`
1031
1072
  );
1032
1073
  if (t.txOutputs.length !== o.txOutputs.length)
1033
- throw new m(
1074
+ throw new $(
1034
1075
  `output count differs (requested=${t.txOutputs.length}, returned=${o.txOutputs.length})`
1035
1076
  );
1036
1077
  for (let n = 0; n < t.txInputs.length; n++) {
1037
1078
  const i = t.txInputs[n], s = o.txInputs[n];
1038
1079
  if (!i.hash.equals(s.hash))
1039
- throw new m(
1040
- `input ${n} prevout txid differs (requested=${ve(i.hash)}, returned=${ve(s.hash)})`
1080
+ throw new $(
1081
+ `input ${n} prevout txid differs (requested=${Ee(i.hash)}, returned=${Ee(s.hash)})`
1041
1082
  );
1042
1083
  if (i.index !== s.index)
1043
- throw new m(
1084
+ throw new $(
1044
1085
  `input ${n} prevout vout differs (requested=${i.index}, returned=${s.index})`
1045
1086
  );
1046
1087
  if (i.sequence !== s.sequence)
1047
- throw new m(
1088
+ throw new $(
1048
1089
  `input ${n} sequence differs (requested=${i.sequence}, returned=${s.sequence})`
1049
1090
  );
1050
1091
  }
1051
1092
  for (let n = 0; n < t.txOutputs.length; n++) {
1052
1093
  const i = t.txOutputs[n], s = o.txOutputs[n];
1053
1094
  if (!i.script.equals(s.script))
1054
- throw new m(
1055
- `output ${n} scriptPubKey differs (requested=${N(i.script)}, returned=${N(s.script)})`
1095
+ throw new $(
1096
+ `output ${n} scriptPubKey differs (requested=${B(i.script)}, returned=${B(s.script)})`
1056
1097
  );
1057
1098
  if (i.value !== s.value)
1058
- throw new m(
1099
+ throw new $(
1059
1100
  `output ${n} value differs (requested=${i.value}, returned=${s.value})`
1060
1101
  );
1061
1102
  }
1062
1103
  }
1063
- function eo(e) {
1104
+ function oo(e) {
1064
1105
  const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex: i } = e, s = f(o);
1065
- if (s.length !== F)
1106
+ if (s.length !== W)
1066
1107
  throw new Error(
1067
- `Schnorr signature for input ${i} must be ${F} hex chars (64 bytes), got ${s.length}.`
1108
+ `Schnorr signature for input ${i} must be ${W} hex chars (64 bytes), got ${s.length}.`
1068
1109
  );
1069
1110
  const r = f(n);
1070
- if (r.length !== ne)
1111
+ if (r.length !== ie)
1071
1112
  throw new Error(
1072
- `Signer x-only pubkey for input ${i} must be ${ne} hex chars (32 bytes), got ${r.length}.`
1113
+ `Signer x-only pubkey for input ${i} must be ${ie} hex chars (32 bytes), got ${r.length}.`
1073
1114
  );
1074
- const u = V.fromHex(t);
1115
+ const u = H.fromHex(t);
1075
1116
  if (i < 0 || i >= u.data.inputs.length)
1076
1117
  throw new Error(
1077
1118
  `Input index ${i} out of range (${u.data.inputs.length} inputs).`
1078
1119
  );
1079
- const h = [], a = [];
1120
+ const h = [], l = [];
1080
1121
  for (let g = 0; g < u.data.inputs.length; g++) {
1081
- const $ = u.data.inputs[g].witnessUtxo;
1082
- if (!$)
1122
+ const m = u.data.inputs[g].witnessUtxo;
1123
+ if (!m)
1083
1124
  throw new Error(
1084
1125
  `Cannot verify signature: input ${g} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
1085
1126
  );
1086
- h.push($.script), a.push($.value);
1127
+ h.push(m.script), l.push(m.value);
1087
1128
  }
1088
1129
  const d = u.data.inputs[i].tapLeafScript;
1089
1130
  if (!d || d.length !== 1)
1090
1131
  throw new Error(
1091
1132
  `Cannot verify signature: input ${i} of the requested PSBT must have exactly one tapLeafScript, got ${(d == null ? void 0 : d.length) ?? 0}.`
1092
1133
  );
1093
- const l = d[0];
1094
- if (l.leafVersion !== y)
1134
+ const a = d[0];
1135
+ if (a.leafVersion !== y)
1095
1136
  throw new Error(
1096
- `Cannot verify signature: input ${i} tapLeafScript has leaf version 0x${l.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
1137
+ `Cannot verify signature: input ${i} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
1097
1138
  );
1098
- const P = Ce(l.leafVersion, l.script), p = new b();
1139
+ const P = ke(a.leafVersion, a.script), p = new k();
1099
1140
  p.version = u.version, p.locktime = u.locktime;
1100
1141
  for (const g of u.txInputs)
1101
1142
  p.addInput(g.hash, g.index, g.sequence);
@@ -1104,37 +1145,37 @@ function eo(e) {
1104
1145
  const v = p.hashForWitnessV1(
1105
1146
  i,
1106
1147
  h,
1107
- a,
1108
- b.SIGHASH_DEFAULT,
1148
+ l,
1149
+ k.SIGHASH_DEFAULT,
1109
1150
  P
1110
1151
  );
1111
- if (!Se.verifySchnorr(
1152
+ if (!Ce.verifySchnorr(
1112
1153
  v,
1113
- x(r),
1114
- x(s)
1154
+ C(r),
1155
+ C(s)
1115
1156
  ))
1116
1157
  throw new Error(
1117
1158
  `Schnorr signature for input ${i} (signer ${r}) 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.`
1118
1159
  );
1119
1160
  }
1120
1161
  export {
1121
- O as H,
1122
- et as P,
1123
- Dt as a,
1124
- Qt as b,
1125
- Yt as c,
1126
- tt as d,
1127
- ot as e,
1128
- Zt as f,
1129
- jt as g,
1130
- m as h,
1131
- Jt as i,
1132
- eo as j,
1133
- st as k,
1134
- Qe as l,
1135
- Ce as m,
1136
- xe as n,
1137
- je as o,
1138
- Ge as p
1162
+ V as H,
1163
+ ot as P,
1164
+ Zt as a,
1165
+ jt as b,
1166
+ Qt as c,
1167
+ nt as d,
1168
+ rt as e,
1169
+ Jt as f,
1170
+ eo as g,
1171
+ $ as h,
1172
+ to as i,
1173
+ oo as j,
1174
+ ct as k,
1175
+ Ze as l,
1176
+ ke as m,
1177
+ be as n,
1178
+ et as o,
1179
+ ze as p
1139
1180
  };
1140
- //# sourceMappingURL=verifyScriptPathSchnorrSignature-D_epga4j.js.map
1181
+ //# sourceMappingURL=verifyScriptPathSchnorrSignature-CpjSTfMj.js.map