@babylonlabs-io/ts-sdk 0.27.1 → 0.28.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/PeginManager-Da4uSHzl.cjs +2 -0
- package/dist/PeginManager-Da4uSHzl.cjs.map +1 -0
- package/dist/{context-ktqanzXE.js → PeginManager-DzMSIQ0I.js} +1100 -1058
- package/dist/PeginManager-DzMSIQ0I.js.map +1 -0
- package/dist/buildAndBroadcastRefund-DkEpTFkv.cjs +2 -0
- package/dist/buildAndBroadcastRefund-DkEpTFkv.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-BzYJv-Fv.js → buildAndBroadcastRefund-xWS8frc6.js} +338 -348
- package/dist/buildAndBroadcastRefund-xWS8frc6.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +55 -55
- package/dist/sha2-6wN58S6R.js +280 -0
- package/dist/sha2-6wN58S6R.js.map +1 -0
- package/dist/sha2-CsTynrfJ.cjs +2 -0
- package/dist/sha2-CsTynrfJ.cjs.map +1 -0
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/index.d.ts +2 -1
- package/dist/shared/wallets/index.d.ts.map +1 -1
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +8 -0
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
- package/dist/signing-BZigafm0.js.map +1 -1
- package/dist/signing-DHSXjhLM.cjs.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +80 -70
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +52 -52
- package/dist/tbv/core/managers/PeginManager.d.ts +64 -27
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.d.ts +1 -1
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validation.d.ts +0 -4
- package/dist/tbv/core/services/deposit/validation.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/vault-secrets/__tests__/deriveVaultRoot.test.d.ts +13 -0
- package/dist/tbv/core/vault-secrets/__tests__/deriveVaultRoot.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/context.d.ts +9 -0
- package/dist/tbv/core/vault-secrets/context.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts +56 -0
- package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/expand.d.ts +18 -3
- package/dist/tbv/core/vault-secrets/expand.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts +6 -3
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
- package/dist/tbv/core/wots/blockDerivation.d.ts +20 -24
- package/dist/tbv/core/wots/blockDerivation.d.ts.map +1 -1
- package/dist/tbv/core/wots/errors.d.ts +3 -1
- package/dist/tbv/core/wots/errors.d.ts.map +1 -1
- package/dist/tbv/core/wots/index.d.ts +1 -2
- package/dist/tbv/core/wots/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +52 -52
- package/dist/testing/MockBitcoinWallet.d.ts +10 -3
- 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 +67 -55
- package/dist/testing/index.js.map +1 -1
- package/dist/types-CnG3JsRs.js +680 -0
- package/dist/types-CnG3JsRs.js.map +1 -0
- package/dist/types-jmEyzzhY.cjs +2 -0
- package/dist/types-jmEyzzhY.cjs.map +1 -0
- package/dist/{vault-registry-reader-CpCOte7w.js → vault-registry-reader-BywZhqJL.js} +65 -64
- package/dist/{vault-registry-reader-CpCOte7w.js.map → vault-registry-reader-BywZhqJL.js.map} +1 -1
- package/dist/vault-registry-reader-DdruADqa.cjs +2 -0
- package/dist/{vault-registry-reader-BizmBSBV.cjs.map → vault-registry-reader-DdruADqa.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/buildAndBroadcastRefund-BEASMFsz.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BEASMFsz.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BzYJv-Fv.js.map +0 -1
- package/dist/context-B4fYDTxy.cjs +0 -2
- package/dist/context-B4fYDTxy.cjs.map +0 -1
- package/dist/context-ktqanzXE.js.map +0 -1
- package/dist/sha2-1XZuToHP.cjs +0 -2
- package/dist/sha2-1XZuToHP.cjs.map +0 -1
- package/dist/sha2-ZzfZqQSw.js +0 -1123
- package/dist/sha2-ZzfZqQSw.js.map +0 -1
- package/dist/tbv/core/wots/deriveWotsPkHash.d.ts +0 -9
- package/dist/tbv/core/wots/deriveWotsPkHash.d.ts.map +0 -1
- package/dist/vault-registry-reader-BizmBSBV.cjs +0 -2
|
@@ -1,182 +1,16 @@
|
|
|
1
1
|
var W = Object.defineProperty;
|
|
2
2
|
var X = (e, t, r) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
var y = (e, t, r) => X(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as G, c as Y, a as j, R as q, d as N, D as g } from "./types-CnG3JsRs.js";
|
|
5
|
+
import { e as Q, s as l, v as A, b as J, p as P, f } from "./bitcoin-B-Y0DlqR.js";
|
|
6
|
+
import { s as Z } from "./sha2-6wN58S6R.js";
|
|
6
7
|
import * as ee from "bitcoinjs-lib";
|
|
7
|
-
import {
|
|
8
|
+
import { Psbt as B, Transaction as te } from "bitcoinjs-lib";
|
|
8
9
|
import { Buffer as V } from "buffer";
|
|
9
|
-
import { c as
|
|
10
|
+
import { c as b } from "./signing-BZigafm0.js";
|
|
10
11
|
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new PayoutManager instance.
|
|
15
|
-
*
|
|
16
|
-
* @param config - Manager configuration including wallet
|
|
17
|
-
*/
|
|
18
|
-
constructor(t) {
|
|
19
|
-
P(this, "config");
|
|
20
|
-
this.config = t;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Signs a Payout transaction and extracts the Schnorr signature.
|
|
24
|
-
*
|
|
25
|
-
* Flow:
|
|
26
|
-
* 1. Vault provider submits Claim transaction
|
|
27
|
-
* 2. Claimer submits Assert transaction to prove validity
|
|
28
|
-
* 3. Payout can be executed (references Assert tx)
|
|
29
|
-
*
|
|
30
|
-
* This method orchestrates the following steps:
|
|
31
|
-
* 1. Get wallet's public key and convert to x-only format
|
|
32
|
-
* 2. Validate wallet pubkey matches on-chain depositor pubkey (if provided)
|
|
33
|
-
* 3. Build unsigned PSBT using primitives
|
|
34
|
-
* 4. Sign PSBT via btcWallet.signPsbt()
|
|
35
|
-
* 5. Extract 64-byte Schnorr signature using primitives
|
|
36
|
-
*
|
|
37
|
-
* The returned signature can be submitted to the vault provider API.
|
|
38
|
-
*
|
|
39
|
-
* @param params - Payout signing parameters
|
|
40
|
-
* @returns Signature result with 64-byte Schnorr signature and depositor pubkey
|
|
41
|
-
* @throws Error if wallet pubkey doesn't match depositor pubkey
|
|
42
|
-
* @throws Error if wallet operations fail or signature extraction fails
|
|
43
|
-
*/
|
|
44
|
-
async signPayoutTransaction(t) {
|
|
45
|
-
this.validatePayoutOutputs(
|
|
46
|
-
t.payoutTxHex,
|
|
47
|
-
t.registeredPayoutScriptPubKey
|
|
48
|
-
);
|
|
49
|
-
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: o } = A(
|
|
50
|
-
r,
|
|
51
|
-
t.depositorBtcPubkey
|
|
52
|
-
), s = await H({
|
|
53
|
-
payoutTxHex: t.payoutTxHex,
|
|
54
|
-
peginTxHex: t.peginTxHex,
|
|
55
|
-
assertTxHex: t.assertTxHex,
|
|
56
|
-
depositorBtcPubkey: o,
|
|
57
|
-
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
58
|
-
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
59
|
-
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
60
|
-
timelockPegin: t.timelockPegin,
|
|
61
|
-
network: this.config.network
|
|
62
|
-
}), c = await this.config.btcWallet.signPsbt(
|
|
63
|
-
s.psbtHex,
|
|
64
|
-
y(r, 1)
|
|
65
|
-
);
|
|
66
|
-
return {
|
|
67
|
-
signature: x(c, o),
|
|
68
|
-
depositorBtcPubkey: o
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the configured Bitcoin network.
|
|
73
|
-
*
|
|
74
|
-
* @returns The Bitcoin network (mainnet, testnet, signet, regtest)
|
|
75
|
-
*/
|
|
76
|
-
getNetwork() {
|
|
77
|
-
return this.config.network;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Checks if the wallet supports batch signing (signPsbts).
|
|
81
|
-
*
|
|
82
|
-
* @returns true if batch signing is supported
|
|
83
|
-
*/
|
|
84
|
-
supportsBatchSigning() {
|
|
85
|
-
return typeof this.config.btcWallet.signPsbts == "function";
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Batch signs multiple payout transactions (1 per claimer).
|
|
89
|
-
* This allows signing all transactions with a single wallet interaction.
|
|
90
|
-
*
|
|
91
|
-
* @param transactions - Array of payout params to sign
|
|
92
|
-
* @returns Array of signature results matching input order
|
|
93
|
-
* @throws Error if wallet doesn't support batch signing
|
|
94
|
-
* @throws Error if any signing operation fails
|
|
95
|
-
*/
|
|
96
|
-
async signPayoutTransactionsBatch(t) {
|
|
97
|
-
if (!this.supportsBatchSigning())
|
|
98
|
-
throw new Error(
|
|
99
|
-
"Wallet does not support batch signing (signPsbts method not available)"
|
|
100
|
-
);
|
|
101
|
-
const r = await this.config.btcWallet.getPublicKeyHex(), o = [], s = [], c = [];
|
|
102
|
-
for (const n of t) {
|
|
103
|
-
this.validatePayoutOutputs(
|
|
104
|
-
n.payoutTxHex,
|
|
105
|
-
n.registeredPayoutScriptPubKey
|
|
106
|
-
);
|
|
107
|
-
const { depositorPubkey: u } = A(
|
|
108
|
-
r,
|
|
109
|
-
n.depositorBtcPubkey
|
|
110
|
-
);
|
|
111
|
-
c.push(u);
|
|
112
|
-
const d = await H({
|
|
113
|
-
payoutTxHex: n.payoutTxHex,
|
|
114
|
-
peginTxHex: n.peginTxHex,
|
|
115
|
-
assertTxHex: n.assertTxHex,
|
|
116
|
-
depositorBtcPubkey: u,
|
|
117
|
-
vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
|
|
118
|
-
vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
|
|
119
|
-
universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
|
|
120
|
-
timelockPegin: n.timelockPegin,
|
|
121
|
-
network: this.config.network
|
|
122
|
-
});
|
|
123
|
-
o.push(d.psbtHex), s.push(y(r, 1));
|
|
124
|
-
}
|
|
125
|
-
const a = await this.config.btcWallet.signPsbts(
|
|
126
|
-
o,
|
|
127
|
-
s
|
|
128
|
-
);
|
|
129
|
-
if (a.length !== t.length)
|
|
130
|
-
throw new Error(
|
|
131
|
-
`Expected ${t.length} signed PSBTs but received ${a.length}`
|
|
132
|
-
);
|
|
133
|
-
const i = [];
|
|
134
|
-
for (let n = 0; n < t.length; n++) {
|
|
135
|
-
const u = c[n], d = x(
|
|
136
|
-
a[n],
|
|
137
|
-
u
|
|
138
|
-
);
|
|
139
|
-
i.push({
|
|
140
|
-
payoutSignature: d,
|
|
141
|
-
depositorBtcPubkey: u
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return i;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Validates that the payout transaction's largest output pays to the
|
|
148
|
-
* registered depositor payout address (scriptPubKey).
|
|
149
|
-
*
|
|
150
|
-
* This prevents two attack vectors from a malicious vault provider:
|
|
151
|
-
* 1. Substituting a completely different payout address
|
|
152
|
-
* 2. Including a dust output to the correct address while routing
|
|
153
|
-
* the actual funds to an attacker-controlled address
|
|
154
|
-
*
|
|
155
|
-
* @param payoutTxHex - Raw payout transaction hex
|
|
156
|
-
* @param registeredPayoutScriptPubKey - On-chain registered scriptPubKey (hex, with or without 0x prefix)
|
|
157
|
-
* @throws Error if scriptPubKey is invalid hex
|
|
158
|
-
* @throws Error if the largest output does not pay to the registered address
|
|
159
|
-
*/
|
|
160
|
-
validatePayoutOutputs(t, r) {
|
|
161
|
-
if (!J(r))
|
|
162
|
-
throw new Error(
|
|
163
|
-
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
164
|
-
);
|
|
165
|
-
const o = V.from(
|
|
166
|
-
l(r),
|
|
167
|
-
"hex"
|
|
168
|
-
), s = te.fromHex(l(t));
|
|
169
|
-
if (s.outs.length === 0)
|
|
170
|
-
throw new Error("Payout transaction has no outputs");
|
|
171
|
-
if (!s.outs.reduce(
|
|
172
|
-
(a, i) => i.value > a.value ? i : a
|
|
173
|
-
).script.equals(o))
|
|
174
|
-
throw new Error(
|
|
175
|
-
"Payout transaction does not pay to the registered depositor payout address"
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const I = 66;
|
|
12
|
+
import { e as w, a as I, b as re } from "./payout-B_fvQU3q.js";
|
|
13
|
+
const H = 66;
|
|
180
14
|
function L(e) {
|
|
181
15
|
if (!e.startsWith("0x") && !e.startsWith("0X"))
|
|
182
16
|
throw new Error("Expected 0x-prefixed hex string");
|
|
@@ -190,86 +24,86 @@ function L(e) {
|
|
|
190
24
|
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
191
25
|
return r;
|
|
192
26
|
}
|
|
193
|
-
function
|
|
27
|
+
function oe(e) {
|
|
194
28
|
return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
195
29
|
}
|
|
196
30
|
function S(e, t) {
|
|
197
|
-
if (e.length !==
|
|
31
|
+
if (e.length !== H)
|
|
198
32
|
throw new Error(
|
|
199
|
-
`${t} must be exactly 32 bytes (${
|
|
33
|
+
`${t} must be exactly 32 bytes (${H} hex chars with 0x prefix), got ${e.length}`
|
|
200
34
|
);
|
|
201
35
|
}
|
|
202
|
-
function
|
|
36
|
+
function ne(e) {
|
|
203
37
|
S(e, "Secret");
|
|
204
|
-
const t = L(e), r =
|
|
205
|
-
return
|
|
38
|
+
const t = L(e), r = Z(t);
|
|
39
|
+
return oe(r);
|
|
206
40
|
}
|
|
207
41
|
function ie(e, t) {
|
|
208
|
-
return S(e, "Secret"), S(t, "Hashlock"), L(t),
|
|
42
|
+
return S(e, "Secret"), S(t, "Hashlock"), L(t), ne(e).toLowerCase() === t.toLowerCase();
|
|
209
43
|
}
|
|
210
|
-
const
|
|
44
|
+
const se = /^0x[0-9a-fA-F]{64}$/, ae = /^0x[0-9a-fA-F]{40}$/, ue = /^0x([0-9a-fA-F]{2})*$/;
|
|
211
45
|
function E(e, t) {
|
|
212
46
|
if (e.length !== 66)
|
|
213
47
|
throw new Error(
|
|
214
48
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
215
49
|
);
|
|
216
|
-
if (!
|
|
50
|
+
if (!se.test(e))
|
|
217
51
|
throw new Error(
|
|
218
52
|
`${t} must contain only hex characters after the 0x prefix`
|
|
219
53
|
);
|
|
220
54
|
}
|
|
221
|
-
function
|
|
222
|
-
if (!
|
|
55
|
+
function ce(e, t) {
|
|
56
|
+
if (!ae.test(e))
|
|
223
57
|
throw new Error(
|
|
224
58
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
225
59
|
);
|
|
226
60
|
}
|
|
227
|
-
function
|
|
228
|
-
if (!
|
|
61
|
+
function le(e, t) {
|
|
62
|
+
if (!ue.test(e))
|
|
229
63
|
throw new Error(
|
|
230
64
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
231
65
|
);
|
|
232
66
|
}
|
|
233
|
-
async function
|
|
67
|
+
async function Je(e) {
|
|
234
68
|
const {
|
|
235
69
|
btcVaultRegistryAddress: t,
|
|
236
70
|
vaultId: r,
|
|
237
71
|
hashlock: o,
|
|
238
|
-
activationMetadata:
|
|
72
|
+
activationMetadata: i,
|
|
239
73
|
writeContract: c,
|
|
240
74
|
signal: a
|
|
241
75
|
} = e;
|
|
242
|
-
a == null || a.throwIfAborted(),
|
|
243
|
-
const
|
|
244
|
-
if (E(
|
|
76
|
+
a == null || a.throwIfAborted(), ce(t, "btcVaultRegistryAddress"), E(r, "vaultId");
|
|
77
|
+
const s = Q(e.secret);
|
|
78
|
+
if (E(s, "secret"), o !== void 0 && (E(o, "hashlock"), !ie(s, o)))
|
|
245
79
|
throw new Error(
|
|
246
80
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
247
81
|
);
|
|
248
|
-
return
|
|
82
|
+
return le(i, "activationMetadata"), c({
|
|
249
83
|
address: t,
|
|
250
|
-
abi:
|
|
84
|
+
abi: G,
|
|
251
85
|
functionName: "activateVaultWithSecret",
|
|
252
|
-
args: [r,
|
|
86
|
+
args: [r, s, i]
|
|
253
87
|
});
|
|
254
88
|
}
|
|
255
|
-
const
|
|
89
|
+
const de = 1e4;
|
|
256
90
|
async function D(e) {
|
|
257
91
|
const {
|
|
258
92
|
statusReader: t,
|
|
259
93
|
peginTxid: r,
|
|
260
94
|
targetStatuses: o,
|
|
261
|
-
timeoutMs:
|
|
262
|
-
pollIntervalMs: c =
|
|
95
|
+
timeoutMs: i,
|
|
96
|
+
pollIntervalMs: c = de,
|
|
263
97
|
signal: a
|
|
264
|
-
} = e,
|
|
98
|
+
} = e, s = Date.now();
|
|
265
99
|
for (; ; ) {
|
|
266
100
|
if (a != null && a.aborted)
|
|
267
101
|
throw new Error(
|
|
268
102
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
269
103
|
);
|
|
270
|
-
if (Date.now() -
|
|
104
|
+
if (Date.now() - s >= i)
|
|
271
105
|
throw new Error(
|
|
272
|
-
`Polling timeout after ${
|
|
106
|
+
`Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
273
107
|
);
|
|
274
108
|
try {
|
|
275
109
|
const u = (await t.getPeginStatus(
|
|
@@ -278,12 +112,12 @@ async function D(e) {
|
|
|
278
112
|
)).status;
|
|
279
113
|
if (o.has(u))
|
|
280
114
|
return u;
|
|
281
|
-
if (
|
|
115
|
+
if (Y.has(u) && !o.has(u))
|
|
282
116
|
throw new Error(
|
|
283
117
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...o].join(", ")}`
|
|
284
118
|
);
|
|
285
119
|
} catch (n) {
|
|
286
|
-
if (!(n instanceof
|
|
120
|
+
if (!(n instanceof j && n.code === q.NOT_FOUND || n instanceof Error && n.message.includes("PegIn not found")))
|
|
287
121
|
throw n;
|
|
288
122
|
}
|
|
289
123
|
await new Promise((n, u) => {
|
|
@@ -301,89 +135,89 @@ async function D(e) {
|
|
|
301
135
|
}
|
|
302
136
|
}
|
|
303
137
|
const pe = 300 * 1e3, fe = /* @__PURE__ */ new Set([
|
|
304
|
-
|
|
138
|
+
g.PENDING_DEPOSITOR_WOTS_PK,
|
|
305
139
|
...N
|
|
306
140
|
]);
|
|
307
|
-
async function
|
|
141
|
+
async function Ze(e) {
|
|
308
142
|
const {
|
|
309
143
|
statusReader: t,
|
|
310
144
|
wotsSubmitter: r,
|
|
311
145
|
peginTxid: o,
|
|
312
|
-
depositorPk:
|
|
146
|
+
depositorPk: i,
|
|
313
147
|
wotsPublicKeys: c,
|
|
314
148
|
timeoutMs: a = pe,
|
|
315
|
-
signal:
|
|
149
|
+
signal: s
|
|
316
150
|
} = e;
|
|
317
|
-
|
|
151
|
+
s == null || s.throwIfAborted();
|
|
318
152
|
const n = await D({
|
|
319
153
|
statusReader: t,
|
|
320
154
|
peginTxid: o,
|
|
321
155
|
targetStatuses: fe,
|
|
322
156
|
timeoutMs: a,
|
|
323
|
-
signal:
|
|
157
|
+
signal: s
|
|
324
158
|
});
|
|
325
|
-
N.has(n) || (
|
|
159
|
+
N.has(n) || (s == null || s.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
326
160
|
{
|
|
327
161
|
pegin_txid: o,
|
|
328
|
-
depositor_pk:
|
|
162
|
+
depositor_pk: i,
|
|
329
163
|
wots_public_keys: c
|
|
330
164
|
},
|
|
331
|
-
|
|
165
|
+
s
|
|
332
166
|
));
|
|
333
167
|
}
|
|
334
|
-
const
|
|
335
|
-
function
|
|
336
|
-
const o = B.fromBase64(e),
|
|
337
|
-
if (
|
|
168
|
+
const R = 1;
|
|
169
|
+
function he(e, t, r) {
|
|
170
|
+
const o = B.fromBase64(e), i = o.data.getTransaction().toString("hex").toLowerCase(), c = l(t).toLowerCase();
|
|
171
|
+
if (i !== c)
|
|
338
172
|
throw new Error(
|
|
339
173
|
`PSBT integrity check failed for ${r}: unsigned transaction does not match tx_hex`
|
|
340
174
|
);
|
|
341
175
|
return o;
|
|
342
176
|
}
|
|
343
|
-
function
|
|
177
|
+
function ge(e) {
|
|
344
178
|
const t = B.fromHex(e.toHex());
|
|
345
179
|
for (const r of t.data.inputs)
|
|
346
180
|
delete r.tapBip32Derivation, delete r.tapMerkleRoot;
|
|
347
181
|
return t;
|
|
348
182
|
}
|
|
349
|
-
function
|
|
183
|
+
function $(e, t, r) {
|
|
350
184
|
if (!e)
|
|
351
185
|
throw new Error(`Missing ${r} PSBT`);
|
|
352
|
-
const o =
|
|
353
|
-
return
|
|
186
|
+
const o = he(e, t, r);
|
|
187
|
+
return ge(o).toHex();
|
|
354
188
|
}
|
|
355
|
-
function
|
|
356
|
-
const r = [], o = [],
|
|
189
|
+
function be(e, t) {
|
|
190
|
+
const r = [], o = [], i = [], c = $(
|
|
357
191
|
e.payout_psbt,
|
|
358
192
|
e.payout_tx.tx_hex,
|
|
359
193
|
"depositor payout"
|
|
360
194
|
);
|
|
361
195
|
r.push(c), o.push(
|
|
362
|
-
|
|
196
|
+
b(t, R)
|
|
363
197
|
);
|
|
364
198
|
for (const a of e.challenger_presign_data) {
|
|
365
|
-
const
|
|
199
|
+
const s = l(a.challenger_pubkey), n = r.length, u = $(
|
|
366
200
|
a.nopayout_psbt,
|
|
367
201
|
a.nopayout_tx.tx_hex,
|
|
368
|
-
`nopayout (challenger ${
|
|
202
|
+
`nopayout (challenger ${s})`
|
|
369
203
|
);
|
|
370
204
|
r.push(u), o.push(
|
|
371
|
-
|
|
372
|
-
),
|
|
373
|
-
challengerPubkey:
|
|
205
|
+
b(t, R)
|
|
206
|
+
), i.push({
|
|
207
|
+
challengerPubkey: s,
|
|
374
208
|
noPayoutIdx: n
|
|
375
209
|
});
|
|
376
210
|
}
|
|
377
|
-
return { psbtHexes: r, signOptions: o, challengerEntries:
|
|
211
|
+
return { psbtHexes: r, signOptions: o, challengerEntries: i };
|
|
378
212
|
}
|
|
379
|
-
function
|
|
380
|
-
const o =
|
|
213
|
+
function ye(e, t, r) {
|
|
214
|
+
const o = w(
|
|
381
215
|
e[0],
|
|
382
216
|
r
|
|
383
|
-
),
|
|
217
|
+
), i = {};
|
|
384
218
|
for (const c of t)
|
|
385
|
-
|
|
386
|
-
nopayout_signature:
|
|
219
|
+
i[c.challengerPubkey] = {
|
|
220
|
+
nopayout_signature: w(
|
|
387
221
|
e[c.noPayoutIdx],
|
|
388
222
|
r
|
|
389
223
|
)
|
|
@@ -392,44 +226,211 @@ function Pe(e, t, r) {
|
|
|
392
226
|
payout_signatures: {
|
|
393
227
|
payout_signature: o
|
|
394
228
|
},
|
|
395
|
-
per_challenger:
|
|
229
|
+
per_challenger: i
|
|
396
230
|
};
|
|
397
231
|
}
|
|
398
|
-
async function
|
|
232
|
+
async function Pe(e, t, r) {
|
|
399
233
|
if (typeof e.signPsbts == "function")
|
|
400
234
|
return e.signPsbts(t, r);
|
|
401
235
|
const o = [];
|
|
402
|
-
for (let
|
|
403
|
-
o.push(await e.signPsbt(t[
|
|
236
|
+
for (let i = 0; i < t.length; i++)
|
|
237
|
+
o.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
|
|
404
238
|
return o;
|
|
405
239
|
}
|
|
406
|
-
async function
|
|
407
|
-
const { depositorGraph: t, depositorBtcPubkey: r, btcWallet: o } = e,
|
|
240
|
+
async function we(e) {
|
|
241
|
+
const { depositorGraph: t, depositorBtcPubkey: r, btcWallet: o } = e, i = l(r), c = await o.getPublicKeyHex(), { psbtHexes: a, signOptions: s, challengerEntries: n } = be(t, c), u = await Pe(
|
|
408
242
|
o,
|
|
409
243
|
a,
|
|
410
|
-
|
|
244
|
+
s
|
|
411
245
|
);
|
|
412
246
|
if (u.length !== a.length)
|
|
413
247
|
throw new Error(
|
|
414
248
|
`Wallet returned ${u.length} signed PSBTs, expected ${a.length}`
|
|
415
249
|
);
|
|
416
|
-
return
|
|
250
|
+
return ye(
|
|
417
251
|
u,
|
|
418
252
|
n,
|
|
419
|
-
|
|
253
|
+
i
|
|
420
254
|
);
|
|
421
255
|
}
|
|
256
|
+
class xe {
|
|
257
|
+
/**
|
|
258
|
+
* Creates a new PayoutManager instance.
|
|
259
|
+
*
|
|
260
|
+
* @param config - Manager configuration including wallet
|
|
261
|
+
*/
|
|
262
|
+
constructor(t) {
|
|
263
|
+
y(this, "config");
|
|
264
|
+
this.config = t;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Signs a Payout transaction and extracts the Schnorr signature.
|
|
268
|
+
*
|
|
269
|
+
* Flow:
|
|
270
|
+
* 1. Vault provider submits Claim transaction
|
|
271
|
+
* 2. Claimer submits Assert transaction to prove validity
|
|
272
|
+
* 3. Payout can be executed (references Assert tx)
|
|
273
|
+
*
|
|
274
|
+
* This method orchestrates the following steps:
|
|
275
|
+
* 1. Get wallet's public key and convert to x-only format
|
|
276
|
+
* 2. Validate wallet pubkey matches on-chain depositor pubkey (if provided)
|
|
277
|
+
* 3. Build unsigned PSBT using primitives
|
|
278
|
+
* 4. Sign PSBT via btcWallet.signPsbt()
|
|
279
|
+
* 5. Extract 64-byte Schnorr signature using primitives
|
|
280
|
+
*
|
|
281
|
+
* The returned signature can be submitted to the vault provider API.
|
|
282
|
+
*
|
|
283
|
+
* @param params - Payout signing parameters
|
|
284
|
+
* @returns Signature result with 64-byte Schnorr signature and depositor pubkey
|
|
285
|
+
* @throws Error if wallet pubkey doesn't match depositor pubkey
|
|
286
|
+
* @throws Error if wallet operations fail or signature extraction fails
|
|
287
|
+
*/
|
|
288
|
+
async signPayoutTransaction(t) {
|
|
289
|
+
this.validatePayoutOutputs(
|
|
290
|
+
t.payoutTxHex,
|
|
291
|
+
t.registeredPayoutScriptPubKey
|
|
292
|
+
);
|
|
293
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: o } = A(
|
|
294
|
+
r,
|
|
295
|
+
t.depositorBtcPubkey
|
|
296
|
+
), i = await I({
|
|
297
|
+
payoutTxHex: t.payoutTxHex,
|
|
298
|
+
peginTxHex: t.peginTxHex,
|
|
299
|
+
assertTxHex: t.assertTxHex,
|
|
300
|
+
depositorBtcPubkey: o,
|
|
301
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
302
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
303
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
304
|
+
timelockPegin: t.timelockPegin,
|
|
305
|
+
network: this.config.network
|
|
306
|
+
}), c = await this.config.btcWallet.signPsbt(
|
|
307
|
+
i.psbtHex,
|
|
308
|
+
b(r, 1)
|
|
309
|
+
);
|
|
310
|
+
return {
|
|
311
|
+
signature: w(c, o),
|
|
312
|
+
depositorBtcPubkey: o
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Gets the configured Bitcoin network.
|
|
317
|
+
*
|
|
318
|
+
* @returns The Bitcoin network (mainnet, testnet, signet, regtest)
|
|
319
|
+
*/
|
|
320
|
+
getNetwork() {
|
|
321
|
+
return this.config.network;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Checks if the wallet supports batch signing (signPsbts).
|
|
325
|
+
*
|
|
326
|
+
* @returns true if batch signing is supported
|
|
327
|
+
*/
|
|
328
|
+
supportsBatchSigning() {
|
|
329
|
+
return typeof this.config.btcWallet.signPsbts == "function";
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Batch signs multiple payout transactions (1 per claimer).
|
|
333
|
+
* This allows signing all transactions with a single wallet interaction.
|
|
334
|
+
*
|
|
335
|
+
* @param transactions - Array of payout params to sign
|
|
336
|
+
* @returns Array of signature results matching input order
|
|
337
|
+
* @throws Error if wallet doesn't support batch signing
|
|
338
|
+
* @throws Error if any signing operation fails
|
|
339
|
+
*/
|
|
340
|
+
async signPayoutTransactionsBatch(t) {
|
|
341
|
+
if (!this.supportsBatchSigning())
|
|
342
|
+
throw new Error(
|
|
343
|
+
"Wallet does not support batch signing (signPsbts method not available)"
|
|
344
|
+
);
|
|
345
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), o = [], i = [], c = [];
|
|
346
|
+
for (const n of t) {
|
|
347
|
+
this.validatePayoutOutputs(
|
|
348
|
+
n.payoutTxHex,
|
|
349
|
+
n.registeredPayoutScriptPubKey
|
|
350
|
+
);
|
|
351
|
+
const { depositorPubkey: u } = A(
|
|
352
|
+
r,
|
|
353
|
+
n.depositorBtcPubkey
|
|
354
|
+
);
|
|
355
|
+
c.push(u);
|
|
356
|
+
const d = await I({
|
|
357
|
+
payoutTxHex: n.payoutTxHex,
|
|
358
|
+
peginTxHex: n.peginTxHex,
|
|
359
|
+
assertTxHex: n.assertTxHex,
|
|
360
|
+
depositorBtcPubkey: u,
|
|
361
|
+
vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
|
|
362
|
+
vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
|
|
363
|
+
universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
|
|
364
|
+
timelockPegin: n.timelockPegin,
|
|
365
|
+
network: this.config.network
|
|
366
|
+
});
|
|
367
|
+
o.push(d.psbtHex), i.push(b(r, 1));
|
|
368
|
+
}
|
|
369
|
+
const a = await this.config.btcWallet.signPsbts(
|
|
370
|
+
o,
|
|
371
|
+
i
|
|
372
|
+
);
|
|
373
|
+
if (a.length !== t.length)
|
|
374
|
+
throw new Error(
|
|
375
|
+
`Expected ${t.length} signed PSBTs but received ${a.length}`
|
|
376
|
+
);
|
|
377
|
+
const s = [];
|
|
378
|
+
for (let n = 0; n < t.length; n++) {
|
|
379
|
+
const u = c[n], d = w(
|
|
380
|
+
a[n],
|
|
381
|
+
u
|
|
382
|
+
);
|
|
383
|
+
s.push({
|
|
384
|
+
payoutSignature: d,
|
|
385
|
+
depositorBtcPubkey: u
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return s;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Validates that the payout transaction's largest output pays to the
|
|
392
|
+
* registered depositor payout address (scriptPubKey).
|
|
393
|
+
*
|
|
394
|
+
* This prevents two attack vectors from a malicious vault provider:
|
|
395
|
+
* 1. Substituting a completely different payout address
|
|
396
|
+
* 2. Including a dust output to the correct address while routing
|
|
397
|
+
* the actual funds to an attacker-controlled address
|
|
398
|
+
*
|
|
399
|
+
* @param payoutTxHex - Raw payout transaction hex
|
|
400
|
+
* @param registeredPayoutScriptPubKey - On-chain registered scriptPubKey (hex, with or without 0x prefix)
|
|
401
|
+
* @throws Error if scriptPubKey is invalid hex
|
|
402
|
+
* @throws Error if the largest output does not pay to the registered address
|
|
403
|
+
*/
|
|
404
|
+
validatePayoutOutputs(t, r) {
|
|
405
|
+
if (!J(r))
|
|
406
|
+
throw new Error(
|
|
407
|
+
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
408
|
+
);
|
|
409
|
+
const o = V.from(
|
|
410
|
+
l(r),
|
|
411
|
+
"hex"
|
|
412
|
+
), i = te.fromHex(l(t));
|
|
413
|
+
if (i.outs.length === 0)
|
|
414
|
+
throw new Error("Payout transaction has no outputs");
|
|
415
|
+
if (!i.outs.reduce(
|
|
416
|
+
(a, s) => s.value > a.value ? s : a
|
|
417
|
+
).script.equals(o))
|
|
418
|
+
throw new Error(
|
|
419
|
+
"Payout transaction does not pay to the registered depositor payout address"
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
422
423
|
const me = 1200 * 1e3, K = /* @__PURE__ */ new Set([
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
]),
|
|
427
|
-
|
|
424
|
+
g.PENDING_ACKS,
|
|
425
|
+
g.PENDING_ACTIVATION,
|
|
426
|
+
g.ACTIVATED
|
|
427
|
+
]), Te = /* @__PURE__ */ new Set([
|
|
428
|
+
g.PENDING_DEPOSITOR_SIGNATURES,
|
|
428
429
|
...K
|
|
429
430
|
]);
|
|
430
|
-
function
|
|
431
|
+
function ve(e) {
|
|
431
432
|
return e.map((t) => ({
|
|
432
|
-
claimerPubkeyXOnly:
|
|
433
|
+
claimerPubkeyXOnly: P(t.claimer_pubkey),
|
|
433
434
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
434
435
|
assertTxHex: t.assert_tx.tx_hex
|
|
435
436
|
}));
|
|
@@ -445,13 +446,13 @@ function Ee(e) {
|
|
|
445
446
|
function ke(e, t) {
|
|
446
447
|
const r = l(e).toLowerCase(), o = l(
|
|
447
448
|
t.vaultProviderBtcPubkey
|
|
448
|
-
).toLowerCase(),
|
|
449
|
+
).toLowerCase(), i = l(
|
|
449
450
|
t.depositorBtcPubkey
|
|
450
451
|
).toLowerCase();
|
|
451
|
-
if (r === o || r ===
|
|
452
|
+
if (r === o || r === i)
|
|
452
453
|
return t.registeredPayoutScriptPubKey;
|
|
453
454
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
454
|
-
(
|
|
455
|
+
(s) => l(s).toLowerCase() === r
|
|
455
456
|
))
|
|
456
457
|
throw new Error(
|
|
457
458
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
@@ -475,49 +476,49 @@ function C(e, t) {
|
|
|
475
476
|
};
|
|
476
477
|
}
|
|
477
478
|
async function Se(e, t, r, o) {
|
|
478
|
-
const
|
|
479
|
+
const i = new xe({
|
|
479
480
|
network: t.network,
|
|
480
481
|
btcWallet: e
|
|
481
482
|
}), c = r.length;
|
|
482
483
|
o == null || o(0, c);
|
|
483
484
|
let a;
|
|
484
|
-
if (
|
|
485
|
-
a = (await
|
|
485
|
+
if (i.supportsBatchSigning())
|
|
486
|
+
a = (await i.signPayoutTransactionsBatch(
|
|
486
487
|
r.map((u) => C(u, t))
|
|
487
488
|
)).map((u) => u.payoutSignature);
|
|
488
489
|
else {
|
|
489
490
|
a = [];
|
|
490
491
|
for (let n = 0; n < r.length; n++) {
|
|
491
492
|
o == null || o(n, c);
|
|
492
|
-
const u = await
|
|
493
|
+
const u = await i.signPayoutTransaction(
|
|
493
494
|
C(r[n], t)
|
|
494
495
|
);
|
|
495
496
|
a.push(u.signature);
|
|
496
497
|
}
|
|
497
498
|
}
|
|
498
|
-
const
|
|
499
|
+
const s = {};
|
|
499
500
|
for (let n = 0; n < r.length; n++)
|
|
500
|
-
|
|
501
|
+
s[r[n].claimerPubkeyXOnly] = {
|
|
501
502
|
payout_signature: a[n]
|
|
502
503
|
};
|
|
503
|
-
return o == null || o(c, c),
|
|
504
|
+
return o == null || o(c, c), s;
|
|
504
505
|
}
|
|
505
|
-
async function
|
|
506
|
+
async function et(e) {
|
|
506
507
|
const {
|
|
507
508
|
statusReader: t,
|
|
508
509
|
presignClient: r,
|
|
509
510
|
btcWallet: o,
|
|
510
|
-
peginTxid:
|
|
511
|
+
peginTxid: i,
|
|
511
512
|
depositorPk: c,
|
|
512
513
|
signingContext: a,
|
|
513
|
-
timeoutMs:
|
|
514
|
+
timeoutMs: s = me,
|
|
514
515
|
signal: n,
|
|
515
516
|
onProgress: u
|
|
516
517
|
} = e, d = await D({
|
|
517
518
|
statusReader: t,
|
|
518
|
-
peginTxid:
|
|
519
|
-
targetStatuses:
|
|
520
|
-
timeoutMs:
|
|
519
|
+
peginTxid: i,
|
|
520
|
+
targetStatuses: Te,
|
|
521
|
+
timeoutMs: s,
|
|
521
522
|
signal: n
|
|
522
523
|
});
|
|
523
524
|
if (K.has(d))
|
|
@@ -525,31 +526,31 @@ async function Ze(e) {
|
|
|
525
526
|
n == null || n.throwIfAborted();
|
|
526
527
|
const h = await r.requestDepositorPresignTransactions(
|
|
527
528
|
{
|
|
528
|
-
pegin_txid:
|
|
529
|
+
pegin_txid: i,
|
|
529
530
|
depositor_pk: c
|
|
530
531
|
},
|
|
531
532
|
n
|
|
532
533
|
);
|
|
533
534
|
n == null || n.throwIfAborted();
|
|
534
|
-
const
|
|
535
|
-
(z) =>
|
|
536
|
-
),
|
|
535
|
+
const x = P(c), m = h.txs.filter(
|
|
536
|
+
(z) => P(z.claimer_pubkey) !== x
|
|
537
|
+
), T = ve(m), v = await Se(
|
|
537
538
|
o,
|
|
538
539
|
a,
|
|
539
|
-
|
|
540
|
+
T,
|
|
540
541
|
u
|
|
541
542
|
);
|
|
542
543
|
n == null || n.throwIfAborted();
|
|
543
|
-
const p = await
|
|
544
|
+
const p = await we({
|
|
544
545
|
depositorGraph: h.depositor_graph,
|
|
545
546
|
depositorBtcPubkey: c,
|
|
546
547
|
btcWallet: o
|
|
547
548
|
});
|
|
548
549
|
n == null || n.throwIfAborted();
|
|
549
|
-
const _ = { ...
|
|
550
|
+
const _ = { ...v };
|
|
550
551
|
_[l(c)] = p.payout_signatures, await r.submitDepositorPresignatures(
|
|
551
552
|
{
|
|
552
|
-
pegin_txid:
|
|
553
|
+
pegin_txid: i,
|
|
553
554
|
depositor_pk: c,
|
|
554
555
|
signatures: _,
|
|
555
556
|
depositor_claimer_presignatures: p
|
|
@@ -560,18 +561,18 @@ async function Ze(e) {
|
|
|
560
561
|
function Be(e) {
|
|
561
562
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
562
563
|
}
|
|
563
|
-
function
|
|
564
|
+
function tt(e) {
|
|
564
565
|
const {
|
|
565
566
|
amountSats: t,
|
|
566
567
|
minDeposit: r,
|
|
567
568
|
maxDeposit: o,
|
|
568
|
-
btcBalance:
|
|
569
|
+
btcBalance: i,
|
|
569
570
|
estimatedFeeSats: c,
|
|
570
571
|
depositorClaimValue: a
|
|
571
572
|
} = e;
|
|
572
|
-
return !(t <= 0n || t < r || o && o > 0n && t > o || c == null || a == null || t + c + a >
|
|
573
|
+
return !(t <= 0n || t < r || o && o > 0n && t > o || c == null || a == null || t + c + a > i);
|
|
573
574
|
}
|
|
574
|
-
function
|
|
575
|
+
function rt(e, t, r) {
|
|
575
576
|
return e <= 0n ? {
|
|
576
577
|
valid: !1,
|
|
577
578
|
error: "Deposit amount must be greater than zero"
|
|
@@ -583,7 +584,7 @@ function tt(e, t, r) {
|
|
|
583
584
|
error: `Maximum deposit is ${f(r)} BTC`
|
|
584
585
|
} : { valid: !0 };
|
|
585
586
|
}
|
|
586
|
-
function
|
|
587
|
+
function ot(e) {
|
|
587
588
|
const { amount: t, effectiveRemaining: r } = e;
|
|
588
589
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
589
590
|
valid: !1,
|
|
@@ -593,17 +594,17 @@ function rt(e) {
|
|
|
593
594
|
error: `Vault size exceeds remaining capacity (${f(r)} BTC)`
|
|
594
595
|
} : { valid: !0 };
|
|
595
596
|
}
|
|
596
|
-
function
|
|
597
|
+
function nt(e, t) {
|
|
597
598
|
if (!e || e.length === 0)
|
|
598
599
|
return {
|
|
599
600
|
valid: !1,
|
|
600
601
|
error: "At least one vault provider must be selected"
|
|
601
602
|
};
|
|
602
603
|
const r = t.map(
|
|
603
|
-
(
|
|
604
|
+
(i) => i.toLowerCase()
|
|
604
605
|
);
|
|
605
606
|
return e.filter(
|
|
606
|
-
(
|
|
607
|
+
(i) => !r.includes(i.toLowerCase())
|
|
607
608
|
).length > 0 ? {
|
|
608
609
|
valid: !1,
|
|
609
610
|
error: "Invalid vault provider selected"
|
|
@@ -616,21 +617,21 @@ function _e(e, t, r) {
|
|
|
616
617
|
error: "At least one vault amount required"
|
|
617
618
|
};
|
|
618
619
|
for (let o = 0; o < e.length; o++) {
|
|
619
|
-
const
|
|
620
|
-
if (
|
|
620
|
+
const i = e[o];
|
|
621
|
+
if (i <= 0n)
|
|
621
622
|
return {
|
|
622
623
|
valid: !1,
|
|
623
624
|
error: `Vault ${o + 1} amount must be positive`
|
|
624
625
|
};
|
|
625
|
-
if (t &&
|
|
626
|
+
if (t && i < t)
|
|
626
627
|
return {
|
|
627
628
|
valid: !1,
|
|
628
|
-
error: `Vault ${o + 1} amount ${f(
|
|
629
|
+
error: `Vault ${o + 1} amount ${f(i)} BTC is below minimum deposit ${f(t)} BTC`
|
|
629
630
|
};
|
|
630
|
-
if (r &&
|
|
631
|
+
if (r && i > r)
|
|
631
632
|
return {
|
|
632
633
|
valid: !1,
|
|
633
|
-
error: `Vault ${o + 1} amount ${f(
|
|
634
|
+
error: `Vault ${o + 1} amount ${f(i)} BTC exceeds maximum deposit ${f(r)} BTC`
|
|
634
635
|
};
|
|
635
636
|
}
|
|
636
637
|
return { valid: !0 };
|
|
@@ -642,56 +643,45 @@ function Ae(e) {
|
|
|
642
643
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
643
644
|
};
|
|
644
645
|
}
|
|
645
|
-
function
|
|
646
|
+
function Ie(e) {
|
|
646
647
|
if (!e || e.length === 0)
|
|
647
648
|
throw new Error(
|
|
648
649
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
649
650
|
);
|
|
650
651
|
}
|
|
651
|
-
function
|
|
652
|
+
function He(e) {
|
|
652
653
|
if (!e || e.length === 0)
|
|
653
654
|
throw new Error(
|
|
654
655
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
655
656
|
);
|
|
656
657
|
}
|
|
657
|
-
function
|
|
658
|
+
function Re(e) {
|
|
658
659
|
if (e.length === 0)
|
|
659
660
|
throw new Error("No spendable UTXOs available");
|
|
660
661
|
}
|
|
661
|
-
function
|
|
662
|
+
function it(e) {
|
|
662
663
|
const {
|
|
663
664
|
vaultAmounts: t,
|
|
664
665
|
confirmedUTXOs: r,
|
|
665
666
|
vaultProviderBtcPubkey: o,
|
|
666
|
-
vaultKeeperBtcPubkeys:
|
|
667
|
+
vaultKeeperBtcPubkeys: i,
|
|
667
668
|
universalChallengerBtcPubkeys: c,
|
|
668
669
|
minDeposit: a,
|
|
669
|
-
maxDeposit:
|
|
670
|
-
|
|
671
|
-
depositorSecretHashesLength: u
|
|
672
|
-
} = e, d = t.length;
|
|
673
|
-
if (n !== d)
|
|
674
|
-
throw new Error(
|
|
675
|
-
`htlcSecretHexes length (${n}) must match vaultAmounts length (${d})`
|
|
676
|
-
);
|
|
677
|
-
if (u !== d)
|
|
678
|
-
throw new Error(
|
|
679
|
-
`depositorSecretHashes length (${u}) must match vaultAmounts length (${d})`
|
|
680
|
-
);
|
|
681
|
-
const h = _e(
|
|
670
|
+
maxDeposit: s
|
|
671
|
+
} = e, n = _e(
|
|
682
672
|
t,
|
|
683
673
|
a,
|
|
684
|
-
|
|
674
|
+
s
|
|
685
675
|
);
|
|
686
|
-
if (!
|
|
687
|
-
throw new Error(
|
|
688
|
-
const
|
|
689
|
-
if (!
|
|
690
|
-
throw new Error(
|
|
691
|
-
|
|
676
|
+
if (!n.valid)
|
|
677
|
+
throw new Error(n.error);
|
|
678
|
+
const u = Ae(o);
|
|
679
|
+
if (!u.valid)
|
|
680
|
+
throw new Error(u.error);
|
|
681
|
+
Ie(i), He(c), Re(r);
|
|
692
682
|
}
|
|
693
683
|
var U = /* @__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))(U || {});
|
|
694
|
-
const
|
|
684
|
+
const $e = /* @__PURE__ */ new Set([
|
|
695
685
|
"PayoutBroadcast",
|
|
696
686
|
"Failed"
|
|
697
687
|
/* FAILED */
|
|
@@ -701,14 +691,14 @@ function st(e) {
|
|
|
701
691
|
e
|
|
702
692
|
);
|
|
703
693
|
}
|
|
704
|
-
function
|
|
705
|
-
return !!e &&
|
|
694
|
+
function at(e) {
|
|
695
|
+
return !!e && $e.has(e);
|
|
706
696
|
}
|
|
707
697
|
class Ce extends Error {
|
|
708
698
|
constructor(r, o) {
|
|
709
699
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
710
|
-
|
|
711
|
-
|
|
700
|
+
y(this, "vaultId");
|
|
701
|
+
y(this, "cause");
|
|
712
702
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
713
703
|
}
|
|
714
704
|
}
|
|
@@ -781,27 +771,27 @@ function Fe(e) {
|
|
|
781
771
|
}
|
|
782
772
|
return t.extractTransaction().toHex();
|
|
783
773
|
}
|
|
784
|
-
async function
|
|
774
|
+
async function ut(e) {
|
|
785
775
|
const {
|
|
786
776
|
vaultId: t,
|
|
787
777
|
readVault: r,
|
|
788
778
|
readPrePeginContext: o,
|
|
789
|
-
feeRate:
|
|
779
|
+
feeRate: i,
|
|
790
780
|
signPsbt: c,
|
|
791
781
|
broadcastTx: a,
|
|
792
|
-
signal:
|
|
782
|
+
signal: s
|
|
793
783
|
} = e;
|
|
794
|
-
|
|
784
|
+
s == null || s.throwIfAborted(), M(t, "vaultId");
|
|
795
785
|
const n = await r();
|
|
796
|
-
Ke(n),
|
|
786
|
+
Ke(n), s == null || s.throwIfAborted();
|
|
797
787
|
const u = await o(n);
|
|
798
|
-
if (Ue(u),
|
|
799
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
800
|
-
const d = BigInt(Math.ceil(
|
|
801
|
-
|
|
802
|
-
const h =
|
|
788
|
+
if (Ue(u), s == null || s.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
789
|
+
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
790
|
+
const d = BigInt(Math.ceil(i * Ve));
|
|
791
|
+
s == null || s.throwIfAborted();
|
|
792
|
+
const h = P(
|
|
803
793
|
n.depositorBtcPubkey
|
|
804
|
-
), { psbtHex:
|
|
794
|
+
), { psbtHex: x } = await re({
|
|
805
795
|
prePeginParams: {
|
|
806
796
|
depositorPubkey: h,
|
|
807
797
|
vaultProviderPubkey: l(u.vaultProviderPubkey),
|
|
@@ -825,14 +815,14 @@ async function at(e) {
|
|
|
825
815
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
826
816
|
hashlock: l(n.hashlock)
|
|
827
817
|
});
|
|
828
|
-
|
|
829
|
-
const m =
|
|
818
|
+
s == null || s.throwIfAborted();
|
|
819
|
+
const m = b(
|
|
830
820
|
n.depositorBtcPubkey,
|
|
831
821
|
Le
|
|
832
|
-
),
|
|
833
|
-
|
|
822
|
+
), T = await c(x, m), v = Fe(T);
|
|
823
|
+
s == null || s.throwIfAborted();
|
|
834
824
|
try {
|
|
835
|
-
return await a(
|
|
825
|
+
return await a(v);
|
|
836
826
|
} catch (p) {
|
|
837
827
|
throw p instanceof Error && De.test(p.message) ? new Ce(t, p) : p;
|
|
838
828
|
}
|
|
@@ -840,23 +830,23 @@ async function at(e) {
|
|
|
840
830
|
export {
|
|
841
831
|
Ce as B,
|
|
842
832
|
U as C,
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
833
|
+
xe as P,
|
|
834
|
+
Je as a,
|
|
835
|
+
we as b,
|
|
836
|
+
ot as c,
|
|
837
|
+
nt as d,
|
|
848
838
|
_e as e,
|
|
849
839
|
Ae as f,
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
840
|
+
it as g,
|
|
841
|
+
ne as h,
|
|
842
|
+
tt as i,
|
|
853
843
|
ie as j,
|
|
854
844
|
st as k,
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
845
|
+
at as l,
|
|
846
|
+
ut as m,
|
|
847
|
+
et as p,
|
|
848
|
+
Ze as s,
|
|
849
|
+
rt as v,
|
|
860
850
|
D as w
|
|
861
851
|
};
|
|
862
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
852
|
+
//# sourceMappingURL=buildAndBroadcastRefund-xWS8frc6.js.map
|