@babylonlabs-io/ts-sdk 0.15.0 → 0.15.2
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/{errors-D19BQSaj.js → errors-C5aW6wrA.js} +810 -659
- package/dist/errors-C5aW6wrA.js.map +1 -0
- package/dist/errors-DD3lnhb0.cjs +2 -0
- package/dist/errors-DD3lnhb0.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +60 -1
- 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 +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +64 -6
- 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/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/package.json +1 -1
- package/dist/errors-D19BQSaj.js.map +0 -1
- package/dist/errors-vxNv_NdZ.cjs +0 -2
- package/dist/errors-vxNv_NdZ.cjs.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var he = Object.defineProperty;
|
|
2
|
+
var de = (e, t, n) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => de(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as fe from "bitcoinjs-lib";
|
|
5
|
+
import { script as pe, Transaction as J, address as ge, Psbt as bt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as S } from "buffer";
|
|
7
|
-
import { P as
|
|
8
|
-
import { createPublicClient as
|
|
9
|
-
import { deriveVaultId as
|
|
7
|
+
import { P as be, y as ye, D as Mt, M as Ht, B as xe, T as we, G as yt, u as B, b as me, A as Pe, E as Te, a as ve, d as ke, e as He, f as Ee, s as U, q as Ie, x as Et, h as It, i as St, r as Se } from "./challengeAssert-CenzzhZU.js";
|
|
8
|
+
import { createPublicClient as lt, http as ht, encodeFunctionData as Bt, zeroAddress as Be } from "viem";
|
|
9
|
+
import { deriveVaultId as At } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
10
|
function Ae(e, t, n, s) {
|
|
11
11
|
if (!Number.isInteger(s) || s < 1)
|
|
12
12
|
throw new Error(
|
|
@@ -14,32 +14,32 @@ function Ae(e, t, n, s) {
|
|
|
14
14
|
);
|
|
15
15
|
if (e.length === 0)
|
|
16
16
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
17
|
-
const
|
|
18
|
-
const h = S.from(
|
|
19
|
-
return !!
|
|
17
|
+
const o = e.filter((l) => {
|
|
18
|
+
const h = S.from(l.scriptPubKey, "hex");
|
|
19
|
+
return !!pe.decompile(h);
|
|
20
20
|
});
|
|
21
|
-
if (
|
|
21
|
+
if (o.length === 0)
|
|
22
22
|
throw new Error(
|
|
23
23
|
"Insufficient funds: no valid UTXOs available (all have invalid scripts)"
|
|
24
24
|
);
|
|
25
|
-
const
|
|
25
|
+
const r = [...o].sort((l, h) => h.value - l.value), i = [];
|
|
26
26
|
let a = 0n, c = 0n;
|
|
27
|
-
for (const
|
|
28
|
-
i.push(
|
|
29
|
-
const h = i.length *
|
|
30
|
-
if (c = BigInt(Math.ceil(
|
|
31
|
-
const
|
|
32
|
-
Math.ceil(
|
|
27
|
+
for (const l of r) {
|
|
28
|
+
i.push(l), a += BigInt(l.value);
|
|
29
|
+
const h = i.length * be, u = s * Ht, d = h + u + we;
|
|
30
|
+
if (c = BigInt(Math.ceil(d * n)) + BigInt(ye(n)), a - t - c > Mt) {
|
|
31
|
+
const g = BigInt(
|
|
32
|
+
Math.ceil(Ht * n)
|
|
33
33
|
);
|
|
34
|
-
c +=
|
|
34
|
+
c += g;
|
|
35
35
|
}
|
|
36
36
|
if (a >= t + c) {
|
|
37
|
-
const
|
|
37
|
+
const g = a - t - c;
|
|
38
38
|
return {
|
|
39
39
|
selectedUTXOs: i,
|
|
40
40
|
totalValue: a,
|
|
41
41
|
fee: c,
|
|
42
|
-
changeAmount:
|
|
42
|
+
changeAmount: g
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -47,17 +47,17 @@ function Ae(e, t, n, s) {
|
|
|
47
47
|
`Insufficient funds: need ${t + c} sats (${t} pegin + ${c} fee), have ${a} sats`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return e >
|
|
50
|
+
function Jn(e) {
|
|
51
|
+
return e > Mt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
53
|
+
function Yn() {
|
|
54
|
+
return xe;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function dt(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
58
|
-
return `0x${
|
|
58
|
+
return `0x${J.fromHex(t).getId()}`;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function Qn(e, t, n) {
|
|
61
61
|
if (e.length === 0)
|
|
62
62
|
throw new Error("No input UTXOs provided for split transaction");
|
|
63
63
|
if (t.length === 0)
|
|
@@ -67,43 +67,43 @@ function Yn(e, t, n) {
|
|
|
67
67
|
throw new Error(
|
|
68
68
|
`Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`
|
|
69
69
|
);
|
|
70
|
-
const s =
|
|
71
|
-
|
|
70
|
+
const s = yt(n), o = new J();
|
|
71
|
+
o.version = 2;
|
|
72
72
|
for (const c of e) {
|
|
73
|
-
const
|
|
74
|
-
|
|
73
|
+
const l = S.from(c.txid, "hex").reverse();
|
|
74
|
+
o.addInput(l, c.vout);
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const r = [];
|
|
77
77
|
for (let c = 0; c < t.length; c++) {
|
|
78
|
-
const
|
|
78
|
+
const l = t[c];
|
|
79
79
|
let h;
|
|
80
80
|
try {
|
|
81
|
-
h =
|
|
82
|
-
} catch (
|
|
81
|
+
h = ge.toOutputScript(l.address, s);
|
|
82
|
+
} catch (u) {
|
|
83
83
|
throw new Error(
|
|
84
|
-
`Failed to decode address "${
|
|
84
|
+
`Failed to decode address "${l.address}": ${u instanceof Error ? u.message : String(u)}`
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
o.addOutput(h, Number(l.amount)), r.push({
|
|
88
88
|
txid: "",
|
|
89
89
|
// Will be set after txid calculation
|
|
90
90
|
vout: c,
|
|
91
|
-
value: Number(
|
|
91
|
+
value: Number(l.amount),
|
|
92
92
|
scriptPubKey: h.toString("hex")
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
const i =
|
|
96
|
-
for (const c of
|
|
95
|
+
const i = o.toHex(), a = o.getId();
|
|
96
|
+
for (const c of r)
|
|
97
97
|
c.txid = a;
|
|
98
98
|
return {
|
|
99
99
|
txHex: i,
|
|
100
100
|
txid: a,
|
|
101
|
-
outputs:
|
|
101
|
+
outputs: r
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
const s =
|
|
106
|
-
if (
|
|
104
|
+
function ts(e, t, n) {
|
|
105
|
+
const s = J.fromHex(e), o = new bt();
|
|
106
|
+
if (o.setVersion(s.version), o.setLocktime(s.locktime), !S.isBuffer(n) || n.length !== 32)
|
|
107
107
|
throw new Error(
|
|
108
108
|
`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${S.isBuffer(n) ? `${n.length}-byte Buffer` : typeof n}`
|
|
109
109
|
);
|
|
@@ -111,42 +111,42 @@ function Qn(e, t, n) {
|
|
|
111
111
|
throw new Error(
|
|
112
112
|
`UTXO count mismatch: transaction has ${s.ins.length} input${s.ins.length !== 1 ? "s" : ""}, but ${t.length} UTXO${t.length !== 1 ? "s were" : " was"} provided`
|
|
113
113
|
);
|
|
114
|
-
for (let
|
|
115
|
-
const i = s.ins[
|
|
114
|
+
for (let r = 0; r < s.ins.length; r++) {
|
|
115
|
+
const i = s.ins[r], a = t[r];
|
|
116
116
|
if (!a)
|
|
117
|
-
throw new Error(`Missing UTXO data for input ${
|
|
118
|
-
const c = S.from(i.hash).reverse().toString("hex"),
|
|
119
|
-
if (a.txid !== c || a.vout !==
|
|
117
|
+
throw new Error(`Missing UTXO data for input ${r}`);
|
|
118
|
+
const c = S.from(i.hash).reverse().toString("hex"), l = i.index;
|
|
119
|
+
if (a.txid !== c || a.vout !== l)
|
|
120
120
|
throw new Error(
|
|
121
|
-
`Input ${
|
|
121
|
+
`Input ${r} outpoint mismatch: transaction expects ${c}:${l}, but UTXO ${a.txid}:${a.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
|
|
122
122
|
);
|
|
123
123
|
const h = S.from(a.scriptPubKey, "hex");
|
|
124
124
|
if (!(h.length === 34 && h[0] === 81 && // OP_1 (witness version 1)
|
|
125
125
|
h[1] === 32))
|
|
126
126
|
throw new Error(
|
|
127
|
-
`Input ${
|
|
127
|
+
`Input ${r} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${a.scriptPubKey.substring(0, 20)}...`
|
|
128
128
|
);
|
|
129
|
-
const
|
|
129
|
+
const d = {
|
|
130
130
|
script: S.from(a.scriptPubKey, "hex"),
|
|
131
131
|
value: a.value
|
|
132
132
|
};
|
|
133
|
-
|
|
133
|
+
o.addInput({
|
|
134
134
|
hash: i.hash,
|
|
135
135
|
index: i.index,
|
|
136
136
|
sequence: i.sequence,
|
|
137
|
-
witnessUtxo:
|
|
137
|
+
witnessUtxo: d,
|
|
138
138
|
tapInternalKey: n
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
-
for (const
|
|
142
|
-
|
|
143
|
-
script:
|
|
144
|
-
value:
|
|
141
|
+
for (const r of s.outs)
|
|
142
|
+
o.addOutput({
|
|
143
|
+
script: r.script,
|
|
144
|
+
value: r.value
|
|
145
145
|
});
|
|
146
|
-
return
|
|
146
|
+
return o.toHex();
|
|
147
147
|
}
|
|
148
|
-
var
|
|
149
|
-
function
|
|
148
|
+
var rt = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(rt || {});
|
|
149
|
+
function $e(e) {
|
|
150
150
|
const t = e.length;
|
|
151
151
|
return t === 25 && e[0] === 118 && // OP_DUP
|
|
152
152
|
e[1] === 169 && // OP_HASH160
|
|
@@ -159,17 +159,17 @@ function Be(e) {
|
|
|
159
159
|
e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
|
|
160
160
|
e[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
161
161
|
}
|
|
162
|
-
function
|
|
163
|
-
const n = S.from(e.scriptPubKey, "hex"), s =
|
|
162
|
+
function Ue(e, t) {
|
|
163
|
+
const n = S.from(e.scriptPubKey, "hex"), s = $e(n);
|
|
164
164
|
switch (s) {
|
|
165
|
-
case
|
|
165
|
+
case rt.P2WPKH:
|
|
166
166
|
return {
|
|
167
167
|
witnessUtxo: {
|
|
168
168
|
script: n,
|
|
169
169
|
value: e.value
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
case
|
|
172
|
+
case rt.P2WSH: {
|
|
173
173
|
if (!e.witnessScript)
|
|
174
174
|
throw new Error("Missing witnessScript for P2WSH input");
|
|
175
175
|
return {
|
|
@@ -180,7 +180,7 @@ function $e(e, t) {
|
|
|
180
180
|
witnessScript: S.from(e.witnessScript, "hex")
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
case
|
|
183
|
+
case rt.P2TR: {
|
|
184
184
|
if (t && t.length !== 32)
|
|
185
185
|
throw new Error(
|
|
186
186
|
`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
|
|
@@ -198,7 +198,7 @@ function $e(e, t) {
|
|
|
198
198
|
throw new Error(`Unsupported script type: ${s}`);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function xt(e, t) {
|
|
202
202
|
if (!Number.isInteger(t) || t < 1)
|
|
203
203
|
throw new Error(`inputCount must be a positive integer, got ${t}`);
|
|
204
204
|
return {
|
|
@@ -210,14 +210,14 @@ function bt(e, t) {
|
|
|
210
210
|
}))
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
function
|
|
215
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
213
|
+
const Fe = 21e6 * 1e8, Nt = 1e4;
|
|
214
|
+
function Xt(e) {
|
|
215
|
+
return Number.isInteger(e) && e > 0 && e <= Fe;
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
217
|
+
function Ce(e) {
|
|
218
|
+
return Number.isInteger(e) && e > 0 && e <= Nt;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function qt(e, t) {
|
|
221
221
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
222
222
|
}
|
|
223
223
|
const Oe = {
|
|
@@ -225,13 +225,13 @@ const Oe = {
|
|
|
225
225
|
testnet: "https://mempool.space/testnet/api",
|
|
226
226
|
signet: "https://mempool.space/signet/api"
|
|
227
227
|
};
|
|
228
|
-
async function
|
|
228
|
+
async function at(e, t) {
|
|
229
229
|
try {
|
|
230
230
|
const n = await fetch(e, t);
|
|
231
231
|
if (!n.ok) {
|
|
232
|
-
const
|
|
232
|
+
const o = await n.text();
|
|
233
233
|
throw new Error(
|
|
234
|
-
`Mempool API error (${n.status}): ${
|
|
234
|
+
`Mempool API error (${n.status}): ${o || n.statusText}`
|
|
235
235
|
);
|
|
236
236
|
}
|
|
237
237
|
const s = n.headers.get("content-type");
|
|
@@ -250,15 +250,15 @@ async function Le(e, t) {
|
|
|
250
250
|
}
|
|
251
251
|
});
|
|
252
252
|
if (!n.ok) {
|
|
253
|
-
const
|
|
254
|
-
let
|
|
253
|
+
const o = await n.text();
|
|
254
|
+
let r;
|
|
255
255
|
try {
|
|
256
|
-
|
|
256
|
+
r = JSON.parse(o).message;
|
|
257
257
|
} catch {
|
|
258
|
-
|
|
258
|
+
r = o;
|
|
259
259
|
}
|
|
260
260
|
throw new Error(
|
|
261
|
-
|
|
261
|
+
r || `Failed to broadcast transaction: ${n.statusText}`
|
|
262
262
|
);
|
|
263
263
|
}
|
|
264
264
|
return await n.text();
|
|
@@ -266,10 +266,10 @@ async function Le(e, t) {
|
|
|
266
266
|
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
async function
|
|
270
|
-
return
|
|
269
|
+
async function _e(e, t) {
|
|
270
|
+
return at(`${t}/tx/${e}`);
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
272
|
+
async function es(e, t) {
|
|
273
273
|
try {
|
|
274
274
|
const n = await fetch(`${t}/tx/${e}/hex`);
|
|
275
275
|
if (!n.ok) {
|
|
@@ -283,43 +283,43 @@ async function ts(e, t) {
|
|
|
283
283
|
throw n instanceof Error ? new Error(`Failed to get transaction hex for ${e}: ${n.message}`) : new Error(`Failed to get transaction hex for ${e}: Unknown error`);
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
async function
|
|
287
|
-
const s = await
|
|
288
|
-
if (!
|
|
286
|
+
async function Re(e, t, n) {
|
|
287
|
+
const s = await _e(e, n);
|
|
288
|
+
if (!qt(t, s.vout.length))
|
|
289
289
|
throw new Error(
|
|
290
290
|
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
291
291
|
);
|
|
292
|
-
const
|
|
293
|
-
if (!
|
|
294
|
-
throw new Error(`Invalid UTXO value ${
|
|
292
|
+
const o = s.vout[t];
|
|
293
|
+
if (!Xt(o.value))
|
|
294
|
+
throw new Error(`Invalid UTXO value ${o.value} for ${e}:${t}`);
|
|
295
295
|
return {
|
|
296
296
|
txid: e,
|
|
297
297
|
vout: t,
|
|
298
|
-
value:
|
|
299
|
-
scriptPubKey:
|
|
298
|
+
value: o.value,
|
|
299
|
+
scriptPubKey: o.scriptpubkey
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
|
-
async function
|
|
302
|
+
async function ns(e, t) {
|
|
303
303
|
try {
|
|
304
|
-
const n = await
|
|
304
|
+
const n = await at(`${t}/address/${e}/utxo`), s = await at(`${t}/v1/validate-address/${e}`);
|
|
305
305
|
if (!s.isvalid)
|
|
306
306
|
throw new Error(
|
|
307
307
|
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
308
308
|
);
|
|
309
|
-
for (const
|
|
310
|
-
if (!
|
|
311
|
-
throw new Error(`Invalid vout ${
|
|
312
|
-
if (!
|
|
309
|
+
for (const r of n) {
|
|
310
|
+
if (!qt(r.vout))
|
|
311
|
+
throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
|
|
312
|
+
if (!Xt(r.value))
|
|
313
313
|
throw new Error(
|
|
314
|
-
`Invalid UTXO value ${
|
|
314
|
+
`Invalid UTXO value ${r.value} for ${r.txid}:${r.vout}`
|
|
315
315
|
);
|
|
316
316
|
}
|
|
317
|
-
return n.sort((
|
|
318
|
-
txid:
|
|
319
|
-
vout:
|
|
320
|
-
value:
|
|
317
|
+
return n.sort((r, i) => i.value - r.value).map((r) => ({
|
|
318
|
+
txid: r.txid,
|
|
319
|
+
vout: r.vout,
|
|
320
|
+
value: r.value,
|
|
321
321
|
scriptPubKey: s.scriptPubKey,
|
|
322
|
-
confirmed:
|
|
322
|
+
confirmed: r.status.confirmed
|
|
323
323
|
}));
|
|
324
324
|
} catch (n) {
|
|
325
325
|
throw n instanceof Error ? new Error(
|
|
@@ -329,11 +329,11 @@ async function es(e, t) {
|
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
function
|
|
332
|
+
function ss(e) {
|
|
333
333
|
return Oe[e];
|
|
334
334
|
}
|
|
335
|
-
async function
|
|
336
|
-
return
|
|
335
|
+
async function os(e, t) {
|
|
336
|
+
return at(`${t}/address/${e}/txs`);
|
|
337
337
|
}
|
|
338
338
|
async function rs(e) {
|
|
339
339
|
const t = await fetch(`${e}/v1/fees/recommended`);
|
|
@@ -348,10 +348,10 @@ async function rs(e) {
|
|
|
348
348
|
"economyFee",
|
|
349
349
|
"minimumFee"
|
|
350
350
|
];
|
|
351
|
-
for (const
|
|
352
|
-
if (!
|
|
351
|
+
for (const o of s)
|
|
352
|
+
if (!Ce(n[o]))
|
|
353
353
|
throw new Error(
|
|
354
|
-
`Invalid fee rate ${
|
|
354
|
+
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${Nt}`
|
|
355
355
|
);
|
|
356
356
|
if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
|
|
357
357
|
throw new Error(
|
|
@@ -359,7 +359,7 @@ async function rs(e) {
|
|
|
359
359
|
);
|
|
360
360
|
return n;
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const j = [
|
|
363
363
|
{
|
|
364
364
|
type: "function",
|
|
365
365
|
name: "submitPeginRequest",
|
|
@@ -493,6 +493,34 @@ const ct = [
|
|
|
493
493
|
],
|
|
494
494
|
stateMutability: "payable"
|
|
495
495
|
},
|
|
496
|
+
{
|
|
497
|
+
type: "function",
|
|
498
|
+
name: "submitPeginRequestBatch",
|
|
499
|
+
inputs: [
|
|
500
|
+
{ name: "depositor", type: "address", internalType: "address" },
|
|
501
|
+
{ name: "vaultProvider", type: "address", internalType: "address" },
|
|
502
|
+
{
|
|
503
|
+
name: "requests",
|
|
504
|
+
type: "tuple[]",
|
|
505
|
+
internalType: "struct IBTCVaultRegistry.BatchPeginRequest[]",
|
|
506
|
+
components: [
|
|
507
|
+
{ name: "depositorBtcPubKey", type: "bytes32", internalType: "bytes32" },
|
|
508
|
+
{ name: "btcPopSignature", type: "bytes", internalType: "bytes" },
|
|
509
|
+
{ name: "unsignedPrePeginTx", type: "bytes", internalType: "bytes" },
|
|
510
|
+
{ name: "depositorSignedPeginTx", type: "bytes", internalType: "bytes" },
|
|
511
|
+
{ name: "hashlock", type: "bytes32", internalType: "bytes32" },
|
|
512
|
+
{ name: "htlcVout", type: "uint8", internalType: "uint8" },
|
|
513
|
+
{ name: "referralCode", type: "uint32", internalType: "uint32" },
|
|
514
|
+
{ name: "depositorPayoutBtcAddress", type: "bytes", internalType: "bytes" },
|
|
515
|
+
{ name: "depositorWotsPkHash", type: "bytes32", internalType: "bytes32" }
|
|
516
|
+
]
|
|
517
|
+
}
|
|
518
|
+
],
|
|
519
|
+
outputs: [
|
|
520
|
+
{ name: "vaultIds", type: "bytes32[]", internalType: "bytes32[]" }
|
|
521
|
+
],
|
|
522
|
+
stateMutability: "payable"
|
|
523
|
+
},
|
|
496
524
|
{
|
|
497
525
|
type: "function",
|
|
498
526
|
name: "activateVaultWithSecret",
|
|
@@ -624,7 +652,7 @@ const ct = [
|
|
|
624
652
|
name: "PeginSignaturesIncomplete",
|
|
625
653
|
inputs: []
|
|
626
654
|
}
|
|
627
|
-
],
|
|
655
|
+
], q = {
|
|
628
656
|
// VaultAlreadyExists()
|
|
629
657
|
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
630
658
|
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
@@ -654,7 +682,7 @@ const ct = [
|
|
|
654
682
|
// InvalidPeginFee(uint256,uint256)
|
|
655
683
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
656
684
|
};
|
|
657
|
-
function
|
|
685
|
+
function mt(e) {
|
|
658
686
|
if (!e || typeof e != "object") return;
|
|
659
687
|
const t = e;
|
|
660
688
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -662,8 +690,8 @@ function xt(e) {
|
|
|
662
690
|
if (typeof t.details == "string" && t.details.startsWith("0x"))
|
|
663
691
|
return t.details;
|
|
664
692
|
let n = t.cause, s = 0;
|
|
665
|
-
const
|
|
666
|
-
for (; n && typeof n == "object" && s <
|
|
693
|
+
const o = 5;
|
|
694
|
+
for (; n && typeof n == "object" && s < o; ) {
|
|
667
695
|
const a = n;
|
|
668
696
|
if (typeof a.data == "string" && a.data.startsWith("0x"))
|
|
669
697
|
return a.data;
|
|
@@ -673,26 +701,26 @@ function xt(e) {
|
|
|
673
701
|
if (i)
|
|
674
702
|
return i[1];
|
|
675
703
|
}
|
|
676
|
-
function
|
|
677
|
-
const t =
|
|
704
|
+
function is(e) {
|
|
705
|
+
const t = mt(e);
|
|
678
706
|
if (t) {
|
|
679
707
|
const n = t.substring(0, 10);
|
|
680
|
-
return
|
|
708
|
+
return q[t] ?? q[n];
|
|
681
709
|
}
|
|
682
710
|
}
|
|
683
|
-
function
|
|
684
|
-
const t =
|
|
711
|
+
function as(e) {
|
|
712
|
+
const t = mt(e);
|
|
685
713
|
if (t === void 0) return !1;
|
|
686
714
|
const n = t.substring(0, 10);
|
|
687
|
-
return t in
|
|
715
|
+
return t in q || n in q;
|
|
688
716
|
}
|
|
689
|
-
function
|
|
717
|
+
function M(e) {
|
|
690
718
|
console.error("[Contract Error] Raw error:", e);
|
|
691
|
-
const t =
|
|
719
|
+
const t = mt(e);
|
|
692
720
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
693
|
-
const s = t.substring(0, 10),
|
|
694
|
-
if (
|
|
695
|
-
throw console.error("[Contract Error] Known error:",
|
|
721
|
+
const s = t.substring(0, 10), o = q[t] ?? q[s];
|
|
722
|
+
if (o)
|
|
723
|
+
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
696
724
|
}
|
|
697
725
|
const n = (e == null ? void 0 : e.message) || "";
|
|
698
726
|
if (n.includes("gas limit too high") || n.includes("21000000") || n.includes("Internal JSON-RPC error")) {
|
|
@@ -708,24 +736,25 @@ function ut(e) {
|
|
|
708
736
|
}
|
|
709
737
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
710
738
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
739
|
+
const We = 0;
|
|
740
|
+
function Ve(e, t, n, s) {
|
|
741
|
+
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
742
|
+
return o ? Promise.resolve({
|
|
714
743
|
txid: e,
|
|
715
744
|
vout: t,
|
|
716
|
-
value:
|
|
717
|
-
scriptPubKey:
|
|
718
|
-
}) :
|
|
745
|
+
value: o.value,
|
|
746
|
+
scriptPubKey: o.scriptPubKey
|
|
747
|
+
}) : Re(e, t, s);
|
|
719
748
|
}
|
|
720
|
-
const
|
|
721
|
-
class
|
|
749
|
+
const $t = 12e4;
|
|
750
|
+
class cs {
|
|
722
751
|
/**
|
|
723
752
|
* Creates a new PeginManager instance.
|
|
724
753
|
*
|
|
725
754
|
* @param config - Manager configuration including wallets and contract addresses
|
|
726
755
|
*/
|
|
727
756
|
constructor(t) {
|
|
728
|
-
|
|
757
|
+
p(this, "config");
|
|
729
758
|
this.config = t;
|
|
730
759
|
}
|
|
731
760
|
/**
|
|
@@ -749,17 +778,17 @@ class as {
|
|
|
749
778
|
* @throws Error if wallet operations fail or insufficient funds
|
|
750
779
|
*/
|
|
751
780
|
async preparePegin(t) {
|
|
752
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n,
|
|
781
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, o = B(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(B), i = t.universalChallengerBtcPubkeys.map(B);
|
|
753
782
|
if (t.hashlocks.length !== t.amounts.length)
|
|
754
783
|
throw new Error(
|
|
755
784
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
756
785
|
);
|
|
757
786
|
if (t.hashlocks.length === 0)
|
|
758
787
|
throw new Error("hashlocks must contain at least one entry");
|
|
759
|
-
const a =
|
|
788
|
+
const a = r.length, c = {
|
|
760
789
|
depositorPubkey: s,
|
|
761
|
-
vaultProviderPubkey:
|
|
762
|
-
vaultKeeperPubkeys:
|
|
790
|
+
vaultProviderPubkey: o,
|
|
791
|
+
vaultKeeperPubkeys: r,
|
|
763
792
|
universalChallengerPubkeys: i,
|
|
764
793
|
hashlocks: t.hashlocks,
|
|
765
794
|
timelockRefund: t.timelockRefund,
|
|
@@ -769,62 +798,62 @@ class as {
|
|
|
769
798
|
councilQuorum: t.councilQuorum,
|
|
770
799
|
councilSize: t.councilSize,
|
|
771
800
|
network: this.config.btcNetwork
|
|
772
|
-
},
|
|
801
|
+
}, l = await me(c), h = Ae(
|
|
773
802
|
[...t.availableUTXOs],
|
|
774
|
-
|
|
803
|
+
l.totalOutputValue,
|
|
775
804
|
t.mempoolFeeRate,
|
|
776
|
-
|
|
777
|
-
),
|
|
778
|
-
unfundedTxHex:
|
|
805
|
+
Pe(l.htlcValues.length)
|
|
806
|
+
), u = yt(this.config.btcNetwork), d = Te({
|
|
807
|
+
unfundedTxHex: l.psbtHex,
|
|
779
808
|
selectedUTXOs: h.selectedUTXOs,
|
|
780
809
|
changeAddress: t.changeAddress,
|
|
781
810
|
changeAmount: h.changeAmount,
|
|
782
|
-
network:
|
|
783
|
-
}),
|
|
784
|
-
for (let
|
|
785
|
-
const
|
|
811
|
+
network: u
|
|
812
|
+
}), y = B(dt(d)), g = [], x = [], P = [];
|
|
813
|
+
for (let f = 0; f < t.hashlocks.length; f++) {
|
|
814
|
+
const w = await ve({
|
|
786
815
|
prePeginParams: c,
|
|
787
816
|
timelockPegin: t.timelockPegin,
|
|
788
|
-
fundedPrePeginTxHex:
|
|
789
|
-
htlcVout:
|
|
790
|
-
}), v = await
|
|
791
|
-
peginTxHex:
|
|
792
|
-
fundedPrePeginTxHex:
|
|
817
|
+
fundedPrePeginTxHex: d,
|
|
818
|
+
htlcVout: f
|
|
819
|
+
}), v = await ke({
|
|
820
|
+
peginTxHex: w.txHex,
|
|
821
|
+
fundedPrePeginTxHex: d,
|
|
793
822
|
depositorPubkey: s,
|
|
794
|
-
vaultProviderPubkey:
|
|
795
|
-
vaultKeeperPubkeys:
|
|
823
|
+
vaultProviderPubkey: o,
|
|
824
|
+
vaultKeeperPubkeys: r,
|
|
796
825
|
universalChallengerPubkeys: i,
|
|
797
|
-
hashlock: t.hashlocks[
|
|
826
|
+
hashlock: t.hashlocks[f],
|
|
798
827
|
timelockRefund: t.timelockRefund,
|
|
799
828
|
network: this.config.btcNetwork
|
|
800
829
|
});
|
|
801
|
-
|
|
802
|
-
|
|
830
|
+
g.push(w), x.push(v.psbtHex), P.push(
|
|
831
|
+
xt(n, 1)
|
|
803
832
|
);
|
|
804
833
|
}
|
|
805
|
-
const
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
),
|
|
809
|
-
for (let
|
|
810
|
-
const
|
|
811
|
-
|
|
834
|
+
const m = await this.signPsbtsWithFallback(
|
|
835
|
+
x,
|
|
836
|
+
P
|
|
837
|
+
), b = [];
|
|
838
|
+
for (let f = 0; f < m.length; f++) {
|
|
839
|
+
const w = He(
|
|
840
|
+
m[f],
|
|
812
841
|
s
|
|
813
|
-
), v =
|
|
814
|
-
|
|
815
|
-
htlcVout:
|
|
816
|
-
htlcValue:
|
|
842
|
+
), v = Ee(m[f]);
|
|
843
|
+
b.push({
|
|
844
|
+
htlcVout: f,
|
|
845
|
+
htlcValue: l.htlcValues[f],
|
|
817
846
|
peginTxHex: v,
|
|
818
|
-
peginTxid:
|
|
819
|
-
peginInputSignature:
|
|
820
|
-
vaultScriptPubKey:
|
|
847
|
+
peginTxid: g[f].txid,
|
|
848
|
+
peginInputSignature: w,
|
|
849
|
+
vaultScriptPubKey: g[f].vaultScriptPubKey
|
|
821
850
|
});
|
|
822
851
|
}
|
|
823
852
|
return {
|
|
824
|
-
fundedPrePeginTxHex:
|
|
825
|
-
prePeginTxid:
|
|
826
|
-
unsignedPrePeginTxHex:
|
|
827
|
-
perVault:
|
|
853
|
+
fundedPrePeginTxHex: d,
|
|
854
|
+
prePeginTxid: y,
|
|
855
|
+
unsignedPrePeginTxHex: l.psbtHex,
|
|
856
|
+
perVault: b,
|
|
828
857
|
selectedUTXOs: h.selectedUTXOs,
|
|
829
858
|
fee: h.fee,
|
|
830
859
|
changeAmount: h.changeAmount
|
|
@@ -839,23 +868,23 @@ class as {
|
|
|
839
868
|
*/
|
|
840
869
|
async signPsbtsWithFallback(t, n) {
|
|
841
870
|
if (typeof this.config.btcWallet.signPsbts == "function") {
|
|
842
|
-
const
|
|
871
|
+
const o = await this.config.btcWallet.signPsbts(
|
|
843
872
|
t,
|
|
844
873
|
n
|
|
845
874
|
);
|
|
846
|
-
if (
|
|
875
|
+
if (o.length !== t.length)
|
|
847
876
|
throw new Error(
|
|
848
|
-
`Expected ${t.length} signed PSBTs but received ${
|
|
877
|
+
`Expected ${t.length} signed PSBTs but received ${o.length}`
|
|
849
878
|
);
|
|
850
|
-
return
|
|
879
|
+
return o;
|
|
851
880
|
}
|
|
852
881
|
const s = [];
|
|
853
|
-
for (let
|
|
854
|
-
const
|
|
855
|
-
t[
|
|
856
|
-
n[
|
|
882
|
+
for (let o = 0; o < t.length; o++) {
|
|
883
|
+
const r = await this.config.btcWallet.signPsbt(
|
|
884
|
+
t[o],
|
|
885
|
+
n[o]
|
|
857
886
|
);
|
|
858
|
-
s.push(
|
|
887
|
+
s.push(r);
|
|
859
888
|
}
|
|
860
889
|
return s;
|
|
861
890
|
}
|
|
@@ -875,11 +904,11 @@ class as {
|
|
|
875
904
|
* @throws Error if signing or broadcasting fails
|
|
876
905
|
*/
|
|
877
906
|
async signAndBroadcast(t) {
|
|
878
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t,
|
|
879
|
-
if (
|
|
907
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = J.fromHex(o);
|
|
908
|
+
if (r.ins.length === 0)
|
|
880
909
|
throw new Error("Transaction has no inputs");
|
|
881
|
-
const i = new
|
|
882
|
-
i.setVersion(
|
|
910
|
+
const i = new bt();
|
|
911
|
+
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
883
912
|
const a = s.startsWith("0x") ? s.slice(2) : s;
|
|
884
913
|
if (a.length !== 64 || !/^[0-9a-fA-F]+$/.test(a))
|
|
885
914
|
throw new Error(
|
|
@@ -890,45 +919,55 @@ class as {
|
|
|
890
919
|
throw new Error(
|
|
891
920
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
892
921
|
);
|
|
893
|
-
const
|
|
894
|
-
const
|
|
895
|
-
return
|
|
896
|
-
(
|
|
922
|
+
const l = this.config.mempoolApiUrl, h = r.ins.map((b) => {
|
|
923
|
+
const f = S.from(b.hash).reverse().toString("hex"), w = b.index;
|
|
924
|
+
return Ve(f, w, t.localPrevouts, l).then(
|
|
925
|
+
(v) => ({ input: b, utxoData: v, txid: f, vout: w })
|
|
926
|
+
);
|
|
927
|
+
}), u = await Promise.all(h), d = u.reduce(
|
|
928
|
+
(b, f) => b + BigInt(f.utxoData.value),
|
|
929
|
+
0n
|
|
930
|
+
), y = r.outs.reduce(
|
|
931
|
+
(b, f) => b + BigInt(f.value),
|
|
932
|
+
0n
|
|
933
|
+
);
|
|
934
|
+
if (d < y)
|
|
935
|
+
throw new Error(
|
|
936
|
+
`UTXO value mismatch: total input value (${d} sat) is less than total output value (${y} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
897
937
|
);
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const P = $e(
|
|
938
|
+
for (const { input: b, utxoData: f, txid: w, vout: v } of u) {
|
|
939
|
+
const T = Ue(
|
|
901
940
|
{
|
|
902
|
-
value:
|
|
903
|
-
scriptPubKey:
|
|
941
|
+
value: f.value,
|
|
942
|
+
scriptPubKey: f.scriptPubKey
|
|
904
943
|
},
|
|
905
944
|
c
|
|
906
945
|
);
|
|
907
946
|
i.addInput({
|
|
908
|
-
hash:
|
|
909
|
-
index:
|
|
910
|
-
sequence:
|
|
911
|
-
...
|
|
947
|
+
hash: b.hash,
|
|
948
|
+
index: b.index,
|
|
949
|
+
sequence: b.sequence,
|
|
950
|
+
...T
|
|
912
951
|
});
|
|
913
952
|
}
|
|
914
|
-
for (const
|
|
953
|
+
for (const b of r.outs)
|
|
915
954
|
i.addOutput({
|
|
916
|
-
script:
|
|
917
|
-
value:
|
|
955
|
+
script: b.script,
|
|
956
|
+
value: b.value
|
|
918
957
|
});
|
|
919
|
-
const
|
|
958
|
+
const g = await this.config.btcWallet.signPsbt(i.toHex()), x = bt.fromHex(g);
|
|
920
959
|
try {
|
|
921
|
-
|
|
922
|
-
} catch (
|
|
923
|
-
if (!
|
|
924
|
-
(
|
|
960
|
+
x.finalizeAllInputs();
|
|
961
|
+
} catch (b) {
|
|
962
|
+
if (!x.data.inputs.every(
|
|
963
|
+
(w) => w.finalScriptWitness || w.finalScriptSig
|
|
925
964
|
))
|
|
926
965
|
throw new Error(
|
|
927
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
966
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${b}`
|
|
928
967
|
);
|
|
929
968
|
}
|
|
930
|
-
const
|
|
931
|
-
return await Le(
|
|
969
|
+
const P = x.extractTransaction().toHex();
|
|
970
|
+
return await Le(P, l);
|
|
932
971
|
}
|
|
933
972
|
/**
|
|
934
973
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -951,62 +990,62 @@ class as {
|
|
|
951
990
|
const {
|
|
952
991
|
depositorBtcPubkey: n,
|
|
953
992
|
unsignedPrePeginTx: s,
|
|
954
|
-
depositorSignedPeginTx:
|
|
955
|
-
vaultProvider:
|
|
993
|
+
depositorSignedPeginTx: o,
|
|
994
|
+
vaultProvider: r,
|
|
956
995
|
hashlock: i,
|
|
957
996
|
htlcVout: a,
|
|
958
997
|
onPopSigned: c,
|
|
959
|
-
depositorPayoutBtcAddress:
|
|
998
|
+
depositorPayoutBtcAddress: l,
|
|
960
999
|
depositorWotsPkHash: h,
|
|
961
|
-
preSignedBtcPopSignature:
|
|
1000
|
+
preSignedBtcPopSignature: u
|
|
962
1001
|
} = t;
|
|
963
1002
|
if (!this.config.ethWallet.account)
|
|
964
1003
|
throw new Error("Ethereum wallet account not found");
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
1004
|
+
const d = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
|
|
1005
|
+
d,
|
|
1006
|
+
u
|
|
968
1007
|
);
|
|
969
1008
|
c && await c();
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
),
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
),
|
|
976
|
-
if (await this.checkVaultExists(
|
|
1009
|
+
const g = U(n), x = U(s), P = U(o), m = await this.resolvePayoutScriptPubKey(
|
|
1010
|
+
l
|
|
1011
|
+
), b = dt(P), f = await At(
|
|
1012
|
+
B(b),
|
|
1013
|
+
B(d)
|
|
1014
|
+
), w = U(f);
|
|
1015
|
+
if (await this.checkVaultExists(w))
|
|
977
1016
|
throw new Error(
|
|
978
|
-
`Vault already exists (ID: ${
|
|
1017
|
+
`Vault already exists (ID: ${w}, peginTxHash: ${b}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
979
1018
|
);
|
|
980
|
-
const T =
|
|
1019
|
+
const T = lt({
|
|
981
1020
|
chain: this.config.ethChain,
|
|
982
|
-
transport:
|
|
1021
|
+
transport: ht()
|
|
983
1022
|
});
|
|
984
|
-
let
|
|
1023
|
+
let H;
|
|
985
1024
|
try {
|
|
986
|
-
|
|
1025
|
+
H = await T.readContract({
|
|
987
1026
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
988
|
-
abi:
|
|
1027
|
+
abi: j,
|
|
989
1028
|
functionName: "getPegInFee",
|
|
990
|
-
args: [
|
|
1029
|
+
args: [r]
|
|
991
1030
|
});
|
|
992
1031
|
} catch {
|
|
993
1032
|
throw new Error(
|
|
994
1033
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
995
1034
|
);
|
|
996
1035
|
}
|
|
997
|
-
const
|
|
998
|
-
abi:
|
|
1036
|
+
const E = Bt({
|
|
1037
|
+
abi: j,
|
|
999
1038
|
functionName: "submitPeginRequest",
|
|
1000
1039
|
args: [
|
|
1001
|
-
|
|
1002
|
-
b,
|
|
1040
|
+
d,
|
|
1003
1041
|
g,
|
|
1004
|
-
|
|
1042
|
+
y,
|
|
1005
1043
|
x,
|
|
1006
|
-
|
|
1044
|
+
P,
|
|
1045
|
+
r,
|
|
1007
1046
|
i,
|
|
1008
1047
|
a,
|
|
1009
|
-
|
|
1048
|
+
m,
|
|
1010
1049
|
h
|
|
1011
1050
|
]
|
|
1012
1051
|
});
|
|
@@ -1014,39 +1053,151 @@ class as {
|
|
|
1014
1053
|
try {
|
|
1015
1054
|
I = await T.estimateGas({
|
|
1016
1055
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1017
|
-
data:
|
|
1018
|
-
value:
|
|
1056
|
+
data: E,
|
|
1057
|
+
value: H,
|
|
1019
1058
|
account: this.config.ethWallet.account.address
|
|
1020
1059
|
});
|
|
1021
1060
|
} catch (O) {
|
|
1022
|
-
|
|
1061
|
+
M(O);
|
|
1023
1062
|
}
|
|
1024
|
-
let
|
|
1063
|
+
let C;
|
|
1025
1064
|
try {
|
|
1026
|
-
|
|
1065
|
+
C = await this.config.ethWallet.sendTransaction({
|
|
1027
1066
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1028
|
-
data:
|
|
1029
|
-
value:
|
|
1067
|
+
data: E,
|
|
1068
|
+
value: H,
|
|
1030
1069
|
account: this.config.ethWallet.account,
|
|
1031
1070
|
chain: this.config.ethChain,
|
|
1032
1071
|
gas: I
|
|
1033
1072
|
});
|
|
1034
1073
|
} catch (O) {
|
|
1035
|
-
|
|
1074
|
+
M(O);
|
|
1036
1075
|
}
|
|
1037
|
-
const
|
|
1038
|
-
hash:
|
|
1039
|
-
timeout:
|
|
1076
|
+
const D = await T.waitForTransactionReceipt({
|
|
1077
|
+
hash: C,
|
|
1078
|
+
timeout: $t
|
|
1040
1079
|
});
|
|
1041
|
-
return
|
|
1080
|
+
return D.status === "reverted" && M(
|
|
1042
1081
|
new Error(
|
|
1043
|
-
`Transaction reverted. Hash: ${
|
|
1082
|
+
`Transaction reverted. Hash: ${C}. Check the transaction on block explorer for details.`
|
|
1044
1083
|
)
|
|
1045
1084
|
), {
|
|
1046
|
-
ethTxHash:
|
|
1047
|
-
vaultId:
|
|
1048
|
-
peginTxHash:
|
|
1049
|
-
btcPopSignature:
|
|
1085
|
+
ethTxHash: D.transactionHash,
|
|
1086
|
+
vaultId: w,
|
|
1087
|
+
peginTxHash: b,
|
|
1088
|
+
btcPopSignature: y
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Register multiple pegins on Ethereum in a single transaction.
|
|
1093
|
+
*
|
|
1094
|
+
* Uses the contract's submitPeginRequestBatch() to submit all vault
|
|
1095
|
+
* registrations atomically. All vaults must share the same vault provider.
|
|
1096
|
+
* The PoP signature is signed once and included in each request.
|
|
1097
|
+
*
|
|
1098
|
+
* @param params - Batch registration parameters
|
|
1099
|
+
* @returns Batch result with per-vault IDs and single ETH tx hash
|
|
1100
|
+
*/
|
|
1101
|
+
async registerPeginBatchOnChain(t) {
|
|
1102
|
+
const { vaultProvider: n, requests: s, preSignedBtcPopSignature: o, onPopSigned: r } = t;
|
|
1103
|
+
if (s.length === 0)
|
|
1104
|
+
throw new Error("Batch pegin requires at least one request");
|
|
1105
|
+
if (!this.config.ethWallet.account)
|
|
1106
|
+
throw new Error("Ethereum wallet account not found");
|
|
1107
|
+
const i = this.config.ethWallet.account.address, a = await this.resolvePopSignature(
|
|
1108
|
+
i,
|
|
1109
|
+
o
|
|
1110
|
+
);
|
|
1111
|
+
r && await r();
|
|
1112
|
+
const c = [];
|
|
1113
|
+
for (const b of s)
|
|
1114
|
+
c.push(
|
|
1115
|
+
await this.resolvePayoutScriptPubKey(b.depositorPayoutBtcAddress)
|
|
1116
|
+
);
|
|
1117
|
+
const l = [];
|
|
1118
|
+
for (const b of s) {
|
|
1119
|
+
const f = U(
|
|
1120
|
+
b.depositorSignedPeginTx
|
|
1121
|
+
), w = dt(f), v = await At(
|
|
1122
|
+
B(w),
|
|
1123
|
+
B(i)
|
|
1124
|
+
), T = U(v);
|
|
1125
|
+
if (await this.checkVaultExists(T))
|
|
1126
|
+
throw new Error(
|
|
1127
|
+
`Vault already exists (ID: ${T}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
|
|
1128
|
+
);
|
|
1129
|
+
l.push({ vaultId: T, peginTxHash: w });
|
|
1130
|
+
}
|
|
1131
|
+
const h = lt({
|
|
1132
|
+
chain: this.config.ethChain,
|
|
1133
|
+
transport: ht()
|
|
1134
|
+
});
|
|
1135
|
+
let u;
|
|
1136
|
+
try {
|
|
1137
|
+
u = await h.readContract({
|
|
1138
|
+
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1139
|
+
abi: j,
|
|
1140
|
+
functionName: "getPegInFee",
|
|
1141
|
+
args: [n]
|
|
1142
|
+
});
|
|
1143
|
+
} catch {
|
|
1144
|
+
throw new Error(
|
|
1145
|
+
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
const d = u * BigInt(s.length), y = s.map((b, f) => ({
|
|
1149
|
+
depositorBtcPubKey: U(b.depositorBtcPubkey),
|
|
1150
|
+
btcPopSignature: a,
|
|
1151
|
+
unsignedPrePeginTx: U(b.unsignedPrePeginTx),
|
|
1152
|
+
depositorSignedPeginTx: U(
|
|
1153
|
+
b.depositorSignedPeginTx
|
|
1154
|
+
),
|
|
1155
|
+
hashlock: b.hashlock,
|
|
1156
|
+
htlcVout: b.htlcVout,
|
|
1157
|
+
referralCode: We,
|
|
1158
|
+
depositorPayoutBtcAddress: c[f],
|
|
1159
|
+
depositorWotsPkHash: b.depositorWotsPkHash
|
|
1160
|
+
})), g = Bt({
|
|
1161
|
+
abi: j,
|
|
1162
|
+
functionName: "submitPeginRequestBatch",
|
|
1163
|
+
args: [i, n, y]
|
|
1164
|
+
});
|
|
1165
|
+
let x;
|
|
1166
|
+
try {
|
|
1167
|
+
x = await h.estimateGas({
|
|
1168
|
+
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1169
|
+
data: g,
|
|
1170
|
+
value: d,
|
|
1171
|
+
account: this.config.ethWallet.account.address
|
|
1172
|
+
});
|
|
1173
|
+
} catch (b) {
|
|
1174
|
+
M(b);
|
|
1175
|
+
}
|
|
1176
|
+
let P;
|
|
1177
|
+
try {
|
|
1178
|
+
P = await this.config.ethWallet.sendTransaction({
|
|
1179
|
+
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1180
|
+
data: g,
|
|
1181
|
+
value: d,
|
|
1182
|
+
account: this.config.ethWallet.account,
|
|
1183
|
+
chain: this.config.ethChain,
|
|
1184
|
+
gas: x
|
|
1185
|
+
});
|
|
1186
|
+
} catch (b) {
|
|
1187
|
+
M(b);
|
|
1188
|
+
}
|
|
1189
|
+
const m = await h.waitForTransactionReceipt({
|
|
1190
|
+
hash: P,
|
|
1191
|
+
timeout: $t
|
|
1192
|
+
});
|
|
1193
|
+
return m.status === "reverted" && M(
|
|
1194
|
+
new Error(
|
|
1195
|
+
`Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
|
|
1196
|
+
)
|
|
1197
|
+
), {
|
|
1198
|
+
ethTxHash: m.transactionHash,
|
|
1199
|
+
vaults: l,
|
|
1200
|
+
btcPopSignature: a
|
|
1050
1201
|
};
|
|
1051
1202
|
}
|
|
1052
1203
|
/**
|
|
@@ -1057,15 +1208,15 @@ class as {
|
|
|
1057
1208
|
*/
|
|
1058
1209
|
async checkVaultExists(t) {
|
|
1059
1210
|
try {
|
|
1060
|
-
return (await
|
|
1211
|
+
return (await lt({
|
|
1061
1212
|
chain: this.config.ethChain,
|
|
1062
|
-
transport:
|
|
1213
|
+
transport: ht()
|
|
1063
1214
|
}).readContract({
|
|
1064
1215
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1065
|
-
abi:
|
|
1216
|
+
abi: j,
|
|
1066
1217
|
functionName: "getBTCVault",
|
|
1067
1218
|
args: [t]
|
|
1068
|
-
})).depositor !==
|
|
1219
|
+
})).depositor !== Be;
|
|
1069
1220
|
} catch {
|
|
1070
1221
|
return !1;
|
|
1071
1222
|
}
|
|
@@ -1083,19 +1234,19 @@ class as {
|
|
|
1083
1234
|
n = t;
|
|
1084
1235
|
else {
|
|
1085
1236
|
n = await this.config.btcWallet.getAddress();
|
|
1086
|
-
const
|
|
1087
|
-
if (!
|
|
1237
|
+
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1238
|
+
if (!Ie(
|
|
1088
1239
|
n,
|
|
1089
|
-
|
|
1240
|
+
o,
|
|
1090
1241
|
this.config.btcNetwork
|
|
1091
1242
|
))
|
|
1092
1243
|
throw new Error(
|
|
1093
1244
|
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
1094
1245
|
);
|
|
1095
1246
|
}
|
|
1096
|
-
const s =
|
|
1247
|
+
const s = yt(this.config.btcNetwork);
|
|
1097
1248
|
try {
|
|
1098
|
-
return `0x${
|
|
1249
|
+
return `0x${fe.address.toOutputScript(n, s).toString("hex")}`;
|
|
1099
1250
|
} catch {
|
|
1100
1251
|
throw new Error(
|
|
1101
1252
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1111,11 +1262,11 @@ class as {
|
|
|
1111
1262
|
async resolvePopSignature(t, n) {
|
|
1112
1263
|
if (n)
|
|
1113
1264
|
return n;
|
|
1114
|
-
const s = this.config.vaultContracts.btcVaultRegistry,
|
|
1115
|
-
|
|
1265
|
+
const s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1266
|
+
o,
|
|
1116
1267
|
"bip322-simple"
|
|
1117
1268
|
);
|
|
1118
|
-
return
|
|
1269
|
+
return r.startsWith("0x") ? r : `0x${S.from(r, "base64").toString("hex")}`;
|
|
1119
1270
|
}
|
|
1120
1271
|
/**
|
|
1121
1272
|
* Gets the configured Bitcoin network.
|
|
@@ -1134,14 +1285,14 @@ class as {
|
|
|
1134
1285
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1135
1286
|
}
|
|
1136
1287
|
}
|
|
1137
|
-
class
|
|
1288
|
+
class us {
|
|
1138
1289
|
/**
|
|
1139
1290
|
* Creates a new PayoutManager instance.
|
|
1140
1291
|
*
|
|
1141
1292
|
* @param config - Manager configuration including wallet
|
|
1142
1293
|
*/
|
|
1143
1294
|
constructor(t) {
|
|
1144
|
-
|
|
1295
|
+
p(this, "config");
|
|
1145
1296
|
this.config = t;
|
|
1146
1297
|
}
|
|
1147
1298
|
/**
|
|
@@ -1171,10 +1322,10 @@ class cs {
|
|
|
1171
1322
|
t.payoutTxHex,
|
|
1172
1323
|
t.registeredPayoutScriptPubKey
|
|
1173
1324
|
);
|
|
1174
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } =
|
|
1325
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Et(
|
|
1175
1326
|
n,
|
|
1176
1327
|
t.depositorBtcPubkey
|
|
1177
|
-
),
|
|
1328
|
+
), o = await It({
|
|
1178
1329
|
payoutTxHex: t.payoutTxHex,
|
|
1179
1330
|
peginTxHex: t.peginTxHex,
|
|
1180
1331
|
assertTxHex: t.assertTxHex,
|
|
@@ -1184,12 +1335,12 @@ class cs {
|
|
|
1184
1335
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
1185
1336
|
timelockPegin: t.timelockPegin,
|
|
1186
1337
|
network: this.config.network
|
|
1187
|
-
}),
|
|
1188
|
-
|
|
1189
|
-
|
|
1338
|
+
}), r = await this.config.btcWallet.signPsbt(
|
|
1339
|
+
o.psbtHex,
|
|
1340
|
+
xt(n, 1)
|
|
1190
1341
|
);
|
|
1191
1342
|
return {
|
|
1192
|
-
signature:
|
|
1343
|
+
signature: St(r, s),
|
|
1193
1344
|
depositorBtcPubkey: s
|
|
1194
1345
|
};
|
|
1195
1346
|
}
|
|
@@ -1223,33 +1374,33 @@ class cs {
|
|
|
1223
1374
|
throw new Error(
|
|
1224
1375
|
"Wallet does not support batch signing (signPsbts method not available)"
|
|
1225
1376
|
);
|
|
1226
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = [],
|
|
1377
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = [], o = [], r = [];
|
|
1227
1378
|
for (const c of t) {
|
|
1228
1379
|
this.validatePayoutOutputs(
|
|
1229
1380
|
c.payoutTxHex,
|
|
1230
1381
|
c.registeredPayoutScriptPubKey
|
|
1231
1382
|
);
|
|
1232
|
-
const { depositorPubkey:
|
|
1383
|
+
const { depositorPubkey: l } = Et(
|
|
1233
1384
|
n,
|
|
1234
1385
|
c.depositorBtcPubkey
|
|
1235
1386
|
);
|
|
1236
|
-
|
|
1237
|
-
const h = await
|
|
1387
|
+
r.push(l);
|
|
1388
|
+
const h = await It({
|
|
1238
1389
|
payoutTxHex: c.payoutTxHex,
|
|
1239
1390
|
peginTxHex: c.peginTxHex,
|
|
1240
1391
|
assertTxHex: c.assertTxHex,
|
|
1241
|
-
depositorBtcPubkey:
|
|
1392
|
+
depositorBtcPubkey: l,
|
|
1242
1393
|
vaultProviderBtcPubkey: c.vaultProviderBtcPubkey,
|
|
1243
1394
|
vaultKeeperBtcPubkeys: c.vaultKeeperBtcPubkeys,
|
|
1244
1395
|
universalChallengerBtcPubkeys: c.universalChallengerBtcPubkeys,
|
|
1245
1396
|
timelockPegin: c.timelockPegin,
|
|
1246
1397
|
network: this.config.network
|
|
1247
1398
|
});
|
|
1248
|
-
s.push(h.psbtHex),
|
|
1399
|
+
s.push(h.psbtHex), o.push(xt(n, 1));
|
|
1249
1400
|
}
|
|
1250
1401
|
const i = await this.config.btcWallet.signPsbts(
|
|
1251
1402
|
s,
|
|
1252
|
-
|
|
1403
|
+
o
|
|
1253
1404
|
);
|
|
1254
1405
|
if (i.length !== t.length)
|
|
1255
1406
|
throw new Error(
|
|
@@ -1257,13 +1408,13 @@ class cs {
|
|
|
1257
1408
|
);
|
|
1258
1409
|
const a = [];
|
|
1259
1410
|
for (let c = 0; c < t.length; c++) {
|
|
1260
|
-
const
|
|
1411
|
+
const l = r[c], h = St(
|
|
1261
1412
|
i[c],
|
|
1262
|
-
|
|
1413
|
+
l
|
|
1263
1414
|
);
|
|
1264
1415
|
a.push({
|
|
1265
1416
|
payoutSignature: h,
|
|
1266
|
-
depositorBtcPubkey:
|
|
1417
|
+
depositorBtcPubkey: l
|
|
1267
1418
|
});
|
|
1268
1419
|
}
|
|
1269
1420
|
return a;
|
|
@@ -1283,17 +1434,17 @@ class cs {
|
|
|
1283
1434
|
* @throws Error if the largest output does not pay to the registered address
|
|
1284
1435
|
*/
|
|
1285
1436
|
validatePayoutOutputs(t, n) {
|
|
1286
|
-
if (!
|
|
1437
|
+
if (!Se(n))
|
|
1287
1438
|
throw new Error(
|
|
1288
1439
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1289
1440
|
);
|
|
1290
1441
|
const s = S.from(
|
|
1291
|
-
|
|
1442
|
+
B(n),
|
|
1292
1443
|
"hex"
|
|
1293
|
-
),
|
|
1294
|
-
if (
|
|
1444
|
+
), o = J.fromHex(B(t));
|
|
1445
|
+
if (o.outs.length === 0)
|
|
1295
1446
|
throw new Error("Payout transaction has no outputs");
|
|
1296
|
-
if (!
|
|
1447
|
+
if (!o.outs.reduce(
|
|
1297
1448
|
(i, a) => a.value > i.value ? a : i
|
|
1298
1449
|
).script.equals(s))
|
|
1299
1450
|
throw new Error(
|
|
@@ -1301,111 +1452,111 @@ class cs {
|
|
|
1301
1452
|
);
|
|
1302
1453
|
}
|
|
1303
1454
|
}
|
|
1304
|
-
function
|
|
1455
|
+
function Ke(e) {
|
|
1305
1456
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1306
1457
|
}
|
|
1307
|
-
function
|
|
1458
|
+
function V(e, t = "") {
|
|
1308
1459
|
if (!Number.isSafeInteger(e) || e < 0) {
|
|
1309
1460
|
const n = t && `"${t}" `;
|
|
1310
1461
|
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
1311
1462
|
}
|
|
1312
1463
|
}
|
|
1313
|
-
function
|
|
1314
|
-
const s =
|
|
1315
|
-
if (!s ||
|
|
1316
|
-
const i = n && `"${n}" `, a =
|
|
1464
|
+
function K(e, t, n = "") {
|
|
1465
|
+
const s = Ke(e), o = e == null ? void 0 : e.length, r = t !== void 0;
|
|
1466
|
+
if (!s || r && o !== t) {
|
|
1467
|
+
const i = n && `"${n}" `, a = r ? ` of length ${t}` : "", c = s ? `length=${o}` : `type=${typeof e}`;
|
|
1317
1468
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
1318
1469
|
}
|
|
1319
1470
|
return e;
|
|
1320
1471
|
}
|
|
1321
|
-
function
|
|
1472
|
+
function Gt(e) {
|
|
1322
1473
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1323
1474
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1324
|
-
|
|
1475
|
+
V(e.outputLen), V(e.blockLen);
|
|
1325
1476
|
}
|
|
1326
|
-
function
|
|
1477
|
+
function G(e, t = !0) {
|
|
1327
1478
|
if (e.destroyed)
|
|
1328
1479
|
throw new Error("Hash instance has been destroyed");
|
|
1329
1480
|
if (t && e.finished)
|
|
1330
1481
|
throw new Error("Hash#digest() has already been called");
|
|
1331
1482
|
}
|
|
1332
|
-
function
|
|
1333
|
-
|
|
1483
|
+
function jt(e, t) {
|
|
1484
|
+
K(e, void 0, "digestInto() output");
|
|
1334
1485
|
const n = t.outputLen;
|
|
1335
1486
|
if (e.length < n)
|
|
1336
1487
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1337
1488
|
}
|
|
1338
|
-
function
|
|
1489
|
+
function De(e) {
|
|
1339
1490
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1340
1491
|
}
|
|
1341
1492
|
function A(...e) {
|
|
1342
1493
|
for (let t = 0; t < e.length; t++)
|
|
1343
1494
|
e[t].fill(0);
|
|
1344
1495
|
}
|
|
1345
|
-
function
|
|
1496
|
+
function it(e) {
|
|
1346
1497
|
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
1347
1498
|
}
|
|
1348
|
-
function
|
|
1499
|
+
function $(e, t) {
|
|
1349
1500
|
return e << 32 - t | e >>> t;
|
|
1350
1501
|
}
|
|
1351
|
-
function
|
|
1502
|
+
function Y(e, t) {
|
|
1352
1503
|
return e << t | e >>> 32 - t >>> 0;
|
|
1353
1504
|
}
|
|
1354
|
-
const
|
|
1355
|
-
function
|
|
1505
|
+
const Me = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1506
|
+
function Ne(e) {
|
|
1356
1507
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1357
1508
|
}
|
|
1358
|
-
function
|
|
1509
|
+
function Xe(e) {
|
|
1359
1510
|
for (let t = 0; t < e.length; t++)
|
|
1360
|
-
e[t] =
|
|
1511
|
+
e[t] = Ne(e[t]);
|
|
1361
1512
|
return e;
|
|
1362
1513
|
}
|
|
1363
|
-
const
|
|
1364
|
-
function
|
|
1514
|
+
const Ut = Me ? (e) => e : Xe;
|
|
1515
|
+
function qe(e) {
|
|
1365
1516
|
if (typeof e != "string")
|
|
1366
1517
|
throw new Error("string expected");
|
|
1367
1518
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1368
1519
|
}
|
|
1369
|
-
function
|
|
1370
|
-
return typeof e == "string" ?
|
|
1520
|
+
function Ft(e, t = "") {
|
|
1521
|
+
return typeof e == "string" ? qe(e) : K(e, void 0, t);
|
|
1371
1522
|
}
|
|
1372
1523
|
function Ge(e, t) {
|
|
1373
1524
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1374
1525
|
throw new Error("options must be object or undefined");
|
|
1375
1526
|
return Object.assign(e, t);
|
|
1376
1527
|
}
|
|
1377
|
-
function
|
|
1378
|
-
const n = (
|
|
1379
|
-
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (
|
|
1528
|
+
function ct(e, t = {}) {
|
|
1529
|
+
const n = (o, r) => e(r).update(o).digest(), s = e(void 0);
|
|
1530
|
+
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (o) => e(o), Object.assign(n, t), Object.freeze(n);
|
|
1380
1531
|
}
|
|
1381
|
-
const
|
|
1532
|
+
const zt = (e) => ({
|
|
1382
1533
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
1383
1534
|
});
|
|
1384
|
-
class
|
|
1535
|
+
class Zt {
|
|
1385
1536
|
constructor(t, n) {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
if (
|
|
1537
|
+
p(this, "oHash");
|
|
1538
|
+
p(this, "iHash");
|
|
1539
|
+
p(this, "blockLen");
|
|
1540
|
+
p(this, "outputLen");
|
|
1541
|
+
p(this, "finished", !1);
|
|
1542
|
+
p(this, "destroyed", !1);
|
|
1543
|
+
if (Gt(t), K(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1393
1544
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1394
1545
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1395
|
-
const s = this.blockLen,
|
|
1396
|
-
|
|
1397
|
-
for (let
|
|
1398
|
-
r
|
|
1399
|
-
this.iHash.update(
|
|
1400
|
-
for (let
|
|
1401
|
-
r
|
|
1402
|
-
this.oHash.update(
|
|
1546
|
+
const s = this.blockLen, o = new Uint8Array(s);
|
|
1547
|
+
o.set(n.length > s ? t.create().update(n).digest() : n);
|
|
1548
|
+
for (let r = 0; r < o.length; r++)
|
|
1549
|
+
o[r] ^= 54;
|
|
1550
|
+
this.iHash.update(o), this.oHash = t.create();
|
|
1551
|
+
for (let r = 0; r < o.length; r++)
|
|
1552
|
+
o[r] ^= 106;
|
|
1553
|
+
this.oHash.update(o), A(o);
|
|
1403
1554
|
}
|
|
1404
1555
|
update(t) {
|
|
1405
|
-
return
|
|
1556
|
+
return G(this), this.iHash.update(t), this;
|
|
1406
1557
|
}
|
|
1407
1558
|
digestInto(t) {
|
|
1408
|
-
|
|
1559
|
+
G(this), K(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1409
1560
|
}
|
|
1410
1561
|
digest() {
|
|
1411
1562
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -1413,8 +1564,8 @@ class jt {
|
|
|
1413
1564
|
}
|
|
1414
1565
|
_cloneInto(t) {
|
|
1415
1566
|
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
1416
|
-
const { oHash: n, iHash: s, finished:
|
|
1417
|
-
return t = t, t.finished =
|
|
1567
|
+
const { oHash: n, iHash: s, finished: o, destroyed: r, blockLen: i, outputLen: a } = this;
|
|
1568
|
+
return t = t, t.finished = o, t.destroyed = r, t.blockLen = i, t.outputLen = a, t.oHash = n._cloneInto(t.oHash), t.iHash = s._cloneInto(t.iHash), t;
|
|
1418
1569
|
}
|
|
1419
1570
|
clone() {
|
|
1420
1571
|
return this._cloneInto();
|
|
@@ -1423,60 +1574,60 @@ class jt {
|
|
|
1423
1574
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1424
1575
|
}
|
|
1425
1576
|
}
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1577
|
+
const Pt = (e, t, n) => new Zt(e, t).update(n).digest();
|
|
1578
|
+
Pt.create = (e, t) => new Zt(e, t);
|
|
1428
1579
|
function je(e, t, n) {
|
|
1429
1580
|
return e & t ^ ~e & n;
|
|
1430
1581
|
}
|
|
1431
|
-
function
|
|
1582
|
+
function ze(e, t, n) {
|
|
1432
1583
|
return e & t ^ e & n ^ t & n;
|
|
1433
1584
|
}
|
|
1434
|
-
class
|
|
1435
|
-
constructor(t, n, s,
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1585
|
+
class Tt {
|
|
1586
|
+
constructor(t, n, s, o) {
|
|
1587
|
+
p(this, "blockLen");
|
|
1588
|
+
p(this, "outputLen");
|
|
1589
|
+
p(this, "padOffset");
|
|
1590
|
+
p(this, "isLE");
|
|
1440
1591
|
// For partial updates less than block size
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE =
|
|
1592
|
+
p(this, "buffer");
|
|
1593
|
+
p(this, "view");
|
|
1594
|
+
p(this, "finished", !1);
|
|
1595
|
+
p(this, "length", 0);
|
|
1596
|
+
p(this, "pos", 0);
|
|
1597
|
+
p(this, "destroyed", !1);
|
|
1598
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = o, this.buffer = new Uint8Array(t), this.view = it(this.buffer);
|
|
1448
1599
|
}
|
|
1449
1600
|
update(t) {
|
|
1450
|
-
|
|
1451
|
-
const { view: n, buffer: s, blockLen:
|
|
1452
|
-
for (let i = 0; i <
|
|
1453
|
-
const a = Math.min(
|
|
1454
|
-
if (a ===
|
|
1455
|
-
const c =
|
|
1456
|
-
for (;
|
|
1601
|
+
G(this), K(t);
|
|
1602
|
+
const { view: n, buffer: s, blockLen: o } = this, r = t.length;
|
|
1603
|
+
for (let i = 0; i < r; ) {
|
|
1604
|
+
const a = Math.min(o - this.pos, r - i);
|
|
1605
|
+
if (a === o) {
|
|
1606
|
+
const c = it(t);
|
|
1607
|
+
for (; o <= r - i; i += o)
|
|
1457
1608
|
this.process(c, i);
|
|
1458
1609
|
continue;
|
|
1459
1610
|
}
|
|
1460
|
-
s.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos ===
|
|
1611
|
+
s.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === o && (this.process(n, 0), this.pos = 0);
|
|
1461
1612
|
}
|
|
1462
1613
|
return this.length += t.length, this.roundClean(), this;
|
|
1463
1614
|
}
|
|
1464
1615
|
digestInto(t) {
|
|
1465
|
-
|
|
1466
|
-
const { buffer: n, view: s, blockLen:
|
|
1616
|
+
G(this), jt(t, this), this.finished = !0;
|
|
1617
|
+
const { buffer: n, view: s, blockLen: o, isLE: r } = this;
|
|
1467
1618
|
let { pos: i } = this;
|
|
1468
|
-
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset >
|
|
1469
|
-
for (let
|
|
1470
|
-
n[
|
|
1471
|
-
s.setBigUint64(
|
|
1472
|
-
const a =
|
|
1619
|
+
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(s, 0), i = 0);
|
|
1620
|
+
for (let u = i; u < o; u++)
|
|
1621
|
+
n[u] = 0;
|
|
1622
|
+
s.setBigUint64(o - 8, BigInt(this.length * 8), r), this.process(s, 0);
|
|
1623
|
+
const a = it(t), c = this.outputLen;
|
|
1473
1624
|
if (c % 4)
|
|
1474
1625
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1475
|
-
const
|
|
1476
|
-
if (
|
|
1626
|
+
const l = c / 4, h = this.get();
|
|
1627
|
+
if (l > h.length)
|
|
1477
1628
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1478
|
-
for (let
|
|
1479
|
-
a.setUint32(4 *
|
|
1629
|
+
for (let u = 0; u < l; u++)
|
|
1630
|
+
a.setUint32(4 * u, h[u], r);
|
|
1480
1631
|
}
|
|
1481
1632
|
digest() {
|
|
1482
1633
|
const { buffer: t, outputLen: n } = this;
|
|
@@ -1486,8 +1637,8 @@ class wt {
|
|
|
1486
1637
|
}
|
|
1487
1638
|
_cloneInto(t) {
|
|
1488
1639
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
1489
|
-
const { blockLen: n, buffer: s, length:
|
|
1490
|
-
return t.destroyed = i, t.finished =
|
|
1640
|
+
const { blockLen: n, buffer: s, length: o, finished: r, destroyed: i, pos: a } = this;
|
|
1641
|
+
return t.destroyed = i, t.finished = r, t.length = o, t.pos = a, o % n && t.buffer.set(s), t;
|
|
1491
1642
|
}
|
|
1492
1643
|
clone() {
|
|
1493
1644
|
return this._cloneInto();
|
|
@@ -1519,7 +1670,7 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
1519
1670
|
4215389547,
|
|
1520
1671
|
1541459225,
|
|
1521
1672
|
327033209
|
|
1522
|
-
]),
|
|
1673
|
+
]), Ze = /* @__PURE__ */ Uint8Array.from([
|
|
1523
1674
|
7,
|
|
1524
1675
|
4,
|
|
1525
1676
|
13,
|
|
@@ -1536,94 +1687,94 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
1536
1687
|
14,
|
|
1537
1688
|
11,
|
|
1538
1689
|
8
|
|
1539
|
-
]),
|
|
1540
|
-
const n = [[
|
|
1690
|
+
]), Jt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Je = Jt.map((e) => (9 * e + 5) % 16), Yt = /* @__PURE__ */ (() => {
|
|
1691
|
+
const n = [[Jt], [Je]];
|
|
1541
1692
|
for (let s = 0; s < 4; s++)
|
|
1542
|
-
for (let
|
|
1543
|
-
|
|
1693
|
+
for (let o of n)
|
|
1694
|
+
o.push(o[s].map((r) => Ze[r]));
|
|
1544
1695
|
return n;
|
|
1545
|
-
})(),
|
|
1696
|
+
})(), Qt = Yt[0], te = Yt[1], ee = /* @__PURE__ */ [
|
|
1546
1697
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1547
1698
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1548
1699
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1549
1700
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1550
1701
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1551
|
-
].map((e) => Uint8Array.from(e)),
|
|
1702
|
+
].map((e) => Uint8Array.from(e)), Ye = /* @__PURE__ */ Qt.map((e, t) => e.map((n) => ee[t][n])), Qe = /* @__PURE__ */ te.map((e, t) => e.map((n) => ee[t][n])), tn = /* @__PURE__ */ Uint32Array.from([
|
|
1552
1703
|
0,
|
|
1553
1704
|
1518500249,
|
|
1554
1705
|
1859775393,
|
|
1555
1706
|
2400959708,
|
|
1556
1707
|
2840853838
|
|
1557
|
-
]),
|
|
1708
|
+
]), en = /* @__PURE__ */ Uint32Array.from([
|
|
1558
1709
|
1352829926,
|
|
1559
1710
|
1548603684,
|
|
1560
1711
|
1836072691,
|
|
1561
1712
|
2053994217,
|
|
1562
1713
|
0
|
|
1563
1714
|
]);
|
|
1564
|
-
function
|
|
1715
|
+
function Ct(e, t, n, s) {
|
|
1565
1716
|
return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
|
|
1566
1717
|
}
|
|
1567
|
-
const
|
|
1568
|
-
class
|
|
1718
|
+
const Q = /* @__PURE__ */ new Uint32Array(16);
|
|
1719
|
+
class nn extends Tt {
|
|
1569
1720
|
constructor() {
|
|
1570
1721
|
super(64, 20, 8, !0);
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1722
|
+
p(this, "h0", 1732584193);
|
|
1723
|
+
p(this, "h1", -271733879);
|
|
1724
|
+
p(this, "h2", -1732584194);
|
|
1725
|
+
p(this, "h3", 271733878);
|
|
1726
|
+
p(this, "h4", -1009589776);
|
|
1576
1727
|
}
|
|
1577
1728
|
get() {
|
|
1578
|
-
const { h0: n, h1: s, h2:
|
|
1579
|
-
return [n, s,
|
|
1729
|
+
const { h0: n, h1: s, h2: o, h3: r, h4: i } = this;
|
|
1730
|
+
return [n, s, o, r, i];
|
|
1580
1731
|
}
|
|
1581
|
-
set(n, s,
|
|
1582
|
-
this.h0 = n | 0, this.h1 = s | 0, this.h2 =
|
|
1732
|
+
set(n, s, o, r, i) {
|
|
1733
|
+
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
1583
1734
|
}
|
|
1584
1735
|
process(n, s) {
|
|
1585
|
-
for (let
|
|
1586
|
-
|
|
1587
|
-
let
|
|
1588
|
-
for (let
|
|
1589
|
-
const
|
|
1736
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
1737
|
+
Q[g] = n.getUint32(s, !0);
|
|
1738
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, h = this.h3 | 0, u = h, d = this.h4 | 0, y = d;
|
|
1739
|
+
for (let g = 0; g < 5; g++) {
|
|
1740
|
+
const x = 4 - g, P = tn[g], m = en[g], b = Qt[g], f = te[g], w = Ye[g], v = Qe[g];
|
|
1590
1741
|
for (let T = 0; T < 16; T++) {
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1742
|
+
const H = Y(o + Ct(g, i, c, h) + Q[b[T]] + P, w[T]) + d | 0;
|
|
1743
|
+
o = d, d = h, h = Y(c, 10) | 0, c = i, i = H;
|
|
1593
1744
|
}
|
|
1594
1745
|
for (let T = 0; T < 16; T++) {
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1746
|
+
const H = Y(r + Ct(x, a, l, u) + Q[f[T]] + m, v[T]) + y | 0;
|
|
1747
|
+
r = y, y = u, u = Y(l, 10) | 0, l = a, a = H;
|
|
1597
1748
|
}
|
|
1598
1749
|
}
|
|
1599
|
-
this.set(this.h1 + c +
|
|
1750
|
+
this.set(this.h1 + c + u | 0, this.h2 + h + y | 0, this.h3 + d + r | 0, this.h4 + o + a | 0, this.h0 + i + l | 0);
|
|
1600
1751
|
}
|
|
1601
1752
|
roundClean() {
|
|
1602
|
-
A(
|
|
1753
|
+
A(Q);
|
|
1603
1754
|
}
|
|
1604
1755
|
destroy() {
|
|
1605
1756
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1606
1757
|
}
|
|
1607
1758
|
}
|
|
1608
|
-
const
|
|
1609
|
-
function
|
|
1610
|
-
return t ? { h: Number(e &
|
|
1759
|
+
const sn = /* @__PURE__ */ ct(() => new nn()), tt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ot = /* @__PURE__ */ BigInt(32);
|
|
1760
|
+
function on(e, t = !1) {
|
|
1761
|
+
return t ? { h: Number(e & tt), l: Number(e >> Ot & tt) } : { h: Number(e >> Ot & tt) | 0, l: Number(e & tt) | 0 };
|
|
1611
1762
|
}
|
|
1612
|
-
function
|
|
1763
|
+
function ne(e, t = !1) {
|
|
1613
1764
|
const n = e.length;
|
|
1614
|
-
let s = new Uint32Array(n),
|
|
1615
|
-
for (let
|
|
1616
|
-
const { h: i, l: a } =
|
|
1617
|
-
[s[
|
|
1765
|
+
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
1766
|
+
for (let r = 0; r < n; r++) {
|
|
1767
|
+
const { h: i, l: a } = on(e[r], t);
|
|
1768
|
+
[s[r], o[r]] = [i, a];
|
|
1618
1769
|
}
|
|
1619
|
-
return [s,
|
|
1770
|
+
return [s, o];
|
|
1620
1771
|
}
|
|
1621
|
-
const
|
|
1622
|
-
function
|
|
1623
|
-
const
|
|
1624
|
-
return { h: e + n + (
|
|
1772
|
+
const Lt = (e, t, n) => e >>> n, _t = (e, t, n) => e << 32 - n | t >>> n, N = (e, t, n) => e >>> n | t << 32 - n, X = (e, t, n) => e << 32 - n | t >>> n, et = (e, t, n) => e << 64 - n | t >>> n - 32, nt = (e, t, n) => e >>> n - 32 | t << 64 - n, rn = (e, t, n) => e << n | t >>> 32 - n, an = (e, t, n) => t << n | e >>> 32 - n, cn = (e, t, n) => t << n - 32 | e >>> 64 - n, un = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1773
|
+
function F(e, t, n, s) {
|
|
1774
|
+
const o = (t >>> 0) + (s >>> 0);
|
|
1775
|
+
return { h: e + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
1625
1776
|
}
|
|
1626
|
-
const
|
|
1777
|
+
const ln = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), hn = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, dn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), fn = (e, t, n, s, o) => t + n + s + o + (e / 2 ** 32 | 0) | 0, pn = (e, t, n, s, o) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (o >>> 0), gn = (e, t, n, s, o, r) => t + n + s + o + r + (e / 2 ** 32 | 0) | 0, bn = /* @__PURE__ */ Uint32Array.from([
|
|
1627
1778
|
1116352408,
|
|
1628
1779
|
1899447441,
|
|
1629
1780
|
3049323471,
|
|
@@ -1688,56 +1839,56 @@ const un = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ln = (e, t, n, s) =>
|
|
|
1688
1839
|
2756734187,
|
|
1689
1840
|
3204031479,
|
|
1690
1841
|
3329325298
|
|
1691
|
-
]),
|
|
1692
|
-
class
|
|
1842
|
+
]), _ = /* @__PURE__ */ new Uint32Array(64);
|
|
1843
|
+
class yn extends Tt {
|
|
1693
1844
|
constructor(t) {
|
|
1694
1845
|
super(64, t, 8, !1);
|
|
1695
1846
|
}
|
|
1696
1847
|
get() {
|
|
1697
|
-
const { A: t, B: n, C: s, D:
|
|
1698
|
-
return [t, n, s,
|
|
1848
|
+
const { A: t, B: n, C: s, D: o, E: r, F: i, G: a, H: c } = this;
|
|
1849
|
+
return [t, n, s, o, r, i, a, c];
|
|
1699
1850
|
}
|
|
1700
1851
|
// prettier-ignore
|
|
1701
|
-
set(t, n, s,
|
|
1702
|
-
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D =
|
|
1852
|
+
set(t, n, s, o, r, i, a, c) {
|
|
1853
|
+
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = o | 0, this.E = r | 0, this.F = i | 0, this.G = a | 0, this.H = c | 0;
|
|
1703
1854
|
}
|
|
1704
1855
|
process(t, n) {
|
|
1705
|
-
for (let
|
|
1706
|
-
|
|
1707
|
-
for (let
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1856
|
+
for (let u = 0; u < 16; u++, n += 4)
|
|
1857
|
+
_[u] = t.getUint32(n, !1);
|
|
1858
|
+
for (let u = 16; u < 64; u++) {
|
|
1859
|
+
const d = _[u - 15], y = _[u - 2], g = $(d, 7) ^ $(d, 18) ^ d >>> 3, x = $(y, 17) ^ $(y, 19) ^ y >>> 10;
|
|
1860
|
+
_[u] = x + _[u - 7] + g + _[u - 16] | 0;
|
|
1710
1861
|
}
|
|
1711
|
-
let { A: s, B:
|
|
1712
|
-
for (let
|
|
1713
|
-
const
|
|
1714
|
-
h =
|
|
1862
|
+
let { A: s, B: o, C: r, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1863
|
+
for (let u = 0; u < 64; u++) {
|
|
1864
|
+
const d = $(a, 6) ^ $(a, 11) ^ $(a, 25), y = h + d + je(a, c, l) + bn[u] + _[u] | 0, x = ($(s, 2) ^ $(s, 13) ^ $(s, 22)) + ze(s, o, r) | 0;
|
|
1865
|
+
h = l, l = c, c = a, a = i + y | 0, i = r, r = o, o = s, s = y + x | 0;
|
|
1715
1866
|
}
|
|
1716
|
-
s = s + this.A | 0,
|
|
1867
|
+
s = s + this.A | 0, o = o + this.B | 0, r = r + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, o, r, i, a, c, l, h);
|
|
1717
1868
|
}
|
|
1718
1869
|
roundClean() {
|
|
1719
|
-
A(
|
|
1870
|
+
A(_);
|
|
1720
1871
|
}
|
|
1721
1872
|
destroy() {
|
|
1722
1873
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
|
|
1723
1874
|
}
|
|
1724
1875
|
}
|
|
1725
|
-
class xn extends
|
|
1876
|
+
class xn extends yn {
|
|
1726
1877
|
constructor() {
|
|
1727
1878
|
super(32);
|
|
1728
1879
|
// We cannot use array here since array allows indexing by variable
|
|
1729
1880
|
// which means optimizer/compiler cannot use registers.
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1881
|
+
p(this, "A", L[0] | 0);
|
|
1882
|
+
p(this, "B", L[1] | 0);
|
|
1883
|
+
p(this, "C", L[2] | 0);
|
|
1884
|
+
p(this, "D", L[3] | 0);
|
|
1885
|
+
p(this, "E", L[4] | 0);
|
|
1886
|
+
p(this, "F", L[5] | 0);
|
|
1887
|
+
p(this, "G", L[6] | 0);
|
|
1888
|
+
p(this, "H", L[7] | 0);
|
|
1738
1889
|
}
|
|
1739
1890
|
}
|
|
1740
|
-
const
|
|
1891
|
+
const se = ne([
|
|
1741
1892
|
"0x428a2f98d728ae22",
|
|
1742
1893
|
"0x7137449123ef65cd",
|
|
1743
1894
|
"0xb5c0fbcfec4d3b2f",
|
|
@@ -1818,93 +1969,93 @@ const te = Qt([
|
|
|
1818
1969
|
"0x597f299cfc657e2a",
|
|
1819
1970
|
"0x5fcb6fab3ad6faec",
|
|
1820
1971
|
"0x6c44198c4a475817"
|
|
1821
|
-
].map((e) => BigInt(e))),
|
|
1822
|
-
class
|
|
1972
|
+
].map((e) => BigInt(e))), wn = se[0], mn = se[1], R = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
|
|
1973
|
+
class Pn extends Tt {
|
|
1823
1974
|
constructor(t) {
|
|
1824
1975
|
super(128, t, 16, !1);
|
|
1825
1976
|
}
|
|
1826
1977
|
// prettier-ignore
|
|
1827
1978
|
get() {
|
|
1828
|
-
const { Ah: t, Al: n, Bh: s, Bl:
|
|
1829
|
-
return [t, n, s,
|
|
1979
|
+
const { Ah: t, Al: n, Bh: s, Bl: o, Ch: r, Cl: i, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: d, Gh: y, Gl: g, Hh: x, Hl: P } = this;
|
|
1980
|
+
return [t, n, s, o, r, i, a, c, l, h, u, d, y, g, x, P];
|
|
1830
1981
|
}
|
|
1831
1982
|
// prettier-ignore
|
|
1832
|
-
set(t, n, s,
|
|
1833
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl =
|
|
1983
|
+
set(t, n, s, o, r, i, a, c, l, h, u, d, y, g, x, P) {
|
|
1984
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = o | 0, this.Ch = r | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = u | 0, this.Fl = d | 0, this.Gh = y | 0, this.Gl = g | 0, this.Hh = x | 0, this.Hl = P | 0;
|
|
1834
1985
|
}
|
|
1835
1986
|
process(t, n) {
|
|
1836
|
-
for (let
|
|
1837
|
-
|
|
1838
|
-
for (let
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1987
|
+
for (let f = 0; f < 16; f++, n += 4)
|
|
1988
|
+
R[f] = t.getUint32(n), W[f] = t.getUint32(n += 4);
|
|
1989
|
+
for (let f = 16; f < 80; f++) {
|
|
1990
|
+
const w = R[f - 15] | 0, v = W[f - 15] | 0, T = N(w, v, 1) ^ N(w, v, 8) ^ Lt(w, v, 7), H = X(w, v, 1) ^ X(w, v, 8) ^ _t(w, v, 7), E = R[f - 2] | 0, I = W[f - 2] | 0, C = N(E, I, 19) ^ et(E, I, 61) ^ Lt(E, I, 6), D = X(E, I, 19) ^ nt(E, I, 61) ^ _t(E, I, 6), O = dn(H, D, W[f - 7], W[f - 16]), ut = fn(O, T, C, R[f - 7], R[f - 16]);
|
|
1991
|
+
R[f] = ut | 0, W[f] = O | 0;
|
|
1841
1992
|
}
|
|
1842
|
-
let { Ah: s, Al:
|
|
1843
|
-
for (let
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1846
|
-
const
|
|
1847
|
-
s =
|
|
1993
|
+
let { Ah: s, Al: o, Bh: r, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: y, Fl: g, Gh: x, Gl: P, Hh: m, Hl: b } = this;
|
|
1994
|
+
for (let f = 0; f < 80; f++) {
|
|
1995
|
+
const w = N(u, d, 14) ^ N(u, d, 18) ^ et(u, d, 41), v = X(u, d, 14) ^ X(u, d, 18) ^ nt(u, d, 41), T = u & y ^ ~u & x, H = d & g ^ ~d & P, E = pn(b, v, H, mn[f], W[f]), I = gn(E, m, w, T, wn[f], R[f]), C = E | 0, D = N(s, o, 28) ^ et(s, o, 34) ^ et(s, o, 39), O = X(s, o, 28) ^ nt(s, o, 34) ^ nt(s, o, 39), ut = s & r ^ s & a ^ r & a, le = o & i ^ o & c ^ i & c;
|
|
1996
|
+
m = x | 0, b = P | 0, x = y | 0, P = g | 0, y = u | 0, g = d | 0, { h: u, l: d } = F(l | 0, h | 0, I | 0, C | 0), l = a | 0, h = c | 0, a = r | 0, c = i | 0, r = s | 0, i = o | 0;
|
|
1997
|
+
const kt = ln(C, O, le);
|
|
1998
|
+
s = hn(kt, I, D, ut), o = kt | 0;
|
|
1848
1999
|
}
|
|
1849
|
-
({ h: s, l:
|
|
2000
|
+
({ h: s, l: o } = F(this.Ah | 0, this.Al | 0, s | 0, o | 0)), { h: r, l: i } = F(this.Bh | 0, this.Bl | 0, r | 0, i | 0), { h: a, l: c } = F(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = F(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = F(this.Eh | 0, this.El | 0, u | 0, d | 0), { h: y, l: g } = F(this.Fh | 0, this.Fl | 0, y | 0, g | 0), { h: x, l: P } = F(this.Gh | 0, this.Gl | 0, x | 0, P | 0), { h: m, l: b } = F(this.Hh | 0, this.Hl | 0, m | 0, b | 0), this.set(s, o, r, i, a, c, l, h, u, d, y, g, x, P, m, b);
|
|
1850
2001
|
}
|
|
1851
2002
|
roundClean() {
|
|
1852
|
-
A(
|
|
2003
|
+
A(R, W);
|
|
1853
2004
|
}
|
|
1854
2005
|
destroy() {
|
|
1855
2006
|
A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1856
2007
|
}
|
|
1857
2008
|
}
|
|
1858
|
-
class
|
|
2009
|
+
class Tn extends Pn {
|
|
1859
2010
|
constructor() {
|
|
1860
2011
|
super(64);
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
const
|
|
2012
|
+
p(this, "Ah", k[0] | 0);
|
|
2013
|
+
p(this, "Al", k[1] | 0);
|
|
2014
|
+
p(this, "Bh", k[2] | 0);
|
|
2015
|
+
p(this, "Bl", k[3] | 0);
|
|
2016
|
+
p(this, "Ch", k[4] | 0);
|
|
2017
|
+
p(this, "Cl", k[5] | 0);
|
|
2018
|
+
p(this, "Dh", k[6] | 0);
|
|
2019
|
+
p(this, "Dl", k[7] | 0);
|
|
2020
|
+
p(this, "Eh", k[8] | 0);
|
|
2021
|
+
p(this, "El", k[9] | 0);
|
|
2022
|
+
p(this, "Fh", k[10] | 0);
|
|
2023
|
+
p(this, "Fl", k[11] | 0);
|
|
2024
|
+
p(this, "Gh", k[12] | 0);
|
|
2025
|
+
p(this, "Gl", k[13] | 0);
|
|
2026
|
+
p(this, "Hh", k[14] | 0);
|
|
2027
|
+
p(this, "Hl", k[15] | 0);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
const vn = /* @__PURE__ */ ct(
|
|
1880
2031
|
() => new xn(),
|
|
1881
|
-
/* @__PURE__ */
|
|
1882
|
-
),
|
|
1883
|
-
() => new
|
|
1884
|
-
/* @__PURE__ */
|
|
1885
|
-
),
|
|
1886
|
-
for (let e = 0, t =
|
|
1887
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
1888
|
-
let
|
|
1889
|
-
for (let
|
|
1890
|
-
t = (t <<
|
|
1891
|
-
|
|
1892
|
-
}
|
|
1893
|
-
const
|
|
1894
|
-
function
|
|
2032
|
+
/* @__PURE__ */ zt(1)
|
|
2033
|
+
), oe = /* @__PURE__ */ ct(
|
|
2034
|
+
() => new Tn(),
|
|
2035
|
+
/* @__PURE__ */ zt(3)
|
|
2036
|
+
), kn = BigInt(0), z = BigInt(1), Hn = BigInt(2), En = BigInt(7), In = BigInt(256), Sn = BigInt(113), re = [], ie = [], ae = [];
|
|
2037
|
+
for (let e = 0, t = z, n = 1, s = 0; e < 24; e++) {
|
|
2038
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], re.push(2 * (5 * s + n)), ie.push((e + 1) * (e + 2) / 2 % 64);
|
|
2039
|
+
let o = kn;
|
|
2040
|
+
for (let r = 0; r < 7; r++)
|
|
2041
|
+
t = (t << z ^ (t >> En) * Sn) % In, t & Hn && (o ^= z << (z << BigInt(r)) - z);
|
|
2042
|
+
ae.push(o);
|
|
2043
|
+
}
|
|
2044
|
+
const ce = ne(ae, !0), Bn = ce[0], An = ce[1], Rt = (e, t, n) => n > 32 ? cn(e, t, n) : rn(e, t, n), Wt = (e, t, n) => n > 32 ? un(e, t, n) : an(e, t, n);
|
|
2045
|
+
function $n(e, t = 24) {
|
|
1895
2046
|
const n = new Uint32Array(10);
|
|
1896
2047
|
for (let s = 24 - t; s < 24; s++) {
|
|
1897
2048
|
for (let i = 0; i < 10; i++)
|
|
1898
2049
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1899
2050
|
for (let i = 0; i < 10; i += 2) {
|
|
1900
|
-
const a = (i + 8) % 10, c = (i + 2) % 10,
|
|
1901
|
-
for (let
|
|
1902
|
-
e[i +
|
|
2051
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u = Rt(l, h, 1) ^ n[a], d = Wt(l, h, 1) ^ n[a + 1];
|
|
2052
|
+
for (let y = 0; y < 50; y += 10)
|
|
2053
|
+
e[i + y] ^= u, e[i + y + 1] ^= d;
|
|
1903
2054
|
}
|
|
1904
|
-
let
|
|
2055
|
+
let o = e[2], r = e[3];
|
|
1905
2056
|
for (let i = 0; i < 24; i++) {
|
|
1906
|
-
const a =
|
|
1907
|
-
|
|
2057
|
+
const a = ie[i], c = Rt(o, r, a), l = Wt(o, r, a), h = re[i];
|
|
2058
|
+
o = e[h], r = e[h + 1], e[h] = c, e[h + 1] = l;
|
|
1908
2059
|
}
|
|
1909
2060
|
for (let i = 0; i < 50; i += 10) {
|
|
1910
2061
|
for (let a = 0; a < 10; a++)
|
|
@@ -1912,41 +2063,41 @@ function Bn(e, t = 24) {
|
|
|
1912
2063
|
for (let a = 0; a < 10; a++)
|
|
1913
2064
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1914
2065
|
}
|
|
1915
|
-
e[0] ^=
|
|
2066
|
+
e[0] ^= Bn[s], e[1] ^= An[s];
|
|
1916
2067
|
}
|
|
1917
2068
|
A(n);
|
|
1918
2069
|
}
|
|
1919
|
-
class
|
|
2070
|
+
class vt {
|
|
1920
2071
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1921
|
-
constructor(t, n, s,
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF =
|
|
2072
|
+
constructor(t, n, s, o = !1, r = 24) {
|
|
2073
|
+
p(this, "state");
|
|
2074
|
+
p(this, "pos", 0);
|
|
2075
|
+
p(this, "posOut", 0);
|
|
2076
|
+
p(this, "finished", !1);
|
|
2077
|
+
p(this, "state32");
|
|
2078
|
+
p(this, "destroyed", !1);
|
|
2079
|
+
p(this, "blockLen");
|
|
2080
|
+
p(this, "suffix");
|
|
2081
|
+
p(this, "outputLen");
|
|
2082
|
+
p(this, "enableXOF", !1);
|
|
2083
|
+
p(this, "rounds");
|
|
2084
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, V(s, "outputLen"), !(0 < t && t < 200))
|
|
1934
2085
|
throw new Error("only keccak-f1600 function is supported");
|
|
1935
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
2086
|
+
this.state = new Uint8Array(200), this.state32 = De(this.state);
|
|
1936
2087
|
}
|
|
1937
2088
|
clone() {
|
|
1938
2089
|
return this._cloneInto();
|
|
1939
2090
|
}
|
|
1940
2091
|
keccak() {
|
|
1941
|
-
|
|
2092
|
+
Ut(this.state32), $n(this.state32, this.rounds), Ut(this.state32), this.posOut = 0, this.pos = 0;
|
|
1942
2093
|
}
|
|
1943
2094
|
update(t) {
|
|
1944
|
-
|
|
1945
|
-
const { blockLen: n, state: s } = this,
|
|
1946
|
-
for (let
|
|
1947
|
-
const i = Math.min(n - this.pos,
|
|
2095
|
+
G(this), K(t);
|
|
2096
|
+
const { blockLen: n, state: s } = this, o = t.length;
|
|
2097
|
+
for (let r = 0; r < o; ) {
|
|
2098
|
+
const i = Math.min(n - this.pos, o - r);
|
|
1948
2099
|
for (let a = 0; a < i; a++)
|
|
1949
|
-
s[this.pos++] ^= t[
|
|
2100
|
+
s[this.pos++] ^= t[r++];
|
|
1950
2101
|
this.pos === n && this.keccak();
|
|
1951
2102
|
}
|
|
1952
2103
|
return this;
|
|
@@ -1955,16 +2106,16 @@ class mt {
|
|
|
1955
2106
|
if (this.finished)
|
|
1956
2107
|
return;
|
|
1957
2108
|
this.finished = !0;
|
|
1958
|
-
const { state: t, suffix: n, pos: s, blockLen:
|
|
1959
|
-
t[s] ^= n, (n & 128) !== 0 && s ===
|
|
2109
|
+
const { state: t, suffix: n, pos: s, blockLen: o } = this;
|
|
2110
|
+
t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
1960
2111
|
}
|
|
1961
2112
|
writeInto(t) {
|
|
1962
|
-
|
|
2113
|
+
G(this, !1), K(t), this.finish();
|
|
1963
2114
|
const n = this.state, { blockLen: s } = this;
|
|
1964
|
-
for (let
|
|
2115
|
+
for (let o = 0, r = t.length; o < r; ) {
|
|
1965
2116
|
this.posOut >= s && this.keccak();
|
|
1966
|
-
const i = Math.min(s - this.posOut,
|
|
1967
|
-
t.set(n.subarray(this.posOut, this.posOut + i),
|
|
2117
|
+
const i = Math.min(s - this.posOut, r - o);
|
|
2118
|
+
t.set(n.subarray(this.posOut, this.posOut + i), o), this.posOut += i, o += i;
|
|
1968
2119
|
}
|
|
1969
2120
|
return t;
|
|
1970
2121
|
}
|
|
@@ -1974,10 +2125,10 @@ class mt {
|
|
|
1974
2125
|
return this.writeInto(t);
|
|
1975
2126
|
}
|
|
1976
2127
|
xof(t) {
|
|
1977
|
-
return
|
|
2128
|
+
return V(t), this.xofInto(new Uint8Array(t));
|
|
1978
2129
|
}
|
|
1979
2130
|
digestInto(t) {
|
|
1980
|
-
if (
|
|
2131
|
+
if (jt(t, this), this.finished)
|
|
1981
2132
|
throw new Error("digest() was already called");
|
|
1982
2133
|
return this.writeInto(t), this.destroy(), t;
|
|
1983
2134
|
}
|
|
@@ -1988,117 +2139,117 @@ class mt {
|
|
|
1988
2139
|
this.destroyed = !0, A(this.state);
|
|
1989
2140
|
}
|
|
1990
2141
|
_cloneInto(t) {
|
|
1991
|
-
const { blockLen: n, suffix: s, outputLen:
|
|
1992
|
-
return t || (t = new
|
|
2142
|
+
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
2143
|
+
return t || (t = new vt(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
1993
2144
|
}
|
|
1994
2145
|
}
|
|
1995
|
-
const
|
|
1996
|
-
function
|
|
1997
|
-
|
|
1998
|
-
const
|
|
1999
|
-
if (
|
|
2146
|
+
const Un = (e, t, n, s = {}) => ct(() => new vt(t, e, n), s), Fn = /* @__PURE__ */ Un(1, 136, 32);
|
|
2147
|
+
function Cn(e, t, n, s) {
|
|
2148
|
+
Gt(e);
|
|
2149
|
+
const o = Ge({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
2150
|
+
if (V(r, "c"), V(i, "dkLen"), V(a, "asyncTick"), r < 1)
|
|
2000
2151
|
throw new Error("iterations (c) must be >= 1");
|
|
2001
|
-
const c =
|
|
2002
|
-
return { c:
|
|
2152
|
+
const c = Ft(t, "password"), l = Ft(n, "salt"), h = new Uint8Array(i), u = Pt.create(e, c), d = u._cloneInto().update(l);
|
|
2153
|
+
return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
2003
2154
|
}
|
|
2004
|
-
function On(e, t, n, s,
|
|
2005
|
-
return e.destroy(), t.destroy(), s && s.destroy(), A(
|
|
2155
|
+
function On(e, t, n, s, o) {
|
|
2156
|
+
return e.destroy(), t.destroy(), s && s.destroy(), A(o), n;
|
|
2006
2157
|
}
|
|
2007
2158
|
function Ln(e, t, n, s) {
|
|
2008
|
-
const { c:
|
|
2009
|
-
let
|
|
2010
|
-
const h = new Uint8Array(4),
|
|
2011
|
-
for (let
|
|
2012
|
-
const
|
|
2013
|
-
|
|
2014
|
-
for (let
|
|
2015
|
-
a._cloneInto(
|
|
2016
|
-
for (let
|
|
2017
|
-
|
|
2159
|
+
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } = Cn(e, t, n, s);
|
|
2160
|
+
let l;
|
|
2161
|
+
const h = new Uint8Array(4), u = it(h), d = new Uint8Array(a.outputLen);
|
|
2162
|
+
for (let y = 1, g = 0; g < r; y++, g += a.outputLen) {
|
|
2163
|
+
const x = i.subarray(g, g + a.outputLen);
|
|
2164
|
+
u.setInt32(0, y, !1), (l = c._cloneInto(l)).update(h).digestInto(d), x.set(d.subarray(0, x.length));
|
|
2165
|
+
for (let P = 1; P < o; P++) {
|
|
2166
|
+
a._cloneInto(l).update(d).digestInto(d);
|
|
2167
|
+
for (let m = 0; m < x.length; m++)
|
|
2168
|
+
x[m] ^= d[m];
|
|
2018
2169
|
}
|
|
2019
2170
|
}
|
|
2020
|
-
return On(a, c, i,
|
|
2171
|
+
return On(a, c, i, l, d);
|
|
2021
2172
|
}
|
|
2022
|
-
function
|
|
2173
|
+
function ue(e) {
|
|
2023
2174
|
if (typeof e != "string")
|
|
2024
2175
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2025
2176
|
return e.normalize("NFKD");
|
|
2026
2177
|
}
|
|
2027
|
-
function
|
|
2028
|
-
const t =
|
|
2178
|
+
function _n(e) {
|
|
2179
|
+
const t = ue(e), n = t.split(" ");
|
|
2029
2180
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2030
2181
|
throw new Error("Invalid mnemonic");
|
|
2031
2182
|
return { nfkd: t, words: n };
|
|
2032
2183
|
}
|
|
2033
|
-
const
|
|
2184
|
+
const Rn = (e) => ue("mnemonic" + e);
|
|
2034
2185
|
function Wn(e, t = "") {
|
|
2035
|
-
return Ln(
|
|
2186
|
+
return Ln(oe, _n(e).nfkd, Rn(t), { c: 2048, dkLen: 64 });
|
|
2036
2187
|
}
|
|
2037
|
-
const
|
|
2038
|
-
function
|
|
2039
|
-
const t = e.reduce((
|
|
2188
|
+
const Vn = 508, Vt = 16, st = 32, ot = 64, Kt = 5, Kn = 4;
|
|
2189
|
+
function Z(...e) {
|
|
2190
|
+
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
2040
2191
|
let s = 0;
|
|
2041
|
-
for (const
|
|
2042
|
-
n.set(
|
|
2192
|
+
for (const o of e)
|
|
2193
|
+
n.set(o, s), s += o.length;
|
|
2043
2194
|
return n;
|
|
2044
2195
|
}
|
|
2045
|
-
function
|
|
2196
|
+
function ft(e) {
|
|
2046
2197
|
return new TextEncoder().encode(e);
|
|
2047
2198
|
}
|
|
2048
|
-
function
|
|
2049
|
-
const t = new Uint8Array(
|
|
2050
|
-
return new DataView(t.buffer).setUint32(0, e.length, !1),
|
|
2199
|
+
function pt(e) {
|
|
2200
|
+
const t = new Uint8Array(Kn);
|
|
2201
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), Z(t, e);
|
|
2051
2202
|
}
|
|
2052
|
-
function
|
|
2053
|
-
return
|
|
2203
|
+
function gt(e, t) {
|
|
2204
|
+
return Pt(oe, e, t);
|
|
2054
2205
|
}
|
|
2055
|
-
function
|
|
2056
|
-
return
|
|
2206
|
+
function Dt(e) {
|
|
2207
|
+
return sn(vn(e));
|
|
2057
2208
|
}
|
|
2058
|
-
const
|
|
2059
|
-
function
|
|
2209
|
+
const wt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2210
|
+
function Dn(e) {
|
|
2060
2211
|
const t = Wn(e), n = new Uint8Array(t);
|
|
2061
2212
|
return t.fill(0), n;
|
|
2062
2213
|
}
|
|
2063
|
-
async function
|
|
2064
|
-
if (e.length !==
|
|
2214
|
+
async function Mn(e, t, n, s) {
|
|
2215
|
+
if (e.length !== ot)
|
|
2065
2216
|
throw new Error(
|
|
2066
|
-
`WOTS seed must be ${
|
|
2217
|
+
`WOTS seed must be ${ot} bytes, got ${e.length}`
|
|
2067
2218
|
);
|
|
2068
|
-
t =
|
|
2069
|
-
const
|
|
2219
|
+
t = B(t), n = B(n);
|
|
2220
|
+
const o = e.slice(st, ot), r = e.slice(0, st), i = [o, r];
|
|
2070
2221
|
try {
|
|
2071
|
-
const a =
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
), c =
|
|
2222
|
+
const a = Z(
|
|
2223
|
+
pt(ft(t)),
|
|
2224
|
+
pt(ft(n)),
|
|
2225
|
+
pt(ft(s))
|
|
2226
|
+
), c = Z(r, a);
|
|
2076
2227
|
i.push(c);
|
|
2077
|
-
const
|
|
2078
|
-
i.push(
|
|
2079
|
-
const h =
|
|
2080
|
-
i.push(h,
|
|
2081
|
-
const
|
|
2082
|
-
let
|
|
2228
|
+
const l = gt(o, c);
|
|
2229
|
+
i.push(l);
|
|
2230
|
+
const h = l.slice(0, st), u = l.slice(st, ot);
|
|
2231
|
+
i.push(h, u);
|
|
2232
|
+
const d = [], y = [], g = [], x = [];
|
|
2233
|
+
let P = !1;
|
|
2083
2234
|
try {
|
|
2084
|
-
for (let
|
|
2085
|
-
const
|
|
2086
|
-
|
|
2087
|
-
const
|
|
2088
|
-
|
|
2089
|
-
const
|
|
2235
|
+
for (let m = 0; m < Vn; m++) {
|
|
2236
|
+
const b = new Uint8Array(Kt);
|
|
2237
|
+
b[0] = 0, new DataView(b.buffer).setUint32(1, m, !1);
|
|
2238
|
+
const f = new Uint8Array(Kt);
|
|
2239
|
+
f[0] = 1, new DataView(f.buffer).setUint32(1, m, !1);
|
|
2240
|
+
const w = Z(h, b), v = Z(h, f), T = gt(u, w), H = gt(u, v);
|
|
2090
2241
|
try {
|
|
2091
|
-
const
|
|
2092
|
-
|
|
2242
|
+
const E = T.slice(0, Vt), I = H.slice(0, Vt);
|
|
2243
|
+
d.push(E), y.push(I), g.push(Dt(E)), x.push(Dt(I));
|
|
2093
2244
|
} finally {
|
|
2094
|
-
|
|
2245
|
+
w.fill(0), v.fill(0), T.fill(0), H.fill(0);
|
|
2095
2246
|
}
|
|
2096
2247
|
}
|
|
2097
|
-
return
|
|
2248
|
+
return P = !0, { falsePreimages: d, truePreimages: y, falseHashes: g, trueHashes: x };
|
|
2098
2249
|
} finally {
|
|
2099
|
-
if (!
|
|
2100
|
-
for (const
|
|
2101
|
-
for (const
|
|
2250
|
+
if (!P) {
|
|
2251
|
+
for (const m of d) m.fill(0);
|
|
2252
|
+
for (const m of y) m.fill(0);
|
|
2102
2253
|
}
|
|
2103
2254
|
}
|
|
2104
2255
|
} finally {
|
|
@@ -2106,82 +2257,82 @@ async function Dn(e, t, n, s) {
|
|
|
2106
2257
|
a.fill(0);
|
|
2107
2258
|
}
|
|
2108
2259
|
}
|
|
2109
|
-
function
|
|
2260
|
+
function ls(e) {
|
|
2110
2261
|
return {
|
|
2111
|
-
false_list: e.falseHashes.map(
|
|
2112
|
-
true_list: e.trueHashes.map(
|
|
2262
|
+
false_list: e.falseHashes.map(wt),
|
|
2263
|
+
true_list: e.trueHashes.map(wt)
|
|
2113
2264
|
};
|
|
2114
2265
|
}
|
|
2115
|
-
function
|
|
2266
|
+
function Nn(e) {
|
|
2116
2267
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2117
2268
|
throw new Error(
|
|
2118
2269
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
2119
2270
|
);
|
|
2120
2271
|
const t = e.falseHashes[0].length, n = (e.falseHashes.length + e.trueHashes.length) * t, s = new Uint8Array(n);
|
|
2121
|
-
let
|
|
2272
|
+
let o = 0;
|
|
2122
2273
|
for (const i of e.falseHashes)
|
|
2123
|
-
s.set(i,
|
|
2274
|
+
s.set(i, o), o += t;
|
|
2124
2275
|
for (const i of e.trueHashes)
|
|
2125
|
-
s.set(i,
|
|
2126
|
-
const
|
|
2127
|
-
return `0x${
|
|
2276
|
+
s.set(i, o), o += t;
|
|
2277
|
+
const r = Fn(s);
|
|
2278
|
+
return `0x${wt(r)}`;
|
|
2128
2279
|
}
|
|
2129
|
-
async function
|
|
2130
|
-
const
|
|
2280
|
+
async function hs(e, t, n, s) {
|
|
2281
|
+
const o = Dn(e);
|
|
2131
2282
|
try {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2283
|
+
const r = await Mn(
|
|
2284
|
+
o,
|
|
2134
2285
|
t,
|
|
2135
2286
|
n,
|
|
2136
2287
|
s
|
|
2137
2288
|
);
|
|
2138
2289
|
try {
|
|
2139
|
-
return
|
|
2290
|
+
return Nn(r);
|
|
2140
2291
|
} finally {
|
|
2141
|
-
for (const i of
|
|
2142
|
-
for (const i of
|
|
2292
|
+
for (const i of r.falsePreimages) i.fill(0);
|
|
2293
|
+
for (const i of r.truePreimages) i.fill(0);
|
|
2143
2294
|
}
|
|
2144
2295
|
} finally {
|
|
2145
|
-
|
|
2296
|
+
o.fill(0);
|
|
2146
2297
|
}
|
|
2147
2298
|
}
|
|
2148
|
-
function
|
|
2299
|
+
function ds(e) {
|
|
2149
2300
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2150
2301
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2151
2302
|
}
|
|
2152
2303
|
export {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2304
|
+
Nn as A,
|
|
2305
|
+
rt as B,
|
|
2306
|
+
q as C,
|
|
2307
|
+
hs as D,
|
|
2308
|
+
ds as E,
|
|
2158
2309
|
Oe as M,
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2310
|
+
cs as P,
|
|
2311
|
+
Jn as a,
|
|
2312
|
+
Qn as b,
|
|
2313
|
+
dt as c,
|
|
2314
|
+
ts as d,
|
|
2315
|
+
$e as e,
|
|
2316
|
+
Ue as f,
|
|
2317
|
+
Yn as g,
|
|
2318
|
+
xt as h,
|
|
2319
|
+
us as i,
|
|
2320
|
+
os as j,
|
|
2321
|
+
ns as k,
|
|
2322
|
+
ss as l,
|
|
2172
2323
|
rs as m,
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2324
|
+
es as n,
|
|
2325
|
+
_e as o,
|
|
2326
|
+
Re as p,
|
|
2176
2327
|
Le as q,
|
|
2177
|
-
|
|
2328
|
+
j as r,
|
|
2178
2329
|
Ae as s,
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2330
|
+
mt as t,
|
|
2331
|
+
is as u,
|
|
2332
|
+
as as v,
|
|
2333
|
+
M as w,
|
|
2334
|
+
Dn as x,
|
|
2335
|
+
Mn as y,
|
|
2336
|
+
ls as z
|
|
2186
2337
|
};
|
|
2187
|
-
//# sourceMappingURL=errors-
|
|
2338
|
+
//# sourceMappingURL=errors-C5aW6wrA.js.map
|