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