@babylonlabs-io/ts-sdk 0.36.3 → 0.37.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-BxAY2x0g.cjs +2 -0
- package/dist/PayoutManager-BxAY2x0g.cjs.map +1 -0
- package/dist/{PayoutManager-s_uH8Uuj.js → PayoutManager-sfxuOBGq.js} +51 -43
- package/dist/PayoutManager-sfxuOBGq.js.map +1 -0
- package/dist/{PeginManager-CB-dVkT2.js → PeginManager-C7-XYrkK.js} +13 -14
- package/dist/{PeginManager-CB-dVkT2.js.map → PeginManager-C7-XYrkK.js.map} +1 -1
- package/dist/{PeginManager-BPXVXu8t.cjs → PeginManager-CRuwG4I-.cjs} +2 -2
- package/dist/{PeginManager-BPXVXu8t.cjs.map → PeginManager-CRuwG4I-.cjs.map} +1 -1
- package/dist/assertPsbtUnsignedTxMatches-BoHwgW30.cjs +2 -0
- package/dist/assertPsbtUnsignedTxMatches-BoHwgW30.cjs.map +1 -0
- package/dist/assertPsbtUnsignedTxMatches-D7RxpR4A.js +263 -0
- package/dist/assertPsbtUnsignedTxMatches-D7RxpR4A.js.map +1 -0
- package/dist/{bitcoin-B0S8SHCX.js → bitcoin-B5aNKtsk.js} +77 -60
- package/dist/{bitcoin-B0S8SHCX.js.map → bitcoin-B5aNKtsk.js.map} +1 -1
- package/dist/bitcoin-CHfKAhcI.cjs +2 -0
- package/dist/{bitcoin-B3aqjuMP.cjs.map → bitcoin-CHfKAhcI.cjs.map} +1 -1
- package/dist/{buildAndBroadcastRefund-C2VqXiOx.js → buildAndBroadcastRefund-C1eOhIdo.js} +322 -322
- package/dist/buildAndBroadcastRefund-C1eOhIdo.js.map +1 -0
- package/dist/buildAndBroadcastRefund-_CEDUU5H.cjs +2 -0
- package/dist/buildAndBroadcastRefund-_CEDUU5H.cjs.map +1 -0
- package/dist/{challengeAssert-Yyyj-EdR.cjs → challengeAssert-BKDS_ADt.cjs} +2 -2
- package/dist/{challengeAssert-Yyyj-EdR.cjs.map → challengeAssert-BKDS_ADt.cjs.map} +1 -1
- package/dist/{challengeAssert-BzxQmdZy.js → challengeAssert-BXESW00N.js} +7 -7
- package/dist/{challengeAssert-BzxQmdZy.js.map → challengeAssert-BXESW00N.js.map} +1 -1
- package/dist/fundPeginTransaction-BBE3wTjR.cjs +2 -0
- package/dist/{fundPeginTransaction-DaWoYCgO.cjs.map → fundPeginTransaction-BBE3wTjR.cjs.map} +1 -1
- package/dist/fundPeginTransaction-t-6TsHAY.js +84 -0
- package/dist/{fundPeginTransaction-oV-dNJOU.js.map → fundPeginTransaction-t-6TsHAY.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +174 -166
- package/dist/{noPayout-BXeUw0Qq.cjs → noPayout-B6s8vrW6.cjs} +2 -2
- package/dist/{noPayout-BXeUw0Qq.cjs.map → noPayout-B6s8vrW6.cjs.map} +1 -1
- package/dist/{noPayout-DBX6G96_.js → noPayout-BhgknZBx.js} +2 -2
- package/dist/{noPayout-DBX6G96_.js.map → noPayout-BhgknZBx.js.map} +1 -1
- package/dist/{peginInput-tbw9BpZy.cjs → peginInput-57FK2O99.cjs} +2 -2
- package/dist/{peginInput-tbw9BpZy.cjs.map → peginInput-57FK2O99.cjs.map} +1 -1
- package/dist/{peginInput-C2QPvuhR.js → peginInput-CYJzbuwA.js} +3 -3
- package/dist/{peginInput-C2QPvuhR.js.map → peginInput-CYJzbuwA.js.map} +1 -1
- package/dist/{reservation-fZUvejYK.js → reservation-CB-4FBPk.js} +3 -3
- package/dist/{reservation-fZUvejYK.js.map → reservation-CB-4FBPk.js.map} +1 -1
- package/dist/{reservation-DF0uiCUC.cjs → reservation-hjXStM03.cjs} +2 -2
- package/dist/{reservation-DF0uiCUC.cjs.map → reservation-hjXStM03.cjs.map} +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +172 -164
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +7 -8
- 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/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +3 -1
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +31 -27
- package/dist/tbv/core/primitives/psbt/__tests__/assertPsbtUnsignedTxMatches.test.d.ts +5 -0
- package/dist/tbv/core/primitives/psbt/__tests__/assertPsbtUnsignedTxMatches.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertPsbtUnsignedTxMatches.d.ts +31 -0
- package/dist/tbv/core/primitives/psbt/assertPsbtUnsignedTxMatches.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/index.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +33 -3
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/index.d.ts +1 -1
- package/dist/tbv/core/primitives/utils/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.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/__tests__/peginFeeMath.test.d.ts +19 -0
- package/dist/tbv/core/utils/fee/__tests__/peginFeeMath.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/fee/index.d.ts +1 -0
- package/dist/tbv/core/utils/fee/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/fee/peginFeeMath.d.ts +99 -0
- package/dist/tbv/core/utils/fee/peginFeeMath.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +44 -40
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/core/utils/utxo/selectUtxos.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +172 -164
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/{vault-registry-reader-Br9m8bHF.cjs → vault-registry-reader-7gOYnrQD.cjs} +2 -2
- package/dist/{vault-registry-reader-Br9m8bHF.cjs.map → vault-registry-reader-7gOYnrQD.cjs.map} +1 -1
- package/dist/{vault-registry-reader-CohvzvoH.js → vault-registry-reader-Blhu9FW2.js} +2 -2
- package/dist/{vault-registry-reader-CohvzvoH.js.map → vault-registry-reader-Blhu9FW2.js.map} +1 -1
- package/dist/waitForTransactionReceiptSmartAware-CmgFXFza.js +265 -0
- package/dist/waitForTransactionReceiptSmartAware-CmgFXFza.js.map +1 -0
- package/dist/waitForTransactionReceiptSmartAware-tv1mtSIY.cjs +2 -0
- package/dist/waitForTransactionReceiptSmartAware-tv1mtSIY.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/PayoutManager-BhJoQZsG.cjs +0 -2
- package/dist/PayoutManager-BhJoQZsG.cjs.map +0 -1
- package/dist/PayoutManager-s_uH8Uuj.js.map +0 -1
- package/dist/bitcoin-B3aqjuMP.cjs +0 -2
- package/dist/buildAndBroadcastRefund-C2VqXiOx.js.map +0 -1
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs +0 -2
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs.map +0 -1
- package/dist/fundPeginTransaction-DaWoYCgO.cjs +0 -2
- package/dist/fundPeginTransaction-oV-dNJOU.js +0 -76
- package/dist/payout-BNFMBXS6.js +0 -193
- package/dist/payout-BNFMBXS6.js.map +0 -1
- package/dist/payout-DQ_fmJUA.cjs +0 -2
- package/dist/payout-DQ_fmJUA.cjs.map +0 -1
- package/dist/waitForTransactionReceiptSmartAware-Cj_DKm0G.js +0 -217
- package/dist/waitForTransactionReceiptSmartAware-Cj_DKm0G.js.map +0 -1
- package/dist/waitForTransactionReceiptSmartAware-D9ykVriz.cjs +0 -2
- package/dist/waitForTransactionReceiptSmartAware-D9ykVriz.cjs.map +0 -1
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as Y, v as
|
|
6
|
-
import { v as
|
|
7
|
-
import { c as
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { c as ae, a as se, b as ie } from "./noPayout-DBX6G96_.js";
|
|
12
|
-
import { a as ue, b as le, e as V } from "./payout-BNFMBXS6.js";
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var Q = (e, t, r) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var C = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as j } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
|
|
5
|
+
import { e as Y, v as q, s as h, u as N, p as k, d as J, f as m } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { v as Z, P as ee } from "./PayoutManager-sfxuOBGq.js";
|
|
7
|
+
import { c as te, a as re, R as ne, d as L, D as x } from "./types-TiIjyo2b.js";
|
|
8
|
+
import { Transaction as T, Psbt as oe } from "bitcoinjs-lib";
|
|
9
|
+
import { a as se, b as ae, c as V, e as I } from "./assertPsbtUnsignedTxMatches-D7RxpR4A.js";
|
|
10
|
+
import { c as ie, a as ue, b as le } from "./noPayout-BhgknZBx.js";
|
|
13
11
|
import { c as R } from "./signing-DaLvGwQe.js";
|
|
14
12
|
const ce = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
|
|
15
|
-
function
|
|
13
|
+
function S(e, t) {
|
|
16
14
|
if (e.length !== 66)
|
|
17
15
|
throw new Error(
|
|
18
16
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
@@ -28,82 +26,82 @@ function pe(e, t) {
|
|
|
28
26
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
29
27
|
);
|
|
30
28
|
}
|
|
31
|
-
function
|
|
29
|
+
function ge(e, t) {
|
|
32
30
|
if (!he.test(e))
|
|
33
31
|
throw new Error(
|
|
34
32
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
35
33
|
);
|
|
36
34
|
}
|
|
37
|
-
async function
|
|
35
|
+
async function tt(e) {
|
|
38
36
|
const {
|
|
39
37
|
btcVaultRegistryAddress: t,
|
|
40
38
|
vaultId: r,
|
|
41
39
|
hashlock: n,
|
|
42
|
-
activationMetadata:
|
|
40
|
+
activationMetadata: s,
|
|
43
41
|
writeContract: u,
|
|
44
42
|
signal: a
|
|
45
43
|
} = e;
|
|
46
|
-
a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"),
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
44
|
+
a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), S(r, "vaultId");
|
|
45
|
+
const i = Y(e.secret);
|
|
46
|
+
if (S(i, "secret"), n !== void 0 && (S(n, "hashlock"), !Z(i, n)))
|
|
49
47
|
throw new Error(
|
|
50
48
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
51
49
|
);
|
|
52
|
-
return
|
|
50
|
+
return ge(s, "activationMetadata"), u({
|
|
53
51
|
address: t,
|
|
54
|
-
abi:
|
|
52
|
+
abi: j,
|
|
55
53
|
functionName: "activateVaultWithSecret",
|
|
56
|
-
args: [r,
|
|
54
|
+
args: [r, i, s]
|
|
57
55
|
});
|
|
58
56
|
}
|
|
59
|
-
const
|
|
60
|
-
async function
|
|
57
|
+
const fe = 1e4;
|
|
58
|
+
async function D(e) {
|
|
61
59
|
const {
|
|
62
60
|
statusReader: t,
|
|
63
61
|
peginTxid: r,
|
|
64
62
|
targetStatuses: n,
|
|
65
|
-
timeoutMs:
|
|
66
|
-
pollIntervalMs: u =
|
|
63
|
+
timeoutMs: s,
|
|
64
|
+
pollIntervalMs: u = fe,
|
|
67
65
|
signal: a
|
|
68
|
-
} = e,
|
|
66
|
+
} = e, i = Date.now();
|
|
69
67
|
for (; ; ) {
|
|
70
68
|
if (a != null && a.aborted)
|
|
71
69
|
throw new Error(
|
|
72
70
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
73
71
|
);
|
|
74
|
-
if (Date.now() -
|
|
72
|
+
if (Date.now() - i >= s)
|
|
75
73
|
throw new Error(
|
|
76
|
-
`Polling timeout after ${
|
|
74
|
+
`Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
77
75
|
);
|
|
78
76
|
try {
|
|
79
|
-
const
|
|
77
|
+
const o = await t.getPeginStatus(
|
|
80
78
|
{ pegin_txid: r },
|
|
81
79
|
a
|
|
82
80
|
);
|
|
83
|
-
if (
|
|
81
|
+
if (o.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
84
82
|
throw new Error(
|
|
85
|
-
`getPeginStatus returned status for pegin ${
|
|
83
|
+
`getPeginStatus returned status for pegin ${o.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
86
84
|
);
|
|
87
|
-
const l =
|
|
85
|
+
const l = o.status;
|
|
88
86
|
if (n.has(l))
|
|
89
87
|
return l;
|
|
90
|
-
if (
|
|
88
|
+
if (te.has(l) && !n.has(l))
|
|
91
89
|
throw new Error(
|
|
92
90
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
|
|
93
91
|
);
|
|
94
|
-
} catch (
|
|
95
|
-
if (!(
|
|
96
|
-
throw
|
|
92
|
+
} catch (o) {
|
|
93
|
+
if (!(o instanceof re && o.code === ne.NOT_FOUND || o instanceof Error && o.message.includes("PegIn not found")))
|
|
94
|
+
throw o;
|
|
97
95
|
}
|
|
98
|
-
await new Promise((
|
|
96
|
+
await new Promise((o, l) => {
|
|
99
97
|
const d = () => {
|
|
100
|
-
clearTimeout(
|
|
98
|
+
clearTimeout(c), l(
|
|
101
99
|
new Error(
|
|
102
100
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
103
101
|
)
|
|
104
102
|
);
|
|
105
|
-
},
|
|
106
|
-
a == null || a.removeEventListener("abort", d),
|
|
103
|
+
}, c = setTimeout(() => {
|
|
104
|
+
a == null || a.removeEventListener("abort", d), o();
|
|
107
105
|
}, u);
|
|
108
106
|
a == null || a.addEventListener("abort", d, { once: !0 });
|
|
109
107
|
});
|
|
@@ -111,94 +109,99 @@ async function L(e) {
|
|
|
111
109
|
}
|
|
112
110
|
const ye = 300 * 1e3, Pe = /* @__PURE__ */ new Set([
|
|
113
111
|
x.PENDING_DEPOSITOR_WOTS_PK,
|
|
114
|
-
...
|
|
112
|
+
...L
|
|
115
113
|
]);
|
|
116
|
-
async function
|
|
114
|
+
async function rt(e) {
|
|
117
115
|
const {
|
|
118
116
|
statusReader: t,
|
|
119
117
|
wotsSubmitter: r,
|
|
120
118
|
peginTxid: n,
|
|
121
|
-
depositorPk:
|
|
119
|
+
depositorPk: s,
|
|
122
120
|
wotsPublicKeys: u,
|
|
123
121
|
timeoutMs: a = ye,
|
|
124
|
-
signal:
|
|
122
|
+
signal: i
|
|
125
123
|
} = e;
|
|
126
|
-
|
|
127
|
-
const
|
|
124
|
+
i == null || i.throwIfAborted();
|
|
125
|
+
const o = await D({
|
|
128
126
|
statusReader: t,
|
|
129
127
|
peginTxid: n,
|
|
130
128
|
targetStatuses: Pe,
|
|
131
129
|
timeoutMs: a,
|
|
132
|
-
signal:
|
|
130
|
+
signal: i
|
|
133
131
|
});
|
|
134
|
-
|
|
132
|
+
L.has(o) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
135
133
|
{
|
|
136
134
|
pegin_txid: n,
|
|
137
|
-
depositor_pk:
|
|
135
|
+
depositor_pk: s,
|
|
138
136
|
wots_public_keys: u
|
|
139
137
|
},
|
|
140
|
-
|
|
138
|
+
i
|
|
141
139
|
));
|
|
142
140
|
}
|
|
143
|
-
const
|
|
144
|
-
function me(e, t
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
).filter((a) => a !== n);
|
|
148
|
-
if (u.length === 0)
|
|
141
|
+
const H = 1;
|
|
142
|
+
function me(e, t) {
|
|
143
|
+
const r = h(t).toLowerCase(), s = e.map((u) => h(u).toLowerCase()).filter((u) => u !== r);
|
|
144
|
+
if (s.length === 0)
|
|
149
145
|
throw new Error(
|
|
150
|
-
"Cannot derive localChallengers:
|
|
146
|
+
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
151
147
|
);
|
|
152
|
-
if (new Set(
|
|
148
|
+
if (new Set(s).size !== s.length)
|
|
153
149
|
throw new Error(
|
|
154
|
-
"Cannot derive localChallengers:
|
|
150
|
+
"Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
|
|
155
151
|
);
|
|
156
|
-
return
|
|
152
|
+
return s;
|
|
157
153
|
}
|
|
158
|
-
function be(e, t) {
|
|
159
|
-
const
|
|
160
|
-
(
|
|
161
|
-
),
|
|
162
|
-
if (
|
|
154
|
+
function be(e, t, r) {
|
|
155
|
+
const n = r.map(
|
|
156
|
+
(c) => h(c).toLowerCase()
|
|
157
|
+
), s = t.filter((c) => n.includes(c));
|
|
158
|
+
if (s.length > 0)
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
|
|
161
|
+
);
|
|
162
|
+
const u = [...t, ...n], a = e.map(
|
|
163
|
+
(c) => h(c.challenger_pubkey).toLowerCase()
|
|
164
|
+
), i = new Set(a);
|
|
165
|
+
if (i.size !== a.length)
|
|
163
166
|
throw new Error(
|
|
164
167
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
165
168
|
);
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
169
|
+
const o = new Set(u), l = u.filter((c) => !i.has(c)), d = a.filter((c) => !o.has(c));
|
|
170
|
+
if (l.length > 0 || d.length > 0)
|
|
168
171
|
throw new Error(
|
|
169
|
-
"Depositor graph challenger set does not match
|
|
172
|
+
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
|
|
170
173
|
);
|
|
171
174
|
}
|
|
172
175
|
function we(e, t) {
|
|
173
176
|
const r = e.ins[t];
|
|
174
177
|
return N(new Uint8Array(r.hash).slice().reverse());
|
|
175
178
|
}
|
|
176
|
-
function B(e, t, r, n,
|
|
179
|
+
function B(e, t, r, n, s) {
|
|
177
180
|
const u = e.ins[t];
|
|
178
181
|
if (u.index !== 0)
|
|
179
182
|
throw new Error(
|
|
180
|
-
`NoPayout (challenger ${
|
|
183
|
+
`NoPayout (challenger ${s}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
|
|
181
184
|
);
|
|
182
|
-
const a = r.getId(),
|
|
183
|
-
if (
|
|
185
|
+
const a = r.getId(), i = we(e, t);
|
|
186
|
+
if (i !== a)
|
|
184
187
|
throw new Error(
|
|
185
|
-
`NoPayout (challenger ${
|
|
188
|
+
`NoPayout (challenger ${s}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
|
|
186
189
|
);
|
|
187
190
|
}
|
|
188
191
|
async function ve(e, t, r) {
|
|
189
|
-
const n = [],
|
|
190
|
-
r.vaultProviderBtcPubkey,
|
|
192
|
+
const n = [], s = [], u = [], a = me(
|
|
191
193
|
r.vaultKeeperBtcPubkeys,
|
|
192
194
|
r.depositorBtcPubkey
|
|
193
195
|
);
|
|
194
196
|
be(
|
|
195
197
|
e.challenger_presign_data,
|
|
196
|
-
a
|
|
197
|
-
|
|
198
|
+
a,
|
|
199
|
+
r.universalChallengerBtcPubkeys
|
|
200
|
+
), se(
|
|
198
201
|
e.payout_tx.tx_hex,
|
|
199
202
|
r.registeredPayoutScriptPubKey
|
|
200
203
|
);
|
|
201
|
-
const
|
|
204
|
+
const i = await ae({
|
|
202
205
|
payoutTxHex: e.payout_tx.tx_hex,
|
|
203
206
|
peginTxHex: r.peginTxHex,
|
|
204
207
|
assertTxHex: e.assert_tx.tx_hex,
|
|
@@ -209,75 +212,75 @@ async function ve(e, t, r) {
|
|
|
209
212
|
timelockPegin: r.timelockPegin,
|
|
210
213
|
network: r.network
|
|
211
214
|
});
|
|
212
|
-
n.push(
|
|
215
|
+
n.push(i.psbtHex), s.push(
|
|
213
216
|
R(
|
|
214
217
|
t,
|
|
215
|
-
|
|
218
|
+
H
|
|
216
219
|
)
|
|
217
220
|
);
|
|
218
|
-
const
|
|
219
|
-
|
|
221
|
+
const o = h(r.depositorBtcPubkey), l = T.fromHex(
|
|
222
|
+
h(e.assert_tx.tx_hex)
|
|
220
223
|
);
|
|
221
224
|
for (const d of e.challenger_presign_data) {
|
|
222
|
-
const
|
|
225
|
+
const c = h(d.challenger_pubkey), g = n.length, P = await xe({
|
|
223
226
|
challenger: d,
|
|
224
|
-
challengerPubkey:
|
|
225
|
-
claimerPubkey:
|
|
227
|
+
challengerPubkey: c,
|
|
228
|
+
claimerPubkey: o,
|
|
226
229
|
localChallengers: a,
|
|
227
230
|
assertTxParsed: l,
|
|
228
231
|
ctx: r
|
|
229
232
|
});
|
|
230
|
-
n.push(P),
|
|
233
|
+
n.push(P), s.push(
|
|
231
234
|
R(
|
|
232
235
|
t,
|
|
233
|
-
|
|
236
|
+
H
|
|
234
237
|
)
|
|
235
238
|
), u.push({
|
|
236
|
-
challengerPubkey:
|
|
237
|
-
noPayoutIdx:
|
|
239
|
+
challengerPubkey: c,
|
|
240
|
+
noPayoutIdx: g
|
|
238
241
|
});
|
|
239
242
|
}
|
|
240
|
-
return { psbtHexes: n, signOptions:
|
|
243
|
+
return { psbtHexes: n, signOptions: s, challengerEntries: u };
|
|
241
244
|
}
|
|
242
245
|
async function xe(e) {
|
|
243
246
|
const {
|
|
244
247
|
challenger: t,
|
|
245
248
|
challengerPubkey: r,
|
|
246
249
|
claimerPubkey: n,
|
|
247
|
-
localChallengers:
|
|
250
|
+
localChallengers: s,
|
|
248
251
|
assertTxParsed: u,
|
|
249
252
|
ctx: a
|
|
250
253
|
} = e;
|
|
251
|
-
|
|
254
|
+
ie(
|
|
252
255
|
t.nopayout_tx.tx_hex,
|
|
253
256
|
r,
|
|
254
257
|
a.network
|
|
255
258
|
);
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
),
|
|
259
|
-
|
|
259
|
+
const i = T.fromHex(
|
|
260
|
+
h(t.nopayout_tx.tx_hex)
|
|
261
|
+
), o = T.fromHex(
|
|
262
|
+
h(t.challenge_assert_x_tx.tx_hex)
|
|
260
263
|
), l = T.fromHex(
|
|
261
|
-
|
|
264
|
+
h(t.challenge_assert_y_tx.tx_hex)
|
|
262
265
|
);
|
|
263
|
-
if (
|
|
266
|
+
if (i.ins.length !== 3)
|
|
264
267
|
throw new Error(
|
|
265
|
-
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${
|
|
268
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
266
269
|
);
|
|
267
270
|
B(
|
|
268
|
-
|
|
271
|
+
i,
|
|
269
272
|
0,
|
|
270
273
|
u,
|
|
271
274
|
"Assert",
|
|
272
275
|
r
|
|
273
276
|
), B(
|
|
274
|
-
|
|
277
|
+
i,
|
|
275
278
|
1,
|
|
276
|
-
|
|
279
|
+
o,
|
|
277
280
|
"ChallengeAssertX",
|
|
278
281
|
r
|
|
279
282
|
), B(
|
|
280
|
-
|
|
283
|
+
i,
|
|
281
284
|
2,
|
|
282
285
|
l,
|
|
283
286
|
"ChallengeAssertY",
|
|
@@ -285,19 +288,19 @@ async function xe(e) {
|
|
|
285
288
|
);
|
|
286
289
|
const d = [
|
|
287
290
|
u.outs[0],
|
|
288
|
-
|
|
291
|
+
o.outs[0],
|
|
289
292
|
l.outs[0]
|
|
290
|
-
].map((
|
|
291
|
-
script_pubkey: N(new Uint8Array(
|
|
292
|
-
value:
|
|
293
|
+
].map((c) => ({
|
|
294
|
+
script_pubkey: N(new Uint8Array(c.script)),
|
|
295
|
+
value: c.value
|
|
293
296
|
}));
|
|
294
|
-
return
|
|
297
|
+
return ue({
|
|
295
298
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
296
299
|
challengerPubkey: r,
|
|
297
300
|
prevouts: d,
|
|
298
301
|
connectorParams: {
|
|
299
302
|
claimer: n,
|
|
300
|
-
localChallengers:
|
|
303
|
+
localChallengers: s,
|
|
301
304
|
universalChallengers: a.universalChallengerBtcPubkeys,
|
|
302
305
|
timelockAssert: a.timelockAssert,
|
|
303
306
|
councilMembers: a.councilMembers,
|
|
@@ -306,14 +309,15 @@ async function xe(e) {
|
|
|
306
309
|
});
|
|
307
310
|
}
|
|
308
311
|
function ke(e, t, r) {
|
|
309
|
-
|
|
310
|
-
|
|
312
|
+
V(e[0]);
|
|
313
|
+
const n = I(
|
|
314
|
+
e[0].returnedPsbtHex,
|
|
311
315
|
r
|
|
312
|
-
),
|
|
316
|
+
), s = {};
|
|
313
317
|
for (const u of t)
|
|
314
|
-
|
|
315
|
-
nopayout_signature:
|
|
316
|
-
e[u.noPayoutIdx],
|
|
318
|
+
V(e[u.noPayoutIdx]), s[u.challengerPubkey] = {
|
|
319
|
+
nopayout_signature: I(
|
|
320
|
+
e[u.noPayoutIdx].returnedPsbtHex,
|
|
317
321
|
r
|
|
318
322
|
)
|
|
319
323
|
};
|
|
@@ -321,78 +325,74 @@ function ke(e, t, r) {
|
|
|
321
325
|
payout_signatures: {
|
|
322
326
|
payout_signature: n
|
|
323
327
|
},
|
|
324
|
-
per_challenger:
|
|
328
|
+
per_challenger: s
|
|
325
329
|
};
|
|
326
330
|
}
|
|
327
331
|
async function Te(e, t, r) {
|
|
328
332
|
if (typeof e.signPsbts == "function")
|
|
329
333
|
return e.signPsbts(t, r);
|
|
330
334
|
const n = [];
|
|
331
|
-
for (let
|
|
332
|
-
n.push(await e.signPsbt(t[
|
|
335
|
+
for (let s = 0; s < t.length; s++)
|
|
336
|
+
n.push(await e.signPsbt(t[s], r == null ? void 0 : r[s]));
|
|
333
337
|
return n;
|
|
334
338
|
}
|
|
335
339
|
async function Ee(e) {
|
|
336
|
-
const { depositorGraph: t, btcWallet: r, signingContext: n } = e,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
), { psbtHexes: a, signOptions:
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, s = await r.getPublicKeyHex(), { depositorPubkey: u } = q(
|
|
341
|
+
s,
|
|
342
|
+
h(n.depositorBtcPubkey)
|
|
343
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: o } = await ve(
|
|
340
344
|
t,
|
|
341
|
-
|
|
345
|
+
s,
|
|
342
346
|
n
|
|
343
347
|
), l = await Te(
|
|
344
348
|
r,
|
|
345
349
|
a,
|
|
346
|
-
|
|
350
|
+
i
|
|
347
351
|
);
|
|
348
352
|
if (l.length !== a.length)
|
|
349
353
|
throw new Error(
|
|
350
354
|
`Wallet returned ${l.length} signed PSBTs, expected ${a.length}`
|
|
351
355
|
);
|
|
356
|
+
const d = a.map((c, g) => ({
|
|
357
|
+
requestedPsbtHex: c,
|
|
358
|
+
returnedPsbtHex: l[g]
|
|
359
|
+
}));
|
|
352
360
|
return ke(
|
|
353
|
-
|
|
354
|
-
|
|
361
|
+
d,
|
|
362
|
+
o,
|
|
355
363
|
u
|
|
356
364
|
);
|
|
357
365
|
}
|
|
358
|
-
const _e = 1200 * 1e3,
|
|
366
|
+
const _e = 1200 * 1e3, M = /* @__PURE__ */ new Set([
|
|
359
367
|
x.PENDING_ACKS,
|
|
360
368
|
x.PENDING_ACTIVATION,
|
|
361
369
|
x.ACTIVATED
|
|
362
|
-
]),
|
|
370
|
+
]), Ce = /* @__PURE__ */ new Set([
|
|
363
371
|
x.PENDING_DEPOSITOR_SIGNATURES,
|
|
364
|
-
...
|
|
372
|
+
...M
|
|
365
373
|
]);
|
|
366
|
-
function
|
|
374
|
+
function Se(e) {
|
|
367
375
|
return e.map((t) => ({
|
|
368
376
|
claimerPubkeyXOnly: k(t.claimer_pubkey),
|
|
369
377
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
370
378
|
assertTxHex: t.assert_tx.tx_hex
|
|
371
379
|
}));
|
|
372
380
|
}
|
|
373
|
-
function Be(e) {
|
|
374
|
-
const
|
|
375
|
-
internalPubkey: oe.from(e, "hex")
|
|
376
|
-
});
|
|
377
|
-
if (!t)
|
|
378
|
-
throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
|
|
379
|
-
return t.toString("hex");
|
|
380
|
-
}
|
|
381
|
-
function Ae(e, t) {
|
|
382
|
-
const r = c(e).toLowerCase(), n = c(
|
|
381
|
+
function Be(e, t) {
|
|
382
|
+
const r = h(e).toLowerCase(), n = h(
|
|
383
383
|
t.vaultProviderBtcPubkey
|
|
384
|
-
).toLowerCase(),
|
|
384
|
+
).toLowerCase(), s = h(
|
|
385
385
|
t.depositorBtcPubkey
|
|
386
386
|
).toLowerCase();
|
|
387
|
-
if (r === n || r ===
|
|
387
|
+
if (r === n || r === s)
|
|
388
388
|
return t.registeredPayoutScriptPubKey;
|
|
389
389
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
390
|
-
(
|
|
390
|
+
(a) => h(a).toLowerCase() === r
|
|
391
391
|
))
|
|
392
392
|
throw new Error(
|
|
393
393
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
394
394
|
);
|
|
395
|
-
return
|
|
395
|
+
return J(r);
|
|
396
396
|
}
|
|
397
397
|
function K(e, t) {
|
|
398
398
|
return {
|
|
@@ -404,80 +404,80 @@ function K(e, t) {
|
|
|
404
404
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
405
405
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
406
406
|
timelockPegin: t.timelockPegin,
|
|
407
|
-
registeredPayoutScriptPubKey:
|
|
407
|
+
registeredPayoutScriptPubKey: Be(
|
|
408
408
|
e.claimerPubkeyXOnly,
|
|
409
409
|
t
|
|
410
410
|
)
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
-
async function
|
|
414
|
-
const
|
|
413
|
+
async function Ae(e, t, r, n) {
|
|
414
|
+
const s = new ee({
|
|
415
415
|
network: t.network,
|
|
416
416
|
btcWallet: e
|
|
417
417
|
}), u = r.length;
|
|
418
418
|
n == null || n(0, u);
|
|
419
419
|
let a;
|
|
420
|
-
if (
|
|
421
|
-
a = (await
|
|
420
|
+
if (s.supportsBatchSigning())
|
|
421
|
+
a = (await s.signPayoutTransactionsBatch(
|
|
422
422
|
r.map((l) => K(l, t))
|
|
423
423
|
)).map((l) => l.payoutSignature);
|
|
424
424
|
else {
|
|
425
425
|
a = [];
|
|
426
|
-
for (let
|
|
427
|
-
n == null || n(
|
|
428
|
-
const l = await
|
|
429
|
-
K(r[
|
|
426
|
+
for (let o = 0; o < r.length; o++) {
|
|
427
|
+
n == null || n(o, u);
|
|
428
|
+
const l = await s.signPayoutTransaction(
|
|
429
|
+
K(r[o], t)
|
|
430
430
|
);
|
|
431
431
|
a.push(l.signature);
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
|
-
const
|
|
435
|
-
for (let
|
|
436
|
-
|
|
437
|
-
payout_signature: a[
|
|
434
|
+
const i = {};
|
|
435
|
+
for (let o = 0; o < r.length; o++)
|
|
436
|
+
i[r[o].claimerPubkeyXOnly] = {
|
|
437
|
+
payout_signature: a[o]
|
|
438
438
|
};
|
|
439
|
-
return n == null || n(u, u),
|
|
439
|
+
return n == null || n(u, u), i;
|
|
440
440
|
}
|
|
441
|
-
async function
|
|
441
|
+
async function nt(e) {
|
|
442
442
|
const {
|
|
443
443
|
statusReader: t,
|
|
444
444
|
presignClient: r,
|
|
445
445
|
btcWallet: n,
|
|
446
|
-
peginTxid:
|
|
446
|
+
peginTxid: s,
|
|
447
447
|
depositorPk: u,
|
|
448
448
|
signingContext: a,
|
|
449
|
-
timeoutMs:
|
|
450
|
-
signal:
|
|
449
|
+
timeoutMs: i = _e,
|
|
450
|
+
signal: o,
|
|
451
451
|
onProgress: l
|
|
452
|
-
} = e, d = await
|
|
452
|
+
} = e, d = await D({
|
|
453
453
|
statusReader: t,
|
|
454
|
-
peginTxid:
|
|
455
|
-
targetStatuses:
|
|
456
|
-
timeoutMs:
|
|
457
|
-
signal:
|
|
454
|
+
peginTxid: s,
|
|
455
|
+
targetStatuses: Ce,
|
|
456
|
+
timeoutMs: i,
|
|
457
|
+
signal: o
|
|
458
458
|
});
|
|
459
|
-
if (
|
|
459
|
+
if (M.has(d))
|
|
460
460
|
return;
|
|
461
|
-
|
|
462
|
-
const
|
|
461
|
+
o == null || o.throwIfAborted();
|
|
462
|
+
const c = await r.requestDepositorPresignTransactions(
|
|
463
463
|
{
|
|
464
|
-
pegin_txid:
|
|
464
|
+
pegin_txid: s,
|
|
465
465
|
depositor_pk: u
|
|
466
466
|
},
|
|
467
|
-
|
|
467
|
+
o
|
|
468
468
|
);
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
(v) => k(v.claimer_pubkey) !==
|
|
472
|
-
), b =
|
|
469
|
+
o == null || o.throwIfAborted();
|
|
470
|
+
const g = k(u), P = c.txs.filter(
|
|
471
|
+
(v) => k(v.claimer_pubkey) !== g
|
|
472
|
+
), b = Se(P), f = await Ae(
|
|
473
473
|
n,
|
|
474
474
|
a,
|
|
475
475
|
b,
|
|
476
476
|
l
|
|
477
477
|
);
|
|
478
|
-
|
|
479
|
-
const
|
|
480
|
-
depositorGraph:
|
|
478
|
+
o == null || o.throwIfAborted();
|
|
479
|
+
const y = await Ee({
|
|
480
|
+
depositorGraph: c.depositor_graph,
|
|
481
481
|
btcWallet: n,
|
|
482
482
|
signingContext: {
|
|
483
483
|
peginTxHex: a.peginTxHex,
|
|
@@ -493,33 +493,33 @@ async function at(e) {
|
|
|
493
493
|
registeredPayoutScriptPubKey: a.registeredPayoutScriptPubKey
|
|
494
494
|
}
|
|
495
495
|
});
|
|
496
|
-
|
|
496
|
+
o == null || o.throwIfAborted();
|
|
497
497
|
const w = { ...f };
|
|
498
|
-
w[
|
|
498
|
+
w[h(u)] = y.payout_signatures, await r.submitDepositorPresignatures(
|
|
499
499
|
{
|
|
500
|
-
pegin_txid:
|
|
500
|
+
pegin_txid: s,
|
|
501
501
|
depositor_pk: u,
|
|
502
502
|
signatures: w,
|
|
503
|
-
depositor_claimer_presignatures:
|
|
503
|
+
depositor_claimer_presignatures: y
|
|
504
504
|
},
|
|
505
|
-
|
|
505
|
+
o
|
|
506
506
|
);
|
|
507
507
|
}
|
|
508
|
-
function
|
|
508
|
+
function Re(e) {
|
|
509
509
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
510
510
|
}
|
|
511
|
-
function
|
|
511
|
+
function ot(e) {
|
|
512
512
|
const {
|
|
513
513
|
amountSats: t,
|
|
514
514
|
minDeposit: r,
|
|
515
515
|
maxDeposit: n,
|
|
516
|
-
btcBalance:
|
|
516
|
+
btcBalance: s,
|
|
517
517
|
estimatedFeeSats: u,
|
|
518
518
|
depositorClaimValue: a
|
|
519
519
|
} = e;
|
|
520
|
-
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a >
|
|
520
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > s);
|
|
521
521
|
}
|
|
522
|
-
function
|
|
522
|
+
function st(e, t, r) {
|
|
523
523
|
return e <= 0n ? {
|
|
524
524
|
valid: !1,
|
|
525
525
|
error: "Deposit amount must be greater than zero"
|
|
@@ -531,7 +531,7 @@ function it(e, t, r) {
|
|
|
531
531
|
error: `Maximum deposit is ${m(r)} BTC`
|
|
532
532
|
} : { valid: !0 };
|
|
533
533
|
}
|
|
534
|
-
function
|
|
534
|
+
function at(e) {
|
|
535
535
|
const { amount: t, effectiveRemaining: r } = e;
|
|
536
536
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
537
537
|
valid: !1,
|
|
@@ -541,212 +541,212 @@ function ut(e) {
|
|
|
541
541
|
error: `Vault size exceeds remaining capacity (${m(r)} BTC)`
|
|
542
542
|
} : { valid: !0 };
|
|
543
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function it(e, t) {
|
|
545
545
|
if (!e || e.length === 0)
|
|
546
546
|
return {
|
|
547
547
|
valid: !1,
|
|
548
548
|
error: "At least one vault provider must be selected"
|
|
549
549
|
};
|
|
550
550
|
const r = t.map(
|
|
551
|
-
(
|
|
551
|
+
(s) => s.toLowerCase()
|
|
552
552
|
);
|
|
553
553
|
return e.filter(
|
|
554
|
-
(
|
|
554
|
+
(s) => !r.includes(s.toLowerCase())
|
|
555
555
|
).length > 0 ? {
|
|
556
556
|
valid: !1,
|
|
557
557
|
error: "Invalid vault provider selected"
|
|
558
558
|
} : { valid: !0 };
|
|
559
559
|
}
|
|
560
|
-
function
|
|
560
|
+
function $e(e, t, r) {
|
|
561
561
|
if (!e || e.length === 0)
|
|
562
562
|
return {
|
|
563
563
|
valid: !1,
|
|
564
564
|
error: "At least one vault amount required"
|
|
565
565
|
};
|
|
566
566
|
for (let n = 0; n < e.length; n++) {
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
567
|
+
const s = e[n];
|
|
568
|
+
if (s <= 0n)
|
|
569
569
|
return {
|
|
570
570
|
valid: !1,
|
|
571
571
|
error: `Vault ${n + 1} amount must be positive`
|
|
572
572
|
};
|
|
573
|
-
if (t &&
|
|
573
|
+
if (t && s < t)
|
|
574
574
|
return {
|
|
575
575
|
valid: !1,
|
|
576
|
-
error: `Vault ${n + 1} amount ${m(
|
|
576
|
+
error: `Vault ${n + 1} amount ${m(s)} BTC is below minimum deposit ${m(t)} BTC`
|
|
577
577
|
};
|
|
578
|
-
if (r &&
|
|
578
|
+
if (r && s > r)
|
|
579
579
|
return {
|
|
580
580
|
valid: !1,
|
|
581
|
-
error: `Vault ${n + 1} amount ${m(
|
|
581
|
+
error: `Vault ${n + 1} amount ${m(s)} BTC exceeds maximum deposit ${m(r)} BTC`
|
|
582
582
|
};
|
|
583
583
|
}
|
|
584
584
|
return { valid: !0 };
|
|
585
585
|
}
|
|
586
|
-
function
|
|
587
|
-
const t =
|
|
588
|
-
return
|
|
586
|
+
function Ve(e) {
|
|
587
|
+
const t = h(e);
|
|
588
|
+
return Re(t) ? { valid: !0 } : {
|
|
589
589
|
valid: !1,
|
|
590
590
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
591
591
|
};
|
|
592
592
|
}
|
|
593
|
-
function
|
|
593
|
+
function Ie(e) {
|
|
594
594
|
if (!e || e.length === 0)
|
|
595
595
|
throw new Error(
|
|
596
596
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
597
597
|
);
|
|
598
598
|
}
|
|
599
|
-
function
|
|
599
|
+
function He(e) {
|
|
600
600
|
if (!e || e.length === 0)
|
|
601
601
|
throw new Error(
|
|
602
602
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
603
603
|
);
|
|
604
604
|
}
|
|
605
|
-
function
|
|
605
|
+
function Ke(e) {
|
|
606
606
|
if (e.length === 0)
|
|
607
607
|
throw new Error("No spendable UTXOs available");
|
|
608
608
|
}
|
|
609
|
-
function
|
|
609
|
+
function ut(e) {
|
|
610
610
|
const {
|
|
611
611
|
vaultAmounts: t,
|
|
612
612
|
confirmedUTXOs: r,
|
|
613
613
|
vaultProviderBtcPubkey: n,
|
|
614
|
-
vaultKeeperBtcPubkeys:
|
|
614
|
+
vaultKeeperBtcPubkeys: s,
|
|
615
615
|
universalChallengerBtcPubkeys: u,
|
|
616
616
|
minDeposit: a,
|
|
617
|
-
maxDeposit:
|
|
618
|
-
} = e,
|
|
617
|
+
maxDeposit: i
|
|
618
|
+
} = e, o = $e(
|
|
619
619
|
t,
|
|
620
620
|
a,
|
|
621
|
-
|
|
621
|
+
i
|
|
622
622
|
);
|
|
623
|
-
if (!
|
|
624
|
-
throw new Error(
|
|
625
|
-
const l =
|
|
623
|
+
if (!o.valid)
|
|
624
|
+
throw new Error(o.error);
|
|
625
|
+
const l = Ve(n);
|
|
626
626
|
if (!l.valid)
|
|
627
627
|
throw new Error(l.error);
|
|
628
|
-
|
|
628
|
+
Ie(s), He(u), Ke(r);
|
|
629
629
|
}
|
|
630
|
-
async function
|
|
630
|
+
async function lt(e) {
|
|
631
631
|
const {
|
|
632
632
|
vaultRegistryReader: t,
|
|
633
633
|
vaultKeeperReader: r,
|
|
634
634
|
universalChallengerReader: n,
|
|
635
|
-
vaultProviderEthAddress:
|
|
635
|
+
vaultProviderEthAddress: s,
|
|
636
636
|
applicationEntryPoint: u,
|
|
637
637
|
expectedVaultProviderBtcPubkey: a,
|
|
638
|
-
expectedVaultKeeperBtcPubkeys:
|
|
639
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
638
|
+
expectedVaultKeeperBtcPubkeys: i,
|
|
639
|
+
expectedUniversalChallengerBtcPubkeys: o
|
|
640
640
|
} = e, [
|
|
641
641
|
l,
|
|
642
642
|
d,
|
|
643
|
-
|
|
643
|
+
c
|
|
644
644
|
] = await Promise.all([
|
|
645
|
-
t.getVaultProviderBtcPubKey(
|
|
645
|
+
t.getVaultProviderBtcPubKey(s),
|
|
646
646
|
r.getCurrentVaultKeepersVersion(u),
|
|
647
647
|
n.getLatestUniversalChallengersVersion()
|
|
648
|
-
]), [
|
|
648
|
+
]), [g, P] = await Promise.all([
|
|
649
649
|
r.getVaultKeepersByVersion(
|
|
650
650
|
u,
|
|
651
651
|
d
|
|
652
652
|
),
|
|
653
653
|
n.getUniversalChallengersByVersion(
|
|
654
|
-
|
|
654
|
+
c
|
|
655
655
|
)
|
|
656
656
|
]), b = (p) => k(p).toLowerCase(), f = (p) => p.map(b).sort();
|
|
657
657
|
if (b(a) !== l)
|
|
658
658
|
throw new Error(
|
|
659
|
-
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${
|
|
659
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
|
|
660
660
|
);
|
|
661
|
-
const w = f(
|
|
662
|
-
|
|
661
|
+
const w = f(i), v = f(
|
|
662
|
+
g.map((p) => p.btcPubKey)
|
|
663
663
|
);
|
|
664
664
|
if (w.length !== v.length || w.some((p, _) => p !== v[_]))
|
|
665
665
|
throw new Error(
|
|
666
666
|
`Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
667
667
|
);
|
|
668
|
-
const $ = f(
|
|
668
|
+
const $ = f(o), E = f(
|
|
669
669
|
P.map((p) => p.btcPubKey)
|
|
670
670
|
);
|
|
671
671
|
if ($.length !== E.length || $.some((p, _) => p !== E[_]))
|
|
672
672
|
throw new Error(
|
|
673
|
-
`Universal challenger BTC pubkeys (v${
|
|
673
|
+
`Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
674
674
|
);
|
|
675
675
|
return {
|
|
676
676
|
vaultProviderBtcPubkeyXOnly: l,
|
|
677
677
|
vaultKeeperBtcPubkeysSorted: v,
|
|
678
678
|
universalChallengerBtcPubkeysSorted: E,
|
|
679
679
|
expectedAppVaultKeepersVersion: d,
|
|
680
|
-
expectedUniversalChallengersVersion:
|
|
680
|
+
expectedUniversalChallengersVersion: c
|
|
681
681
|
};
|
|
682
682
|
}
|
|
683
|
-
class
|
|
683
|
+
class U extends Error {
|
|
684
684
|
constructor(t) {
|
|
685
685
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
function
|
|
689
|
-
return e instanceof
|
|
688
|
+
function ct(e) {
|
|
689
|
+
return e instanceof U || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
690
690
|
}
|
|
691
|
-
async function
|
|
691
|
+
async function dt(e) {
|
|
692
692
|
const {
|
|
693
693
|
vaultRegistryReader: t,
|
|
694
694
|
vaultIds: r,
|
|
695
695
|
expectedOffchainParamsVersion: n,
|
|
696
|
-
expectedAppVaultKeepersVersion:
|
|
696
|
+
expectedAppVaultKeepersVersion: s,
|
|
697
697
|
expectedUniversalChallengersVersion: u
|
|
698
|
-
} = e, a = await t.getProtocolInfoBatch(r),
|
|
699
|
-
if (a.forEach((
|
|
698
|
+
} = e, a = await t.getProtocolInfoBatch(r), i = [];
|
|
699
|
+
if (a.forEach((o, l) => {
|
|
700
700
|
const d = r[l];
|
|
701
|
-
|
|
702
|
-
`vault ${d}: offchainParams expected v${n}, got v${
|
|
703
|
-
),
|
|
704
|
-
`vault ${d}: appVaultKeepers expected v${
|
|
705
|
-
),
|
|
706
|
-
`vault ${d}: universalChallengers expected v${u}, got v${
|
|
701
|
+
o.offchainParamsVersion !== n && i.push(
|
|
702
|
+
`vault ${d}: offchainParams expected v${n}, got v${o.offchainParamsVersion}`
|
|
703
|
+
), o.appVaultKeepersVersion !== s && i.push(
|
|
704
|
+
`vault ${d}: appVaultKeepers expected v${s}, got v${o.appVaultKeepersVersion}`
|
|
705
|
+
), o.universalChallengersVersion !== u && i.push(
|
|
706
|
+
`vault ${d}: universalChallengers expected v${u}, got v${o.universalChallengersVersion}`
|
|
707
707
|
);
|
|
708
|
-
}),
|
|
709
|
-
throw new
|
|
710
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
708
|
+
}), i.length > 0)
|
|
709
|
+
throw new U(
|
|
710
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
711
711
|
);
|
|
712
712
|
}
|
|
713
|
-
var
|
|
714
|
-
const
|
|
713
|
+
var F = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(F || {});
|
|
714
|
+
const Oe = /* @__PURE__ */ new Set([
|
|
715
715
|
"PayoutBroadcast",
|
|
716
716
|
"Failed"
|
|
717
717
|
/* FAILED */
|
|
718
718
|
]);
|
|
719
|
-
function
|
|
720
|
-
return Object.values(
|
|
719
|
+
function ht(e) {
|
|
720
|
+
return Object.values(F).includes(
|
|
721
721
|
e
|
|
722
722
|
);
|
|
723
723
|
}
|
|
724
|
-
function
|
|
725
|
-
return !!e &&
|
|
724
|
+
function pt(e) {
|
|
725
|
+
return !!e && Oe.has(e);
|
|
726
726
|
}
|
|
727
|
-
class
|
|
727
|
+
class Ne extends Error {
|
|
728
728
|
constructor(r, n) {
|
|
729
729
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
C(this, "vaultId");
|
|
731
|
+
C(this, "cause");
|
|
732
732
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
|
-
const
|
|
736
|
-
function
|
|
735
|
+
const Le = /^0x[0-9a-fA-F]{64}$/, De = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, X = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, z = 160;
|
|
736
|
+
function gt(e) {
|
|
737
737
|
if (!Number.isFinite(e) || e <= 0)
|
|
738
738
|
throw new Error(
|
|
739
739
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
740
740
|
);
|
|
741
|
-
return BigInt(Math.ceil(e *
|
|
741
|
+
return BigInt(Math.ceil(e * z));
|
|
742
742
|
}
|
|
743
|
-
const
|
|
744
|
-
function
|
|
743
|
+
const Me = 1, O = 65535, Ue = /non-BIP68-final/i;
|
|
744
|
+
function G(e, t) {
|
|
745
745
|
if (e.length !== 66)
|
|
746
746
|
throw new Error(
|
|
747
747
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
748
748
|
);
|
|
749
|
-
if (!
|
|
749
|
+
if (!Le.test(e))
|
|
750
750
|
throw new Error(
|
|
751
751
|
`${t} must contain only hex characters after the 0x prefix`
|
|
752
752
|
);
|
|
@@ -755,8 +755,8 @@ function A(e, t) {
|
|
|
755
755
|
if (!Number.isInteger(e) || e < 0)
|
|
756
756
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
757
757
|
}
|
|
758
|
-
function
|
|
759
|
-
if (
|
|
758
|
+
function Fe(e) {
|
|
759
|
+
if (G(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > O)
|
|
760
760
|
throw new Error(
|
|
761
761
|
`htlcVout must be an integer 0-${O}, got ${e.htlcVout}`
|
|
762
762
|
);
|
|
@@ -765,19 +765,19 @@ function Xe(e) {
|
|
|
765
765
|
"universalChallengersVersion"
|
|
766
766
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
767
767
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
768
|
-
if (!
|
|
768
|
+
if (!De.test(e.unsignedPrePeginTxHex))
|
|
769
769
|
throw new Error(
|
|
770
770
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
771
771
|
);
|
|
772
|
-
if (!e.depositorBtcPubkey || !
|
|
772
|
+
if (!e.depositorBtcPubkey || !X.test(e.depositorBtcPubkey))
|
|
773
773
|
throw new Error(
|
|
774
774
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
775
775
|
);
|
|
776
776
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
777
777
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
778
778
|
}
|
|
779
|
-
function
|
|
780
|
-
if (!e.vaultProviderPubkey || !
|
|
779
|
+
function Xe(e) {
|
|
780
|
+
if (!e.vaultProviderPubkey || !X.test(e.vaultProviderPubkey))
|
|
781
781
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
782
782
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
783
783
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -798,8 +798,8 @@ function ze(e) {
|
|
|
798
798
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
799
799
|
);
|
|
800
800
|
}
|
|
801
|
-
function
|
|
802
|
-
const t =
|
|
801
|
+
function ze(e) {
|
|
802
|
+
const t = oe.fromHex(e);
|
|
803
803
|
try {
|
|
804
804
|
t.finalizeAllInputs();
|
|
805
805
|
} catch (r) {
|
|
@@ -809,85 +809,85 @@ function Ge(e) {
|
|
|
809
809
|
}
|
|
810
810
|
return t.extractTransaction().toHex();
|
|
811
811
|
}
|
|
812
|
-
async function
|
|
812
|
+
async function ft(e) {
|
|
813
813
|
const {
|
|
814
814
|
vaultId: t,
|
|
815
815
|
readVault: r,
|
|
816
816
|
readPrePeginContext: n,
|
|
817
|
-
feeRate:
|
|
817
|
+
feeRate: s,
|
|
818
818
|
signPsbt: u,
|
|
819
819
|
broadcastTx: a,
|
|
820
|
-
signal:
|
|
820
|
+
signal: i
|
|
821
821
|
} = e;
|
|
822
|
-
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
const l = await n(
|
|
826
|
-
if (
|
|
827
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
828
|
-
const d = BigInt(Math.ceil(
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
), { psbtHex:
|
|
822
|
+
i == null || i.throwIfAborted(), G(t, "vaultId");
|
|
823
|
+
const o = await r();
|
|
824
|
+
Fe(o), i == null || i.throwIfAborted();
|
|
825
|
+
const l = await n(o);
|
|
826
|
+
if (Xe(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
827
|
+
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
828
|
+
const d = BigInt(Math.ceil(s * z));
|
|
829
|
+
i == null || i.throwIfAborted();
|
|
830
|
+
const c = k(
|
|
831
|
+
o.depositorBtcPubkey
|
|
832
|
+
), { psbtHex: g } = await le({
|
|
833
833
|
prePeginParams: {
|
|
834
|
-
depositorPubkey:
|
|
835
|
-
vaultProviderPubkey:
|
|
836
|
-
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(
|
|
837
|
-
universalChallengerPubkeys: l.universalChallengerPubkeys.map(
|
|
838
|
-
hashlocks: [
|
|
834
|
+
depositorPubkey: c,
|
|
835
|
+
vaultProviderPubkey: h(l.vaultProviderPubkey),
|
|
836
|
+
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(h),
|
|
837
|
+
universalChallengerPubkeys: l.universalChallengerPubkeys.map(h),
|
|
838
|
+
hashlocks: [h(o.hashlock)],
|
|
839
839
|
timelockRefund: l.timelockRefund,
|
|
840
|
-
pegInAmounts: [
|
|
840
|
+
pegInAmounts: [o.amount],
|
|
841
841
|
feeRate: l.feeRate,
|
|
842
842
|
numLocalChallengers: l.numLocalChallengers,
|
|
843
843
|
councilQuorum: l.councilQuorum,
|
|
844
844
|
councilSize: l.councilSize,
|
|
845
845
|
network: l.network
|
|
846
846
|
},
|
|
847
|
-
fundedPrePeginTxHex:
|
|
848
|
-
htlcVout:
|
|
847
|
+
fundedPrePeginTxHex: h(o.unsignedPrePeginTxHex),
|
|
848
|
+
htlcVout: o.htlcVout,
|
|
849
849
|
refundFee: d,
|
|
850
850
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
851
851
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
852
852
|
// value would derive the wrong refund script leaf and yield an
|
|
853
853
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
854
|
-
hashlock:
|
|
854
|
+
hashlock: h(o.hashlock)
|
|
855
855
|
});
|
|
856
|
-
|
|
856
|
+
i == null || i.throwIfAborted();
|
|
857
857
|
const P = R(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
), b = await u(
|
|
861
|
-
|
|
858
|
+
o.depositorBtcPubkey,
|
|
859
|
+
Me
|
|
860
|
+
), b = await u(g, P), f = ze(b);
|
|
861
|
+
i == null || i.throwIfAborted();
|
|
862
862
|
try {
|
|
863
863
|
return await a(f);
|
|
864
|
-
} catch (
|
|
865
|
-
throw
|
|
864
|
+
} catch (y) {
|
|
865
|
+
throw y instanceof Error && Ue.test(y.message) ? new Ne(t, y) : y;
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
export {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
869
|
+
Ne as B,
|
|
870
|
+
F as C,
|
|
871
|
+
U as R,
|
|
872
|
+
tt as a,
|
|
873
873
|
Ee as b,
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
874
|
+
at as c,
|
|
875
|
+
it as d,
|
|
876
|
+
$e as e,
|
|
877
|
+
Ve as f,
|
|
878
|
+
ut as g,
|
|
879
|
+
lt as h,
|
|
880
|
+
ot as i,
|
|
881
|
+
ct as j,
|
|
882
|
+
dt as k,
|
|
883
|
+
ht as l,
|
|
884
|
+
pt as m,
|
|
885
|
+
ft as n,
|
|
886
|
+
gt as o,
|
|
887
|
+
z as p,
|
|
888
|
+
nt as r,
|
|
889
|
+
rt as s,
|
|
890
|
+
st as v,
|
|
891
|
+
D as w
|
|
892
892
|
};
|
|
893
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
893
|
+
//# sourceMappingURL=buildAndBroadcastRefund-C1eOhIdo.js.map
|