opnet 1.8.3 → 1.8.4
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/CHANGELOG.md +20 -0
- package/browser/_version.d.ts +1 -1
- package/browser/contracts/CallResult.d.ts +1 -0
- package/browser/index.js +9929 -10210
- package/browser/noble-curves.js +3049 -2135
- package/browser/noble-hashes.js +1812 -2504
- package/browser/protobuf.js +2695 -2103
- package/browser/rolldown-runtime.js +35 -0
- package/browser/vendors.js +36998 -45617
- package/browser/worker_threads-browser.js +7 -9
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/contracts/CallResult.d.ts +1 -0
- package/build/contracts/CallResult.js +5 -11
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -11
- package/src/_version.ts +1 -1
- package/src/contracts/CallResult.ts +21 -14
package/browser/noble-hashes.js
CHANGED
|
@@ -1,2577 +1,1885 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function abytes(value, length, title = "") {
|
|
14
|
-
const bytes = isBytes(value);
|
|
15
|
-
const len = value?.length;
|
|
16
|
-
const needsLen = length !== void 0;
|
|
17
|
-
if (!bytes || needsLen && len !== length) {
|
|
18
|
-
const prefix = title && `"${title}" `;
|
|
19
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
20
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
21
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
22
|
-
}
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
function ahash(h) {
|
|
26
|
-
if (typeof h !== "function" || typeof h.create !== "function")
|
|
27
|
-
throw new Error("Hash must wrapped by utils.createHasher");
|
|
28
|
-
anumber(h.outputLen);
|
|
29
|
-
anumber(h.blockLen);
|
|
30
|
-
}
|
|
31
|
-
function aexists(instance, checkFinished = true) {
|
|
32
|
-
if (instance.destroyed)
|
|
33
|
-
throw new Error("Hash instance has been destroyed");
|
|
34
|
-
if (checkFinished && instance.finished)
|
|
35
|
-
throw new Error("Hash#digest() has already been called");
|
|
36
|
-
}
|
|
37
|
-
function aoutput(out, instance) {
|
|
38
|
-
abytes(out, void 0, "digestInto() output");
|
|
39
|
-
const min = instance.outputLen;
|
|
40
|
-
if (out.length < min) {
|
|
41
|
-
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function u32(arr) {
|
|
45
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
46
|
-
}
|
|
47
|
-
function clean(...arrays) {
|
|
48
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
49
|
-
arrays[i].fill(0);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function createView(arr) {
|
|
53
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
54
|
-
}
|
|
55
|
-
function rotr(word, shift) {
|
|
56
|
-
return word << 32 - shift | word >>> shift;
|
|
57
|
-
}
|
|
58
|
-
function rotl(word, shift) {
|
|
59
|
-
return word << shift | word >>> 32 - shift >>> 0;
|
|
60
|
-
}
|
|
61
|
-
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
62
|
-
function byteSwap(word) {
|
|
63
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
64
|
-
}
|
|
65
|
-
function byteSwap32(arr) {
|
|
66
|
-
for (let i = 0; i < arr.length; i++) {
|
|
67
|
-
arr[i] = byteSwap(arr[i]);
|
|
68
|
-
}
|
|
69
|
-
return arr;
|
|
70
|
-
}
|
|
71
|
-
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
72
|
-
const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
75
|
-
))();
|
|
76
|
-
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
77
|
-
function bytesToHex(bytes) {
|
|
78
|
-
abytes(bytes);
|
|
79
|
-
if (hasHexBuiltin)
|
|
80
|
-
return bytes.toHex();
|
|
81
|
-
let hex = "";
|
|
82
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
83
|
-
hex += hexes[bytes[i]];
|
|
84
|
-
}
|
|
85
|
-
return hex;
|
|
86
|
-
}
|
|
87
|
-
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
88
|
-
function asciiToBase16(ch) {
|
|
89
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
90
|
-
return ch - asciis._0;
|
|
91
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
92
|
-
return ch - (asciis.A - 10);
|
|
93
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
94
|
-
return ch - (asciis.a - 10);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
function hexToBytes(hex) {
|
|
98
|
-
if (typeof hex !== "string")
|
|
99
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
100
|
-
if (hasHexBuiltin)
|
|
101
|
-
return Uint8Array.fromHex(hex);
|
|
102
|
-
const hl = hex.length;
|
|
103
|
-
const al = hl / 2;
|
|
104
|
-
if (hl % 2)
|
|
105
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
106
|
-
const array = new Uint8Array(al);
|
|
107
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
108
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
109
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
110
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
111
|
-
const char = hex[hi] + hex[hi + 1];
|
|
112
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
113
|
-
}
|
|
114
|
-
array[ai] = n1 * 16 + n2;
|
|
115
|
-
}
|
|
116
|
-
return array;
|
|
117
|
-
}
|
|
118
|
-
function concatBytes(...arrays) {
|
|
119
|
-
let sum = 0;
|
|
120
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
121
|
-
const a = arrays[i];
|
|
122
|
-
abytes(a);
|
|
123
|
-
sum += a.length;
|
|
124
|
-
}
|
|
125
|
-
const res = new Uint8Array(sum);
|
|
126
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
127
|
-
const a = arrays[i];
|
|
128
|
-
res.set(a, pad);
|
|
129
|
-
pad += a.length;
|
|
130
|
-
}
|
|
131
|
-
return res;
|
|
132
|
-
}
|
|
133
|
-
function createHasher(hashCons, info = {}) {
|
|
134
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
135
|
-
const tmp = hashCons(void 0);
|
|
136
|
-
hashC.outputLen = tmp.outputLen;
|
|
137
|
-
hashC.blockLen = tmp.blockLen;
|
|
138
|
-
hashC.create = (opts) => hashCons(opts);
|
|
139
|
-
Object.assign(hashC, info);
|
|
140
|
-
return Object.freeze(hashC);
|
|
141
|
-
}
|
|
142
|
-
function randomBytes(bytesLength = 32) {
|
|
143
|
-
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
144
|
-
if (typeof cr?.getRandomValues !== "function")
|
|
145
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
146
|
-
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
147
|
-
}
|
|
148
|
-
const oidNist = (suffix) => ({
|
|
149
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
1
|
+
import { n as __esmMin, r as __exportAll, t as __commonJSMin } from "./rolldown-runtime.js";
|
|
2
|
+
import { C as Maj, D as anumber, E as aexists, I as rotl, L as swap32IfBE, M as init_utils, O as aoutput, P as oidNist, R as u32, S as HashMD, T as abytes, _ as rotlBL, b as split, g as rotlBH, h as init__u64, j as createHasher, k as clean, v as rotlSH, w as init__md, x as Chi, y as rotlSL } from "./noble-curves.js";
|
|
3
|
+
//#region node_modules/@noble/hashes/legacy.js
|
|
4
|
+
var legacy_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
_MD5: () => _MD5,
|
|
6
|
+
_RIPEMD160: () => _RIPEMD160,
|
|
7
|
+
_SHA1: () => _SHA1,
|
|
8
|
+
md5: () => md5,
|
|
9
|
+
ripemd160: () => ripemd160,
|
|
10
|
+
sha1: () => sha1
|
|
150
11
|
});
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Internal Merkle-Damgard hash utils.
|
|
154
|
-
* @module
|
|
155
|
-
*/
|
|
156
|
-
/** Choice: a ? b : c */
|
|
157
|
-
function Chi(a, b, c) {
|
|
158
|
-
return (a & b) ^ (~a & c);
|
|
159
|
-
}
|
|
160
|
-
/** Majority function, true if any two inputs is true. */
|
|
161
|
-
function Maj(a, b, c) {
|
|
162
|
-
return (a & b) ^ (a & c) ^ (b & c);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Merkle-Damgard hash construction base class.
|
|
166
|
-
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
167
|
-
*/
|
|
168
|
-
class HashMD {
|
|
169
|
-
blockLen;
|
|
170
|
-
outputLen;
|
|
171
|
-
padOffset;
|
|
172
|
-
isLE;
|
|
173
|
-
// For partial updates less than block size
|
|
174
|
-
buffer;
|
|
175
|
-
view;
|
|
176
|
-
finished = false;
|
|
177
|
-
length = 0;
|
|
178
|
-
pos = 0;
|
|
179
|
-
destroyed = false;
|
|
180
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
181
|
-
this.blockLen = blockLen;
|
|
182
|
-
this.outputLen = outputLen;
|
|
183
|
-
this.padOffset = padOffset;
|
|
184
|
-
this.isLE = isLE;
|
|
185
|
-
this.buffer = new Uint8Array(blockLen);
|
|
186
|
-
this.view = createView(this.buffer);
|
|
187
|
-
}
|
|
188
|
-
update(data) {
|
|
189
|
-
aexists(this);
|
|
190
|
-
abytes(data);
|
|
191
|
-
const { view, buffer, blockLen } = this;
|
|
192
|
-
const len = data.length;
|
|
193
|
-
for (let pos = 0; pos < len;) {
|
|
194
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
195
|
-
// Fast path: we have at least one block in input, cast it to view and process
|
|
196
|
-
if (take === blockLen) {
|
|
197
|
-
const dataView = createView(data);
|
|
198
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
199
|
-
this.process(dataView, pos);
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
203
|
-
this.pos += take;
|
|
204
|
-
pos += take;
|
|
205
|
-
if (this.pos === blockLen) {
|
|
206
|
-
this.process(view, 0);
|
|
207
|
-
this.pos = 0;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
this.length += data.length;
|
|
211
|
-
this.roundClean();
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
digestInto(out) {
|
|
215
|
-
aexists(this);
|
|
216
|
-
aoutput(out, this);
|
|
217
|
-
this.finished = true;
|
|
218
|
-
// Padding
|
|
219
|
-
// We can avoid allocation of buffer for padding completely if it
|
|
220
|
-
// was previously not allocated here. But it won't change performance.
|
|
221
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
222
|
-
let { pos } = this;
|
|
223
|
-
// append the bit '1' to the message
|
|
224
|
-
buffer[pos++] = 0b10000000;
|
|
225
|
-
clean(this.buffer.subarray(pos));
|
|
226
|
-
// we have less than padOffset left in buffer, so we cannot put length in
|
|
227
|
-
// current block, need process it and pad again
|
|
228
|
-
if (this.padOffset > blockLen - pos) {
|
|
229
|
-
this.process(view, 0);
|
|
230
|
-
pos = 0;
|
|
231
|
-
}
|
|
232
|
-
// Pad until full block byte with zeros
|
|
233
|
-
for (let i = pos; i < blockLen; i++)
|
|
234
|
-
buffer[i] = 0;
|
|
235
|
-
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
236
|
-
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
237
|
-
// So we just write lowest 64 bits of that value.
|
|
238
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
239
|
-
this.process(view, 0);
|
|
240
|
-
const oview = createView(out);
|
|
241
|
-
const len = this.outputLen;
|
|
242
|
-
// NOTE: we do division by 4 later, which must be fused in single op with modulo by JIT
|
|
243
|
-
if (len % 4)
|
|
244
|
-
throw new Error('_sha2: outputLen must be aligned to 32bit');
|
|
245
|
-
const outLen = len / 4;
|
|
246
|
-
const state = this.get();
|
|
247
|
-
if (outLen > state.length)
|
|
248
|
-
throw new Error('_sha2: outputLen bigger than state');
|
|
249
|
-
for (let i = 0; i < outLen; i++)
|
|
250
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
251
|
-
}
|
|
252
|
-
digest() {
|
|
253
|
-
const { buffer, outputLen } = this;
|
|
254
|
-
this.digestInto(buffer);
|
|
255
|
-
const res = buffer.slice(0, outputLen);
|
|
256
|
-
this.destroy();
|
|
257
|
-
return res;
|
|
258
|
-
}
|
|
259
|
-
_cloneInto(to) {
|
|
260
|
-
to ||= new this.constructor();
|
|
261
|
-
to.set(...this.get());
|
|
262
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
263
|
-
to.destroyed = destroyed;
|
|
264
|
-
to.finished = finished;
|
|
265
|
-
to.length = length;
|
|
266
|
-
to.pos = pos;
|
|
267
|
-
if (length % blockLen)
|
|
268
|
-
to.buffer.set(buffer);
|
|
269
|
-
return to;
|
|
270
|
-
}
|
|
271
|
-
clone() {
|
|
272
|
-
return this._cloneInto();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
277
|
-
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
278
|
-
*/
|
|
279
|
-
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
280
|
-
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
281
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
282
|
-
]);
|
|
283
|
-
/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */
|
|
284
|
-
const SHA224_IV = /* @__PURE__ */ Uint32Array.from([
|
|
285
|
-
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
|
|
286
|
-
]);
|
|
287
|
-
/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */
|
|
288
|
-
const SHA384_IV = /* @__PURE__ */ Uint32Array.from([
|
|
289
|
-
0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,
|
|
290
|
-
0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,
|
|
291
|
-
]);
|
|
292
|
-
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
|
293
|
-
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
294
|
-
0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
|
|
295
|
-
0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
|
|
296
|
-
]);
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
300
|
-
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
301
|
-
* @module
|
|
302
|
-
*/
|
|
303
|
-
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
304
|
-
const _32n = /* @__PURE__ */ BigInt(32);
|
|
305
|
-
function fromBig(n, le = false) {
|
|
306
|
-
if (le)
|
|
307
|
-
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
308
|
-
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
309
|
-
}
|
|
310
|
-
function split(lst, le = false) {
|
|
311
|
-
const len = lst.length;
|
|
312
|
-
let Ah = new Uint32Array(len);
|
|
313
|
-
let Al = new Uint32Array(len);
|
|
314
|
-
for (let i = 0; i < len; i++) {
|
|
315
|
-
const { h, l } = fromBig(lst[i], le);
|
|
316
|
-
[Ah[i], Al[i]] = [h, l];
|
|
317
|
-
}
|
|
318
|
-
return [Ah, Al];
|
|
319
|
-
}
|
|
320
|
-
// for Shift in [0, 32)
|
|
321
|
-
const shrSH = (h, _l, s) => h >>> s;
|
|
322
|
-
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
323
|
-
// Right rotate for Shift in [1, 32)
|
|
324
|
-
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
|
|
325
|
-
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
326
|
-
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
327
|
-
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
328
|
-
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
329
|
-
// Left rotate for Shift in [1, 32)
|
|
330
|
-
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
331
|
-
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
332
|
-
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
333
|
-
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
334
|
-
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
335
|
-
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
336
|
-
// simple take carry out of low bit sum by shift, we need to use division.
|
|
337
|
-
function add(Ah, Al, Bh, Bl) {
|
|
338
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
339
|
-
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
340
|
-
}
|
|
341
|
-
// Addition with more than 2 elements
|
|
342
|
-
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
343
|
-
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
344
|
-
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
345
|
-
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
|
|
346
|
-
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
347
|
-
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
351
|
-
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
352
|
-
* Check out [RFC 4634](https://www.rfc-editor.org/rfc/rfc4634) and
|
|
353
|
-
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
354
|
-
* @module
|
|
355
|
-
*/
|
|
356
|
-
/**
|
|
357
|
-
* Round constants:
|
|
358
|
-
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
|
|
359
|
-
*/
|
|
360
|
-
// prettier-ignore
|
|
361
|
-
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
362
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
363
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
364
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
365
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
366
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
367
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
368
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
369
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
370
|
-
]);
|
|
371
|
-
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
372
|
-
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
373
|
-
/** Internal 32-byte base SHA2 hash class. */
|
|
374
|
-
class SHA2_32B extends HashMD {
|
|
375
|
-
constructor(outputLen) {
|
|
376
|
-
super(64, outputLen, 8, false);
|
|
377
|
-
}
|
|
378
|
-
get() {
|
|
379
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
380
|
-
return [A, B, C, D, E, F, G, H];
|
|
381
|
-
}
|
|
382
|
-
// prettier-ignore
|
|
383
|
-
set(A, B, C, D, E, F, G, H) {
|
|
384
|
-
this.A = A | 0;
|
|
385
|
-
this.B = B | 0;
|
|
386
|
-
this.C = C | 0;
|
|
387
|
-
this.D = D | 0;
|
|
388
|
-
this.E = E | 0;
|
|
389
|
-
this.F = F | 0;
|
|
390
|
-
this.G = G | 0;
|
|
391
|
-
this.H = H | 0;
|
|
392
|
-
}
|
|
393
|
-
process(view, offset) {
|
|
394
|
-
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
395
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
396
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
397
|
-
for (let i = 16; i < 64; i++) {
|
|
398
|
-
const W15 = SHA256_W[i - 15];
|
|
399
|
-
const W2 = SHA256_W[i - 2];
|
|
400
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
|
401
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
|
402
|
-
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
403
|
-
}
|
|
404
|
-
// Compression function main loop, 64 rounds
|
|
405
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
406
|
-
for (let i = 0; i < 64; i++) {
|
|
407
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
408
|
-
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
409
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
410
|
-
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
411
|
-
H = G;
|
|
412
|
-
G = F;
|
|
413
|
-
F = E;
|
|
414
|
-
E = (D + T1) | 0;
|
|
415
|
-
D = C;
|
|
416
|
-
C = B;
|
|
417
|
-
B = A;
|
|
418
|
-
A = (T1 + T2) | 0;
|
|
419
|
-
}
|
|
420
|
-
// Add the compressed chunk to the current hash value
|
|
421
|
-
A = (A + this.A) | 0;
|
|
422
|
-
B = (B + this.B) | 0;
|
|
423
|
-
C = (C + this.C) | 0;
|
|
424
|
-
D = (D + this.D) | 0;
|
|
425
|
-
E = (E + this.E) | 0;
|
|
426
|
-
F = (F + this.F) | 0;
|
|
427
|
-
G = (G + this.G) | 0;
|
|
428
|
-
H = (H + this.H) | 0;
|
|
429
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
430
|
-
}
|
|
431
|
-
roundClean() {
|
|
432
|
-
clean(SHA256_W);
|
|
433
|
-
}
|
|
434
|
-
destroy() {
|
|
435
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
436
|
-
clean(this.buffer);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
/** Internal SHA2-256 hash class. */
|
|
440
|
-
class _SHA256 extends SHA2_32B {
|
|
441
|
-
// We cannot use array here since array allows indexing by variable
|
|
442
|
-
// which means optimizer/compiler cannot use registers.
|
|
443
|
-
A = SHA256_IV[0] | 0;
|
|
444
|
-
B = SHA256_IV[1] | 0;
|
|
445
|
-
C = SHA256_IV[2] | 0;
|
|
446
|
-
D = SHA256_IV[3] | 0;
|
|
447
|
-
E = SHA256_IV[4] | 0;
|
|
448
|
-
F = SHA256_IV[5] | 0;
|
|
449
|
-
G = SHA256_IV[6] | 0;
|
|
450
|
-
H = SHA256_IV[7] | 0;
|
|
451
|
-
constructor() {
|
|
452
|
-
super(32);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
/** Internal SHA2-224 hash class. */
|
|
456
|
-
class _SHA224 extends SHA2_32B {
|
|
457
|
-
A = SHA224_IV[0] | 0;
|
|
458
|
-
B = SHA224_IV[1] | 0;
|
|
459
|
-
C = SHA224_IV[2] | 0;
|
|
460
|
-
D = SHA224_IV[3] | 0;
|
|
461
|
-
E = SHA224_IV[4] | 0;
|
|
462
|
-
F = SHA224_IV[5] | 0;
|
|
463
|
-
G = SHA224_IV[6] | 0;
|
|
464
|
-
H = SHA224_IV[7] | 0;
|
|
465
|
-
constructor() {
|
|
466
|
-
super(28);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
// SHA2-512 is slower than sha256 in js because u64 operations are slow.
|
|
470
|
-
// Round contants
|
|
471
|
-
// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
|
|
472
|
-
// prettier-ignore
|
|
473
|
-
const K512 = /* @__PURE__ */ (() => split([
|
|
474
|
-
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
|
|
475
|
-
'0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
|
|
476
|
-
'0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
|
|
477
|
-
'0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
|
|
478
|
-
'0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
|
|
479
|
-
'0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
|
|
480
|
-
'0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
|
|
481
|
-
'0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
|
|
482
|
-
'0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
|
|
483
|
-
'0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
|
|
484
|
-
'0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
|
|
485
|
-
'0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
|
|
486
|
-
'0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
|
|
487
|
-
'0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
|
|
488
|
-
'0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
|
|
489
|
-
'0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
|
|
490
|
-
'0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
|
|
491
|
-
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
|
|
492
|
-
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
|
|
493
|
-
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
|
|
494
|
-
].map(n => BigInt(n))))();
|
|
495
|
-
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
496
|
-
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
497
|
-
// Reusable temporary buffers
|
|
498
|
-
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
499
|
-
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
500
|
-
/** Internal 64-byte base SHA2 hash class. */
|
|
501
|
-
class SHA2_64B extends HashMD {
|
|
502
|
-
constructor(outputLen) {
|
|
503
|
-
super(128, outputLen, 16, false);
|
|
504
|
-
}
|
|
505
|
-
// prettier-ignore
|
|
506
|
-
get() {
|
|
507
|
-
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
508
|
-
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
509
|
-
}
|
|
510
|
-
// prettier-ignore
|
|
511
|
-
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
512
|
-
this.Ah = Ah | 0;
|
|
513
|
-
this.Al = Al | 0;
|
|
514
|
-
this.Bh = Bh | 0;
|
|
515
|
-
this.Bl = Bl | 0;
|
|
516
|
-
this.Ch = Ch | 0;
|
|
517
|
-
this.Cl = Cl | 0;
|
|
518
|
-
this.Dh = Dh | 0;
|
|
519
|
-
this.Dl = Dl | 0;
|
|
520
|
-
this.Eh = Eh | 0;
|
|
521
|
-
this.El = El | 0;
|
|
522
|
-
this.Fh = Fh | 0;
|
|
523
|
-
this.Fl = Fl | 0;
|
|
524
|
-
this.Gh = Gh | 0;
|
|
525
|
-
this.Gl = Gl | 0;
|
|
526
|
-
this.Hh = Hh | 0;
|
|
527
|
-
this.Hl = Hl | 0;
|
|
528
|
-
}
|
|
529
|
-
process(view, offset) {
|
|
530
|
-
// Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
|
|
531
|
-
for (let i = 0; i < 16; i++, offset += 4) {
|
|
532
|
-
SHA512_W_H[i] = view.getUint32(offset);
|
|
533
|
-
SHA512_W_L[i] = view.getUint32((offset += 4));
|
|
534
|
-
}
|
|
535
|
-
for (let i = 16; i < 80; i++) {
|
|
536
|
-
// s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
|
|
537
|
-
const W15h = SHA512_W_H[i - 15] | 0;
|
|
538
|
-
const W15l = SHA512_W_L[i - 15] | 0;
|
|
539
|
-
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
540
|
-
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
541
|
-
// s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
|
|
542
|
-
const W2h = SHA512_W_H[i - 2] | 0;
|
|
543
|
-
const W2l = SHA512_W_L[i - 2] | 0;
|
|
544
|
-
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
545
|
-
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
546
|
-
// SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
|
|
547
|
-
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
548
|
-
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
549
|
-
SHA512_W_H[i] = SUMh | 0;
|
|
550
|
-
SHA512_W_L[i] = SUMl | 0;
|
|
551
|
-
}
|
|
552
|
-
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
553
|
-
// Compression function main loop, 80 rounds
|
|
554
|
-
for (let i = 0; i < 80; i++) {
|
|
555
|
-
// S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
|
|
556
|
-
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
557
|
-
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
558
|
-
//const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
559
|
-
const CHIh = (Eh & Fh) ^ (~Eh & Gh);
|
|
560
|
-
const CHIl = (El & Fl) ^ (~El & Gl);
|
|
561
|
-
// T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
|
|
562
|
-
// prettier-ignore
|
|
563
|
-
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
564
|
-
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
565
|
-
const T1l = T1ll | 0;
|
|
566
|
-
// S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
|
|
567
|
-
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
568
|
-
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
569
|
-
const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
|
|
570
|
-
const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
|
|
571
|
-
Hh = Gh | 0;
|
|
572
|
-
Hl = Gl | 0;
|
|
573
|
-
Gh = Fh | 0;
|
|
574
|
-
Gl = Fl | 0;
|
|
575
|
-
Fh = Eh | 0;
|
|
576
|
-
Fl = El | 0;
|
|
577
|
-
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
578
|
-
Dh = Ch | 0;
|
|
579
|
-
Dl = Cl | 0;
|
|
580
|
-
Ch = Bh | 0;
|
|
581
|
-
Cl = Bl | 0;
|
|
582
|
-
Bh = Ah | 0;
|
|
583
|
-
Bl = Al | 0;
|
|
584
|
-
const All = add3L(T1l, sigma0l, MAJl);
|
|
585
|
-
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
586
|
-
Al = All | 0;
|
|
587
|
-
}
|
|
588
|
-
// Add the compressed chunk to the current hash value
|
|
589
|
-
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
590
|
-
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
591
|
-
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
592
|
-
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
593
|
-
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
594
|
-
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
595
|
-
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
596
|
-
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
597
|
-
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
598
|
-
}
|
|
599
|
-
roundClean() {
|
|
600
|
-
clean(SHA512_W_H, SHA512_W_L);
|
|
601
|
-
}
|
|
602
|
-
destroy() {
|
|
603
|
-
clean(this.buffer);
|
|
604
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
/** Internal SHA2-512 hash class. */
|
|
608
|
-
class _SHA512 extends SHA2_64B {
|
|
609
|
-
Ah = SHA512_IV[0] | 0;
|
|
610
|
-
Al = SHA512_IV[1] | 0;
|
|
611
|
-
Bh = SHA512_IV[2] | 0;
|
|
612
|
-
Bl = SHA512_IV[3] | 0;
|
|
613
|
-
Ch = SHA512_IV[4] | 0;
|
|
614
|
-
Cl = SHA512_IV[5] | 0;
|
|
615
|
-
Dh = SHA512_IV[6] | 0;
|
|
616
|
-
Dl = SHA512_IV[7] | 0;
|
|
617
|
-
Eh = SHA512_IV[8] | 0;
|
|
618
|
-
El = SHA512_IV[9] | 0;
|
|
619
|
-
Fh = SHA512_IV[10] | 0;
|
|
620
|
-
Fl = SHA512_IV[11] | 0;
|
|
621
|
-
Gh = SHA512_IV[12] | 0;
|
|
622
|
-
Gl = SHA512_IV[13] | 0;
|
|
623
|
-
Hh = SHA512_IV[14] | 0;
|
|
624
|
-
Hl = SHA512_IV[15] | 0;
|
|
625
|
-
constructor() {
|
|
626
|
-
super(64);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
/** Internal SHA2-384 hash class. */
|
|
630
|
-
class _SHA384 extends SHA2_64B {
|
|
631
|
-
Ah = SHA384_IV[0] | 0;
|
|
632
|
-
Al = SHA384_IV[1] | 0;
|
|
633
|
-
Bh = SHA384_IV[2] | 0;
|
|
634
|
-
Bl = SHA384_IV[3] | 0;
|
|
635
|
-
Ch = SHA384_IV[4] | 0;
|
|
636
|
-
Cl = SHA384_IV[5] | 0;
|
|
637
|
-
Dh = SHA384_IV[6] | 0;
|
|
638
|
-
Dl = SHA384_IV[7] | 0;
|
|
639
|
-
Eh = SHA384_IV[8] | 0;
|
|
640
|
-
El = SHA384_IV[9] | 0;
|
|
641
|
-
Fh = SHA384_IV[10] | 0;
|
|
642
|
-
Fl = SHA384_IV[11] | 0;
|
|
643
|
-
Gh = SHA384_IV[12] | 0;
|
|
644
|
-
Gl = SHA384_IV[13] | 0;
|
|
645
|
-
Hh = SHA384_IV[14] | 0;
|
|
646
|
-
Hl = SHA384_IV[15] | 0;
|
|
647
|
-
constructor() {
|
|
648
|
-
super(48);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Truncated SHA512/256 and SHA512/224.
|
|
653
|
-
* SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as "intermediary" IV of SHA512/t.
|
|
654
|
-
* Then t hashes string to produce result IV.
|
|
655
|
-
* See `test/misc/sha2-gen-iv.js`.
|
|
656
|
-
*/
|
|
657
|
-
/** SHA512/224 IV */
|
|
658
|
-
const T224_IV = /* @__PURE__ */ Uint32Array.from([
|
|
659
|
-
0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,
|
|
660
|
-
0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,
|
|
661
|
-
]);
|
|
662
|
-
/** SHA512/256 IV */
|
|
663
|
-
const T256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
664
|
-
0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,
|
|
665
|
-
0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,
|
|
666
|
-
]);
|
|
667
|
-
/** Internal SHA2-512/224 hash class. */
|
|
668
|
-
class _SHA512_224 extends SHA2_64B {
|
|
669
|
-
Ah = T224_IV[0] | 0;
|
|
670
|
-
Al = T224_IV[1] | 0;
|
|
671
|
-
Bh = T224_IV[2] | 0;
|
|
672
|
-
Bl = T224_IV[3] | 0;
|
|
673
|
-
Ch = T224_IV[4] | 0;
|
|
674
|
-
Cl = T224_IV[5] | 0;
|
|
675
|
-
Dh = T224_IV[6] | 0;
|
|
676
|
-
Dl = T224_IV[7] | 0;
|
|
677
|
-
Eh = T224_IV[8] | 0;
|
|
678
|
-
El = T224_IV[9] | 0;
|
|
679
|
-
Fh = T224_IV[10] | 0;
|
|
680
|
-
Fl = T224_IV[11] | 0;
|
|
681
|
-
Gh = T224_IV[12] | 0;
|
|
682
|
-
Gl = T224_IV[13] | 0;
|
|
683
|
-
Hh = T224_IV[14] | 0;
|
|
684
|
-
Hl = T224_IV[15] | 0;
|
|
685
|
-
constructor() {
|
|
686
|
-
super(28);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
/** Internal SHA2-512/256 hash class. */
|
|
690
|
-
class _SHA512_256 extends SHA2_64B {
|
|
691
|
-
Ah = T256_IV[0] | 0;
|
|
692
|
-
Al = T256_IV[1] | 0;
|
|
693
|
-
Bh = T256_IV[2] | 0;
|
|
694
|
-
Bl = T256_IV[3] | 0;
|
|
695
|
-
Ch = T256_IV[4] | 0;
|
|
696
|
-
Cl = T256_IV[5] | 0;
|
|
697
|
-
Dh = T256_IV[6] | 0;
|
|
698
|
-
Dl = T256_IV[7] | 0;
|
|
699
|
-
Eh = T256_IV[8] | 0;
|
|
700
|
-
El = T256_IV[9] | 0;
|
|
701
|
-
Fh = T256_IV[10] | 0;
|
|
702
|
-
Fl = T256_IV[11] | 0;
|
|
703
|
-
Gh = T256_IV[12] | 0;
|
|
704
|
-
Gl = T256_IV[13] | 0;
|
|
705
|
-
Hh = T256_IV[14] | 0;
|
|
706
|
-
Hl = T256_IV[15] | 0;
|
|
707
|
-
constructor() {
|
|
708
|
-
super(32);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* SHA2-256 hash function from RFC 4634. In JS it's the fastest: even faster than Blake3. Some info:
|
|
713
|
-
*
|
|
714
|
-
* - Trying 2^128 hashes would get 50% chance of collision, using birthday attack.
|
|
715
|
-
* - BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
716
|
-
* - Each sha256 hash is executing 2^18 bit operations.
|
|
717
|
-
* - Good 2024 ASICs can do 200Th/sec with 3500 watts of power, corresponding to 2^36 hashes/joule.
|
|
718
|
-
*/
|
|
719
|
-
const sha256$1 = /* @__PURE__ */ createHasher(() => new _SHA256(),
|
|
720
|
-
/* @__PURE__ */ oidNist(0x01));
|
|
721
|
-
/** SHA2-224 hash function from RFC 4634 */
|
|
722
|
-
const sha224 = /* @__PURE__ */ createHasher(() => new _SHA224(),
|
|
723
|
-
/* @__PURE__ */ oidNist(0x04));
|
|
724
|
-
/** SHA2-512 hash function from RFC 4634. */
|
|
725
|
-
const sha512$1 = /* @__PURE__ */ createHasher(() => new _SHA512(),
|
|
726
|
-
/* @__PURE__ */ oidNist(0x03));
|
|
727
|
-
/** SHA2-384 hash function from RFC 4634. */
|
|
728
|
-
const sha384 = /* @__PURE__ */ createHasher(() => new _SHA384(),
|
|
729
|
-
/* @__PURE__ */ oidNist(0x02));
|
|
730
|
-
/**
|
|
731
|
-
* SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
|
|
732
|
-
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
733
|
-
*/
|
|
734
|
-
const sha512_256 = /* @__PURE__ */ createHasher(() => new _SHA512_256(),
|
|
735
|
-
/* @__PURE__ */ oidNist(0x06));
|
|
736
|
-
/**
|
|
737
|
-
* SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
|
|
738
|
-
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
739
|
-
*/
|
|
740
|
-
const sha512_224 = /* @__PURE__ */ createHasher(() => new _SHA512_224(),
|
|
741
|
-
/* @__PURE__ */ oidNist(0x05));
|
|
742
|
-
|
|
743
|
-
const sha2$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
744
|
-
__proto__: null,
|
|
745
|
-
_SHA224,
|
|
746
|
-
_SHA256,
|
|
747
|
-
_SHA384,
|
|
748
|
-
_SHA512,
|
|
749
|
-
_SHA512_224,
|
|
750
|
-
_SHA512_256,
|
|
751
|
-
sha224,
|
|
752
|
-
sha256: sha256$1,
|
|
753
|
-
sha384,
|
|
754
|
-
sha512: sha512$1,
|
|
755
|
-
sha512_224,
|
|
756
|
-
sha512_256
|
|
757
|
-
}, Symbol.toStringTag, { value: 'Module' }));
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
|
|
761
|
-
SHA1 (RFC 3174), MD5 (RFC 1321) and RIPEMD160 (RFC 2286) legacy, weak hash functions.
|
|
762
|
-
Don't use them in a new protocol. What "weak" means:
|
|
763
|
-
|
|
764
|
-
- Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.
|
|
765
|
-
- No practical pre-image attacks (only theoretical, 2^123.4)
|
|
766
|
-
- HMAC seems kinda ok: https://www.rfc-editor.org/rfc/rfc6151
|
|
767
|
-
* @module
|
|
768
|
-
*/
|
|
769
|
-
/** Initial SHA1 state */
|
|
770
|
-
const SHA1_IV = /* @__PURE__ */ Uint32Array.from([
|
|
771
|
-
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
|
|
772
|
-
]);
|
|
773
|
-
// Reusable temporary buffer
|
|
774
|
-
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
|
|
775
|
-
/** Internal SHA1 legacy hash class. */
|
|
776
|
-
class _SHA1 extends HashMD {
|
|
777
|
-
A = SHA1_IV[0] | 0;
|
|
778
|
-
B = SHA1_IV[1] | 0;
|
|
779
|
-
C = SHA1_IV[2] | 0;
|
|
780
|
-
D = SHA1_IV[3] | 0;
|
|
781
|
-
E = SHA1_IV[4] | 0;
|
|
782
|
-
constructor() {
|
|
783
|
-
super(64, 20, 8, false);
|
|
784
|
-
}
|
|
785
|
-
get() {
|
|
786
|
-
const { A, B, C, D, E } = this;
|
|
787
|
-
return [A, B, C, D, E];
|
|
788
|
-
}
|
|
789
|
-
set(A, B, C, D, E) {
|
|
790
|
-
this.A = A | 0;
|
|
791
|
-
this.B = B | 0;
|
|
792
|
-
this.C = C | 0;
|
|
793
|
-
this.D = D | 0;
|
|
794
|
-
this.E = E | 0;
|
|
795
|
-
}
|
|
796
|
-
process(view, offset) {
|
|
797
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
798
|
-
SHA1_W[i] = view.getUint32(offset, false);
|
|
799
|
-
for (let i = 16; i < 80; i++)
|
|
800
|
-
SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);
|
|
801
|
-
// Compression function main loop, 80 rounds
|
|
802
|
-
let { A, B, C, D, E } = this;
|
|
803
|
-
for (let i = 0; i < 80; i++) {
|
|
804
|
-
let F, K;
|
|
805
|
-
if (i < 20) {
|
|
806
|
-
F = Chi(B, C, D);
|
|
807
|
-
K = 0x5a827999;
|
|
808
|
-
}
|
|
809
|
-
else if (i < 40) {
|
|
810
|
-
F = B ^ C ^ D;
|
|
811
|
-
K = 0x6ed9eba1;
|
|
812
|
-
}
|
|
813
|
-
else if (i < 60) {
|
|
814
|
-
F = Maj(B, C, D);
|
|
815
|
-
K = 0x8f1bbcdc;
|
|
816
|
-
}
|
|
817
|
-
else {
|
|
818
|
-
F = B ^ C ^ D;
|
|
819
|
-
K = 0xca62c1d6;
|
|
820
|
-
}
|
|
821
|
-
const T = (rotl(A, 5) + F + E + K + SHA1_W[i]) | 0;
|
|
822
|
-
E = D;
|
|
823
|
-
D = C;
|
|
824
|
-
C = rotl(B, 30);
|
|
825
|
-
B = A;
|
|
826
|
-
A = T;
|
|
827
|
-
}
|
|
828
|
-
// Add the compressed chunk to the current hash value
|
|
829
|
-
A = (A + this.A) | 0;
|
|
830
|
-
B = (B + this.B) | 0;
|
|
831
|
-
C = (C + this.C) | 0;
|
|
832
|
-
D = (D + this.D) | 0;
|
|
833
|
-
E = (E + this.E) | 0;
|
|
834
|
-
this.set(A, B, C, D, E);
|
|
835
|
-
}
|
|
836
|
-
roundClean() {
|
|
837
|
-
clean(SHA1_W);
|
|
838
|
-
}
|
|
839
|
-
destroy() {
|
|
840
|
-
this.set(0, 0, 0, 0, 0);
|
|
841
|
-
clean(this.buffer);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
/** SHA1 (RFC 3174) legacy hash function. It was cryptographically broken. */
|
|
845
|
-
const sha1 = /* @__PURE__ */ createHasher(() => new _SHA1());
|
|
846
|
-
/** Per-round constants */
|
|
847
|
-
const p32 = /* @__PURE__ */ Math.pow(2, 32);
|
|
848
|
-
const K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
|
|
849
|
-
/** md5 initial state: same as sha1, but 4 u32 instead of 5. */
|
|
850
|
-
const MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
|
|
851
|
-
// Reusable temporary buffer
|
|
852
|
-
const MD5_W = /* @__PURE__ */ new Uint32Array(16);
|
|
853
|
-
/** Internal MD5 legacy hash class. */
|
|
854
|
-
class _MD5 extends HashMD {
|
|
855
|
-
A = MD5_IV[0] | 0;
|
|
856
|
-
B = MD5_IV[1] | 0;
|
|
857
|
-
C = MD5_IV[2] | 0;
|
|
858
|
-
D = MD5_IV[3] | 0;
|
|
859
|
-
constructor() {
|
|
860
|
-
super(64, 16, 8, true);
|
|
861
|
-
}
|
|
862
|
-
get() {
|
|
863
|
-
const { A, B, C, D } = this;
|
|
864
|
-
return [A, B, C, D];
|
|
865
|
-
}
|
|
866
|
-
set(A, B, C, D) {
|
|
867
|
-
this.A = A | 0;
|
|
868
|
-
this.B = B | 0;
|
|
869
|
-
this.C = C | 0;
|
|
870
|
-
this.D = D | 0;
|
|
871
|
-
}
|
|
872
|
-
process(view, offset) {
|
|
873
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
874
|
-
MD5_W[i] = view.getUint32(offset, true);
|
|
875
|
-
// Compression function main loop, 64 rounds
|
|
876
|
-
let { A, B, C, D } = this;
|
|
877
|
-
for (let i = 0; i < 64; i++) {
|
|
878
|
-
let F, g, s;
|
|
879
|
-
if (i < 16) {
|
|
880
|
-
F = Chi(B, C, D);
|
|
881
|
-
g = i;
|
|
882
|
-
s = [7, 12, 17, 22];
|
|
883
|
-
}
|
|
884
|
-
else if (i < 32) {
|
|
885
|
-
F = Chi(D, B, C);
|
|
886
|
-
g = (5 * i + 1) % 16;
|
|
887
|
-
s = [5, 9, 14, 20];
|
|
888
|
-
}
|
|
889
|
-
else if (i < 48) {
|
|
890
|
-
F = B ^ C ^ D;
|
|
891
|
-
g = (3 * i + 5) % 16;
|
|
892
|
-
s = [4, 11, 16, 23];
|
|
893
|
-
}
|
|
894
|
-
else {
|
|
895
|
-
F = C ^ (B | ~D);
|
|
896
|
-
g = (7 * i) % 16;
|
|
897
|
-
s = [6, 10, 15, 21];
|
|
898
|
-
}
|
|
899
|
-
F = F + A + K[i] + MD5_W[g];
|
|
900
|
-
A = D;
|
|
901
|
-
D = C;
|
|
902
|
-
C = B;
|
|
903
|
-
B = B + rotl(F, s[i % 4]);
|
|
904
|
-
}
|
|
905
|
-
// Add the compressed chunk to the current hash value
|
|
906
|
-
A = (A + this.A) | 0;
|
|
907
|
-
B = (B + this.B) | 0;
|
|
908
|
-
C = (C + this.C) | 0;
|
|
909
|
-
D = (D + this.D) | 0;
|
|
910
|
-
this.set(A, B, C, D);
|
|
911
|
-
}
|
|
912
|
-
roundClean() {
|
|
913
|
-
clean(MD5_W);
|
|
914
|
-
}
|
|
915
|
-
destroy() {
|
|
916
|
-
this.set(0, 0, 0, 0);
|
|
917
|
-
clean(this.buffer);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* MD5 (RFC 1321) legacy hash function. It was cryptographically broken.
|
|
922
|
-
* MD5 architecture is similar to SHA1, with some differences:
|
|
923
|
-
* - Reduced output length: 16 bytes (128 bit) instead of 20
|
|
924
|
-
* - 64 rounds, instead of 80
|
|
925
|
-
* - Little-endian: could be faster, but will require more code
|
|
926
|
-
* - Non-linear index selection: huge speed-up for unroll
|
|
927
|
-
* - Per round constants: more memory accesses, additional speed-up for unroll
|
|
928
|
-
*/
|
|
929
|
-
const md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
930
|
-
// RIPEMD-160
|
|
931
|
-
const Rho160 = /* @__PURE__ */ Uint8Array.from([
|
|
932
|
-
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
933
|
-
]);
|
|
934
|
-
const Id160 = /* @__PURE__ */ (() => Uint8Array.from(new Array(16).fill(0).map((_, i) => i)))();
|
|
935
|
-
const Pi160 = /* @__PURE__ */ (() => Id160.map((i) => (9 * i + 5) % 16))();
|
|
936
|
-
const idxLR = /* @__PURE__ */ (() => {
|
|
937
|
-
const L = [Id160];
|
|
938
|
-
const R = [Pi160];
|
|
939
|
-
const res = [L, R];
|
|
940
|
-
for (let i = 0; i < 4; i++)
|
|
941
|
-
for (let j of res)
|
|
942
|
-
j.push(j[i].map((k) => Rho160[k]));
|
|
943
|
-
return res;
|
|
944
|
-
})();
|
|
945
|
-
const idxL = /* @__PURE__ */ (() => idxLR[0])();
|
|
946
|
-
const idxR = /* @__PURE__ */ (() => idxLR[1])();
|
|
947
|
-
// const [idxL, idxR] = idxLR;
|
|
948
|
-
const shifts160 = /* @__PURE__ */ [
|
|
949
|
-
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
950
|
-
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
951
|
-
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
952
|
-
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
953
|
-
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5],
|
|
954
|
-
].map((i) => Uint8Array.from(i));
|
|
955
|
-
const shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
956
|
-
const shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
957
|
-
const Kl160 = /* @__PURE__ */ Uint32Array.from([
|
|
958
|
-
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
|
|
959
|
-
]);
|
|
960
|
-
const Kr160 = /* @__PURE__ */ Uint32Array.from([
|
|
961
|
-
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
|
|
962
|
-
]);
|
|
963
|
-
// It's called f() in spec.
|
|
964
12
|
function ripemd_f(group, x, y, z) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
return (x | ~y) ^ z;
|
|
971
|
-
if (group === 3)
|
|
972
|
-
return (x & z) | (y & ~z);
|
|
973
|
-
return x ^ (y | ~z);
|
|
974
|
-
}
|
|
975
|
-
// Reusable temporary buffer
|
|
976
|
-
const BUF_160 = /* @__PURE__ */ new Uint32Array(16);
|
|
977
|
-
class _RIPEMD160 extends HashMD {
|
|
978
|
-
h0 = 0x67452301 | 0;
|
|
979
|
-
h1 = 0xefcdab89 | 0;
|
|
980
|
-
h2 = 0x98badcfe | 0;
|
|
981
|
-
h3 = 0x10325476 | 0;
|
|
982
|
-
h4 = 0xc3d2e1f0 | 0;
|
|
983
|
-
constructor() {
|
|
984
|
-
super(64, 20, 8, true);
|
|
985
|
-
}
|
|
986
|
-
get() {
|
|
987
|
-
const { h0, h1, h2, h3, h4 } = this;
|
|
988
|
-
return [h0, h1, h2, h3, h4];
|
|
989
|
-
}
|
|
990
|
-
set(h0, h1, h2, h3, h4) {
|
|
991
|
-
this.h0 = h0 | 0;
|
|
992
|
-
this.h1 = h1 | 0;
|
|
993
|
-
this.h2 = h2 | 0;
|
|
994
|
-
this.h3 = h3 | 0;
|
|
995
|
-
this.h4 = h4 | 0;
|
|
996
|
-
}
|
|
997
|
-
process(view, offset) {
|
|
998
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
999
|
-
BUF_160[i] = view.getUint32(offset, true);
|
|
1000
|
-
// prettier-ignore
|
|
1001
|
-
let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
|
|
1002
|
-
// Instead of iterating 0 to 80, we split it into 5 groups
|
|
1003
|
-
// And use the groups in constants, functions, etc. Much simpler
|
|
1004
|
-
for (let group = 0; group < 5; group++) {
|
|
1005
|
-
const rGroup = 4 - group;
|
|
1006
|
-
const hbl = Kl160[group], hbr = Kr160[group]; // prettier-ignore
|
|
1007
|
-
const rl = idxL[group], rr = idxR[group]; // prettier-ignore
|
|
1008
|
-
const sl = shiftsL160[group], sr = shiftsR160[group]; // prettier-ignore
|
|
1009
|
-
for (let i = 0; i < 16; i++) {
|
|
1010
|
-
const tl = (rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el) | 0;
|
|
1011
|
-
al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl; // prettier-ignore
|
|
1012
|
-
}
|
|
1013
|
-
// 2 loops are 10% faster
|
|
1014
|
-
for (let i = 0; i < 16; i++) {
|
|
1015
|
-
const tr = (rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er) | 0;
|
|
1016
|
-
ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr; // prettier-ignore
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
// Add the compressed chunk to the current hash value
|
|
1020
|
-
this.set((this.h1 + cl + dr) | 0, (this.h2 + dl + er) | 0, (this.h3 + el + ar) | 0, (this.h4 + al + br) | 0, (this.h0 + bl + cr) | 0);
|
|
1021
|
-
}
|
|
1022
|
-
roundClean() {
|
|
1023
|
-
clean(BUF_160);
|
|
1024
|
-
}
|
|
1025
|
-
destroy() {
|
|
1026
|
-
this.destroyed = true;
|
|
1027
|
-
clean(this.buffer);
|
|
1028
|
-
this.set(0, 0, 0, 0, 0);
|
|
1029
|
-
}
|
|
13
|
+
if (group === 0) return x ^ y ^ z;
|
|
14
|
+
if (group === 1) return x & y | ~x & z;
|
|
15
|
+
if (group === 2) return (x | ~y) ^ z;
|
|
16
|
+
if (group === 3) return x & z | y & ~z;
|
|
17
|
+
return x ^ (y | ~z);
|
|
1030
18
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
*/
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
*
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
19
|
+
var SHA1_IV, SHA1_W, _SHA1, sha1, p32, K, MD5_IV, MD5_W, _MD5, md5, Rho160, Id160, Pi160, idxLR, idxL, idxR, shifts160, shiftsL160, shiftsR160, Kl160, Kr160, BUF_160, _RIPEMD160, ripemd160;
|
|
20
|
+
var init_legacy = __esmMin((() => {
|
|
21
|
+
init__md();
|
|
22
|
+
init_utils();
|
|
23
|
+
SHA1_IV = /* @__PURE__ */ Uint32Array.from([
|
|
24
|
+
1732584193,
|
|
25
|
+
4023233417,
|
|
26
|
+
2562383102,
|
|
27
|
+
271733878,
|
|
28
|
+
3285377520
|
|
29
|
+
]);
|
|
30
|
+
SHA1_W = /* @__PURE__ */ new Uint32Array(80);
|
|
31
|
+
_SHA1 = class extends HashMD {
|
|
32
|
+
A = SHA1_IV[0] | 0;
|
|
33
|
+
B = SHA1_IV[1] | 0;
|
|
34
|
+
C = SHA1_IV[2] | 0;
|
|
35
|
+
D = SHA1_IV[3] | 0;
|
|
36
|
+
E = SHA1_IV[4] | 0;
|
|
37
|
+
constructor() {
|
|
38
|
+
super(64, 20, 8, false);
|
|
39
|
+
}
|
|
40
|
+
get() {
|
|
41
|
+
const { A, B, C, D, E } = this;
|
|
42
|
+
return [
|
|
43
|
+
A,
|
|
44
|
+
B,
|
|
45
|
+
C,
|
|
46
|
+
D,
|
|
47
|
+
E
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
set(A, B, C, D, E) {
|
|
51
|
+
this.A = A | 0;
|
|
52
|
+
this.B = B | 0;
|
|
53
|
+
this.C = C | 0;
|
|
54
|
+
this.D = D | 0;
|
|
55
|
+
this.E = E | 0;
|
|
56
|
+
}
|
|
57
|
+
process(view, offset) {
|
|
58
|
+
for (let i = 0; i < 16; i++, offset += 4) SHA1_W[i] = view.getUint32(offset, false);
|
|
59
|
+
for (let i = 16; i < 80; i++) SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);
|
|
60
|
+
let { A, B, C, D, E } = this;
|
|
61
|
+
for (let i = 0; i < 80; i++) {
|
|
62
|
+
let F, K;
|
|
63
|
+
if (i < 20) {
|
|
64
|
+
F = Chi(B, C, D);
|
|
65
|
+
K = 1518500249;
|
|
66
|
+
} else if (i < 40) {
|
|
67
|
+
F = B ^ C ^ D;
|
|
68
|
+
K = 1859775393;
|
|
69
|
+
} else if (i < 60) {
|
|
70
|
+
F = Maj(B, C, D);
|
|
71
|
+
K = 2400959708;
|
|
72
|
+
} else {
|
|
73
|
+
F = B ^ C ^ D;
|
|
74
|
+
K = 3395469782;
|
|
75
|
+
}
|
|
76
|
+
const T = rotl(A, 5) + F + E + K + SHA1_W[i] | 0;
|
|
77
|
+
E = D;
|
|
78
|
+
D = C;
|
|
79
|
+
C = rotl(B, 30);
|
|
80
|
+
B = A;
|
|
81
|
+
A = T;
|
|
82
|
+
}
|
|
83
|
+
A = A + this.A | 0;
|
|
84
|
+
B = B + this.B | 0;
|
|
85
|
+
C = C + this.C | 0;
|
|
86
|
+
D = D + this.D | 0;
|
|
87
|
+
E = E + this.E | 0;
|
|
88
|
+
this.set(A, B, C, D, E);
|
|
89
|
+
}
|
|
90
|
+
roundClean() {
|
|
91
|
+
clean(SHA1_W);
|
|
92
|
+
}
|
|
93
|
+
destroy() {
|
|
94
|
+
this.set(0, 0, 0, 0, 0);
|
|
95
|
+
clean(this.buffer);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
sha1 = /* @__PURE__ */ createHasher(() => new _SHA1());
|
|
99
|
+
p32 = /* @__PURE__ */ Math.pow(2, 32);
|
|
100
|
+
K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
|
|
101
|
+
MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
|
|
102
|
+
MD5_W = /* @__PURE__ */ new Uint32Array(16);
|
|
103
|
+
_MD5 = class extends HashMD {
|
|
104
|
+
A = MD5_IV[0] | 0;
|
|
105
|
+
B = MD5_IV[1] | 0;
|
|
106
|
+
C = MD5_IV[2] | 0;
|
|
107
|
+
D = MD5_IV[3] | 0;
|
|
108
|
+
constructor() {
|
|
109
|
+
super(64, 16, 8, true);
|
|
110
|
+
}
|
|
111
|
+
get() {
|
|
112
|
+
const { A, B, C, D } = this;
|
|
113
|
+
return [
|
|
114
|
+
A,
|
|
115
|
+
B,
|
|
116
|
+
C,
|
|
117
|
+
D
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
set(A, B, C, D) {
|
|
121
|
+
this.A = A | 0;
|
|
122
|
+
this.B = B | 0;
|
|
123
|
+
this.C = C | 0;
|
|
124
|
+
this.D = D | 0;
|
|
125
|
+
}
|
|
126
|
+
process(view, offset) {
|
|
127
|
+
for (let i = 0; i < 16; i++, offset += 4) MD5_W[i] = view.getUint32(offset, true);
|
|
128
|
+
let { A, B, C, D } = this;
|
|
129
|
+
for (let i = 0; i < 64; i++) {
|
|
130
|
+
let F, g, s;
|
|
131
|
+
if (i < 16) {
|
|
132
|
+
F = Chi(B, C, D);
|
|
133
|
+
g = i;
|
|
134
|
+
s = [
|
|
135
|
+
7,
|
|
136
|
+
12,
|
|
137
|
+
17,
|
|
138
|
+
22
|
|
139
|
+
];
|
|
140
|
+
} else if (i < 32) {
|
|
141
|
+
F = Chi(D, B, C);
|
|
142
|
+
g = (5 * i + 1) % 16;
|
|
143
|
+
s = [
|
|
144
|
+
5,
|
|
145
|
+
9,
|
|
146
|
+
14,
|
|
147
|
+
20
|
|
148
|
+
];
|
|
149
|
+
} else if (i < 48) {
|
|
150
|
+
F = B ^ C ^ D;
|
|
151
|
+
g = (3 * i + 5) % 16;
|
|
152
|
+
s = [
|
|
153
|
+
4,
|
|
154
|
+
11,
|
|
155
|
+
16,
|
|
156
|
+
23
|
|
157
|
+
];
|
|
158
|
+
} else {
|
|
159
|
+
F = C ^ (B | ~D);
|
|
160
|
+
g = 7 * i % 16;
|
|
161
|
+
s = [
|
|
162
|
+
6,
|
|
163
|
+
10,
|
|
164
|
+
15,
|
|
165
|
+
21
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
F = F + A + K[i] + MD5_W[g];
|
|
169
|
+
A = D;
|
|
170
|
+
D = C;
|
|
171
|
+
C = B;
|
|
172
|
+
B = B + rotl(F, s[i % 4]);
|
|
173
|
+
}
|
|
174
|
+
A = A + this.A | 0;
|
|
175
|
+
B = B + this.B | 0;
|
|
176
|
+
C = C + this.C | 0;
|
|
177
|
+
D = D + this.D | 0;
|
|
178
|
+
this.set(A, B, C, D);
|
|
179
|
+
}
|
|
180
|
+
roundClean() {
|
|
181
|
+
clean(MD5_W);
|
|
182
|
+
}
|
|
183
|
+
destroy() {
|
|
184
|
+
this.set(0, 0, 0, 0);
|
|
185
|
+
clean(this.buffer);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
189
|
+
Rho160 = /* @__PURE__ */ Uint8Array.from([
|
|
190
|
+
7,
|
|
191
|
+
4,
|
|
192
|
+
13,
|
|
193
|
+
1,
|
|
194
|
+
10,
|
|
195
|
+
6,
|
|
196
|
+
15,
|
|
197
|
+
3,
|
|
198
|
+
12,
|
|
199
|
+
0,
|
|
200
|
+
9,
|
|
201
|
+
5,
|
|
202
|
+
2,
|
|
203
|
+
14,
|
|
204
|
+
11,
|
|
205
|
+
8
|
|
206
|
+
]);
|
|
207
|
+
Id160 = Uint8Array.from(new Array(16).fill(0).map((_, i) => i));
|
|
208
|
+
Pi160 = Id160.map((i) => (9 * i + 5) % 16);
|
|
209
|
+
idxLR = /* @__PURE__ */ (() => {
|
|
210
|
+
const res = [[Id160], [Pi160]];
|
|
211
|
+
for (let i = 0; i < 4; i++) for (let j of res) j.push(j[i].map((k) => Rho160[k]));
|
|
212
|
+
return res;
|
|
213
|
+
})();
|
|
214
|
+
idxL = idxLR[0];
|
|
215
|
+
idxR = idxLR[1];
|
|
216
|
+
shifts160 = /* @__PURE__ */ [
|
|
217
|
+
[
|
|
218
|
+
11,
|
|
219
|
+
14,
|
|
220
|
+
15,
|
|
221
|
+
12,
|
|
222
|
+
5,
|
|
223
|
+
8,
|
|
224
|
+
7,
|
|
225
|
+
9,
|
|
226
|
+
11,
|
|
227
|
+
13,
|
|
228
|
+
14,
|
|
229
|
+
15,
|
|
230
|
+
6,
|
|
231
|
+
7,
|
|
232
|
+
9,
|
|
233
|
+
8
|
|
234
|
+
],
|
|
235
|
+
[
|
|
236
|
+
12,
|
|
237
|
+
13,
|
|
238
|
+
11,
|
|
239
|
+
15,
|
|
240
|
+
6,
|
|
241
|
+
9,
|
|
242
|
+
9,
|
|
243
|
+
7,
|
|
244
|
+
12,
|
|
245
|
+
15,
|
|
246
|
+
11,
|
|
247
|
+
13,
|
|
248
|
+
7,
|
|
249
|
+
8,
|
|
250
|
+
7,
|
|
251
|
+
7
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
13,
|
|
255
|
+
15,
|
|
256
|
+
14,
|
|
257
|
+
11,
|
|
258
|
+
7,
|
|
259
|
+
7,
|
|
260
|
+
6,
|
|
261
|
+
8,
|
|
262
|
+
13,
|
|
263
|
+
14,
|
|
264
|
+
13,
|
|
265
|
+
12,
|
|
266
|
+
5,
|
|
267
|
+
5,
|
|
268
|
+
6,
|
|
269
|
+
9
|
|
270
|
+
],
|
|
271
|
+
[
|
|
272
|
+
14,
|
|
273
|
+
11,
|
|
274
|
+
12,
|
|
275
|
+
14,
|
|
276
|
+
8,
|
|
277
|
+
6,
|
|
278
|
+
5,
|
|
279
|
+
5,
|
|
280
|
+
15,
|
|
281
|
+
12,
|
|
282
|
+
15,
|
|
283
|
+
14,
|
|
284
|
+
9,
|
|
285
|
+
9,
|
|
286
|
+
8,
|
|
287
|
+
6
|
|
288
|
+
],
|
|
289
|
+
[
|
|
290
|
+
15,
|
|
291
|
+
12,
|
|
292
|
+
13,
|
|
293
|
+
13,
|
|
294
|
+
9,
|
|
295
|
+
5,
|
|
296
|
+
8,
|
|
297
|
+
6,
|
|
298
|
+
14,
|
|
299
|
+
11,
|
|
300
|
+
12,
|
|
301
|
+
11,
|
|
302
|
+
8,
|
|
303
|
+
6,
|
|
304
|
+
5,
|
|
305
|
+
5
|
|
306
|
+
]
|
|
307
|
+
].map((i) => Uint8Array.from(i));
|
|
308
|
+
shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
309
|
+
shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
310
|
+
Kl160 = /* @__PURE__ */ Uint32Array.from([
|
|
311
|
+
0,
|
|
312
|
+
1518500249,
|
|
313
|
+
1859775393,
|
|
314
|
+
2400959708,
|
|
315
|
+
2840853838
|
|
316
|
+
]);
|
|
317
|
+
Kr160 = /* @__PURE__ */ Uint32Array.from([
|
|
318
|
+
1352829926,
|
|
319
|
+
1548603684,
|
|
320
|
+
1836072691,
|
|
321
|
+
2053994217,
|
|
322
|
+
0
|
|
323
|
+
]);
|
|
324
|
+
BUF_160 = /* @__PURE__ */ new Uint32Array(16);
|
|
325
|
+
_RIPEMD160 = class extends HashMD {
|
|
326
|
+
h0 = 1732584193;
|
|
327
|
+
h1 = -271733879;
|
|
328
|
+
h2 = -1732584194;
|
|
329
|
+
h3 = 271733878;
|
|
330
|
+
h4 = -1009589776;
|
|
331
|
+
constructor() {
|
|
332
|
+
super(64, 20, 8, true);
|
|
333
|
+
}
|
|
334
|
+
get() {
|
|
335
|
+
const { h0, h1, h2, h3, h4 } = this;
|
|
336
|
+
return [
|
|
337
|
+
h0,
|
|
338
|
+
h1,
|
|
339
|
+
h2,
|
|
340
|
+
h3,
|
|
341
|
+
h4
|
|
342
|
+
];
|
|
343
|
+
}
|
|
344
|
+
set(h0, h1, h2, h3, h4) {
|
|
345
|
+
this.h0 = h0 | 0;
|
|
346
|
+
this.h1 = h1 | 0;
|
|
347
|
+
this.h2 = h2 | 0;
|
|
348
|
+
this.h3 = h3 | 0;
|
|
349
|
+
this.h4 = h4 | 0;
|
|
350
|
+
}
|
|
351
|
+
process(view, offset) {
|
|
352
|
+
for (let i = 0; i < 16; i++, offset += 4) BUF_160[i] = view.getUint32(offset, true);
|
|
353
|
+
let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
|
|
354
|
+
for (let group = 0; group < 5; group++) {
|
|
355
|
+
const rGroup = 4 - group;
|
|
356
|
+
const hbl = Kl160[group], hbr = Kr160[group];
|
|
357
|
+
const rl = idxL[group], rr = idxR[group];
|
|
358
|
+
const sl = shiftsL160[group], sr = shiftsR160[group];
|
|
359
|
+
for (let i = 0; i < 16; i++) {
|
|
360
|
+
const tl = rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el | 0;
|
|
361
|
+
al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl;
|
|
362
|
+
}
|
|
363
|
+
for (let i = 0; i < 16; i++) {
|
|
364
|
+
const tr = rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er | 0;
|
|
365
|
+
ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
this.set(this.h1 + cl + dr | 0, this.h2 + dl + er | 0, this.h3 + el + ar | 0, this.h4 + al + br | 0, this.h0 + bl + cr | 0);
|
|
369
|
+
}
|
|
370
|
+
roundClean() {
|
|
371
|
+
clean(BUF_160);
|
|
372
|
+
}
|
|
373
|
+
destroy() {
|
|
374
|
+
this.destroyed = true;
|
|
375
|
+
clean(this.buffer);
|
|
376
|
+
this.set(0, 0, 0, 0, 0);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
ripemd160 = /* @__PURE__ */ createHasher(() => new _RIPEMD160());
|
|
380
|
+
}));
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region node_modules/@noble/hashes/sha3.js
|
|
1193
383
|
/** `keccakf1600` internal function, additionally allows to adjust round count. */
|
|
1194
384
|
function keccakP(s, rounds = 24) {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
for (let x = 0; x < 10; x++)
|
|
1231
|
-
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
1232
|
-
}
|
|
1233
|
-
// Iota (ι)
|
|
1234
|
-
s[0] ^= SHA3_IOTA_H[round];
|
|
1235
|
-
s[1] ^= SHA3_IOTA_L[round];
|
|
1236
|
-
}
|
|
1237
|
-
clean(B);
|
|
1238
|
-
}
|
|
1239
|
-
/** Keccak sponge function. */
|
|
1240
|
-
class Keccak {
|
|
1241
|
-
state;
|
|
1242
|
-
pos = 0;
|
|
1243
|
-
posOut = 0;
|
|
1244
|
-
finished = false;
|
|
1245
|
-
state32;
|
|
1246
|
-
destroyed = false;
|
|
1247
|
-
blockLen;
|
|
1248
|
-
suffix;
|
|
1249
|
-
outputLen;
|
|
1250
|
-
enableXOF = false;
|
|
1251
|
-
rounds;
|
|
1252
|
-
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1253
|
-
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
1254
|
-
this.blockLen = blockLen;
|
|
1255
|
-
this.suffix = suffix;
|
|
1256
|
-
this.outputLen = outputLen;
|
|
1257
|
-
this.enableXOF = enableXOF;
|
|
1258
|
-
this.rounds = rounds;
|
|
1259
|
-
// Can be passed from user as dkLen
|
|
1260
|
-
anumber(outputLen, 'outputLen');
|
|
1261
|
-
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
1262
|
-
// 0 < blockLen < 200
|
|
1263
|
-
if (!(0 < blockLen && blockLen < 200))
|
|
1264
|
-
throw new Error('only keccak-f1600 function is supported');
|
|
1265
|
-
this.state = new Uint8Array(200);
|
|
1266
|
-
this.state32 = u32(this.state);
|
|
1267
|
-
}
|
|
1268
|
-
clone() {
|
|
1269
|
-
return this._cloneInto();
|
|
1270
|
-
}
|
|
1271
|
-
keccak() {
|
|
1272
|
-
swap32IfBE(this.state32);
|
|
1273
|
-
keccakP(this.state32, this.rounds);
|
|
1274
|
-
swap32IfBE(this.state32);
|
|
1275
|
-
this.posOut = 0;
|
|
1276
|
-
this.pos = 0;
|
|
1277
|
-
}
|
|
1278
|
-
update(data) {
|
|
1279
|
-
aexists(this);
|
|
1280
|
-
abytes(data);
|
|
1281
|
-
const { blockLen, state } = this;
|
|
1282
|
-
const len = data.length;
|
|
1283
|
-
for (let pos = 0; pos < len;) {
|
|
1284
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1285
|
-
for (let i = 0; i < take; i++)
|
|
1286
|
-
state[this.pos++] ^= data[pos++];
|
|
1287
|
-
if (this.pos === blockLen)
|
|
1288
|
-
this.keccak();
|
|
1289
|
-
}
|
|
1290
|
-
return this;
|
|
1291
|
-
}
|
|
1292
|
-
finish() {
|
|
1293
|
-
if (this.finished)
|
|
1294
|
-
return;
|
|
1295
|
-
this.finished = true;
|
|
1296
|
-
const { state, suffix, pos, blockLen } = this;
|
|
1297
|
-
// Do the padding
|
|
1298
|
-
state[pos] ^= suffix;
|
|
1299
|
-
if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
|
|
1300
|
-
this.keccak();
|
|
1301
|
-
state[blockLen - 1] ^= 0x80;
|
|
1302
|
-
this.keccak();
|
|
1303
|
-
}
|
|
1304
|
-
writeInto(out) {
|
|
1305
|
-
aexists(this, false);
|
|
1306
|
-
abytes(out);
|
|
1307
|
-
this.finish();
|
|
1308
|
-
const bufferOut = this.state;
|
|
1309
|
-
const { blockLen } = this;
|
|
1310
|
-
for (let pos = 0, len = out.length; pos < len;) {
|
|
1311
|
-
if (this.posOut >= blockLen)
|
|
1312
|
-
this.keccak();
|
|
1313
|
-
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
1314
|
-
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
1315
|
-
this.posOut += take;
|
|
1316
|
-
pos += take;
|
|
1317
|
-
}
|
|
1318
|
-
return out;
|
|
1319
|
-
}
|
|
1320
|
-
xofInto(out) {
|
|
1321
|
-
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
|
1322
|
-
if (!this.enableXOF)
|
|
1323
|
-
throw new Error('XOF is not possible for this instance');
|
|
1324
|
-
return this.writeInto(out);
|
|
1325
|
-
}
|
|
1326
|
-
xof(bytes) {
|
|
1327
|
-
anumber(bytes);
|
|
1328
|
-
return this.xofInto(new Uint8Array(bytes));
|
|
1329
|
-
}
|
|
1330
|
-
digestInto(out) {
|
|
1331
|
-
aoutput(out, this);
|
|
1332
|
-
if (this.finished)
|
|
1333
|
-
throw new Error('digest() was already called');
|
|
1334
|
-
this.writeInto(out);
|
|
1335
|
-
this.destroy();
|
|
1336
|
-
return out;
|
|
1337
|
-
}
|
|
1338
|
-
digest() {
|
|
1339
|
-
return this.digestInto(new Uint8Array(this.outputLen));
|
|
1340
|
-
}
|
|
1341
|
-
destroy() {
|
|
1342
|
-
this.destroyed = true;
|
|
1343
|
-
clean(this.state);
|
|
1344
|
-
}
|
|
1345
|
-
_cloneInto(to) {
|
|
1346
|
-
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
1347
|
-
to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
1348
|
-
to.state32.set(this.state32);
|
|
1349
|
-
to.pos = this.pos;
|
|
1350
|
-
to.posOut = this.posOut;
|
|
1351
|
-
to.finished = this.finished;
|
|
1352
|
-
to.rounds = rounds;
|
|
1353
|
-
// Suffix can change in cSHAKE
|
|
1354
|
-
to.suffix = suffix;
|
|
1355
|
-
to.outputLen = outputLen;
|
|
1356
|
-
to.enableXOF = enableXOF;
|
|
1357
|
-
to.destroyed = this.destroyed;
|
|
1358
|
-
return to;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
const genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true), info);
|
|
1362
|
-
/** SHAKE128 XOF with 128-bit security. */
|
|
1363
|
-
const shake128 =
|
|
1364
|
-
/* @__PURE__ */
|
|
1365
|
-
genShake(0x1f, 168, 16, /* @__PURE__ */ oidNist(0x0b));
|
|
1366
|
-
/** SHAKE256 XOF with 256-bit security. */
|
|
1367
|
-
const shake256 =
|
|
1368
|
-
/* @__PURE__ */
|
|
1369
|
-
genShake(0x1f, 136, 32, /* @__PURE__ */ oidNist(0x0c));
|
|
1370
|
-
|
|
1371
|
-
var sha256 = {};
|
|
1372
|
-
|
|
1373
|
-
var sha2 = {};
|
|
1374
|
-
|
|
1375
|
-
var _md = {};
|
|
1376
|
-
|
|
1377
|
-
var utils = {};
|
|
1378
|
-
|
|
1379
|
-
var crypto = {};
|
|
1380
|
-
|
|
1381
|
-
var hasRequiredCrypto;
|
|
1382
|
-
|
|
1383
|
-
function requireCrypto () {
|
|
1384
|
-
if (hasRequiredCrypto) return crypto;
|
|
1385
|
-
hasRequiredCrypto = 1;
|
|
1386
|
-
Object.defineProperty(crypto, "__esModule", { value: true });
|
|
1387
|
-
crypto.crypto = void 0;
|
|
1388
|
-
crypto.crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1389
|
-
return crypto;
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
var hasRequiredUtils;
|
|
1393
|
-
|
|
1394
|
-
function requireUtils () {
|
|
1395
|
-
if (hasRequiredUtils) return utils;
|
|
1396
|
-
hasRequiredUtils = 1;
|
|
1397
|
-
(function (exports$1) {
|
|
1398
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1399
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1400
|
-
exports$1.wrapXOFConstructorWithOpts = exports$1.wrapConstructorWithOpts = exports$1.wrapConstructor = exports$1.Hash = exports$1.nextTick = exports$1.swap32IfBE = exports$1.byteSwapIfBE = exports$1.swap8IfBE = exports$1.isLE = void 0;
|
|
1401
|
-
exports$1.isBytes = isBytes;
|
|
1402
|
-
exports$1.anumber = anumber;
|
|
1403
|
-
exports$1.abytes = abytes;
|
|
1404
|
-
exports$1.ahash = ahash;
|
|
1405
|
-
exports$1.aexists = aexists;
|
|
1406
|
-
exports$1.aoutput = aoutput;
|
|
1407
|
-
exports$1.u8 = u8;
|
|
1408
|
-
exports$1.u32 = u32;
|
|
1409
|
-
exports$1.clean = clean;
|
|
1410
|
-
exports$1.createView = createView;
|
|
1411
|
-
exports$1.rotr = rotr;
|
|
1412
|
-
exports$1.rotl = rotl;
|
|
1413
|
-
exports$1.byteSwap = byteSwap;
|
|
1414
|
-
exports$1.byteSwap32 = byteSwap32;
|
|
1415
|
-
exports$1.bytesToHex = bytesToHex;
|
|
1416
|
-
exports$1.hexToBytes = hexToBytes;
|
|
1417
|
-
exports$1.asyncLoop = asyncLoop;
|
|
1418
|
-
exports$1.utf8ToBytes = utf8ToBytes;
|
|
1419
|
-
exports$1.bytesToUtf8 = bytesToUtf8;
|
|
1420
|
-
exports$1.toBytes = toBytes;
|
|
1421
|
-
exports$1.kdfInputToBytes = kdfInputToBytes;
|
|
1422
|
-
exports$1.concatBytes = concatBytes;
|
|
1423
|
-
exports$1.checkOpts = checkOpts;
|
|
1424
|
-
exports$1.createHasher = createHasher;
|
|
1425
|
-
exports$1.createOptHasher = createOptHasher;
|
|
1426
|
-
exports$1.createXOFer = createXOFer;
|
|
1427
|
-
exports$1.randomBytes = randomBytes;
|
|
1428
|
-
const crypto_1 = /*@__PURE__*/ requireCrypto();
|
|
1429
|
-
function isBytes(a) {
|
|
1430
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1431
|
-
}
|
|
1432
|
-
function anumber(n) {
|
|
1433
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
1434
|
-
throw new Error("positive integer expected, got " + n);
|
|
1435
|
-
}
|
|
1436
|
-
function abytes(b, ...lengths) {
|
|
1437
|
-
if (!isBytes(b))
|
|
1438
|
-
throw new Error("Uint8Array expected");
|
|
1439
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1440
|
-
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1441
|
-
}
|
|
1442
|
-
function ahash(h) {
|
|
1443
|
-
if (typeof h !== "function" || typeof h.create !== "function")
|
|
1444
|
-
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
1445
|
-
anumber(h.outputLen);
|
|
1446
|
-
anumber(h.blockLen);
|
|
1447
|
-
}
|
|
1448
|
-
function aexists(instance, checkFinished = true) {
|
|
1449
|
-
if (instance.destroyed)
|
|
1450
|
-
throw new Error("Hash instance has been destroyed");
|
|
1451
|
-
if (checkFinished && instance.finished)
|
|
1452
|
-
throw new Error("Hash#digest() has already been called");
|
|
1453
|
-
}
|
|
1454
|
-
function aoutput(out, instance) {
|
|
1455
|
-
abytes(out);
|
|
1456
|
-
const min = instance.outputLen;
|
|
1457
|
-
if (out.length < min) {
|
|
1458
|
-
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
function u8(arr) {
|
|
1462
|
-
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
1463
|
-
}
|
|
1464
|
-
function u32(arr) {
|
|
1465
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
1466
|
-
}
|
|
1467
|
-
function clean(...arrays) {
|
|
1468
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
1469
|
-
arrays[i].fill(0);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
function createView(arr) {
|
|
1473
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
1474
|
-
}
|
|
1475
|
-
function rotr(word, shift) {
|
|
1476
|
-
return word << 32 - shift | word >>> shift;
|
|
1477
|
-
}
|
|
1478
|
-
function rotl(word, shift) {
|
|
1479
|
-
return word << shift | word >>> 32 - shift >>> 0;
|
|
1480
|
-
}
|
|
1481
|
-
exports$1.isLE = (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
1482
|
-
function byteSwap(word) {
|
|
1483
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
1484
|
-
}
|
|
1485
|
-
exports$1.swap8IfBE = exports$1.isLE ? (n) => n : (n) => byteSwap(n);
|
|
1486
|
-
exports$1.byteSwapIfBE = exports$1.swap8IfBE;
|
|
1487
|
-
function byteSwap32(arr) {
|
|
1488
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1489
|
-
arr[i] = byteSwap(arr[i]);
|
|
1490
|
-
}
|
|
1491
|
-
return arr;
|
|
1492
|
-
}
|
|
1493
|
-
exports$1.swap32IfBE = exports$1.isLE ? (u) => u : byteSwap32;
|
|
1494
|
-
const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
1495
|
-
// @ts-ignore
|
|
1496
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
1497
|
-
))();
|
|
1498
|
-
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
1499
|
-
function bytesToHex(bytes) {
|
|
1500
|
-
abytes(bytes);
|
|
1501
|
-
if (hasHexBuiltin)
|
|
1502
|
-
return bytes.toHex();
|
|
1503
|
-
let hex = "";
|
|
1504
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
1505
|
-
hex += hexes[bytes[i]];
|
|
1506
|
-
}
|
|
1507
|
-
return hex;
|
|
1508
|
-
}
|
|
1509
|
-
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
1510
|
-
function asciiToBase16(ch) {
|
|
1511
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
1512
|
-
return ch - asciis._0;
|
|
1513
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
1514
|
-
return ch - (asciis.A - 10);
|
|
1515
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
1516
|
-
return ch - (asciis.a - 10);
|
|
1517
|
-
return;
|
|
1518
|
-
}
|
|
1519
|
-
function hexToBytes(hex) {
|
|
1520
|
-
if (typeof hex !== "string")
|
|
1521
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
1522
|
-
if (hasHexBuiltin)
|
|
1523
|
-
return Uint8Array.fromHex(hex);
|
|
1524
|
-
const hl = hex.length;
|
|
1525
|
-
const al = hl / 2;
|
|
1526
|
-
if (hl % 2)
|
|
1527
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
1528
|
-
const array = new Uint8Array(al);
|
|
1529
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
1530
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
1531
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
1532
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
1533
|
-
const char = hex[hi] + hex[hi + 1];
|
|
1534
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
1535
|
-
}
|
|
1536
|
-
array[ai] = n1 * 16 + n2;
|
|
1537
|
-
}
|
|
1538
|
-
return array;
|
|
1539
|
-
}
|
|
1540
|
-
const nextTick = async () => {
|
|
1541
|
-
};
|
|
1542
|
-
exports$1.nextTick = nextTick;
|
|
1543
|
-
async function asyncLoop(iters, tick, cb) {
|
|
1544
|
-
let ts = Date.now();
|
|
1545
|
-
for (let i = 0; i < iters; i++) {
|
|
1546
|
-
cb(i);
|
|
1547
|
-
const diff = Date.now() - ts;
|
|
1548
|
-
if (diff >= 0 && diff < tick)
|
|
1549
|
-
continue;
|
|
1550
|
-
await (0, exports$1.nextTick)();
|
|
1551
|
-
ts += diff;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
function utf8ToBytes(str) {
|
|
1555
|
-
if (typeof str !== "string")
|
|
1556
|
-
throw new Error("string expected");
|
|
1557
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
1558
|
-
}
|
|
1559
|
-
function bytesToUtf8(bytes) {
|
|
1560
|
-
return new TextDecoder().decode(bytes);
|
|
1561
|
-
}
|
|
1562
|
-
function toBytes(data) {
|
|
1563
|
-
if (typeof data === "string")
|
|
1564
|
-
data = utf8ToBytes(data);
|
|
1565
|
-
abytes(data);
|
|
1566
|
-
return data;
|
|
1567
|
-
}
|
|
1568
|
-
function kdfInputToBytes(data) {
|
|
1569
|
-
if (typeof data === "string")
|
|
1570
|
-
data = utf8ToBytes(data);
|
|
1571
|
-
abytes(data);
|
|
1572
|
-
return data;
|
|
1573
|
-
}
|
|
1574
|
-
function concatBytes(...arrays) {
|
|
1575
|
-
let sum = 0;
|
|
1576
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
1577
|
-
const a = arrays[i];
|
|
1578
|
-
abytes(a);
|
|
1579
|
-
sum += a.length;
|
|
1580
|
-
}
|
|
1581
|
-
const res = new Uint8Array(sum);
|
|
1582
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
1583
|
-
const a = arrays[i];
|
|
1584
|
-
res.set(a, pad);
|
|
1585
|
-
pad += a.length;
|
|
1586
|
-
}
|
|
1587
|
-
return res;
|
|
1588
|
-
}
|
|
1589
|
-
function checkOpts(defaults, opts) {
|
|
1590
|
-
if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]")
|
|
1591
|
-
throw new Error("options should be object or undefined");
|
|
1592
|
-
const merged = Object.assign(defaults, opts);
|
|
1593
|
-
return merged;
|
|
1594
|
-
}
|
|
1595
|
-
class Hash {
|
|
1596
|
-
}
|
|
1597
|
-
exports$1.Hash = Hash;
|
|
1598
|
-
function createHasher(hashCons) {
|
|
1599
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
1600
|
-
const tmp = hashCons();
|
|
1601
|
-
hashC.outputLen = tmp.outputLen;
|
|
1602
|
-
hashC.blockLen = tmp.blockLen;
|
|
1603
|
-
hashC.create = () => hashCons();
|
|
1604
|
-
return hashC;
|
|
1605
|
-
}
|
|
1606
|
-
function createOptHasher(hashCons) {
|
|
1607
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
1608
|
-
const tmp = hashCons({});
|
|
1609
|
-
hashC.outputLen = tmp.outputLen;
|
|
1610
|
-
hashC.blockLen = tmp.blockLen;
|
|
1611
|
-
hashC.create = (opts) => hashCons(opts);
|
|
1612
|
-
return hashC;
|
|
1613
|
-
}
|
|
1614
|
-
function createXOFer(hashCons) {
|
|
1615
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
1616
|
-
const tmp = hashCons({});
|
|
1617
|
-
hashC.outputLen = tmp.outputLen;
|
|
1618
|
-
hashC.blockLen = tmp.blockLen;
|
|
1619
|
-
hashC.create = (opts) => hashCons(opts);
|
|
1620
|
-
return hashC;
|
|
1621
|
-
}
|
|
1622
|
-
exports$1.wrapConstructor = createHasher;
|
|
1623
|
-
exports$1.wrapConstructorWithOpts = createOptHasher;
|
|
1624
|
-
exports$1.wrapXOFConstructorWithOpts = createXOFer;
|
|
1625
|
-
function randomBytes(bytesLength = 32) {
|
|
1626
|
-
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
|
|
1627
|
-
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
1628
|
-
}
|
|
1629
|
-
if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === "function") {
|
|
1630
|
-
return Uint8Array.from(crypto_1.crypto.randomBytes(bytesLength));
|
|
1631
|
-
}
|
|
1632
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
1633
|
-
}
|
|
1634
|
-
} (utils));
|
|
1635
|
-
return utils;
|
|
385
|
+
const B = new Uint32Array(10);
|
|
386
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
387
|
+
for (let x = 0; x < 10; x++) B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
388
|
+
for (let x = 0; x < 10; x += 2) {
|
|
389
|
+
const idx1 = (x + 8) % 10;
|
|
390
|
+
const idx0 = (x + 2) % 10;
|
|
391
|
+
const B0 = B[idx0];
|
|
392
|
+
const B1 = B[idx0 + 1];
|
|
393
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
394
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
395
|
+
for (let y = 0; y < 50; y += 10) {
|
|
396
|
+
s[x + y] ^= Th;
|
|
397
|
+
s[x + y + 1] ^= Tl;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
let curH = s[2];
|
|
401
|
+
let curL = s[3];
|
|
402
|
+
for (let t = 0; t < 24; t++) {
|
|
403
|
+
const shift = SHA3_ROTL[t];
|
|
404
|
+
const Th = rotlH(curH, curL, shift);
|
|
405
|
+
const Tl = rotlL(curH, curL, shift);
|
|
406
|
+
const PI = SHA3_PI[t];
|
|
407
|
+
curH = s[PI];
|
|
408
|
+
curL = s[PI + 1];
|
|
409
|
+
s[PI] = Th;
|
|
410
|
+
s[PI + 1] = Tl;
|
|
411
|
+
}
|
|
412
|
+
for (let y = 0; y < 50; y += 10) {
|
|
413
|
+
for (let x = 0; x < 10; x++) B[x] = s[y + x];
|
|
414
|
+
for (let x = 0; x < 10; x++) s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
415
|
+
}
|
|
416
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
417
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
418
|
+
}
|
|
419
|
+
clean(B);
|
|
1636
420
|
}
|
|
1637
|
-
|
|
1638
|
-
var
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
421
|
+
var _0n, _1n, _2n, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, genShake, shake128, shake256;
|
|
422
|
+
var init_sha3 = __esmMin((() => {
|
|
423
|
+
init__u64();
|
|
424
|
+
init_utils();
|
|
425
|
+
_0n = BigInt(0);
|
|
426
|
+
_1n = BigInt(1);
|
|
427
|
+
_2n = BigInt(2);
|
|
428
|
+
_7n = BigInt(7);
|
|
429
|
+
_256n = BigInt(256);
|
|
430
|
+
_0x71n = BigInt(113);
|
|
431
|
+
SHA3_PI = [];
|
|
432
|
+
SHA3_ROTL = [];
|
|
433
|
+
_SHA3_IOTA = [];
|
|
434
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
435
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
436
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
437
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
438
|
+
let t = _0n;
|
|
439
|
+
for (let j = 0; j < 7; j++) {
|
|
440
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
441
|
+
if (R & _2n) t ^= _1n << (_1n << BigInt(j)) - _1n;
|
|
442
|
+
}
|
|
443
|
+
_SHA3_IOTA.push(t);
|
|
444
|
+
}
|
|
445
|
+
IOTAS = split(_SHA3_IOTA, true);
|
|
446
|
+
SHA3_IOTA_H = IOTAS[0];
|
|
447
|
+
SHA3_IOTA_L = IOTAS[1];
|
|
448
|
+
rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
449
|
+
rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
450
|
+
Keccak = class Keccak {
|
|
451
|
+
state;
|
|
452
|
+
pos = 0;
|
|
453
|
+
posOut = 0;
|
|
454
|
+
finished = false;
|
|
455
|
+
state32;
|
|
456
|
+
destroyed = false;
|
|
457
|
+
blockLen;
|
|
458
|
+
suffix;
|
|
459
|
+
outputLen;
|
|
460
|
+
enableXOF = false;
|
|
461
|
+
rounds;
|
|
462
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
463
|
+
this.blockLen = blockLen;
|
|
464
|
+
this.suffix = suffix;
|
|
465
|
+
this.outputLen = outputLen;
|
|
466
|
+
this.enableXOF = enableXOF;
|
|
467
|
+
this.rounds = rounds;
|
|
468
|
+
anumber(outputLen, "outputLen");
|
|
469
|
+
if (!(0 < blockLen && blockLen < 200)) throw new Error("only keccak-f1600 function is supported");
|
|
470
|
+
this.state = new Uint8Array(200);
|
|
471
|
+
this.state32 = u32(this.state);
|
|
472
|
+
}
|
|
473
|
+
clone() {
|
|
474
|
+
return this._cloneInto();
|
|
475
|
+
}
|
|
476
|
+
keccak() {
|
|
477
|
+
swap32IfBE(this.state32);
|
|
478
|
+
keccakP(this.state32, this.rounds);
|
|
479
|
+
swap32IfBE(this.state32);
|
|
480
|
+
this.posOut = 0;
|
|
481
|
+
this.pos = 0;
|
|
482
|
+
}
|
|
483
|
+
update(data) {
|
|
484
|
+
aexists(this);
|
|
485
|
+
abytes(data);
|
|
486
|
+
const { blockLen, state } = this;
|
|
487
|
+
const len = data.length;
|
|
488
|
+
for (let pos = 0; pos < len;) {
|
|
489
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
490
|
+
for (let i = 0; i < take; i++) state[this.pos++] ^= data[pos++];
|
|
491
|
+
if (this.pos === blockLen) this.keccak();
|
|
492
|
+
}
|
|
493
|
+
return this;
|
|
494
|
+
}
|
|
495
|
+
finish() {
|
|
496
|
+
if (this.finished) return;
|
|
497
|
+
this.finished = true;
|
|
498
|
+
const { state, suffix, pos, blockLen } = this;
|
|
499
|
+
state[pos] ^= suffix;
|
|
500
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1) this.keccak();
|
|
501
|
+
state[blockLen - 1] ^= 128;
|
|
502
|
+
this.keccak();
|
|
503
|
+
}
|
|
504
|
+
writeInto(out) {
|
|
505
|
+
aexists(this, false);
|
|
506
|
+
abytes(out);
|
|
507
|
+
this.finish();
|
|
508
|
+
const bufferOut = this.state;
|
|
509
|
+
const { blockLen } = this;
|
|
510
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
511
|
+
if (this.posOut >= blockLen) this.keccak();
|
|
512
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
513
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
514
|
+
this.posOut += take;
|
|
515
|
+
pos += take;
|
|
516
|
+
}
|
|
517
|
+
return out;
|
|
518
|
+
}
|
|
519
|
+
xofInto(out) {
|
|
520
|
+
if (!this.enableXOF) throw new Error("XOF is not possible for this instance");
|
|
521
|
+
return this.writeInto(out);
|
|
522
|
+
}
|
|
523
|
+
xof(bytes) {
|
|
524
|
+
anumber(bytes);
|
|
525
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
526
|
+
}
|
|
527
|
+
digestInto(out) {
|
|
528
|
+
aoutput(out, this);
|
|
529
|
+
if (this.finished) throw new Error("digest() was already called");
|
|
530
|
+
this.writeInto(out);
|
|
531
|
+
this.destroy();
|
|
532
|
+
return out;
|
|
533
|
+
}
|
|
534
|
+
digest() {
|
|
535
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
536
|
+
}
|
|
537
|
+
destroy() {
|
|
538
|
+
this.destroyed = true;
|
|
539
|
+
clean(this.state);
|
|
540
|
+
}
|
|
541
|
+
_cloneInto(to) {
|
|
542
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
543
|
+
to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
544
|
+
to.state32.set(this.state32);
|
|
545
|
+
to.pos = this.pos;
|
|
546
|
+
to.posOut = this.posOut;
|
|
547
|
+
to.finished = this.finished;
|
|
548
|
+
to.rounds = rounds;
|
|
549
|
+
to.suffix = suffix;
|
|
550
|
+
to.outputLen = outputLen;
|
|
551
|
+
to.enableXOF = enableXOF;
|
|
552
|
+
to.destroyed = this.destroyed;
|
|
553
|
+
return to;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true), info);
|
|
557
|
+
shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
|
|
558
|
+
shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
|
|
559
|
+
}));
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/crypto.js
|
|
562
|
+
var require_crypto = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
563
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
564
|
+
exports.crypto = void 0;
|
|
565
|
+
exports.crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
566
|
+
}));
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/utils.js
|
|
569
|
+
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1648
570
|
/**
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
571
|
+
* Utilities for hex, bytes, CSPRNG.
|
|
572
|
+
* @module
|
|
573
|
+
*/
|
|
574
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
575
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
576
|
+
exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
|
|
577
|
+
exports.isBytes = isBytes;
|
|
578
|
+
exports.anumber = anumber;
|
|
579
|
+
exports.abytes = abytes;
|
|
580
|
+
exports.ahash = ahash;
|
|
581
|
+
exports.aexists = aexists;
|
|
582
|
+
exports.aoutput = aoutput;
|
|
583
|
+
exports.u8 = u8;
|
|
584
|
+
exports.u32 = u32;
|
|
585
|
+
exports.clean = clean;
|
|
586
|
+
exports.createView = createView;
|
|
587
|
+
exports.rotr = rotr;
|
|
588
|
+
exports.rotl = rotl;
|
|
589
|
+
exports.byteSwap = byteSwap;
|
|
590
|
+
exports.byteSwap32 = byteSwap32;
|
|
591
|
+
exports.bytesToHex = bytesToHex;
|
|
592
|
+
exports.hexToBytes = hexToBytes;
|
|
593
|
+
exports.asyncLoop = asyncLoop;
|
|
594
|
+
exports.utf8ToBytes = utf8ToBytes;
|
|
595
|
+
exports.bytesToUtf8 = bytesToUtf8;
|
|
596
|
+
exports.toBytes = toBytes;
|
|
597
|
+
exports.kdfInputToBytes = kdfInputToBytes;
|
|
598
|
+
exports.concatBytes = concatBytes;
|
|
599
|
+
exports.checkOpts = checkOpts;
|
|
600
|
+
exports.createHasher = createHasher;
|
|
601
|
+
exports.createOptHasher = createOptHasher;
|
|
602
|
+
exports.createXOFer = createXOFer;
|
|
603
|
+
exports.randomBytes = randomBytes;
|
|
604
|
+
var crypto_1 = require_crypto();
|
|
605
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
606
|
+
function isBytes(a) {
|
|
607
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
608
|
+
}
|
|
609
|
+
/** Asserts something is positive integer. */
|
|
610
|
+
function anumber(n) {
|
|
611
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error("positive integer expected, got " + n);
|
|
612
|
+
}
|
|
613
|
+
/** Asserts something is Uint8Array. */
|
|
614
|
+
function abytes(b, ...lengths) {
|
|
615
|
+
if (!isBytes(b)) throw new Error("Uint8Array expected");
|
|
616
|
+
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
617
|
+
}
|
|
618
|
+
/** Asserts something is hash */
|
|
619
|
+
function ahash(h) {
|
|
620
|
+
if (typeof h !== "function" || typeof h.create !== "function") throw new Error("Hash should be wrapped by utils.createHasher");
|
|
621
|
+
anumber(h.outputLen);
|
|
622
|
+
anumber(h.blockLen);
|
|
623
|
+
}
|
|
624
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
|
625
|
+
function aexists(instance, checkFinished = true) {
|
|
626
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
627
|
+
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
628
|
+
}
|
|
629
|
+
/** Asserts output is properly-sized byte array */
|
|
630
|
+
function aoutput(out, instance) {
|
|
631
|
+
abytes(out);
|
|
632
|
+
const min = instance.outputLen;
|
|
633
|
+
if (out.length < min) throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
634
|
+
}
|
|
635
|
+
/** Cast u8 / u16 / u32 to u8. */
|
|
636
|
+
function u8(arr) {
|
|
637
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
638
|
+
}
|
|
639
|
+
/** Cast u8 / u16 / u32 to u32. */
|
|
640
|
+
function u32(arr) {
|
|
641
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
642
|
+
}
|
|
643
|
+
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
644
|
+
function clean(...arrays) {
|
|
645
|
+
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
646
|
+
}
|
|
647
|
+
/** Create DataView of an array for easy byte-level manipulation. */
|
|
648
|
+
function createView(arr) {
|
|
649
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
650
|
+
}
|
|
651
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
|
652
|
+
function rotr(word, shift) {
|
|
653
|
+
return word << 32 - shift | word >>> shift;
|
|
654
|
+
}
|
|
655
|
+
/** The rotate left (circular left shift) operation for uint32 */
|
|
656
|
+
function rotl(word, shift) {
|
|
657
|
+
return word << shift | word >>> 32 - shift >>> 0;
|
|
658
|
+
}
|
|
659
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
660
|
+
exports.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
661
|
+
/** The byte swap operation for uint32 */
|
|
662
|
+
function byteSwap(word) {
|
|
663
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
664
|
+
}
|
|
665
|
+
/** Conditionally byte swap if on a big-endian platform */
|
|
666
|
+
exports.swap8IfBE = exports.isLE ? (n) => n : (n) => byteSwap(n);
|
|
667
|
+
/** @deprecated */
|
|
668
|
+
exports.byteSwapIfBE = exports.swap8IfBE;
|
|
669
|
+
/** In place byte swap for Uint32Array */
|
|
670
|
+
function byteSwap32(arr) {
|
|
671
|
+
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
672
|
+
return arr;
|
|
673
|
+
}
|
|
674
|
+
exports.swap32IfBE = exports.isLE ? (u) => u : byteSwap32;
|
|
675
|
+
var hasHexBuiltin = typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
|
|
676
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
677
|
+
/**
|
|
678
|
+
* Convert byte array to hex string. Uses built-in function, when available.
|
|
679
|
+
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
680
|
+
*/
|
|
681
|
+
function bytesToHex(bytes) {
|
|
682
|
+
abytes(bytes);
|
|
683
|
+
if (hasHexBuiltin) return bytes.toHex();
|
|
684
|
+
let hex = "";
|
|
685
|
+
for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
|
|
686
|
+
return hex;
|
|
687
|
+
}
|
|
688
|
+
var asciis = {
|
|
689
|
+
_0: 48,
|
|
690
|
+
_9: 57,
|
|
691
|
+
A: 65,
|
|
692
|
+
F: 70,
|
|
693
|
+
a: 97,
|
|
694
|
+
f: 102
|
|
695
|
+
};
|
|
696
|
+
function asciiToBase16(ch) {
|
|
697
|
+
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0;
|
|
698
|
+
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10);
|
|
699
|
+
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Convert hex string to byte array. Uses built-in function, when available.
|
|
703
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
704
|
+
*/
|
|
705
|
+
function hexToBytes(hex) {
|
|
706
|
+
if (typeof hex !== "string") throw new Error("hex string expected, got " + typeof hex);
|
|
707
|
+
if (hasHexBuiltin) return Uint8Array.fromHex(hex);
|
|
708
|
+
const hl = hex.length;
|
|
709
|
+
const al = hl / 2;
|
|
710
|
+
if (hl % 2) throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
711
|
+
const array = new Uint8Array(al);
|
|
712
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
713
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
714
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
715
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
716
|
+
const char = hex[hi] + hex[hi + 1];
|
|
717
|
+
throw new Error("hex string expected, got non-hex character \"" + char + "\" at index " + hi);
|
|
718
|
+
}
|
|
719
|
+
array[ai] = n1 * 16 + n2;
|
|
720
|
+
}
|
|
721
|
+
return array;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* There is no setImmediate in browser and setTimeout is slow.
|
|
725
|
+
* Call of async fn will return Promise, which will be fullfiled only on
|
|
726
|
+
* next scheduler queue processing step and this is exactly what we need.
|
|
727
|
+
*/
|
|
728
|
+
var nextTick = async () => {};
|
|
729
|
+
exports.nextTick = nextTick;
|
|
730
|
+
/** Returns control to thread each 'tick' ms to avoid blocking. */
|
|
731
|
+
async function asyncLoop(iters, tick, cb) {
|
|
732
|
+
let ts = Date.now();
|
|
733
|
+
for (let i = 0; i < iters; i++) {
|
|
734
|
+
cb(i);
|
|
735
|
+
const diff = Date.now() - ts;
|
|
736
|
+
if (diff >= 0 && diff < tick) continue;
|
|
737
|
+
await (0, exports.nextTick)();
|
|
738
|
+
ts += diff;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Converts string to bytes using UTF8 encoding.
|
|
743
|
+
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
744
|
+
*/
|
|
745
|
+
function utf8ToBytes(str) {
|
|
746
|
+
if (typeof str !== "string") throw new Error("string expected");
|
|
747
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Converts bytes to string using UTF8 encoding.
|
|
751
|
+
* @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
|
|
752
|
+
*/
|
|
753
|
+
function bytesToUtf8(bytes) {
|
|
754
|
+
return new TextDecoder().decode(bytes);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
758
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
759
|
+
* Keep in mind for future mutable operations.
|
|
760
|
+
*/
|
|
761
|
+
function toBytes(data) {
|
|
762
|
+
if (typeof data === "string") data = utf8ToBytes(data);
|
|
763
|
+
abytes(data);
|
|
764
|
+
return data;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Helper for KDFs: consumes uint8array or string.
|
|
768
|
+
* When string is passed, does utf8 decoding, using TextDecoder.
|
|
769
|
+
*/
|
|
770
|
+
function kdfInputToBytes(data) {
|
|
771
|
+
if (typeof data === "string") data = utf8ToBytes(data);
|
|
772
|
+
abytes(data);
|
|
773
|
+
return data;
|
|
774
|
+
}
|
|
775
|
+
/** Copies several Uint8Arrays into one. */
|
|
776
|
+
function concatBytes(...arrays) {
|
|
777
|
+
let sum = 0;
|
|
778
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
779
|
+
const a = arrays[i];
|
|
780
|
+
abytes(a);
|
|
781
|
+
sum += a.length;
|
|
782
|
+
}
|
|
783
|
+
const res = new Uint8Array(sum);
|
|
784
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
785
|
+
const a = arrays[i];
|
|
786
|
+
res.set(a, pad);
|
|
787
|
+
pad += a.length;
|
|
788
|
+
}
|
|
789
|
+
return res;
|
|
790
|
+
}
|
|
791
|
+
function checkOpts(defaults, opts) {
|
|
792
|
+
if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]") throw new Error("options should be object or undefined");
|
|
793
|
+
return Object.assign(defaults, opts);
|
|
794
|
+
}
|
|
795
|
+
/** For runtime check if class implements interface */
|
|
796
|
+
var Hash = class {};
|
|
797
|
+
exports.Hash = Hash;
|
|
798
|
+
/** Wraps hash function, creating an interface on top of it */
|
|
799
|
+
function createHasher(hashCons) {
|
|
800
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
801
|
+
const tmp = hashCons();
|
|
802
|
+
hashC.outputLen = tmp.outputLen;
|
|
803
|
+
hashC.blockLen = tmp.blockLen;
|
|
804
|
+
hashC.create = () => hashCons();
|
|
805
|
+
return hashC;
|
|
806
|
+
}
|
|
807
|
+
function createOptHasher(hashCons) {
|
|
808
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
809
|
+
const tmp = hashCons({});
|
|
810
|
+
hashC.outputLen = tmp.outputLen;
|
|
811
|
+
hashC.blockLen = tmp.blockLen;
|
|
812
|
+
hashC.create = (opts) => hashCons(opts);
|
|
813
|
+
return hashC;
|
|
814
|
+
}
|
|
815
|
+
function createXOFer(hashCons) {
|
|
816
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
817
|
+
const tmp = hashCons({});
|
|
818
|
+
hashC.outputLen = tmp.outputLen;
|
|
819
|
+
hashC.blockLen = tmp.blockLen;
|
|
820
|
+
hashC.create = (opts) => hashCons(opts);
|
|
821
|
+
return hashC;
|
|
822
|
+
}
|
|
823
|
+
exports.wrapConstructor = createHasher;
|
|
824
|
+
exports.wrapConstructorWithOpts = createOptHasher;
|
|
825
|
+
exports.wrapXOFConstructorWithOpts = createXOFer;
|
|
826
|
+
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
827
|
+
function randomBytes(bytesLength = 32) {
|
|
828
|
+
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
829
|
+
if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === "function") return Uint8Array.from(crypto_1.crypto.randomBytes(bytesLength));
|
|
830
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
831
|
+
}
|
|
832
|
+
}));
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/_md.js
|
|
835
|
+
var require__md = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
836
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
837
|
+
exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
|
|
838
|
+
exports.setBigUint64 = setBigUint64;
|
|
839
|
+
exports.Chi = Chi;
|
|
840
|
+
exports.Maj = Maj;
|
|
841
|
+
/**
|
|
842
|
+
* Internal Merkle-Damgard hash utils.
|
|
843
|
+
* @module
|
|
844
|
+
*/
|
|
845
|
+
var utils_ts_1 = require_utils();
|
|
1653
846
|
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
|
1654
847
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
|
848
|
+
if (typeof view.setBigUint64 === "function") return view.setBigUint64(byteOffset, value, isLE);
|
|
849
|
+
const _32n = BigInt(32);
|
|
850
|
+
const _u32_max = BigInt(4294967295);
|
|
851
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
852
|
+
const wl = Number(value & _u32_max);
|
|
853
|
+
const h = isLE ? 4 : 0;
|
|
854
|
+
const l = isLE ? 0 : 4;
|
|
855
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
856
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
1665
857
|
}
|
|
1666
858
|
/** Choice: a ? b : c */
|
|
1667
859
|
function Chi(a, b, c) {
|
|
1668
|
-
|
|
860
|
+
return a & b ^ ~a & c;
|
|
1669
861
|
}
|
|
1670
862
|
/** Majority function, true if any two inputs is true. */
|
|
1671
863
|
function Maj(a, b, c) {
|
|
1672
|
-
|
|
864
|
+
return a & b ^ a & c ^ b & c;
|
|
1673
865
|
}
|
|
1674
866
|
/**
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
}
|
|
1764
|
-
_cloneInto(to) {
|
|
1765
|
-
to || (to = new this.constructor());
|
|
1766
|
-
to.set(...this.get());
|
|
1767
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1768
|
-
to.destroyed = destroyed;
|
|
1769
|
-
to.finished = finished;
|
|
1770
|
-
to.length = length;
|
|
1771
|
-
to.pos = pos;
|
|
1772
|
-
if (length % blockLen)
|
|
1773
|
-
to.buffer.set(buffer);
|
|
1774
|
-
return to;
|
|
1775
|
-
}
|
|
1776
|
-
clone() {
|
|
1777
|
-
return this._cloneInto();
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
_md.HashMD = HashMD;
|
|
867
|
+
* Merkle-Damgard hash construction base class.
|
|
868
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
869
|
+
*/
|
|
870
|
+
var HashMD = class extends utils_ts_1.Hash {
|
|
871
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
872
|
+
super();
|
|
873
|
+
this.finished = false;
|
|
874
|
+
this.length = 0;
|
|
875
|
+
this.pos = 0;
|
|
876
|
+
this.destroyed = false;
|
|
877
|
+
this.blockLen = blockLen;
|
|
878
|
+
this.outputLen = outputLen;
|
|
879
|
+
this.padOffset = padOffset;
|
|
880
|
+
this.isLE = isLE;
|
|
881
|
+
this.buffer = new Uint8Array(blockLen);
|
|
882
|
+
this.view = (0, utils_ts_1.createView)(this.buffer);
|
|
883
|
+
}
|
|
884
|
+
update(data) {
|
|
885
|
+
(0, utils_ts_1.aexists)(this);
|
|
886
|
+
data = (0, utils_ts_1.toBytes)(data);
|
|
887
|
+
(0, utils_ts_1.abytes)(data);
|
|
888
|
+
const { view, buffer, blockLen } = this;
|
|
889
|
+
const len = data.length;
|
|
890
|
+
for (let pos = 0; pos < len;) {
|
|
891
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
892
|
+
if (take === blockLen) {
|
|
893
|
+
const dataView = (0, utils_ts_1.createView)(data);
|
|
894
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
895
|
+
continue;
|
|
896
|
+
}
|
|
897
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
898
|
+
this.pos += take;
|
|
899
|
+
pos += take;
|
|
900
|
+
if (this.pos === blockLen) {
|
|
901
|
+
this.process(view, 0);
|
|
902
|
+
this.pos = 0;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
this.length += data.length;
|
|
906
|
+
this.roundClean();
|
|
907
|
+
return this;
|
|
908
|
+
}
|
|
909
|
+
digestInto(out) {
|
|
910
|
+
(0, utils_ts_1.aexists)(this);
|
|
911
|
+
(0, utils_ts_1.aoutput)(out, this);
|
|
912
|
+
this.finished = true;
|
|
913
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
914
|
+
let { pos } = this;
|
|
915
|
+
buffer[pos++] = 128;
|
|
916
|
+
(0, utils_ts_1.clean)(this.buffer.subarray(pos));
|
|
917
|
+
if (this.padOffset > blockLen - pos) {
|
|
918
|
+
this.process(view, 0);
|
|
919
|
+
pos = 0;
|
|
920
|
+
}
|
|
921
|
+
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
922
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
923
|
+
this.process(view, 0);
|
|
924
|
+
const oview = (0, utils_ts_1.createView)(out);
|
|
925
|
+
const len = this.outputLen;
|
|
926
|
+
if (len % 4) throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
927
|
+
const outLen = len / 4;
|
|
928
|
+
const state = this.get();
|
|
929
|
+
if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
|
|
930
|
+
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
931
|
+
}
|
|
932
|
+
digest() {
|
|
933
|
+
const { buffer, outputLen } = this;
|
|
934
|
+
this.digestInto(buffer);
|
|
935
|
+
const res = buffer.slice(0, outputLen);
|
|
936
|
+
this.destroy();
|
|
937
|
+
return res;
|
|
938
|
+
}
|
|
939
|
+
_cloneInto(to) {
|
|
940
|
+
to || (to = new this.constructor());
|
|
941
|
+
to.set(...this.get());
|
|
942
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
943
|
+
to.destroyed = destroyed;
|
|
944
|
+
to.finished = finished;
|
|
945
|
+
to.length = length;
|
|
946
|
+
to.pos = pos;
|
|
947
|
+
if (length % blockLen) to.buffer.set(buffer);
|
|
948
|
+
return to;
|
|
949
|
+
}
|
|
950
|
+
clone() {
|
|
951
|
+
return this._cloneInto();
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
exports.HashMD = HashMD;
|
|
1781
955
|
/**
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
956
|
+
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
957
|
+
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
958
|
+
*/
|
|
1785
959
|
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
1786
|
-
|
|
1787
|
-
|
|
960
|
+
exports.SHA256_IV = Uint32Array.from([
|
|
961
|
+
1779033703,
|
|
962
|
+
3144134277,
|
|
963
|
+
1013904242,
|
|
964
|
+
2773480762,
|
|
965
|
+
1359893119,
|
|
966
|
+
2600822924,
|
|
967
|
+
528734635,
|
|
968
|
+
1541459225
|
|
1788
969
|
]);
|
|
1789
970
|
/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */
|
|
1790
|
-
|
|
1791
|
-
|
|
971
|
+
exports.SHA224_IV = Uint32Array.from([
|
|
972
|
+
3238371032,
|
|
973
|
+
914150663,
|
|
974
|
+
812702999,
|
|
975
|
+
4144912697,
|
|
976
|
+
4290775857,
|
|
977
|
+
1750603025,
|
|
978
|
+
1694076839,
|
|
979
|
+
3204075428
|
|
1792
980
|
]);
|
|
1793
981
|
/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
982
|
+
exports.SHA384_IV = Uint32Array.from([
|
|
983
|
+
3418070365,
|
|
984
|
+
3238371032,
|
|
985
|
+
1654270250,
|
|
986
|
+
914150663,
|
|
987
|
+
2438529370,
|
|
988
|
+
812702999,
|
|
989
|
+
355462360,
|
|
990
|
+
4144912697,
|
|
991
|
+
1731405415,
|
|
992
|
+
4290775857,
|
|
993
|
+
2394180231,
|
|
994
|
+
1750603025,
|
|
995
|
+
3675008525,
|
|
996
|
+
1694076839,
|
|
997
|
+
1203062813,
|
|
998
|
+
3204075428
|
|
1797
999
|
]);
|
|
1798
1000
|
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1001
|
+
exports.SHA512_IV = Uint32Array.from([
|
|
1002
|
+
1779033703,
|
|
1003
|
+
4089235720,
|
|
1004
|
+
3144134277,
|
|
1005
|
+
2227873595,
|
|
1006
|
+
1013904242,
|
|
1007
|
+
4271175723,
|
|
1008
|
+
2773480762,
|
|
1009
|
+
1595750129,
|
|
1010
|
+
1359893119,
|
|
1011
|
+
2917565137,
|
|
1012
|
+
2600822924,
|
|
1013
|
+
725511199,
|
|
1014
|
+
528734635,
|
|
1015
|
+
4215389547,
|
|
1016
|
+
1541459225,
|
|
1017
|
+
327033209
|
|
1802
1018
|
]);
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
if (hasRequired_u64) return _u64;
|
|
1813
|
-
hasRequired_u64 = 1;
|
|
1814
|
-
Object.defineProperty(_u64, "__esModule", { value: true });
|
|
1815
|
-
_u64.toBig = _u64.shrSL = _u64.shrSH = _u64.rotrSL = _u64.rotrSH = _u64.rotrBL = _u64.rotrBH = _u64.rotr32L = _u64.rotr32H = _u64.rotlSL = _u64.rotlSH = _u64.rotlBL = _u64.rotlBH = _u64.add5L = _u64.add5H = _u64.add4L = _u64.add4H = _u64.add3L = _u64.add3H = void 0;
|
|
1816
|
-
_u64.add = add;
|
|
1817
|
-
_u64.fromBig = fromBig;
|
|
1818
|
-
_u64.split = split;
|
|
1019
|
+
}));
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/_u64.js
|
|
1022
|
+
var require__u64 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1023
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1024
|
+
exports.toBig = exports.shrSL = exports.shrSH = exports.rotrSL = exports.rotrSH = exports.rotrBL = exports.rotrBH = exports.rotr32L = exports.rotr32H = exports.rotlSL = exports.rotlSH = exports.rotlBL = exports.rotlBH = exports.add5L = exports.add5H = exports.add4L = exports.add4H = exports.add3L = exports.add3H = void 0;
|
|
1025
|
+
exports.add = add;
|
|
1026
|
+
exports.fromBig = fromBig;
|
|
1027
|
+
exports.split = split;
|
|
1819
1028
|
/**
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1029
|
+
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
1030
|
+
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
1031
|
+
* @module
|
|
1032
|
+
*/
|
|
1033
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
1034
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
1826
1035
|
function fromBig(n, le = false) {
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1036
|
+
if (le) return {
|
|
1037
|
+
h: Number(n & U32_MASK64),
|
|
1038
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
1039
|
+
};
|
|
1040
|
+
return {
|
|
1041
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
1042
|
+
l: Number(n & U32_MASK64) | 0
|
|
1043
|
+
};
|
|
1830
1044
|
}
|
|
1831
1045
|
function split(lst, le = false) {
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1046
|
+
const len = lst.length;
|
|
1047
|
+
let Ah = new Uint32Array(len);
|
|
1048
|
+
let Al = new Uint32Array(len);
|
|
1049
|
+
for (let i = 0; i < len; i++) {
|
|
1050
|
+
const { h, l } = fromBig(lst[i], le);
|
|
1051
|
+
[Ah[i], Al[i]] = [h, l];
|
|
1052
|
+
}
|
|
1053
|
+
return [Ah, Al];
|
|
1840
1054
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
_u64.rotlSL = rotlSL;
|
|
1868
|
-
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
1869
|
-
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
1870
|
-
_u64.rotlBH = rotlBH;
|
|
1871
|
-
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
1872
|
-
_u64.rotlBL = rotlBL;
|
|
1873
|
-
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
1874
|
-
// simple take carry out of low bit sum by shift, we need to use division.
|
|
1055
|
+
var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
|
|
1056
|
+
exports.toBig = toBig;
|
|
1057
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
1058
|
+
exports.shrSH = shrSH;
|
|
1059
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1060
|
+
exports.shrSL = shrSL;
|
|
1061
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
1062
|
+
exports.rotrSH = rotrSH;
|
|
1063
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1064
|
+
exports.rotrSL = rotrSL;
|
|
1065
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
1066
|
+
exports.rotrBH = rotrBH;
|
|
1067
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
1068
|
+
exports.rotrBL = rotrBL;
|
|
1069
|
+
var rotr32H = (_h, l) => l;
|
|
1070
|
+
exports.rotr32H = rotr32H;
|
|
1071
|
+
var rotr32L = (h, _l) => h;
|
|
1072
|
+
exports.rotr32L = rotr32L;
|
|
1073
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
1074
|
+
exports.rotlSH = rotlSH;
|
|
1075
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
1076
|
+
exports.rotlSL = rotlSL;
|
|
1077
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
1078
|
+
exports.rotlBH = rotlBH;
|
|
1079
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
1080
|
+
exports.rotlBL = rotlBL;
|
|
1875
1081
|
function add(Ah, Al, Bh, Bl) {
|
|
1876
|
-
|
|
1877
|
-
|
|
1082
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
1083
|
+
return {
|
|
1084
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
1085
|
+
l: l | 0
|
|
1086
|
+
};
|
|
1878
1087
|
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1088
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
1089
|
+
exports.add3L = add3L;
|
|
1090
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
1091
|
+
exports.add3H = add3H;
|
|
1092
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
1093
|
+
exports.add4L = add4L;
|
|
1094
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
1095
|
+
exports.add4H = add4H;
|
|
1096
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
1097
|
+
exports.add5L = add5L;
|
|
1098
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
1099
|
+
exports.add5H = add5H;
|
|
1100
|
+
exports.default = {
|
|
1101
|
+
fromBig,
|
|
1102
|
+
split,
|
|
1103
|
+
toBig,
|
|
1104
|
+
shrSH,
|
|
1105
|
+
shrSL,
|
|
1106
|
+
rotrSH,
|
|
1107
|
+
rotrSL,
|
|
1108
|
+
rotrBH,
|
|
1109
|
+
rotrBL,
|
|
1110
|
+
rotr32H,
|
|
1111
|
+
rotr32L,
|
|
1112
|
+
rotlSH,
|
|
1113
|
+
rotlSL,
|
|
1114
|
+
rotlBH,
|
|
1115
|
+
rotlBL,
|
|
1116
|
+
add,
|
|
1117
|
+
add3L,
|
|
1118
|
+
add3H,
|
|
1119
|
+
add4L,
|
|
1120
|
+
add4H,
|
|
1121
|
+
add5H,
|
|
1122
|
+
add5L
|
|
1900
1123
|
};
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
function requireSha2 () {
|
|
1909
|
-
if (hasRequiredSha2) return sha2;
|
|
1910
|
-
hasRequiredSha2 = 1;
|
|
1911
|
-
Object.defineProperty(sha2, "__esModule", { value: true });
|
|
1912
|
-
sha2.sha512_224 = sha2.sha512_256 = sha2.sha384 = sha2.sha512 = sha2.sha224 = sha2.sha256 = sha2.SHA512_256 = sha2.SHA512_224 = sha2.SHA384 = sha2.SHA512 = sha2.SHA224 = sha2.SHA256 = void 0;
|
|
1124
|
+
}));
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/sha2.js
|
|
1127
|
+
var require_sha2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1128
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1129
|
+
exports.sha512_224 = exports.sha512_256 = exports.sha384 = exports.sha512 = exports.sha224 = exports.sha256 = exports.SHA512_256 = exports.SHA512_224 = exports.SHA384 = exports.SHA512 = exports.SHA224 = exports.SHA256 = void 0;
|
|
1913
1130
|
/**
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1131
|
+
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
1132
|
+
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
1133
|
+
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
1134
|
+
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
1135
|
+
* @module
|
|
1136
|
+
*/
|
|
1137
|
+
var _md_ts_1 = require__md();
|
|
1138
|
+
var u64 = require__u64();
|
|
1139
|
+
var utils_ts_1 = require_utils();
|
|
1923
1140
|
/**
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1141
|
+
* Round constants:
|
|
1142
|
+
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
|
|
1143
|
+
*/
|
|
1144
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
1145
|
+
1116352408,
|
|
1146
|
+
1899447441,
|
|
1147
|
+
3049323471,
|
|
1148
|
+
3921009573,
|
|
1149
|
+
961987163,
|
|
1150
|
+
1508970993,
|
|
1151
|
+
2453635748,
|
|
1152
|
+
2870763221,
|
|
1153
|
+
3624381080,
|
|
1154
|
+
310598401,
|
|
1155
|
+
607225278,
|
|
1156
|
+
1426881987,
|
|
1157
|
+
1925078388,
|
|
1158
|
+
2162078206,
|
|
1159
|
+
2614888103,
|
|
1160
|
+
3248222580,
|
|
1161
|
+
3835390401,
|
|
1162
|
+
4022224774,
|
|
1163
|
+
264347078,
|
|
1164
|
+
604807628,
|
|
1165
|
+
770255983,
|
|
1166
|
+
1249150122,
|
|
1167
|
+
1555081692,
|
|
1168
|
+
1996064986,
|
|
1169
|
+
2554220882,
|
|
1170
|
+
2821834349,
|
|
1171
|
+
2952996808,
|
|
1172
|
+
3210313671,
|
|
1173
|
+
3336571891,
|
|
1174
|
+
3584528711,
|
|
1175
|
+
113926993,
|
|
1176
|
+
338241895,
|
|
1177
|
+
666307205,
|
|
1178
|
+
773529912,
|
|
1179
|
+
1294757372,
|
|
1180
|
+
1396182291,
|
|
1181
|
+
1695183700,
|
|
1182
|
+
1986661051,
|
|
1183
|
+
2177026350,
|
|
1184
|
+
2456956037,
|
|
1185
|
+
2730485921,
|
|
1186
|
+
2820302411,
|
|
1187
|
+
3259730800,
|
|
1188
|
+
3345764771,
|
|
1189
|
+
3516065817,
|
|
1190
|
+
3600352804,
|
|
1191
|
+
4094571909,
|
|
1192
|
+
275423344,
|
|
1193
|
+
430227734,
|
|
1194
|
+
506948616,
|
|
1195
|
+
659060556,
|
|
1196
|
+
883997877,
|
|
1197
|
+
958139571,
|
|
1198
|
+
1322822218,
|
|
1199
|
+
1537002063,
|
|
1200
|
+
1747873779,
|
|
1201
|
+
1955562222,
|
|
1202
|
+
2024104815,
|
|
1203
|
+
2227730452,
|
|
1204
|
+
2361852424,
|
|
1205
|
+
2428436474,
|
|
1206
|
+
2756734187,
|
|
1207
|
+
3204031479,
|
|
1208
|
+
3329325298
|
|
1937
1209
|
]);
|
|
1938
1210
|
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
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
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
1211
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
1212
|
+
var SHA256 = class extends _md_ts_1.HashMD {
|
|
1213
|
+
constructor(outputLen = 32) {
|
|
1214
|
+
super(64, outputLen, 8, false);
|
|
1215
|
+
this.A = _md_ts_1.SHA256_IV[0] | 0;
|
|
1216
|
+
this.B = _md_ts_1.SHA256_IV[1] | 0;
|
|
1217
|
+
this.C = _md_ts_1.SHA256_IV[2] | 0;
|
|
1218
|
+
this.D = _md_ts_1.SHA256_IV[3] | 0;
|
|
1219
|
+
this.E = _md_ts_1.SHA256_IV[4] | 0;
|
|
1220
|
+
this.F = _md_ts_1.SHA256_IV[5] | 0;
|
|
1221
|
+
this.G = _md_ts_1.SHA256_IV[6] | 0;
|
|
1222
|
+
this.H = _md_ts_1.SHA256_IV[7] | 0;
|
|
1223
|
+
}
|
|
1224
|
+
get() {
|
|
1225
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
1226
|
+
return [
|
|
1227
|
+
A,
|
|
1228
|
+
B,
|
|
1229
|
+
C,
|
|
1230
|
+
D,
|
|
1231
|
+
E,
|
|
1232
|
+
F,
|
|
1233
|
+
G,
|
|
1234
|
+
H
|
|
1235
|
+
];
|
|
1236
|
+
}
|
|
1237
|
+
set(A, B, C, D, E, F, G, H) {
|
|
1238
|
+
this.A = A | 0;
|
|
1239
|
+
this.B = B | 0;
|
|
1240
|
+
this.C = C | 0;
|
|
1241
|
+
this.D = D | 0;
|
|
1242
|
+
this.E = E | 0;
|
|
1243
|
+
this.F = F | 0;
|
|
1244
|
+
this.G = G | 0;
|
|
1245
|
+
this.H = H | 0;
|
|
1246
|
+
}
|
|
1247
|
+
process(view, offset) {
|
|
1248
|
+
for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
|
|
1249
|
+
for (let i = 16; i < 64; i++) {
|
|
1250
|
+
const W15 = SHA256_W[i - 15];
|
|
1251
|
+
const W2 = SHA256_W[i - 2];
|
|
1252
|
+
const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
|
|
1253
|
+
SHA256_W[i] = ((0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10) + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
1254
|
+
}
|
|
1255
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
1256
|
+
for (let i = 0; i < 64; i++) {
|
|
1257
|
+
const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
|
|
1258
|
+
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
1259
|
+
const T2 = ((0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22)) + (0, _md_ts_1.Maj)(A, B, C) | 0;
|
|
1260
|
+
H = G;
|
|
1261
|
+
G = F;
|
|
1262
|
+
F = E;
|
|
1263
|
+
E = D + T1 | 0;
|
|
1264
|
+
D = C;
|
|
1265
|
+
C = B;
|
|
1266
|
+
B = A;
|
|
1267
|
+
A = T1 + T2 | 0;
|
|
1268
|
+
}
|
|
1269
|
+
A = A + this.A | 0;
|
|
1270
|
+
B = B + this.B | 0;
|
|
1271
|
+
C = C + this.C | 0;
|
|
1272
|
+
D = D + this.D | 0;
|
|
1273
|
+
E = E + this.E | 0;
|
|
1274
|
+
F = F + this.F | 0;
|
|
1275
|
+
G = G + this.G | 0;
|
|
1276
|
+
H = H + this.H | 0;
|
|
1277
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
1278
|
+
}
|
|
1279
|
+
roundClean() {
|
|
1280
|
+
(0, utils_ts_1.clean)(SHA256_W);
|
|
1281
|
+
}
|
|
1282
|
+
destroy() {
|
|
1283
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
1284
|
+
(0, utils_ts_1.clean)(this.buffer);
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
exports.SHA256 = SHA256;
|
|
1288
|
+
var SHA224 = class extends SHA256 {
|
|
1289
|
+
constructor() {
|
|
1290
|
+
super(28);
|
|
1291
|
+
this.A = _md_ts_1.SHA224_IV[0] | 0;
|
|
1292
|
+
this.B = _md_ts_1.SHA224_IV[1] | 0;
|
|
1293
|
+
this.C = _md_ts_1.SHA224_IV[2] | 0;
|
|
1294
|
+
this.D = _md_ts_1.SHA224_IV[3] | 0;
|
|
1295
|
+
this.E = _md_ts_1.SHA224_IV[4] | 0;
|
|
1296
|
+
this.F = _md_ts_1.SHA224_IV[5] | 0;
|
|
1297
|
+
this.G = _md_ts_1.SHA224_IV[6] | 0;
|
|
1298
|
+
this.H = _md_ts_1.SHA224_IV[7] | 0;
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
exports.SHA224 = SHA224;
|
|
1302
|
+
var K512 = u64.split([
|
|
1303
|
+
"0x428a2f98d728ae22",
|
|
1304
|
+
"0x7137449123ef65cd",
|
|
1305
|
+
"0xb5c0fbcfec4d3b2f",
|
|
1306
|
+
"0xe9b5dba58189dbbc",
|
|
1307
|
+
"0x3956c25bf348b538",
|
|
1308
|
+
"0x59f111f1b605d019",
|
|
1309
|
+
"0x923f82a4af194f9b",
|
|
1310
|
+
"0xab1c5ed5da6d8118",
|
|
1311
|
+
"0xd807aa98a3030242",
|
|
1312
|
+
"0x12835b0145706fbe",
|
|
1313
|
+
"0x243185be4ee4b28c",
|
|
1314
|
+
"0x550c7dc3d5ffb4e2",
|
|
1315
|
+
"0x72be5d74f27b896f",
|
|
1316
|
+
"0x80deb1fe3b1696b1",
|
|
1317
|
+
"0x9bdc06a725c71235",
|
|
1318
|
+
"0xc19bf174cf692694",
|
|
1319
|
+
"0xe49b69c19ef14ad2",
|
|
1320
|
+
"0xefbe4786384f25e3",
|
|
1321
|
+
"0x0fc19dc68b8cd5b5",
|
|
1322
|
+
"0x240ca1cc77ac9c65",
|
|
1323
|
+
"0x2de92c6f592b0275",
|
|
1324
|
+
"0x4a7484aa6ea6e483",
|
|
1325
|
+
"0x5cb0a9dcbd41fbd4",
|
|
1326
|
+
"0x76f988da831153b5",
|
|
1327
|
+
"0x983e5152ee66dfab",
|
|
1328
|
+
"0xa831c66d2db43210",
|
|
1329
|
+
"0xb00327c898fb213f",
|
|
1330
|
+
"0xbf597fc7beef0ee4",
|
|
1331
|
+
"0xc6e00bf33da88fc2",
|
|
1332
|
+
"0xd5a79147930aa725",
|
|
1333
|
+
"0x06ca6351e003826f",
|
|
1334
|
+
"0x142929670a0e6e70",
|
|
1335
|
+
"0x27b70a8546d22ffc",
|
|
1336
|
+
"0x2e1b21385c26c926",
|
|
1337
|
+
"0x4d2c6dfc5ac42aed",
|
|
1338
|
+
"0x53380d139d95b3df",
|
|
1339
|
+
"0x650a73548baf63de",
|
|
1340
|
+
"0x766a0abb3c77b2a8",
|
|
1341
|
+
"0x81c2c92e47edaee6",
|
|
1342
|
+
"0x92722c851482353b",
|
|
1343
|
+
"0xa2bfe8a14cf10364",
|
|
1344
|
+
"0xa81a664bbc423001",
|
|
1345
|
+
"0xc24b8b70d0f89791",
|
|
1346
|
+
"0xc76c51a30654be30",
|
|
1347
|
+
"0xd192e819d6ef5218",
|
|
1348
|
+
"0xd69906245565a910",
|
|
1349
|
+
"0xf40e35855771202a",
|
|
1350
|
+
"0x106aa07032bbd1b8",
|
|
1351
|
+
"0x19a4c116b8d2d0c8",
|
|
1352
|
+
"0x1e376c085141ab53",
|
|
1353
|
+
"0x2748774cdf8eeb99",
|
|
1354
|
+
"0x34b0bcb5e19b48a8",
|
|
1355
|
+
"0x391c0cb3c5c95a63",
|
|
1356
|
+
"0x4ed8aa4ae3418acb",
|
|
1357
|
+
"0x5b9cca4f7763e373",
|
|
1358
|
+
"0x682e6ff3d6b2b8a3",
|
|
1359
|
+
"0x748f82ee5defb2fc",
|
|
1360
|
+
"0x78a5636f43172f60",
|
|
1361
|
+
"0x84c87814a1f0ab72",
|
|
1362
|
+
"0x8cc702081a6439ec",
|
|
1363
|
+
"0x90befffa23631e28",
|
|
1364
|
+
"0xa4506cebde82bde9",
|
|
1365
|
+
"0xbef9a3f7b2c67915",
|
|
1366
|
+
"0xc67178f2e372532b",
|
|
1367
|
+
"0xca273eceea26619c",
|
|
1368
|
+
"0xd186b8c721c0c207",
|
|
1369
|
+
"0xeada7dd6cde0eb1e",
|
|
1370
|
+
"0xf57d4f7fee6ed178",
|
|
1371
|
+
"0x06f067aa72176fba",
|
|
1372
|
+
"0x0a637dc5a2c898a6",
|
|
1373
|
+
"0x113f9804bef90dae",
|
|
1374
|
+
"0x1b710b35131c471b",
|
|
1375
|
+
"0x28db77f523047d84",
|
|
1376
|
+
"0x32caab7b40c72493",
|
|
1377
|
+
"0x3c9ebe0a15c9bebc",
|
|
1378
|
+
"0x431d67c49c100d4c",
|
|
1379
|
+
"0x4cc5d4becb3e42b6",
|
|
1380
|
+
"0x597f299cfc657e2a",
|
|
1381
|
+
"0x5fcb6fab3ad6faec",
|
|
1382
|
+
"0x6c44198c4a475817"
|
|
1383
|
+
].map((n) => BigInt(n)));
|
|
1384
|
+
var SHA512_Kh = K512[0];
|
|
1385
|
+
var SHA512_Kl = K512[1];
|
|
1386
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
1387
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
1388
|
+
var SHA512 = class extends _md_ts_1.HashMD {
|
|
1389
|
+
constructor(outputLen = 64) {
|
|
1390
|
+
super(128, outputLen, 16, false);
|
|
1391
|
+
this.Ah = _md_ts_1.SHA512_IV[0] | 0;
|
|
1392
|
+
this.Al = _md_ts_1.SHA512_IV[1] | 0;
|
|
1393
|
+
this.Bh = _md_ts_1.SHA512_IV[2] | 0;
|
|
1394
|
+
this.Bl = _md_ts_1.SHA512_IV[3] | 0;
|
|
1395
|
+
this.Ch = _md_ts_1.SHA512_IV[4] | 0;
|
|
1396
|
+
this.Cl = _md_ts_1.SHA512_IV[5] | 0;
|
|
1397
|
+
this.Dh = _md_ts_1.SHA512_IV[6] | 0;
|
|
1398
|
+
this.Dl = _md_ts_1.SHA512_IV[7] | 0;
|
|
1399
|
+
this.Eh = _md_ts_1.SHA512_IV[8] | 0;
|
|
1400
|
+
this.El = _md_ts_1.SHA512_IV[9] | 0;
|
|
1401
|
+
this.Fh = _md_ts_1.SHA512_IV[10] | 0;
|
|
1402
|
+
this.Fl = _md_ts_1.SHA512_IV[11] | 0;
|
|
1403
|
+
this.Gh = _md_ts_1.SHA512_IV[12] | 0;
|
|
1404
|
+
this.Gl = _md_ts_1.SHA512_IV[13] | 0;
|
|
1405
|
+
this.Hh = _md_ts_1.SHA512_IV[14] | 0;
|
|
1406
|
+
this.Hl = _md_ts_1.SHA512_IV[15] | 0;
|
|
1407
|
+
}
|
|
1408
|
+
get() {
|
|
1409
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1410
|
+
return [
|
|
1411
|
+
Ah,
|
|
1412
|
+
Al,
|
|
1413
|
+
Bh,
|
|
1414
|
+
Bl,
|
|
1415
|
+
Ch,
|
|
1416
|
+
Cl,
|
|
1417
|
+
Dh,
|
|
1418
|
+
Dl,
|
|
1419
|
+
Eh,
|
|
1420
|
+
El,
|
|
1421
|
+
Fh,
|
|
1422
|
+
Fl,
|
|
1423
|
+
Gh,
|
|
1424
|
+
Gl,
|
|
1425
|
+
Hh,
|
|
1426
|
+
Hl
|
|
1427
|
+
];
|
|
1428
|
+
}
|
|
1429
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
1430
|
+
this.Ah = Ah | 0;
|
|
1431
|
+
this.Al = Al | 0;
|
|
1432
|
+
this.Bh = Bh | 0;
|
|
1433
|
+
this.Bl = Bl | 0;
|
|
1434
|
+
this.Ch = Ch | 0;
|
|
1435
|
+
this.Cl = Cl | 0;
|
|
1436
|
+
this.Dh = Dh | 0;
|
|
1437
|
+
this.Dl = Dl | 0;
|
|
1438
|
+
this.Eh = Eh | 0;
|
|
1439
|
+
this.El = El | 0;
|
|
1440
|
+
this.Fh = Fh | 0;
|
|
1441
|
+
this.Fl = Fl | 0;
|
|
1442
|
+
this.Gh = Gh | 0;
|
|
1443
|
+
this.Gl = Gl | 0;
|
|
1444
|
+
this.Hh = Hh | 0;
|
|
1445
|
+
this.Hl = Hl | 0;
|
|
1446
|
+
}
|
|
1447
|
+
process(view, offset) {
|
|
1448
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
1449
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
1450
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
1451
|
+
}
|
|
1452
|
+
for (let i = 16; i < 80; i++) {
|
|
1453
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
1454
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
1455
|
+
const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
|
|
1456
|
+
const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
|
|
1457
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
1458
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
1459
|
+
const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
|
|
1460
|
+
const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
|
|
1461
|
+
const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
1462
|
+
SHA512_W_H[i] = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]) | 0;
|
|
1463
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
1464
|
+
}
|
|
1465
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1466
|
+
for (let i = 0; i < 80; i++) {
|
|
1467
|
+
const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
|
|
1468
|
+
const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
|
|
1469
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
1470
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
1471
|
+
const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
1472
|
+
const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
1473
|
+
const T1l = T1ll | 0;
|
|
1474
|
+
const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
|
|
1475
|
+
const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
|
|
1476
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
1477
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
1478
|
+
Hh = Gh | 0;
|
|
1479
|
+
Hl = Gl | 0;
|
|
1480
|
+
Gh = Fh | 0;
|
|
1481
|
+
Gl = Fl | 0;
|
|
1482
|
+
Fh = Eh | 0;
|
|
1483
|
+
Fl = El | 0;
|
|
1484
|
+
({h: Eh, l: El} = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1485
|
+
Dh = Ch | 0;
|
|
1486
|
+
Dl = Cl | 0;
|
|
1487
|
+
Ch = Bh | 0;
|
|
1488
|
+
Cl = Bl | 0;
|
|
1489
|
+
Bh = Ah | 0;
|
|
1490
|
+
Bl = Al | 0;
|
|
1491
|
+
const All = u64.add3L(T1l, sigma0l, MAJl);
|
|
1492
|
+
Ah = u64.add3H(All, T1h, sigma0h, MAJh);
|
|
1493
|
+
Al = All | 0;
|
|
1494
|
+
}
|
|
1495
|
+
({h: Ah, l: Al} = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1496
|
+
({h: Bh, l: Bl} = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1497
|
+
({h: Ch, l: Cl} = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1498
|
+
({h: Dh, l: Dl} = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1499
|
+
({h: Eh, l: El} = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1500
|
+
({h: Fh, l: Fl} = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1501
|
+
({h: Gh, l: Gl} = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1502
|
+
({h: Hh, l: Hl} = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1503
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1504
|
+
}
|
|
1505
|
+
roundClean() {
|
|
1506
|
+
(0, utils_ts_1.clean)(SHA512_W_H, SHA512_W_L);
|
|
1507
|
+
}
|
|
1508
|
+
destroy() {
|
|
1509
|
+
(0, utils_ts_1.clean)(this.buffer);
|
|
1510
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
exports.SHA512 = SHA512;
|
|
1514
|
+
var SHA384 = class extends SHA512 {
|
|
1515
|
+
constructor() {
|
|
1516
|
+
super(48);
|
|
1517
|
+
this.Ah = _md_ts_1.SHA384_IV[0] | 0;
|
|
1518
|
+
this.Al = _md_ts_1.SHA384_IV[1] | 0;
|
|
1519
|
+
this.Bh = _md_ts_1.SHA384_IV[2] | 0;
|
|
1520
|
+
this.Bl = _md_ts_1.SHA384_IV[3] | 0;
|
|
1521
|
+
this.Ch = _md_ts_1.SHA384_IV[4] | 0;
|
|
1522
|
+
this.Cl = _md_ts_1.SHA384_IV[5] | 0;
|
|
1523
|
+
this.Dh = _md_ts_1.SHA384_IV[6] | 0;
|
|
1524
|
+
this.Dl = _md_ts_1.SHA384_IV[7] | 0;
|
|
1525
|
+
this.Eh = _md_ts_1.SHA384_IV[8] | 0;
|
|
1526
|
+
this.El = _md_ts_1.SHA384_IV[9] | 0;
|
|
1527
|
+
this.Fh = _md_ts_1.SHA384_IV[10] | 0;
|
|
1528
|
+
this.Fl = _md_ts_1.SHA384_IV[11] | 0;
|
|
1529
|
+
this.Gh = _md_ts_1.SHA384_IV[12] | 0;
|
|
1530
|
+
this.Gl = _md_ts_1.SHA384_IV[13] | 0;
|
|
1531
|
+
this.Hh = _md_ts_1.SHA384_IV[14] | 0;
|
|
1532
|
+
this.Hl = _md_ts_1.SHA384_IV[15] | 0;
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
exports.SHA384 = SHA384;
|
|
2209
1536
|
/**
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
1537
|
+
* Truncated SHA512/256 and SHA512/224.
|
|
1538
|
+
* SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as "intermediary" IV of SHA512/t.
|
|
1539
|
+
* Then t hashes string to produce result IV.
|
|
1540
|
+
* See `test/misc/sha2-gen-iv.js`.
|
|
1541
|
+
*/
|
|
2215
1542
|
/** SHA512/224 IV */
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
1543
|
+
var T224_IV = /* @__PURE__ */ Uint32Array.from([
|
|
1544
|
+
2352822216,
|
|
1545
|
+
424955298,
|
|
1546
|
+
1944164710,
|
|
1547
|
+
2312950998,
|
|
1548
|
+
502970286,
|
|
1549
|
+
855612546,
|
|
1550
|
+
1738396948,
|
|
1551
|
+
1479516111,
|
|
1552
|
+
258812777,
|
|
1553
|
+
2077511080,
|
|
1554
|
+
2011393907,
|
|
1555
|
+
79989058,
|
|
1556
|
+
1067287976,
|
|
1557
|
+
1780299464,
|
|
1558
|
+
286451373,
|
|
1559
|
+
2446758561
|
|
2219
1560
|
]);
|
|
2220
1561
|
/** SHA512/256 IV */
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
1562
|
+
var T256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
1563
|
+
573645204,
|
|
1564
|
+
4230739756,
|
|
1565
|
+
2673172387,
|
|
1566
|
+
3360449730,
|
|
1567
|
+
596883563,
|
|
1568
|
+
1867755857,
|
|
1569
|
+
2520282905,
|
|
1570
|
+
1497426621,
|
|
1571
|
+
2519219938,
|
|
1572
|
+
2827943907,
|
|
1573
|
+
3193839141,
|
|
1574
|
+
1401305490,
|
|
1575
|
+
721525244,
|
|
1576
|
+
746961066,
|
|
1577
|
+
246885852,
|
|
1578
|
+
2177182882
|
|
2224
1579
|
]);
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
}
|
|
2268
|
-
|
|
1580
|
+
var SHA512_224 = class extends SHA512 {
|
|
1581
|
+
constructor() {
|
|
1582
|
+
super(28);
|
|
1583
|
+
this.Ah = T224_IV[0] | 0;
|
|
1584
|
+
this.Al = T224_IV[1] | 0;
|
|
1585
|
+
this.Bh = T224_IV[2] | 0;
|
|
1586
|
+
this.Bl = T224_IV[3] | 0;
|
|
1587
|
+
this.Ch = T224_IV[4] | 0;
|
|
1588
|
+
this.Cl = T224_IV[5] | 0;
|
|
1589
|
+
this.Dh = T224_IV[6] | 0;
|
|
1590
|
+
this.Dl = T224_IV[7] | 0;
|
|
1591
|
+
this.Eh = T224_IV[8] | 0;
|
|
1592
|
+
this.El = T224_IV[9] | 0;
|
|
1593
|
+
this.Fh = T224_IV[10] | 0;
|
|
1594
|
+
this.Fl = T224_IV[11] | 0;
|
|
1595
|
+
this.Gh = T224_IV[12] | 0;
|
|
1596
|
+
this.Gl = T224_IV[13] | 0;
|
|
1597
|
+
this.Hh = T224_IV[14] | 0;
|
|
1598
|
+
this.Hl = T224_IV[15] | 0;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
exports.SHA512_224 = SHA512_224;
|
|
1602
|
+
var SHA512_256 = class extends SHA512 {
|
|
1603
|
+
constructor() {
|
|
1604
|
+
super(32);
|
|
1605
|
+
this.Ah = T256_IV[0] | 0;
|
|
1606
|
+
this.Al = T256_IV[1] | 0;
|
|
1607
|
+
this.Bh = T256_IV[2] | 0;
|
|
1608
|
+
this.Bl = T256_IV[3] | 0;
|
|
1609
|
+
this.Ch = T256_IV[4] | 0;
|
|
1610
|
+
this.Cl = T256_IV[5] | 0;
|
|
1611
|
+
this.Dh = T256_IV[6] | 0;
|
|
1612
|
+
this.Dl = T256_IV[7] | 0;
|
|
1613
|
+
this.Eh = T256_IV[8] | 0;
|
|
1614
|
+
this.El = T256_IV[9] | 0;
|
|
1615
|
+
this.Fh = T256_IV[10] | 0;
|
|
1616
|
+
this.Fl = T256_IV[11] | 0;
|
|
1617
|
+
this.Gh = T256_IV[12] | 0;
|
|
1618
|
+
this.Gl = T256_IV[13] | 0;
|
|
1619
|
+
this.Hh = T256_IV[14] | 0;
|
|
1620
|
+
this.Hl = T256_IV[15] | 0;
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
exports.SHA512_256 = SHA512_256;
|
|
2269
1624
|
/**
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
1625
|
+
* SHA2-256 hash function from RFC 4634.
|
|
1626
|
+
*
|
|
1627
|
+
* It is the fastest JS hash, even faster than Blake3.
|
|
1628
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
1629
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
1630
|
+
*/
|
|
1631
|
+
exports.sha256 = (0, utils_ts_1.createHasher)(() => new SHA256());
|
|
2277
1632
|
/** SHA2-224 hash function from RFC 4634 */
|
|
2278
|
-
|
|
1633
|
+
exports.sha224 = (0, utils_ts_1.createHasher)(() => new SHA224());
|
|
2279
1634
|
/** SHA2-512 hash function from RFC 4634. */
|
|
2280
|
-
|
|
1635
|
+
exports.sha512 = (0, utils_ts_1.createHasher)(() => new SHA512());
|
|
2281
1636
|
/** SHA2-384 hash function from RFC 4634. */
|
|
2282
|
-
|
|
1637
|
+
exports.sha384 = (0, utils_ts_1.createHasher)(() => new SHA384());
|
|
2283
1638
|
/**
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
1639
|
+
* SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
|
|
1640
|
+
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
1641
|
+
*/
|
|
1642
|
+
exports.sha512_256 = (0, utils_ts_1.createHasher)(() => new SHA512_256());
|
|
2288
1643
|
/**
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
function requireSha256 () {
|
|
2300
|
-
if (hasRequiredSha256) return sha256;
|
|
2301
|
-
hasRequiredSha256 = 1;
|
|
2302
|
-
Object.defineProperty(sha256, "__esModule", { value: true });
|
|
2303
|
-
sha256.sha224 = sha256.SHA224 = sha256.sha256 = sha256.SHA256 = void 0;
|
|
1644
|
+
* SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
|
|
1645
|
+
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
1646
|
+
*/
|
|
1647
|
+
exports.sha512_224 = (0, utils_ts_1.createHasher)(() => new SHA512_224());
|
|
1648
|
+
}));
|
|
1649
|
+
//#endregion
|
|
1650
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/sha256.js
|
|
1651
|
+
var require_sha256 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1652
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1653
|
+
exports.sha224 = exports.SHA224 = exports.sha256 = exports.SHA256 = void 0;
|
|
2304
1654
|
/**
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
1655
|
+
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
|
1656
|
+
*
|
|
1657
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
1658
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
1659
|
+
*
|
|
1660
|
+
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
1661
|
+
* @module
|
|
1662
|
+
* @deprecated
|
|
1663
|
+
*/
|
|
1664
|
+
var sha2_ts_1 = require_sha2();
|
|
2315
1665
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2316
|
-
|
|
1666
|
+
exports.SHA256 = sha2_ts_1.SHA256;
|
|
2317
1667
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2318
|
-
|
|
1668
|
+
exports.sha256 = sha2_ts_1.sha256;
|
|
2319
1669
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2320
|
-
|
|
1670
|
+
exports.SHA224 = sha2_ts_1.SHA224;
|
|
2321
1671
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
var hasRequiredSha512;
|
|
2330
|
-
|
|
2331
|
-
function requireSha512 () {
|
|
2332
|
-
if (hasRequiredSha512) return sha512;
|
|
2333
|
-
hasRequiredSha512 = 1;
|
|
2334
|
-
Object.defineProperty(sha512, "__esModule", { value: true });
|
|
2335
|
-
sha512.sha512_256 = sha512.SHA512_256 = sha512.sha512_224 = sha512.SHA512_224 = sha512.sha384 = sha512.SHA384 = sha512.sha512 = sha512.SHA512 = void 0;
|
|
1672
|
+
exports.sha224 = sha2_ts_1.sha224;
|
|
1673
|
+
}));
|
|
1674
|
+
//#endregion
|
|
1675
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/sha512.js
|
|
1676
|
+
var require_sha512 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1677
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1678
|
+
exports.sha512_256 = exports.SHA512_256 = exports.sha512_224 = exports.SHA512_224 = exports.sha384 = exports.SHA384 = exports.sha512 = exports.SHA512 = void 0;
|
|
2336
1679
|
/**
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
1680
|
+
* SHA2-512 a.k.a. sha512 and sha384. It is slower than sha256 in js because u64 operations are slow.
|
|
1681
|
+
*
|
|
1682
|
+
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
1683
|
+
* [the paper on truncated SHA512/256](https://eprint.iacr.org/2010/548.pdf).
|
|
1684
|
+
* @module
|
|
1685
|
+
* @deprecated
|
|
1686
|
+
*/
|
|
1687
|
+
var sha2_ts_1 = require_sha2();
|
|
2345
1688
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2346
|
-
|
|
1689
|
+
exports.SHA512 = sha2_ts_1.SHA512;
|
|
2347
1690
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2348
|
-
|
|
1691
|
+
exports.sha512 = sha2_ts_1.sha512;
|
|
2349
1692
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2350
|
-
|
|
1693
|
+
exports.SHA384 = sha2_ts_1.SHA384;
|
|
2351
1694
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2352
|
-
|
|
1695
|
+
exports.sha384 = sha2_ts_1.sha384;
|
|
2353
1696
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2354
|
-
|
|
1697
|
+
exports.SHA512_224 = sha2_ts_1.SHA512_224;
|
|
2355
1698
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2356
|
-
|
|
1699
|
+
exports.sha512_224 = sha2_ts_1.sha512_224;
|
|
2357
1700
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2358
|
-
|
|
1701
|
+
exports.SHA512_256 = sha2_ts_1.SHA512_256;
|
|
2359
1702
|
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
var hmac = {};
|
|
2368
|
-
|
|
2369
|
-
var hasRequiredHmac;
|
|
2370
|
-
|
|
2371
|
-
function requireHmac () {
|
|
2372
|
-
if (hasRequiredHmac) return hmac;
|
|
2373
|
-
hasRequiredHmac = 1;
|
|
2374
|
-
(function (exports$1) {
|
|
2375
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
2376
|
-
exports$1.hmac = exports$1.HMAC = void 0;
|
|
2377
|
-
/**
|
|
2378
|
-
* HMAC: RFC2104 message authentication code.
|
|
2379
|
-
* @module
|
|
2380
|
-
*/
|
|
2381
|
-
const utils_ts_1 = /*@__PURE__*/ requireUtils();
|
|
2382
|
-
class HMAC extends utils_ts_1.Hash {
|
|
2383
|
-
constructor(hash, _key) {
|
|
2384
|
-
super();
|
|
2385
|
-
this.finished = false;
|
|
2386
|
-
this.destroyed = false;
|
|
2387
|
-
(0, utils_ts_1.ahash)(hash);
|
|
2388
|
-
const key = (0, utils_ts_1.toBytes)(_key);
|
|
2389
|
-
this.iHash = hash.create();
|
|
2390
|
-
if (typeof this.iHash.update !== 'function')
|
|
2391
|
-
throw new Error('Expected instance of class which extends utils.Hash');
|
|
2392
|
-
this.blockLen = this.iHash.blockLen;
|
|
2393
|
-
this.outputLen = this.iHash.outputLen;
|
|
2394
|
-
const blockLen = this.blockLen;
|
|
2395
|
-
const pad = new Uint8Array(blockLen);
|
|
2396
|
-
// blockLen can be bigger than outputLen
|
|
2397
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
2398
|
-
for (let i = 0; i < pad.length; i++)
|
|
2399
|
-
pad[i] ^= 0x36;
|
|
2400
|
-
this.iHash.update(pad);
|
|
2401
|
-
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
|
2402
|
-
this.oHash = hash.create();
|
|
2403
|
-
// Undo internal XOR && apply outer XOR
|
|
2404
|
-
for (let i = 0; i < pad.length; i++)
|
|
2405
|
-
pad[i] ^= 0x36 ^ 0x5c;
|
|
2406
|
-
this.oHash.update(pad);
|
|
2407
|
-
(0, utils_ts_1.clean)(pad);
|
|
2408
|
-
}
|
|
2409
|
-
update(buf) {
|
|
2410
|
-
(0, utils_ts_1.aexists)(this);
|
|
2411
|
-
this.iHash.update(buf);
|
|
2412
|
-
return this;
|
|
2413
|
-
}
|
|
2414
|
-
digestInto(out) {
|
|
2415
|
-
(0, utils_ts_1.aexists)(this);
|
|
2416
|
-
(0, utils_ts_1.abytes)(out, this.outputLen);
|
|
2417
|
-
this.finished = true;
|
|
2418
|
-
this.iHash.digestInto(out);
|
|
2419
|
-
this.oHash.update(out);
|
|
2420
|
-
this.oHash.digestInto(out);
|
|
2421
|
-
this.destroy();
|
|
2422
|
-
}
|
|
2423
|
-
digest() {
|
|
2424
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
2425
|
-
this.digestInto(out);
|
|
2426
|
-
return out;
|
|
2427
|
-
}
|
|
2428
|
-
_cloneInto(to) {
|
|
2429
|
-
// Create new instance without calling constructor since key already in state and we don't know it.
|
|
2430
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
2431
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
2432
|
-
to = to;
|
|
2433
|
-
to.finished = finished;
|
|
2434
|
-
to.destroyed = destroyed;
|
|
2435
|
-
to.blockLen = blockLen;
|
|
2436
|
-
to.outputLen = outputLen;
|
|
2437
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
2438
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
2439
|
-
return to;
|
|
2440
|
-
}
|
|
2441
|
-
clone() {
|
|
2442
|
-
return this._cloneInto();
|
|
2443
|
-
}
|
|
2444
|
-
destroy() {
|
|
2445
|
-
this.destroyed = true;
|
|
2446
|
-
this.oHash.destroy();
|
|
2447
|
-
this.iHash.destroy();
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
exports$1.HMAC = HMAC;
|
|
2451
|
-
/**
|
|
2452
|
-
* HMAC: RFC2104 message authentication code.
|
|
2453
|
-
* @param hash - function that would be used e.g. sha256
|
|
2454
|
-
* @param key - message key
|
|
2455
|
-
* @param message - message data
|
|
2456
|
-
* @example
|
|
2457
|
-
* import { hmac } from '@noble/hashes/hmac';
|
|
2458
|
-
* import { sha256 } from '@noble/hashes/sha2';
|
|
2459
|
-
* const mac1 = hmac(sha256, 'key', 'message');
|
|
2460
|
-
*/
|
|
2461
|
-
const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
2462
|
-
exports$1.hmac = hmac;
|
|
2463
|
-
exports$1.hmac.create = (hash, key) => new HMAC(hash, key);
|
|
2464
|
-
|
|
2465
|
-
} (hmac));
|
|
2466
|
-
return hmac;
|
|
2467
|
-
}
|
|
2468
|
-
|
|
2469
|
-
var hasRequiredPbkdf2;
|
|
2470
|
-
|
|
2471
|
-
function requirePbkdf2 () {
|
|
2472
|
-
if (hasRequiredPbkdf2) return pbkdf2;
|
|
2473
|
-
hasRequiredPbkdf2 = 1;
|
|
2474
|
-
Object.defineProperty(pbkdf2, "__esModule", { value: true });
|
|
2475
|
-
pbkdf2.pbkdf2 = pbkdf2$1;
|
|
2476
|
-
pbkdf2.pbkdf2Async = pbkdf2Async;
|
|
1703
|
+
exports.sha512_256 = sha2_ts_1.sha512_256;
|
|
1704
|
+
}));
|
|
1705
|
+
//#endregion
|
|
1706
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/hmac.js
|
|
1707
|
+
var require_hmac = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1708
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1709
|
+
exports.hmac = exports.HMAC = void 0;
|
|
2477
1710
|
/**
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
1711
|
+
* HMAC: RFC2104 message authentication code.
|
|
1712
|
+
* @module
|
|
1713
|
+
*/
|
|
1714
|
+
var utils_ts_1 = require_utils();
|
|
1715
|
+
var HMAC = class extends utils_ts_1.Hash {
|
|
1716
|
+
constructor(hash, _key) {
|
|
1717
|
+
super();
|
|
1718
|
+
this.finished = false;
|
|
1719
|
+
this.destroyed = false;
|
|
1720
|
+
(0, utils_ts_1.ahash)(hash);
|
|
1721
|
+
const key = (0, utils_ts_1.toBytes)(_key);
|
|
1722
|
+
this.iHash = hash.create();
|
|
1723
|
+
if (typeof this.iHash.update !== "function") throw new Error("Expected instance of class which extends utils.Hash");
|
|
1724
|
+
this.blockLen = this.iHash.blockLen;
|
|
1725
|
+
this.outputLen = this.iHash.outputLen;
|
|
1726
|
+
const blockLen = this.blockLen;
|
|
1727
|
+
const pad = new Uint8Array(blockLen);
|
|
1728
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
1729
|
+
for (let i = 0; i < pad.length; i++) pad[i] ^= 54;
|
|
1730
|
+
this.iHash.update(pad);
|
|
1731
|
+
this.oHash = hash.create();
|
|
1732
|
+
for (let i = 0; i < pad.length; i++) pad[i] ^= 106;
|
|
1733
|
+
this.oHash.update(pad);
|
|
1734
|
+
(0, utils_ts_1.clean)(pad);
|
|
1735
|
+
}
|
|
1736
|
+
update(buf) {
|
|
1737
|
+
(0, utils_ts_1.aexists)(this);
|
|
1738
|
+
this.iHash.update(buf);
|
|
1739
|
+
return this;
|
|
1740
|
+
}
|
|
1741
|
+
digestInto(out) {
|
|
1742
|
+
(0, utils_ts_1.aexists)(this);
|
|
1743
|
+
(0, utils_ts_1.abytes)(out, this.outputLen);
|
|
1744
|
+
this.finished = true;
|
|
1745
|
+
this.iHash.digestInto(out);
|
|
1746
|
+
this.oHash.update(out);
|
|
1747
|
+
this.oHash.digestInto(out);
|
|
1748
|
+
this.destroy();
|
|
1749
|
+
}
|
|
1750
|
+
digest() {
|
|
1751
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
1752
|
+
this.digestInto(out);
|
|
1753
|
+
return out;
|
|
1754
|
+
}
|
|
1755
|
+
_cloneInto(to) {
|
|
1756
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
1757
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
1758
|
+
to = to;
|
|
1759
|
+
to.finished = finished;
|
|
1760
|
+
to.destroyed = destroyed;
|
|
1761
|
+
to.blockLen = blockLen;
|
|
1762
|
+
to.outputLen = outputLen;
|
|
1763
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
1764
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
1765
|
+
return to;
|
|
1766
|
+
}
|
|
1767
|
+
clone() {
|
|
1768
|
+
return this._cloneInto();
|
|
1769
|
+
}
|
|
1770
|
+
destroy() {
|
|
1771
|
+
this.destroyed = true;
|
|
1772
|
+
this.oHash.destroy();
|
|
1773
|
+
this.iHash.destroy();
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
exports.HMAC = HMAC;
|
|
1777
|
+
/**
|
|
1778
|
+
* HMAC: RFC2104 message authentication code.
|
|
1779
|
+
* @param hash - function that would be used e.g. sha256
|
|
1780
|
+
* @param key - message key
|
|
1781
|
+
* @param message - message data
|
|
1782
|
+
* @example
|
|
1783
|
+
* import { hmac } from '@noble/hashes/hmac';
|
|
1784
|
+
* import { sha256 } from '@noble/hashes/sha2';
|
|
1785
|
+
* const mac1 = hmac(sha256, 'key', 'message');
|
|
1786
|
+
*/
|
|
1787
|
+
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
1788
|
+
exports.hmac = hmac;
|
|
1789
|
+
exports.hmac.create = (hash, key) => new HMAC(hash, key);
|
|
1790
|
+
}));
|
|
1791
|
+
//#endregion
|
|
1792
|
+
//#region node_modules/bip39/node_modules/@noble/hashes/pbkdf2.js
|
|
1793
|
+
var require_pbkdf2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1794
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1795
|
+
exports.pbkdf2 = pbkdf2;
|
|
1796
|
+
exports.pbkdf2Async = pbkdf2Async;
|
|
1797
|
+
/**
|
|
1798
|
+
* PBKDF (RFC 2898). Can be used to create a key from password and salt.
|
|
1799
|
+
* @module
|
|
1800
|
+
*/
|
|
1801
|
+
var hmac_ts_1 = require_hmac();
|
|
1802
|
+
var utils_ts_1 = require_utils();
|
|
2485
1803
|
function pbkdf2Init(hash, _password, _salt, _opts) {
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
1804
|
+
(0, utils_ts_1.ahash)(hash);
|
|
1805
|
+
const { c, dkLen, asyncTick } = (0, utils_ts_1.checkOpts)({
|
|
1806
|
+
dkLen: 32,
|
|
1807
|
+
asyncTick: 10
|
|
1808
|
+
}, _opts);
|
|
1809
|
+
(0, utils_ts_1.anumber)(c);
|
|
1810
|
+
(0, utils_ts_1.anumber)(dkLen);
|
|
1811
|
+
(0, utils_ts_1.anumber)(asyncTick);
|
|
1812
|
+
if (c < 1) throw new Error("iterations (c) should be >= 1");
|
|
1813
|
+
const password = (0, utils_ts_1.kdfInputToBytes)(_password);
|
|
1814
|
+
const salt = (0, utils_ts_1.kdfInputToBytes)(_salt);
|
|
1815
|
+
const DK = new Uint8Array(dkLen);
|
|
1816
|
+
const PRF = hmac_ts_1.hmac.create(hash, password);
|
|
1817
|
+
return {
|
|
1818
|
+
c,
|
|
1819
|
+
dkLen,
|
|
1820
|
+
asyncTick,
|
|
1821
|
+
DK,
|
|
1822
|
+
PRF,
|
|
1823
|
+
PRFSalt: PRF._cloneInto().update(salt)
|
|
1824
|
+
};
|
|
2502
1825
|
}
|
|
2503
1826
|
function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
return DK;
|
|
1827
|
+
PRF.destroy();
|
|
1828
|
+
PRFSalt.destroy();
|
|
1829
|
+
if (prfW) prfW.destroy();
|
|
1830
|
+
(0, utils_ts_1.clean)(u);
|
|
1831
|
+
return DK;
|
|
2510
1832
|
}
|
|
2511
1833
|
/**
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
function pbkdf2
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
2538
|
-
for (let i = 0; i < Ti.length; i++)
|
|
2539
|
-
Ti[i] ^= u[i];
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
1834
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function
|
|
1835
|
+
* @param hash - hash function that would be used e.g. sha256
|
|
1836
|
+
* @param password - password from which a derived key is generated
|
|
1837
|
+
* @param salt - cryptographic salt
|
|
1838
|
+
* @param opts - {c, dkLen} where c is work factor and dkLen is output message size
|
|
1839
|
+
* @example
|
|
1840
|
+
* const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) });
|
|
1841
|
+
*/
|
|
1842
|
+
function pbkdf2(hash, password, salt, opts) {
|
|
1843
|
+
const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
|
1844
|
+
let prfW;
|
|
1845
|
+
const arr = new Uint8Array(4);
|
|
1846
|
+
const view = (0, utils_ts_1.createView)(arr);
|
|
1847
|
+
const u = new Uint8Array(PRF.outputLen);
|
|
1848
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
1849
|
+
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
1850
|
+
view.setInt32(0, ti, false);
|
|
1851
|
+
(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
|
|
1852
|
+
Ti.set(u.subarray(0, Ti.length));
|
|
1853
|
+
for (let ui = 1; ui < c; ui++) {
|
|
1854
|
+
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
1855
|
+
for (let i = 0; i < Ti.length; i++) Ti[i] ^= u[i];
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
2543
1859
|
}
|
|
2544
1860
|
/**
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
1861
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function. Async version.
|
|
1862
|
+
* @example
|
|
1863
|
+
* await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 });
|
|
1864
|
+
*/
|
|
2549
1865
|
async function pbkdf2Async(hash, password, salt, opts) {
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
2567
|
-
for (let i = 0; i < Ti.length; i++)
|
|
2568
|
-
Ti[i] ^= u[i];
|
|
2569
|
-
});
|
|
2570
|
-
}
|
|
2571
|
-
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
1866
|
+
const { c, dkLen, asyncTick, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
|
1867
|
+
let prfW;
|
|
1868
|
+
const arr = new Uint8Array(4);
|
|
1869
|
+
const view = (0, utils_ts_1.createView)(arr);
|
|
1870
|
+
const u = new Uint8Array(PRF.outputLen);
|
|
1871
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
1872
|
+
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
1873
|
+
view.setInt32(0, ti, false);
|
|
1874
|
+
(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
|
|
1875
|
+
Ti.set(u.subarray(0, Ti.length));
|
|
1876
|
+
await (0, utils_ts_1.asyncLoop)(c - 1, asyncTick, () => {
|
|
1877
|
+
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
1878
|
+
for (let i = 0; i < Ti.length; i++) Ti[i] ^= u[i];
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
2572
1882
|
}
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
|
-
export { sha1 as a, require$$1 as b, require$$2 as c, require$$0 as d, randomBytes as e, abytes as f, concatBytes as g, shake128 as h, isBytes as i, shake256 as j, sha512$1 as k, requirePbkdf2 as l, requireSha512 as m, requireSha256 as n, requireUtils as o, bytesToHex as p, anumber as q, ripemd160 as r, sha256$1 as s, hexToBytes as t, ahash as u, hmac$1 as v };
|
|
1883
|
+
}));
|
|
1884
|
+
//#endregion
|
|
1885
|
+
export { init_sha3 as a, init_legacy as c, sha1 as d, require_utils as i, legacy_exports as l, require_sha512 as n, shake128 as o, require_sha256 as r, shake256 as s, require_pbkdf2 as t, ripemd160 as u };
|