@babylonlabs-io/ts-sdk 0.13.0 → 0.13.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-ZoUEvcDE.js → errors-D19BQSaj.js} +417 -373
- package/dist/errors-D19BQSaj.js.map +1 -0
- package/dist/errors-vxNv_NdZ.cjs +2 -0
- package/dist/errors-vxNv_NdZ.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +21 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +7 -3
- package/dist/tbv/core/managers/PeginManager.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-B2aR9f2F.cjs +0 -2
- package/dist/errors-B2aR9f2F.cjs.map +0 -1
- package/dist/errors-ZoUEvcDE.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var ce = Object.defineProperty;
|
|
2
2
|
var ue = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var
|
|
3
|
+
var d = (e, t, n) => ue(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
import * as le from "bitcoinjs-lib";
|
|
5
|
-
import { script as he, Transaction as
|
|
5
|
+
import { script as he, Transaction as q, address as fe, Psbt as dt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as S } from "buffer";
|
|
7
|
-
import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as
|
|
8
|
-
import { createPublicClient as It, http as Et, encodeFunctionData as
|
|
9
|
-
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
-
function
|
|
7
|
+
import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as $, b as xe, A as ye, E as we, a as me, d as Pe, e as Te, f as ve, s as z, q as ke, x as vt, h as kt, i as Ht, r as He } from "./challengeAssert-CenzzhZU.js";
|
|
8
|
+
import { createPublicClient as It, http as Et, encodeFunctionData as Ie, zeroAddress as Ee } from "viem";
|
|
9
|
+
import { deriveVaultId as Se } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
function Ae(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}`
|
|
@@ -26,20 +26,20 @@ function Ee(e, t, n, s) {
|
|
|
26
26
|
let a = 0n, c = 0n;
|
|
27
27
|
for (const u of o) {
|
|
28
28
|
i.push(u), a += BigInt(u.value);
|
|
29
|
-
const h = i.length * de, l = s * Tt,
|
|
30
|
-
if (c = BigInt(Math.ceil(
|
|
31
|
-
const
|
|
29
|
+
const h = i.length * de, l = s * Tt, f = h + l + ge;
|
|
30
|
+
if (c = BigInt(Math.ceil(f * n)) + BigInt(pe(n)), a - t - c > Vt) {
|
|
31
|
+
const b = BigInt(
|
|
32
32
|
Math.ceil(Tt * n)
|
|
33
33
|
);
|
|
34
|
-
c +=
|
|
34
|
+
c += b;
|
|
35
35
|
}
|
|
36
36
|
if (a >= t + c) {
|
|
37
|
-
const
|
|
37
|
+
const b = a - t - c;
|
|
38
38
|
return {
|
|
39
39
|
selectedUTXOs: i,
|
|
40
40
|
totalValue: a,
|
|
41
41
|
fee: c,
|
|
42
|
-
changeAmount:
|
|
42
|
+
changeAmount: b
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -47,17 +47,17 @@ function Ee(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
|
|
50
|
+
function Zn(e) {
|
|
51
51
|
return e > Vt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function Jn() {
|
|
54
54
|
return be;
|
|
55
55
|
}
|
|
56
56
|
function St(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
58
|
-
return `0x${
|
|
58
|
+
return `0x${q.fromHex(t).getId()}`;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function Yn(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,7 +67,7 @@ function Zn(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 = pt(n), r = new
|
|
70
|
+
const s = pt(n), r = new q();
|
|
71
71
|
r.version = 2;
|
|
72
72
|
for (const c of e) {
|
|
73
73
|
const u = S.from(c.txid, "hex").reverse();
|
|
@@ -101,8 +101,8 @@ function Zn(e, t, n) {
|
|
|
101
101
|
outputs: o
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
const s =
|
|
104
|
+
function Qn(e, t, n) {
|
|
105
|
+
const s = q.fromHex(e), r = new dt();
|
|
106
106
|
if (r.setVersion(s.version), r.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}`
|
|
@@ -126,7 +126,7 @@ function Jn(e, t, n) {
|
|
|
126
126
|
throw new Error(
|
|
127
127
|
`Input ${o} 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 f = {
|
|
130
130
|
script: S.from(a.scriptPubKey, "hex"),
|
|
131
131
|
value: a.value
|
|
132
132
|
};
|
|
@@ -134,7 +134,7 @@ function Jn(e, t, n) {
|
|
|
134
134
|
hash: i.hash,
|
|
135
135
|
index: i.index,
|
|
136
136
|
sequence: i.sequence,
|
|
137
|
-
witnessUtxo:
|
|
137
|
+
witnessUtxo: f,
|
|
138
138
|
tapInternalKey: n
|
|
139
139
|
});
|
|
140
140
|
}
|
|
@@ -145,8 +145,8 @@ function Jn(e, t, n) {
|
|
|
145
145
|
});
|
|
146
146
|
return r.toHex();
|
|
147
147
|
}
|
|
148
|
-
var
|
|
149
|
-
function
|
|
148
|
+
var st = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(st || {});
|
|
149
|
+
function Be(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 Se(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 $e(e, t) {
|
|
163
|
+
const n = S.from(e.scriptPubKey, "hex"), s = Be(n);
|
|
164
164
|
switch (s) {
|
|
165
|
-
case
|
|
165
|
+
case st.P2WPKH:
|
|
166
166
|
return {
|
|
167
167
|
witnessUtxo: {
|
|
168
168
|
script: n,
|
|
169
169
|
value: e.value
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
case
|
|
172
|
+
case st.P2WSH: {
|
|
173
173
|
if (!e.witnessScript)
|
|
174
174
|
throw new Error("Missing witnessScript for P2WSH input");
|
|
175
175
|
return {
|
|
@@ -180,7 +180,7 @@ function Ae(e, t) {
|
|
|
180
180
|
witnessScript: S.from(e.witnessScript, "hex")
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
case
|
|
183
|
+
case st.P2TR: {
|
|
184
184
|
if (t && t.length !== 32)
|
|
185
185
|
throw new Error(
|
|
186
186
|
`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
|
|
@@ -210,22 +210,22 @@ function bt(e, t) {
|
|
|
210
210
|
}))
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
function
|
|
215
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
213
|
+
const Ue = 21e6 * 1e8, Kt = 1e4;
|
|
214
|
+
function Dt(e) {
|
|
215
|
+
return Number.isInteger(e) && e > 0 && e <= Ue;
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
217
|
+
function Fe(e) {
|
|
218
|
+
return Number.isInteger(e) && e > 0 && e <= Kt;
|
|
219
219
|
}
|
|
220
220
|
function Mt(e, t) {
|
|
221
221
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
222
222
|
}
|
|
223
|
-
const
|
|
223
|
+
const Oe = {
|
|
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 ot(e, t) {
|
|
229
229
|
try {
|
|
230
230
|
const n = await fetch(e, t);
|
|
231
231
|
if (!n.ok) {
|
|
@@ -240,7 +240,7 @@ async function nt(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 Le(e, t) {
|
|
244
244
|
try {
|
|
245
245
|
const n = await fetch(`${t}/tx`, {
|
|
246
246
|
method: "POST",
|
|
@@ -266,10 +266,10 @@ async function Fe(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 Ce(e, t) {
|
|
270
|
+
return ot(`${t}/tx/${e}`);
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
272
|
+
async function ts(e, t) {
|
|
273
273
|
try {
|
|
274
274
|
const n = await fetch(`${t}/tx/${e}/hex`);
|
|
275
275
|
if (!n.ok) {
|
|
@@ -283,14 +283,14 @@ async function Yn(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
|
|
286
|
+
async function _e(e, t, n) {
|
|
287
|
+
const s = await Ce(e, n);
|
|
288
288
|
if (!Mt(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
292
|
const r = s.vout[t];
|
|
293
|
-
if (!
|
|
293
|
+
if (!Dt(r.value))
|
|
294
294
|
throw new Error(`Invalid UTXO value ${r.value} for ${e}:${t}`);
|
|
295
295
|
return {
|
|
296
296
|
txid: e,
|
|
@@ -299,9 +299,9 @@ async function Oe(e, t, n) {
|
|
|
299
299
|
scriptPubKey: r.scriptpubkey
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
|
-
async function
|
|
302
|
+
async function es(e, t) {
|
|
303
303
|
try {
|
|
304
|
-
const n = await
|
|
304
|
+
const n = await ot(`${t}/address/${e}/utxo`), s = await ot(`${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.`
|
|
@@ -309,7 +309,7 @@ async function Qn(e, t) {
|
|
|
309
309
|
for (const o of n) {
|
|
310
310
|
if (!Mt(o.vout))
|
|
311
311
|
throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);
|
|
312
|
-
if (!
|
|
312
|
+
if (!Dt(o.value))
|
|
313
313
|
throw new Error(
|
|
314
314
|
`Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`
|
|
315
315
|
);
|
|
@@ -329,13 +329,13 @@ async function Qn(e, t) {
|
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
332
|
+
function ns(e) {
|
|
333
|
+
return Oe[e];
|
|
334
334
|
}
|
|
335
|
-
async function
|
|
336
|
-
return
|
|
335
|
+
async function ss(e, t) {
|
|
336
|
+
return ot(`${t}/address/${e}/txs`);
|
|
337
337
|
}
|
|
338
|
-
async function
|
|
338
|
+
async function rs(e) {
|
|
339
339
|
const t = await fetch(`${e}/v1/fees/recommended`);
|
|
340
340
|
if (!t.ok)
|
|
341
341
|
throw new Error(
|
|
@@ -349,9 +349,9 @@ async function ns(e) {
|
|
|
349
349
|
"minimumFee"
|
|
350
350
|
];
|
|
351
351
|
for (const r of s)
|
|
352
|
-
if (
|
|
352
|
+
if (!Fe(n[r]))
|
|
353
353
|
throw new Error(
|
|
354
|
-
`Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${
|
|
354
|
+
`Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Kt}`
|
|
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(
|
|
@@ -624,7 +624,7 @@ const ct = [
|
|
|
624
624
|
name: "PeginSignaturesIncomplete",
|
|
625
625
|
inputs: []
|
|
626
626
|
}
|
|
627
|
-
],
|
|
627
|
+
], N = {
|
|
628
628
|
// VaultAlreadyExists()
|
|
629
629
|
"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
630
|
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
@@ -673,24 +673,24 @@ function xt(e) {
|
|
|
673
673
|
if (i)
|
|
674
674
|
return i[1];
|
|
675
675
|
}
|
|
676
|
-
function
|
|
676
|
+
function os(e) {
|
|
677
677
|
const t = xt(e);
|
|
678
678
|
if (t) {
|
|
679
679
|
const n = t.substring(0, 10);
|
|
680
|
-
return
|
|
680
|
+
return N[t] ?? N[n];
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
|
-
function
|
|
683
|
+
function is(e) {
|
|
684
684
|
const t = xt(e);
|
|
685
685
|
if (t === void 0) return !1;
|
|
686
686
|
const n = t.substring(0, 10);
|
|
687
|
-
return t in
|
|
687
|
+
return t in N || n in N;
|
|
688
688
|
}
|
|
689
689
|
function ut(e) {
|
|
690
690
|
console.error("[Contract Error] Raw error:", e);
|
|
691
691
|
const t = xt(e);
|
|
692
692
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
693
|
-
const s = t.substring(0, 10), r =
|
|
693
|
+
const s = t.substring(0, 10), r = N[t] ?? N[s];
|
|
694
694
|
if (r)
|
|
695
695
|
throw console.error("[Contract Error] Known error:", r), new Error(r);
|
|
696
696
|
}
|
|
@@ -708,24 +708,24 @@ function ut(e) {
|
|
|
708
708
|
}
|
|
709
709
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
710
710
|
}
|
|
711
|
-
function
|
|
711
|
+
function We(e, t, n, s) {
|
|
712
712
|
const r = n == null ? void 0 : n[`${e}:${t}`];
|
|
713
713
|
return r ? Promise.resolve({
|
|
714
714
|
txid: e,
|
|
715
715
|
vout: t,
|
|
716
716
|
value: r.value,
|
|
717
717
|
scriptPubKey: r.scriptPubKey
|
|
718
|
-
}) :
|
|
718
|
+
}) : _e(e, t, s);
|
|
719
719
|
}
|
|
720
|
-
const
|
|
721
|
-
class
|
|
720
|
+
const Re = 12e4;
|
|
721
|
+
class as {
|
|
722
722
|
/**
|
|
723
723
|
* Creates a new PeginManager instance.
|
|
724
724
|
*
|
|
725
725
|
* @param config - Manager configuration including wallets and contract addresses
|
|
726
726
|
*/
|
|
727
727
|
constructor(t) {
|
|
728
|
-
|
|
728
|
+
d(this, "config");
|
|
729
729
|
this.config = t;
|
|
730
730
|
}
|
|
731
731
|
/**
|
|
@@ -749,7 +749,7 @@ class os {
|
|
|
749
749
|
* @throws Error if wallet operations fail or insufficient funds
|
|
750
750
|
*/
|
|
751
751
|
async preparePegin(t) {
|
|
752
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r =
|
|
752
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = $(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map($), i = t.universalChallengerBtcPubkeys.map($);
|
|
753
753
|
if (t.hashlocks.length !== t.amounts.length)
|
|
754
754
|
throw new Error(
|
|
755
755
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
@@ -769,36 +769,36 @@ class os {
|
|
|
769
769
|
councilQuorum: t.councilQuorum,
|
|
770
770
|
councilSize: t.councilSize,
|
|
771
771
|
network: this.config.btcNetwork
|
|
772
|
-
}, u = await xe(c), h =
|
|
772
|
+
}, u = await xe(c), h = Ae(
|
|
773
773
|
[...t.availableUTXOs],
|
|
774
774
|
u.totalOutputValue,
|
|
775
775
|
t.mempoolFeeRate,
|
|
776
776
|
ye(u.htlcValues.length)
|
|
777
|
-
), l = pt(this.config.btcNetwork),
|
|
777
|
+
), l = pt(this.config.btcNetwork), f = we({
|
|
778
778
|
unfundedTxHex: u.psbtHex,
|
|
779
779
|
selectedUTXOs: h.selectedUTXOs,
|
|
780
780
|
changeAddress: t.changeAddress,
|
|
781
781
|
changeAmount: h.changeAmount,
|
|
782
782
|
network: l
|
|
783
|
-
}), g =
|
|
784
|
-
for (let
|
|
783
|
+
}), g = $(St(f)), b = [], w = [], x = [];
|
|
784
|
+
for (let p = 0; p < t.hashlocks.length; p++) {
|
|
785
785
|
const P = await me({
|
|
786
786
|
prePeginParams: c,
|
|
787
787
|
timelockPegin: t.timelockPegin,
|
|
788
|
-
fundedPrePeginTxHex:
|
|
789
|
-
htlcVout:
|
|
790
|
-
}),
|
|
788
|
+
fundedPrePeginTxHex: f,
|
|
789
|
+
htlcVout: p
|
|
790
|
+
}), v = await Pe({
|
|
791
791
|
peginTxHex: P.txHex,
|
|
792
|
-
fundedPrePeginTxHex:
|
|
792
|
+
fundedPrePeginTxHex: f,
|
|
793
793
|
depositorPubkey: s,
|
|
794
794
|
vaultProviderPubkey: r,
|
|
795
795
|
vaultKeeperPubkeys: o,
|
|
796
796
|
universalChallengerPubkeys: i,
|
|
797
|
-
hashlock: t.hashlocks[
|
|
797
|
+
hashlock: t.hashlocks[p],
|
|
798
798
|
timelockRefund: t.timelockRefund,
|
|
799
799
|
network: this.config.btcNetwork
|
|
800
800
|
});
|
|
801
|
-
|
|
801
|
+
b.push(P), w.push(v.psbtHex), x.push(
|
|
802
802
|
bt(n, 1)
|
|
803
803
|
);
|
|
804
804
|
}
|
|
@@ -806,22 +806,22 @@ class os {
|
|
|
806
806
|
w,
|
|
807
807
|
x
|
|
808
808
|
), m = [];
|
|
809
|
-
for (let
|
|
809
|
+
for (let p = 0; p < y.length; p++) {
|
|
810
810
|
const P = Te(
|
|
811
|
-
y[
|
|
811
|
+
y[p],
|
|
812
812
|
s
|
|
813
|
-
),
|
|
813
|
+
), v = ve(y[p]);
|
|
814
814
|
m.push({
|
|
815
|
-
htlcVout:
|
|
816
|
-
htlcValue: u.htlcValues[
|
|
817
|
-
peginTxHex:
|
|
818
|
-
peginTxid: p
|
|
815
|
+
htlcVout: p,
|
|
816
|
+
htlcValue: u.htlcValues[p],
|
|
817
|
+
peginTxHex: v,
|
|
818
|
+
peginTxid: b[p].txid,
|
|
819
819
|
peginInputSignature: P,
|
|
820
|
-
vaultScriptPubKey: p
|
|
820
|
+
vaultScriptPubKey: b[p].vaultScriptPubKey
|
|
821
821
|
});
|
|
822
822
|
}
|
|
823
823
|
return {
|
|
824
|
-
fundedPrePeginTxHex:
|
|
824
|
+
fundedPrePeginTxHex: f,
|
|
825
825
|
prePeginTxid: g,
|
|
826
826
|
unsignedPrePeginTxHex: u.psbtHex,
|
|
827
827
|
perVault: m,
|
|
@@ -875,7 +875,7 @@ class os {
|
|
|
875
875
|
* @throws Error if signing or broadcasting fails
|
|
876
876
|
*/
|
|
877
877
|
async signAndBroadcast(t) {
|
|
878
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o =
|
|
878
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = q.fromHex(r);
|
|
879
879
|
if (o.ins.length === 0)
|
|
880
880
|
throw new Error("Transaction has no inputs");
|
|
881
881
|
const i = new dt();
|
|
@@ -892,12 +892,12 @@ class os {
|
|
|
892
892
|
);
|
|
893
893
|
const u = this.config.mempoolApiUrl, h = o.ins.map((x) => {
|
|
894
894
|
const y = S.from(x.hash).reverse().toString("hex"), m = x.index;
|
|
895
|
-
return
|
|
896
|
-
(
|
|
895
|
+
return We(y, m, t.localPrevouts, u).then(
|
|
896
|
+
(p) => ({ input: x, utxoData: p, txid: y, vout: m })
|
|
897
897
|
);
|
|
898
898
|
}), l = await Promise.all(h);
|
|
899
|
-
for (const { input: x, utxoData: y, txid: m, vout:
|
|
900
|
-
const P =
|
|
899
|
+
for (const { input: x, utxoData: y, txid: m, vout: p } of l) {
|
|
900
|
+
const P = $e(
|
|
901
901
|
{
|
|
902
902
|
value: y.value,
|
|
903
903
|
scriptPubKey: y.scriptPubKey
|
|
@@ -916,7 +916,7 @@ class os {
|
|
|
916
916
|
script: x.script,
|
|
917
917
|
value: x.value
|
|
918
918
|
});
|
|
919
|
-
const
|
|
919
|
+
const f = await this.config.btcWallet.signPsbt(i.toHex()), g = dt.fromHex(f);
|
|
920
920
|
try {
|
|
921
921
|
g.finalizeAllInputs();
|
|
922
922
|
} catch (x) {
|
|
@@ -927,8 +927,8 @@ class os {
|
|
|
927
927
|
`PSBT finalization failed and wallet did not auto-finalize: ${x}`
|
|
928
928
|
);
|
|
929
929
|
}
|
|
930
|
-
const
|
|
931
|
-
return await
|
|
930
|
+
const b = g.extractTransaction().toHex();
|
|
931
|
+
return await Le(b, u);
|
|
932
932
|
}
|
|
933
933
|
/**
|
|
934
934
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -962,25 +962,28 @@ class os {
|
|
|
962
962
|
} = t;
|
|
963
963
|
if (!this.config.ethWallet.account)
|
|
964
964
|
throw new Error("Ethereum wallet account not found");
|
|
965
|
-
const
|
|
966
|
-
|
|
965
|
+
const f = this.config.ethWallet.account.address, g = await this.resolvePopSignature(
|
|
966
|
+
f,
|
|
967
967
|
l
|
|
968
968
|
);
|
|
969
969
|
c && await c();
|
|
970
|
-
const
|
|
970
|
+
const b = z(n), w = z(s), x = z(r), y = await this.resolvePayoutScriptPubKey(
|
|
971
971
|
u
|
|
972
|
-
), m = St(x)
|
|
973
|
-
|
|
972
|
+
), m = St(x), p = await Se(
|
|
973
|
+
$(m),
|
|
974
|
+
$(f)
|
|
975
|
+
), P = z(p);
|
|
976
|
+
if (await this.checkVaultExists(P))
|
|
974
977
|
throw new Error(
|
|
975
|
-
`Vault already exists
|
|
978
|
+
`Vault already exists (ID: ${P}, peginTxHash: ${m}). 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.`
|
|
976
979
|
);
|
|
977
|
-
const
|
|
980
|
+
const T = It({
|
|
978
981
|
chain: this.config.ethChain,
|
|
979
982
|
transport: Et()
|
|
980
983
|
});
|
|
981
|
-
let
|
|
984
|
+
let E;
|
|
982
985
|
try {
|
|
983
|
-
|
|
986
|
+
E = await T.readContract({
|
|
984
987
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
985
988
|
abi: ct,
|
|
986
989
|
functionName: "getPegInFee",
|
|
@@ -991,12 +994,12 @@ class os {
|
|
|
991
994
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
992
995
|
);
|
|
993
996
|
}
|
|
994
|
-
const
|
|
997
|
+
const H = Ie({
|
|
995
998
|
abi: ct,
|
|
996
999
|
functionName: "submitPeginRequest",
|
|
997
1000
|
args: [
|
|
998
|
-
|
|
999
|
-
|
|
1001
|
+
f,
|
|
1002
|
+
b,
|
|
1000
1003
|
g,
|
|
1001
1004
|
w,
|
|
1002
1005
|
x,
|
|
@@ -1007,41 +1010,42 @@ class os {
|
|
|
1007
1010
|
h
|
|
1008
1011
|
]
|
|
1009
1012
|
});
|
|
1010
|
-
let
|
|
1013
|
+
let I;
|
|
1011
1014
|
try {
|
|
1012
|
-
|
|
1015
|
+
I = await T.estimateGas({
|
|
1013
1016
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1014
|
-
data:
|
|
1015
|
-
value:
|
|
1017
|
+
data: H,
|
|
1018
|
+
value: E,
|
|
1016
1019
|
account: this.config.ethWallet.account.address
|
|
1017
1020
|
});
|
|
1018
|
-
} catch (
|
|
1019
|
-
ut(
|
|
1021
|
+
} catch (O) {
|
|
1022
|
+
ut(O);
|
|
1020
1023
|
}
|
|
1021
|
-
let
|
|
1024
|
+
let F;
|
|
1022
1025
|
try {
|
|
1023
|
-
|
|
1026
|
+
F = await this.config.ethWallet.sendTransaction({
|
|
1024
1027
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1025
|
-
data:
|
|
1026
|
-
value:
|
|
1028
|
+
data: H,
|
|
1029
|
+
value: E,
|
|
1027
1030
|
account: this.config.ethWallet.account,
|
|
1028
1031
|
chain: this.config.ethChain,
|
|
1029
|
-
gas:
|
|
1032
|
+
gas: I
|
|
1030
1033
|
});
|
|
1031
|
-
} catch (
|
|
1032
|
-
ut(
|
|
1034
|
+
} catch (O) {
|
|
1035
|
+
ut(O);
|
|
1033
1036
|
}
|
|
1034
|
-
const
|
|
1035
|
-
hash:
|
|
1036
|
-
timeout:
|
|
1037
|
+
const K = await T.waitForTransactionReceipt({
|
|
1038
|
+
hash: F,
|
|
1039
|
+
timeout: Re
|
|
1037
1040
|
});
|
|
1038
|
-
return
|
|
1041
|
+
return K.status === "reverted" && ut(
|
|
1039
1042
|
new Error(
|
|
1040
|
-
`Transaction reverted. Hash: ${
|
|
1043
|
+
`Transaction reverted. Hash: ${F}. Check the transaction on block explorer for details.`
|
|
1041
1044
|
)
|
|
1042
1045
|
), {
|
|
1043
|
-
ethTxHash:
|
|
1044
|
-
vaultId:
|
|
1046
|
+
ethTxHash: K.transactionHash,
|
|
1047
|
+
vaultId: P,
|
|
1048
|
+
peginTxHash: m,
|
|
1045
1049
|
btcPopSignature: g
|
|
1046
1050
|
};
|
|
1047
1051
|
}
|
|
@@ -1061,7 +1065,7 @@ class os {
|
|
|
1061
1065
|
abi: ct,
|
|
1062
1066
|
functionName: "getBTCVault",
|
|
1063
1067
|
args: [t]
|
|
1064
|
-
})).depositor !==
|
|
1068
|
+
})).depositor !== Ee;
|
|
1065
1069
|
} catch {
|
|
1066
1070
|
return !1;
|
|
1067
1071
|
}
|
|
@@ -1130,14 +1134,14 @@ class os {
|
|
|
1130
1134
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1131
1135
|
}
|
|
1132
1136
|
}
|
|
1133
|
-
class
|
|
1137
|
+
class cs {
|
|
1134
1138
|
/**
|
|
1135
1139
|
* Creates a new PayoutManager instance.
|
|
1136
1140
|
*
|
|
1137
1141
|
* @param config - Manager configuration including wallet
|
|
1138
1142
|
*/
|
|
1139
1143
|
constructor(t) {
|
|
1140
|
-
|
|
1144
|
+
d(this, "config");
|
|
1141
1145
|
this.config = t;
|
|
1142
1146
|
}
|
|
1143
1147
|
/**
|
|
@@ -1163,6 +1167,10 @@ class is {
|
|
|
1163
1167
|
* @throws Error if wallet operations fail or signature extraction fails
|
|
1164
1168
|
*/
|
|
1165
1169
|
async signPayoutTransaction(t) {
|
|
1170
|
+
this.validatePayoutOutputs(
|
|
1171
|
+
t.payoutTxHex,
|
|
1172
|
+
t.registeredPayoutScriptPubKey
|
|
1173
|
+
);
|
|
1166
1174
|
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = vt(
|
|
1167
1175
|
n,
|
|
1168
1176
|
t.depositorBtcPubkey
|
|
@@ -1217,6 +1225,10 @@ class is {
|
|
|
1217
1225
|
);
|
|
1218
1226
|
const n = await this.config.btcWallet.getPublicKeyHex(), s = [], r = [], o = [];
|
|
1219
1227
|
for (const c of t) {
|
|
1228
|
+
this.validatePayoutOutputs(
|
|
1229
|
+
c.payoutTxHex,
|
|
1230
|
+
c.registeredPayoutScriptPubKey
|
|
1231
|
+
);
|
|
1220
1232
|
const { depositorPubkey: u } = vt(
|
|
1221
1233
|
n,
|
|
1222
1234
|
c.depositorBtcPubkey
|
|
@@ -1256,18 +1268,50 @@ class is {
|
|
|
1256
1268
|
}
|
|
1257
1269
|
return a;
|
|
1258
1270
|
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Validates that the payout transaction's largest output pays to the
|
|
1273
|
+
* registered depositor payout address (scriptPubKey).
|
|
1274
|
+
*
|
|
1275
|
+
* This prevents two attack vectors from a malicious vault provider:
|
|
1276
|
+
* 1. Substituting a completely different payout address
|
|
1277
|
+
* 2. Including a dust output to the correct address while routing
|
|
1278
|
+
* the actual funds to an attacker-controlled address
|
|
1279
|
+
*
|
|
1280
|
+
* @param payoutTxHex - Raw payout transaction hex
|
|
1281
|
+
* @param registeredPayoutScriptPubKey - On-chain registered scriptPubKey (hex, with or without 0x prefix)
|
|
1282
|
+
* @throws Error if scriptPubKey is invalid hex
|
|
1283
|
+
* @throws Error if the largest output does not pay to the registered address
|
|
1284
|
+
*/
|
|
1285
|
+
validatePayoutOutputs(t, n) {
|
|
1286
|
+
if (!He(n))
|
|
1287
|
+
throw new Error(
|
|
1288
|
+
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1289
|
+
);
|
|
1290
|
+
const s = S.from(
|
|
1291
|
+
$(n),
|
|
1292
|
+
"hex"
|
|
1293
|
+
), r = q.fromHex($(t));
|
|
1294
|
+
if (r.outs.length === 0)
|
|
1295
|
+
throw new Error("Payout transaction has no outputs");
|
|
1296
|
+
if (!r.outs.reduce(
|
|
1297
|
+
(i, a) => a.value > i.value ? a : i
|
|
1298
|
+
).script.equals(s))
|
|
1299
|
+
throw new Error(
|
|
1300
|
+
"Payout transaction does not pay to the registered depositor payout address"
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1259
1303
|
}
|
|
1260
|
-
function
|
|
1304
|
+
function Ve(e) {
|
|
1261
1305
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1262
1306
|
}
|
|
1263
|
-
function
|
|
1307
|
+
function R(e, t = "") {
|
|
1264
1308
|
if (!Number.isSafeInteger(e) || e < 0) {
|
|
1265
1309
|
const n = t && `"${t}" `;
|
|
1266
1310
|
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
1267
1311
|
}
|
|
1268
1312
|
}
|
|
1269
|
-
function
|
|
1270
|
-
const s =
|
|
1313
|
+
function V(e, t, n = "") {
|
|
1314
|
+
const s = Ve(e), r = e == null ? void 0 : e.length, o = t !== void 0;
|
|
1271
1315
|
if (!s || o && r !== t) {
|
|
1272
1316
|
const i = n && `"${n}" `, a = o ? ` of length ${t}` : "", c = s ? `length=${r}` : `type=${typeof e}`;
|
|
1273
1317
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
@@ -1277,60 +1321,60 @@ function W(e, t, n = "") {
|
|
|
1277
1321
|
function Nt(e) {
|
|
1278
1322
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1279
1323
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1280
|
-
|
|
1324
|
+
R(e.outputLen), R(e.blockLen);
|
|
1281
1325
|
}
|
|
1282
|
-
function
|
|
1326
|
+
function X(e, t = !0) {
|
|
1283
1327
|
if (e.destroyed)
|
|
1284
1328
|
throw new Error("Hash instance has been destroyed");
|
|
1285
1329
|
if (t && e.finished)
|
|
1286
1330
|
throw new Error("Hash#digest() has already been called");
|
|
1287
1331
|
}
|
|
1288
1332
|
function Xt(e, t) {
|
|
1289
|
-
|
|
1333
|
+
V(e, void 0, "digestInto() output");
|
|
1290
1334
|
const n = t.outputLen;
|
|
1291
1335
|
if (e.length < n)
|
|
1292
1336
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1293
1337
|
}
|
|
1294
|
-
function
|
|
1338
|
+
function Ke(e) {
|
|
1295
1339
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1296
1340
|
}
|
|
1297
1341
|
function A(...e) {
|
|
1298
1342
|
for (let t = 0; t < e.length; t++)
|
|
1299
1343
|
e[t].fill(0);
|
|
1300
1344
|
}
|
|
1301
|
-
function
|
|
1345
|
+
function rt(e) {
|
|
1302
1346
|
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
1303
1347
|
}
|
|
1304
1348
|
function B(e, t) {
|
|
1305
1349
|
return e << 32 - t | e >>> t;
|
|
1306
1350
|
}
|
|
1307
|
-
function
|
|
1351
|
+
function Z(e, t) {
|
|
1308
1352
|
return e << t | e >>> 32 - t >>> 0;
|
|
1309
1353
|
}
|
|
1310
|
-
const
|
|
1311
|
-
function
|
|
1354
|
+
const De = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1355
|
+
function Me(e) {
|
|
1312
1356
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1313
1357
|
}
|
|
1314
|
-
function
|
|
1358
|
+
function Ne(e) {
|
|
1315
1359
|
for (let t = 0; t < e.length; t++)
|
|
1316
|
-
e[t] =
|
|
1360
|
+
e[t] = Me(e[t]);
|
|
1317
1361
|
return e;
|
|
1318
1362
|
}
|
|
1319
|
-
const At =
|
|
1320
|
-
function
|
|
1363
|
+
const At = De ? (e) => e : Ne;
|
|
1364
|
+
function Xe(e) {
|
|
1321
1365
|
if (typeof e != "string")
|
|
1322
1366
|
throw new Error("string expected");
|
|
1323
1367
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1324
1368
|
}
|
|
1325
1369
|
function Bt(e, t = "") {
|
|
1326
|
-
return typeof e == "string" ?
|
|
1370
|
+
return typeof e == "string" ? Xe(e) : V(e, void 0, t);
|
|
1327
1371
|
}
|
|
1328
|
-
function
|
|
1372
|
+
function Ge(e, t) {
|
|
1329
1373
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1330
1374
|
throw new Error("options must be object or undefined");
|
|
1331
1375
|
return Object.assign(e, t);
|
|
1332
1376
|
}
|
|
1333
|
-
function
|
|
1377
|
+
function it(e, t = {}) {
|
|
1334
1378
|
const n = (r, o) => e(o).update(r).digest(), s = e(void 0);
|
|
1335
1379
|
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
|
|
1336
1380
|
}
|
|
@@ -1339,13 +1383,13 @@ const Gt = (e) => ({
|
|
|
1339
1383
|
});
|
|
1340
1384
|
class jt {
|
|
1341
1385
|
constructor(t, n) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
if (Nt(t),
|
|
1386
|
+
d(this, "oHash");
|
|
1387
|
+
d(this, "iHash");
|
|
1388
|
+
d(this, "blockLen");
|
|
1389
|
+
d(this, "outputLen");
|
|
1390
|
+
d(this, "finished", !1);
|
|
1391
|
+
d(this, "destroyed", !1);
|
|
1392
|
+
if (Nt(t), V(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1349
1393
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1350
1394
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1351
1395
|
const s = this.blockLen, r = new Uint8Array(s);
|
|
@@ -1358,10 +1402,10 @@ class jt {
|
|
|
1358
1402
|
this.oHash.update(r), A(r);
|
|
1359
1403
|
}
|
|
1360
1404
|
update(t) {
|
|
1361
|
-
return
|
|
1405
|
+
return X(this), this.iHash.update(t), this;
|
|
1362
1406
|
}
|
|
1363
1407
|
digestInto(t) {
|
|
1364
|
-
|
|
1408
|
+
X(this), V(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1365
1409
|
}
|
|
1366
1410
|
digest() {
|
|
1367
1411
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -1381,34 +1425,34 @@ class jt {
|
|
|
1381
1425
|
}
|
|
1382
1426
|
const yt = (e, t, n) => new jt(e, t).update(n).digest();
|
|
1383
1427
|
yt.create = (e, t) => new jt(e, t);
|
|
1384
|
-
function
|
|
1428
|
+
function je(e, t, n) {
|
|
1385
1429
|
return e & t ^ ~e & n;
|
|
1386
1430
|
}
|
|
1387
|
-
function
|
|
1431
|
+
function qe(e, t, n) {
|
|
1388
1432
|
return e & t ^ e & n ^ t & n;
|
|
1389
1433
|
}
|
|
1390
1434
|
class wt {
|
|
1391
1435
|
constructor(t, n, s, r) {
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1436
|
+
d(this, "blockLen");
|
|
1437
|
+
d(this, "outputLen");
|
|
1438
|
+
d(this, "padOffset");
|
|
1439
|
+
d(this, "isLE");
|
|
1396
1440
|
// For partial updates less than block size
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view =
|
|
1441
|
+
d(this, "buffer");
|
|
1442
|
+
d(this, "view");
|
|
1443
|
+
d(this, "finished", !1);
|
|
1444
|
+
d(this, "length", 0);
|
|
1445
|
+
d(this, "pos", 0);
|
|
1446
|
+
d(this, "destroyed", !1);
|
|
1447
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = rt(this.buffer);
|
|
1404
1448
|
}
|
|
1405
1449
|
update(t) {
|
|
1406
|
-
|
|
1450
|
+
X(this), V(t);
|
|
1407
1451
|
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
1408
1452
|
for (let i = 0; i < o; ) {
|
|
1409
1453
|
const a = Math.min(r - this.pos, o - i);
|
|
1410
1454
|
if (a === r) {
|
|
1411
|
-
const c =
|
|
1455
|
+
const c = rt(t);
|
|
1412
1456
|
for (; r <= o - i; i += r)
|
|
1413
1457
|
this.process(c, i);
|
|
1414
1458
|
continue;
|
|
@@ -1418,14 +1462,14 @@ class wt {
|
|
|
1418
1462
|
return this.length += t.length, this.roundClean(), this;
|
|
1419
1463
|
}
|
|
1420
1464
|
digestInto(t) {
|
|
1421
|
-
|
|
1465
|
+
X(this), Xt(t, this), this.finished = !0;
|
|
1422
1466
|
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
1423
1467
|
let { pos: i } = this;
|
|
1424
1468
|
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
1425
1469
|
for (let l = i; l < r; l++)
|
|
1426
1470
|
n[l] = 0;
|
|
1427
1471
|
s.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
1428
|
-
const a =
|
|
1472
|
+
const a = rt(t), c = this.outputLen;
|
|
1429
1473
|
if (c % 4)
|
|
1430
1474
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1431
1475
|
const u = c / 4, h = this.get();
|
|
@@ -1449,7 +1493,7 @@ class wt {
|
|
|
1449
1493
|
return this._cloneInto();
|
|
1450
1494
|
}
|
|
1451
1495
|
}
|
|
1452
|
-
const
|
|
1496
|
+
const L = /* @__PURE__ */ Uint32Array.from([
|
|
1453
1497
|
1779033703,
|
|
1454
1498
|
3144134277,
|
|
1455
1499
|
1013904242,
|
|
@@ -1458,7 +1502,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1458
1502
|
2600822924,
|
|
1459
1503
|
528734635,
|
|
1460
1504
|
1541459225
|
|
1461
|
-
]),
|
|
1505
|
+
]), k = /* @__PURE__ */ Uint32Array.from([
|
|
1462
1506
|
1779033703,
|
|
1463
1507
|
4089235720,
|
|
1464
1508
|
3144134277,
|
|
@@ -1475,7 +1519,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1475
1519
|
4215389547,
|
|
1476
1520
|
1541459225,
|
|
1477
1521
|
327033209
|
|
1478
|
-
]),
|
|
1522
|
+
]), ze = /* @__PURE__ */ Uint8Array.from([
|
|
1479
1523
|
7,
|
|
1480
1524
|
4,
|
|
1481
1525
|
13,
|
|
@@ -1492,11 +1536,11 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1492
1536
|
14,
|
|
1493
1537
|
11,
|
|
1494
1538
|
8
|
|
1495
|
-
]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)),
|
|
1496
|
-
const n = [[qt], [
|
|
1539
|
+
]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ze = qt.map((e) => (9 * e + 5) % 16), zt = /* @__PURE__ */ (() => {
|
|
1540
|
+
const n = [[qt], [Ze]];
|
|
1497
1541
|
for (let s = 0; s < 4; s++)
|
|
1498
1542
|
for (let r of n)
|
|
1499
|
-
r.push(r[s].map((o) =>
|
|
1543
|
+
r.push(r[s].map((o) => ze[o]));
|
|
1500
1544
|
return n;
|
|
1501
1545
|
})(), Zt = zt[0], Jt = zt[1], Yt = /* @__PURE__ */ [
|
|
1502
1546
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
@@ -1504,13 +1548,13 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1504
1548
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1505
1549
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1506
1550
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1507
|
-
].map((e) => Uint8Array.from(e)),
|
|
1551
|
+
].map((e) => Uint8Array.from(e)), Je = /* @__PURE__ */ Zt.map((e, t) => e.map((n) => Yt[t][n])), Ye = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Yt[t][n])), Qe = /* @__PURE__ */ Uint32Array.from([
|
|
1508
1552
|
0,
|
|
1509
1553
|
1518500249,
|
|
1510
1554
|
1859775393,
|
|
1511
1555
|
2400959708,
|
|
1512
1556
|
2840853838
|
|
1513
|
-
]),
|
|
1557
|
+
]), tn = /* @__PURE__ */ Uint32Array.from([
|
|
1514
1558
|
1352829926,
|
|
1515
1559
|
1548603684,
|
|
1516
1560
|
1836072691,
|
|
@@ -1520,15 +1564,15 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1520
1564
|
function $t(e, t, n, s) {
|
|
1521
1565
|
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);
|
|
1522
1566
|
}
|
|
1523
|
-
const
|
|
1524
|
-
class
|
|
1567
|
+
const J = /* @__PURE__ */ new Uint32Array(16);
|
|
1568
|
+
class en extends wt {
|
|
1525
1569
|
constructor() {
|
|
1526
1570
|
super(64, 20, 8, !0);
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1571
|
+
d(this, "h0", 1732584193);
|
|
1572
|
+
d(this, "h1", -271733879);
|
|
1573
|
+
d(this, "h2", -1732584194);
|
|
1574
|
+
d(this, "h3", 271733878);
|
|
1575
|
+
d(this, "h4", -1009589776);
|
|
1532
1576
|
}
|
|
1533
1577
|
get() {
|
|
1534
1578
|
const { h0: n, h1: s, h2: r, h3: o, h4: i } = this;
|
|
@@ -1538,48 +1582,48 @@ class Qe extends wt {
|
|
|
1538
1582
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = i | 0;
|
|
1539
1583
|
}
|
|
1540
1584
|
process(n, s) {
|
|
1541
|
-
for (let
|
|
1542
|
-
|
|
1543
|
-
let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, h = this.h3 | 0, l = h,
|
|
1544
|
-
for (let
|
|
1545
|
-
const w = 4 -
|
|
1546
|
-
for (let
|
|
1547
|
-
const E =
|
|
1548
|
-
r =
|
|
1585
|
+
for (let b = 0; b < 16; b++, s += 4)
|
|
1586
|
+
J[b] = n.getUint32(s, !0);
|
|
1587
|
+
let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, h = this.h3 | 0, l = h, f = this.h4 | 0, g = f;
|
|
1588
|
+
for (let b = 0; b < 5; b++) {
|
|
1589
|
+
const w = 4 - b, x = Qe[b], y = tn[b], m = Zt[b], p = Jt[b], P = Je[b], v = Ye[b];
|
|
1590
|
+
for (let T = 0; T < 16; T++) {
|
|
1591
|
+
const E = Z(r + $t(b, i, c, h) + J[m[T]] + x, P[T]) + f | 0;
|
|
1592
|
+
r = f, f = h, h = Z(c, 10) | 0, c = i, i = E;
|
|
1549
1593
|
}
|
|
1550
|
-
for (let
|
|
1551
|
-
const E =
|
|
1552
|
-
o = g, g = l, l =
|
|
1594
|
+
for (let T = 0; T < 16; T++) {
|
|
1595
|
+
const E = Z(o + $t(w, a, u, l) + J[p[T]] + y, v[T]) + g | 0;
|
|
1596
|
+
o = g, g = l, l = Z(u, 10) | 0, u = a, a = E;
|
|
1553
1597
|
}
|
|
1554
1598
|
}
|
|
1555
|
-
this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 +
|
|
1599
|
+
this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 + f + o | 0, this.h4 + r + a | 0, this.h0 + i + u | 0);
|
|
1556
1600
|
}
|
|
1557
1601
|
roundClean() {
|
|
1558
|
-
A(
|
|
1602
|
+
A(J);
|
|
1559
1603
|
}
|
|
1560
1604
|
destroy() {
|
|
1561
1605
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1562
1606
|
}
|
|
1563
1607
|
}
|
|
1564
|
-
const
|
|
1565
|
-
function
|
|
1566
|
-
return t ? { h: Number(e &
|
|
1608
|
+
const nn = /* @__PURE__ */ it(() => new en()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ut = /* @__PURE__ */ BigInt(32);
|
|
1609
|
+
function sn(e, t = !1) {
|
|
1610
|
+
return t ? { h: Number(e & Y), l: Number(e >> Ut & Y) } : { h: Number(e >> Ut & Y) | 0, l: Number(e & Y) | 0 };
|
|
1567
1611
|
}
|
|
1568
1612
|
function Qt(e, t = !1) {
|
|
1569
1613
|
const n = e.length;
|
|
1570
1614
|
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
1571
1615
|
for (let o = 0; o < n; o++) {
|
|
1572
|
-
const { h: i, l: a } =
|
|
1616
|
+
const { h: i, l: a } = sn(e[o], t);
|
|
1573
1617
|
[s[o], r[o]] = [i, a];
|
|
1574
1618
|
}
|
|
1575
1619
|
return [s, r];
|
|
1576
1620
|
}
|
|
1577
|
-
const Ft = (e, t, n) => e >>> n,
|
|
1578
|
-
function
|
|
1621
|
+
const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n, D = (e, t, n) => e >>> n | t << 32 - n, M = (e, t, n) => e << 32 - n | t >>> n, Q = (e, t, n) => e << 64 - n | t >>> n - 32, tt = (e, t, n) => e >>> n - 32 | t << 64 - n, rn = (e, t, n) => e << n | t >>> 32 - n, on = (e, t, n) => t << n | e >>> 32 - n, an = (e, t, n) => t << n - 32 | e >>> 64 - n, cn = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1622
|
+
function U(e, t, n, s) {
|
|
1579
1623
|
const r = (t >>> 0) + (s >>> 0);
|
|
1580
1624
|
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
1581
1625
|
}
|
|
1582
|
-
const
|
|
1626
|
+
const un = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ln = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, hn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), fn = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, dn = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), pn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, bn = /* @__PURE__ */ Uint32Array.from([
|
|
1583
1627
|
1116352408,
|
|
1584
1628
|
1899447441,
|
|
1585
1629
|
3049323471,
|
|
@@ -1644,8 +1688,8 @@ const an = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), cn = (e, t, n, s) =>
|
|
|
1644
1688
|
2756734187,
|
|
1645
1689
|
3204031479,
|
|
1646
1690
|
3329325298
|
|
1647
|
-
]),
|
|
1648
|
-
class
|
|
1691
|
+
]), C = /* @__PURE__ */ new Uint32Array(64);
|
|
1692
|
+
class gn extends wt {
|
|
1649
1693
|
constructor(t) {
|
|
1650
1694
|
super(64, t, 8, !1);
|
|
1651
1695
|
}
|
|
@@ -1659,38 +1703,38 @@ class pn extends wt {
|
|
|
1659
1703
|
}
|
|
1660
1704
|
process(t, n) {
|
|
1661
1705
|
for (let l = 0; l < 16; l++, n += 4)
|
|
1662
|
-
|
|
1706
|
+
C[l] = t.getUint32(n, !1);
|
|
1663
1707
|
for (let l = 16; l < 64; l++) {
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1708
|
+
const f = C[l - 15], g = C[l - 2], b = B(f, 7) ^ B(f, 18) ^ f >>> 3, w = B(g, 17) ^ B(g, 19) ^ g >>> 10;
|
|
1709
|
+
C[l] = w + C[l - 7] + b + C[l - 16] | 0;
|
|
1666
1710
|
}
|
|
1667
1711
|
let { A: s, B: r, C: o, D: i, E: a, F: c, G: u, H: h } = this;
|
|
1668
1712
|
for (let l = 0; l < 64; l++) {
|
|
1669
|
-
const
|
|
1713
|
+
const f = B(a, 6) ^ B(a, 11) ^ B(a, 25), g = h + f + je(a, c, u) + bn[l] + C[l] | 0, w = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + qe(s, r, o) | 0;
|
|
1670
1714
|
h = u, u = c, c = a, a = i + g | 0, i = o, o = r, r = s, s = g + w | 0;
|
|
1671
1715
|
}
|
|
1672
1716
|
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, u = u + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, a, c, u, h);
|
|
1673
1717
|
}
|
|
1674
1718
|
roundClean() {
|
|
1675
|
-
A(
|
|
1719
|
+
A(C);
|
|
1676
1720
|
}
|
|
1677
1721
|
destroy() {
|
|
1678
1722
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
|
|
1679
1723
|
}
|
|
1680
1724
|
}
|
|
1681
|
-
class
|
|
1725
|
+
class xn extends gn {
|
|
1682
1726
|
constructor() {
|
|
1683
1727
|
super(32);
|
|
1684
1728
|
// We cannot use array here since array allows indexing by variable
|
|
1685
1729
|
// which means optimizer/compiler cannot use registers.
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1730
|
+
d(this, "A", L[0] | 0);
|
|
1731
|
+
d(this, "B", L[1] | 0);
|
|
1732
|
+
d(this, "C", L[2] | 0);
|
|
1733
|
+
d(this, "D", L[3] | 0);
|
|
1734
|
+
d(this, "E", L[4] | 0);
|
|
1735
|
+
d(this, "F", L[5] | 0);
|
|
1736
|
+
d(this, "G", L[6] | 0);
|
|
1737
|
+
d(this, "H", L[7] | 0);
|
|
1694
1738
|
}
|
|
1695
1739
|
}
|
|
1696
1740
|
const te = Qt([
|
|
@@ -1774,92 +1818,92 @@ const te = Qt([
|
|
|
1774
1818
|
"0x597f299cfc657e2a",
|
|
1775
1819
|
"0x5fcb6fab3ad6faec",
|
|
1776
1820
|
"0x6c44198c4a475817"
|
|
1777
|
-
].map((e) => BigInt(e))),
|
|
1778
|
-
class
|
|
1821
|
+
].map((e) => BigInt(e))), yn = te[0], wn = te[1], _ = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
|
|
1822
|
+
class mn extends wt {
|
|
1779
1823
|
constructor(t) {
|
|
1780
1824
|
super(128, t, 16, !1);
|
|
1781
1825
|
}
|
|
1782
1826
|
// prettier-ignore
|
|
1783
1827
|
get() {
|
|
1784
|
-
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl:
|
|
1785
|
-
return [t, n, s, r, o, i, a, c, u, h, l,
|
|
1828
|
+
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl: f, Gh: g, Gl: b, Hh: w, Hl: x } = this;
|
|
1829
|
+
return [t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x];
|
|
1786
1830
|
}
|
|
1787
1831
|
// prettier-ignore
|
|
1788
|
-
set(t, n, s, r, o, i, a, c, u, h, l,
|
|
1789
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = u | 0, this.El = h | 0, this.Fh = l | 0, this.Fl =
|
|
1832
|
+
set(t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x) {
|
|
1833
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = u | 0, this.El = h | 0, this.Fh = l | 0, this.Fl = f | 0, this.Gh = g | 0, this.Gl = b | 0, this.Hh = w | 0, this.Hl = x | 0;
|
|
1790
1834
|
}
|
|
1791
1835
|
process(t, n) {
|
|
1792
|
-
for (let
|
|
1793
|
-
|
|
1794
|
-
for (let
|
|
1795
|
-
const P =
|
|
1796
|
-
|
|
1836
|
+
for (let p = 0; p < 16; p++, n += 4)
|
|
1837
|
+
_[p] = t.getUint32(n), W[p] = t.getUint32(n += 4);
|
|
1838
|
+
for (let p = 16; p < 80; p++) {
|
|
1839
|
+
const P = _[p - 15] | 0, v = W[p - 15] | 0, T = D(P, v, 1) ^ D(P, v, 8) ^ Ft(P, v, 7), E = M(P, v, 1) ^ M(P, v, 8) ^ Ot(P, v, 7), H = _[p - 2] | 0, I = W[p - 2] | 0, F = D(H, I, 19) ^ Q(H, I, 61) ^ Ft(H, I, 6), K = M(H, I, 19) ^ tt(H, I, 61) ^ Ot(H, I, 6), O = hn(E, K, W[p - 7], W[p - 16]), at = fn(O, T, F, _[p - 7], _[p - 16]);
|
|
1840
|
+
_[p] = at | 0, W[p] = O | 0;
|
|
1797
1841
|
}
|
|
1798
|
-
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El:
|
|
1799
|
-
for (let
|
|
1800
|
-
const P =
|
|
1801
|
-
y = w | 0, m = x | 0, w = g | 0, x =
|
|
1802
|
-
const Pt =
|
|
1803
|
-
s =
|
|
1842
|
+
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El: f, Fh: g, Fl: b, Gh: w, Gl: x, Hh: y, Hl: m } = this;
|
|
1843
|
+
for (let p = 0; p < 80; p++) {
|
|
1844
|
+
const P = D(l, f, 14) ^ D(l, f, 18) ^ Q(l, f, 41), v = M(l, f, 14) ^ M(l, f, 18) ^ tt(l, f, 41), T = l & g ^ ~l & w, E = f & b ^ ~f & x, H = dn(m, v, E, wn[p], W[p]), I = pn(H, y, P, T, yn[p], _[p]), F = H | 0, K = D(s, r, 28) ^ Q(s, r, 34) ^ Q(s, r, 39), O = M(s, r, 28) ^ tt(s, r, 34) ^ tt(s, r, 39), at = s & o ^ s & a ^ o & a, ae = r & i ^ r & c ^ i & c;
|
|
1845
|
+
y = w | 0, m = x | 0, w = g | 0, x = b | 0, g = l | 0, b = f | 0, { h: l, l: f } = U(u | 0, h | 0, I | 0, F | 0), u = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
|
|
1846
|
+
const Pt = un(F, O, ae);
|
|
1847
|
+
s = ln(Pt, I, K, at), r = Pt | 0;
|
|
1804
1848
|
}
|
|
1805
|
-
({ h: s, l: r } =
|
|
1849
|
+
({ h: s, l: r } = U(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = U(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = U(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: u, l: h } = U(this.Dh | 0, this.Dl | 0, u | 0, h | 0), { h: l, l: f } = U(this.Eh | 0, this.El | 0, l | 0, f | 0), { h: g, l: b } = U(this.Fh | 0, this.Fl | 0, g | 0, b | 0), { h: w, l: x } = U(this.Gh | 0, this.Gl | 0, w | 0, x | 0), { h: y, l: m } = U(this.Hh | 0, this.Hl | 0, y | 0, m | 0), this.set(s, r, o, i, a, c, u, h, l, f, g, b, w, x, y, m);
|
|
1806
1850
|
}
|
|
1807
1851
|
roundClean() {
|
|
1808
|
-
A(
|
|
1852
|
+
A(_, W);
|
|
1809
1853
|
}
|
|
1810
1854
|
destroy() {
|
|
1811
1855
|
A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1812
1856
|
}
|
|
1813
1857
|
}
|
|
1814
|
-
class
|
|
1858
|
+
class Pn extends mn {
|
|
1815
1859
|
constructor() {
|
|
1816
1860
|
super(64);
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
const
|
|
1836
|
-
() => new
|
|
1861
|
+
d(this, "Ah", k[0] | 0);
|
|
1862
|
+
d(this, "Al", k[1] | 0);
|
|
1863
|
+
d(this, "Bh", k[2] | 0);
|
|
1864
|
+
d(this, "Bl", k[3] | 0);
|
|
1865
|
+
d(this, "Ch", k[4] | 0);
|
|
1866
|
+
d(this, "Cl", k[5] | 0);
|
|
1867
|
+
d(this, "Dh", k[6] | 0);
|
|
1868
|
+
d(this, "Dl", k[7] | 0);
|
|
1869
|
+
d(this, "Eh", k[8] | 0);
|
|
1870
|
+
d(this, "El", k[9] | 0);
|
|
1871
|
+
d(this, "Fh", k[10] | 0);
|
|
1872
|
+
d(this, "Fl", k[11] | 0);
|
|
1873
|
+
d(this, "Gh", k[12] | 0);
|
|
1874
|
+
d(this, "Gl", k[13] | 0);
|
|
1875
|
+
d(this, "Hh", k[14] | 0);
|
|
1876
|
+
d(this, "Hl", k[15] | 0);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
const Tn = /* @__PURE__ */ it(
|
|
1880
|
+
() => new xn(),
|
|
1837
1881
|
/* @__PURE__ */ Gt(1)
|
|
1838
|
-
), ee = /* @__PURE__ */
|
|
1839
|
-
() => new
|
|
1882
|
+
), ee = /* @__PURE__ */ it(
|
|
1883
|
+
() => new Pn(),
|
|
1840
1884
|
/* @__PURE__ */ Gt(3)
|
|
1841
|
-
),
|
|
1842
|
-
for (let e = 0, t =
|
|
1885
|
+
), vn = BigInt(0), G = BigInt(1), kn = BigInt(2), Hn = BigInt(7), In = BigInt(256), En = BigInt(113), ne = [], se = [], re = [];
|
|
1886
|
+
for (let e = 0, t = G, n = 1, s = 0; e < 24; e++) {
|
|
1843
1887
|
[n, s] = [s, (2 * n + 3 * s) % 5], ne.push(2 * (5 * s + n)), se.push((e + 1) * (e + 2) / 2 % 64);
|
|
1844
|
-
let r =
|
|
1888
|
+
let r = vn;
|
|
1845
1889
|
for (let o = 0; o < 7; o++)
|
|
1846
|
-
t = (t <<
|
|
1890
|
+
t = (t << G ^ (t >> Hn) * En) % In, t & kn && (r ^= G << (G << BigInt(o)) - G);
|
|
1847
1891
|
re.push(r);
|
|
1848
1892
|
}
|
|
1849
|
-
const oe = Qt(re, !0),
|
|
1850
|
-
function
|
|
1893
|
+
const oe = Qt(re, !0), Sn = oe[0], An = oe[1], Lt = (e, t, n) => n > 32 ? an(e, t, n) : rn(e, t, n), Ct = (e, t, n) => n > 32 ? cn(e, t, n) : on(e, t, n);
|
|
1894
|
+
function Bn(e, t = 24) {
|
|
1851
1895
|
const n = new Uint32Array(10);
|
|
1852
1896
|
for (let s = 24 - t; s < 24; s++) {
|
|
1853
1897
|
for (let i = 0; i < 10; i++)
|
|
1854
1898
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1855
1899
|
for (let i = 0; i < 10; i += 2) {
|
|
1856
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l =
|
|
1900
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Lt(u, h, 1) ^ n[a], f = Ct(u, h, 1) ^ n[a + 1];
|
|
1857
1901
|
for (let g = 0; g < 50; g += 10)
|
|
1858
|
-
e[i + g] ^= l, e[i + g + 1] ^=
|
|
1902
|
+
e[i + g] ^= l, e[i + g + 1] ^= f;
|
|
1859
1903
|
}
|
|
1860
1904
|
let r = e[2], o = e[3];
|
|
1861
1905
|
for (let i = 0; i < 24; i++) {
|
|
1862
|
-
const a = se[i], c =
|
|
1906
|
+
const a = se[i], c = Lt(r, o, a), u = Ct(r, o, a), h = ne[i];
|
|
1863
1907
|
r = e[h], o = e[h + 1], e[h] = c, e[h + 1] = u;
|
|
1864
1908
|
}
|
|
1865
1909
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -1868,36 +1912,36 @@ function Sn(e, t = 24) {
|
|
|
1868
1912
|
for (let a = 0; a < 10; a++)
|
|
1869
1913
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1870
1914
|
}
|
|
1871
|
-
e[0] ^=
|
|
1915
|
+
e[0] ^= Sn[s], e[1] ^= An[s];
|
|
1872
1916
|
}
|
|
1873
1917
|
A(n);
|
|
1874
1918
|
}
|
|
1875
1919
|
class mt {
|
|
1876
1920
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1877
1921
|
constructor(t, n, s, r = !1, o = 24) {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o,
|
|
1922
|
+
d(this, "state");
|
|
1923
|
+
d(this, "pos", 0);
|
|
1924
|
+
d(this, "posOut", 0);
|
|
1925
|
+
d(this, "finished", !1);
|
|
1926
|
+
d(this, "state32");
|
|
1927
|
+
d(this, "destroyed", !1);
|
|
1928
|
+
d(this, "blockLen");
|
|
1929
|
+
d(this, "suffix");
|
|
1930
|
+
d(this, "outputLen");
|
|
1931
|
+
d(this, "enableXOF", !1);
|
|
1932
|
+
d(this, "rounds");
|
|
1933
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, R(s, "outputLen"), !(0 < t && t < 200))
|
|
1890
1934
|
throw new Error("only keccak-f1600 function is supported");
|
|
1891
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
1935
|
+
this.state = new Uint8Array(200), this.state32 = Ke(this.state);
|
|
1892
1936
|
}
|
|
1893
1937
|
clone() {
|
|
1894
1938
|
return this._cloneInto();
|
|
1895
1939
|
}
|
|
1896
1940
|
keccak() {
|
|
1897
|
-
At(this.state32),
|
|
1941
|
+
At(this.state32), Bn(this.state32, this.rounds), At(this.state32), this.posOut = 0, this.pos = 0;
|
|
1898
1942
|
}
|
|
1899
1943
|
update(t) {
|
|
1900
|
-
|
|
1944
|
+
X(this), V(t);
|
|
1901
1945
|
const { blockLen: n, state: s } = this, r = t.length;
|
|
1902
1946
|
for (let o = 0; o < r; ) {
|
|
1903
1947
|
const i = Math.min(n - this.pos, r - o);
|
|
@@ -1915,7 +1959,7 @@ class mt {
|
|
|
1915
1959
|
t[s] ^= n, (n & 128) !== 0 && s === r - 1 && this.keccak(), t[r - 1] ^= 128, this.keccak();
|
|
1916
1960
|
}
|
|
1917
1961
|
writeInto(t) {
|
|
1918
|
-
|
|
1962
|
+
X(this, !1), V(t), this.finish();
|
|
1919
1963
|
const n = this.state, { blockLen: s } = this;
|
|
1920
1964
|
for (let r = 0, o = t.length; r < o; ) {
|
|
1921
1965
|
this.posOut >= s && this.keccak();
|
|
@@ -1930,7 +1974,7 @@ class mt {
|
|
|
1930
1974
|
return this.writeInto(t);
|
|
1931
1975
|
}
|
|
1932
1976
|
xof(t) {
|
|
1933
|
-
return
|
|
1977
|
+
return R(t), this.xofInto(new Uint8Array(t));
|
|
1934
1978
|
}
|
|
1935
1979
|
digestInto(t) {
|
|
1936
1980
|
if (Xt(t, this), this.finished)
|
|
@@ -1948,50 +1992,50 @@ class mt {
|
|
|
1948
1992
|
return t || (t = new mt(n, s, r, i, o)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = o, t.suffix = s, t.outputLen = r, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
1949
1993
|
}
|
|
1950
1994
|
}
|
|
1951
|
-
const
|
|
1952
|
-
function
|
|
1995
|
+
const $n = (e, t, n, s = {}) => it(() => new mt(t, e, n), s), Un = /* @__PURE__ */ $n(1, 136, 32);
|
|
1996
|
+
function Fn(e, t, n, s) {
|
|
1953
1997
|
Nt(e);
|
|
1954
|
-
const r =
|
|
1955
|
-
if (
|
|
1998
|
+
const r = Ge({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
|
|
1999
|
+
if (R(o, "c"), R(i, "dkLen"), R(a, "asyncTick"), o < 1)
|
|
1956
2000
|
throw new Error("iterations (c) must be >= 1");
|
|
1957
|
-
const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c),
|
|
1958
|
-
return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt:
|
|
2001
|
+
const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c), f = l._cloneInto().update(u);
|
|
2002
|
+
return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt: f };
|
|
1959
2003
|
}
|
|
1960
|
-
function
|
|
2004
|
+
function On(e, t, n, s, r) {
|
|
1961
2005
|
return e.destroy(), t.destroy(), s && s.destroy(), A(r), n;
|
|
1962
2006
|
}
|
|
1963
|
-
function
|
|
1964
|
-
const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } =
|
|
2007
|
+
function Ln(e, t, n, s) {
|
|
2008
|
+
const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = Fn(e, t, n, s);
|
|
1965
2009
|
let u;
|
|
1966
|
-
const h = new Uint8Array(4), l =
|
|
1967
|
-
for (let g = 1,
|
|
1968
|
-
const w = i.subarray(
|
|
1969
|
-
l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(
|
|
2010
|
+
const h = new Uint8Array(4), l = rt(h), f = new Uint8Array(a.outputLen);
|
|
2011
|
+
for (let g = 1, b = 0; b < o; g++, b += a.outputLen) {
|
|
2012
|
+
const w = i.subarray(b, b + a.outputLen);
|
|
2013
|
+
l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(f), w.set(f.subarray(0, w.length));
|
|
1970
2014
|
for (let x = 1; x < r; x++) {
|
|
1971
|
-
a._cloneInto(u).update(
|
|
2015
|
+
a._cloneInto(u).update(f).digestInto(f);
|
|
1972
2016
|
for (let y = 0; y < w.length; y++)
|
|
1973
|
-
w[y] ^=
|
|
2017
|
+
w[y] ^= f[y];
|
|
1974
2018
|
}
|
|
1975
2019
|
}
|
|
1976
|
-
return
|
|
2020
|
+
return On(a, c, i, u, f);
|
|
1977
2021
|
}
|
|
1978
2022
|
function ie(e) {
|
|
1979
2023
|
if (typeof e != "string")
|
|
1980
2024
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
1981
2025
|
return e.normalize("NFKD");
|
|
1982
2026
|
}
|
|
1983
|
-
function
|
|
2027
|
+
function Cn(e) {
|
|
1984
2028
|
const t = ie(e), n = t.split(" ");
|
|
1985
2029
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
1986
2030
|
throw new Error("Invalid mnemonic");
|
|
1987
2031
|
return { nfkd: t, words: n };
|
|
1988
2032
|
}
|
|
1989
|
-
const
|
|
1990
|
-
function
|
|
1991
|
-
return
|
|
2033
|
+
const _n = (e) => ie("mnemonic" + e);
|
|
2034
|
+
function Wn(e, t = "") {
|
|
2035
|
+
return Ln(ee, Cn(e).nfkd, _n(t), { c: 2048, dkLen: 64 });
|
|
1992
2036
|
}
|
|
1993
|
-
const
|
|
1994
|
-
function
|
|
2037
|
+
const Rn = 508, _t = 16, et = 32, nt = 64, Wt = 5, Vn = 4;
|
|
2038
|
+
function j(...e) {
|
|
1995
2039
|
const t = e.reduce((r, o) => r + o.length, 0), n = new Uint8Array(t);
|
|
1996
2040
|
let s = 0;
|
|
1997
2041
|
for (const r of e)
|
|
@@ -2002,58 +2046,58 @@ function lt(e) {
|
|
|
2002
2046
|
return new TextEncoder().encode(e);
|
|
2003
2047
|
}
|
|
2004
2048
|
function ht(e) {
|
|
2005
|
-
const t = new Uint8Array(
|
|
2006
|
-
return new DataView(t.buffer).setUint32(0, e.length, !1),
|
|
2049
|
+
const t = new Uint8Array(Vn);
|
|
2050
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), j(t, e);
|
|
2007
2051
|
}
|
|
2008
2052
|
function ft(e, t) {
|
|
2009
2053
|
return yt(ee, e, t);
|
|
2010
2054
|
}
|
|
2011
2055
|
function Rt(e) {
|
|
2012
|
-
return
|
|
2056
|
+
return nn(Tn(e));
|
|
2013
2057
|
}
|
|
2014
2058
|
const gt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2015
|
-
function
|
|
2016
|
-
const t =
|
|
2059
|
+
function Kn(e) {
|
|
2060
|
+
const t = Wn(e), n = new Uint8Array(t);
|
|
2017
2061
|
return t.fill(0), n;
|
|
2018
2062
|
}
|
|
2019
|
-
async function
|
|
2020
|
-
if (e.length !==
|
|
2063
|
+
async function Dn(e, t, n, s) {
|
|
2064
|
+
if (e.length !== nt)
|
|
2021
2065
|
throw new Error(
|
|
2022
|
-
`WOTS seed must be ${
|
|
2066
|
+
`WOTS seed must be ${nt} bytes, got ${e.length}`
|
|
2023
2067
|
);
|
|
2024
|
-
t =
|
|
2025
|
-
const r = e.slice(
|
|
2068
|
+
t = $(t), n = $(n);
|
|
2069
|
+
const r = e.slice(et, nt), o = e.slice(0, et), i = [r, o];
|
|
2026
2070
|
try {
|
|
2027
|
-
const a =
|
|
2071
|
+
const a = j(
|
|
2028
2072
|
ht(lt(t)),
|
|
2029
2073
|
ht(lt(n)),
|
|
2030
2074
|
ht(lt(s))
|
|
2031
|
-
), c =
|
|
2075
|
+
), c = j(o, a);
|
|
2032
2076
|
i.push(c);
|
|
2033
2077
|
const u = ft(r, c);
|
|
2034
2078
|
i.push(u);
|
|
2035
|
-
const h = u.slice(0,
|
|
2079
|
+
const h = u.slice(0, et), l = u.slice(et, nt);
|
|
2036
2080
|
i.push(h, l);
|
|
2037
|
-
const
|
|
2081
|
+
const f = [], g = [], b = [], w = [];
|
|
2038
2082
|
let x = !1;
|
|
2039
2083
|
try {
|
|
2040
|
-
for (let y = 0; y <
|
|
2084
|
+
for (let y = 0; y < Rn; y++) {
|
|
2041
2085
|
const m = new Uint8Array(Wt);
|
|
2042
2086
|
m[0] = 0, new DataView(m.buffer).setUint32(1, y, !1);
|
|
2043
|
-
const
|
|
2044
|
-
|
|
2045
|
-
const P =
|
|
2087
|
+
const p = new Uint8Array(Wt);
|
|
2088
|
+
p[0] = 1, new DataView(p.buffer).setUint32(1, y, !1);
|
|
2089
|
+
const P = j(h, m), v = j(h, p), T = ft(l, P), E = ft(l, v);
|
|
2046
2090
|
try {
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2091
|
+
const H = T.slice(0, _t), I = E.slice(0, _t);
|
|
2092
|
+
f.push(H), g.push(I), b.push(Rt(H)), w.push(Rt(I));
|
|
2049
2093
|
} finally {
|
|
2050
|
-
P.fill(0),
|
|
2094
|
+
P.fill(0), v.fill(0), T.fill(0), E.fill(0);
|
|
2051
2095
|
}
|
|
2052
2096
|
}
|
|
2053
|
-
return x = !0, { falsePreimages:
|
|
2097
|
+
return x = !0, { falsePreimages: f, truePreimages: g, falseHashes: b, trueHashes: w };
|
|
2054
2098
|
} finally {
|
|
2055
2099
|
if (!x) {
|
|
2056
|
-
for (const y of
|
|
2100
|
+
for (const y of f) y.fill(0);
|
|
2057
2101
|
for (const y of g) y.fill(0);
|
|
2058
2102
|
}
|
|
2059
2103
|
}
|
|
@@ -2062,13 +2106,13 @@ async function Vn(e, t, n, s) {
|
|
|
2062
2106
|
a.fill(0);
|
|
2063
2107
|
}
|
|
2064
2108
|
}
|
|
2065
|
-
function
|
|
2109
|
+
function us(e) {
|
|
2066
2110
|
return {
|
|
2067
2111
|
false_list: e.falseHashes.map(gt),
|
|
2068
2112
|
true_list: e.trueHashes.map(gt)
|
|
2069
2113
|
};
|
|
2070
2114
|
}
|
|
2071
|
-
function
|
|
2115
|
+
function Mn(e) {
|
|
2072
2116
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2073
2117
|
throw new Error(
|
|
2074
2118
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -2079,20 +2123,20 @@ function Dn(e) {
|
|
|
2079
2123
|
s.set(i, r), r += t;
|
|
2080
2124
|
for (const i of e.trueHashes)
|
|
2081
2125
|
s.set(i, r), r += t;
|
|
2082
|
-
const o =
|
|
2126
|
+
const o = Un(s);
|
|
2083
2127
|
return `0x${gt(o)}`;
|
|
2084
2128
|
}
|
|
2085
|
-
async function
|
|
2086
|
-
const r =
|
|
2129
|
+
async function ls(e, t, n, s) {
|
|
2130
|
+
const r = Kn(e);
|
|
2087
2131
|
try {
|
|
2088
|
-
const o = await
|
|
2132
|
+
const o = await Dn(
|
|
2089
2133
|
r,
|
|
2090
2134
|
t,
|
|
2091
2135
|
n,
|
|
2092
2136
|
s
|
|
2093
2137
|
);
|
|
2094
2138
|
try {
|
|
2095
|
-
return
|
|
2139
|
+
return Mn(o);
|
|
2096
2140
|
} finally {
|
|
2097
2141
|
for (const i of o.falsePreimages) i.fill(0);
|
|
2098
2142
|
for (const i of o.truePreimages) i.fill(0);
|
|
@@ -2101,43 +2145,43 @@ async function cs(e, t, n, s) {
|
|
|
2101
2145
|
r.fill(0);
|
|
2102
2146
|
}
|
|
2103
2147
|
}
|
|
2104
|
-
function
|
|
2148
|
+
function hs(e) {
|
|
2105
2149
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2106
2150
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2107
2151
|
}
|
|
2108
2152
|
export {
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2153
|
+
Mn as A,
|
|
2154
|
+
st as B,
|
|
2155
|
+
N as C,
|
|
2156
|
+
ls as D,
|
|
2157
|
+
hs as E,
|
|
2158
|
+
Oe as M,
|
|
2159
|
+
as as P,
|
|
2160
|
+
Zn as a,
|
|
2161
|
+
Yn as b,
|
|
2118
2162
|
St as c,
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2163
|
+
Qn as d,
|
|
2164
|
+
Be as e,
|
|
2165
|
+
$e as f,
|
|
2166
|
+
Jn as g,
|
|
2123
2167
|
bt as h,
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2168
|
+
cs as i,
|
|
2169
|
+
ss as j,
|
|
2170
|
+
es as k,
|
|
2171
|
+
ns as l,
|
|
2172
|
+
rs as m,
|
|
2173
|
+
ts as n,
|
|
2174
|
+
Ce as o,
|
|
2175
|
+
_e as p,
|
|
2176
|
+
Le as q,
|
|
2133
2177
|
ct as r,
|
|
2134
|
-
|
|
2178
|
+
Ae as s,
|
|
2135
2179
|
xt as t,
|
|
2136
|
-
|
|
2137
|
-
|
|
2180
|
+
os as u,
|
|
2181
|
+
is as v,
|
|
2138
2182
|
ut as w,
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2183
|
+
Kn as x,
|
|
2184
|
+
Dn as y,
|
|
2185
|
+
us as z
|
|
2142
2186
|
};
|
|
2143
|
-
//# sourceMappingURL=errors-
|
|
2187
|
+
//# sourceMappingURL=errors-D19BQSaj.js.map
|