@babylonlabs-io/ts-sdk 0.15.2 → 0.15.3
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/{challengeAssert-CenzzhZU.js → challengeAssert-C5DQSUnp.js} +249 -265
- package/dist/challengeAssert-C5DQSUnp.js.map +1 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs +2 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs.map +1 -0
- package/dist/errors-BZc3Urez.cjs +2 -0
- package/dist/errors-BZc3Urez.cjs.map +1 -0
- package/dist/{errors-C5aW6wrA.js → errors-UqmtfBtv.js} +189 -188
- package/dist/errors-UqmtfBtv.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +2 -2
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts +2 -13
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/scripts/payout.d.ts +7 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +17 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +2 -2
- package/package.json +3 -3
- package/dist/challengeAssert-BpzES0KW.cjs +0 -2
- package/dist/challengeAssert-BpzES0KW.cjs.map +0 -1
- package/dist/challengeAssert-CenzzhZU.js.map +0 -1
- package/dist/errors-C5aW6wrA.js.map +0 -1
- package/dist/errors-DD3lnhb0.cjs +0 -2
- package/dist/errors-DD3lnhb0.cjs.map +0 -1
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import { createPrePeginTransaction as W, buildPeginTxFromPrePegin as
|
|
2
|
-
import * as
|
|
3
|
-
import { payments as
|
|
4
|
-
import { Buffer as
|
|
5
|
-
import * as
|
|
1
|
+
import { createPrePeginTransaction as W, buildPeginTxFromPrePegin as F, getPrePeginHtlcConnectorInfo as _, tapInternalPubkey as m, initWasm as N, WasmPrePeginTx as q, createPayoutConnector as z, getPeginPayoutScriptInfo as M, getAssertNoPayoutScriptInfo as D, getChallengeAssertScriptInfo as X } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
2
|
+
import * as B from "bitcoinjs-lib";
|
|
3
|
+
import { payments as R, networks as I, initEccLib as G, Transaction as y, Psbt as w } from "bitcoinjs-lib";
|
|
4
|
+
import { Buffer as l } from "buffer";
|
|
5
|
+
import * as Q from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
6
|
+
const E = 192;
|
|
6
7
|
function g(t) {
|
|
7
8
|
return t.startsWith("0x") ? t.slice(2) : t;
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
+
function lt(t) {
|
|
10
11
|
return t.startsWith("0x") ? t : `0x${t}`;
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function d(t) {
|
|
13
14
|
const e = g(t);
|
|
14
|
-
if (!
|
|
15
|
+
if (!A(e))
|
|
15
16
|
throw new Error(`Invalid hex string: ${t}`);
|
|
16
17
|
const n = new Uint8Array(e.length / 2);
|
|
17
18
|
for (let r = 0; r < e.length; r += 2)
|
|
18
19
|
n[r / 2] = parseInt(e.slice(r, r + 2), 16);
|
|
19
20
|
return n;
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function v(t) {
|
|
22
23
|
return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
+
function Y(t) {
|
|
25
26
|
return t.length === 32 ? t : t.slice(1, 33);
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
+
function A(t) {
|
|
28
29
|
return /^[0-9a-fA-F]*$/.test(t) && t.length % 2 === 0;
|
|
29
30
|
}
|
|
30
31
|
function C(t) {
|
|
31
32
|
const e = g(t);
|
|
32
|
-
if (!
|
|
33
|
+
if (!A(e))
|
|
33
34
|
throw new Error(`Invalid hex characters in public key: ${t}`);
|
|
34
35
|
if (e.length === 64)
|
|
35
36
|
return e;
|
|
@@ -37,14 +38,14 @@ function C(t) {
|
|
|
37
38
|
throw new Error(
|
|
38
39
|
`Invalid public key length: ${e.length} (expected 64, 66, or 130 hex chars)`
|
|
39
40
|
);
|
|
40
|
-
const n =
|
|
41
|
-
return
|
|
41
|
+
const n = d(e);
|
|
42
|
+
return v(Y(n));
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function pt(t) {
|
|
44
45
|
const e = g(t);
|
|
45
|
-
return
|
|
46
|
+
return A(e);
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
+
function ft(t, e) {
|
|
48
49
|
const n = C(t), r = e ?? n;
|
|
49
50
|
if (n.toLowerCase() !== r.toLowerCase())
|
|
50
51
|
throw new Error(
|
|
@@ -52,9 +53,9 @@ function dt(t, e) {
|
|
|
52
53
|
);
|
|
53
54
|
return { walletPubkeyRaw: t, walletPubkeyXOnly: n, depositorPubkey: r };
|
|
54
55
|
}
|
|
55
|
-
let
|
|
56
|
-
function
|
|
57
|
-
|
|
56
|
+
let L = !1;
|
|
57
|
+
function O() {
|
|
58
|
+
L || (G(Q), L = !0);
|
|
58
59
|
}
|
|
59
60
|
function V(t) {
|
|
60
61
|
switch (t) {
|
|
@@ -69,24 +70,24 @@ function V(t) {
|
|
|
69
70
|
throw new Error(`Unknown network: ${t}`);
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
const n =
|
|
75
|
-
internalPubkey:
|
|
73
|
+
function Z(t, e) {
|
|
74
|
+
O();
|
|
75
|
+
const n = d(C(t)), { address: r } = R.p2tr({
|
|
76
|
+
internalPubkey: l.from(n),
|
|
76
77
|
network: V(e)
|
|
77
78
|
});
|
|
78
79
|
if (!r)
|
|
79
80
|
throw new Error("Failed to derive taproot address from public key");
|
|
80
81
|
return r;
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
+
function j(t, e) {
|
|
83
84
|
const n = g(t);
|
|
84
85
|
if (n.length !== 66)
|
|
85
86
|
throw new Error(
|
|
86
87
|
`Native SegWit requires a compressed public key (66 hex chars), got ${n.length}`
|
|
87
88
|
);
|
|
88
|
-
const { address: r } =
|
|
89
|
-
pubkey:
|
|
89
|
+
const { address: r } = R.p2wpkh({
|
|
90
|
+
pubkey: l.from(d(n)),
|
|
90
91
|
network: V(e)
|
|
91
92
|
});
|
|
92
93
|
if (!r)
|
|
@@ -95,10 +96,10 @@ function Z(t, e) {
|
|
|
95
96
|
);
|
|
96
97
|
return r;
|
|
97
98
|
}
|
|
98
|
-
function
|
|
99
|
+
function dt(t, e, n) {
|
|
99
100
|
const r = g(e);
|
|
100
101
|
try {
|
|
101
|
-
if (t ===
|
|
102
|
+
if (t === Z(r, n))
|
|
102
103
|
return !0;
|
|
103
104
|
} catch {
|
|
104
105
|
}
|
|
@@ -106,7 +107,7 @@ function ht(t, e, n) {
|
|
|
106
107
|
r.length === 66 ? o.push(r) : r.length === 64 && o.push(`02${r}`, `03${r}`);
|
|
107
108
|
for (const s of o)
|
|
108
109
|
try {
|
|
109
|
-
if (t ===
|
|
110
|
+
if (t === j(s, n))
|
|
110
111
|
return !0;
|
|
111
112
|
} catch {
|
|
112
113
|
}
|
|
@@ -115,23 +116,23 @@ function ht(t, e, n) {
|
|
|
115
116
|
function H(t) {
|
|
116
117
|
return C(t).toLowerCase();
|
|
117
118
|
}
|
|
118
|
-
function
|
|
119
|
+
function ht(t, e, n) {
|
|
119
120
|
const r = /* @__PURE__ */ new Set();
|
|
120
121
|
r.add(H(t));
|
|
121
122
|
for (const o of e)
|
|
122
123
|
r.add(H(o));
|
|
123
124
|
return r.delete(H(n)), r.size;
|
|
124
125
|
}
|
|
125
|
-
const
|
|
126
|
-
function
|
|
127
|
-
return t <=
|
|
126
|
+
const gt = 58, Pt = 43, xt = 11, J = 546, tt = BigInt(J), et = 30, nt = 2, yt = 1.1;
|
|
127
|
+
function kt(t) {
|
|
128
|
+
return t <= nt ? et : 0;
|
|
128
129
|
}
|
|
129
|
-
const
|
|
130
|
+
const rt = 1;
|
|
130
131
|
function vt(t) {
|
|
131
|
-
return t +
|
|
132
|
+
return t + rt;
|
|
132
133
|
}
|
|
133
|
-
const
|
|
134
|
-
function
|
|
134
|
+
const wt = 5;
|
|
135
|
+
function K(t) {
|
|
135
136
|
const n = t.substring(8, 12) === "0001" ? 12 : 8, r = parseInt(
|
|
136
137
|
t.substring(n, n + 2),
|
|
137
138
|
16
|
|
@@ -143,33 +144,34 @@ function F(t) {
|
|
|
143
144
|
throw new Error(`Expected 0 inputs from WASM, got ${r}`);
|
|
144
145
|
if (o === 0)
|
|
145
146
|
throw new Error("Expected at least 1 output from WASM, got 0");
|
|
146
|
-
const s =
|
|
147
|
+
const s = l.from(t.substring(0, 8), "hex").readUInt32LE(0), c = l.from(
|
|
147
148
|
t.substring(t.length - 8),
|
|
148
149
|
"hex"
|
|
149
|
-
).readUInt32LE(0),
|
|
150
|
-
let
|
|
150
|
+
).readUInt32LE(0), u = [];
|
|
151
|
+
let i = n + 4;
|
|
151
152
|
for (let p = 0; p < o; p++) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
const P = t.substring(
|
|
157
|
-
|
|
153
|
+
const a = t.substring(i, i + 16), f = Number(l.from(a, "hex").readBigUInt64LE(0));
|
|
154
|
+
i += 16;
|
|
155
|
+
const h = parseInt(t.substring(i, i + 2), 16);
|
|
156
|
+
i += 2;
|
|
157
|
+
const P = t.substring(i, i + h * 2), x = l.from(P, "hex");
|
|
158
|
+
i += h * 2, u.push({ value: f, script: x });
|
|
158
159
|
}
|
|
159
|
-
return { version: s, locktime: c, outputs:
|
|
160
|
-
}
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
return { version: s, locktime: c, outputs: u };
|
|
161
|
+
}
|
|
162
|
+
function bt(t) {
|
|
163
|
+
O();
|
|
164
|
+
const { unfundedTxHex: e, selectedUTXOs: n, changeAddress: r, changeAmount: o, network: s } = t, { version: c, locktime: u, outputs: i } = K(e), p = new B.Transaction();
|
|
165
|
+
p.version = c, p.locktime = u;
|
|
166
|
+
for (const a of n) {
|
|
167
|
+
const f = l.from(a.txid, "hex").reverse();
|
|
168
|
+
p.addInput(f, a.vout);
|
|
167
169
|
}
|
|
168
|
-
for (const
|
|
169
|
-
p.addOutput(
|
|
170
|
-
if (o >
|
|
171
|
-
const
|
|
172
|
-
p.addOutput(
|
|
170
|
+
for (const a of i)
|
|
171
|
+
p.addOutput(a.script, a.value);
|
|
172
|
+
if (o > tt) {
|
|
173
|
+
const a = B.address.toOutputScript(r, s);
|
|
174
|
+
p.addOutput(a, Number(o));
|
|
173
175
|
}
|
|
174
176
|
return p.toHex();
|
|
175
177
|
}
|
|
@@ -187,7 +189,7 @@ async function St(t) {
|
|
|
187
189
|
councilQuorum: t.councilQuorum,
|
|
188
190
|
councilSize: t.councilSize,
|
|
189
191
|
network: t.network
|
|
190
|
-
}), r =
|
|
192
|
+
}), r = K(e.txHex).outputs.reduce(
|
|
191
193
|
(o, s) => o + BigInt(s.value),
|
|
192
194
|
0n
|
|
193
195
|
);
|
|
@@ -201,8 +203,8 @@ async function St(t) {
|
|
|
201
203
|
depositorClaimValue: e.depositorClaimValue
|
|
202
204
|
};
|
|
203
205
|
}
|
|
204
|
-
async function
|
|
205
|
-
const e = await
|
|
206
|
+
async function mt(t) {
|
|
207
|
+
const e = await F(
|
|
206
208
|
{
|
|
207
209
|
depositorPubkey: t.prePeginParams.depositorPubkey,
|
|
208
210
|
vaultProviderPubkey: t.prePeginParams.vaultProviderPubkey,
|
|
@@ -228,8 +230,8 @@ async function Et(t) {
|
|
|
228
230
|
vaultValue: e.vaultValue
|
|
229
231
|
};
|
|
230
232
|
}
|
|
231
|
-
async function
|
|
232
|
-
const e = g(t.peginTxHex), n = g(t.fundedPrePeginTxHex), r = await
|
|
233
|
+
async function Et(t) {
|
|
234
|
+
const e = g(t.peginTxHex), n = g(t.fundedPrePeginTxHex), r = await _({
|
|
233
235
|
depositorPubkey: t.depositorPubkey,
|
|
234
236
|
vaultProviderPubkey: t.vaultProviderPubkey,
|
|
235
237
|
vaultKeeperPubkeys: t.vaultKeeperPubkeys,
|
|
@@ -237,25 +239,25 @@ async function Tt(t) {
|
|
|
237
239
|
hashlock: t.hashlock,
|
|
238
240
|
timelockRefund: t.timelockRefund,
|
|
239
241
|
network: t.network
|
|
240
|
-
}), o =
|
|
242
|
+
}), o = y.fromHex(e), s = y.fromHex(n);
|
|
241
243
|
if (o.ins.length !== 1)
|
|
242
244
|
throw new Error(
|
|
243
245
|
`PegIn transaction must have exactly 1 input, got ${o.ins.length}`
|
|
244
246
|
);
|
|
245
|
-
const c = o.ins[0],
|
|
247
|
+
const c = o.ins[0], u = s.getId(), i = v(
|
|
246
248
|
new Uint8Array(c.hash).slice().reverse()
|
|
247
249
|
);
|
|
248
|
-
if (
|
|
250
|
+
if (i !== u)
|
|
249
251
|
throw new Error(
|
|
250
|
-
`PegIn input does not reference the Pre-PegIn transaction. Expected ${
|
|
252
|
+
`PegIn input does not reference the Pre-PegIn transaction. Expected ${u}, got ${i}`
|
|
251
253
|
);
|
|
252
254
|
const p = s.outs[c.index];
|
|
253
255
|
if (!p)
|
|
254
256
|
throw new Error(
|
|
255
257
|
`Pre-PegIn output ${c.index} not found (Pre-PegIn has ${s.outs.length} outputs)`
|
|
256
258
|
);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
+
const a = d(r.hashlockScript), f = d(r.hashlockControlBlock), h = new w();
|
|
260
|
+
h.setVersion(o.version), h.setLocktime(o.locktime), h.addInput({
|
|
259
261
|
hash: c.hash,
|
|
260
262
|
index: c.index,
|
|
261
263
|
sequence: c.sequence,
|
|
@@ -265,32 +267,32 @@ async function Tt(t) {
|
|
|
265
267
|
},
|
|
266
268
|
tapLeafScript: [
|
|
267
269
|
{
|
|
268
|
-
leafVersion:
|
|
269
|
-
script:
|
|
270
|
-
controlBlock:
|
|
270
|
+
leafVersion: E,
|
|
271
|
+
script: l.from(a),
|
|
272
|
+
controlBlock: l.from(f)
|
|
271
273
|
}
|
|
272
274
|
],
|
|
273
|
-
tapInternalKey:
|
|
275
|
+
tapInternalKey: l.from(m)
|
|
274
276
|
// sighashType omitted — defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
275
277
|
});
|
|
276
278
|
for (const P of o.outs)
|
|
277
|
-
|
|
279
|
+
h.addOutput({
|
|
278
280
|
script: P.script,
|
|
279
281
|
value: P.value
|
|
280
282
|
});
|
|
281
|
-
return { psbtHex:
|
|
283
|
+
return { psbtHex: h.toHex() };
|
|
282
284
|
}
|
|
283
|
-
function
|
|
284
|
-
const r =
|
|
285
|
+
function Tt(t, e) {
|
|
286
|
+
const r = w.fromHex(t).data.inputs[0];
|
|
285
287
|
if (!r)
|
|
286
288
|
throw new Error("PegIn PSBT has no inputs");
|
|
287
289
|
if (r.tapScriptSig && r.tapScriptSig.length > 0) {
|
|
288
|
-
const o =
|
|
289
|
-
|
|
290
|
+
const o = l.from(
|
|
291
|
+
d(e)
|
|
290
292
|
);
|
|
291
293
|
for (const s of r.tapScriptSig)
|
|
292
294
|
if (s.pubkey.equals(o))
|
|
293
|
-
return
|
|
295
|
+
return ot(s.signature);
|
|
294
296
|
throw new Error(
|
|
295
297
|
`No PegIn input signature found for depositor pubkey: ${e}`
|
|
296
298
|
);
|
|
@@ -301,8 +303,8 @@ function It(t, e) {
|
|
|
301
303
|
"No tapScriptSig or finalScriptWitness found in signed PegIn input PSBT"
|
|
302
304
|
);
|
|
303
305
|
}
|
|
304
|
-
function
|
|
305
|
-
const e =
|
|
306
|
+
function It(t) {
|
|
307
|
+
const e = w.fromHex(t);
|
|
306
308
|
try {
|
|
307
309
|
e.finalizeAllInputs();
|
|
308
310
|
} catch (n) {
|
|
@@ -315,16 +317,16 @@ function Ht(t) {
|
|
|
315
317
|
}
|
|
316
318
|
return e.extractTransaction().toHex();
|
|
317
319
|
}
|
|
318
|
-
function
|
|
320
|
+
function ot(t) {
|
|
319
321
|
if (t.length === 64)
|
|
320
|
-
return
|
|
322
|
+
return v(new Uint8Array(t));
|
|
321
323
|
if (t.length === 65)
|
|
322
|
-
return
|
|
324
|
+
return v(new Uint8Array(t.subarray(0, 64)));
|
|
323
325
|
throw new Error(`Unexpected PegIn input signature length: ${t.length}`);
|
|
324
326
|
}
|
|
325
|
-
async function
|
|
326
|
-
await
|
|
327
|
-
const { prePeginParams: e, fundedPrePeginTxHex: n, htlcVout: r, refundFee: o, hashlock: s } = t, c = new
|
|
327
|
+
async function Ht(t) {
|
|
328
|
+
await N();
|
|
329
|
+
const { prePeginParams: e, fundedPrePeginTxHex: n, htlcVout: r, refundFee: o, hashlock: s } = t, c = new q(
|
|
328
330
|
e.depositorPubkey,
|
|
329
331
|
e.vaultProviderPubkey,
|
|
330
332
|
e.vaultKeeperPubkeys,
|
|
@@ -338,10 +340,10 @@ async function At(t) {
|
|
|
338
340
|
e.councilSize,
|
|
339
341
|
e.network
|
|
340
342
|
);
|
|
341
|
-
let
|
|
343
|
+
let u = null;
|
|
342
344
|
try {
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
+
u = c.fromFundedTransaction(n);
|
|
346
|
+
const i = u.buildRefundTx(o, r), p = await _({
|
|
345
347
|
depositorPubkey: e.depositorPubkey,
|
|
346
348
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
347
349
|
vaultKeeperPubkeys: e.vaultKeeperPubkeys,
|
|
@@ -349,46 +351,46 @@ async function At(t) {
|
|
|
349
351
|
hashlock: s,
|
|
350
352
|
timelockRefund: e.timelockRefund,
|
|
351
353
|
network: e.network
|
|
352
|
-
}),
|
|
353
|
-
if (!
|
|
354
|
+
}), a = n.startsWith("0x") ? n.slice(2) : n, f = y.fromHex(a), h = f.outs[r];
|
|
355
|
+
if (!h)
|
|
354
356
|
throw new Error(
|
|
355
357
|
`HTLC output at vout ${r} not found in funded Pre-PegIn tx (tx has ${f.outs.length} outputs)`
|
|
356
358
|
);
|
|
357
|
-
const P =
|
|
359
|
+
const P = y.fromHex(i);
|
|
358
360
|
if (P.ins.length !== 1)
|
|
359
361
|
throw new Error(
|
|
360
362
|
`Refund transaction must have exactly 1 input, got ${P.ins.length}`
|
|
361
363
|
);
|
|
362
|
-
const
|
|
363
|
-
new Uint8Array(
|
|
364
|
+
const x = P.ins[0], b = f.getId(), T = v(
|
|
365
|
+
new Uint8Array(x.hash).slice().reverse()
|
|
364
366
|
);
|
|
365
|
-
if (
|
|
367
|
+
if (T !== b)
|
|
366
368
|
throw new Error(
|
|
367
|
-
`Refund input does not reference the Pre-PegIn transaction. Expected ${
|
|
369
|
+
`Refund input does not reference the Pre-PegIn transaction. Expected ${b}, got ${T}`
|
|
368
370
|
);
|
|
369
|
-
if (
|
|
371
|
+
if (x.index !== r)
|
|
370
372
|
throw new Error(
|
|
371
|
-
`Refund input index ${
|
|
373
|
+
`Refund input index ${x.index} does not match expected htlcVout ${r}`
|
|
372
374
|
);
|
|
373
|
-
const k = new
|
|
375
|
+
const k = new w();
|
|
374
376
|
k.setVersion(P.version), k.setLocktime(P.locktime), k.addInput({
|
|
375
|
-
hash:
|
|
376
|
-
index:
|
|
377
|
-
sequence:
|
|
377
|
+
hash: x.hash,
|
|
378
|
+
index: x.index,
|
|
379
|
+
sequence: x.sequence,
|
|
378
380
|
witnessUtxo: {
|
|
379
|
-
script:
|
|
380
|
-
value:
|
|
381
|
+
script: h.script,
|
|
382
|
+
value: h.value
|
|
381
383
|
},
|
|
382
384
|
tapLeafScript: [
|
|
383
385
|
{
|
|
384
|
-
leafVersion:
|
|
385
|
-
script:
|
|
386
|
-
controlBlock:
|
|
387
|
-
|
|
386
|
+
leafVersion: E,
|
|
387
|
+
script: l.from(d(p.refundScript)),
|
|
388
|
+
controlBlock: l.from(
|
|
389
|
+
d(p.refundControlBlock)
|
|
388
390
|
)
|
|
389
391
|
}
|
|
390
392
|
],
|
|
391
|
-
tapInternalKey:
|
|
393
|
+
tapInternalKey: l.from(m)
|
|
392
394
|
});
|
|
393
395
|
for (const S of P.outs)
|
|
394
396
|
k.addOutput({
|
|
@@ -397,10 +399,10 @@ async function At(t) {
|
|
|
397
399
|
});
|
|
398
400
|
return { psbtHex: k.toHex() };
|
|
399
401
|
} finally {
|
|
400
|
-
|
|
402
|
+
u == null || u.free(), c.free();
|
|
401
403
|
}
|
|
402
404
|
}
|
|
403
|
-
async function
|
|
405
|
+
async function st(t) {
|
|
404
406
|
const e = await z(
|
|
405
407
|
{
|
|
406
408
|
depositor: t.depositor,
|
|
@@ -415,48 +417,48 @@ async function ot(t) {
|
|
|
415
417
|
payoutScript: e.payoutScript,
|
|
416
418
|
taprootScriptHash: e.taprootScriptHash,
|
|
417
419
|
scriptPubKey: e.scriptPubKey,
|
|
418
|
-
address: e.address
|
|
420
|
+
address: e.address,
|
|
421
|
+
payoutControlBlock: e.payoutControlBlock
|
|
419
422
|
};
|
|
420
423
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const e = g(t.payoutTxHex), n = g(t.peginTxHex), r = g(t.assertTxHex), o = await ot({
|
|
424
|
+
async function At(t) {
|
|
425
|
+
const e = g(t.payoutTxHex), n = g(t.peginTxHex), r = g(t.assertTxHex), o = await st({
|
|
424
426
|
depositor: t.depositorBtcPubkey,
|
|
425
427
|
vaultProvider: t.vaultProviderBtcPubkey,
|
|
426
428
|
vaultKeepers: t.vaultKeeperBtcPubkeys,
|
|
427
429
|
universalChallengers: t.universalChallengerBtcPubkeys,
|
|
428
430
|
timelockPegin: t.timelockPegin,
|
|
429
431
|
network: t.network
|
|
430
|
-
}), s =
|
|
431
|
-
if (
|
|
432
|
+
}), s = d(o.payoutScript), c = d(o.payoutControlBlock), u = y.fromHex(e), i = y.fromHex(n), p = y.fromHex(r), a = new w();
|
|
433
|
+
if (a.setVersion(u.version), a.setLocktime(u.locktime), u.ins.length !== 2)
|
|
432
434
|
throw new Error(
|
|
433
|
-
`Payout transaction must have exactly 2 inputs, got ${
|
|
435
|
+
`Payout transaction must have exactly 2 inputs, got ${u.ins.length}`
|
|
434
436
|
);
|
|
435
|
-
const f =
|
|
437
|
+
const f = u.ins[0], h = u.ins[1], P = v(
|
|
436
438
|
new Uint8Array(f.hash).slice().reverse()
|
|
437
|
-
),
|
|
438
|
-
if (P !==
|
|
439
|
+
), x = i.getId();
|
|
440
|
+
if (P !== x)
|
|
439
441
|
throw new Error(
|
|
440
|
-
`Input 0 does not reference pegin transaction. Expected ${
|
|
442
|
+
`Input 0 does not reference pegin transaction. Expected ${x}, got ${P}`
|
|
441
443
|
);
|
|
442
|
-
const
|
|
443
|
-
new Uint8Array(
|
|
444
|
-
),
|
|
445
|
-
if (
|
|
444
|
+
const b = v(
|
|
445
|
+
new Uint8Array(h.hash).slice().reverse()
|
|
446
|
+
), T = p.getId();
|
|
447
|
+
if (b !== T)
|
|
446
448
|
throw new Error(
|
|
447
|
-
`Input 1 does not reference assert transaction. Expected ${
|
|
449
|
+
`Input 1 does not reference assert transaction. Expected ${T}, got ${b}`
|
|
448
450
|
);
|
|
449
|
-
const k =
|
|
451
|
+
const k = i.outs[f.index];
|
|
450
452
|
if (!k)
|
|
451
453
|
throw new Error(
|
|
452
454
|
`Previous output not found for input 0 (txid: ${P}, index: ${f.index})`
|
|
453
455
|
);
|
|
454
|
-
const S = p.outs[
|
|
456
|
+
const S = p.outs[h.index];
|
|
455
457
|
if (!S)
|
|
456
458
|
throw new Error(
|
|
457
|
-
`Previous output not found for input 1 (txid: ${
|
|
459
|
+
`Previous output not found for input 1 (txid: ${b}, index: ${h.index})`
|
|
458
460
|
);
|
|
459
|
-
|
|
461
|
+
a.addInput({
|
|
460
462
|
hash: f.hash,
|
|
461
463
|
index: f.index,
|
|
462
464
|
sequence: f.sequence,
|
|
@@ -466,73 +468,73 @@ async function $t(t) {
|
|
|
466
468
|
},
|
|
467
469
|
tapLeafScript: [
|
|
468
470
|
{
|
|
469
|
-
leafVersion:
|
|
470
|
-
script:
|
|
471
|
-
controlBlock:
|
|
471
|
+
leafVersion: E,
|
|
472
|
+
script: l.from(s),
|
|
473
|
+
controlBlock: l.from(c)
|
|
472
474
|
}
|
|
473
475
|
],
|
|
474
|
-
tapInternalKey:
|
|
476
|
+
tapInternalKey: l.from(m)
|
|
475
477
|
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
476
|
-
}),
|
|
477
|
-
hash:
|
|
478
|
-
index:
|
|
479
|
-
sequence:
|
|
478
|
+
}), a.addInput({
|
|
479
|
+
hash: h.hash,
|
|
480
|
+
index: h.index,
|
|
481
|
+
sequence: h.sequence,
|
|
480
482
|
witnessUtxo: {
|
|
481
483
|
script: S.script,
|
|
482
484
|
value: S.value
|
|
483
485
|
}
|
|
484
486
|
// No tapLeafScript - depositor doesn't sign this input
|
|
485
487
|
});
|
|
486
|
-
for (const
|
|
487
|
-
|
|
488
|
-
script:
|
|
489
|
-
value:
|
|
488
|
+
for (const $ of u.outs)
|
|
489
|
+
a.addOutput({
|
|
490
|
+
script: $.script,
|
|
491
|
+
value: $.value
|
|
490
492
|
});
|
|
491
493
|
return {
|
|
492
|
-
psbtHex:
|
|
494
|
+
psbtHex: a.toHex()
|
|
493
495
|
};
|
|
494
496
|
}
|
|
495
|
-
function
|
|
496
|
-
const r =
|
|
497
|
+
function Ct(t, e, n = 0) {
|
|
498
|
+
const r = w.fromHex(t);
|
|
497
499
|
if (n >= r.data.inputs.length)
|
|
498
500
|
throw new Error(
|
|
499
501
|
`Input index ${n} out of range (${r.data.inputs.length} inputs)`
|
|
500
502
|
);
|
|
501
503
|
const o = r.data.inputs[n];
|
|
502
504
|
if (o.tapScriptSig && o.tapScriptSig.length > 0) {
|
|
503
|
-
const s =
|
|
505
|
+
const s = d(e);
|
|
504
506
|
for (const c of o.tapScriptSig)
|
|
505
|
-
if (c.pubkey.equals(
|
|
506
|
-
return
|
|
507
|
+
if (c.pubkey.equals(l.from(s)))
|
|
508
|
+
return U(c.signature, n);
|
|
507
509
|
throw new Error(
|
|
508
510
|
`No signature found for depositor pubkey: ${e} at input ${n}`
|
|
509
511
|
);
|
|
510
512
|
}
|
|
511
513
|
if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
|
|
512
|
-
const s =
|
|
514
|
+
const s = it(o.finalScriptWitness);
|
|
513
515
|
if (s.length >= 1)
|
|
514
|
-
return
|
|
516
|
+
return U(s[0], n);
|
|
515
517
|
}
|
|
516
518
|
throw new Error(
|
|
517
519
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
|
|
518
520
|
);
|
|
519
521
|
}
|
|
520
|
-
function
|
|
522
|
+
function U(t, e) {
|
|
521
523
|
if (t.length === 64)
|
|
522
|
-
return
|
|
524
|
+
return v(new Uint8Array(t));
|
|
523
525
|
if (t.length === 65) {
|
|
524
526
|
const n = t[64];
|
|
525
|
-
if (n !==
|
|
527
|
+
if (n !== y.SIGHASH_ALL)
|
|
526
528
|
throw new Error(
|
|
527
529
|
`Unexpected sighash type 0x${n.toString(16).padStart(2, "0")} at input ${e}. Expected SIGHASH_ALL (0x01).`
|
|
528
530
|
);
|
|
529
|
-
return
|
|
531
|
+
return v(new Uint8Array(t.subarray(0, 64)));
|
|
530
532
|
}
|
|
531
533
|
throw new Error(
|
|
532
534
|
`Unexpected signature length at input ${e}: ${t.length}`
|
|
533
535
|
);
|
|
534
536
|
}
|
|
535
|
-
function
|
|
537
|
+
function it(t) {
|
|
536
538
|
const e = [];
|
|
537
539
|
let n = 0;
|
|
538
540
|
const r = () => {
|
|
@@ -554,123 +556,104 @@ function st(t) {
|
|
|
554
556
|
}
|
|
555
557
|
return e;
|
|
556
558
|
}
|
|
557
|
-
function
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
if (!o)
|
|
563
|
-
throw new Error("Failed to compute output key");
|
|
564
|
-
const s = 192, c = o[0] === 3 ? 1 : 0, i = s | c, u = new Uint8Array(1 + t.length);
|
|
565
|
-
return u[0] = i, u.set(t, 1), u;
|
|
566
|
-
}
|
|
567
|
-
A($);
|
|
568
|
-
async function Ct(t) {
|
|
569
|
-
const e = g(t.payoutTxHex), n = x.fromHex(e), r = await M(t.connectorParams), o = h(r), s = ut(b, o), c = new v();
|
|
570
|
-
c.setVersion(n.version), c.setLocktime(n.locktime);
|
|
559
|
+
async function $t(t) {
|
|
560
|
+
const e = g(t.payoutTxHex), n = y.fromHex(e), { payoutScript: r, payoutControlBlock: o } = await M(
|
|
561
|
+
t.connectorParams
|
|
562
|
+
), s = d(r), c = d(o), u = new w();
|
|
563
|
+
u.setVersion(n.version), u.setLocktime(n.locktime);
|
|
571
564
|
for (let i = 0; i < n.ins.length; i++) {
|
|
572
|
-
const
|
|
573
|
-
if (!
|
|
565
|
+
const p = n.ins[i], a = t.prevouts[i];
|
|
566
|
+
if (!a)
|
|
574
567
|
throw new Error(`Missing prevout data for input ${i}`);
|
|
575
|
-
const
|
|
576
|
-
hash:
|
|
577
|
-
index:
|
|
578
|
-
sequence:
|
|
568
|
+
const f = {
|
|
569
|
+
hash: p.hash,
|
|
570
|
+
index: p.index,
|
|
571
|
+
sequence: p.sequence,
|
|
579
572
|
witnessUtxo: {
|
|
580
|
-
script:
|
|
581
|
-
value:
|
|
573
|
+
script: l.from(d(g(a.script_pubkey))),
|
|
574
|
+
value: a.value
|
|
582
575
|
}
|
|
583
576
|
};
|
|
584
|
-
i === 0 && (
|
|
577
|
+
i === 0 && (f.tapLeafScript = [
|
|
585
578
|
{
|
|
586
|
-
leafVersion:
|
|
587
|
-
script:
|
|
588
|
-
controlBlock:
|
|
579
|
+
leafVersion: E,
|
|
580
|
+
script: l.from(s),
|
|
581
|
+
controlBlock: l.from(c)
|
|
589
582
|
}
|
|
590
|
-
],
|
|
583
|
+
], f.tapInternalKey = l.from(m)), u.addInput(f);
|
|
591
584
|
}
|
|
592
585
|
for (const i of n.outs)
|
|
593
|
-
|
|
586
|
+
u.addOutput({
|
|
594
587
|
script: i.script,
|
|
595
588
|
value: i.value
|
|
596
589
|
});
|
|
597
|
-
return
|
|
598
|
-
}
|
|
599
|
-
function ut(t, e) {
|
|
600
|
-
const n = { output: a.from(e) }, o = T.p2tr({
|
|
601
|
-
internalPubkey: a.from(t),
|
|
602
|
-
scriptTree: n
|
|
603
|
-
}).pubkey;
|
|
604
|
-
if (!o)
|
|
605
|
-
throw new Error("Failed to compute output key");
|
|
606
|
-
const s = 192, c = o[0] === 3 ? 1 : 0, i = s | c, u = new Uint8Array(1 + t.length);
|
|
607
|
-
return u[0] = i, u.set(t, 1), u;
|
|
590
|
+
return u.toHex();
|
|
608
591
|
}
|
|
609
|
-
async function
|
|
610
|
-
const e = g(t.noPayoutTxHex), n =
|
|
592
|
+
async function Bt(t) {
|
|
593
|
+
const e = g(t.noPayoutTxHex), n = y.fromHex(e), { noPayoutScript: r, noPayoutControlBlock: o } = await D(
|
|
611
594
|
t.connectorParams,
|
|
612
595
|
t.challengerPubkey
|
|
613
|
-
), s =
|
|
614
|
-
|
|
615
|
-
for (let
|
|
616
|
-
const p = n.ins[
|
|
617
|
-
if (!
|
|
618
|
-
throw new Error(`Missing prevout data for input ${
|
|
596
|
+
), s = d(r), c = d(o), u = new w();
|
|
597
|
+
u.setVersion(n.version), u.setLocktime(n.locktime);
|
|
598
|
+
for (let i = 0; i < n.ins.length; i++) {
|
|
599
|
+
const p = n.ins[i], a = t.prevouts[i];
|
|
600
|
+
if (!a)
|
|
601
|
+
throw new Error(`Missing prevout data for input ${i}`);
|
|
619
602
|
const f = {
|
|
620
603
|
hash: p.hash,
|
|
621
604
|
index: p.index,
|
|
622
605
|
sequence: p.sequence,
|
|
623
606
|
witnessUtxo: {
|
|
624
|
-
script:
|
|
625
|
-
value:
|
|
607
|
+
script: l.from(d(g(a.script_pubkey))),
|
|
608
|
+
value: a.value
|
|
626
609
|
}
|
|
627
610
|
};
|
|
628
|
-
|
|
611
|
+
i === 0 && (f.tapLeafScript = [
|
|
629
612
|
{
|
|
630
|
-
leafVersion:
|
|
631
|
-
script:
|
|
632
|
-
controlBlock:
|
|
613
|
+
leafVersion: E,
|
|
614
|
+
script: l.from(s),
|
|
615
|
+
controlBlock: l.from(c)
|
|
633
616
|
}
|
|
634
|
-
], f.tapInternalKey =
|
|
617
|
+
], f.tapInternalKey = l.from(m)), u.addInput(f);
|
|
635
618
|
}
|
|
636
|
-
for (const
|
|
637
|
-
|
|
638
|
-
script:
|
|
639
|
-
value:
|
|
619
|
+
for (const i of n.outs)
|
|
620
|
+
u.addOutput({
|
|
621
|
+
script: i.script,
|
|
622
|
+
value: i.value
|
|
640
623
|
});
|
|
641
|
-
return
|
|
624
|
+
return u.toHex();
|
|
642
625
|
}
|
|
643
|
-
async function
|
|
644
|
-
const e = g(t.challengeAssertTxHex), n =
|
|
626
|
+
async function Lt(t) {
|
|
627
|
+
const e = g(t.challengeAssertTxHex), n = y.fromHex(e);
|
|
645
628
|
if (t.connectorParamsPerInput.length !== n.ins.length)
|
|
646
629
|
throw new Error(
|
|
647
630
|
`Expected ${n.ins.length} connector params, got ${t.connectorParamsPerInput.length}`
|
|
648
631
|
);
|
|
649
632
|
const r = await Promise.all(
|
|
650
633
|
t.connectorParamsPerInput.map((s) => X(s))
|
|
651
|
-
), o = new
|
|
634
|
+
), o = new w();
|
|
652
635
|
o.setVersion(n.version), o.setLocktime(n.locktime);
|
|
653
636
|
for (let s = 0; s < n.ins.length; s++) {
|
|
654
|
-
const c = n.ins[s],
|
|
655
|
-
if (!
|
|
637
|
+
const c = n.ins[s], u = t.prevouts[s];
|
|
638
|
+
if (!u)
|
|
656
639
|
throw new Error(`Missing prevout data for input ${s}`);
|
|
657
|
-
const { script:
|
|
640
|
+
const { script: i, controlBlock: p } = r[s], a = d(i), f = d(p);
|
|
658
641
|
o.addInput({
|
|
659
642
|
hash: c.hash,
|
|
660
643
|
index: c.index,
|
|
661
644
|
sequence: c.sequence,
|
|
662
645
|
witnessUtxo: {
|
|
663
|
-
script:
|
|
664
|
-
value:
|
|
646
|
+
script: l.from(d(g(u.script_pubkey))),
|
|
647
|
+
value: u.value
|
|
665
648
|
},
|
|
666
649
|
tapLeafScript: [
|
|
667
650
|
{
|
|
668
|
-
leafVersion:
|
|
669
|
-
script:
|
|
670
|
-
controlBlock:
|
|
651
|
+
leafVersion: E,
|
|
652
|
+
script: l.from(a),
|
|
653
|
+
controlBlock: l.from(f)
|
|
671
654
|
}
|
|
672
655
|
],
|
|
673
|
-
tapInternalKey:
|
|
656
|
+
tapInternalKey: l.from(m)
|
|
674
657
|
});
|
|
675
658
|
}
|
|
676
659
|
for (const s of n.outs)
|
|
@@ -682,43 +665,44 @@ async function Ut(t) {
|
|
|
682
665
|
}
|
|
683
666
|
export {
|
|
684
667
|
vt as A,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
668
|
+
J as B,
|
|
669
|
+
K as C,
|
|
670
|
+
tt as D,
|
|
671
|
+
bt as E,
|
|
672
|
+
yt as F,
|
|
690
673
|
V as G,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
Pt as
|
|
694
|
-
|
|
674
|
+
O as H,
|
|
675
|
+
et as L,
|
|
676
|
+
Pt as M,
|
|
677
|
+
gt as P,
|
|
678
|
+
wt as S,
|
|
695
679
|
xt as T,
|
|
696
|
-
|
|
697
|
-
|
|
680
|
+
nt as W,
|
|
681
|
+
mt as a,
|
|
698
682
|
St as b,
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
683
|
+
ht as c,
|
|
684
|
+
Et as d,
|
|
685
|
+
Tt as e,
|
|
686
|
+
It as f,
|
|
687
|
+
Ht as g,
|
|
688
|
+
At as h,
|
|
689
|
+
Ct as i,
|
|
690
|
+
$t as j,
|
|
691
|
+
Bt as k,
|
|
692
|
+
Lt as l,
|
|
693
|
+
st as m,
|
|
694
|
+
j as n,
|
|
695
|
+
Z as o,
|
|
696
|
+
d as p,
|
|
697
|
+
dt as q,
|
|
698
|
+
pt as r,
|
|
699
|
+
lt as s,
|
|
716
700
|
C as t,
|
|
717
701
|
g as u,
|
|
718
|
-
|
|
719
|
-
w,
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
702
|
+
Y as v,
|
|
703
|
+
v as w,
|
|
704
|
+
ft as x,
|
|
705
|
+
kt as y,
|
|
706
|
+
rt as z
|
|
723
707
|
};
|
|
724
|
-
//# sourceMappingURL=challengeAssert-
|
|
708
|
+
//# sourceMappingURL=challengeAssert-C5DQSUnp.js.map
|