@babylonlabs-io/ts-sdk 0.15.1 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{challengeAssert-CenzzhZU.js → challengeAssert-C5DQSUnp.js} +249 -265
- package/dist/challengeAssert-C5DQSUnp.js.map +1 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs +2 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs.map +1 -0
- package/dist/errors-BZc3Urez.cjs +2 -0
- package/dist/errors-BZc3Urez.cjs.map +1 -0
- package/dist/{errors-2TV9gKO6.js → errors-UqmtfBtv.js} +780 -638
- package/dist/errors-UqmtfBtv.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- 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 +2 -2
- 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/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts +2 -13
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/scripts/payout.d.ts +7 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +17 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +2 -2
- package/package.json +3 -3
- package/dist/challengeAssert-BpzES0KW.cjs +0 -2
- package/dist/challengeAssert-BpzES0KW.cjs.map +0 -1
- package/dist/challengeAssert-CenzzhZU.js.map +0 -1
- package/dist/errors-2TV9gKO6.js.map +0 -1
- package/dist/errors-ryNiW8NM.cjs +0 -2
- package/dist/errors-ryNiW8NM.cjs.map +0 -1
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var de = Object.defineProperty;
|
|
2
|
+
var fe = (e, t, n) => t in e ? de(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => fe(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as pe from "bitcoinjs-lib";
|
|
5
|
+
import { script as ge, Transaction as J, address as be, 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
|
|
10
|
-
function
|
|
7
|
+
import { P as ye, y as xe, D as Mt, M as Ht, B as we, T as me, H as Nt, G as yt, u as B, b as Pe, A as Te, E as ve, a as ke, d as He, e as Ee, f as Ie, s as U, q as Se, x as Et, h as It, i as St, r as Be } from "./challengeAssert-C5DQSUnp.js";
|
|
8
|
+
import { createPublicClient as lt, http as ht, encodeFunctionData as Bt, zeroAddress as Ae } from "viem";
|
|
9
|
+
import { deriveVaultId as At } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
function $e(e, t, n, s) {
|
|
11
11
|
if (!Number.isInteger(s) || s < 1)
|
|
12
12
|
throw new Error(
|
|
13
13
|
`Invalid numOutputs: expected a positive integer, got ${s}`
|
|
14
14
|
);
|
|
15
15
|
if (e.length === 0)
|
|
16
16
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
17
|
-
const
|
|
17
|
+
const o = e.filter((l) => {
|
|
18
18
|
const h = S.from(l.scriptPubKey, "hex");
|
|
19
|
-
return !!
|
|
19
|
+
return !!ge.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 l of
|
|
27
|
+
for (const l of r) {
|
|
28
28
|
i.push(l), a += BigInt(l.value);
|
|
29
|
-
const h = i.length *
|
|
30
|
-
if (c = BigInt(Math.ceil(
|
|
31
|
-
const
|
|
32
|
-
Math.ceil(
|
|
29
|
+
const h = i.length * ye, u = s * Ht, d = h + u + me;
|
|
30
|
+
if (c = BigInt(Math.ceil(d * n)) + BigInt(xe(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,18 +47,18 @@ 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 Yn(e) {
|
|
51
|
+
return e > Mt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
53
|
+
function Qn() {
|
|
54
|
+
return we;
|
|
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
|
|
61
|
-
if (e.length === 0)
|
|
60
|
+
function ts(e, t, n) {
|
|
61
|
+
if (Nt(), e.length === 0)
|
|
62
62
|
throw new Error("No input UTXOs provided for split transaction");
|
|
63
63
|
if (t.length === 0)
|
|
64
64
|
throw new Error("No outputs specified for split transaction");
|
|
@@ -67,24 +67,24 @@ 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
73
|
const l = S.from(c.txid, "hex").reverse();
|
|
74
|
-
|
|
74
|
+
o.addInput(l, c.vout);
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const r = [];
|
|
77
77
|
for (let c = 0; c < t.length; c++) {
|
|
78
78
|
const l = t[c];
|
|
79
79
|
let h;
|
|
80
80
|
try {
|
|
81
|
-
h =
|
|
81
|
+
h = be.toOutputScript(l.address, s);
|
|
82
82
|
} catch (u) {
|
|
83
83
|
throw new Error(
|
|
84
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,
|
|
@@ -92,18 +92,18 @@ function Yn(e, t, n) {
|
|
|
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 es(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 ${
|
|
117
|
+
throw new Error(`Missing UTXO data for input ${r}`);
|
|
118
118
|
const c = S.from(i.hash).reverse().toString("hex"), l = i.index;
|
|
119
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 Ue(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 Fe(e, t) {
|
|
163
|
+
const n = S.from(e.scriptPubKey, "hex"), s = Ue(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,28 +210,28 @@ function bt(e, t) {
|
|
|
210
210
|
}))
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
function
|
|
215
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
213
|
+
const Ce = 21e6 * 1e8, Xt = 1e4;
|
|
214
|
+
function qt(e) {
|
|
215
|
+
return Number.isInteger(e) && e > 0 && e <= Ce;
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
217
|
+
function Oe(e) {
|
|
218
|
+
return Number.isInteger(e) && e > 0 && e <= Xt;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function Gt(e, t) {
|
|
221
221
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
222
222
|
}
|
|
223
|
-
const
|
|
223
|
+
const Le = {
|
|
224
224
|
mainnet: "https://mempool.space/api",
|
|
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");
|
|
@@ -240,7 +240,7 @@ async function ot(e, t) {
|
|
|
240
240
|
throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
async function
|
|
243
|
+
async function _e(e, t) {
|
|
244
244
|
try {
|
|
245
245
|
const n = await fetch(`${t}/tx`, {
|
|
246
246
|
method: "POST",
|
|
@@ -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 Re(e, t) {
|
|
270
|
+
return at(`${t}/tx/${e}`);
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
272
|
+
async function ns(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 We(e, t, n) {
|
|
287
|
+
const s = await Re(e, n);
|
|
288
|
+
if (!Gt(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 (!qt(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 ss(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 (!Gt(r.vout))
|
|
311
|
+
throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
|
|
312
|
+
if (!qt(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,13 +329,13 @@ async function es(e, t) {
|
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
332
|
+
function os(e) {
|
|
333
|
+
return Le[e];
|
|
334
334
|
}
|
|
335
|
-
async function
|
|
336
|
-
return
|
|
335
|
+
async function rs(e, t) {
|
|
336
|
+
return at(`${t}/address/${e}/txs`);
|
|
337
337
|
}
|
|
338
|
-
async function
|
|
338
|
+
async function is(e) {
|
|
339
339
|
const t = await fetch(`${e}/v1/fees/recommended`);
|
|
340
340
|
if (!t.ok)
|
|
341
341
|
throw new Error(
|
|
@@ -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 (!Oe(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 ≤ ${Xt}`
|
|
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 as(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 cs(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 Ve = 0;
|
|
740
|
+
function Ke(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
|
+
}) : We(e, t, s);
|
|
719
748
|
}
|
|
720
|
-
const
|
|
721
|
-
class
|
|
749
|
+
const $t = 12e4;
|
|
750
|
+
class us {
|
|
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
|
-
}, l = await
|
|
801
|
+
}, l = await Pe(c), h = $e(
|
|
773
802
|
[...t.availableUTXOs],
|
|
774
803
|
l.totalOutputValue,
|
|
775
804
|
t.mempoolFeeRate,
|
|
776
|
-
|
|
777
|
-
), u =
|
|
805
|
+
Te(l.htlcValues.length)
|
|
806
|
+
), u = yt(this.config.btcNetwork), d = ve({
|
|
778
807
|
unfundedTxHex: l.psbtHex,
|
|
779
808
|
selectedUTXOs: h.selectedUTXOs,
|
|
780
809
|
changeAddress: t.changeAddress,
|
|
781
810
|
changeAmount: h.changeAmount,
|
|
782
811
|
network: u
|
|
783
|
-
}),
|
|
784
|
-
for (let
|
|
785
|
-
const w = await
|
|
812
|
+
}), y = B(dt(d)), g = [], x = [], P = [];
|
|
813
|
+
for (let f = 0; f < t.hashlocks.length; f++) {
|
|
814
|
+
const w = await ke({
|
|
786
815
|
prePeginParams: c,
|
|
787
816
|
timelockPegin: t.timelockPegin,
|
|
788
|
-
fundedPrePeginTxHex:
|
|
789
|
-
htlcVout:
|
|
790
|
-
}), v = await
|
|
817
|
+
fundedPrePeginTxHex: d,
|
|
818
|
+
htlcVout: f
|
|
819
|
+
}), v = await He({
|
|
791
820
|
peginTxHex: w.txHex,
|
|
792
|
-
fundedPrePeginTxHex:
|
|
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
834
|
const m = await this.signPsbtsWithFallback(
|
|
806
|
-
|
|
835
|
+
x,
|
|
807
836
|
P
|
|
808
|
-
),
|
|
809
|
-
for (let
|
|
810
|
-
const w =
|
|
811
|
-
m[
|
|
837
|
+
), b = [];
|
|
838
|
+
for (let f = 0; f < m.length; f++) {
|
|
839
|
+
const w = Ee(
|
|
840
|
+
m[f],
|
|
812
841
|
s
|
|
813
|
-
), v =
|
|
814
|
-
|
|
815
|
-
htlcVout:
|
|
816
|
-
htlcValue: l.htlcValues[
|
|
842
|
+
), v = Ie(m[f]);
|
|
843
|
+
b.push({
|
|
844
|
+
htlcVout: f,
|
|
845
|
+
htlcValue: l.htlcValues[f],
|
|
817
846
|
peginTxHex: v,
|
|
818
|
-
peginTxid:
|
|
847
|
+
peginTxid: g[f].txid,
|
|
819
848
|
peginInputSignature: w,
|
|
820
|
-
vaultScriptPubKey:
|
|
849
|
+
vaultScriptPubKey: g[f].vaultScriptPubKey
|
|
821
850
|
});
|
|
822
851
|
}
|
|
823
852
|
return {
|
|
824
|
-
fundedPrePeginTxHex:
|
|
825
|
-
prePeginTxid:
|
|
853
|
+
fundedPrePeginTxHex: d,
|
|
854
|
+
prePeginTxid: y,
|
|
826
855
|
unsignedPrePeginTxHex: l.psbtHex,
|
|
827
|
-
perVault:
|
|
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,55 +919,55 @@ class as {
|
|
|
890
919
|
throw new Error(
|
|
891
920
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
892
921
|
);
|
|
893
|
-
const l = this.config.mempoolApiUrl, h =
|
|
894
|
-
const
|
|
895
|
-
return
|
|
896
|
-
(v) => ({ input:
|
|
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 Ke(f, w, t.localPrevouts, l).then(
|
|
925
|
+
(v) => ({ input: b, utxoData: v, txid: f, vout: w })
|
|
897
926
|
);
|
|
898
|
-
}), u = await Promise.all(h),
|
|
899
|
-
(
|
|
927
|
+
}), u = await Promise.all(h), d = u.reduce(
|
|
928
|
+
(b, f) => b + BigInt(f.utxoData.value),
|
|
900
929
|
0n
|
|
901
|
-
),
|
|
902
|
-
(
|
|
930
|
+
), y = r.outs.reduce(
|
|
931
|
+
(b, f) => b + BigInt(f.value),
|
|
903
932
|
0n
|
|
904
933
|
);
|
|
905
|
-
if (
|
|
934
|
+
if (d < y)
|
|
906
935
|
throw new Error(
|
|
907
|
-
`UTXO value mismatch: total input value (${
|
|
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.`
|
|
908
937
|
);
|
|
909
|
-
for (const { input:
|
|
910
|
-
const T =
|
|
938
|
+
for (const { input: b, utxoData: f, txid: w, vout: v } of u) {
|
|
939
|
+
const T = Fe(
|
|
911
940
|
{
|
|
912
|
-
value:
|
|
913
|
-
scriptPubKey:
|
|
941
|
+
value: f.value,
|
|
942
|
+
scriptPubKey: f.scriptPubKey
|
|
914
943
|
},
|
|
915
944
|
c
|
|
916
945
|
);
|
|
917
946
|
i.addInput({
|
|
918
|
-
hash:
|
|
919
|
-
index:
|
|
920
|
-
sequence:
|
|
947
|
+
hash: b.hash,
|
|
948
|
+
index: b.index,
|
|
949
|
+
sequence: b.sequence,
|
|
921
950
|
...T
|
|
922
951
|
});
|
|
923
952
|
}
|
|
924
|
-
for (const
|
|
953
|
+
for (const b of r.outs)
|
|
925
954
|
i.addOutput({
|
|
926
|
-
script:
|
|
927
|
-
value:
|
|
955
|
+
script: b.script,
|
|
956
|
+
value: b.value
|
|
928
957
|
});
|
|
929
|
-
const
|
|
958
|
+
const g = await this.config.btcWallet.signPsbt(i.toHex()), x = bt.fromHex(g);
|
|
930
959
|
try {
|
|
931
|
-
|
|
932
|
-
} catch (
|
|
933
|
-
if (!
|
|
960
|
+
x.finalizeAllInputs();
|
|
961
|
+
} catch (b) {
|
|
962
|
+
if (!x.data.inputs.every(
|
|
934
963
|
(w) => w.finalScriptWitness || w.finalScriptSig
|
|
935
964
|
))
|
|
936
965
|
throw new Error(
|
|
937
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
966
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${b}`
|
|
938
967
|
);
|
|
939
968
|
}
|
|
940
|
-
const P =
|
|
941
|
-
return await
|
|
969
|
+
const P = x.extractTransaction().toHex();
|
|
970
|
+
return await _e(P, l);
|
|
942
971
|
}
|
|
943
972
|
/**
|
|
944
973
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -961,8 +990,8 @@ class as {
|
|
|
961
990
|
const {
|
|
962
991
|
depositorBtcPubkey: n,
|
|
963
992
|
unsignedPrePeginTx: s,
|
|
964
|
-
depositorSignedPeginTx:
|
|
965
|
-
vaultProvider:
|
|
993
|
+
depositorSignedPeginTx: o,
|
|
994
|
+
vaultProvider: r,
|
|
966
995
|
hashlock: i,
|
|
967
996
|
htlcVout: a,
|
|
968
997
|
onPopSigned: c,
|
|
@@ -972,48 +1001,48 @@ class as {
|
|
|
972
1001
|
} = t;
|
|
973
1002
|
if (!this.config.ethWallet.account)
|
|
974
1003
|
throw new Error("Ethereum wallet account not found");
|
|
975
|
-
const
|
|
976
|
-
|
|
1004
|
+
const d = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
|
|
1005
|
+
d,
|
|
977
1006
|
u
|
|
978
1007
|
);
|
|
979
1008
|
c && await c();
|
|
980
|
-
const
|
|
1009
|
+
const g = U(n), x = U(s), P = U(o), m = await this.resolvePayoutScriptPubKey(
|
|
981
1010
|
l
|
|
982
|
-
),
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
), w =
|
|
1011
|
+
), b = dt(P), f = await At(
|
|
1012
|
+
B(b),
|
|
1013
|
+
B(d)
|
|
1014
|
+
), w = U(f);
|
|
986
1015
|
if (await this.checkVaultExists(w))
|
|
987
1016
|
throw new Error(
|
|
988
|
-
`Vault already exists (ID: ${w}, peginTxHash: ${
|
|
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.`
|
|
989
1018
|
);
|
|
990
|
-
const T =
|
|
1019
|
+
const T = lt({
|
|
991
1020
|
chain: this.config.ethChain,
|
|
992
|
-
transport:
|
|
1021
|
+
transport: ht()
|
|
993
1022
|
});
|
|
994
|
-
let
|
|
1023
|
+
let H;
|
|
995
1024
|
try {
|
|
996
|
-
|
|
1025
|
+
H = await T.readContract({
|
|
997
1026
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
998
|
-
abi:
|
|
1027
|
+
abi: j,
|
|
999
1028
|
functionName: "getPegInFee",
|
|
1000
|
-
args: [
|
|
1029
|
+
args: [r]
|
|
1001
1030
|
});
|
|
1002
1031
|
} catch {
|
|
1003
1032
|
throw new Error(
|
|
1004
1033
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1005
1034
|
);
|
|
1006
1035
|
}
|
|
1007
|
-
const
|
|
1008
|
-
abi:
|
|
1036
|
+
const E = Bt({
|
|
1037
|
+
abi: j,
|
|
1009
1038
|
functionName: "submitPeginRequest",
|
|
1010
1039
|
args: [
|
|
1011
|
-
|
|
1012
|
-
b,
|
|
1040
|
+
d,
|
|
1013
1041
|
g,
|
|
1014
1042
|
y,
|
|
1043
|
+
x,
|
|
1015
1044
|
P,
|
|
1016
|
-
|
|
1045
|
+
r,
|
|
1017
1046
|
i,
|
|
1018
1047
|
a,
|
|
1019
1048
|
m,
|
|
@@ -1024,39 +1053,151 @@ class as {
|
|
|
1024
1053
|
try {
|
|
1025
1054
|
I = await T.estimateGas({
|
|
1026
1055
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1027
|
-
data:
|
|
1028
|
-
value:
|
|
1056
|
+
data: E,
|
|
1057
|
+
value: H,
|
|
1029
1058
|
account: this.config.ethWallet.account.address
|
|
1030
1059
|
});
|
|
1031
1060
|
} catch (O) {
|
|
1032
|
-
|
|
1061
|
+
M(O);
|
|
1033
1062
|
}
|
|
1034
|
-
let
|
|
1063
|
+
let C;
|
|
1035
1064
|
try {
|
|
1036
|
-
|
|
1065
|
+
C = await this.config.ethWallet.sendTransaction({
|
|
1037
1066
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1038
|
-
data:
|
|
1039
|
-
value:
|
|
1067
|
+
data: E,
|
|
1068
|
+
value: H,
|
|
1040
1069
|
account: this.config.ethWallet.account,
|
|
1041
1070
|
chain: this.config.ethChain,
|
|
1042
1071
|
gas: I
|
|
1043
1072
|
});
|
|
1044
1073
|
} catch (O) {
|
|
1045
|
-
|
|
1074
|
+
M(O);
|
|
1046
1075
|
}
|
|
1047
|
-
const
|
|
1048
|
-
hash:
|
|
1049
|
-
timeout:
|
|
1076
|
+
const D = await T.waitForTransactionReceipt({
|
|
1077
|
+
hash: C,
|
|
1078
|
+
timeout: $t
|
|
1050
1079
|
});
|
|
1051
|
-
return
|
|
1080
|
+
return D.status === "reverted" && M(
|
|
1052
1081
|
new Error(
|
|
1053
|
-
`Transaction reverted. Hash: ${
|
|
1082
|
+
`Transaction reverted. Hash: ${C}. Check the transaction on block explorer for details.`
|
|
1054
1083
|
)
|
|
1055
1084
|
), {
|
|
1056
|
-
ethTxHash:
|
|
1085
|
+
ethTxHash: D.transactionHash,
|
|
1057
1086
|
vaultId: w,
|
|
1058
|
-
peginTxHash:
|
|
1059
|
-
btcPopSignature:
|
|
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: Ve,
|
|
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
|
|
1060
1201
|
};
|
|
1061
1202
|
}
|
|
1062
1203
|
/**
|
|
@@ -1067,15 +1208,15 @@ class as {
|
|
|
1067
1208
|
*/
|
|
1068
1209
|
async checkVaultExists(t) {
|
|
1069
1210
|
try {
|
|
1070
|
-
return (await
|
|
1211
|
+
return (await lt({
|
|
1071
1212
|
chain: this.config.ethChain,
|
|
1072
|
-
transport:
|
|
1213
|
+
transport: ht()
|
|
1073
1214
|
}).readContract({
|
|
1074
1215
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1075
|
-
abi:
|
|
1216
|
+
abi: j,
|
|
1076
1217
|
functionName: "getBTCVault",
|
|
1077
1218
|
args: [t]
|
|
1078
|
-
})).depositor !==
|
|
1219
|
+
})).depositor !== Ae;
|
|
1079
1220
|
} catch {
|
|
1080
1221
|
return !1;
|
|
1081
1222
|
}
|
|
@@ -1088,24 +1229,25 @@ class as {
|
|
|
1088
1229
|
* wallet's public key to guard against a compromised wallet provider.
|
|
1089
1230
|
*/
|
|
1090
1231
|
async resolvePayoutScriptPubKey(t) {
|
|
1232
|
+
Nt();
|
|
1091
1233
|
let n;
|
|
1092
1234
|
if (t)
|
|
1093
1235
|
n = t;
|
|
1094
1236
|
else {
|
|
1095
1237
|
n = await this.config.btcWallet.getAddress();
|
|
1096
|
-
const
|
|
1097
|
-
if (!
|
|
1238
|
+
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1239
|
+
if (!Se(
|
|
1098
1240
|
n,
|
|
1099
|
-
|
|
1241
|
+
o,
|
|
1100
1242
|
this.config.btcNetwork
|
|
1101
1243
|
))
|
|
1102
1244
|
throw new Error(
|
|
1103
1245
|
"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)."
|
|
1104
1246
|
);
|
|
1105
1247
|
}
|
|
1106
|
-
const s =
|
|
1248
|
+
const s = yt(this.config.btcNetwork);
|
|
1107
1249
|
try {
|
|
1108
|
-
return `0x${
|
|
1250
|
+
return `0x${pe.address.toOutputScript(n, s).toString("hex")}`;
|
|
1109
1251
|
} catch {
|
|
1110
1252
|
throw new Error(
|
|
1111
1253
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1121,11 +1263,11 @@ class as {
|
|
|
1121
1263
|
async resolvePopSignature(t, n) {
|
|
1122
1264
|
if (n)
|
|
1123
1265
|
return n;
|
|
1124
|
-
const s = this.config.vaultContracts.btcVaultRegistry,
|
|
1125
|
-
|
|
1266
|
+
const s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1267
|
+
o,
|
|
1126
1268
|
"bip322-simple"
|
|
1127
1269
|
);
|
|
1128
|
-
return
|
|
1270
|
+
return r.startsWith("0x") ? r : `0x${S.from(r, "base64").toString("hex")}`;
|
|
1129
1271
|
}
|
|
1130
1272
|
/**
|
|
1131
1273
|
* Gets the configured Bitcoin network.
|
|
@@ -1144,14 +1286,14 @@ class as {
|
|
|
1144
1286
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1145
1287
|
}
|
|
1146
1288
|
}
|
|
1147
|
-
class
|
|
1289
|
+
class ls {
|
|
1148
1290
|
/**
|
|
1149
1291
|
* Creates a new PayoutManager instance.
|
|
1150
1292
|
*
|
|
1151
1293
|
* @param config - Manager configuration including wallet
|
|
1152
1294
|
*/
|
|
1153
1295
|
constructor(t) {
|
|
1154
|
-
|
|
1296
|
+
p(this, "config");
|
|
1155
1297
|
this.config = t;
|
|
1156
1298
|
}
|
|
1157
1299
|
/**
|
|
@@ -1181,10 +1323,10 @@ class cs {
|
|
|
1181
1323
|
t.payoutTxHex,
|
|
1182
1324
|
t.registeredPayoutScriptPubKey
|
|
1183
1325
|
);
|
|
1184
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } =
|
|
1326
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Et(
|
|
1185
1327
|
n,
|
|
1186
1328
|
t.depositorBtcPubkey
|
|
1187
|
-
),
|
|
1329
|
+
), o = await It({
|
|
1188
1330
|
payoutTxHex: t.payoutTxHex,
|
|
1189
1331
|
peginTxHex: t.peginTxHex,
|
|
1190
1332
|
assertTxHex: t.assertTxHex,
|
|
@@ -1194,12 +1336,12 @@ class cs {
|
|
|
1194
1336
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
1195
1337
|
timelockPegin: t.timelockPegin,
|
|
1196
1338
|
network: this.config.network
|
|
1197
|
-
}),
|
|
1198
|
-
|
|
1199
|
-
|
|
1339
|
+
}), r = await this.config.btcWallet.signPsbt(
|
|
1340
|
+
o.psbtHex,
|
|
1341
|
+
xt(n, 1)
|
|
1200
1342
|
);
|
|
1201
1343
|
return {
|
|
1202
|
-
signature:
|
|
1344
|
+
signature: St(r, s),
|
|
1203
1345
|
depositorBtcPubkey: s
|
|
1204
1346
|
};
|
|
1205
1347
|
}
|
|
@@ -1233,18 +1375,18 @@ class cs {
|
|
|
1233
1375
|
throw new Error(
|
|
1234
1376
|
"Wallet does not support batch signing (signPsbts method not available)"
|
|
1235
1377
|
);
|
|
1236
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = [],
|
|
1378
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = [], o = [], r = [];
|
|
1237
1379
|
for (const c of t) {
|
|
1238
1380
|
this.validatePayoutOutputs(
|
|
1239
1381
|
c.payoutTxHex,
|
|
1240
1382
|
c.registeredPayoutScriptPubKey
|
|
1241
1383
|
);
|
|
1242
|
-
const { depositorPubkey: l } =
|
|
1384
|
+
const { depositorPubkey: l } = Et(
|
|
1243
1385
|
n,
|
|
1244
1386
|
c.depositorBtcPubkey
|
|
1245
1387
|
);
|
|
1246
|
-
|
|
1247
|
-
const h = await
|
|
1388
|
+
r.push(l);
|
|
1389
|
+
const h = await It({
|
|
1248
1390
|
payoutTxHex: c.payoutTxHex,
|
|
1249
1391
|
peginTxHex: c.peginTxHex,
|
|
1250
1392
|
assertTxHex: c.assertTxHex,
|
|
@@ -1255,11 +1397,11 @@ class cs {
|
|
|
1255
1397
|
timelockPegin: c.timelockPegin,
|
|
1256
1398
|
network: this.config.network
|
|
1257
1399
|
});
|
|
1258
|
-
s.push(h.psbtHex),
|
|
1400
|
+
s.push(h.psbtHex), o.push(xt(n, 1));
|
|
1259
1401
|
}
|
|
1260
1402
|
const i = await this.config.btcWallet.signPsbts(
|
|
1261
1403
|
s,
|
|
1262
|
-
|
|
1404
|
+
o
|
|
1263
1405
|
);
|
|
1264
1406
|
if (i.length !== t.length)
|
|
1265
1407
|
throw new Error(
|
|
@@ -1267,7 +1409,7 @@ class cs {
|
|
|
1267
1409
|
);
|
|
1268
1410
|
const a = [];
|
|
1269
1411
|
for (let c = 0; c < t.length; c++) {
|
|
1270
|
-
const l =
|
|
1412
|
+
const l = r[c], h = St(
|
|
1271
1413
|
i[c],
|
|
1272
1414
|
l
|
|
1273
1415
|
);
|
|
@@ -1293,17 +1435,17 @@ class cs {
|
|
|
1293
1435
|
* @throws Error if the largest output does not pay to the registered address
|
|
1294
1436
|
*/
|
|
1295
1437
|
validatePayoutOutputs(t, n) {
|
|
1296
|
-
if (!
|
|
1438
|
+
if (!Be(n))
|
|
1297
1439
|
throw new Error(
|
|
1298
1440
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1299
1441
|
);
|
|
1300
1442
|
const s = S.from(
|
|
1301
|
-
|
|
1443
|
+
B(n),
|
|
1302
1444
|
"hex"
|
|
1303
|
-
),
|
|
1304
|
-
if (
|
|
1445
|
+
), o = J.fromHex(B(t));
|
|
1446
|
+
if (o.outs.length === 0)
|
|
1305
1447
|
throw new Error("Payout transaction has no outputs");
|
|
1306
|
-
if (!
|
|
1448
|
+
if (!o.outs.reduce(
|
|
1307
1449
|
(i, a) => a.value > i.value ? a : i
|
|
1308
1450
|
).script.equals(s))
|
|
1309
1451
|
throw new Error(
|
|
@@ -1311,111 +1453,111 @@ class cs {
|
|
|
1311
1453
|
);
|
|
1312
1454
|
}
|
|
1313
1455
|
}
|
|
1314
|
-
function
|
|
1456
|
+
function De(e) {
|
|
1315
1457
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1316
1458
|
}
|
|
1317
|
-
function
|
|
1459
|
+
function V(e, t = "") {
|
|
1318
1460
|
if (!Number.isSafeInteger(e) || e < 0) {
|
|
1319
1461
|
const n = t && `"${t}" `;
|
|
1320
1462
|
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
1321
1463
|
}
|
|
1322
1464
|
}
|
|
1323
|
-
function
|
|
1324
|
-
const s =
|
|
1325
|
-
if (!s ||
|
|
1326
|
-
const i = n && `"${n}" `, a =
|
|
1465
|
+
function K(e, t, n = "") {
|
|
1466
|
+
const s = De(e), o = e == null ? void 0 : e.length, r = t !== void 0;
|
|
1467
|
+
if (!s || r && o !== t) {
|
|
1468
|
+
const i = n && `"${n}" `, a = r ? ` of length ${t}` : "", c = s ? `length=${o}` : `type=${typeof e}`;
|
|
1327
1469
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
1328
1470
|
}
|
|
1329
1471
|
return e;
|
|
1330
1472
|
}
|
|
1331
|
-
function
|
|
1473
|
+
function jt(e) {
|
|
1332
1474
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1333
1475
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1334
|
-
|
|
1476
|
+
V(e.outputLen), V(e.blockLen);
|
|
1335
1477
|
}
|
|
1336
|
-
function
|
|
1478
|
+
function G(e, t = !0) {
|
|
1337
1479
|
if (e.destroyed)
|
|
1338
1480
|
throw new Error("Hash instance has been destroyed");
|
|
1339
1481
|
if (t && e.finished)
|
|
1340
1482
|
throw new Error("Hash#digest() has already been called");
|
|
1341
1483
|
}
|
|
1342
|
-
function
|
|
1343
|
-
|
|
1484
|
+
function zt(e, t) {
|
|
1485
|
+
K(e, void 0, "digestInto() output");
|
|
1344
1486
|
const n = t.outputLen;
|
|
1345
1487
|
if (e.length < n)
|
|
1346
1488
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1347
1489
|
}
|
|
1348
|
-
function
|
|
1490
|
+
function Me(e) {
|
|
1349
1491
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1350
1492
|
}
|
|
1351
1493
|
function A(...e) {
|
|
1352
1494
|
for (let t = 0; t < e.length; t++)
|
|
1353
1495
|
e[t].fill(0);
|
|
1354
1496
|
}
|
|
1355
|
-
function
|
|
1497
|
+
function it(e) {
|
|
1356
1498
|
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
1357
1499
|
}
|
|
1358
|
-
function
|
|
1500
|
+
function $(e, t) {
|
|
1359
1501
|
return e << 32 - t | e >>> t;
|
|
1360
1502
|
}
|
|
1361
|
-
function
|
|
1503
|
+
function Y(e, t) {
|
|
1362
1504
|
return e << t | e >>> 32 - t >>> 0;
|
|
1363
1505
|
}
|
|
1364
|
-
const
|
|
1365
|
-
function
|
|
1506
|
+
const Ne = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1507
|
+
function Xe(e) {
|
|
1366
1508
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1367
1509
|
}
|
|
1368
|
-
function
|
|
1510
|
+
function qe(e) {
|
|
1369
1511
|
for (let t = 0; t < e.length; t++)
|
|
1370
|
-
e[t] =
|
|
1512
|
+
e[t] = Xe(e[t]);
|
|
1371
1513
|
return e;
|
|
1372
1514
|
}
|
|
1373
|
-
const
|
|
1374
|
-
function
|
|
1515
|
+
const Ut = Ne ? (e) => e : qe;
|
|
1516
|
+
function Ge(e) {
|
|
1375
1517
|
if (typeof e != "string")
|
|
1376
1518
|
throw new Error("string expected");
|
|
1377
1519
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1378
1520
|
}
|
|
1379
|
-
function
|
|
1380
|
-
return typeof e == "string" ?
|
|
1521
|
+
function Ft(e, t = "") {
|
|
1522
|
+
return typeof e == "string" ? Ge(e) : K(e, void 0, t);
|
|
1381
1523
|
}
|
|
1382
|
-
function
|
|
1524
|
+
function je(e, t) {
|
|
1383
1525
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1384
1526
|
throw new Error("options must be object or undefined");
|
|
1385
1527
|
return Object.assign(e, t);
|
|
1386
1528
|
}
|
|
1387
|
-
function
|
|
1388
|
-
const n = (
|
|
1389
|
-
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (
|
|
1529
|
+
function ct(e, t = {}) {
|
|
1530
|
+
const n = (o, r) => e(r).update(o).digest(), s = e(void 0);
|
|
1531
|
+
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (o) => e(o), Object.assign(n, t), Object.freeze(n);
|
|
1390
1532
|
}
|
|
1391
|
-
const
|
|
1533
|
+
const Zt = (e) => ({
|
|
1392
1534
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
1393
1535
|
});
|
|
1394
|
-
class
|
|
1536
|
+
class Jt {
|
|
1395
1537
|
constructor(t, n) {
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
if (
|
|
1538
|
+
p(this, "oHash");
|
|
1539
|
+
p(this, "iHash");
|
|
1540
|
+
p(this, "blockLen");
|
|
1541
|
+
p(this, "outputLen");
|
|
1542
|
+
p(this, "finished", !1);
|
|
1543
|
+
p(this, "destroyed", !1);
|
|
1544
|
+
if (jt(t), K(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1403
1545
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1404
1546
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1405
|
-
const s = this.blockLen,
|
|
1406
|
-
|
|
1407
|
-
for (let
|
|
1408
|
-
r
|
|
1409
|
-
this.iHash.update(
|
|
1410
|
-
for (let
|
|
1411
|
-
r
|
|
1412
|
-
this.oHash.update(
|
|
1547
|
+
const s = this.blockLen, o = new Uint8Array(s);
|
|
1548
|
+
o.set(n.length > s ? t.create().update(n).digest() : n);
|
|
1549
|
+
for (let r = 0; r < o.length; r++)
|
|
1550
|
+
o[r] ^= 54;
|
|
1551
|
+
this.iHash.update(o), this.oHash = t.create();
|
|
1552
|
+
for (let r = 0; r < o.length; r++)
|
|
1553
|
+
o[r] ^= 106;
|
|
1554
|
+
this.oHash.update(o), A(o);
|
|
1413
1555
|
}
|
|
1414
1556
|
update(t) {
|
|
1415
|
-
return
|
|
1557
|
+
return G(this), this.iHash.update(t), this;
|
|
1416
1558
|
}
|
|
1417
1559
|
digestInto(t) {
|
|
1418
|
-
|
|
1560
|
+
G(this), K(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1419
1561
|
}
|
|
1420
1562
|
digest() {
|
|
1421
1563
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -1423,8 +1565,8 @@ class jt {
|
|
|
1423
1565
|
}
|
|
1424
1566
|
_cloneInto(t) {
|
|
1425
1567
|
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
1426
|
-
const { oHash: n, iHash: s, finished:
|
|
1427
|
-
return t = t, t.finished =
|
|
1568
|
+
const { oHash: n, iHash: s, finished: o, destroyed: r, blockLen: i, outputLen: a } = this;
|
|
1569
|
+
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;
|
|
1428
1570
|
}
|
|
1429
1571
|
clone() {
|
|
1430
1572
|
return this._cloneInto();
|
|
@@ -1433,60 +1575,60 @@ class jt {
|
|
|
1433
1575
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1434
1576
|
}
|
|
1435
1577
|
}
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
function
|
|
1578
|
+
const Pt = (e, t, n) => new Jt(e, t).update(n).digest();
|
|
1579
|
+
Pt.create = (e, t) => new Jt(e, t);
|
|
1580
|
+
function ze(e, t, n) {
|
|
1439
1581
|
return e & t ^ ~e & n;
|
|
1440
1582
|
}
|
|
1441
|
-
function
|
|
1583
|
+
function Ze(e, t, n) {
|
|
1442
1584
|
return e & t ^ e & n ^ t & n;
|
|
1443
1585
|
}
|
|
1444
|
-
class
|
|
1445
|
-
constructor(t, n, s,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1586
|
+
class Tt {
|
|
1587
|
+
constructor(t, n, s, o) {
|
|
1588
|
+
p(this, "blockLen");
|
|
1589
|
+
p(this, "outputLen");
|
|
1590
|
+
p(this, "padOffset");
|
|
1591
|
+
p(this, "isLE");
|
|
1450
1592
|
// For partial updates less than block size
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE =
|
|
1593
|
+
p(this, "buffer");
|
|
1594
|
+
p(this, "view");
|
|
1595
|
+
p(this, "finished", !1);
|
|
1596
|
+
p(this, "length", 0);
|
|
1597
|
+
p(this, "pos", 0);
|
|
1598
|
+
p(this, "destroyed", !1);
|
|
1599
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = o, this.buffer = new Uint8Array(t), this.view = it(this.buffer);
|
|
1458
1600
|
}
|
|
1459
1601
|
update(t) {
|
|
1460
|
-
|
|
1461
|
-
const { view: n, buffer: s, blockLen:
|
|
1462
|
-
for (let i = 0; i <
|
|
1463
|
-
const a = Math.min(
|
|
1464
|
-
if (a ===
|
|
1465
|
-
const c =
|
|
1466
|
-
for (;
|
|
1602
|
+
G(this), K(t);
|
|
1603
|
+
const { view: n, buffer: s, blockLen: o } = this, r = t.length;
|
|
1604
|
+
for (let i = 0; i < r; ) {
|
|
1605
|
+
const a = Math.min(o - this.pos, r - i);
|
|
1606
|
+
if (a === o) {
|
|
1607
|
+
const c = it(t);
|
|
1608
|
+
for (; o <= r - i; i += o)
|
|
1467
1609
|
this.process(c, i);
|
|
1468
1610
|
continue;
|
|
1469
1611
|
}
|
|
1470
|
-
s.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos ===
|
|
1612
|
+
s.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === o && (this.process(n, 0), this.pos = 0);
|
|
1471
1613
|
}
|
|
1472
1614
|
return this.length += t.length, this.roundClean(), this;
|
|
1473
1615
|
}
|
|
1474
1616
|
digestInto(t) {
|
|
1475
|
-
|
|
1476
|
-
const { buffer: n, view: s, blockLen:
|
|
1617
|
+
G(this), zt(t, this), this.finished = !0;
|
|
1618
|
+
const { buffer: n, view: s, blockLen: o, isLE: r } = this;
|
|
1477
1619
|
let { pos: i } = this;
|
|
1478
|
-
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset >
|
|
1479
|
-
for (let u = i; u <
|
|
1620
|
+
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(s, 0), i = 0);
|
|
1621
|
+
for (let u = i; u < o; u++)
|
|
1480
1622
|
n[u] = 0;
|
|
1481
|
-
s.setBigUint64(
|
|
1482
|
-
const a =
|
|
1623
|
+
s.setBigUint64(o - 8, BigInt(this.length * 8), r), this.process(s, 0);
|
|
1624
|
+
const a = it(t), c = this.outputLen;
|
|
1483
1625
|
if (c % 4)
|
|
1484
1626
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1485
1627
|
const l = c / 4, h = this.get();
|
|
1486
1628
|
if (l > h.length)
|
|
1487
1629
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1488
1630
|
for (let u = 0; u < l; u++)
|
|
1489
|
-
a.setUint32(4 * u, h[u],
|
|
1631
|
+
a.setUint32(4 * u, h[u], r);
|
|
1490
1632
|
}
|
|
1491
1633
|
digest() {
|
|
1492
1634
|
const { buffer: t, outputLen: n } = this;
|
|
@@ -1496,8 +1638,8 @@ class wt {
|
|
|
1496
1638
|
}
|
|
1497
1639
|
_cloneInto(t) {
|
|
1498
1640
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
1499
|
-
const { blockLen: n, buffer: s, length:
|
|
1500
|
-
return t.destroyed = i, t.finished =
|
|
1641
|
+
const { blockLen: n, buffer: s, length: o, finished: r, destroyed: i, pos: a } = this;
|
|
1642
|
+
return t.destroyed = i, t.finished = r, t.length = o, t.pos = a, o % n && t.buffer.set(s), t;
|
|
1501
1643
|
}
|
|
1502
1644
|
clone() {
|
|
1503
1645
|
return this._cloneInto();
|
|
@@ -1529,7 +1671,7 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
1529
1671
|
4215389547,
|
|
1530
1672
|
1541459225,
|
|
1531
1673
|
327033209
|
|
1532
|
-
]),
|
|
1674
|
+
]), Je = /* @__PURE__ */ Uint8Array.from([
|
|
1533
1675
|
7,
|
|
1534
1676
|
4,
|
|
1535
1677
|
13,
|
|
@@ -1546,94 +1688,94 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
1546
1688
|
14,
|
|
1547
1689
|
11,
|
|
1548
1690
|
8
|
|
1549
|
-
]),
|
|
1550
|
-
const n = [[
|
|
1691
|
+
]), Yt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ye = Yt.map((e) => (9 * e + 5) % 16), Qt = /* @__PURE__ */ (() => {
|
|
1692
|
+
const n = [[Yt], [Ye]];
|
|
1551
1693
|
for (let s = 0; s < 4; s++)
|
|
1552
|
-
for (let
|
|
1553
|
-
|
|
1694
|
+
for (let o of n)
|
|
1695
|
+
o.push(o[s].map((r) => Je[r]));
|
|
1554
1696
|
return n;
|
|
1555
|
-
})(),
|
|
1697
|
+
})(), te = Qt[0], ee = Qt[1], ne = /* @__PURE__ */ [
|
|
1556
1698
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1557
1699
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1558
1700
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1559
1701
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1560
1702
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1561
|
-
].map((e) => Uint8Array.from(e)),
|
|
1703
|
+
].map((e) => Uint8Array.from(e)), Qe = /* @__PURE__ */ te.map((e, t) => e.map((n) => ne[t][n])), tn = /* @__PURE__ */ ee.map((e, t) => e.map((n) => ne[t][n])), en = /* @__PURE__ */ Uint32Array.from([
|
|
1562
1704
|
0,
|
|
1563
1705
|
1518500249,
|
|
1564
1706
|
1859775393,
|
|
1565
1707
|
2400959708,
|
|
1566
1708
|
2840853838
|
|
1567
|
-
]),
|
|
1709
|
+
]), nn = /* @__PURE__ */ Uint32Array.from([
|
|
1568
1710
|
1352829926,
|
|
1569
1711
|
1548603684,
|
|
1570
1712
|
1836072691,
|
|
1571
1713
|
2053994217,
|
|
1572
1714
|
0
|
|
1573
1715
|
]);
|
|
1574
|
-
function
|
|
1716
|
+
function Ct(e, t, n, s) {
|
|
1575
1717
|
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);
|
|
1576
1718
|
}
|
|
1577
|
-
const
|
|
1578
|
-
class
|
|
1719
|
+
const Q = /* @__PURE__ */ new Uint32Array(16);
|
|
1720
|
+
class sn extends Tt {
|
|
1579
1721
|
constructor() {
|
|
1580
1722
|
super(64, 20, 8, !0);
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1723
|
+
p(this, "h0", 1732584193);
|
|
1724
|
+
p(this, "h1", -271733879);
|
|
1725
|
+
p(this, "h2", -1732584194);
|
|
1726
|
+
p(this, "h3", 271733878);
|
|
1727
|
+
p(this, "h4", -1009589776);
|
|
1586
1728
|
}
|
|
1587
1729
|
get() {
|
|
1588
|
-
const { h0: n, h1: s, h2:
|
|
1589
|
-
return [n, s,
|
|
1730
|
+
const { h0: n, h1: s, h2: o, h3: r, h4: i } = this;
|
|
1731
|
+
return [n, s, o, r, i];
|
|
1590
1732
|
}
|
|
1591
|
-
set(n, s,
|
|
1592
|
-
this.h0 = n | 0, this.h1 = s | 0, this.h2 =
|
|
1733
|
+
set(n, s, o, r, i) {
|
|
1734
|
+
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
1593
1735
|
}
|
|
1594
1736
|
process(n, s) {
|
|
1595
|
-
for (let
|
|
1596
|
-
|
|
1597
|
-
let
|
|
1598
|
-
for (let
|
|
1599
|
-
const
|
|
1737
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
1738
|
+
Q[g] = n.getUint32(s, !0);
|
|
1739
|
+
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;
|
|
1740
|
+
for (let g = 0; g < 5; g++) {
|
|
1741
|
+
const x = 4 - g, P = en[g], m = nn[g], b = te[g], f = ee[g], w = Qe[g], v = tn[g];
|
|
1600
1742
|
for (let T = 0; T < 16; T++) {
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1743
|
+
const H = Y(o + Ct(g, i, c, h) + Q[b[T]] + P, w[T]) + d | 0;
|
|
1744
|
+
o = d, d = h, h = Y(c, 10) | 0, c = i, i = H;
|
|
1603
1745
|
}
|
|
1604
1746
|
for (let T = 0; T < 16; T++) {
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1747
|
+
const H = Y(r + Ct(x, a, l, u) + Q[f[T]] + m, v[T]) + y | 0;
|
|
1748
|
+
r = y, y = u, u = Y(l, 10) | 0, l = a, a = H;
|
|
1607
1749
|
}
|
|
1608
1750
|
}
|
|
1609
|
-
this.set(this.h1 + c + u | 0, this.h2 + h +
|
|
1751
|
+
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);
|
|
1610
1752
|
}
|
|
1611
1753
|
roundClean() {
|
|
1612
|
-
A(
|
|
1754
|
+
A(Q);
|
|
1613
1755
|
}
|
|
1614
1756
|
destroy() {
|
|
1615
1757
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1616
1758
|
}
|
|
1617
1759
|
}
|
|
1618
|
-
const
|
|
1619
|
-
function
|
|
1620
|
-
return t ? { h: Number(e &
|
|
1760
|
+
const on = /* @__PURE__ */ ct(() => new sn()), tt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ot = /* @__PURE__ */ BigInt(32);
|
|
1761
|
+
function rn(e, t = !1) {
|
|
1762
|
+
return t ? { h: Number(e & tt), l: Number(e >> Ot & tt) } : { h: Number(e >> Ot & tt) | 0, l: Number(e & tt) | 0 };
|
|
1621
1763
|
}
|
|
1622
|
-
function
|
|
1764
|
+
function se(e, t = !1) {
|
|
1623
1765
|
const n = e.length;
|
|
1624
|
-
let s = new Uint32Array(n),
|
|
1625
|
-
for (let
|
|
1626
|
-
const { h: i, l: a } =
|
|
1627
|
-
[s[
|
|
1766
|
+
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
1767
|
+
for (let r = 0; r < n; r++) {
|
|
1768
|
+
const { h: i, l: a } = rn(e[r], t);
|
|
1769
|
+
[s[r], o[r]] = [i, a];
|
|
1628
1770
|
}
|
|
1629
|
-
return [s,
|
|
1771
|
+
return [s, o];
|
|
1630
1772
|
}
|
|
1631
|
-
const
|
|
1632
|
-
function
|
|
1633
|
-
const
|
|
1634
|
-
return { h: e + n + (
|
|
1773
|
+
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, an = (e, t, n) => e << n | t >>> 32 - n, cn = (e, t, n) => t << n | e >>> 32 - n, un = (e, t, n) => t << n - 32 | e >>> 64 - n, ln = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1774
|
+
function F(e, t, n, s) {
|
|
1775
|
+
const o = (t >>> 0) + (s >>> 0);
|
|
1776
|
+
return { h: e + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
1635
1777
|
}
|
|
1636
|
-
const
|
|
1778
|
+
const hn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), dn = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, fn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), pn = (e, t, n, s, o) => t + n + s + o + (e / 2 ** 32 | 0) | 0, gn = (e, t, n, s, o) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (o >>> 0), bn = (e, t, n, s, o, r) => t + n + s + o + r + (e / 2 ** 32 | 0) | 0, yn = /* @__PURE__ */ Uint32Array.from([
|
|
1637
1779
|
1116352408,
|
|
1638
1780
|
1899447441,
|
|
1639
1781
|
3049323471,
|
|
@@ -1698,56 +1840,56 @@ const un = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ln = (e, t, n, s) =>
|
|
|
1698
1840
|
2756734187,
|
|
1699
1841
|
3204031479,
|
|
1700
1842
|
3329325298
|
|
1701
|
-
]),
|
|
1702
|
-
class
|
|
1843
|
+
]), _ = /* @__PURE__ */ new Uint32Array(64);
|
|
1844
|
+
class xn extends Tt {
|
|
1703
1845
|
constructor(t) {
|
|
1704
1846
|
super(64, t, 8, !1);
|
|
1705
1847
|
}
|
|
1706
1848
|
get() {
|
|
1707
|
-
const { A: t, B: n, C: s, D:
|
|
1708
|
-
return [t, n, s,
|
|
1849
|
+
const { A: t, B: n, C: s, D: o, E: r, F: i, G: a, H: c } = this;
|
|
1850
|
+
return [t, n, s, o, r, i, a, c];
|
|
1709
1851
|
}
|
|
1710
1852
|
// prettier-ignore
|
|
1711
|
-
set(t, n, s,
|
|
1712
|
-
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D =
|
|
1853
|
+
set(t, n, s, o, r, i, a, c) {
|
|
1854
|
+
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;
|
|
1713
1855
|
}
|
|
1714
1856
|
process(t, n) {
|
|
1715
1857
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1716
|
-
|
|
1858
|
+
_[u] = t.getUint32(n, !1);
|
|
1717
1859
|
for (let u = 16; u < 64; u++) {
|
|
1718
|
-
const
|
|
1719
|
-
|
|
1860
|
+
const d = _[u - 15], y = _[u - 2], g = $(d, 7) ^ $(d, 18) ^ d >>> 3, x = $(y, 17) ^ $(y, 19) ^ y >>> 10;
|
|
1861
|
+
_[u] = x + _[u - 7] + g + _[u - 16] | 0;
|
|
1720
1862
|
}
|
|
1721
|
-
let { A: s, B:
|
|
1863
|
+
let { A: s, B: o, C: r, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1722
1864
|
for (let u = 0; u < 64; u++) {
|
|
1723
|
-
const
|
|
1724
|
-
h = l, l = c, c = a, a = i +
|
|
1865
|
+
const d = $(a, 6) ^ $(a, 11) ^ $(a, 25), y = h + d + ze(a, c, l) + yn[u] + _[u] | 0, x = ($(s, 2) ^ $(s, 13) ^ $(s, 22)) + Ze(s, o, r) | 0;
|
|
1866
|
+
h = l, l = c, c = a, a = i + y | 0, i = r, r = o, o = s, s = y + x | 0;
|
|
1725
1867
|
}
|
|
1726
|
-
s = s + this.A | 0,
|
|
1868
|
+
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);
|
|
1727
1869
|
}
|
|
1728
1870
|
roundClean() {
|
|
1729
|
-
A(
|
|
1871
|
+
A(_);
|
|
1730
1872
|
}
|
|
1731
1873
|
destroy() {
|
|
1732
1874
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
|
|
1733
1875
|
}
|
|
1734
1876
|
}
|
|
1735
|
-
class
|
|
1877
|
+
class wn extends xn {
|
|
1736
1878
|
constructor() {
|
|
1737
1879
|
super(32);
|
|
1738
1880
|
// We cannot use array here since array allows indexing by variable
|
|
1739
1881
|
// which means optimizer/compiler cannot use registers.
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1882
|
+
p(this, "A", L[0] | 0);
|
|
1883
|
+
p(this, "B", L[1] | 0);
|
|
1884
|
+
p(this, "C", L[2] | 0);
|
|
1885
|
+
p(this, "D", L[3] | 0);
|
|
1886
|
+
p(this, "E", L[4] | 0);
|
|
1887
|
+
p(this, "F", L[5] | 0);
|
|
1888
|
+
p(this, "G", L[6] | 0);
|
|
1889
|
+
p(this, "H", L[7] | 0);
|
|
1748
1890
|
}
|
|
1749
1891
|
}
|
|
1750
|
-
const
|
|
1892
|
+
const oe = se([
|
|
1751
1893
|
"0x428a2f98d728ae22",
|
|
1752
1894
|
"0x7137449123ef65cd",
|
|
1753
1895
|
"0xb5c0fbcfec4d3b2f",
|
|
@@ -1828,93 +1970,93 @@ const te = Qt([
|
|
|
1828
1970
|
"0x597f299cfc657e2a",
|
|
1829
1971
|
"0x5fcb6fab3ad6faec",
|
|
1830
1972
|
"0x6c44198c4a475817"
|
|
1831
|
-
].map((e) => BigInt(e))),
|
|
1832
|
-
class
|
|
1973
|
+
].map((e) => BigInt(e))), mn = oe[0], Pn = oe[1], R = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
|
|
1974
|
+
class Tn extends Tt {
|
|
1833
1975
|
constructor(t) {
|
|
1834
1976
|
super(128, t, 16, !1);
|
|
1835
1977
|
}
|
|
1836
1978
|
// prettier-ignore
|
|
1837
1979
|
get() {
|
|
1838
|
-
const { Ah: t, Al: n, Bh: s, Bl:
|
|
1839
|
-
return [t, n, s,
|
|
1980
|
+
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;
|
|
1981
|
+
return [t, n, s, o, r, i, a, c, l, h, u, d, y, g, x, P];
|
|
1840
1982
|
}
|
|
1841
1983
|
// prettier-ignore
|
|
1842
|
-
set(t, n, s,
|
|
1843
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl =
|
|
1984
|
+
set(t, n, s, o, r, i, a, c, l, h, u, d, y, g, x, P) {
|
|
1985
|
+
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;
|
|
1844
1986
|
}
|
|
1845
1987
|
process(t, n) {
|
|
1846
|
-
for (let
|
|
1847
|
-
|
|
1848
|
-
for (let
|
|
1849
|
-
const w =
|
|
1850
|
-
|
|
1988
|
+
for (let f = 0; f < 16; f++, n += 4)
|
|
1989
|
+
R[f] = t.getUint32(n), W[f] = t.getUint32(n += 4);
|
|
1990
|
+
for (let f = 16; f < 80; f++) {
|
|
1991
|
+
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 = fn(H, D, W[f - 7], W[f - 16]), ut = pn(O, T, C, R[f - 7], R[f - 16]);
|
|
1992
|
+
R[f] = ut | 0, W[f] = O | 0;
|
|
1851
1993
|
}
|
|
1852
|
-
let { Ah: s, Al:
|
|
1853
|
-
for (let
|
|
1854
|
-
const w =
|
|
1855
|
-
m =
|
|
1856
|
-
const
|
|
1857
|
-
s =
|
|
1994
|
+
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;
|
|
1995
|
+
for (let f = 0; f < 80; f++) {
|
|
1996
|
+
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 = gn(b, v, H, Pn[f], W[f]), I = bn(E, m, w, T, mn[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, he = o & i ^ o & c ^ i & c;
|
|
1997
|
+
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;
|
|
1998
|
+
const kt = hn(C, O, he);
|
|
1999
|
+
s = dn(kt, I, D, ut), o = kt | 0;
|
|
1858
2000
|
}
|
|
1859
|
-
({ h: s, l:
|
|
2001
|
+
({ 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);
|
|
1860
2002
|
}
|
|
1861
2003
|
roundClean() {
|
|
1862
|
-
A(
|
|
2004
|
+
A(R, W);
|
|
1863
2005
|
}
|
|
1864
2006
|
destroy() {
|
|
1865
2007
|
A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1866
2008
|
}
|
|
1867
2009
|
}
|
|
1868
|
-
class
|
|
2010
|
+
class vn extends Tn {
|
|
1869
2011
|
constructor() {
|
|
1870
2012
|
super(64);
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
const
|
|
1890
|
-
() => new
|
|
1891
|
-
/* @__PURE__ */
|
|
1892
|
-
),
|
|
1893
|
-
() => new
|
|
1894
|
-
/* @__PURE__ */
|
|
1895
|
-
),
|
|
1896
|
-
for (let e = 0, t =
|
|
1897
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
1898
|
-
let
|
|
1899
|
-
for (let
|
|
1900
|
-
t = (t <<
|
|
1901
|
-
|
|
1902
|
-
}
|
|
1903
|
-
const
|
|
1904
|
-
function
|
|
2013
|
+
p(this, "Ah", k[0] | 0);
|
|
2014
|
+
p(this, "Al", k[1] | 0);
|
|
2015
|
+
p(this, "Bh", k[2] | 0);
|
|
2016
|
+
p(this, "Bl", k[3] | 0);
|
|
2017
|
+
p(this, "Ch", k[4] | 0);
|
|
2018
|
+
p(this, "Cl", k[5] | 0);
|
|
2019
|
+
p(this, "Dh", k[6] | 0);
|
|
2020
|
+
p(this, "Dl", k[7] | 0);
|
|
2021
|
+
p(this, "Eh", k[8] | 0);
|
|
2022
|
+
p(this, "El", k[9] | 0);
|
|
2023
|
+
p(this, "Fh", k[10] | 0);
|
|
2024
|
+
p(this, "Fl", k[11] | 0);
|
|
2025
|
+
p(this, "Gh", k[12] | 0);
|
|
2026
|
+
p(this, "Gl", k[13] | 0);
|
|
2027
|
+
p(this, "Hh", k[14] | 0);
|
|
2028
|
+
p(this, "Hl", k[15] | 0);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
const kn = /* @__PURE__ */ ct(
|
|
2032
|
+
() => new wn(),
|
|
2033
|
+
/* @__PURE__ */ Zt(1)
|
|
2034
|
+
), re = /* @__PURE__ */ ct(
|
|
2035
|
+
() => new vn(),
|
|
2036
|
+
/* @__PURE__ */ Zt(3)
|
|
2037
|
+
), Hn = BigInt(0), z = BigInt(1), En = BigInt(2), In = BigInt(7), Sn = BigInt(256), Bn = BigInt(113), ie = [], ae = [], ce = [];
|
|
2038
|
+
for (let e = 0, t = z, n = 1, s = 0; e < 24; e++) {
|
|
2039
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], ie.push(2 * (5 * s + n)), ae.push((e + 1) * (e + 2) / 2 % 64);
|
|
2040
|
+
let o = Hn;
|
|
2041
|
+
for (let r = 0; r < 7; r++)
|
|
2042
|
+
t = (t << z ^ (t >> In) * Bn) % Sn, t & En && (o ^= z << (z << BigInt(r)) - z);
|
|
2043
|
+
ce.push(o);
|
|
2044
|
+
}
|
|
2045
|
+
const ue = se(ce, !0), An = ue[0], $n = ue[1], Rt = (e, t, n) => n > 32 ? un(e, t, n) : an(e, t, n), Wt = (e, t, n) => n > 32 ? ln(e, t, n) : cn(e, t, n);
|
|
2046
|
+
function Un(e, t = 24) {
|
|
1905
2047
|
const n = new Uint32Array(10);
|
|
1906
2048
|
for (let s = 24 - t; s < 24; s++) {
|
|
1907
2049
|
for (let i = 0; i < 10; i++)
|
|
1908
2050
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1909
2051
|
for (let i = 0; i < 10; i += 2) {
|
|
1910
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u =
|
|
1911
|
-
for (let
|
|
1912
|
-
e[i +
|
|
2052
|
+
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];
|
|
2053
|
+
for (let y = 0; y < 50; y += 10)
|
|
2054
|
+
e[i + y] ^= u, e[i + y + 1] ^= d;
|
|
1913
2055
|
}
|
|
1914
|
-
let
|
|
2056
|
+
let o = e[2], r = e[3];
|
|
1915
2057
|
for (let i = 0; i < 24; i++) {
|
|
1916
|
-
const a =
|
|
1917
|
-
|
|
2058
|
+
const a = ae[i], c = Rt(o, r, a), l = Wt(o, r, a), h = ie[i];
|
|
2059
|
+
o = e[h], r = e[h + 1], e[h] = c, e[h + 1] = l;
|
|
1918
2060
|
}
|
|
1919
2061
|
for (let i = 0; i < 50; i += 10) {
|
|
1920
2062
|
for (let a = 0; a < 10; a++)
|
|
@@ -1922,41 +2064,41 @@ function Bn(e, t = 24) {
|
|
|
1922
2064
|
for (let a = 0; a < 10; a++)
|
|
1923
2065
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1924
2066
|
}
|
|
1925
|
-
e[0] ^=
|
|
2067
|
+
e[0] ^= An[s], e[1] ^= $n[s];
|
|
1926
2068
|
}
|
|
1927
2069
|
A(n);
|
|
1928
2070
|
}
|
|
1929
|
-
class
|
|
2071
|
+
class vt {
|
|
1930
2072
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1931
|
-
constructor(t, n, s,
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF =
|
|
2073
|
+
constructor(t, n, s, o = !1, r = 24) {
|
|
2074
|
+
p(this, "state");
|
|
2075
|
+
p(this, "pos", 0);
|
|
2076
|
+
p(this, "posOut", 0);
|
|
2077
|
+
p(this, "finished", !1);
|
|
2078
|
+
p(this, "state32");
|
|
2079
|
+
p(this, "destroyed", !1);
|
|
2080
|
+
p(this, "blockLen");
|
|
2081
|
+
p(this, "suffix");
|
|
2082
|
+
p(this, "outputLen");
|
|
2083
|
+
p(this, "enableXOF", !1);
|
|
2084
|
+
p(this, "rounds");
|
|
2085
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, V(s, "outputLen"), !(0 < t && t < 200))
|
|
1944
2086
|
throw new Error("only keccak-f1600 function is supported");
|
|
1945
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
2087
|
+
this.state = new Uint8Array(200), this.state32 = Me(this.state);
|
|
1946
2088
|
}
|
|
1947
2089
|
clone() {
|
|
1948
2090
|
return this._cloneInto();
|
|
1949
2091
|
}
|
|
1950
2092
|
keccak() {
|
|
1951
|
-
|
|
2093
|
+
Ut(this.state32), Un(this.state32, this.rounds), Ut(this.state32), this.posOut = 0, this.pos = 0;
|
|
1952
2094
|
}
|
|
1953
2095
|
update(t) {
|
|
1954
|
-
|
|
1955
|
-
const { blockLen: n, state: s } = this,
|
|
1956
|
-
for (let
|
|
1957
|
-
const i = Math.min(n - this.pos,
|
|
2096
|
+
G(this), K(t);
|
|
2097
|
+
const { blockLen: n, state: s } = this, o = t.length;
|
|
2098
|
+
for (let r = 0; r < o; ) {
|
|
2099
|
+
const i = Math.min(n - this.pos, o - r);
|
|
1958
2100
|
for (let a = 0; a < i; a++)
|
|
1959
|
-
s[this.pos++] ^= t[
|
|
2101
|
+
s[this.pos++] ^= t[r++];
|
|
1960
2102
|
this.pos === n && this.keccak();
|
|
1961
2103
|
}
|
|
1962
2104
|
return this;
|
|
@@ -1965,16 +2107,16 @@ class mt {
|
|
|
1965
2107
|
if (this.finished)
|
|
1966
2108
|
return;
|
|
1967
2109
|
this.finished = !0;
|
|
1968
|
-
const { state: t, suffix: n, pos: s, blockLen:
|
|
1969
|
-
t[s] ^= n, (n & 128) !== 0 && s ===
|
|
2110
|
+
const { state: t, suffix: n, pos: s, blockLen: o } = this;
|
|
2111
|
+
t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
1970
2112
|
}
|
|
1971
2113
|
writeInto(t) {
|
|
1972
|
-
|
|
2114
|
+
G(this, !1), K(t), this.finish();
|
|
1973
2115
|
const n = this.state, { blockLen: s } = this;
|
|
1974
|
-
for (let
|
|
2116
|
+
for (let o = 0, r = t.length; o < r; ) {
|
|
1975
2117
|
this.posOut >= s && this.keccak();
|
|
1976
|
-
const i = Math.min(s - this.posOut,
|
|
1977
|
-
t.set(n.subarray(this.posOut, this.posOut + i),
|
|
2118
|
+
const i = Math.min(s - this.posOut, r - o);
|
|
2119
|
+
t.set(n.subarray(this.posOut, this.posOut + i), o), this.posOut += i, o += i;
|
|
1978
2120
|
}
|
|
1979
2121
|
return t;
|
|
1980
2122
|
}
|
|
@@ -1984,10 +2126,10 @@ class mt {
|
|
|
1984
2126
|
return this.writeInto(t);
|
|
1985
2127
|
}
|
|
1986
2128
|
xof(t) {
|
|
1987
|
-
return
|
|
2129
|
+
return V(t), this.xofInto(new Uint8Array(t));
|
|
1988
2130
|
}
|
|
1989
2131
|
digestInto(t) {
|
|
1990
|
-
if (
|
|
2132
|
+
if (zt(t, this), this.finished)
|
|
1991
2133
|
throw new Error("digest() was already called");
|
|
1992
2134
|
return this.writeInto(t), this.destroy(), t;
|
|
1993
2135
|
}
|
|
@@ -1998,117 +2140,117 @@ class mt {
|
|
|
1998
2140
|
this.destroyed = !0, A(this.state);
|
|
1999
2141
|
}
|
|
2000
2142
|
_cloneInto(t) {
|
|
2001
|
-
const { blockLen: n, suffix: s, outputLen:
|
|
2002
|
-
return t || (t = new
|
|
2143
|
+
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
2144
|
+
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;
|
|
2003
2145
|
}
|
|
2004
2146
|
}
|
|
2005
|
-
const
|
|
2006
|
-
function
|
|
2007
|
-
|
|
2008
|
-
const
|
|
2009
|
-
if (
|
|
2147
|
+
const Fn = (e, t, n, s = {}) => ct(() => new vt(t, e, n), s), Cn = /* @__PURE__ */ Fn(1, 136, 32);
|
|
2148
|
+
function On(e, t, n, s) {
|
|
2149
|
+
jt(e);
|
|
2150
|
+
const o = je({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
2151
|
+
if (V(r, "c"), V(i, "dkLen"), V(a, "asyncTick"), r < 1)
|
|
2010
2152
|
throw new Error("iterations (c) must be >= 1");
|
|
2011
|
-
const c =
|
|
2012
|
-
return { c:
|
|
2153
|
+
const c = Ft(t, "password"), l = Ft(n, "salt"), h = new Uint8Array(i), u = Pt.create(e, c), d = u._cloneInto().update(l);
|
|
2154
|
+
return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
2013
2155
|
}
|
|
2014
|
-
function
|
|
2015
|
-
return e.destroy(), t.destroy(), s && s.destroy(), A(
|
|
2156
|
+
function Ln(e, t, n, s, o) {
|
|
2157
|
+
return e.destroy(), t.destroy(), s && s.destroy(), A(o), n;
|
|
2016
2158
|
}
|
|
2017
|
-
function
|
|
2018
|
-
const { c:
|
|
2159
|
+
function _n(e, t, n, s) {
|
|
2160
|
+
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } = On(e, t, n, s);
|
|
2019
2161
|
let l;
|
|
2020
|
-
const h = new Uint8Array(4), u =
|
|
2021
|
-
for (let
|
|
2022
|
-
const
|
|
2023
|
-
u.setInt32(0,
|
|
2024
|
-
for (let P = 1; P <
|
|
2025
|
-
a._cloneInto(l).update(
|
|
2026
|
-
for (let m = 0; m <
|
|
2027
|
-
|
|
2162
|
+
const h = new Uint8Array(4), u = it(h), d = new Uint8Array(a.outputLen);
|
|
2163
|
+
for (let y = 1, g = 0; g < r; y++, g += a.outputLen) {
|
|
2164
|
+
const x = i.subarray(g, g + a.outputLen);
|
|
2165
|
+
u.setInt32(0, y, !1), (l = c._cloneInto(l)).update(h).digestInto(d), x.set(d.subarray(0, x.length));
|
|
2166
|
+
for (let P = 1; P < o; P++) {
|
|
2167
|
+
a._cloneInto(l).update(d).digestInto(d);
|
|
2168
|
+
for (let m = 0; m < x.length; m++)
|
|
2169
|
+
x[m] ^= d[m];
|
|
2028
2170
|
}
|
|
2029
2171
|
}
|
|
2030
|
-
return
|
|
2172
|
+
return Ln(a, c, i, l, d);
|
|
2031
2173
|
}
|
|
2032
|
-
function
|
|
2174
|
+
function le(e) {
|
|
2033
2175
|
if (typeof e != "string")
|
|
2034
2176
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2035
2177
|
return e.normalize("NFKD");
|
|
2036
2178
|
}
|
|
2037
|
-
function
|
|
2038
|
-
const t =
|
|
2179
|
+
function Rn(e) {
|
|
2180
|
+
const t = le(e), n = t.split(" ");
|
|
2039
2181
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2040
2182
|
throw new Error("Invalid mnemonic");
|
|
2041
2183
|
return { nfkd: t, words: n };
|
|
2042
2184
|
}
|
|
2043
|
-
const
|
|
2044
|
-
function
|
|
2045
|
-
return
|
|
2185
|
+
const Wn = (e) => le("mnemonic" + e);
|
|
2186
|
+
function Vn(e, t = "") {
|
|
2187
|
+
return _n(re, Rn(e).nfkd, Wn(t), { c: 2048, dkLen: 64 });
|
|
2046
2188
|
}
|
|
2047
|
-
const
|
|
2048
|
-
function
|
|
2049
|
-
const t = e.reduce((
|
|
2189
|
+
const Kn = 508, Vt = 16, st = 32, ot = 64, Kt = 5, Dn = 4;
|
|
2190
|
+
function Z(...e) {
|
|
2191
|
+
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
2050
2192
|
let s = 0;
|
|
2051
|
-
for (const
|
|
2052
|
-
n.set(
|
|
2193
|
+
for (const o of e)
|
|
2194
|
+
n.set(o, s), s += o.length;
|
|
2053
2195
|
return n;
|
|
2054
2196
|
}
|
|
2055
|
-
function
|
|
2197
|
+
function ft(e) {
|
|
2056
2198
|
return new TextEncoder().encode(e);
|
|
2057
2199
|
}
|
|
2058
|
-
function
|
|
2059
|
-
const t = new Uint8Array(
|
|
2060
|
-
return new DataView(t.buffer).setUint32(0, e.length, !1),
|
|
2200
|
+
function pt(e) {
|
|
2201
|
+
const t = new Uint8Array(Dn);
|
|
2202
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), Z(t, e);
|
|
2061
2203
|
}
|
|
2062
|
-
function
|
|
2063
|
-
return
|
|
2204
|
+
function gt(e, t) {
|
|
2205
|
+
return Pt(re, e, t);
|
|
2064
2206
|
}
|
|
2065
|
-
function
|
|
2066
|
-
return
|
|
2207
|
+
function Dt(e) {
|
|
2208
|
+
return on(kn(e));
|
|
2067
2209
|
}
|
|
2068
|
-
const
|
|
2069
|
-
function
|
|
2070
|
-
const t =
|
|
2210
|
+
const wt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2211
|
+
function Mn(e) {
|
|
2212
|
+
const t = Vn(e), n = new Uint8Array(t);
|
|
2071
2213
|
return t.fill(0), n;
|
|
2072
2214
|
}
|
|
2073
|
-
async function
|
|
2074
|
-
if (e.length !==
|
|
2215
|
+
async function Nn(e, t, n, s) {
|
|
2216
|
+
if (e.length !== ot)
|
|
2075
2217
|
throw new Error(
|
|
2076
|
-
`WOTS seed must be ${
|
|
2218
|
+
`WOTS seed must be ${ot} bytes, got ${e.length}`
|
|
2077
2219
|
);
|
|
2078
|
-
t =
|
|
2079
|
-
const
|
|
2220
|
+
t = B(t), n = B(n);
|
|
2221
|
+
const o = e.slice(st, ot), r = e.slice(0, st), i = [o, r];
|
|
2080
2222
|
try {
|
|
2081
|
-
const a =
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
), c =
|
|
2223
|
+
const a = Z(
|
|
2224
|
+
pt(ft(t)),
|
|
2225
|
+
pt(ft(n)),
|
|
2226
|
+
pt(ft(s))
|
|
2227
|
+
), c = Z(r, a);
|
|
2086
2228
|
i.push(c);
|
|
2087
|
-
const l =
|
|
2229
|
+
const l = gt(o, c);
|
|
2088
2230
|
i.push(l);
|
|
2089
|
-
const h = l.slice(0,
|
|
2231
|
+
const h = l.slice(0, st), u = l.slice(st, ot);
|
|
2090
2232
|
i.push(h, u);
|
|
2091
|
-
const
|
|
2233
|
+
const d = [], y = [], g = [], x = [];
|
|
2092
2234
|
let P = !1;
|
|
2093
2235
|
try {
|
|
2094
|
-
for (let m = 0; m <
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2099
|
-
const w =
|
|
2236
|
+
for (let m = 0; m < Kn; m++) {
|
|
2237
|
+
const b = new Uint8Array(Kt);
|
|
2238
|
+
b[0] = 0, new DataView(b.buffer).setUint32(1, m, !1);
|
|
2239
|
+
const f = new Uint8Array(Kt);
|
|
2240
|
+
f[0] = 1, new DataView(f.buffer).setUint32(1, m, !1);
|
|
2241
|
+
const w = Z(h, b), v = Z(h, f), T = gt(u, w), H = gt(u, v);
|
|
2100
2242
|
try {
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2243
|
+
const E = T.slice(0, Vt), I = H.slice(0, Vt);
|
|
2244
|
+
d.push(E), y.push(I), g.push(Dt(E)), x.push(Dt(I));
|
|
2103
2245
|
} finally {
|
|
2104
|
-
w.fill(0), v.fill(0), T.fill(0),
|
|
2246
|
+
w.fill(0), v.fill(0), T.fill(0), H.fill(0);
|
|
2105
2247
|
}
|
|
2106
2248
|
}
|
|
2107
|
-
return P = !0, { falsePreimages:
|
|
2249
|
+
return P = !0, { falsePreimages: d, truePreimages: y, falseHashes: g, trueHashes: x };
|
|
2108
2250
|
} finally {
|
|
2109
2251
|
if (!P) {
|
|
2110
|
-
for (const m of
|
|
2111
|
-
for (const m of
|
|
2252
|
+
for (const m of d) m.fill(0);
|
|
2253
|
+
for (const m of y) m.fill(0);
|
|
2112
2254
|
}
|
|
2113
2255
|
}
|
|
2114
2256
|
} finally {
|
|
@@ -2116,82 +2258,82 @@ async function Dn(e, t, n, s) {
|
|
|
2116
2258
|
a.fill(0);
|
|
2117
2259
|
}
|
|
2118
2260
|
}
|
|
2119
|
-
function
|
|
2261
|
+
function hs(e) {
|
|
2120
2262
|
return {
|
|
2121
|
-
false_list: e.falseHashes.map(
|
|
2122
|
-
true_list: e.trueHashes.map(
|
|
2263
|
+
false_list: e.falseHashes.map(wt),
|
|
2264
|
+
true_list: e.trueHashes.map(wt)
|
|
2123
2265
|
};
|
|
2124
2266
|
}
|
|
2125
|
-
function
|
|
2267
|
+
function Xn(e) {
|
|
2126
2268
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2127
2269
|
throw new Error(
|
|
2128
2270
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
2129
2271
|
);
|
|
2130
2272
|
const t = e.falseHashes[0].length, n = (e.falseHashes.length + e.trueHashes.length) * t, s = new Uint8Array(n);
|
|
2131
|
-
let
|
|
2273
|
+
let o = 0;
|
|
2132
2274
|
for (const i of e.falseHashes)
|
|
2133
|
-
s.set(i,
|
|
2275
|
+
s.set(i, o), o += t;
|
|
2134
2276
|
for (const i of e.trueHashes)
|
|
2135
|
-
s.set(i,
|
|
2136
|
-
const
|
|
2137
|
-
return `0x${
|
|
2277
|
+
s.set(i, o), o += t;
|
|
2278
|
+
const r = Cn(s);
|
|
2279
|
+
return `0x${wt(r)}`;
|
|
2138
2280
|
}
|
|
2139
|
-
async function
|
|
2140
|
-
const
|
|
2281
|
+
async function ds(e, t, n, s) {
|
|
2282
|
+
const o = Mn(e);
|
|
2141
2283
|
try {
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2284
|
+
const r = await Nn(
|
|
2285
|
+
o,
|
|
2144
2286
|
t,
|
|
2145
2287
|
n,
|
|
2146
2288
|
s
|
|
2147
2289
|
);
|
|
2148
2290
|
try {
|
|
2149
|
-
return
|
|
2291
|
+
return Xn(r);
|
|
2150
2292
|
} finally {
|
|
2151
|
-
for (const i of
|
|
2152
|
-
for (const i of
|
|
2293
|
+
for (const i of r.falsePreimages) i.fill(0);
|
|
2294
|
+
for (const i of r.truePreimages) i.fill(0);
|
|
2153
2295
|
}
|
|
2154
2296
|
} finally {
|
|
2155
|
-
|
|
2297
|
+
o.fill(0);
|
|
2156
2298
|
}
|
|
2157
2299
|
}
|
|
2158
|
-
function
|
|
2300
|
+
function fs(e) {
|
|
2159
2301
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2160
2302
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2161
2303
|
}
|
|
2162
2304
|
export {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2305
|
+
Xn as A,
|
|
2306
|
+
rt as B,
|
|
2307
|
+
q as C,
|
|
2308
|
+
ds as D,
|
|
2309
|
+
fs as E,
|
|
2310
|
+
Le as M,
|
|
2311
|
+
us as P,
|
|
2312
|
+
Yn as a,
|
|
2313
|
+
ts as b,
|
|
2314
|
+
dt as c,
|
|
2315
|
+
es as d,
|
|
2316
|
+
Ue as e,
|
|
2317
|
+
Fe as f,
|
|
2318
|
+
Qn as g,
|
|
2319
|
+
xt as h,
|
|
2320
|
+
ls as i,
|
|
2321
|
+
rs as j,
|
|
2322
|
+
ss as k,
|
|
2323
|
+
os as l,
|
|
2324
|
+
is as m,
|
|
2325
|
+
ns as n,
|
|
2326
|
+
Re as o,
|
|
2327
|
+
We as p,
|
|
2328
|
+
_e as q,
|
|
2329
|
+
j as r,
|
|
2330
|
+
$e as s,
|
|
2331
|
+
mt as t,
|
|
2332
|
+
as as u,
|
|
2333
|
+
cs as v,
|
|
2334
|
+
M as w,
|
|
2335
|
+
Mn as x,
|
|
2336
|
+
Nn as y,
|
|
2337
|
+
hs as z
|
|
2196
2338
|
};
|
|
2197
|
-
//# sourceMappingURL=errors-
|
|
2339
|
+
//# sourceMappingURL=errors-UqmtfBtv.js.map
|