@babylonlabs-io/ts-sdk 0.53.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.
- package/dist/{PayoutManager-Ddo9_Ozc.js → PayoutManager-BJmPnyRP.js} +120 -103
- package/dist/PayoutManager-BJmPnyRP.js.map +1 -0
- package/dist/PayoutManager-aqtsj60t.cjs +2 -0
- package/dist/PayoutManager-aqtsj60t.cjs.map +1 -0
- package/dist/{PeginManager-CTU0wgkJ.js → PeginManager-D22MLWfM.js} +113 -128
- package/dist/PeginManager-D22MLWfM.js.map +1 -0
- package/dist/PeginManager-vUUfZCzj.cjs +2 -0
- package/dist/PeginManager-vUUfZCzj.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-DjS9nf87.js → buildAndBroadcastRefund-BiSO4zg2.js} +222 -235
- package/dist/buildAndBroadcastRefund-BiSO4zg2.js.map +1 -0
- package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs +2 -0
- package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs.map +1 -0
- package/dist/{fundPeginTransaction-96FxwYYJ.js → fundPeginTransaction-B2wyjqp0.js} +21 -22
- package/dist/fundPeginTransaction-B2wyjqp0.js.map +1 -0
- package/dist/fundPeginTransaction-BLD8FRL9.cjs +2 -0
- package/dist/fundPeginTransaction-BLD8FRL9.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +176 -175
- package/dist/{noPayout-8dDKwi6n.cjs → noPayout-CNMqNNpc.cjs} +2 -2
- package/dist/{noPayout-8dDKwi6n.cjs.map → noPayout-CNMqNNpc.cjs.map} +1 -1
- package/dist/{noPayout-tZFoNun3.js → noPayout-CfBg3HzC.js} +2 -2
- package/dist/{noPayout-tZFoNun3.js.map → noPayout-CfBg3HzC.js.map} +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +176 -175
- package/dist/tbv/core/managers/PeginManager.d.ts +3 -2
- package/dist/tbv/core/managers/PeginManager.d.ts.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/managers/pegin/signPsbtsWithFallback.d.ts +10 -6
- package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +2 -2
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +38 -36
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +11 -0
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +11 -10
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +10 -2
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/utils/fee/constants.d.ts +6 -14
- package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +35 -36
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +176 -175
- package/dist/testing/MockBitcoinWallet.d.ts +1 -1
- package/dist/testing/MockBitcoinWallet.d.ts.map +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +3 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js +658 -0
- package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js.map +1 -0
- package/dist/{waitForTransactionReceiptSmartAware-U706oKTc.cjs → waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs} +2 -2
- package/dist/{waitForTransactionReceiptSmartAware-U706oKTc.cjs.map → waitForTransactionReceiptSmartAware-AgZ-3WV_.cjs.map} +1 -1
- package/dist/{waitForTransactionReceiptSmartAware-Ckg_oZAo.js → waitForTransactionReceiptSmartAware-lobLm0q0.js} +2 -2
- package/dist/{waitForTransactionReceiptSmartAware-Ckg_oZAo.js.map → waitForTransactionReceiptSmartAware-lobLm0q0.js.map} +1 -1
- package/package.json +3 -3
- package/dist/PayoutManager-1GWmbvI9.cjs +0 -2
- package/dist/PayoutManager-1GWmbvI9.cjs.map +0 -1
- package/dist/PayoutManager-Ddo9_Ozc.js.map +0 -1
- package/dist/PeginManager-CTU0wgkJ.js.map +0 -1
- package/dist/PeginManager-De-eHl3v.cjs +0 -2
- package/dist/PeginManager-De-eHl3v.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BnD2qUDW.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BnD2qUDW.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-DjS9nf87.js.map +0 -1
- package/dist/fundPeginTransaction-96FxwYYJ.js.map +0 -1
- package/dist/fundPeginTransaction-DuMwnytD.cjs +0 -2
- package/dist/fundPeginTransaction-DuMwnytD.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-DpWZx5J0.js +0 -567
- package/dist/verifyScriptPathSchnorrSignature-DpWZx5J0.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-a4Us7D3e.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-a4Us7D3e.cjs.map +0 -1
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
var J = Object.defineProperty;
|
|
2
|
-
var Z = (e,
|
|
3
|
-
var $ = (e,
|
|
2
|
+
var Z = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var $ = (e, t, r) => Z(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { B as ee } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
|
|
5
5
|
import { e as te, v as re, s as p, u as X, p as A, f as E } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
-
import { v as ne,
|
|
7
|
-
import { D as w, c as
|
|
8
|
-
import { Transaction as S, Psbt as
|
|
9
|
-
import { c as
|
|
10
|
-
import { c as
|
|
6
|
+
import { v as ne, s as oe, P as ae, f as se } from "./PayoutManager-BJmPnyRP.js";
|
|
7
|
+
import { D as w, c as ie, a as ue, R as le, d as z } from "./types-CQDRQvV-.js";
|
|
8
|
+
import { Transaction as S, Psbt as ce } from "bitcoinjs-lib";
|
|
9
|
+
import { c as he, d as I, e as N, f as H } from "./verifyScriptPathSchnorrSignature-DA4Z4yZ3.js";
|
|
10
|
+
import { c as de, a as pe, b as ge } from "./noPayout-CfBg3HzC.js";
|
|
11
11
|
import { c as O } from "./signing-DaLvGwQe.js";
|
|
12
|
-
import { a as
|
|
13
|
-
const
|
|
14
|
-
function V(e,
|
|
12
|
+
import { a as fe } from "./constants-BhclpREj.js";
|
|
13
|
+
const me = /^0x[0-9a-fA-F]{64}$/, Pe = /^0x[0-9a-fA-F]{40}$/, be = /^0x([0-9a-fA-F]{2})*$/;
|
|
14
|
+
function V(e, t) {
|
|
15
15
|
if (e.length !== 66)
|
|
16
16
|
throw new Error(
|
|
17
|
-
`${
|
|
17
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
18
18
|
);
|
|
19
|
-
if (!
|
|
19
|
+
if (!me.test(e))
|
|
20
20
|
throw new Error(
|
|
21
|
-
`${
|
|
21
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
if (!
|
|
24
|
+
function ye(e, t) {
|
|
25
|
+
if (!Pe.test(e))
|
|
26
26
|
throw new Error(
|
|
27
|
-
`${
|
|
27
|
+
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
if (!
|
|
30
|
+
function we(e, t) {
|
|
31
|
+
if (!be.test(e))
|
|
32
32
|
throw new Error(
|
|
33
|
-
`${
|
|
33
|
+
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
async function ut(e) {
|
|
37
37
|
const {
|
|
38
|
-
btcVaultRegistryAddress:
|
|
39
|
-
vaultId:
|
|
38
|
+
btcVaultRegistryAddress: t,
|
|
39
|
+
vaultId: r,
|
|
40
40
|
hashlock: n,
|
|
41
41
|
activationMetadata: s,
|
|
42
42
|
writeContract: l,
|
|
43
43
|
signal: a
|
|
44
44
|
} = e;
|
|
45
|
-
a == null || a.throwIfAborted(),
|
|
45
|
+
a == null || a.throwIfAborted(), ye(t, "btcVaultRegistryAddress"), V(r, "vaultId");
|
|
46
46
|
const i = te(e.secret);
|
|
47
47
|
if (V(i, "secret"), n !== void 0 && (V(n, "hashlock"), !ne(i, n)))
|
|
48
48
|
throw new Error(
|
|
49
49
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
50
50
|
);
|
|
51
|
-
return
|
|
52
|
-
address:
|
|
51
|
+
return we(s, "activationMetadata"), l({
|
|
52
|
+
address: t,
|
|
53
53
|
abi: ee,
|
|
54
54
|
functionName: "activateVaultWithSecret",
|
|
55
|
-
args: [
|
|
55
|
+
args: [r, i, s]
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const xe = 1e4;
|
|
59
59
|
async function G(e) {
|
|
60
60
|
const {
|
|
61
|
-
statusReader:
|
|
62
|
-
peginTxid:
|
|
61
|
+
statusReader: t,
|
|
62
|
+
peginTxid: r,
|
|
63
63
|
targetStatuses: n,
|
|
64
64
|
timeoutMs: s,
|
|
65
|
-
pollIntervalMs: l =
|
|
65
|
+
pollIntervalMs: l = xe,
|
|
66
66
|
signal: a
|
|
67
67
|
} = e, i = Date.now();
|
|
68
68
|
for (; ; ) {
|
|
69
69
|
if (a != null && a.aborted)
|
|
70
70
|
throw new Error(
|
|
71
|
-
`Polling aborted for pegin ${
|
|
71
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
72
72
|
);
|
|
73
73
|
if (Date.now() - i >= s)
|
|
74
74
|
throw new Error(
|
|
75
|
-
`Polling timeout after ${s}ms for pegin ${
|
|
75
|
+
`Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
76
76
|
);
|
|
77
77
|
try {
|
|
78
|
-
const o = await
|
|
79
|
-
{ pegin_txid:
|
|
78
|
+
const o = await t.getPeginStatus(
|
|
79
|
+
{ pegin_txid: r },
|
|
80
80
|
a
|
|
81
81
|
);
|
|
82
|
-
if (o.pegin_txid.toLowerCase() !==
|
|
82
|
+
if (o.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
83
83
|
throw new Error(
|
|
84
|
-
`getPeginStatus returned status for pegin ${o.pegin_txid.slice(0, 8)}…, requested ${
|
|
84
|
+
`getPeginStatus returned status for pegin ${o.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
85
85
|
);
|
|
86
86
|
const u = o.status;
|
|
87
87
|
if (n.has(u) || u === w.ACTIVATED)
|
|
88
88
|
return u;
|
|
89
|
-
if (u === w.EXPIRED ||
|
|
89
|
+
if (u === w.EXPIRED || ie.has(u))
|
|
90
90
|
throw new Error(
|
|
91
|
-
`Pegin ${
|
|
91
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...n].join(", ")}`
|
|
92
92
|
);
|
|
93
93
|
} catch (o) {
|
|
94
|
-
if (!(o instanceof
|
|
94
|
+
if (!(o instanceof ue && o.code === le.PEGIN_NOT_FOUND))
|
|
95
95
|
throw o;
|
|
96
96
|
}
|
|
97
97
|
await new Promise((o, u) => {
|
|
98
98
|
const h = () => {
|
|
99
99
|
clearTimeout(c), u(
|
|
100
100
|
new Error(
|
|
101
|
-
`Polling aborted for pegin ${
|
|
101
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
102
102
|
)
|
|
103
103
|
);
|
|
104
104
|
}, c = setTimeout(() => {
|
|
@@ -108,29 +108,29 @@ async function G(e) {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
const
|
|
111
|
+
const ve = 300 * 1e3, Ee = /* @__PURE__ */ new Set([
|
|
112
112
|
w.PENDING_DEPOSITOR_WOTS_PK,
|
|
113
113
|
...z
|
|
114
114
|
]);
|
|
115
115
|
async function lt(e) {
|
|
116
116
|
const {
|
|
117
|
-
statusReader:
|
|
118
|
-
wotsSubmitter:
|
|
117
|
+
statusReader: t,
|
|
118
|
+
wotsSubmitter: r,
|
|
119
119
|
peginTxid: n,
|
|
120
120
|
depositorPk: s,
|
|
121
121
|
wotsPublicKeys: l,
|
|
122
|
-
timeoutMs: a =
|
|
122
|
+
timeoutMs: a = ve,
|
|
123
123
|
signal: i
|
|
124
124
|
} = e;
|
|
125
125
|
i == null || i.throwIfAborted();
|
|
126
126
|
const o = await G({
|
|
127
|
-
statusReader:
|
|
127
|
+
statusReader: t,
|
|
128
128
|
peginTxid: n,
|
|
129
|
-
targetStatuses:
|
|
129
|
+
targetStatuses: Ee,
|
|
130
130
|
timeoutMs: a,
|
|
131
131
|
signal: i
|
|
132
132
|
});
|
|
133
|
-
z.has(o) || (i == null || i.throwIfAborted(), await
|
|
133
|
+
z.has(o) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
134
134
|
{
|
|
135
135
|
pegin_txid: n,
|
|
136
136
|
depositor_pk: s,
|
|
@@ -139,9 +139,9 @@ async function lt(e) {
|
|
|
139
139
|
i
|
|
140
140
|
));
|
|
141
141
|
}
|
|
142
|
-
const K = 1,
|
|
143
|
-
function
|
|
144
|
-
const
|
|
142
|
+
const K = 1, Te = 1;
|
|
143
|
+
function ke(e, t) {
|
|
144
|
+
const r = p(t).toLowerCase(), s = e.map((l) => p(l).toLowerCase()).filter((l) => l !== r);
|
|
145
145
|
if (s.length === 0)
|
|
146
146
|
throw new Error(
|
|
147
147
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
@@ -152,15 +152,15 @@ function Te(e, r) {
|
|
|
152
152
|
);
|
|
153
153
|
return s;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
const n =
|
|
155
|
+
function _e(e, t, r) {
|
|
156
|
+
const n = r.map(
|
|
157
157
|
(c) => p(c).toLowerCase()
|
|
158
|
-
), s =
|
|
158
|
+
), s = t.filter((c) => n.includes(c));
|
|
159
159
|
if (s.length > 0)
|
|
160
160
|
throw new Error(
|
|
161
161
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
|
|
162
162
|
);
|
|
163
|
-
const l = [...
|
|
163
|
+
const l = [...t, ...n], a = e.map(
|
|
164
164
|
(c) => p(c.challenger_pubkey).toLowerCase()
|
|
165
165
|
), i = new Set(a);
|
|
166
166
|
if (i.size !== a.length)
|
|
@@ -173,68 +173,68 @@ function ke(e, r, t) {
|
|
|
173
173
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (u.length > 0 ? ` (missing: ${u.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
178
|
-
return X(new Uint8Array(
|
|
176
|
+
function Ce(e, t) {
|
|
177
|
+
const r = e.ins[t];
|
|
178
|
+
return X(new Uint8Array(r.hash).slice().reverse());
|
|
179
179
|
}
|
|
180
|
-
function R(e,
|
|
181
|
-
const l = e.ins[
|
|
180
|
+
function R(e, t, r, n, s) {
|
|
181
|
+
const l = e.ins[t];
|
|
182
182
|
if (l.index !== 0)
|
|
183
183
|
throw new Error(
|
|
184
|
-
`NoPayout (challenger ${s}) input ${
|
|
184
|
+
`NoPayout (challenger ${s}) input ${t} expected to spend ${n} vout 0, got vout ${l.index}`
|
|
185
185
|
);
|
|
186
|
-
const a =
|
|
186
|
+
const a = r.getId(), i = Ce(e, t);
|
|
187
187
|
if (i !== a)
|
|
188
188
|
throw new Error(
|
|
189
|
-
`NoPayout (challenger ${s}) input ${
|
|
189
|
+
`NoPayout (challenger ${s}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
|
|
190
190
|
);
|
|
191
191
|
}
|
|
192
|
-
async function
|
|
193
|
-
const n = [], s = [], l = [], a =
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
async function Se(e, t, r) {
|
|
193
|
+
const n = [], s = [], l = [], a = ke(
|
|
194
|
+
r.vaultKeeperBtcPubkeys,
|
|
195
|
+
r.depositorBtcPubkey
|
|
196
196
|
);
|
|
197
|
-
|
|
197
|
+
_e(
|
|
198
198
|
e.challenger_presign_data,
|
|
199
199
|
a,
|
|
200
|
-
|
|
200
|
+
r.universalChallengerBtcPubkeys
|
|
201
201
|
);
|
|
202
|
-
const i = await
|
|
203
|
-
vaultCoreVersion:
|
|
202
|
+
const i = await he({
|
|
203
|
+
vaultCoreVersion: r.vaultCoreVersion,
|
|
204
204
|
payoutTxHex: e.payout_tx.tx_hex,
|
|
205
|
-
peginTxHex:
|
|
205
|
+
peginTxHex: r.peginTxHex,
|
|
206
206
|
assertTxHex: e.assert_tx.tx_hex,
|
|
207
|
-
depositorBtcPubkey:
|
|
208
|
-
vaultProviderBtcPubkey:
|
|
209
|
-
vaultKeeperBtcPubkeys:
|
|
210
|
-
universalChallengerBtcPubkeys:
|
|
211
|
-
timelockPegin:
|
|
212
|
-
network:
|
|
213
|
-
claimerBtcPubkey:
|
|
214
|
-
registeredPayoutScriptPubKey:
|
|
215
|
-
commissionBps:
|
|
207
|
+
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
208
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
209
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
210
|
+
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
|
|
211
|
+
timelockPegin: r.timelockPegin,
|
|
212
|
+
network: r.network,
|
|
213
|
+
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
214
|
+
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
215
|
+
commissionBps: Te
|
|
216
216
|
});
|
|
217
217
|
n.push(i.psbtHex), s.push(
|
|
218
218
|
O(
|
|
219
|
-
|
|
219
|
+
t,
|
|
220
220
|
K
|
|
221
221
|
)
|
|
222
222
|
);
|
|
223
|
-
const o = p(
|
|
223
|
+
const o = p(r.depositorBtcPubkey), u = S.fromHex(
|
|
224
224
|
p(e.assert_tx.tx_hex)
|
|
225
225
|
);
|
|
226
226
|
for (const h of e.challenger_presign_data) {
|
|
227
|
-
const c = p(h.challenger_pubkey), d = n.length, P = await
|
|
227
|
+
const c = p(h.challenger_pubkey), d = n.length, P = await Ae({
|
|
228
228
|
challenger: h,
|
|
229
229
|
challengerPubkey: c,
|
|
230
230
|
claimerPubkey: o,
|
|
231
231
|
localChallengers: a,
|
|
232
232
|
assertTxParsed: u,
|
|
233
|
-
ctx:
|
|
233
|
+
ctx: r
|
|
234
234
|
});
|
|
235
235
|
n.push(P), s.push(
|
|
236
236
|
O(
|
|
237
|
-
|
|
237
|
+
t,
|
|
238
238
|
K
|
|
239
239
|
)
|
|
240
240
|
), l.push({
|
|
@@ -244,49 +244,49 @@ async function Ce(e, r, t) {
|
|
|
244
244
|
}
|
|
245
245
|
return { psbtHexes: n, signOptions: s, challengerEntries: l };
|
|
246
246
|
}
|
|
247
|
-
async function
|
|
247
|
+
async function Ae(e) {
|
|
248
248
|
const {
|
|
249
|
-
challenger:
|
|
250
|
-
challengerPubkey:
|
|
249
|
+
challenger: t,
|
|
250
|
+
challengerPubkey: r,
|
|
251
251
|
claimerPubkey: n,
|
|
252
252
|
localChallengers: s,
|
|
253
253
|
assertTxParsed: l,
|
|
254
254
|
ctx: a
|
|
255
255
|
} = e;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
de(
|
|
257
|
+
t.nopayout_tx.tx_hex,
|
|
258
|
+
r,
|
|
259
259
|
a.network
|
|
260
260
|
);
|
|
261
261
|
const i = S.fromHex(
|
|
262
|
-
p(
|
|
262
|
+
p(t.nopayout_tx.tx_hex)
|
|
263
263
|
), o = S.fromHex(
|
|
264
|
-
p(
|
|
264
|
+
p(t.challenge_assert_x_tx.tx_hex)
|
|
265
265
|
), u = S.fromHex(
|
|
266
|
-
p(
|
|
266
|
+
p(t.challenge_assert_y_tx.tx_hex)
|
|
267
267
|
);
|
|
268
268
|
if (i.ins.length !== 3)
|
|
269
269
|
throw new Error(
|
|
270
|
-
`NoPayout (challenger ${
|
|
270
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
271
271
|
);
|
|
272
272
|
R(
|
|
273
273
|
i,
|
|
274
274
|
0,
|
|
275
275
|
l,
|
|
276
276
|
"Assert",
|
|
277
|
-
|
|
277
|
+
r
|
|
278
278
|
), R(
|
|
279
279
|
i,
|
|
280
280
|
1,
|
|
281
281
|
o,
|
|
282
282
|
"ChallengeAssertX",
|
|
283
|
-
|
|
283
|
+
r
|
|
284
284
|
), R(
|
|
285
285
|
i,
|
|
286
286
|
2,
|
|
287
287
|
u,
|
|
288
288
|
"ChallengeAssertY",
|
|
289
|
-
|
|
289
|
+
r
|
|
290
290
|
);
|
|
291
291
|
const h = [
|
|
292
292
|
l.outs[0],
|
|
@@ -296,9 +296,9 @@ async function Se(e) {
|
|
|
296
296
|
script_pubkey: X(new Uint8Array(c.script)),
|
|
297
297
|
value: c.value
|
|
298
298
|
}));
|
|
299
|
-
return
|
|
300
|
-
noPayoutTxHex:
|
|
301
|
-
challengerPubkey:
|
|
299
|
+
return pe({
|
|
300
|
+
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
301
|
+
challengerPubkey: r,
|
|
302
302
|
prevouts: h,
|
|
303
303
|
connectorParams: {
|
|
304
304
|
txGraphVersion: a.vaultCoreVersion,
|
|
@@ -311,29 +311,29 @@ async function Se(e) {
|
|
|
311
311
|
}
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
|
-
function
|
|
314
|
+
function $e(e, t, r) {
|
|
315
315
|
I(e[0]);
|
|
316
316
|
const s = N(
|
|
317
317
|
e[0].returnedPsbtHex,
|
|
318
|
-
|
|
318
|
+
r
|
|
319
319
|
);
|
|
320
320
|
H({
|
|
321
321
|
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
322
322
|
signatureHex: s,
|
|
323
|
-
signerXOnlyPubkeyHex:
|
|
323
|
+
signerXOnlyPubkeyHex: r,
|
|
324
324
|
inputIndex: 0
|
|
325
325
|
});
|
|
326
326
|
const l = {};
|
|
327
|
-
for (const a of
|
|
327
|
+
for (const a of t) {
|
|
328
328
|
I(e[a.noPayoutIdx]);
|
|
329
329
|
const i = N(
|
|
330
330
|
e[a.noPayoutIdx].returnedPsbtHex,
|
|
331
|
-
|
|
331
|
+
r
|
|
332
332
|
);
|
|
333
333
|
H({
|
|
334
334
|
requestedPsbtHex: e[a.noPayoutIdx].requestedPsbtHex,
|
|
335
335
|
signatureHex: i,
|
|
336
|
-
signerXOnlyPubkeyHex:
|
|
336
|
+
signerXOnlyPubkeyHex: r,
|
|
337
337
|
inputIndex: 0
|
|
338
338
|
}), l[a.challengerPubkey] = {
|
|
339
339
|
nopayout_signature: i
|
|
@@ -346,36 +346,23 @@ function Ae(e, r, t) {
|
|
|
346
346
|
per_challenger: l
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
|
-
async function $e(e, r, t) {
|
|
350
|
-
if (typeof e.signPsbts == "function")
|
|
351
|
-
return e.signPsbts(r, t);
|
|
352
|
-
const n = [];
|
|
353
|
-
for (let s = 0; s < r.length; s++)
|
|
354
|
-
n.push(await e.signPsbt(r[s], t == null ? void 0 : t[s]));
|
|
355
|
-
return n;
|
|
356
|
-
}
|
|
357
349
|
async function Ve(e) {
|
|
358
|
-
const { depositorGraph:
|
|
350
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, s = await r.getPublicKeyHex(), { depositorPubkey: l } = re(
|
|
359
351
|
s,
|
|
360
352
|
p(n.depositorBtcPubkey)
|
|
361
|
-
), { psbtHexes: a, signOptions: i, challengerEntries: o } = await
|
|
362
|
-
|
|
353
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: o } = await Se(
|
|
354
|
+
t,
|
|
363
355
|
s,
|
|
364
356
|
n
|
|
365
|
-
), u = await
|
|
366
|
-
|
|
357
|
+
), u = await oe(
|
|
358
|
+
r,
|
|
367
359
|
a,
|
|
368
360
|
i
|
|
369
|
-
)
|
|
370
|
-
if (u.length !== a.length)
|
|
371
|
-
throw new Error(
|
|
372
|
-
`Wallet returned ${u.length} signed PSBTs, expected ${a.length}`
|
|
373
|
-
);
|
|
374
|
-
const h = a.map((c, d) => ({
|
|
361
|
+
), h = a.map((c, d) => ({
|
|
375
362
|
requestedPsbtHex: c,
|
|
376
363
|
returnedPsbtHex: u[d]
|
|
377
364
|
}));
|
|
378
|
-
return
|
|
365
|
+
return $e(
|
|
379
366
|
h,
|
|
380
367
|
o,
|
|
381
368
|
l
|
|
@@ -391,19 +378,19 @@ const Re = 1200 * 1e3, q = /* @__PURE__ */ new Set([
|
|
|
391
378
|
...q
|
|
392
379
|
]);
|
|
393
380
|
function Ie(e) {
|
|
394
|
-
return e.map((
|
|
395
|
-
claimerPubkeyXOnly: A(
|
|
396
|
-
payoutTxHex:
|
|
397
|
-
assertTxHex:
|
|
381
|
+
return e.map((t) => ({
|
|
382
|
+
claimerPubkeyXOnly: A(t.claimer_pubkey),
|
|
383
|
+
payoutTxHex: t.payout_tx.tx_hex,
|
|
384
|
+
assertTxHex: t.assert_tx.tx_hex
|
|
398
385
|
}));
|
|
399
386
|
}
|
|
400
387
|
function _(e) {
|
|
401
388
|
return A(e).toLowerCase();
|
|
402
389
|
}
|
|
403
|
-
function Ne(e,
|
|
390
|
+
function Ne(e, t, r, n) {
|
|
404
391
|
const s = _(n), l = [
|
|
405
|
-
_(
|
|
406
|
-
...
|
|
392
|
+
_(t),
|
|
393
|
+
...r.map(_)
|
|
407
394
|
], a = new Set(l);
|
|
408
395
|
if (a.size !== l.length)
|
|
409
396
|
throw new Error(
|
|
@@ -426,54 +413,54 @@ function Ne(e, r, t, n) {
|
|
|
426
413
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
427
414
|
);
|
|
428
415
|
}
|
|
429
|
-
function U(e,
|
|
416
|
+
function U(e, t) {
|
|
430
417
|
return {
|
|
431
|
-
vaultCoreVersion:
|
|
418
|
+
vaultCoreVersion: t.vaultCoreVersion,
|
|
432
419
|
payoutTxHex: e.payoutTxHex,
|
|
433
|
-
peginTxHex:
|
|
420
|
+
peginTxHex: t.peginTxHex,
|
|
434
421
|
assertTxHex: e.assertTxHex,
|
|
435
|
-
vaultProviderBtcPubkey:
|
|
436
|
-
vaultKeeperBtcPubkeys:
|
|
437
|
-
universalChallengerBtcPubkeys:
|
|
438
|
-
depositorBtcPubkey:
|
|
439
|
-
timelockPegin:
|
|
440
|
-
registeredPayoutScriptPubKey:
|
|
422
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
423
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
424
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
425
|
+
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
426
|
+
timelockPegin: t.timelockPegin,
|
|
427
|
+
registeredPayoutScriptPubKey: t.registeredPayoutScriptPubKey,
|
|
441
428
|
claimerBtcPubkey: e.claimerPubkeyXOnly,
|
|
442
|
-
commissionBps:
|
|
429
|
+
commissionBps: t.commissionBps
|
|
443
430
|
};
|
|
444
431
|
}
|
|
445
|
-
async function He(e,
|
|
446
|
-
const s = new
|
|
447
|
-
network:
|
|
432
|
+
async function He(e, t, r, n) {
|
|
433
|
+
const s = new ae({
|
|
434
|
+
network: t.network,
|
|
448
435
|
btcWallet: e
|
|
449
|
-
}), l =
|
|
436
|
+
}), l = r.length;
|
|
450
437
|
n == null || n(0, l);
|
|
451
438
|
let a;
|
|
452
439
|
if (s.supportsBatchSigning())
|
|
453
440
|
a = (await s.signPayoutTransactionsBatch(
|
|
454
|
-
|
|
441
|
+
r.map((u) => U(u, t))
|
|
455
442
|
)).map((u) => u.payoutSignature);
|
|
456
443
|
else {
|
|
457
444
|
a = [];
|
|
458
|
-
for (let o = 0; o <
|
|
445
|
+
for (let o = 0; o < r.length; o++) {
|
|
459
446
|
n == null || n(o, l);
|
|
460
447
|
const u = await s.signPayoutTransaction(
|
|
461
|
-
U(
|
|
448
|
+
U(r[o], t)
|
|
462
449
|
);
|
|
463
450
|
a.push(u.signature);
|
|
464
451
|
}
|
|
465
452
|
}
|
|
466
453
|
const i = {};
|
|
467
|
-
for (let o = 0; o <
|
|
468
|
-
i[
|
|
454
|
+
for (let o = 0; o < r.length; o++)
|
|
455
|
+
i[r[o].claimerPubkeyXOnly] = {
|
|
469
456
|
payout_signature: a[o]
|
|
470
457
|
};
|
|
471
458
|
return n == null || n(l, l), i;
|
|
472
459
|
}
|
|
473
460
|
async function ct(e) {
|
|
474
461
|
const {
|
|
475
|
-
statusReader:
|
|
476
|
-
presignClient:
|
|
462
|
+
statusReader: t,
|
|
463
|
+
presignClient: r,
|
|
477
464
|
btcWallet: n,
|
|
478
465
|
peginTxid: s,
|
|
479
466
|
depositorPk: l,
|
|
@@ -482,7 +469,7 @@ async function ct(e) {
|
|
|
482
469
|
signal: o,
|
|
483
470
|
onProgress: u
|
|
484
471
|
} = e, h = await G({
|
|
485
|
-
statusReader:
|
|
472
|
+
statusReader: t,
|
|
486
473
|
peginTxid: s,
|
|
487
474
|
targetStatuses: Be,
|
|
488
475
|
timeoutMs: i,
|
|
@@ -491,7 +478,7 @@ async function ct(e) {
|
|
|
491
478
|
if (q.has(h))
|
|
492
479
|
return;
|
|
493
480
|
o == null || o.throwIfAborted();
|
|
494
|
-
const c = await
|
|
481
|
+
const c = await r.requestDepositorPresignTransactions(
|
|
495
482
|
{
|
|
496
483
|
pegin_txid: s,
|
|
497
484
|
depositor_pk: l
|
|
@@ -535,7 +522,7 @@ async function ct(e) {
|
|
|
535
522
|
});
|
|
536
523
|
o == null || o.throwIfAborted();
|
|
537
524
|
const b = { ...y };
|
|
538
|
-
b[p(l)] = x.payout_signatures, await
|
|
525
|
+
b[p(l)] = x.payout_signatures, await r.submitDepositorPresignatures(
|
|
539
526
|
{
|
|
540
527
|
pegin_txid: s,
|
|
541
528
|
depositor_pk: l,
|
|
@@ -550,54 +537,54 @@ function Oe(e) {
|
|
|
550
537
|
}
|
|
551
538
|
function ht(e) {
|
|
552
539
|
const {
|
|
553
|
-
amountSats:
|
|
554
|
-
minDeposit:
|
|
540
|
+
amountSats: t,
|
|
541
|
+
minDeposit: r,
|
|
555
542
|
maxDeposit: n,
|
|
556
543
|
btcBalance: s,
|
|
557
544
|
estimatedFeeSats: l,
|
|
558
545
|
depositorClaimValue: a
|
|
559
546
|
} = e;
|
|
560
|
-
return !(
|
|
547
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || l == null || a == null || t + l + a > s);
|
|
561
548
|
}
|
|
562
|
-
function dt(e,
|
|
549
|
+
function dt(e, t, r) {
|
|
563
550
|
return e <= 0n ? {
|
|
564
551
|
valid: !1,
|
|
565
552
|
error: "Deposit amount must be greater than zero"
|
|
566
|
-
} : e <
|
|
553
|
+
} : e < t ? {
|
|
567
554
|
valid: !1,
|
|
568
|
-
error: `Minimum deposit is ${E(
|
|
569
|
-
} :
|
|
555
|
+
error: `Minimum deposit is ${E(t)} BTC`
|
|
556
|
+
} : r && r > 0n && e > r ? {
|
|
570
557
|
valid: !1,
|
|
571
|
-
error: `Maximum deposit is ${E(
|
|
558
|
+
error: `Maximum deposit is ${E(r)} BTC`
|
|
572
559
|
} : { valid: !0 };
|
|
573
560
|
}
|
|
574
561
|
function pt(e) {
|
|
575
|
-
const { amount:
|
|
576
|
-
return
|
|
562
|
+
const { amount: t, effectiveRemaining: r } = e;
|
|
563
|
+
return r === null ? { valid: !0 } : r === 0n ? {
|
|
577
564
|
valid: !1,
|
|
578
565
|
error: "Supply cap reached — deposits temporarily paused"
|
|
579
|
-
} :
|
|
566
|
+
} : t > r ? {
|
|
580
567
|
valid: !1,
|
|
581
|
-
error: `Vault size exceeds remaining capacity (${E(
|
|
568
|
+
error: `Vault size exceeds remaining capacity (${E(r)} BTC)`
|
|
582
569
|
} : { valid: !0 };
|
|
583
570
|
}
|
|
584
|
-
function gt(e,
|
|
571
|
+
function gt(e, t) {
|
|
585
572
|
if (!e || e.length === 0)
|
|
586
573
|
return {
|
|
587
574
|
valid: !1,
|
|
588
575
|
error: "At least one vault provider must be selected"
|
|
589
576
|
};
|
|
590
|
-
const
|
|
577
|
+
const r = t.map(
|
|
591
578
|
(s) => s.toLowerCase()
|
|
592
579
|
);
|
|
593
580
|
return e.filter(
|
|
594
|
-
(s) => !
|
|
581
|
+
(s) => !r.includes(s.toLowerCase())
|
|
595
582
|
).length > 0 ? {
|
|
596
583
|
valid: !1,
|
|
597
584
|
error: "Invalid vault provider selected"
|
|
598
585
|
} : { valid: !0 };
|
|
599
586
|
}
|
|
600
|
-
function De(e,
|
|
587
|
+
function De(e, t, r) {
|
|
601
588
|
if (!e || e.length === 0)
|
|
602
589
|
return {
|
|
603
590
|
valid: !1,
|
|
@@ -610,22 +597,22 @@ function De(e, r, t) {
|
|
|
610
597
|
valid: !1,
|
|
611
598
|
error: `Vault ${n + 1} amount must be positive`
|
|
612
599
|
};
|
|
613
|
-
if (
|
|
600
|
+
if (t && s < t)
|
|
614
601
|
return {
|
|
615
602
|
valid: !1,
|
|
616
|
-
error: `Vault ${n + 1} amount ${E(s)} BTC is below minimum deposit ${E(
|
|
603
|
+
error: `Vault ${n + 1} amount ${E(s)} BTC is below minimum deposit ${E(t)} BTC`
|
|
617
604
|
};
|
|
618
|
-
if (
|
|
605
|
+
if (r && s > r)
|
|
619
606
|
return {
|
|
620
607
|
valid: !1,
|
|
621
|
-
error: `Vault ${n + 1} amount ${E(s)} BTC exceeds maximum deposit ${E(
|
|
608
|
+
error: `Vault ${n + 1} amount ${E(s)} BTC exceeds maximum deposit ${E(r)} BTC`
|
|
622
609
|
};
|
|
623
610
|
}
|
|
624
611
|
return { valid: !0 };
|
|
625
612
|
}
|
|
626
613
|
function Ke(e) {
|
|
627
|
-
const
|
|
628
|
-
return Oe(
|
|
614
|
+
const t = p(e);
|
|
615
|
+
return Oe(t) ? { valid: !0 } : {
|
|
629
616
|
valid: !1,
|
|
630
617
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
631
618
|
};
|
|
@@ -648,15 +635,15 @@ function Me(e) {
|
|
|
648
635
|
}
|
|
649
636
|
function ft(e) {
|
|
650
637
|
const {
|
|
651
|
-
vaultAmounts:
|
|
652
|
-
confirmedUTXOs:
|
|
638
|
+
vaultAmounts: t,
|
|
639
|
+
confirmedUTXOs: r,
|
|
653
640
|
vaultProviderBtcPubkey: n,
|
|
654
641
|
vaultKeeperBtcPubkeys: s,
|
|
655
642
|
universalChallengerBtcPubkeys: l,
|
|
656
643
|
minDeposit: a,
|
|
657
644
|
maxDeposit: i
|
|
658
645
|
} = e, o = De(
|
|
659
|
-
|
|
646
|
+
t,
|
|
660
647
|
a,
|
|
661
648
|
i
|
|
662
649
|
);
|
|
@@ -665,12 +652,12 @@ function ft(e) {
|
|
|
665
652
|
const u = Ke(n);
|
|
666
653
|
if (!u.valid)
|
|
667
654
|
throw new Error(u.error);
|
|
668
|
-
Ue(s), Fe(l), Me(
|
|
655
|
+
Ue(s), Fe(l), Me(r);
|
|
669
656
|
}
|
|
670
657
|
async function mt(e) {
|
|
671
658
|
const {
|
|
672
|
-
vaultRegistryReader:
|
|
673
|
-
vaultKeeperReader:
|
|
659
|
+
vaultRegistryReader: t,
|
|
660
|
+
vaultKeeperReader: r,
|
|
674
661
|
universalChallengerReader: n,
|
|
675
662
|
vaultProviderEthAddress: s,
|
|
676
663
|
applicationEntryPoint: l,
|
|
@@ -682,11 +669,11 @@ async function mt(e) {
|
|
|
682
669
|
h,
|
|
683
670
|
c
|
|
684
671
|
] = await Promise.all([
|
|
685
|
-
|
|
686
|
-
|
|
672
|
+
t.getVaultProviderBtcPubKey(s),
|
|
673
|
+
r.getCurrentVaultKeepersVersion(l),
|
|
687
674
|
n.getLatestUniversalChallengersVersion()
|
|
688
675
|
]), [d, P] = await Promise.all([
|
|
689
|
-
|
|
676
|
+
r.getVaultKeepersByVersion(
|
|
690
677
|
l,
|
|
691
678
|
h
|
|
692
679
|
),
|
|
@@ -721,8 +708,8 @@ async function mt(e) {
|
|
|
721
708
|
};
|
|
722
709
|
}
|
|
723
710
|
class j extends Error {
|
|
724
|
-
constructor(
|
|
725
|
-
super(
|
|
711
|
+
constructor(t) {
|
|
712
|
+
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
726
713
|
}
|
|
727
714
|
}
|
|
728
715
|
function Pt(e) {
|
|
@@ -730,15 +717,15 @@ function Pt(e) {
|
|
|
730
717
|
}
|
|
731
718
|
async function bt(e) {
|
|
732
719
|
const {
|
|
733
|
-
vaultRegistryReader:
|
|
734
|
-
vaultIds:
|
|
720
|
+
vaultRegistryReader: t,
|
|
721
|
+
vaultIds: r,
|
|
735
722
|
expectedOffchainParamsVersion: n,
|
|
736
723
|
expectedAppVaultKeepersVersion: s,
|
|
737
724
|
expectedUniversalChallengersVersion: l,
|
|
738
725
|
expectedVaultCoreVersion: a
|
|
739
|
-
} = e, i = await
|
|
726
|
+
} = e, i = await t.getProtocolInfoBatch(r), o = [];
|
|
740
727
|
if (i.forEach((u, h) => {
|
|
741
|
-
const c =
|
|
728
|
+
const c = r[h];
|
|
742
729
|
u.offchainParamsVersion !== n && o.push(
|
|
743
730
|
`vault ${c}: offchainParams expected v${n}, got v${u.offchainParamsVersion}`
|
|
744
731
|
), u.appVaultKeepersVersion !== s && o.push(
|
|
@@ -768,35 +755,35 @@ function wt(e) {
|
|
|
768
755
|
return !!e && Le.has(e);
|
|
769
756
|
}
|
|
770
757
|
class Xe extends Error {
|
|
771
|
-
constructor(
|
|
758
|
+
constructor(r, n) {
|
|
772
759
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
773
760
|
$(this, "vaultId");
|
|
774
761
|
$(this, "cause");
|
|
775
|
-
this.name = "BIP68NotMatureError", this.vaultId =
|
|
762
|
+
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
776
763
|
}
|
|
777
764
|
}
|
|
778
|
-
const ze = /^0x[0-9a-fA-F]{64}$/, Ge = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/,
|
|
765
|
+
const ze = /^0x[0-9a-fA-F]{64}$/, Ge = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Y = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, W = 160, F = 2e3, M = 10n, L = 100n;
|
|
779
766
|
function xt(e) {
|
|
780
767
|
if (!Number.isFinite(e) || e <= 0)
|
|
781
768
|
throw new Error(
|
|
782
769
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
783
770
|
);
|
|
784
|
-
return BigInt(Math.ceil(e *
|
|
771
|
+
return BigInt(Math.ceil(e * W));
|
|
785
772
|
}
|
|
786
773
|
const qe = 1, je = /non-BIP68-final/i;
|
|
787
|
-
function D(e,
|
|
774
|
+
function D(e, t) {
|
|
788
775
|
if (e.length !== 66)
|
|
789
776
|
throw new Error(
|
|
790
|
-
`${
|
|
777
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
791
778
|
);
|
|
792
779
|
if (!ze.test(e))
|
|
793
780
|
throw new Error(
|
|
794
|
-
`${
|
|
781
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
795
782
|
);
|
|
796
783
|
}
|
|
797
|
-
function B(e,
|
|
784
|
+
function B(e, t) {
|
|
798
785
|
if (!Number.isInteger(e) || e < 0)
|
|
799
|
-
throw new Error(`${
|
|
786
|
+
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
800
787
|
}
|
|
801
788
|
function Qe(e) {
|
|
802
789
|
if (D(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
@@ -809,30 +796,30 @@ function Qe(e) {
|
|
|
809
796
|
throw new Error(
|
|
810
797
|
`htlcVout ${e.htlcVout} is out of range for batch of size ${e.batch.length}`
|
|
811
798
|
);
|
|
812
|
-
for (let
|
|
813
|
-
const n = e.batch[
|
|
814
|
-
if (D(n.hashlock, `batch[${
|
|
799
|
+
for (let r = 0; r < e.batch.length; r++) {
|
|
800
|
+
const n = e.batch[r];
|
|
801
|
+
if (D(n.hashlock, `batch[${r}].hashlock`), !Number.isInteger(n.htlcVout) || n.htlcVout !== r)
|
|
815
802
|
throw new Error(
|
|
816
|
-
`batch[${
|
|
803
|
+
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${n.htlcVout}`
|
|
817
804
|
);
|
|
818
805
|
if (typeof n.amount != "bigint" || n.amount <= 0n)
|
|
819
806
|
throw new Error(
|
|
820
|
-
`batch[${
|
|
807
|
+
`batch[${r}].amount must be a positive bigint, got ${n.amount}`
|
|
821
808
|
);
|
|
822
809
|
}
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
810
|
+
const t = e.batch[e.htlcVout];
|
|
811
|
+
if (t.hashlock.toLowerCase() !== e.hashlock.toLowerCase())
|
|
825
812
|
throw new Error(
|
|
826
|
-
`batch[${e.htlcVout}].hashlock (${
|
|
813
|
+
`batch[${e.htlcVout}].hashlock (${t.hashlock}) does not match target hashlock (${e.hashlock})`
|
|
827
814
|
);
|
|
828
|
-
if (
|
|
815
|
+
if (t.amount !== e.amount)
|
|
829
816
|
throw new Error(
|
|
830
|
-
`batch[${e.htlcVout}].amount (${
|
|
817
|
+
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
831
818
|
);
|
|
832
819
|
if (B(e.offchainParamsVersion, "offchainParamsVersion"), B(e.appVaultKeepersVersion, "appVaultKeepersVersion"), B(
|
|
833
820
|
e.universalChallengersVersion,
|
|
834
821
|
"universalChallengersVersion"
|
|
835
|
-
),
|
|
822
|
+
), fe(
|
|
836
823
|
e.vaultCoreVersion,
|
|
837
824
|
"VaultRefundData.vaultCoreVersion"
|
|
838
825
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
@@ -841,15 +828,15 @@ function Qe(e) {
|
|
|
841
828
|
throw new Error(
|
|
842
829
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
843
830
|
);
|
|
844
|
-
if (!e.depositorBtcPubkey || !
|
|
831
|
+
if (!e.depositorBtcPubkey || !Y.test(e.depositorBtcPubkey))
|
|
845
832
|
throw new Error(
|
|
846
833
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
847
834
|
);
|
|
848
835
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
849
836
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
850
837
|
}
|
|
851
|
-
function
|
|
852
|
-
if (!e.vaultProviderPubkey || !
|
|
838
|
+
function Ye(e) {
|
|
839
|
+
if (!e.vaultProviderPubkey || !Y.test(e.vaultProviderPubkey))
|
|
853
840
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
854
841
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
855
842
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -874,38 +861,38 @@ function We(e) {
|
|
|
874
861
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
875
862
|
);
|
|
876
863
|
}
|
|
877
|
-
function
|
|
878
|
-
const
|
|
864
|
+
function We(e) {
|
|
865
|
+
const t = ce.fromHex(e);
|
|
879
866
|
try {
|
|
880
|
-
|
|
881
|
-
} catch (
|
|
882
|
-
const n =
|
|
867
|
+
t.finalizeAllInputs();
|
|
868
|
+
} catch (r) {
|
|
869
|
+
const n = r instanceof Error ? r.message : String(r);
|
|
883
870
|
if (!n.includes("already finalized"))
|
|
884
871
|
throw new Error(`Failed to finalize refund PSBT: ${n}`);
|
|
885
872
|
}
|
|
886
|
-
return
|
|
873
|
+
return t.extractTransaction().toHex();
|
|
887
874
|
}
|
|
888
875
|
async function vt(e) {
|
|
889
876
|
const {
|
|
890
|
-
vaultId:
|
|
891
|
-
readVault:
|
|
877
|
+
vaultId: t,
|
|
878
|
+
readVault: r,
|
|
892
879
|
readPrePeginContext: n,
|
|
893
880
|
feeRate: s,
|
|
894
881
|
signPsbt: l,
|
|
895
882
|
broadcastTx: a,
|
|
896
883
|
signal: i
|
|
897
884
|
} = e;
|
|
898
|
-
i == null || i.throwIfAborted(), D(
|
|
899
|
-
const o = await
|
|
885
|
+
i == null || i.throwIfAborted(), D(t, "vaultId");
|
|
886
|
+
const o = await r();
|
|
900
887
|
Qe(o), i == null || i.throwIfAborted();
|
|
901
888
|
const u = await n(o);
|
|
902
|
-
if (
|
|
889
|
+
if (Ye(u), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
903
890
|
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
904
891
|
if (s > F)
|
|
905
892
|
throw new Error(
|
|
906
893
|
`feeRate ${s} sat/vB exceeds refund safety cap ${F} sat/vB; refusing to sign refund.`
|
|
907
894
|
);
|
|
908
|
-
const h = BigInt(Math.ceil(s *
|
|
895
|
+
const h = BigInt(Math.ceil(s * W)), c = o.amount * M / L;
|
|
909
896
|
if (h > c)
|
|
910
897
|
throw new Error(
|
|
911
898
|
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${M}/${L} of vault.amount=${o.amount}); refusing to sign refund.`
|
|
@@ -913,7 +900,7 @@ async function vt(e) {
|
|
|
913
900
|
i == null || i.throwIfAborted();
|
|
914
901
|
const d = A(
|
|
915
902
|
o.depositorBtcPubkey
|
|
916
|
-
), P = p(o.unsignedPrePeginTxHex), m =
|
|
903
|
+
), P = p(o.unsignedPrePeginTxHex), m = se(P);
|
|
917
904
|
if (m !== void 0 && m.vout !== o.batch.length)
|
|
918
905
|
throw new Error(
|
|
919
906
|
`Auth-anchor OP_RETURN at vout ${m.vout} does not match batch size (${o.batch.length} HTLC outputs expect the anchor at vout ${o.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
@@ -931,7 +918,7 @@ async function vt(e) {
|
|
|
931
918
|
throw new Error(
|
|
932
919
|
`Funded Pre-PegIn tx has ${x.outs.length} outputs but batch requires at least ${o.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
933
920
|
);
|
|
934
|
-
const { psbtHex: b } = await
|
|
921
|
+
const { psbtHex: b } = await ge({
|
|
935
922
|
prePeginParams: {
|
|
936
923
|
vaultCoreVersion: o.vaultCoreVersion,
|
|
937
924
|
depositorPubkey: d,
|
|
@@ -984,12 +971,12 @@ async function vt(e) {
|
|
|
984
971
|
signerXOnlyPubkeyHex: d,
|
|
985
972
|
inputIndex: k
|
|
986
973
|
});
|
|
987
|
-
const C =
|
|
974
|
+
const C = We(T);
|
|
988
975
|
i == null || i.throwIfAborted();
|
|
989
976
|
try {
|
|
990
977
|
return await a(C);
|
|
991
978
|
} catch (f) {
|
|
992
|
-
throw f instanceof Error && je.test(f.message) ? new Xe(
|
|
979
|
+
throw f instanceof Error && je.test(f.message) ? new Xe(t, f) : f;
|
|
993
980
|
}
|
|
994
981
|
}
|
|
995
982
|
export {
|
|
@@ -1016,8 +1003,8 @@ export {
|
|
|
1016
1003
|
ct as r,
|
|
1017
1004
|
lt as s,
|
|
1018
1005
|
F as t,
|
|
1019
|
-
|
|
1006
|
+
W as u,
|
|
1020
1007
|
dt as v,
|
|
1021
1008
|
G as w
|
|
1022
1009
|
};
|
|
1023
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
1010
|
+
//# sourceMappingURL=buildAndBroadcastRefund-BiSO4zg2.js.map
|