@babylonlabs-io/ts-sdk 5.1.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PayoutManager-BHeiLQ1j.js → PayoutManager-3-MzBVLj.js} +2 -2
- package/dist/{PayoutManager-BHeiLQ1j.js.map → PayoutManager-3-MzBVLj.js.map} +1 -1
- package/dist/{PayoutManager-B5nR0x1t.cjs → PayoutManager-PQqeqX41.cjs} +2 -2
- package/dist/{PayoutManager-B5nR0x1t.cjs.map → PayoutManager-PQqeqX41.cjs.map} +1 -1
- package/dist/{PeginManager-6ghglb4r.cjs → PeginManager-D_ZUfbIy.cjs} +2 -2
- package/dist/{PeginManager-6ghglb4r.cjs.map → PeginManager-D_ZUfbIy.cjs.map} +1 -1
- package/dist/{PeginManager-CXNqbgA4.js → PeginManager-m3IlM4wS.js} +4 -4
- package/dist/{PeginManager-CXNqbgA4.js.map → PeginManager-m3IlM4wS.js.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs → buildAndBroadcastReclaim-CMjlyooo.cjs} +2 -2
- package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs.map → buildAndBroadcastReclaim-CMjlyooo.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-Acz637Vf.js → buildAndBroadcastReclaim-D8l-QJWo.js} +793 -772
- package/dist/{buildAndBroadcastReclaim-Acz637Vf.js.map → buildAndBroadcastReclaim-D8l-QJWo.js.map} +1 -1
- package/dist/{challengeAssert-CuX_8Twt.cjs → challengeAssert-DlzX_kjF.cjs} +2 -2
- package/dist/{challengeAssert-CuX_8Twt.cjs.map → challengeAssert-DlzX_kjF.cjs.map} +1 -1
- package/dist/{challengeAssert-D_lRvsO0.js → challengeAssert-hpOHGPXX.js} +2 -2
- package/dist/{challengeAssert-D_lRvsO0.js.map → challengeAssert-hpOHGPXX.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +312 -309
- package/dist/index.js.map +1 -1
- package/dist/peginState-B4t_PDgj.cjs.map +1 -1
- package/dist/peginState-CXdbSit3.js.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +306 -303
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +5 -0
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +31 -29
- package/dist/tbv/core/primitives/index.js.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/signetPeginHashlockSpend.fixture.d.ts +19 -0
- package/dist/tbv/core/primitives/psbt/__tests__/signetPeginHashlockSpend.fixture.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/verifyPeginHashlockSpend.test.d.ts +9 -0
- package/dist/tbv/core/primitives/psbt/__tests__/verifyPeginHashlockSpend.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/verifyPeginHashlockSpend.d.ts +73 -0
- package/dist/tbv/core/primitives/psbt/verifyPeginHashlockSpend.d.ts.map +1 -0
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts +6 -0
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
- package/dist/tbv/core/recovery/toRefundInputs.d.ts +0 -2
- package/dist/tbv/core/recovery/toRefundInputs.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +16 -5
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +74 -73
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +6 -2
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/errors.d.ts +15 -0
- package/dist/tbv/core/services/refund/errors.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/index.d.ts +1 -1
- package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +306 -303
- package/dist/tbv/index.js.map +1 -1
- package/dist/{toRefundInputs-DwXpKQxN.js → toRefundInputs-D5tx3eeA.js} +152 -152
- package/dist/{toRefundInputs-DwXpKQxN.js.map → toRefundInputs-D5tx3eeA.js.map} +1 -1
- package/dist/{toRefundInputs-BzyN0zvj.cjs → toRefundInputs-Df6eRITl.cjs} +2 -2
- package/dist/{toRefundInputs-BzyN0zvj.cjs.map → toRefundInputs-Df6eRITl.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-BVrAmVL3.cjs → verifyKeyPathSchnorrSignature-B7Za6aa1.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-BVrAmVL3.cjs.map → verifyKeyPathSchnorrSignature-B7Za6aa1.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-CIE3jlVt.js → verifyKeyPathSchnorrSignature-dw7xhm5Y.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-CIE3jlVt.js.map → verifyKeyPathSchnorrSignature-dw7xhm5Y.js.map} +1 -1
- package/dist/verifyPeginHashlockSpend-CdTFR2K6.js +167 -0
- package/dist/verifyPeginHashlockSpend-CdTFR2K6.js.map +1 -0
- package/dist/verifyPeginHashlockSpend-CisfqMuT.cjs +2 -0
- package/dist/verifyPeginHashlockSpend-CisfqMuT.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-DLNGgm4j.js → verifyScriptPathSchnorrSignature-BVGPEZXW.js} +9 -8
- package/dist/{verifyScriptPathSchnorrSignature-DLNGgm4j.js.map → verifyScriptPathSchnorrSignature-BVGPEZXW.js.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-BHskbJJx.cjs → verifyScriptPathSchnorrSignature-p3sVoWQi.cjs} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-BHskbJJx.cjs.map → verifyScriptPathSchnorrSignature-p3sVoWQi.cjs.map} +1 -1
- package/package.json +1 -1
package/dist/tbv/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -10,12 +10,12 @@ import { getUtxoInfo as de } from "./tbv/core/clients/mempool/index.js";
|
|
|
10
10
|
import { M as D } from "./validation-OSC0xTHB.js";
|
|
11
11
|
import { keccak256 as J, toHex as me, encodeAbiParameters as pe, isAddress as ge, zeroAddress as fe } from "viem";
|
|
12
12
|
import { s as Pe } from "./sha2-YqVHJiFj.js";
|
|
13
|
-
import { d as _ } from "./PayoutManager-
|
|
14
|
-
import { b as ve, a as be } from "./PeginManager-
|
|
13
|
+
import { d as _ } from "./PayoutManager-3-MzBVLj.js";
|
|
14
|
+
import { b as ve, a as be } from "./PeginManager-m3IlM4wS.js";
|
|
15
15
|
import { computeMinClaimValue as Y, computeMinPeginFee as Z, peginP2aAnchorOutput as ee, getPrePeginHtlcConnectorInfo as we, expandAuthAnchor as ye } from "./tbv/core/wasm/index.js";
|
|
16
|
-
import { d as
|
|
17
|
-
import { p as
|
|
18
|
-
import {
|
|
16
|
+
import { d as xe } from "./deriveVaultRoot-BcvmER1E.js";
|
|
17
|
+
import { p as Ce } from "./parseFundingOutpoints-GSM-IaaK.js";
|
|
18
|
+
import { p as Ee, H as U } from "./verifyScriptPathSchnorrSignature-BVGPEZXW.js";
|
|
19
19
|
import { c as j } from "./fundPeginTransaction-CwhRbCQC.js";
|
|
20
20
|
const Re = [
|
|
21
21
|
"vaultCoreVersion",
|
|
@@ -29,7 +29,7 @@ const Re = [
|
|
|
29
29
|
function Ve(e, t) {
|
|
30
30
|
const o = t.depositor.toLowerCase(), r = S(t).toLowerCase();
|
|
31
31
|
return e.filter(
|
|
32
|
-
(
|
|
32
|
+
(s) => s.vaultId !== t.vaultId && s.depositor.toLowerCase() === o && S(s).toLowerCase() === r
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
function $e(e, t) {
|
|
@@ -57,7 +57,7 @@ function Ae(e) {
|
|
|
57
57
|
return t.forEach((o, r) => {
|
|
58
58
|
if (o.vault.protocol.htlcVout !== r)
|
|
59
59
|
throw new Error(
|
|
60
|
-
`Sibling discovery produced a non-contiguous HTLC vector (${t.map((
|
|
60
|
+
`Sibling discovery produced a non-contiguous HTLC vector (${t.map((s) => s.vault.protocol.htlcVout).join(", ")}).`
|
|
61
61
|
);
|
|
62
62
|
}), t.map((o) => ({
|
|
63
63
|
hashlock: o.vault.protocol.hashlock,
|
|
@@ -79,27 +79,27 @@ function dt(e) {
|
|
|
79
79
|
return t.name === te && t.reason === "device-envelope";
|
|
80
80
|
}
|
|
81
81
|
async function Be(e, t) {
|
|
82
|
-
const o = M.fromHex(f(e)),
|
|
82
|
+
const o = M.fromHex(f(e)), s = (await Promise.all(
|
|
83
83
|
o.ins.map(
|
|
84
|
-
(
|
|
84
|
+
(c) => (
|
|
85
85
|
// Bitcoin stores the prev-txid in reverse (internal) byte order.
|
|
86
86
|
de(
|
|
87
|
-
he.from(
|
|
88
|
-
|
|
87
|
+
he.from(c.hash).reverse().toString("hex"),
|
|
88
|
+
c.index,
|
|
89
89
|
t
|
|
90
90
|
)
|
|
91
91
|
)
|
|
92
92
|
)
|
|
93
|
-
)).reduce((
|
|
94
|
-
if (
|
|
93
|
+
)).reduce((c, n) => c + BigInt(n.value), 0n), i = o.outs.reduce((c, n) => c + BigInt(n.value), 0n), a = s - i;
|
|
94
|
+
if (a <= 0n)
|
|
95
95
|
throw new Error(
|
|
96
|
-
`The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${
|
|
96
|
+
`The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${a} sats).`
|
|
97
97
|
);
|
|
98
|
-
if (
|
|
98
|
+
if (a > D)
|
|
99
99
|
throw new Error(
|
|
100
|
-
`The funded Pre-PegIn transaction's computed fee (${
|
|
100
|
+
`The funded Pre-PegIn transaction's computed fee (${a} sats) exceeds the maximum reasonable fee (${D} sats); the mempool API may have returned manipulated prevout data.`
|
|
101
101
|
);
|
|
102
|
-
return
|
|
102
|
+
return a;
|
|
103
103
|
}
|
|
104
104
|
async function oe(e) {
|
|
105
105
|
const t = e.siblings.length;
|
|
@@ -107,10 +107,10 @@ async function oe(e) {
|
|
|
107
107
|
throw new Error(
|
|
108
108
|
"rebuildDepositTermsCore: at least one sibling is required"
|
|
109
109
|
);
|
|
110
|
-
for (const [m,
|
|
111
|
-
if (
|
|
110
|
+
for (const [m, h] of e.siblings.entries())
|
|
111
|
+
if (h.amount <= 0n)
|
|
112
112
|
throw new Error(
|
|
113
|
-
`rebuildDepositTermsCore: sibling[${m}] has non-positive on-chain pegin amount ${
|
|
113
|
+
`rebuildDepositTermsCore: sibling[${m}] has non-positive on-chain pegin amount ${h.amount}; the chain-read vault record is invalid. Resume refused.`
|
|
114
114
|
);
|
|
115
115
|
if (e.prepeginMaxFee <= 0n)
|
|
116
116
|
throw new Error(
|
|
@@ -123,51 +123,51 @@ async function oe(e) {
|
|
|
123
123
|
throw new Error(
|
|
124
124
|
`Funded Pre-PegIn tx hashes to ${r}, expected ${o} (on-chain prepeginTxid). Resume refused.`
|
|
125
125
|
);
|
|
126
|
-
const
|
|
126
|
+
const s = _(
|
|
127
127
|
f(e.fundedPrePeginTxHex)
|
|
128
128
|
);
|
|
129
|
-
if (
|
|
129
|
+
if (s === void 0)
|
|
130
130
|
throw new Error(
|
|
131
131
|
"Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN commitment — it either predates auth anchoring or is malformed. The intent resume path requires the anchor to prove sibling completeness. Resume refused."
|
|
132
132
|
);
|
|
133
|
-
if (
|
|
133
|
+
if (s.vout !== t)
|
|
134
134
|
throw new Error(
|
|
135
|
-
`Auth-anchor OP_RETURN at vout ${
|
|
135
|
+
`Auth-anchor OP_RETURN at vout ${s.vout} does not match the discovered sibling count ${t}; the discovered sibling set does not cover this transaction's HTLC outputs (a lagging index can cause this — retry later). Resume refused.`
|
|
136
136
|
);
|
|
137
|
-
const
|
|
137
|
+
const i = e.vaultKeeperBtcPubkeys.length, a = e.universalChallengerBtcPubkeys.length, c = await Y(
|
|
138
138
|
e.vaultCoreVersion,
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
i,
|
|
140
|
+
a,
|
|
141
141
|
e.councilQuorum,
|
|
142
142
|
e.councilSize,
|
|
143
143
|
e.protocolFeeRate
|
|
144
|
-
),
|
|
144
|
+
), n = await Z(
|
|
145
145
|
e.vaultCoreVersion,
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
i,
|
|
147
|
+
a,
|
|
148
148
|
e.minPeginFeeRate
|
|
149
|
-
), { value:
|
|
149
|
+
), { value: d } = await ee(
|
|
150
150
|
e.vaultCoreVersion
|
|
151
151
|
);
|
|
152
|
-
if (
|
|
152
|
+
if (c <= 0n)
|
|
153
153
|
throw new Error(
|
|
154
|
-
`WASM returned non-positive depositorClaimValue ${
|
|
154
|
+
`WASM returned non-positive depositorClaimValue ${c}; expected > 0. Resume refused.`
|
|
155
155
|
);
|
|
156
|
-
if (
|
|
156
|
+
if (n <= 0n)
|
|
157
157
|
throw new Error(
|
|
158
|
-
`WASM returned non-positive peginMaxFee ${
|
|
158
|
+
`WASM returned non-positive peginMaxFee ${n}; expected > 0. Resume refused.`
|
|
159
159
|
);
|
|
160
|
-
if (
|
|
160
|
+
if (d < 0n)
|
|
161
161
|
throw new Error(
|
|
162
|
-
`WASM returned negative P2A anchor value ${
|
|
162
|
+
`WASM returned negative P2A anchor value ${d}. Resume refused.`
|
|
163
163
|
);
|
|
164
|
-
const u =
|
|
165
|
-
if (u <= 0n || u >
|
|
164
|
+
const u = n + d, l = e.minPeginFeeRate * j;
|
|
165
|
+
if (u <= 0n || u > l)
|
|
166
166
|
throw new Error(
|
|
167
|
-
`WASM implied PegIn reserve ${u} sat is outside (0, ${
|
|
167
|
+
`WASM implied PegIn reserve ${u} sat is outside (0, ${l}] (minPeginFeeRate=${e.minPeginFeeRate} × ${j} vbytes). Resume refused.`
|
|
168
168
|
);
|
|
169
169
|
const w = e.siblings.map(
|
|
170
|
-
(m) => m.amount +
|
|
170
|
+
(m) => m.amount + c + n + d
|
|
171
171
|
), y = await Promise.all(
|
|
172
172
|
e.siblings.map(async (m) => (await we({
|
|
173
173
|
txGraphVersion: e.vaultCoreVersion,
|
|
@@ -179,11 +179,11 @@ async function oe(e) {
|
|
|
179
179
|
timelockRefund: e.timelockRefund,
|
|
180
180
|
network: e.network
|
|
181
181
|
})).scriptPubKey)
|
|
182
|
-
),
|
|
182
|
+
), x = M.fromHex(
|
|
183
183
|
f(e.fundedPrePeginTxHex)
|
|
184
184
|
).outs.map((m) => ({ value: m.value, script: m.script }));
|
|
185
185
|
return Ee(
|
|
186
|
-
|
|
186
|
+
x,
|
|
187
187
|
w,
|
|
188
188
|
y
|
|
189
189
|
), ve({
|
|
@@ -199,8 +199,8 @@ async function oe(e) {
|
|
|
199
199
|
universalChallengerBtcPubkeys: e.universalChallengerBtcPubkeys,
|
|
200
200
|
maxAcceptableCommissionBps: e.maxAcceptableCommissionBps,
|
|
201
201
|
peginAmounts: e.siblings.map((m) => m.amount),
|
|
202
|
-
depositorClaimValue:
|
|
203
|
-
peginMaxFee:
|
|
202
|
+
depositorClaimValue: c,
|
|
203
|
+
peginMaxFee: n
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
async function mt(e) {
|
|
@@ -209,40 +209,40 @@ async function mt(e) {
|
|
|
209
209
|
throw new Error(
|
|
210
210
|
"Connected wallet key is not the vault's depositor key; select the account that made the deposit."
|
|
211
211
|
);
|
|
212
|
-
const r = f(t.prePeginTxHash).toLowerCase(),
|
|
212
|
+
const r = f(t.prePeginTxHash).toLowerCase(), s = f(
|
|
213
213
|
H(e.fundedPrePeginTxHex)
|
|
214
214
|
).toLowerCase();
|
|
215
|
-
if (
|
|
215
|
+
if (s !== r)
|
|
216
216
|
throw new Error(
|
|
217
|
-
`Funded Pre-PegIn tx hashes to ${
|
|
217
|
+
`Funded Pre-PegIn tx hashes to ${s}, expected ${r} (on-chain prePeginTxHash).`
|
|
218
218
|
);
|
|
219
|
-
const
|
|
219
|
+
const i = await Promise.all(
|
|
220
220
|
Ve(
|
|
221
221
|
t.registrationRecords,
|
|
222
222
|
t.registrationRecord
|
|
223
|
-
).map(async (
|
|
224
|
-
const u = await e.siblingReader.getVaultData(
|
|
225
|
-
if (u.protocol.prePeginTxHash.toLowerCase() !== S(
|
|
223
|
+
).map(async (d) => {
|
|
224
|
+
const u = await e.siblingReader.getVaultData(d.vaultId);
|
|
225
|
+
if (u.protocol.prePeginTxHash.toLowerCase() !== S(d).toLowerCase())
|
|
226
226
|
throw new Error(
|
|
227
|
-
`Sibling ${
|
|
227
|
+
`Sibling ${d.vaultId} is registered against a different Pre-PegIn on chain than its registration log records; refusing an inconsistent node.`
|
|
228
228
|
);
|
|
229
229
|
return {
|
|
230
230
|
vault: u,
|
|
231
|
-
maxAcceptableCommissionBps:
|
|
231
|
+
maxAcceptableCommissionBps: d.maxAcceptableCommissionBps
|
|
232
232
|
};
|
|
233
233
|
})
|
|
234
|
-
),
|
|
234
|
+
), a = {
|
|
235
235
|
vault: t.vault,
|
|
236
236
|
maxAcceptableCommissionBps: t.registrationRecord.maxAcceptableCommissionBps
|
|
237
237
|
};
|
|
238
|
-
$e(
|
|
239
|
-
const
|
|
238
|
+
$e(a, i);
|
|
239
|
+
const c = Ae([a, ...i]), n = await Be(
|
|
240
240
|
e.fundedPrePeginTxHex,
|
|
241
241
|
e.mempoolApiUrl
|
|
242
242
|
);
|
|
243
243
|
return oe({
|
|
244
244
|
vaultCoreVersion: t.vault.protocol.vaultCoreVersion,
|
|
245
|
-
siblings:
|
|
245
|
+
siblings: c,
|
|
246
246
|
fundedPrePeginTxHex: e.fundedPrePeginTxHex,
|
|
247
247
|
depositorBtcPubkey: o,
|
|
248
248
|
vaultProviderBtcPubkey: t.participantKeys.vaultProvider.operationBtcPubkey,
|
|
@@ -256,7 +256,7 @@ async function mt(e) {
|
|
|
256
256
|
timelockAssert: t.context.timelockAssert,
|
|
257
257
|
timelockRefund: t.offchainParams.tRefund,
|
|
258
258
|
prepeginTxid: r,
|
|
259
|
-
prepeginMaxFee:
|
|
259
|
+
prepeginMaxFee: n,
|
|
260
260
|
// The submitted ceiling, verbatim: the device must see the terms the
|
|
261
261
|
// depositor originally approved.
|
|
262
262
|
maxAcceptableCommissionBps: t.registrationRecord.maxAcceptableCommissionBps,
|
|
@@ -401,40 +401,40 @@ class $ extends Error {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
async function Pt(e) {
|
|
404
|
-
const { wallet: t, depositorBtcPubkey: o, fundedPrePeginTxHex: r } = e,
|
|
405
|
-
if (
|
|
404
|
+
const { wallet: t, depositorBtcPubkey: o, fundedPrePeginTxHex: r } = e, s = f(r), i = _(s);
|
|
405
|
+
if (i === void 0)
|
|
406
406
|
throw new K(
|
|
407
407
|
"Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN, so the number of HTLC outputs it funds cannot be determined. Legacy pre-anchor deposits are not recoverable by this path."
|
|
408
408
|
);
|
|
409
|
-
const
|
|
410
|
-
if (
|
|
409
|
+
const a = i.vout;
|
|
410
|
+
if (a === 0)
|
|
411
411
|
throw new K(
|
|
412
412
|
"Pre-PegIn's auth-anchor OP_RETURN is at vout 0, implying zero HTLC outputs; there is nothing to recover."
|
|
413
413
|
);
|
|
414
|
-
const
|
|
414
|
+
const c = Ce(s), n = await xe(t, {
|
|
415
415
|
// The vault context takes the 32-byte x-only key; a wallet's compressed
|
|
416
416
|
// key would otherwise fail a byte-length check deep in the encoder with
|
|
417
417
|
// nothing pointing back at the caller.
|
|
418
418
|
depositorBtcPubkey: ce(
|
|
419
419
|
q(o)
|
|
420
420
|
),
|
|
421
|
-
fundingOutpoints:
|
|
421
|
+
fundingOutpoints: c
|
|
422
422
|
});
|
|
423
423
|
try {
|
|
424
|
-
const u = await ye(
|
|
425
|
-
let
|
|
424
|
+
const u = await ye(n);
|
|
425
|
+
let l;
|
|
426
426
|
try {
|
|
427
|
-
|
|
427
|
+
l = ue(Pe(u));
|
|
428
428
|
} finally {
|
|
429
429
|
u.fill(0);
|
|
430
430
|
}
|
|
431
|
-
if (
|
|
432
|
-
throw new Oe(
|
|
431
|
+
if (l !== i.hash)
|
|
432
|
+
throw new Oe(l, i.hash);
|
|
433
433
|
} catch (u) {
|
|
434
|
-
throw
|
|
434
|
+
throw n.fill(0), u;
|
|
435
435
|
}
|
|
436
|
-
const { hashlocks:
|
|
437
|
-
return { vaultCount:
|
|
436
|
+
const { hashlocks: d } = await be(n, a);
|
|
437
|
+
return { vaultCount: a, hashlocks: d, authAnchorHash: i.hash };
|
|
438
438
|
}
|
|
439
439
|
function vt(e) {
|
|
440
440
|
const { vaultCoreVersion: t, offchainParams: o, participantKeySets: r } = e;
|
|
@@ -450,15 +450,15 @@ function vt(e) {
|
|
|
450
450
|
throw new Error(
|
|
451
451
|
"buildPeginParamsCandidates: at least one participant key set is required"
|
|
452
452
|
);
|
|
453
|
-
const
|
|
454
|
-
for (const
|
|
455
|
-
for (const
|
|
456
|
-
|
|
453
|
+
const s = [];
|
|
454
|
+
for (const i of o)
|
|
455
|
+
for (const a of r)
|
|
456
|
+
s.push({
|
|
457
457
|
vaultCoreVersion: t,
|
|
458
|
-
offchainParams:
|
|
459
|
-
participants:
|
|
458
|
+
offchainParams: i,
|
|
459
|
+
participants: a
|
|
460
460
|
});
|
|
461
|
-
return
|
|
461
|
+
return s;
|
|
462
462
|
}
|
|
463
463
|
function Ue(e) {
|
|
464
464
|
return `${e.axis} v${e.version} (${e.reason})`;
|
|
@@ -487,11 +487,11 @@ function Ge(e) {
|
|
|
487
487
|
].join("|");
|
|
488
488
|
}
|
|
489
489
|
async function Qe(e) {
|
|
490
|
-
const { offchainParams: t, participants: o } = e, r = o.vaultKeeperBtcPubkeys.length,
|
|
490
|
+
const { offchainParams: t, participants: o } = e, r = o.vaultKeeperBtcPubkeys.length, s = o.universalChallengerBtcPubkeys.length, [i, a, c] = await Promise.all([
|
|
491
491
|
Y(
|
|
492
492
|
e.vaultCoreVersion,
|
|
493
493
|
r,
|
|
494
|
-
|
|
494
|
+
s,
|
|
495
495
|
t.councilQuorum,
|
|
496
496
|
t.councilSize,
|
|
497
497
|
t.protocolFeeRate
|
|
@@ -499,64 +499,64 @@ async function Qe(e) {
|
|
|
499
499
|
Z(
|
|
500
500
|
e.vaultCoreVersion,
|
|
501
501
|
r,
|
|
502
|
-
|
|
502
|
+
s,
|
|
503
503
|
t.minPeginFeeRate
|
|
504
504
|
),
|
|
505
505
|
ee(e.vaultCoreVersion)
|
|
506
|
-
]),
|
|
507
|
-
if (
|
|
506
|
+
]), n = c.value;
|
|
507
|
+
if (i <= 0n)
|
|
508
508
|
throw new $(
|
|
509
|
-
`WASM returned non-positive depositorClaimValue ${
|
|
509
|
+
`WASM returned non-positive depositorClaimValue ${i} for graph version ${e.vaultCoreVersion}`
|
|
510
510
|
);
|
|
511
|
-
if (
|
|
511
|
+
if (a <= 0n)
|
|
512
512
|
throw new $(
|
|
513
|
-
`WASM returned non-positive peginMaxFee ${
|
|
513
|
+
`WASM returned non-positive peginMaxFee ${a} for graph version ${e.vaultCoreVersion}`
|
|
514
514
|
);
|
|
515
|
-
if (
|
|
515
|
+
if (n < 0n)
|
|
516
516
|
throw new $(
|
|
517
|
-
`WASM returned negative P2A anchor value ${
|
|
517
|
+
`WASM returned negative P2A anchor value ${n} for graph version ${e.vaultCoreVersion}`
|
|
518
518
|
);
|
|
519
|
-
return { depositorClaimValue:
|
|
519
|
+
return { depositorClaimValue: i, peginMaxFee: a, p2aAnchorValue: n };
|
|
520
520
|
}
|
|
521
521
|
async function bt(e) {
|
|
522
522
|
const {
|
|
523
523
|
hashlocks: t,
|
|
524
524
|
fundedPrePeginTxHex: o,
|
|
525
525
|
depositorBtcPubkey: r,
|
|
526
|
-
prepeginMaxFee:
|
|
527
|
-
maxAcceptableCommissionBps:
|
|
528
|
-
network:
|
|
529
|
-
candidates:
|
|
530
|
-
unresolvedVersions:
|
|
526
|
+
prepeginMaxFee: s,
|
|
527
|
+
maxAcceptableCommissionBps: i,
|
|
528
|
+
network: a,
|
|
529
|
+
candidates: c,
|
|
530
|
+
unresolvedVersions: n
|
|
531
531
|
} = e;
|
|
532
532
|
if (t.length === 0)
|
|
533
533
|
throw new Error(
|
|
534
534
|
"reconstructPeginParams: at least one hashlock is required"
|
|
535
535
|
);
|
|
536
|
-
if (
|
|
536
|
+
if (c.length === 0)
|
|
537
537
|
throw new Error("reconstructPeginParams: candidate space is empty");
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
538
|
+
const d = q(r), u = f(o), l = _(u);
|
|
539
|
+
if (l === void 0)
|
|
540
540
|
throw new K(
|
|
541
541
|
"Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN; the sibling set cannot be proven complete. Reconstruction refused."
|
|
542
542
|
);
|
|
543
|
-
if (
|
|
543
|
+
if (l.vout !== t.length)
|
|
544
544
|
throw new Error(
|
|
545
|
-
`reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${
|
|
545
|
+
`reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${l.vout}, so the transaction funds ${l.vout} HTLC output(s). Reconstruction refused.`
|
|
546
546
|
);
|
|
547
|
-
const w = M.fromHex(u).outs, y = t.map((p, g) => BigInt(w[g].value)),
|
|
547
|
+
const w = M.fromHex(u).outs, y = t.map((p, g) => BigInt(w[g].value)), x = f(
|
|
548
548
|
H(u)
|
|
549
|
-
).toLowerCase(), m = /* @__PURE__ */ new Map(),
|
|
549
|
+
).toLowerCase(), m = /* @__PURE__ */ new Map(), h = [], A = [], T = [];
|
|
550
550
|
let N = 0;
|
|
551
|
-
for (const p of
|
|
551
|
+
for (const p of c)
|
|
552
552
|
try {
|
|
553
553
|
const g = Ge(p);
|
|
554
554
|
let P = m.get(g);
|
|
555
555
|
P === void 0 && (P = await Qe(p), m.set(g, P));
|
|
556
|
-
const
|
|
556
|
+
const C = P.depositorClaimValue + P.peginMaxFee + P.p2aAnchorValue, E = y.map((R) => R - C), k = E.findIndex((R) => R <= 0n);
|
|
557
557
|
if (k !== -1)
|
|
558
558
|
throw new U(
|
|
559
|
-
`HTLC output[${k}] value ${y[k]} is not above this candidate's reserve ${
|
|
559
|
+
`HTLC output[${k}] value ${y[k]} is not above this candidate's reserve ${C}, so it implies a non-positive pegin amount ${E[k]}.`
|
|
560
560
|
);
|
|
561
561
|
const { offchainParams: b, participants: B } = p, L = await oe({
|
|
562
562
|
vaultCoreVersion: p.vaultCoreVersion,
|
|
@@ -565,7 +565,7 @@ async function bt(e) {
|
|
|
565
565
|
amount: E[ne]
|
|
566
566
|
})),
|
|
567
567
|
fundedPrePeginTxHex: u,
|
|
568
|
-
depositorBtcPubkey:
|
|
568
|
+
depositorBtcPubkey: d,
|
|
569
569
|
vaultProviderBtcPubkey: B.vaultProviderBtcPubkey,
|
|
570
570
|
vaultKeeperBtcPubkeys: B.vaultKeeperBtcPubkeys,
|
|
571
571
|
universalChallengerBtcPubkeys: B.universalChallengerBtcPubkeys,
|
|
@@ -576,12 +576,12 @@ async function bt(e) {
|
|
|
576
576
|
timelockPegin: b.timelockPegin,
|
|
577
577
|
timelockAssert: b.timelockAssert,
|
|
578
578
|
timelockRefund: b.timelockRefund,
|
|
579
|
-
prepeginTxid:
|
|
580
|
-
prepeginMaxFee:
|
|
581
|
-
maxAcceptableCommissionBps:
|
|
582
|
-
network:
|
|
579
|
+
prepeginTxid: x,
|
|
580
|
+
prepeginMaxFee: s,
|
|
581
|
+
maxAcceptableCommissionBps: i,
|
|
582
|
+
network: a
|
|
583
583
|
});
|
|
584
|
-
|
|
584
|
+
h.push({
|
|
585
585
|
candidate: p,
|
|
586
586
|
terms: L,
|
|
587
587
|
peginAmounts: E,
|
|
@@ -590,82 +590,82 @@ async function bt(e) {
|
|
|
590
590
|
} catch (g) {
|
|
591
591
|
if (g instanceof $)
|
|
592
592
|
throw g;
|
|
593
|
-
const P = F(p),
|
|
594
|
-
g instanceof U ? A.length < X && A.push(`[${P}] ${
|
|
593
|
+
const P = F(p), C = g instanceof Error ? g.message : String(g);
|
|
594
|
+
g instanceof U ? A.length < X && A.push(`[${P}] ${C}`) : (N++, T.length < X && T.push(`${P} (${C})`));
|
|
595
595
|
}
|
|
596
|
-
const re =
|
|
597
|
-
...
|
|
596
|
+
const re = n.length + N, O = [
|
|
597
|
+
...n.map(Ue),
|
|
598
598
|
...T
|
|
599
599
|
];
|
|
600
|
-
if (
|
|
601
|
-
throw new Le(
|
|
602
|
-
if (new Set(
|
|
600
|
+
if (h.length === 0)
|
|
601
|
+
throw new Le(c.length, A, O);
|
|
602
|
+
if (new Set(h.map((p) => p.fingerprint)).size > 1)
|
|
603
603
|
throw new ze(
|
|
604
|
-
|
|
604
|
+
h.map((p) => F(p.candidate))
|
|
605
605
|
);
|
|
606
606
|
if (re > 0)
|
|
607
607
|
throw new De(
|
|
608
|
-
F(
|
|
608
|
+
F(h[0].candidate),
|
|
609
609
|
O
|
|
610
610
|
);
|
|
611
611
|
return {
|
|
612
|
-
candidate:
|
|
613
|
-
terms:
|
|
614
|
-
peginAmounts:
|
|
615
|
-
authAnchorHash:
|
|
616
|
-
|
|
617
|
-
|
|
612
|
+
candidate: h[0].candidate,
|
|
613
|
+
terms: h[0].terms,
|
|
614
|
+
peginAmounts: h[0].peginAmounts,
|
|
615
|
+
authAnchorHash: l.hash,
|
|
616
|
+
fundedPrePeginTxHex: u,
|
|
617
|
+
candidatesTried: c.length,
|
|
618
|
+
matchedCandidates: h.map((p) => p.candidate)
|
|
618
619
|
};
|
|
619
620
|
}
|
|
620
621
|
function wt(e, t) {
|
|
621
622
|
const {
|
|
622
623
|
htlcVout: o,
|
|
623
624
|
depositorBtcPubkey: r,
|
|
624
|
-
applicationEntryPoint:
|
|
625
|
-
|
|
626
|
-
hashlocks: s,
|
|
625
|
+
applicationEntryPoint: s,
|
|
626
|
+
hashlocks: i,
|
|
627
627
|
network: a
|
|
628
|
-
} = t, { candidate:
|
|
629
|
-
if (
|
|
628
|
+
} = t, { candidate: c, peginAmounts: n, fundedPrePeginTxHex: d } = e, { offchainParams: u, participants: l } = c;
|
|
629
|
+
if (i.length !== n.length)
|
|
630
630
|
throw new Error(
|
|
631
|
-
`toRefundInputs: ${
|
|
631
|
+
`toRefundInputs: ${i.length} hashlock(s) but ${n.length} reconstructed amount(s); the reconstruction and the hashlock vector describe different transactions.`
|
|
632
632
|
);
|
|
633
|
-
if (!Number.isInteger(o) || o < 0 || o >=
|
|
633
|
+
if (!Number.isInteger(o) || o < 0 || o >= n.length)
|
|
634
634
|
throw new Error(
|
|
635
|
-
`toRefundInputs: htlcVout ${o} is outside the reconstructed batch of ${
|
|
635
|
+
`toRefundInputs: htlcVout ${o} is outside the reconstructed batch of ${n.length} vault(s).`
|
|
636
636
|
);
|
|
637
|
-
const w =
|
|
638
|
-
hashlock: le(
|
|
637
|
+
const w = n.map((m, h) => ({
|
|
638
|
+
hashlock: le(i[h]),
|
|
639
639
|
amount: m,
|
|
640
|
-
htlcVout:
|
|
640
|
+
htlcVout: h
|
|
641
641
|
})), y = {
|
|
642
|
-
vaultCoreVersion:
|
|
642
|
+
vaultCoreVersion: c.vaultCoreVersion,
|
|
643
643
|
hashlock: w[o].hashlock,
|
|
644
644
|
htlcVout: o,
|
|
645
645
|
offchainParamsVersion: u.version,
|
|
646
|
-
appVaultKeepersVersion:
|
|
647
|
-
universalChallengersVersion:
|
|
648
|
-
vaultProvider:
|
|
649
|
-
applicationEntryPoint:
|
|
650
|
-
amount:
|
|
651
|
-
unsignedPrePeginTxHex:
|
|
646
|
+
appVaultKeepersVersion: l.appVaultKeepersVersion,
|
|
647
|
+
universalChallengersVersion: l.universalChallengersVersion,
|
|
648
|
+
vaultProvider: l.vaultProvider,
|
|
649
|
+
applicationEntryPoint: s,
|
|
650
|
+
amount: n[o],
|
|
651
|
+
unsignedPrePeginTxHex: d,
|
|
652
652
|
depositorBtcPubkey: r,
|
|
653
653
|
batch: w
|
|
654
|
-
},
|
|
655
|
-
vaultProviderPubkey:
|
|
656
|
-
vaultKeeperPubkeys:
|
|
657
|
-
universalChallengerPubkeys:
|
|
654
|
+
}, x = {
|
|
655
|
+
vaultProviderPubkey: l.vaultProviderBtcPubkey,
|
|
656
|
+
vaultKeeperPubkeys: l.vaultKeeperBtcPubkeys,
|
|
657
|
+
universalChallengerPubkeys: l.universalChallengerBtcPubkeys,
|
|
658
658
|
timelockRefund: u.timelockRefund,
|
|
659
659
|
feeRate: u.protocolFeeRate,
|
|
660
660
|
minPeginFeeRate: u.minPeginFeeRate,
|
|
661
661
|
// Depositor-as-claimer: the local-challenger count is the keeper count,
|
|
662
662
|
// the vault provider excluded — btc-vault graph.rs derive_challengers.
|
|
663
|
-
numLocalChallengers:
|
|
663
|
+
numLocalChallengers: l.vaultKeeperBtcPubkeys.length,
|
|
664
664
|
councilQuorum: u.councilQuorum,
|
|
665
665
|
councilSize: u.councilSize,
|
|
666
666
|
network: a
|
|
667
667
|
};
|
|
668
|
-
return { vault: y, context:
|
|
668
|
+
return { vault: y, context: x };
|
|
669
669
|
}
|
|
670
670
|
export {
|
|
671
671
|
te as D,
|
|
@@ -697,4 +697,4 @@ export {
|
|
|
697
697
|
$ as w,
|
|
698
698
|
wt as x
|
|
699
699
|
};
|
|
700
|
-
//# sourceMappingURL=toRefundInputs-
|
|
700
|
+
//# sourceMappingURL=toRefundInputs-D5tx3eeA.js.map
|