@babylonlabs-io/ts-sdk 0.52.0 → 0.55.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 (160) hide show
  1. package/dist/ApplicationRegistry.abi-CLaa6E99.cjs +2 -0
  2. package/dist/ApplicationRegistry.abi-CLaa6E99.cjs.map +1 -0
  3. package/dist/{ApplicationRegistry.abi-Dn2qk6JG.js → ApplicationRegistry.abi-w5prf7Ig.js} +14 -1
  4. package/dist/ApplicationRegistry.abi-w5prf7Ig.js.map +1 -0
  5. package/dist/PayoutManager-BJmPnyRP.js +260 -0
  6. package/dist/PayoutManager-BJmPnyRP.js.map +1 -0
  7. package/dist/PayoutManager-aqtsj60t.cjs +2 -0
  8. package/dist/PayoutManager-aqtsj60t.cjs.map +1 -0
  9. package/dist/{PeginManager-BGWNJYPk.js → PeginManager-D22MLWfM.js} +132 -144
  10. package/dist/PeginManager-D22MLWfM.js.map +1 -0
  11. package/dist/PeginManager-vUUfZCzj.cjs +2 -0
  12. package/dist/PeginManager-vUUfZCzj.cjs.map +1 -0
  13. package/dist/{buildAndBroadcastRefund-BAT5A6MP.js → buildAndBroadcastRefund-BiSO4zg2.js} +358 -360
  14. package/dist/buildAndBroadcastRefund-BiSO4zg2.js.map +1 -0
  15. package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs +2 -0
  16. package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs.map +1 -0
  17. package/dist/{challengeAssert-HNbugpqL.cjs → challengeAssert-DLQfNcfU.cjs} +2 -2
  18. package/dist/{challengeAssert-HNbugpqL.cjs.map → challengeAssert-DLQfNcfU.cjs.map} +1 -1
  19. package/dist/{challengeAssert-csvYXBJB.js → challengeAssert-DvdbpEDY.js} +2 -2
  20. package/dist/{challengeAssert-csvYXBJB.js.map → challengeAssert-DvdbpEDY.js.map} +1 -1
  21. package/dist/constants-BhclpREj.js +19 -0
  22. package/dist/constants-BhclpREj.js.map +1 -0
  23. package/dist/constants-CvbARMl-.cjs +2 -0
  24. package/dist/constants-CvbARMl-.cjs.map +1 -0
  25. package/dist/{fundPeginTransaction-96FxwYYJ.js → fundPeginTransaction-B2wyjqp0.js} +21 -22
  26. package/dist/fundPeginTransaction-B2wyjqp0.js.map +1 -0
  27. package/dist/fundPeginTransaction-BLD8FRL9.cjs +2 -0
  28. package/dist/fundPeginTransaction-BLD8FRL9.cjs.map +1 -0
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.js +192 -190
  31. package/dist/index.js.map +1 -1
  32. package/dist/{mempoolApi-Dc1KSVNI.js → mempoolApi-CB7bHuwi.js} +106 -101
  33. package/dist/mempoolApi-CB7bHuwi.js.map +1 -0
  34. package/dist/mempoolApi-DqJByvqR.cjs +2 -0
  35. package/dist/mempoolApi-DqJByvqR.cjs.map +1 -0
  36. package/dist/noPayout-CNMqNNpc.cjs +2 -0
  37. package/dist/noPayout-CNMqNNpc.cjs.map +1 -0
  38. package/dist/{noPayout-DVx3zxUz.js → noPayout-CfBg3HzC.js} +30 -30
  39. package/dist/noPayout-CfBg3HzC.js.map +1 -0
  40. package/dist/{peginInput-B5XDDHpy.js → peginInput-BKD_b3gq.js} +10 -11
  41. package/dist/peginInput-BKD_b3gq.js.map +1 -0
  42. package/dist/{peginInput-De0C6aSj.cjs → peginInput-CAiiDZeO.cjs} +2 -2
  43. package/dist/peginInput-CAiiDZeO.cjs.map +1 -0
  44. package/dist/primeVpAuth-CF4cH5_e.cjs +2 -0
  45. package/dist/primeVpAuth-CF4cH5_e.cjs.map +1 -0
  46. package/dist/{primeVpAuth-DxMuWQCi.js → primeVpAuth-l-5x_2UV.js} +91 -85
  47. package/dist/{primeVpAuth-yTddDmGy.cjs.map → primeVpAuth-l-5x_2UV.js.map} +1 -1
  48. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
  49. package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
  50. package/dist/tbv/core/clients/eth/types.d.ts +8 -0
  51. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  52. package/dist/tbv/core/clients/index.cjs +1 -1
  53. package/dist/tbv/core/clients/index.js +2 -2
  54. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +10 -0
  55. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
  56. package/dist/tbv/core/contracts/index.cjs +1 -1
  57. package/dist/tbv/core/contracts/index.js +1 -1
  58. package/dist/tbv/core/index.cjs +1 -1
  59. package/dist/tbv/core/index.js +190 -188
  60. package/dist/tbv/core/index.js.map +1 -1
  61. package/dist/tbv/core/managers/PayoutManager.d.ts +6 -0
  62. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  63. package/dist/tbv/core/managers/PeginManager.d.ts +10 -2
  64. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  65. package/dist/tbv/core/managers/index.cjs +1 -1
  66. package/dist/tbv/core/managers/index.js +2 -2
  67. package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts +10 -6
  68. package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts.map +1 -1
  69. package/dist/tbv/core/primitives/__tests__/vaultCoreVersion.test.d.ts +8 -0
  70. package/dist/tbv/core/primitives/__tests__/vaultCoreVersion.test.d.ts.map +1 -0
  71. package/dist/tbv/core/primitives/index.cjs +1 -1
  72. package/dist/tbv/core/primitives/index.d.ts +3 -3
  73. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  74. package/dist/tbv/core/primitives/index.js +40 -37
  75. package/dist/tbv/core/primitives/index.js.map +1 -1
  76. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +11 -0
  77. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -0
  78. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +11 -10
  79. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  80. package/dist/tbv/core/primitives/psbt/payout.d.ts +6 -0
  81. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  82. package/dist/tbv/core/primitives/psbt/pegin.d.ts +17 -2
  83. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  84. package/dist/tbv/core/primitives/psbt/peginInput.d.ts +6 -0
  85. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
  86. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  87. package/dist/tbv/core/primitives/scripts/payout.d.ts +6 -0
  88. package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
  89. package/dist/tbv/core/primitives/vaultCoreVersion.d.ts +26 -0
  90. package/dist/tbv/core/primitives/vaultCoreVersion.d.ts.map +1 -0
  91. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +7 -0
  92. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  93. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +6 -0
  94. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  95. package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts +8 -0
  96. package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts.map +1 -1
  97. package/dist/tbv/core/services/index.cjs +1 -1
  98. package/dist/tbv/core/services/index.js +2 -2
  99. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +6 -0
  100. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  101. package/dist/tbv/core/utils/fee/constants.d.ts +6 -14
  102. package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
  103. package/dist/tbv/core/utils/index.cjs +1 -1
  104. package/dist/tbv/core/utils/index.js +35 -36
  105. package/dist/tbv/index.cjs +1 -1
  106. package/dist/tbv/index.js +190 -188
  107. package/dist/tbv/index.js.map +1 -1
  108. package/dist/testing/MockBitcoinWallet.d.ts +1 -1
  109. package/dist/testing/MockBitcoinWallet.d.ts.map +1 -1
  110. package/dist/testing/index.cjs +1 -1
  111. package/dist/testing/index.cjs.map +1 -1
  112. package/dist/testing/index.js +3 -3
  113. package/dist/testing/index.js.map +1 -1
  114. package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs +2 -0
  115. package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs.map +1 -0
  116. package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js +658 -0
  117. package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js.map +1 -0
  118. package/dist/{waitForTransactionReceiptSmartAware-U706oKTc.cjs → waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs} +2 -2
  119. package/dist/{waitForTransactionReceiptSmartAware-U706oKTc.cjs.map → waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs.map} +1 -1
  120. package/dist/{waitForTransactionReceiptSmartAware-Ckg_oZAo.js → waitForTransactionReceiptSmartAware-lobLm0q0.js} +2 -2
  121. package/dist/{waitForTransactionReceiptSmartAware-Ckg_oZAo.js.map → waitForTransactionReceiptSmartAware-lobLm0q0.js.map} +1 -1
  122. package/package.json +2 -2
  123. package/dist/ApplicationRegistry.abi-BAPhJch3.cjs +0 -2
  124. package/dist/ApplicationRegistry.abi-BAPhJch3.cjs.map +0 -1
  125. package/dist/ApplicationRegistry.abi-Dn2qk6JG.js.map +0 -1
  126. package/dist/PayoutManager-BwrV3xFW.js +0 -241
  127. package/dist/PayoutManager-BwrV3xFW.js.map +0 -1
  128. package/dist/PayoutManager-CBfHfLfz.cjs +0 -2
  129. package/dist/PayoutManager-CBfHfLfz.cjs.map +0 -1
  130. package/dist/PeginManager-BGWNJYPk.js.map +0 -1
  131. package/dist/PeginManager-DDp-ZRIa.cjs +0 -2
  132. package/dist/PeginManager-DDp-ZRIa.cjs.map +0 -1
  133. package/dist/buildAndBroadcastRefund-3MLyCOtv.cjs +0 -2
  134. package/dist/buildAndBroadcastRefund-3MLyCOtv.cjs.map +0 -1
  135. package/dist/buildAndBroadcastRefund-BAT5A6MP.js.map +0 -1
  136. package/dist/constants-CSG2XeD8.cjs +0 -2
  137. package/dist/constants-CSG2XeD8.cjs.map +0 -1
  138. package/dist/constants-Cd_fN8VT.js +0 -12
  139. package/dist/constants-Cd_fN8VT.js.map +0 -1
  140. package/dist/fundPeginTransaction-96FxwYYJ.js.map +0 -1
  141. package/dist/fundPeginTransaction-DuMwnytD.cjs +0 -2
  142. package/dist/fundPeginTransaction-DuMwnytD.cjs.map +0 -1
  143. package/dist/mempoolApi-Dc1KSVNI.js.map +0 -1
  144. package/dist/mempoolApi-NMiYQAXI.cjs +0 -2
  145. package/dist/mempoolApi-NMiYQAXI.cjs.map +0 -1
  146. package/dist/noPayout-ChPNKTbm.cjs +0 -2
  147. package/dist/noPayout-ChPNKTbm.cjs.map +0 -1
  148. package/dist/noPayout-DVx3zxUz.js.map +0 -1
  149. package/dist/peginInput-B5XDDHpy.js.map +0 -1
  150. package/dist/peginInput-De0C6aSj.cjs.map +0 -1
  151. package/dist/primeVpAuth-DxMuWQCi.js.map +0 -1
  152. package/dist/primeVpAuth-yTddDmGy.cjs +0 -2
  153. package/dist/tbv/core/primitives/__tests__/txGraphVersion.test.d.ts +0 -7
  154. package/dist/tbv/core/primitives/__tests__/txGraphVersion.test.d.ts.map +0 -1
  155. package/dist/tbv/core/primitives/txGraphVersion.d.ts +0 -11
  156. package/dist/tbv/core/primitives/txGraphVersion.d.ts.map +0 -1
  157. package/dist/verifyScriptPathSchnorrSignature-BKECXOpa.js +0 -572
  158. package/dist/verifyScriptPathSchnorrSignature-BKECXOpa.js.map +0 -1
  159. package/dist/verifyScriptPathSchnorrSignature-CVPh04ZI.cjs +0 -2
  160. package/dist/verifyScriptPathSchnorrSignature-CVPh04ZI.cjs.map +0 -1
