@babylonlabs-io/ts-sdk 0.3.0 → 0.4.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-BkOfdb2_.js → PayoutManager-BK1jKgL5.js} +405 -364
- package/dist/PayoutManager-BK1jKgL5.js.map +1 -0
- package/dist/PayoutManager-CzKMN6xT.cjs +2 -0
- package/dist/PayoutManager-CzKMN6xT.cjs.map +1 -0
- package/dist/challengeAssert-DOa5L0kv.cjs +2 -0
- package/dist/challengeAssert-DOa5L0kv.cjs.map +1 -0
- package/dist/challengeAssert-Dvcg38_y.js +606 -0
- package/dist/challengeAssert-Dvcg38_y.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +62 -58
- package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts +50 -4
- package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +62 -58
- package/dist/tbv/core/managers/PeginManager.d.ts +89 -48
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/__tests__/PeginManager.test.d.ts +1 -1
- package/dist/tbv/core/managers/index.d.ts +4 -4
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +5 -3
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +22 -18
- package/dist/tbv/core/primitives/psbt/__tests__/pegin.test.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/index.d.ts +8 -3
- package/dist/tbv/core/primitives/psbt/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +76 -59
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts +69 -0
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +11 -0
- 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/index.cjs +1 -1
- package/dist/tbv/index.js +62 -58
- package/dist/tbv/integrations/aave/clients/abis/AaveIntegrationController.abi.json.d.ts +16 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.js +3 -3
- package/package.json +3 -3
- package/dist/PayoutManager-BkOfdb2_.js.map +0 -1
- package/dist/PayoutManager-DZ7EIcAJ.cjs +0 -2
- package/dist/PayoutManager-DZ7EIcAJ.cjs.map +0 -1
- package/dist/challengeAssert-34HqeVFH.cjs +0 -2
- package/dist/challengeAssert-34HqeVFH.cjs.map +0 -1
- package/dist/challengeAssert-DVErOd8l.js +0 -423
- package/dist/challengeAssert-DVErOd8l.js.map +0 -1
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
import { createPrePeginTransaction as R, buildPeginTxFromPrePegin as W, getPrePeginHtlcConnectorInfo as F, tapInternalPubkey as k, createPayoutConnector as K, getPeginPayoutScript as q, getAssertNoPayoutScriptInfo as N, getChallengeAssertScriptInfo as M } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
2
|
+
import * as C from "bitcoinjs-lib";
|
|
3
|
+
import { payments as b, networks as T, initEccLib as I, Transaction as y, Psbt as w } from "bitcoinjs-lib";
|
|
4
|
+
import { Buffer as a } from "buffer";
|
|
5
|
+
import * as H from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
6
|
+
const ct = 58, ut = 43, at = 11, D = 546, z = BigInt(D), X = 30, Y = 2, lt = 1.1;
|
|
7
|
+
function pt(t) {
|
|
8
|
+
return t <= Y ? X : 0;
|
|
9
|
+
}
|
|
10
|
+
const ft = 5;
|
|
11
|
+
function h(t) {
|
|
12
|
+
return t.startsWith("0x") ? t.slice(2) : t;
|
|
13
|
+
}
|
|
14
|
+
function ht(t) {
|
|
15
|
+
return t.startsWith("0x") ? t : `0x${t}`;
|
|
16
|
+
}
|
|
17
|
+
function d(t) {
|
|
18
|
+
const n = h(t);
|
|
19
|
+
if (!A(n))
|
|
20
|
+
throw new Error(`Invalid hex string: ${t}`);
|
|
21
|
+
const e = new Uint8Array(n.length / 2);
|
|
22
|
+
for (let r = 0; r < n.length; r += 2)
|
|
23
|
+
e[r / 2] = parseInt(n.slice(r, r + 2), 16);
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
function x(t) {
|
|
27
|
+
return Array.from(t).map((n) => n.toString(16).padStart(2, "0")).join("");
|
|
28
|
+
}
|
|
29
|
+
function Q(t) {
|
|
30
|
+
return t.length === 32 ? t : t.slice(1, 33);
|
|
31
|
+
}
|
|
32
|
+
function A(t) {
|
|
33
|
+
return /^[0-9a-fA-F]*$/.test(t) && t.length % 2 === 0;
|
|
34
|
+
}
|
|
35
|
+
function _(t) {
|
|
36
|
+
const n = h(t);
|
|
37
|
+
if (!A(n))
|
|
38
|
+
throw new Error(`Invalid hex characters in public key: ${t}`);
|
|
39
|
+
if (n.length === 64)
|
|
40
|
+
return n;
|
|
41
|
+
if (n.length !== 66 && n.length !== 130)
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Invalid public key length: ${n.length} (expected 64, 66, or 130 hex chars)`
|
|
44
|
+
);
|
|
45
|
+
const e = d(n);
|
|
46
|
+
return x(Q(e));
|
|
47
|
+
}
|
|
48
|
+
function dt(t) {
|
|
49
|
+
const n = h(t);
|
|
50
|
+
return A(n);
|
|
51
|
+
}
|
|
52
|
+
function gt(t, n) {
|
|
53
|
+
const e = _(t), r = n ?? e;
|
|
54
|
+
if (e.toLowerCase() !== r.toLowerCase())
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Wallet public key does not match vault depositor. Expected: ${r}, Got: ${e}. Please connect the wallet that was used to create this vault.`
|
|
57
|
+
);
|
|
58
|
+
return { walletPubkeyRaw: t, walletPubkeyXOnly: e, depositorPubkey: r };
|
|
59
|
+
}
|
|
60
|
+
let U = !1;
|
|
61
|
+
function G() {
|
|
62
|
+
U || (I(H), U = !0);
|
|
63
|
+
}
|
|
64
|
+
function O(t) {
|
|
65
|
+
switch (t) {
|
|
66
|
+
case "bitcoin":
|
|
67
|
+
return T.bitcoin;
|
|
68
|
+
case "testnet":
|
|
69
|
+
case "signet":
|
|
70
|
+
return T.testnet;
|
|
71
|
+
case "regtest":
|
|
72
|
+
return T.regtest;
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`Unknown network: ${t}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function Z(t, n) {
|
|
78
|
+
G();
|
|
79
|
+
const e = d(_(t)), { address: r } = b.p2tr({
|
|
80
|
+
internalPubkey: a.from(e),
|
|
81
|
+
network: O(n)
|
|
82
|
+
});
|
|
83
|
+
if (!r)
|
|
84
|
+
throw new Error("Failed to derive taproot address from public key");
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
function j(t, n) {
|
|
88
|
+
const e = h(t);
|
|
89
|
+
if (e.length !== 66)
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Native SegWit requires a compressed public key (66 hex chars), got ${e.length}`
|
|
92
|
+
);
|
|
93
|
+
const { address: r } = b.p2wpkh({
|
|
94
|
+
pubkey: a.from(d(e)),
|
|
95
|
+
network: O(n)
|
|
96
|
+
});
|
|
97
|
+
if (!r)
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Failed to derive native segwit address from public key"
|
|
100
|
+
);
|
|
101
|
+
return r;
|
|
102
|
+
}
|
|
103
|
+
function Pt(t, n, e) {
|
|
104
|
+
const r = h(n);
|
|
105
|
+
try {
|
|
106
|
+
if (t === Z(r, e))
|
|
107
|
+
return !0;
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
const s = [];
|
|
111
|
+
r.length === 66 ? s.push(r) : r.length === 64 && s.push(`02${r}`, `03${r}`);
|
|
112
|
+
for (const o of s)
|
|
113
|
+
try {
|
|
114
|
+
if (t === j(o, e))
|
|
115
|
+
return !0;
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
return !1;
|
|
119
|
+
}
|
|
120
|
+
function V(t) {
|
|
121
|
+
const e = t.substring(8, 12) === "0001" ? 12 : 8, r = parseInt(
|
|
122
|
+
t.substring(e, e + 2),
|
|
123
|
+
16
|
|
124
|
+
), s = parseInt(
|
|
125
|
+
t.substring(e + 2, e + 4),
|
|
126
|
+
16
|
|
127
|
+
);
|
|
128
|
+
if (r !== 0)
|
|
129
|
+
throw new Error(`Expected 0 inputs from WASM, got ${r}`);
|
|
130
|
+
if (s === 0)
|
|
131
|
+
throw new Error("Expected at least 1 output from WASM, got 0");
|
|
132
|
+
const o = a.from(t.substring(0, 8), "hex").readUInt32LE(0), u = a.from(
|
|
133
|
+
t.substring(t.length - 8),
|
|
134
|
+
"hex"
|
|
135
|
+
).readUInt32LE(0), c = [];
|
|
136
|
+
let i = e + 4;
|
|
137
|
+
for (let p = 0; p < s; p++) {
|
|
138
|
+
const l = t.substring(i, i + 16), f = Number(a.from(l, "hex").readBigUInt64LE(0));
|
|
139
|
+
i += 16;
|
|
140
|
+
const g = parseInt(t.substring(i, i + 2), 16);
|
|
141
|
+
i += 2;
|
|
142
|
+
const P = t.substring(i, i + g * 2), v = a.from(P, "hex");
|
|
143
|
+
i += g * 2, c.push({ value: f, script: v });
|
|
144
|
+
}
|
|
145
|
+
return { version: o, locktime: u, outputs: c };
|
|
146
|
+
}
|
|
147
|
+
function yt(t) {
|
|
148
|
+
const { unfundedTxHex: n, selectedUTXOs: e, changeAddress: r, changeAmount: s, network: o } = t, { version: u, locktime: c, outputs: i } = V(n), p = new C.Transaction();
|
|
149
|
+
p.version = u, p.locktime = c;
|
|
150
|
+
for (const l of e) {
|
|
151
|
+
const f = a.from(l.txid, "hex").reverse();
|
|
152
|
+
p.addInput(f, l.vout);
|
|
153
|
+
}
|
|
154
|
+
for (const l of i)
|
|
155
|
+
p.addOutput(l.script, l.value);
|
|
156
|
+
if (s > z) {
|
|
157
|
+
const l = C.address.toOutputScript(r, o);
|
|
158
|
+
p.addOutput(l, Number(s));
|
|
159
|
+
}
|
|
160
|
+
return p.toHex();
|
|
161
|
+
}
|
|
162
|
+
async function xt(t) {
|
|
163
|
+
const n = await R({
|
|
164
|
+
depositorPubkey: t.depositorPubkey,
|
|
165
|
+
vaultProviderPubkey: t.vaultProviderPubkey,
|
|
166
|
+
vaultKeeperPubkeys: t.vaultKeeperPubkeys,
|
|
167
|
+
universalChallengerPubkeys: t.universalChallengerPubkeys,
|
|
168
|
+
hashH: t.hashH,
|
|
169
|
+
timelockRefund: t.timelockRefund,
|
|
170
|
+
pegInAmount: t.pegInAmount,
|
|
171
|
+
feeRate: t.feeRate,
|
|
172
|
+
numLocalChallengers: t.numLocalChallengers,
|
|
173
|
+
councilQuorum: t.councilQuorum,
|
|
174
|
+
councilSize: t.councilSize,
|
|
175
|
+
network: t.network
|
|
176
|
+
}), r = V(n.txHex).outputs.reduce(
|
|
177
|
+
(s, o) => s + BigInt(o.value),
|
|
178
|
+
0n
|
|
179
|
+
);
|
|
180
|
+
return {
|
|
181
|
+
psbtHex: n.txHex,
|
|
182
|
+
totalOutputValue: r,
|
|
183
|
+
htlcValue: n.htlcValue,
|
|
184
|
+
htlcScriptPubKey: n.htlcScriptPubKey,
|
|
185
|
+
htlcAddress: n.htlcAddress,
|
|
186
|
+
peginAmount: n.peginAmount,
|
|
187
|
+
depositorClaimValue: n.depositorClaimValue
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async function kt(t) {
|
|
191
|
+
const n = await W(
|
|
192
|
+
{
|
|
193
|
+
depositorPubkey: t.prePeginParams.depositorPubkey,
|
|
194
|
+
vaultProviderPubkey: t.prePeginParams.vaultProviderPubkey,
|
|
195
|
+
vaultKeeperPubkeys: t.prePeginParams.vaultKeeperPubkeys,
|
|
196
|
+
universalChallengerPubkeys: t.prePeginParams.universalChallengerPubkeys,
|
|
197
|
+
hashH: t.prePeginParams.hashH,
|
|
198
|
+
timelockRefund: t.prePeginParams.timelockRefund,
|
|
199
|
+
pegInAmount: t.prePeginParams.pegInAmount,
|
|
200
|
+
feeRate: t.prePeginParams.feeRate,
|
|
201
|
+
numLocalChallengers: t.prePeginParams.numLocalChallengers,
|
|
202
|
+
councilQuorum: t.prePeginParams.councilQuorum,
|
|
203
|
+
councilSize: t.prePeginParams.councilSize,
|
|
204
|
+
network: t.prePeginParams.network
|
|
205
|
+
},
|
|
206
|
+
t.timelockPegin,
|
|
207
|
+
t.fundedPrePeginTxid
|
|
208
|
+
);
|
|
209
|
+
return {
|
|
210
|
+
txHex: n.txHex,
|
|
211
|
+
txid: n.txid,
|
|
212
|
+
vaultScriptPubKey: n.vaultScriptPubKey,
|
|
213
|
+
vaultValue: n.vaultValue
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
async function wt(t) {
|
|
217
|
+
const n = h(t.peginTxHex), e = h(t.fundedPrePeginTxHex), r = await F({
|
|
218
|
+
depositorPubkey: t.depositorPubkey,
|
|
219
|
+
vaultProviderPubkey: t.vaultProviderPubkey,
|
|
220
|
+
vaultKeeperPubkeys: t.vaultKeeperPubkeys,
|
|
221
|
+
universalChallengerPubkeys: t.universalChallengerPubkeys,
|
|
222
|
+
hashH: t.hashH,
|
|
223
|
+
timelockRefund: t.timelockRefund,
|
|
224
|
+
network: t.network
|
|
225
|
+
}), s = y.fromHex(n), o = y.fromHex(e);
|
|
226
|
+
if (s.ins.length !== 1)
|
|
227
|
+
throw new Error(
|
|
228
|
+
`PegIn transaction must have exactly 1 input, got ${s.ins.length}`
|
|
229
|
+
);
|
|
230
|
+
const u = s.ins[0], c = o.getId(), i = x(
|
|
231
|
+
new Uint8Array(u.hash).slice().reverse()
|
|
232
|
+
);
|
|
233
|
+
if (i !== c)
|
|
234
|
+
throw new Error(
|
|
235
|
+
`PegIn input does not reference the Pre-PegIn transaction. Expected ${c}, got ${i}`
|
|
236
|
+
);
|
|
237
|
+
const p = o.outs[u.index];
|
|
238
|
+
if (!p)
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Pre-PegIn output ${u.index} not found (Pre-PegIn has ${o.outs.length} outputs)`
|
|
241
|
+
);
|
|
242
|
+
const l = d(r.hashlockScript), f = d(r.hashlockControlBlock), g = new w();
|
|
243
|
+
g.setVersion(s.version), g.setLocktime(s.locktime), g.addInput({
|
|
244
|
+
hash: u.hash,
|
|
245
|
+
index: u.index,
|
|
246
|
+
sequence: u.sequence,
|
|
247
|
+
witnessUtxo: {
|
|
248
|
+
script: p.script,
|
|
249
|
+
value: p.value
|
|
250
|
+
},
|
|
251
|
+
tapLeafScript: [
|
|
252
|
+
{
|
|
253
|
+
leafVersion: 192,
|
|
254
|
+
script: a.from(l),
|
|
255
|
+
controlBlock: a.from(f)
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
tapInternalKey: a.from(k)
|
|
259
|
+
// sighashType omitted — defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
260
|
+
});
|
|
261
|
+
for (const P of s.outs)
|
|
262
|
+
g.addOutput({
|
|
263
|
+
script: P.script,
|
|
264
|
+
value: P.value
|
|
265
|
+
});
|
|
266
|
+
return { psbtHex: g.toHex() };
|
|
267
|
+
}
|
|
268
|
+
function vt(t, n) {
|
|
269
|
+
const r = w.fromHex(t).data.inputs[0];
|
|
270
|
+
if (!r)
|
|
271
|
+
throw new Error("PegIn PSBT has no inputs");
|
|
272
|
+
if (r.tapScriptSig && r.tapScriptSig.length > 0) {
|
|
273
|
+
const s = a.from(
|
|
274
|
+
d(n)
|
|
275
|
+
);
|
|
276
|
+
for (const o of r.tapScriptSig)
|
|
277
|
+
if (o.pubkey.equals(s))
|
|
278
|
+
return J(o.signature);
|
|
279
|
+
throw new Error(
|
|
280
|
+
`No PegIn input signature found for depositor pubkey: ${n}`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
throw r.finalScriptWitness && r.finalScriptWitness.length > 0 ? new Error(
|
|
284
|
+
"PegIn input PSBT is already finalized. Cannot reliably extract the depositor signature from the witness stack. Ensure the wallet returns a non-finalized PSBT with tapScriptSig entries."
|
|
285
|
+
) : new Error(
|
|
286
|
+
"No tapScriptSig or finalScriptWitness found in signed PegIn input PSBT"
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
function J(t) {
|
|
290
|
+
if (t.length === 64)
|
|
291
|
+
return x(new Uint8Array(t));
|
|
292
|
+
if (t.length === 65)
|
|
293
|
+
return x(new Uint8Array(t.subarray(0, 64)));
|
|
294
|
+
throw new Error(`Unexpected PegIn input signature length: ${t.length}`);
|
|
295
|
+
}
|
|
296
|
+
async function tt(t) {
|
|
297
|
+
const n = await K(
|
|
298
|
+
{
|
|
299
|
+
depositor: t.depositor,
|
|
300
|
+
vaultProvider: t.vaultProvider,
|
|
301
|
+
vaultKeepers: t.vaultKeepers,
|
|
302
|
+
universalChallengers: t.universalChallengers,
|
|
303
|
+
timelockPegin: t.timelockPegin
|
|
304
|
+
},
|
|
305
|
+
t.network
|
|
306
|
+
);
|
|
307
|
+
return {
|
|
308
|
+
payoutScript: n.payoutScript,
|
|
309
|
+
taprootScriptHash: n.taprootScriptHash,
|
|
310
|
+
scriptPubKey: n.scriptPubKey,
|
|
311
|
+
address: n.address
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
I(H);
|
|
315
|
+
async function bt(t) {
|
|
316
|
+
const n = h(t.payoutTxHex), e = h(t.peginTxHex), r = h(t.assertTxHex), s = await tt({
|
|
317
|
+
depositor: t.depositorBtcPubkey,
|
|
318
|
+
vaultProvider: t.vaultProviderBtcPubkey,
|
|
319
|
+
vaultKeepers: t.vaultKeeperBtcPubkeys,
|
|
320
|
+
universalChallengers: t.universalChallengerBtcPubkeys,
|
|
321
|
+
timelockPegin: t.timelockPegin,
|
|
322
|
+
network: t.network
|
|
323
|
+
}), o = d(s.payoutScript), u = nt(k, o), c = y.fromHex(n), i = y.fromHex(e), p = y.fromHex(r), l = new w();
|
|
324
|
+
if (l.setVersion(c.version), l.setLocktime(c.locktime), c.ins.length !== 2)
|
|
325
|
+
throw new Error(
|
|
326
|
+
`Payout transaction must have exactly 2 inputs, got ${c.ins.length}`
|
|
327
|
+
);
|
|
328
|
+
const f = c.ins[0], g = c.ins[1], P = x(
|
|
329
|
+
new Uint8Array(f.hash).slice().reverse()
|
|
330
|
+
), v = i.getId();
|
|
331
|
+
if (P !== v)
|
|
332
|
+
throw new Error(
|
|
333
|
+
`Input 0 does not reference pegin transaction. Expected ${v}, got ${P}`
|
|
334
|
+
);
|
|
335
|
+
const m = x(
|
|
336
|
+
new Uint8Array(g.hash).slice().reverse()
|
|
337
|
+
), B = p.getId();
|
|
338
|
+
if (m !== B)
|
|
339
|
+
throw new Error(
|
|
340
|
+
`Input 1 does not reference assert transaction. Expected ${B}, got ${m}`
|
|
341
|
+
);
|
|
342
|
+
const S = i.outs[f.index];
|
|
343
|
+
if (!S)
|
|
344
|
+
throw new Error(
|
|
345
|
+
`Previous output not found for input 0 (txid: ${P}, index: ${f.index})`
|
|
346
|
+
);
|
|
347
|
+
const E = p.outs[g.index];
|
|
348
|
+
if (!E)
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Previous output not found for input 1 (txid: ${m}, index: ${g.index})`
|
|
351
|
+
);
|
|
352
|
+
l.addInput({
|
|
353
|
+
hash: f.hash,
|
|
354
|
+
index: f.index,
|
|
355
|
+
sequence: f.sequence,
|
|
356
|
+
witnessUtxo: {
|
|
357
|
+
script: S.script,
|
|
358
|
+
value: S.value
|
|
359
|
+
},
|
|
360
|
+
tapLeafScript: [
|
|
361
|
+
{
|
|
362
|
+
leafVersion: 192,
|
|
363
|
+
script: a.from(o),
|
|
364
|
+
controlBlock: a.from(u)
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
tapInternalKey: a.from(k)
|
|
368
|
+
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
369
|
+
}), l.addInput({
|
|
370
|
+
hash: g.hash,
|
|
371
|
+
index: g.index,
|
|
372
|
+
sequence: g.sequence,
|
|
373
|
+
witnessUtxo: {
|
|
374
|
+
script: E.script,
|
|
375
|
+
value: E.value
|
|
376
|
+
}
|
|
377
|
+
// No tapLeafScript - depositor doesn't sign this input
|
|
378
|
+
});
|
|
379
|
+
for (const $ of c.outs)
|
|
380
|
+
l.addOutput({
|
|
381
|
+
script: $.script,
|
|
382
|
+
value: $.value
|
|
383
|
+
});
|
|
384
|
+
return {
|
|
385
|
+
psbtHex: l.toHex()
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function mt(t, n, e = 0) {
|
|
389
|
+
const r = w.fromHex(t);
|
|
390
|
+
if (e >= r.data.inputs.length)
|
|
391
|
+
throw new Error(
|
|
392
|
+
`Input index ${e} out of range (${r.data.inputs.length} inputs)`
|
|
393
|
+
);
|
|
394
|
+
const s = r.data.inputs[e];
|
|
395
|
+
if (s.tapScriptSig && s.tapScriptSig.length > 0) {
|
|
396
|
+
const o = d(n);
|
|
397
|
+
for (const u of s.tapScriptSig)
|
|
398
|
+
if (u.pubkey.equals(a.from(o)))
|
|
399
|
+
return L(u.signature, e);
|
|
400
|
+
throw new Error(
|
|
401
|
+
`No signature found for depositor pubkey: ${n} at input ${e}`
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
if (s.finalScriptWitness && s.finalScriptWitness.length > 0) {
|
|
405
|
+
const o = et(s.finalScriptWitness);
|
|
406
|
+
if (o.length >= 1)
|
|
407
|
+
return L(o[0], e);
|
|
408
|
+
}
|
|
409
|
+
throw new Error(
|
|
410
|
+
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${e}`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
function L(t, n) {
|
|
414
|
+
if (t.length === 64)
|
|
415
|
+
return x(new Uint8Array(t));
|
|
416
|
+
if (t.length === 65)
|
|
417
|
+
return x(new Uint8Array(t.subarray(0, 64)));
|
|
418
|
+
throw new Error(
|
|
419
|
+
`Unexpected signature length at input ${n}: ${t.length}`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
function et(t) {
|
|
423
|
+
const n = [];
|
|
424
|
+
let e = 0;
|
|
425
|
+
const r = () => {
|
|
426
|
+
const o = t[e++];
|
|
427
|
+
if (o < 253) return o;
|
|
428
|
+
if (o === 253) {
|
|
429
|
+
const u = t[e] | t[e + 1] << 8;
|
|
430
|
+
return e += 2, u;
|
|
431
|
+
}
|
|
432
|
+
if (o === 254) {
|
|
433
|
+
const u = t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24;
|
|
434
|
+
return e += 4, u;
|
|
435
|
+
}
|
|
436
|
+
return e += 8, 0;
|
|
437
|
+
}, s = r();
|
|
438
|
+
for (let o = 0; o < s; o++) {
|
|
439
|
+
const u = r();
|
|
440
|
+
n.push(t.subarray(e, e + u)), e += u;
|
|
441
|
+
}
|
|
442
|
+
return n;
|
|
443
|
+
}
|
|
444
|
+
function nt(t, n) {
|
|
445
|
+
const e = { output: a.from(n) }, s = b.p2tr({
|
|
446
|
+
internalPubkey: a.from(t),
|
|
447
|
+
scriptTree: e
|
|
448
|
+
}).pubkey;
|
|
449
|
+
if (!s)
|
|
450
|
+
throw new Error("Failed to compute output key");
|
|
451
|
+
const o = 192, u = s[0] === 3 ? 1 : 0, c = o | u, i = new Uint8Array(1 + t.length);
|
|
452
|
+
return i[0] = c, i.set(t, 1), i;
|
|
453
|
+
}
|
|
454
|
+
I(H);
|
|
455
|
+
async function St(t) {
|
|
456
|
+
const n = h(t.payoutTxHex), e = y.fromHex(n), r = await q(t.connectorParams), s = d(r), o = rt(k, s), u = new w();
|
|
457
|
+
u.setVersion(e.version), u.setLocktime(e.locktime);
|
|
458
|
+
for (let c = 0; c < e.ins.length; c++) {
|
|
459
|
+
const i = e.ins[c], p = t.prevouts[c];
|
|
460
|
+
if (!p)
|
|
461
|
+
throw new Error(`Missing prevout data for input ${c}`);
|
|
462
|
+
const l = {
|
|
463
|
+
hash: i.hash,
|
|
464
|
+
index: i.index,
|
|
465
|
+
sequence: i.sequence,
|
|
466
|
+
witnessUtxo: {
|
|
467
|
+
script: a.from(d(h(p.script_pubkey))),
|
|
468
|
+
value: p.value
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
c === 0 && (l.tapLeafScript = [
|
|
472
|
+
{
|
|
473
|
+
leafVersion: 192,
|
|
474
|
+
script: a.from(s),
|
|
475
|
+
controlBlock: a.from(o)
|
|
476
|
+
}
|
|
477
|
+
], l.tapInternalKey = a.from(k)), u.addInput(l);
|
|
478
|
+
}
|
|
479
|
+
for (const c of e.outs)
|
|
480
|
+
u.addOutput({
|
|
481
|
+
script: c.script,
|
|
482
|
+
value: c.value
|
|
483
|
+
});
|
|
484
|
+
return u.toHex();
|
|
485
|
+
}
|
|
486
|
+
function rt(t, n) {
|
|
487
|
+
const e = { output: a.from(n) }, s = b.p2tr({
|
|
488
|
+
internalPubkey: a.from(t),
|
|
489
|
+
scriptTree: e
|
|
490
|
+
}).pubkey;
|
|
491
|
+
if (!s)
|
|
492
|
+
throw new Error("Failed to compute output key");
|
|
493
|
+
const o = 192, u = s[0] === 3 ? 1 : 0, c = o | u, i = new Uint8Array(1 + t.length);
|
|
494
|
+
return i[0] = c, i.set(t, 1), i;
|
|
495
|
+
}
|
|
496
|
+
async function Et(t) {
|
|
497
|
+
const n = h(t.noPayoutTxHex), e = y.fromHex(n), { noPayoutScript: r, noPayoutControlBlock: s } = await N(
|
|
498
|
+
t.connectorParams,
|
|
499
|
+
t.challengerPubkey
|
|
500
|
+
), o = d(r), u = d(s), c = new w();
|
|
501
|
+
c.setVersion(e.version), c.setLocktime(e.locktime);
|
|
502
|
+
for (let i = 0; i < e.ins.length; i++) {
|
|
503
|
+
const p = e.ins[i], l = t.prevouts[i];
|
|
504
|
+
if (!l)
|
|
505
|
+
throw new Error(`Missing prevout data for input ${i}`);
|
|
506
|
+
const f = {
|
|
507
|
+
hash: p.hash,
|
|
508
|
+
index: p.index,
|
|
509
|
+
sequence: p.sequence,
|
|
510
|
+
witnessUtxo: {
|
|
511
|
+
script: a.from(d(h(l.script_pubkey))),
|
|
512
|
+
value: l.value
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
i === 0 && (f.tapLeafScript = [
|
|
516
|
+
{
|
|
517
|
+
leafVersion: 192,
|
|
518
|
+
script: a.from(o),
|
|
519
|
+
controlBlock: a.from(u)
|
|
520
|
+
}
|
|
521
|
+
], f.tapInternalKey = a.from(k)), c.addInput(f);
|
|
522
|
+
}
|
|
523
|
+
for (const i of e.outs)
|
|
524
|
+
c.addOutput({
|
|
525
|
+
script: i.script,
|
|
526
|
+
value: i.value
|
|
527
|
+
});
|
|
528
|
+
return c.toHex();
|
|
529
|
+
}
|
|
530
|
+
async function Tt(t) {
|
|
531
|
+
const n = h(t.challengeAssertTxHex), e = y.fromHex(n);
|
|
532
|
+
if (t.connectorParamsPerInput.length !== e.ins.length)
|
|
533
|
+
throw new Error(
|
|
534
|
+
`Expected ${e.ins.length} connector params, got ${t.connectorParamsPerInput.length}`
|
|
535
|
+
);
|
|
536
|
+
const r = await Promise.all(
|
|
537
|
+
t.connectorParamsPerInput.map((o) => M(o))
|
|
538
|
+
), s = new w();
|
|
539
|
+
s.setVersion(e.version), s.setLocktime(e.locktime);
|
|
540
|
+
for (let o = 0; o < e.ins.length; o++) {
|
|
541
|
+
const u = e.ins[o], c = t.prevouts[o];
|
|
542
|
+
if (!c)
|
|
543
|
+
throw new Error(`Missing prevout data for input ${o}`);
|
|
544
|
+
const { script: i, controlBlock: p } = r[o], l = d(i), f = d(p);
|
|
545
|
+
s.addInput({
|
|
546
|
+
hash: u.hash,
|
|
547
|
+
index: u.index,
|
|
548
|
+
sequence: u.sequence,
|
|
549
|
+
witnessUtxo: {
|
|
550
|
+
script: a.from(d(h(c.script_pubkey))),
|
|
551
|
+
value: c.value
|
|
552
|
+
},
|
|
553
|
+
tapLeafScript: [
|
|
554
|
+
{
|
|
555
|
+
leafVersion: 192,
|
|
556
|
+
script: a.from(l),
|
|
557
|
+
controlBlock: a.from(f)
|
|
558
|
+
}
|
|
559
|
+
],
|
|
560
|
+
tapInternalKey: a.from(k)
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
for (const o of e.outs)
|
|
564
|
+
s.addOutput({
|
|
565
|
+
script: o.script,
|
|
566
|
+
value: o.value
|
|
567
|
+
});
|
|
568
|
+
return s.toHex();
|
|
569
|
+
}
|
|
570
|
+
export {
|
|
571
|
+
D as B,
|
|
572
|
+
z as D,
|
|
573
|
+
lt as F,
|
|
574
|
+
X as L,
|
|
575
|
+
ut as M,
|
|
576
|
+
ct as P,
|
|
577
|
+
ft as S,
|
|
578
|
+
at as T,
|
|
579
|
+
Y as W,
|
|
580
|
+
kt as a,
|
|
581
|
+
xt as b,
|
|
582
|
+
wt as c,
|
|
583
|
+
bt as d,
|
|
584
|
+
vt as e,
|
|
585
|
+
mt as f,
|
|
586
|
+
St as g,
|
|
587
|
+
Et as h,
|
|
588
|
+
Tt as i,
|
|
589
|
+
tt as j,
|
|
590
|
+
j as k,
|
|
591
|
+
Z as l,
|
|
592
|
+
d as m,
|
|
593
|
+
Pt as n,
|
|
594
|
+
dt as o,
|
|
595
|
+
ht as p,
|
|
596
|
+
_ as q,
|
|
597
|
+
pt as r,
|
|
598
|
+
h as s,
|
|
599
|
+
Q as t,
|
|
600
|
+
x as u,
|
|
601
|
+
gt as v,
|
|
602
|
+
V as w,
|
|
603
|
+
yt as x,
|
|
604
|
+
O as y
|
|
605
|
+
};
|
|
606
|
+
//# sourceMappingURL=challengeAssert-Dvcg38_y.js.map
|