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