@@ -1,572 +0,0 @@
1
- import { computeMinClaimValue as Z, buildPeginTxFromPrePegin as j, createPrePeginTransaction as J, createPayoutConnector as ee, tapInternalPubkey as te } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
- import { c as B, d as ne } from "./fundPeginTransaction-96FxwYYJ.js";
3
- import { Buffer as c } from "buffer";
4
- import { Transaction as S, Psbt as T, crypto as re } from "bitcoinjs-lib";
5
- import { s as x, h as E, u as H, T as V, c as oe, d as ie, S as R, X as q } from "./bitcoin-B5aNKtsk.js";
6
- import { P as C, A as I, a as N, M as _, V as se, N as M } from "./constants-Cd_fN8VT.js";
7
- import * as ue from "@bitcoin-js/tiny-secp256k1-asmjs";
8
- const k = 1;
9
- async function ae(e, t) {
10
- const n = t.pegInAmounts.length;
11
- if (e.htlcValues.length !== n)
12
- throw new Error(
13
- `WASM Pre-PegIn returned ${e.htlcValues.length} HTLC value(s), expected ${n} (one per requested deposit).`
14
- );
15
- if (e.peginAmounts.length !== n || e.htlcScriptPubKeys.length !== n || e.htlcAddresses.length !== n)
16
- throw new Error(
17
- `WASM Pre-PegIn returned mismatched array lengths (htlcValues=${e.htlcValues.length}, peginAmounts=${e.peginAmounts.length}, htlcScriptPubKeys=${e.htlcScriptPubKeys.length}, htlcAddresses=${e.htlcAddresses.length}); expected ${n} each.`
18
- );
19
- if (e.depositorClaimValue <= 0n)
20
- throw new Error(
21
- `WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
22
- );
23
- const r = await Z(
24
- // Phase-1 pin: the builder constructs the v1 graph, so the cross-check
25
- // must price the same version's claim value.
26
- k,
27
- t.numLocalChallengers,
28
- t.universalChallengerPubkeys.length,
29
- t.councilQuorum,
30
- t.councilSize,
31
- t.feeRate
32
- );
33
- if (e.depositorClaimValue !== r)
34
- throw new Error(
35
- `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${r} (numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
36
- );
37
- const o = t.minPeginFeeRate * B;
38
- for (let i = 0; i < n; i++) {
39
- const u = t.pegInAmounts[i], s = e.peginAmounts[i], a = e.htlcValues[i];
40
- if (s !== u)
41
- throw new Error(
42
- `WASM Pre-PegIn peginAmount[${i}] ${s} does not match the requested amount ${u}; refusing to build a tx whose recorded amount differs from the depositor's request.`
43
- );
44
- if (s <= 0n)
45
- throw new Error(
46
- `WASM Pre-PegIn peginAmount[${i}] is non-positive (${s}); expected > 0.`
47
- );
48
- if (a <= 0n)
49
- throw new Error(
50
- `WASM Pre-PegIn htlcValue[${i}] is non-positive (${a}); expected > 0.`
51
- );
52
- const l = a - s - e.depositorClaimValue;
53
- if (l <= 0n)
54
- throw new Error(
55
- `WASM Pre-PegIn htlcValue[${i}] ${a} does not strictly cover peginAmount ${s} + depositorClaimValue ${e.depositorClaimValue} + a PegIn fee (implied fee ${l}).`
56
- );
57
- if (l > o)
58
- throw new Error(
59
- `WASM Pre-PegIn implied PegIn fee for HTLC[${i}] (${l} sat) exceeds the plausibility cap ${o} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${B} vbytes); htlcValue ${a} appears grossly inflated.`
60
- );
61
- }
62
- }
63
- function ce(e, t, n) {
64
- if (e.length < t.length)
65
- throw new Error(
66
- `Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
67
- );
68
- for (let r = 0; r < t.length; r++) {
69
- const o = BigInt(e[r].value);
70
- if (o !== t[r])
71
- throw new Error(
72
- `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.`
73
- );
74
- const i = e[r].script.toString("hex").toLowerCase(), u = n[r].toLowerCase();
75
- if (i !== u)
76
- throw new Error(
77
- `Encoded Pre-PegIn HTLC output[${r}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${u}.`
78
- );
79
- }
80
- }
81
- const K = 64, le = /^[0-9a-fA-F]+$/;
82
- async function Te(e) {
83
- const t = Q(e.authAnchorHash), n = await J({
84
- // Phase-1 pin: every deposit builds the v1 graph until fresh/resume
85
- // version resolution lands (fresh: activeVaultCoreVersion; resume: the
86
- // vault's stamped vaultCoreVersion).
87
- txGraphVersion: k,
88
- depositorPubkey: e.depositorPubkey,
89
- vaultProviderPubkey: e.vaultProviderPubkey,
90
- vaultKeeperPubkeys: e.vaultKeeperPubkeys,
91
- universalChallengerPubkeys: e.universalChallengerPubkeys,
92
- hashlocks: [...e.hashlocks],
93
- timelockRefund: e.timelockRefund,
94
- pegInAmounts: [...e.pegInAmounts],
95
- feeRate: e.feeRate,
96
- minPeginFeeRate: e.minPeginFeeRate,
97
- numLocalChallengers: e.numLocalChallengers,
98
- councilQuorum: e.councilQuorum,
99
- councilSize: e.councilSize,
100
- network: e.network,
101
- authAnchorHash: t
102
- });
103
- await ae(n, e);
104
- const r = ne(n.txHex);
105
- ce(
106
- r.outputs,
107
- n.htlcValues,
108
- n.htlcScriptPubKeys
109
- );
110
- const o = r.outputs.reduce(
111
- (u, s) => u + BigInt(s.value),
112
- 0n
113
- ), i = t !== void 0 ? n.htlcValues.length : null;
114
- return {
115
- psbtHex: n.txHex,
116
- totalOutputValue: o,
117
- htlcValues: n.htlcValues,
118
- htlcScriptPubKeys: n.htlcScriptPubKeys,
119
- htlcAddresses: n.htlcAddresses,
120
- peginAmounts: n.peginAmounts,
121
- depositorClaimValue: n.depositorClaimValue,
122
- authAnchorVout: i
123
- };
124
- }
125
- function Q(e) {
126
- if (e === void 0) return;
127
- const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
128
- if (t.length !== K || !le.test(t))
129
- throw new Error(
130
- `authAnchorHash must be 32-byte hex (${K} chars, no 0x prefix); got length ${t.length}`
131
- );
132
- return t.toLowerCase();
133
- }
134
- async function ke(e) {
135
- const t = await j(
136
- {
137
- txGraphVersion: k,
138
- depositorPubkey: e.prePeginParams.depositorPubkey,
139
- vaultProviderPubkey: e.prePeginParams.vaultProviderPubkey,
140
- vaultKeeperPubkeys: e.prePeginParams.vaultKeeperPubkeys,
141
- universalChallengerPubkeys: e.prePeginParams.universalChallengerPubkeys,
142
- hashlocks: [...e.prePeginParams.hashlocks],
143
- timelockRefund: e.prePeginParams.timelockRefund,
144
- pegInAmounts: [...e.prePeginParams.pegInAmounts],
145
- feeRate: e.prePeginParams.feeRate,
146
- minPeginFeeRate: e.prePeginParams.minPeginFeeRate,
147
- numLocalChallengers: e.prePeginParams.numLocalChallengers,
148
- councilQuorum: e.prePeginParams.councilQuorum,
149
- councilSize: e.prePeginParams.councilSize,
150
- network: e.prePeginParams.network,
151
- authAnchorHash: Q(
152
- e.prePeginParams.authAnchorHash
153
- )
154
- },
155
- e.timelockPegin,
156
- e.fundedPrePeginTxHex,
157
- e.htlcVout
158
- );
159
- return {
160
- txHex: t.txHex,
161
- txid: t.txid,
162
- vaultScriptPubKey: t.vaultScriptPubKey,
163
- vaultValue: t.vaultValue
164
- };
165
- }
166
- async function he(e) {
167
- const t = await ee(
168
- {
169
- txGraphVersion: k,
170
- depositor: e.depositor,
171
- vaultProvider: e.vaultProvider,
172
- vaultKeepers: e.vaultKeepers,
173
- universalChallengers: e.universalChallengers,
174
- timelockPegin: e.timelockPegin
175
- },
176
- e.network
177
- );
178
- return {
179
- payoutScript: t.payoutScript,
180
- taprootScriptHash: t.taprootScriptHash,
181
- scriptPubKey: t.scriptPubKey,
182
- address: t.address,
183
- payoutControlBlock: t.payoutControlBlock
184
- };
185
- }
186
- const F = 3, X = 10, W = 100;
187
- async function Ce(e) {
188
- const t = x(e.payoutTxHex), n = x(e.peginTxHex), r = x(e.assertTxHex), o = await he({
189
- depositor: e.depositorBtcPubkey,
190
- vaultProvider: e.vaultProviderBtcPubkey,
191
- vaultKeepers: e.vaultKeeperBtcPubkeys,
192
- universalChallengers: e.universalChallengerBtcPubkeys,
193
- timelockPegin: e.timelockPegin,
194
- network: e.network
195
- }), i = E(o.payoutScript), u = E(o.payoutControlBlock), s = S.fromHex(t), a = S.fromHex(n), l = S.fromHex(r), p = new T();
196
- if (p.setVersion(s.version), p.setLocktime(s.locktime), s.ins.length !== 2)
197
- throw new Error(
198
- `Payout transaction must have exactly 2 inputs, got ${s.ins.length}`
199
- );
200
- const f = s.ins[0], P = s.ins[1], h = H(
201
- new Uint8Array(f.hash).slice().reverse()
202
- ), w = a.getId();
203
- if (h !== w || f.index !== C)
204
- throw new Error(
205
- `Input 0 must spend PegIn:${C}. Expected ${w}:${C}, got ${h}:${f.index}`
206
- );
207
- const $ = H(
208
- new Uint8Array(P.hash).slice().reverse()
209
- ), d = l.getId();
210
- if ($ !== d || P.index !== I)
211
- throw new Error(
212
- `Input 1 must spend Assert:${I}. Expected ${d}:${I}, got ${$}:${P.index}`
213
- );
214
- const g = a.outs[f.index];
215
- if (!g)
216
- throw new Error(
217
- `Previous output not found for input 0 (txid: ${h}, index: ${f.index})`
218
- );
219
- const y = l.outs[P.index];
220
- if (!y)
221
- throw new Error(
222
- `Previous output not found for input 1 (txid: ${$}, index: ${P.index})`
223
- );
224
- de({
225
- payoutTx: s,
226
- peginValueSats: g.value,
227
- claimerBtcPubkey: e.claimerBtcPubkey,
228
- vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
229
- depositorBtcPubkey: e.depositorBtcPubkey,
230
- vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys,
231
- registeredPayoutScriptPubKey: e.registeredPayoutScriptPubKey,
232
- commissionBps: e.commissionBps
233
- });
234
- const v = g.value + y.value;
235
- let b = 0;
236
- for (const A of s.outs) b += A.value;
237
- if (b > v)
238
- throw new Error(
239
- `Payout outputs (${b} sats) exceed inputs (${v} sats); invalid transaction.`
240
- );
241
- const U = v - b, L = Math.floor(
242
- v * X / W
243
- );
244
- if (U > L)
245
- throw new Error(
246
- `Payout implicit fee ${U} sats exceeds the safety cap of ${L} sats (${X}/${W} of inputs=${v}); refusing to sign payout.`
247
- );
248
- p.addInput({
249
- hash: f.hash,
250
- index: f.index,
251
- sequence: f.sequence,
252
- witnessUtxo: {
253
- script: g.script,
254
- value: g.value
255
- },
256
- tapLeafScript: [
257
- {
258
- leafVersion: V,
259
- script: c.from(i),
260
- controlBlock: c.from(u)
261
- }
262
- ],
263
- tapInternalKey: c.from(te)
264
- // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
265
- }), p.addInput({
266
- hash: P.hash,
267
- index: P.index,
268
- sequence: P.sequence,
269
- witnessUtxo: {
270
- script: y.script,
271
- value: y.value
272
- }
273
- // No tapLeafScript - depositor doesn't sign this input
274
- });
275
- for (const A of s.outs)
276
- p.addOutput({
277
- script: A.script,
278
- value: A.value
279
- });
280
- return {
281
- psbtHex: p.toHex()
282
- };
283
- }
284
- function de(e) {
285
- const {
286
- payoutTx: t,
287
- peginValueSats: n,
288
- claimerBtcPubkey: r,
289
- vaultProviderBtcPubkey: o,
290
- depositorBtcPubkey: i,
291
- vaultKeeperBtcPubkeys: u,
292
- registeredPayoutScriptPubKey: s,
293
- commissionBps: a
294
- } = e;
295
- if (!oe(s))
296
- throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
297
- const l = x(r).toLowerCase(), p = x(o).toLowerCase(), f = x(i).toLowerCase(), P = u.map(
298
- (y) => x(y).toLowerCase()
299
- );
300
- let h, w, $;
301
- if (l === p)
302
- h = "vp-claimer", w = se, $ = x(s);
303
- else if (l === f)
304
- h = "depositor-as-claimer", w = M, $ = x(s);
305
- else if (P.includes(l))
306
- h = "vk-claimer", w = M, $ = x(ie(l));
307
- else
308
- throw new Error(
309
- `Unknown claimer pubkey ${l}: not VP, depositor, or a registered vault keeper`
310
- );
311
- if (t.outs.length !== w)
312
- throw new Error(
313
- `Payout transaction has ${t.outs.length} output(s), expected exactly ${w} for role ${h}.`
314
- );
315
- const d = c.from($, "hex");
316
- if (!t.outs[0].script.equals(d))
317
- throw new Error(
318
- `Payout transaction output 0 does not pay the expected scriptPubKey for role ${h}`
319
- );
320
- const g = w - 1;
321
- if (t.outs[g].value !== N)
322
- throw new Error(
323
- `Payout CPFP anchor (out ${g}) value ${t.outs[g].value} sats must equal ${N} sats`
324
- );
325
- if (h === "vp-claimer") {
326
- if (!Number.isInteger(a) || a < 0 || a >= _)
327
- throw new Error(
328
- `commissionBps must be an integer in [0, ${_}), got ${a}`
329
- );
330
- const y = Math.floor(
331
- n * a / _
332
- );
333
- if (t.outs[1].value > y)
334
- throw new Error(
335
- `Payout VP commission (out 1) value ${t.outs[1].value} sats exceeds cap ${y} sats (${a} bps of peginValue=${n})`
336
- );
337
- }
338
- }
339
- function Ie(e, t, n = 0) {
340
- const r = T.fromHex(e);
341
- if (n >= r.data.inputs.length)
342
- throw new Error(
343
- `Input index ${n} out of range (${r.data.inputs.length} inputs)`
344
- );
345
- const o = r.data.inputs[n];
346
- if (o.tapScriptSig && o.tapScriptSig.length > 0) {
347
- const i = E(t);
348
- for (const u of o.tapScriptSig)
349
- if (u.pubkey.equals(c.from(i)))
350
- return z(u.signature, n);
351
- throw new Error(
352
- `No signature found for depositor pubkey: ${t} at input ${n}`
353
- );
354
- }
355
- if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
356
- const i = pe(o.finalScriptWitness);
357
- if (i.length !== F)
358
- throw new Error(
359
- `Unexpected finalized witness stack size at input ${n}: expected ${F} items (signature, script, controlBlock), got ${i.length}`
360
- );
361
- return z(i[0], n);
362
- }
363
- throw new Error(
364
- `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
365
- );
366
- }
367
- function z(e, t) {
368
- if (e.length === 64)
369
- return H(new Uint8Array(e));
370
- throw e.length === 65 ? new Error(
371
- `Unexpected sighash byte 0x${e[64].toString(16).padStart(2, "0")} at input ${t}. Expected implicit SIGHASH_DEFAULT as a 64-byte signature.`
372
- ) : new Error(
373
- `Unexpected signature length at input ${t}: ${e.length}`
374
- );
375
- }
376
- function pe(e) {
377
- const t = [];
378
- let n = 0;
379
- const r = (u) => {
380
- if (n + u > e.length)
381
- throw new Error(
382
- `Malformed witness data: need ${u} byte(s) at offset ${n}, only ${e.length - n} remaining`
383
- );
384
- }, o = () => {
385
- r(1);
386
- const u = e[n++];
387
- if (u < 253) return u;
388
- if (u === 253) {
389
- r(2);
390
- const s = (e[n] | e[n + 1] << 8) >>> 0;
391
- return n += 2, s;
392
- }
393
- if (u === 254) {
394
- r(4);
395
- const s = (e[n] | e[n + 1] << 8 | e[n + 2] << 16 | e[n + 3] << 24) >>> 0;
396
- return n += 4, s;
397
- }
398
- throw new Error(
399
- `Malformed witness data: 8-byte varint (0xff) not supported at offset ${n - 1}`
400
- );
401
- }, i = o();
402
- for (let u = 0; u < i; u++) {
403
- const s = o();
404
- r(s), t.push(c.from(e.subarray(n, n + s))), n += s;
405
- }
406
- if (n !== e.length)
407
- throw new Error(
408
- `Malformed witness data: ${e.length - n} trailing byte(s) after parsing ${i} item(s)`
409
- );
410
- return t;
411
- }
412
- class m extends Error {
413
- constructor(t) {
414
- super(
415
- `Wallet returned a PSBT for a different transaction: ${t}`
416
- ), this.name = "PsbtSubstitutionError";
417
- }
418
- }
419
- function G(e, t) {
420
- try {
421
- return T.fromHex(t);
422
- } catch (n) {
423
- const r = n instanceof Error ? n.message : String(n);
424
- throw new Error(`Failed to parse ${e} PSBT: ${r}`);
425
- }
426
- }
427
- const fe = 8;
428
- function O(e) {
429
- return `${e.toString("hex").slice(0, fe)}…`;
430
- }
431
- function Y(e) {
432
- const t = c.from(e).reverse();
433
- return O(t);
434
- }
435
- function _e(e) {
436
- const t = G("requested", e.requestedPsbtHex), n = G("returned", e.returnedPsbtHex);
437
- if (t.version !== n.version)
438
- throw new m(
439
- `tx version differs (requested=${t.version}, returned=${n.version})`
440
- );
441
- if (t.locktime !== n.locktime)
442
- throw new m(
443
- `tx locktime differs (requested=${t.locktime}, returned=${n.locktime})`
444
- );
445
- if (t.txInputs.length !== n.txInputs.length)
446
- throw new m(
447
- `input count differs (requested=${t.txInputs.length}, returned=${n.txInputs.length})`
448
- );
449
- if (t.txOutputs.length !== n.txOutputs.length)
450
- throw new m(
451
- `output count differs (requested=${t.txOutputs.length}, returned=${n.txOutputs.length})`
452
- );
453
- for (let r = 0; r < t.txInputs.length; r++) {
454
- const o = t.txInputs[r], i = n.txInputs[r];
455
- if (!o.hash.equals(i.hash))
456
- throw new m(
457
- `input ${r} prevout txid differs (requested=${Y(o.hash)}, returned=${Y(i.hash)})`
458
- );
459
- if (o.index !== i.index)
460
- throw new m(
461
- `input ${r} prevout vout differs (requested=${o.index}, returned=${i.index})`
462
- );
463
- if (o.sequence !== i.sequence)
464
- throw new m(
465
- `input ${r} sequence differs (requested=${o.sequence}, returned=${i.sequence})`
466
- );
467
- }
468
- for (let r = 0; r < t.txOutputs.length; r++) {
469
- const o = t.txOutputs[r], i = n.txOutputs[r];
470
- if (!o.script.equals(i.script))
471
- throw new m(
472
- `output ${r} scriptPubKey differs (requested=${O(o.script)}, returned=${O(i.script)})`
473
- );
474
- if (o.value !== i.value)
475
- throw new m(
476
- `output ${r} value differs (requested=${o.value}, returned=${i.value})`
477
- );
478
- }
479
- }
480
- const D = 253, ge = 254, Pe = 65535, xe = 4294967295;
481
- function we(e) {
482
- if (e < D)
483
- return c.from([e]);
484
- if (e <= Pe) {
485
- const t = c.alloc(2);
486
- return t.writeUInt16LE(e), c.concat([c.from([D]), t]);
487
- }
488
- if (e <= xe) {
489
- const t = c.alloc(4);
490
- return t.writeUInt32LE(e), c.concat([c.from([ge]), t]);
491
- }
492
- throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
493
- }
494
- const $e = "TapLeaf";
495
- function ye(e, t) {
496
- const n = c.concat([
497
- c.from([e]),
498
- we(t.length),
499
- c.from(t)
500
- ]);
501
- return re.taggedHash($e, n);
502
- }
503
- function He(e) {
504
- const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: r, inputIndex: o } = e, i = x(n);
505
- if (i.length !== R)
506
- throw new Error(
507
- `Schnorr signature for input ${o} must be ${R} hex chars (64 bytes), got ${i.length}.`
508
- );
509
- const u = x(r);
510
- if (u.length !== q)
511
- throw new Error(
512
- `Signer x-only pubkey for input ${o} must be ${q} hex chars (32 bytes), got ${u.length}.`
513
- );
514
- const s = T.fromHex(t);
515
- if (o < 0 || o >= s.data.inputs.length)
516
- throw new Error(
517
- `Input index ${o} out of range (${s.data.inputs.length} inputs).`
518
- );
519
- const a = [], l = [];
520
- for (let d = 0; d < s.data.inputs.length; d++) {
521
- const g = s.data.inputs[d].witnessUtxo;
522
- if (!g)
523
- throw new Error(
524
- `Cannot verify signature: input ${d} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
525
- );
526
- a.push(g.script), l.push(g.value);
527
- }
528
- const p = s.data.inputs[o].tapLeafScript;
529
- if (!p || p.length !== 1)
530
- throw new Error(
531
- `Cannot verify signature: input ${o} of the requested PSBT must have exactly one tapLeafScript, got ${(p == null ? void 0 : p.length) ?? 0}.`
532
- );
533
- const f = p[0];
534
- if (f.leafVersion !== V)
535
- throw new Error(
536
- `Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${f.leafVersion.toString(16)}, expected 0x${V.toString(16)}.`
537
- );
538
- const P = ye(f.leafVersion, f.script), h = new S();
539
- h.version = s.version, h.locktime = s.locktime;
540
- for (const d of s.txInputs)
541
- h.addInput(d.hash, d.index, d.sequence);
542
- for (const d of s.txOutputs)
543
- h.addOutput(d.script, d.value);
544
- const w = h.hashForWitnessV1(
545
- o,
546
- a,
547
- l,
548
- S.SIGHASH_DEFAULT,
549
- P
550
- );
551
- if (!ue.verifySchnorr(
552
- w,
553
- E(u),
554
- E(i)
555
- ))
556
- throw new Error(
557
- `Schnorr signature for input ${o} (signer ${u}) 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.`
558
- );
559
- }
560
- export {
561
- m as P,
562
- k as T,
563
- Te as a,
564
- ke as b,
565
- Ce as c,
566
- _e as d,
567
- Ie as e,
568
- He as f,
569
- he as g,
570
- Q as n
571
- };
572
- //# sourceMappingURL=verifyScriptPathSchnorrSignature-BKECXOpa.js.map