@ghostlytools/cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +405 -0
- package/SKILL.md +282 -0
- package/dist/assets/argon2id-088uQfnH.js +645 -0
- package/dist/assets/argon2id-088uQfnH.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-Bxru_BVW.wasm +0 -0
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js +6 -0
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -0
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js +6 -0
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -0
- package/dist/assets/bitcoindevkit_bg-CRkZTSbO.wasm +0 -0
- package/dist/assets/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/dist/assets/endpoint-h3cqRyRz.js +185 -0
- package/dist/assets/endpoint-h3cqRyRz.js.map +1 -0
- package/dist/assets/fedimintWorker.mjs +95 -0
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js +6 -0
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -0
- package/dist/assets/fedimint_client_wasm_bg-DeFtkIv6.wasm +0 -0
- package/dist/assets/fileBytes-ByS16quP.js +154 -0
- package/dist/assets/fileBytes-ByS16quP.js.map +1 -0
- package/dist/assets/fileBytesIdb-COzoilo9.js +230 -0
- package/dist/assets/fileBytesIdb-COzoilo9.js.map +1 -0
- package/dist/assets/fileBytesOpfs-B27wAMUh.js +145 -0
- package/dist/assets/fileBytesOpfs-B27wAMUh.js.map +1 -0
- package/dist/assets/ghostly_iroh_web-CPa_YEfb.js +1154 -0
- package/dist/assets/ghostly_iroh_web-CPa_YEfb.js.map +1 -0
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/hyperdhtRelay-BKsFpPjr.js +342 -0
- package/dist/assets/hyperdhtRelay-BKsFpPjr.js.map +1 -0
- package/dist/assets/legacy_ciphers-JJOu0JXL.js +5185 -0
- package/dist/assets/legacy_ciphers-JJOu0JXL.js.map +1 -0
- package/dist/assets/mainline-DOncVbJN.js +176 -0
- package/dist/assets/mainline-DOncVbJN.js.map +1 -0
- package/dist/assets/nacl-fast-CDhNCYHs.js +1512 -0
- package/dist/assets/nacl-fast-CDhNCYHs.js.map +1 -0
- package/dist/assets/noble_curves-DDWn5AH0.js +2978 -0
- package/dist/assets/noble_curves-DDWn5AH0.js.map +1 -0
- package/dist/assets/noble_hashes-B7AZyFyS.js +427 -0
- package/dist/assets/noble_hashes-B7AZyFyS.js.map +1 -0
- package/dist/assets/openpgp-BBFr-zHQ.js +16573 -0
- package/dist/assets/openpgp-BBFr-zHQ.js.map +1 -0
- package/dist/assets/server-5T5l8hfy.js +28293 -0
- package/dist/assets/server-5T5l8hfy.js.map +1 -0
- package/dist/assets/sha512-BYId-G-T.js +1034 -0
- package/dist/assets/sha512-BYId-G-T.js.map +1 -0
- package/dist/assets/src-DptDr2et.js +20971 -0
- package/dist/assets/src-DptDr2et.js.map +1 -0
- package/dist/assets/storage-Bya5b2Xt.js +1648 -0
- package/dist/assets/storage-Bya5b2Xt.js.map +1 -0
- package/dist/assets/tree-store-N362nuzZ.js +1031 -0
- package/dist/assets/tree-store-N362nuzZ.js.map +1 -0
- package/dist/assets/unbzip2-stream-B1C-JX9L.js +681 -0
- package/dist/assets/unbzip2-stream-B1C-JX9L.js.map +1 -0
- package/dist/assets/web-OUQl4Q7L.js +3802 -0
- package/dist/assets/web-OUQl4Q7L.js.map +1 -0
- package/dist/ghostly.mjs +17087 -0
- package/dist/ghostly.mjs.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
//#region ../../node_modules/openpgp/dist/lightweight/sha512.mjs
|
|
2
|
+
/*! OpenPGP.js v6.3.2 - 2026-09-24 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
|
|
3
|
+
var globalThis$1 = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
4
|
+
var crypto = typeof globalThis$1 === "object" && "crypto" in globalThis$1 ? globalThis$1.crypto : void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Utilities for hex, bytes, CSPRNG.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
11
|
+
function isBytes(a) {
|
|
12
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
13
|
+
}
|
|
14
|
+
/** Asserts something is positive integer. */
|
|
15
|
+
function anumber(n) {
|
|
16
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error("positive integer expected, got " + n);
|
|
17
|
+
}
|
|
18
|
+
/** Asserts something is Uint8Array. */
|
|
19
|
+
function abytes(b, ...lengths) {
|
|
20
|
+
if (!isBytes(b)) throw new Error("Uint8Array expected");
|
|
21
|
+
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
22
|
+
}
|
|
23
|
+
/** Asserts something is hash */
|
|
24
|
+
function ahash(h) {
|
|
25
|
+
if (typeof h !== "function" || typeof h.create !== "function") throw new Error("Hash should be wrapped by utils.createHasher");
|
|
26
|
+
anumber(h.outputLen);
|
|
27
|
+
anumber(h.blockLen);
|
|
28
|
+
}
|
|
29
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
|
30
|
+
function aexists(instance, checkFinished = true) {
|
|
31
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
32
|
+
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
33
|
+
}
|
|
34
|
+
/** Asserts output is properly-sized byte array */
|
|
35
|
+
function aoutput(out, instance) {
|
|
36
|
+
abytes(out);
|
|
37
|
+
const min = instance.outputLen;
|
|
38
|
+
if (out.length < min) throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
39
|
+
}
|
|
40
|
+
/** Cast u8 / u16 / u32 to u32. */
|
|
41
|
+
function u32(arr) {
|
|
42
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
43
|
+
}
|
|
44
|
+
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
45
|
+
function clean(...arrays) {
|
|
46
|
+
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
47
|
+
}
|
|
48
|
+
/** Create DataView of an array for easy byte-level manipulation. */
|
|
49
|
+
function createView(arr) {
|
|
50
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
51
|
+
}
|
|
52
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
|
53
|
+
function rotr(word, shift) {
|
|
54
|
+
return word << 32 - shift | word >>> shift;
|
|
55
|
+
}
|
|
56
|
+
/** The rotate left (circular left shift) operation for uint32 */
|
|
57
|
+
function rotl(word, shift) {
|
|
58
|
+
return word << shift | word >>> 32 - shift >>> 0;
|
|
59
|
+
}
|
|
60
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
61
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
62
|
+
/** The byte swap operation for uint32 */
|
|
63
|
+
function byteSwap(word) {
|
|
64
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
65
|
+
}
|
|
66
|
+
/** In place byte swap for Uint32Array */
|
|
67
|
+
function byteSwap32(arr) {
|
|
68
|
+
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
69
|
+
return arr;
|
|
70
|
+
}
|
|
71
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
72
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
73
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
74
|
+
/**
|
|
75
|
+
* Convert byte array to hex string. Uses built-in function, when available.
|
|
76
|
+
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
77
|
+
*/
|
|
78
|
+
function bytesToHex(bytes) {
|
|
79
|
+
abytes(bytes);
|
|
80
|
+
if (hasHexBuiltin) return bytes.toHex();
|
|
81
|
+
let hex = "";
|
|
82
|
+
for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
|
|
83
|
+
return hex;
|
|
84
|
+
}
|
|
85
|
+
var asciis = {
|
|
86
|
+
_0: 48,
|
|
87
|
+
_9: 57,
|
|
88
|
+
A: 65,
|
|
89
|
+
F: 70,
|
|
90
|
+
a: 97,
|
|
91
|
+
f: 102
|
|
92
|
+
};
|
|
93
|
+
function asciiToBase16(ch) {
|
|
94
|
+
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0;
|
|
95
|
+
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10);
|
|
96
|
+
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Convert hex string to byte array. Uses built-in function, when available.
|
|
100
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
101
|
+
*/
|
|
102
|
+
function hexToBytes(hex) {
|
|
103
|
+
if (typeof hex !== "string") throw new Error("hex string expected, got " + typeof hex);
|
|
104
|
+
if (hasHexBuiltin) return Uint8Array.fromHex(hex);
|
|
105
|
+
const hl = hex.length;
|
|
106
|
+
const al = hl / 2;
|
|
107
|
+
if (hl % 2) throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
108
|
+
const array = new Uint8Array(al);
|
|
109
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
110
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
111
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
112
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
113
|
+
const char = hex[hi] + hex[hi + 1];
|
|
114
|
+
throw new Error("hex string expected, got non-hex character \"" + char + "\" at index " + hi);
|
|
115
|
+
}
|
|
116
|
+
array[ai] = n1 * 16 + n2;
|
|
117
|
+
}
|
|
118
|
+
return array;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Converts string to bytes using UTF8 encoding.
|
|
122
|
+
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
123
|
+
*/
|
|
124
|
+
function utf8ToBytes(str) {
|
|
125
|
+
if (typeof str !== "string") throw new Error("string expected");
|
|
126
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
130
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
131
|
+
* Keep in mind for future mutable operations.
|
|
132
|
+
*/
|
|
133
|
+
function toBytes(data) {
|
|
134
|
+
if (typeof data === "string") data = utf8ToBytes(data);
|
|
135
|
+
abytes(data);
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
/** Copies several Uint8Arrays into one. */
|
|
139
|
+
function concatBytes(...arrays) {
|
|
140
|
+
let sum = 0;
|
|
141
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
142
|
+
const a = arrays[i];
|
|
143
|
+
abytes(a);
|
|
144
|
+
sum += a.length;
|
|
145
|
+
}
|
|
146
|
+
const res = new Uint8Array(sum);
|
|
147
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
148
|
+
const a = arrays[i];
|
|
149
|
+
res.set(a, pad);
|
|
150
|
+
pad += a.length;
|
|
151
|
+
}
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
/** For runtime check if class implements interface */
|
|
155
|
+
var Hash = class {};
|
|
156
|
+
/** Wraps hash function, creating an interface on top of it */
|
|
157
|
+
function createHasher(hashCons) {
|
|
158
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
159
|
+
const tmp = hashCons();
|
|
160
|
+
hashC.outputLen = tmp.outputLen;
|
|
161
|
+
hashC.blockLen = tmp.blockLen;
|
|
162
|
+
hashC.create = () => hashCons();
|
|
163
|
+
return hashC;
|
|
164
|
+
}
|
|
165
|
+
function createXOFer(hashCons) {
|
|
166
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
167
|
+
const tmp = hashCons({});
|
|
168
|
+
hashC.outputLen = tmp.outputLen;
|
|
169
|
+
hashC.blockLen = tmp.blockLen;
|
|
170
|
+
hashC.create = (opts) => hashCons(opts);
|
|
171
|
+
return hashC;
|
|
172
|
+
}
|
|
173
|
+
var wrapConstructor = createHasher;
|
|
174
|
+
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
175
|
+
function randomBytes(bytesLength = 32) {
|
|
176
|
+
if (crypto && typeof crypto.getRandomValues === "function") return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
177
|
+
if (crypto && typeof crypto.randomBytes === "function") return Uint8Array.from(crypto.randomBytes(bytesLength));
|
|
178
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Internal Merkle-Damgard hash utils.
|
|
182
|
+
* @module
|
|
183
|
+
*/
|
|
184
|
+
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
|
185
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
186
|
+
if (typeof view.setBigUint64 === "function") return view.setBigUint64(byteOffset, value, isLE);
|
|
187
|
+
const _32n = BigInt(32);
|
|
188
|
+
const _u32_max = BigInt(4294967295);
|
|
189
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
190
|
+
const wl = Number(value & _u32_max);
|
|
191
|
+
const h = isLE ? 4 : 0;
|
|
192
|
+
const l = isLE ? 0 : 4;
|
|
193
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
194
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
195
|
+
}
|
|
196
|
+
/** Choice: a ? b : c */
|
|
197
|
+
function Chi(a, b, c) {
|
|
198
|
+
return a & b ^ ~a & c;
|
|
199
|
+
}
|
|
200
|
+
/** Majority function, true if any two inputs is true. */
|
|
201
|
+
function Maj(a, b, c) {
|
|
202
|
+
return a & b ^ a & c ^ b & c;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Merkle-Damgard hash construction base class.
|
|
206
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
207
|
+
*/
|
|
208
|
+
var HashMD = class extends Hash {
|
|
209
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
210
|
+
super();
|
|
211
|
+
this.finished = false;
|
|
212
|
+
this.length = 0;
|
|
213
|
+
this.pos = 0;
|
|
214
|
+
this.destroyed = false;
|
|
215
|
+
this.blockLen = blockLen;
|
|
216
|
+
this.outputLen = outputLen;
|
|
217
|
+
this.padOffset = padOffset;
|
|
218
|
+
this.isLE = isLE;
|
|
219
|
+
this.buffer = new Uint8Array(blockLen);
|
|
220
|
+
this.view = createView(this.buffer);
|
|
221
|
+
}
|
|
222
|
+
update(data) {
|
|
223
|
+
aexists(this);
|
|
224
|
+
data = toBytes(data);
|
|
225
|
+
abytes(data);
|
|
226
|
+
const { view, buffer, blockLen } = this;
|
|
227
|
+
const len = data.length;
|
|
228
|
+
for (let pos = 0; pos < len;) {
|
|
229
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
230
|
+
if (take === blockLen) {
|
|
231
|
+
const dataView = createView(data);
|
|
232
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
236
|
+
this.pos += take;
|
|
237
|
+
pos += take;
|
|
238
|
+
if (this.pos === blockLen) {
|
|
239
|
+
this.process(view, 0);
|
|
240
|
+
this.pos = 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this.length += data.length;
|
|
244
|
+
this.roundClean();
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
digestInto(out) {
|
|
248
|
+
aexists(this);
|
|
249
|
+
aoutput(out, this);
|
|
250
|
+
this.finished = true;
|
|
251
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
252
|
+
let { pos } = this;
|
|
253
|
+
buffer[pos++] = 128;
|
|
254
|
+
clean(this.buffer.subarray(pos));
|
|
255
|
+
if (this.padOffset > blockLen - pos) {
|
|
256
|
+
this.process(view, 0);
|
|
257
|
+
pos = 0;
|
|
258
|
+
}
|
|
259
|
+
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
260
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
261
|
+
this.process(view, 0);
|
|
262
|
+
const oview = createView(out);
|
|
263
|
+
const len = this.outputLen;
|
|
264
|
+
if (len % 4) throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
265
|
+
const outLen = len / 4;
|
|
266
|
+
const state = this.get();
|
|
267
|
+
if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
|
|
268
|
+
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
269
|
+
}
|
|
270
|
+
digest() {
|
|
271
|
+
const { buffer, outputLen } = this;
|
|
272
|
+
this.digestInto(buffer);
|
|
273
|
+
const res = buffer.slice(0, outputLen);
|
|
274
|
+
this.destroy();
|
|
275
|
+
return res;
|
|
276
|
+
}
|
|
277
|
+
_cloneInto(to) {
|
|
278
|
+
to || (to = new this.constructor());
|
|
279
|
+
to.set(...this.get());
|
|
280
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
281
|
+
to.destroyed = destroyed;
|
|
282
|
+
to.finished = finished;
|
|
283
|
+
to.length = length;
|
|
284
|
+
to.pos = pos;
|
|
285
|
+
if (length % blockLen) to.buffer.set(buffer);
|
|
286
|
+
return to;
|
|
287
|
+
}
|
|
288
|
+
clone() {
|
|
289
|
+
return this._cloneInto();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
294
|
+
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
295
|
+
*/
|
|
296
|
+
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
297
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
298
|
+
1779033703,
|
|
299
|
+
3144134277,
|
|
300
|
+
1013904242,
|
|
301
|
+
2773480762,
|
|
302
|
+
1359893119,
|
|
303
|
+
2600822924,
|
|
304
|
+
528734635,
|
|
305
|
+
1541459225
|
|
306
|
+
]);
|
|
307
|
+
/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */
|
|
308
|
+
var SHA224_IV = /* @__PURE__ */ Uint32Array.from([
|
|
309
|
+
3238371032,
|
|
310
|
+
914150663,
|
|
311
|
+
812702999,
|
|
312
|
+
4144912697,
|
|
313
|
+
4290775857,
|
|
314
|
+
1750603025,
|
|
315
|
+
1694076839,
|
|
316
|
+
3204075428
|
|
317
|
+
]);
|
|
318
|
+
/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */
|
|
319
|
+
var SHA384_IV = /* @__PURE__ */ Uint32Array.from([
|
|
320
|
+
3418070365,
|
|
321
|
+
3238371032,
|
|
322
|
+
1654270250,
|
|
323
|
+
914150663,
|
|
324
|
+
2438529370,
|
|
325
|
+
812702999,
|
|
326
|
+
355462360,
|
|
327
|
+
4144912697,
|
|
328
|
+
1731405415,
|
|
329
|
+
4290775857,
|
|
330
|
+
2394180231,
|
|
331
|
+
1750603025,
|
|
332
|
+
3675008525,
|
|
333
|
+
1694076839,
|
|
334
|
+
1203062813,
|
|
335
|
+
3204075428
|
|
336
|
+
]);
|
|
337
|
+
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
|
338
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
339
|
+
1779033703,
|
|
340
|
+
4089235720,
|
|
341
|
+
3144134277,
|
|
342
|
+
2227873595,
|
|
343
|
+
1013904242,
|
|
344
|
+
4271175723,
|
|
345
|
+
2773480762,
|
|
346
|
+
1595750129,
|
|
347
|
+
1359893119,
|
|
348
|
+
2917565137,
|
|
349
|
+
2600822924,
|
|
350
|
+
725511199,
|
|
351
|
+
528734635,
|
|
352
|
+
4215389547,
|
|
353
|
+
1541459225,
|
|
354
|
+
327033209
|
|
355
|
+
]);
|
|
356
|
+
/**
|
|
357
|
+
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
358
|
+
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
359
|
+
* @module
|
|
360
|
+
*/
|
|
361
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
362
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
363
|
+
function fromBig(n, le = false) {
|
|
364
|
+
if (le) return {
|
|
365
|
+
h: Number(n & U32_MASK64),
|
|
366
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
367
|
+
};
|
|
368
|
+
return {
|
|
369
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
370
|
+
l: Number(n & U32_MASK64) | 0
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function split(lst, le = false) {
|
|
374
|
+
const len = lst.length;
|
|
375
|
+
let Ah = new Uint32Array(len);
|
|
376
|
+
let Al = new Uint32Array(len);
|
|
377
|
+
for (let i = 0; i < len; i++) {
|
|
378
|
+
const { h, l } = fromBig(lst[i], le);
|
|
379
|
+
[Ah[i], Al[i]] = [h, l];
|
|
380
|
+
}
|
|
381
|
+
return [Ah, Al];
|
|
382
|
+
}
|
|
383
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
384
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
385
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
386
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
387
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
388
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
389
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
390
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
391
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
392
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
393
|
+
function add(Ah, Al, Bh, Bl) {
|
|
394
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
395
|
+
return {
|
|
396
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
397
|
+
l: l | 0
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
401
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
402
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
403
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
404
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
405
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
406
|
+
/**
|
|
407
|
+
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
408
|
+
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
409
|
+
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
410
|
+
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
411
|
+
* @module
|
|
412
|
+
*/
|
|
413
|
+
/**
|
|
414
|
+
* Round constants:
|
|
415
|
+
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
|
|
416
|
+
*/
|
|
417
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
418
|
+
1116352408,
|
|
419
|
+
1899447441,
|
|
420
|
+
3049323471,
|
|
421
|
+
3921009573,
|
|
422
|
+
961987163,
|
|
423
|
+
1508970993,
|
|
424
|
+
2453635748,
|
|
425
|
+
2870763221,
|
|
426
|
+
3624381080,
|
|
427
|
+
310598401,
|
|
428
|
+
607225278,
|
|
429
|
+
1426881987,
|
|
430
|
+
1925078388,
|
|
431
|
+
2162078206,
|
|
432
|
+
2614888103,
|
|
433
|
+
3248222580,
|
|
434
|
+
3835390401,
|
|
435
|
+
4022224774,
|
|
436
|
+
264347078,
|
|
437
|
+
604807628,
|
|
438
|
+
770255983,
|
|
439
|
+
1249150122,
|
|
440
|
+
1555081692,
|
|
441
|
+
1996064986,
|
|
442
|
+
2554220882,
|
|
443
|
+
2821834349,
|
|
444
|
+
2952996808,
|
|
445
|
+
3210313671,
|
|
446
|
+
3336571891,
|
|
447
|
+
3584528711,
|
|
448
|
+
113926993,
|
|
449
|
+
338241895,
|
|
450
|
+
666307205,
|
|
451
|
+
773529912,
|
|
452
|
+
1294757372,
|
|
453
|
+
1396182291,
|
|
454
|
+
1695183700,
|
|
455
|
+
1986661051,
|
|
456
|
+
2177026350,
|
|
457
|
+
2456956037,
|
|
458
|
+
2730485921,
|
|
459
|
+
2820302411,
|
|
460
|
+
3259730800,
|
|
461
|
+
3345764771,
|
|
462
|
+
3516065817,
|
|
463
|
+
3600352804,
|
|
464
|
+
4094571909,
|
|
465
|
+
275423344,
|
|
466
|
+
430227734,
|
|
467
|
+
506948616,
|
|
468
|
+
659060556,
|
|
469
|
+
883997877,
|
|
470
|
+
958139571,
|
|
471
|
+
1322822218,
|
|
472
|
+
1537002063,
|
|
473
|
+
1747873779,
|
|
474
|
+
1955562222,
|
|
475
|
+
2024104815,
|
|
476
|
+
2227730452,
|
|
477
|
+
2361852424,
|
|
478
|
+
2428436474,
|
|
479
|
+
2756734187,
|
|
480
|
+
3204031479,
|
|
481
|
+
3329325298
|
|
482
|
+
]);
|
|
483
|
+
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
484
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
485
|
+
var SHA256 = class extends HashMD {
|
|
486
|
+
constructor(outputLen = 32) {
|
|
487
|
+
super(64, outputLen, 8, false);
|
|
488
|
+
this.A = SHA256_IV[0] | 0;
|
|
489
|
+
this.B = SHA256_IV[1] | 0;
|
|
490
|
+
this.C = SHA256_IV[2] | 0;
|
|
491
|
+
this.D = SHA256_IV[3] | 0;
|
|
492
|
+
this.E = SHA256_IV[4] | 0;
|
|
493
|
+
this.F = SHA256_IV[5] | 0;
|
|
494
|
+
this.G = SHA256_IV[6] | 0;
|
|
495
|
+
this.H = SHA256_IV[7] | 0;
|
|
496
|
+
}
|
|
497
|
+
get() {
|
|
498
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
499
|
+
return [
|
|
500
|
+
A,
|
|
501
|
+
B,
|
|
502
|
+
C,
|
|
503
|
+
D,
|
|
504
|
+
E,
|
|
505
|
+
F,
|
|
506
|
+
G,
|
|
507
|
+
H
|
|
508
|
+
];
|
|
509
|
+
}
|
|
510
|
+
set(A, B, C, D, E, F, G, H) {
|
|
511
|
+
this.A = A | 0;
|
|
512
|
+
this.B = B | 0;
|
|
513
|
+
this.C = C | 0;
|
|
514
|
+
this.D = D | 0;
|
|
515
|
+
this.E = E | 0;
|
|
516
|
+
this.F = F | 0;
|
|
517
|
+
this.G = G | 0;
|
|
518
|
+
this.H = H | 0;
|
|
519
|
+
}
|
|
520
|
+
process(view, offset) {
|
|
521
|
+
for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
|
|
522
|
+
for (let i = 16; i < 64; i++) {
|
|
523
|
+
const W15 = SHA256_W[i - 15];
|
|
524
|
+
const W2 = SHA256_W[i - 2];
|
|
525
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
526
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
527
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
528
|
+
}
|
|
529
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
530
|
+
for (let i = 0; i < 64; i++) {
|
|
531
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
532
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
533
|
+
const T2 = (rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22)) + Maj(A, B, C) | 0;
|
|
534
|
+
H = G;
|
|
535
|
+
G = F;
|
|
536
|
+
F = E;
|
|
537
|
+
E = D + T1 | 0;
|
|
538
|
+
D = C;
|
|
539
|
+
C = B;
|
|
540
|
+
B = A;
|
|
541
|
+
A = T1 + T2 | 0;
|
|
542
|
+
}
|
|
543
|
+
A = A + this.A | 0;
|
|
544
|
+
B = B + this.B | 0;
|
|
545
|
+
C = C + this.C | 0;
|
|
546
|
+
D = D + this.D | 0;
|
|
547
|
+
E = E + this.E | 0;
|
|
548
|
+
F = F + this.F | 0;
|
|
549
|
+
G = G + this.G | 0;
|
|
550
|
+
H = H + this.H | 0;
|
|
551
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
552
|
+
}
|
|
553
|
+
roundClean() {
|
|
554
|
+
clean(SHA256_W);
|
|
555
|
+
}
|
|
556
|
+
destroy() {
|
|
557
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
558
|
+
clean(this.buffer);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
var SHA224 = class extends SHA256 {
|
|
562
|
+
constructor() {
|
|
563
|
+
super(28);
|
|
564
|
+
this.A = SHA224_IV[0] | 0;
|
|
565
|
+
this.B = SHA224_IV[1] | 0;
|
|
566
|
+
this.C = SHA224_IV[2] | 0;
|
|
567
|
+
this.D = SHA224_IV[3] | 0;
|
|
568
|
+
this.E = SHA224_IV[4] | 0;
|
|
569
|
+
this.F = SHA224_IV[5] | 0;
|
|
570
|
+
this.G = SHA224_IV[6] | 0;
|
|
571
|
+
this.H = SHA224_IV[7] | 0;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
575
|
+
"0x428a2f98d728ae22",
|
|
576
|
+
"0x7137449123ef65cd",
|
|
577
|
+
"0xb5c0fbcfec4d3b2f",
|
|
578
|
+
"0xe9b5dba58189dbbc",
|
|
579
|
+
"0x3956c25bf348b538",
|
|
580
|
+
"0x59f111f1b605d019",
|
|
581
|
+
"0x923f82a4af194f9b",
|
|
582
|
+
"0xab1c5ed5da6d8118",
|
|
583
|
+
"0xd807aa98a3030242",
|
|
584
|
+
"0x12835b0145706fbe",
|
|
585
|
+
"0x243185be4ee4b28c",
|
|
586
|
+
"0x550c7dc3d5ffb4e2",
|
|
587
|
+
"0x72be5d74f27b896f",
|
|
588
|
+
"0x80deb1fe3b1696b1",
|
|
589
|
+
"0x9bdc06a725c71235",
|
|
590
|
+
"0xc19bf174cf692694",
|
|
591
|
+
"0xe49b69c19ef14ad2",
|
|
592
|
+
"0xefbe4786384f25e3",
|
|
593
|
+
"0x0fc19dc68b8cd5b5",
|
|
594
|
+
"0x240ca1cc77ac9c65",
|
|
595
|
+
"0x2de92c6f592b0275",
|
|
596
|
+
"0x4a7484aa6ea6e483",
|
|
597
|
+
"0x5cb0a9dcbd41fbd4",
|
|
598
|
+
"0x76f988da831153b5",
|
|
599
|
+
"0x983e5152ee66dfab",
|
|
600
|
+
"0xa831c66d2db43210",
|
|
601
|
+
"0xb00327c898fb213f",
|
|
602
|
+
"0xbf597fc7beef0ee4",
|
|
603
|
+
"0xc6e00bf33da88fc2",
|
|
604
|
+
"0xd5a79147930aa725",
|
|
605
|
+
"0x06ca6351e003826f",
|
|
606
|
+
"0x142929670a0e6e70",
|
|
607
|
+
"0x27b70a8546d22ffc",
|
|
608
|
+
"0x2e1b21385c26c926",
|
|
609
|
+
"0x4d2c6dfc5ac42aed",
|
|
610
|
+
"0x53380d139d95b3df",
|
|
611
|
+
"0x650a73548baf63de",
|
|
612
|
+
"0x766a0abb3c77b2a8",
|
|
613
|
+
"0x81c2c92e47edaee6",
|
|
614
|
+
"0x92722c851482353b",
|
|
615
|
+
"0xa2bfe8a14cf10364",
|
|
616
|
+
"0xa81a664bbc423001",
|
|
617
|
+
"0xc24b8b70d0f89791",
|
|
618
|
+
"0xc76c51a30654be30",
|
|
619
|
+
"0xd192e819d6ef5218",
|
|
620
|
+
"0xd69906245565a910",
|
|
621
|
+
"0xf40e35855771202a",
|
|
622
|
+
"0x106aa07032bbd1b8",
|
|
623
|
+
"0x19a4c116b8d2d0c8",
|
|
624
|
+
"0x1e376c085141ab53",
|
|
625
|
+
"0x2748774cdf8eeb99",
|
|
626
|
+
"0x34b0bcb5e19b48a8",
|
|
627
|
+
"0x391c0cb3c5c95a63",
|
|
628
|
+
"0x4ed8aa4ae3418acb",
|
|
629
|
+
"0x5b9cca4f7763e373",
|
|
630
|
+
"0x682e6ff3d6b2b8a3",
|
|
631
|
+
"0x748f82ee5defb2fc",
|
|
632
|
+
"0x78a5636f43172f60",
|
|
633
|
+
"0x84c87814a1f0ab72",
|
|
634
|
+
"0x8cc702081a6439ec",
|
|
635
|
+
"0x90befffa23631e28",
|
|
636
|
+
"0xa4506cebde82bde9",
|
|
637
|
+
"0xbef9a3f7b2c67915",
|
|
638
|
+
"0xc67178f2e372532b",
|
|
639
|
+
"0xca273eceea26619c",
|
|
640
|
+
"0xd186b8c721c0c207",
|
|
641
|
+
"0xeada7dd6cde0eb1e",
|
|
642
|
+
"0xf57d4f7fee6ed178",
|
|
643
|
+
"0x06f067aa72176fba",
|
|
644
|
+
"0x0a637dc5a2c898a6",
|
|
645
|
+
"0x113f9804bef90dae",
|
|
646
|
+
"0x1b710b35131c471b",
|
|
647
|
+
"0x28db77f523047d84",
|
|
648
|
+
"0x32caab7b40c72493",
|
|
649
|
+
"0x3c9ebe0a15c9bebc",
|
|
650
|
+
"0x431d67c49c100d4c",
|
|
651
|
+
"0x4cc5d4becb3e42b6",
|
|
652
|
+
"0x597f299cfc657e2a",
|
|
653
|
+
"0x5fcb6fab3ad6faec",
|
|
654
|
+
"0x6c44198c4a475817"
|
|
655
|
+
].map((n) => BigInt(n))))();
|
|
656
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
657
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
658
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
659
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
660
|
+
var SHA512 = class extends HashMD {
|
|
661
|
+
constructor(outputLen = 64) {
|
|
662
|
+
super(128, outputLen, 16, false);
|
|
663
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
664
|
+
this.Al = SHA512_IV[1] | 0;
|
|
665
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
666
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
667
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
668
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
669
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
670
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
671
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
672
|
+
this.El = SHA512_IV[9] | 0;
|
|
673
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
674
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
675
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
676
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
677
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
678
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
679
|
+
}
|
|
680
|
+
get() {
|
|
681
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
682
|
+
return [
|
|
683
|
+
Ah,
|
|
684
|
+
Al,
|
|
685
|
+
Bh,
|
|
686
|
+
Bl,
|
|
687
|
+
Ch,
|
|
688
|
+
Cl,
|
|
689
|
+
Dh,
|
|
690
|
+
Dl,
|
|
691
|
+
Eh,
|
|
692
|
+
El,
|
|
693
|
+
Fh,
|
|
694
|
+
Fl,
|
|
695
|
+
Gh,
|
|
696
|
+
Gl,
|
|
697
|
+
Hh,
|
|
698
|
+
Hl
|
|
699
|
+
];
|
|
700
|
+
}
|
|
701
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
702
|
+
this.Ah = Ah | 0;
|
|
703
|
+
this.Al = Al | 0;
|
|
704
|
+
this.Bh = Bh | 0;
|
|
705
|
+
this.Bl = Bl | 0;
|
|
706
|
+
this.Ch = Ch | 0;
|
|
707
|
+
this.Cl = Cl | 0;
|
|
708
|
+
this.Dh = Dh | 0;
|
|
709
|
+
this.Dl = Dl | 0;
|
|
710
|
+
this.Eh = Eh | 0;
|
|
711
|
+
this.El = El | 0;
|
|
712
|
+
this.Fh = Fh | 0;
|
|
713
|
+
this.Fl = Fl | 0;
|
|
714
|
+
this.Gh = Gh | 0;
|
|
715
|
+
this.Gl = Gl | 0;
|
|
716
|
+
this.Hh = Hh | 0;
|
|
717
|
+
this.Hl = Hl | 0;
|
|
718
|
+
}
|
|
719
|
+
process(view, offset) {
|
|
720
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
721
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
722
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
723
|
+
}
|
|
724
|
+
for (let i = 16; i < 80; i++) {
|
|
725
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
726
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
727
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
728
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
729
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
730
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
731
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
732
|
+
const SUMl = add4L(s0l, rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6), SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
733
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
734
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
735
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
736
|
+
}
|
|
737
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
738
|
+
for (let i = 0; i < 80; i++) {
|
|
739
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
740
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
741
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
742
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
743
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
744
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
745
|
+
const T1l = T1ll | 0;
|
|
746
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
747
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
748
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
749
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
750
|
+
Hh = Gh | 0;
|
|
751
|
+
Hl = Gl | 0;
|
|
752
|
+
Gh = Fh | 0;
|
|
753
|
+
Gl = Fl | 0;
|
|
754
|
+
Fh = Eh | 0;
|
|
755
|
+
Fl = El | 0;
|
|
756
|
+
({h: Eh, l: El} = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
757
|
+
Dh = Ch | 0;
|
|
758
|
+
Dl = Cl | 0;
|
|
759
|
+
Ch = Bh | 0;
|
|
760
|
+
Cl = Bl | 0;
|
|
761
|
+
Bh = Ah | 0;
|
|
762
|
+
Bl = Al | 0;
|
|
763
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
764
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
765
|
+
Al = All | 0;
|
|
766
|
+
}
|
|
767
|
+
({h: Ah, l: Al} = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
768
|
+
({h: Bh, l: Bl} = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
769
|
+
({h: Ch, l: Cl} = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
770
|
+
({h: Dh, l: Dl} = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
771
|
+
({h: Eh, l: El} = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
772
|
+
({h: Fh, l: Fl} = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
773
|
+
({h: Gh, l: Gl} = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
774
|
+
({h: Hh, l: Hl} = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
775
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
776
|
+
}
|
|
777
|
+
roundClean() {
|
|
778
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
779
|
+
}
|
|
780
|
+
destroy() {
|
|
781
|
+
clean(this.buffer);
|
|
782
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
var SHA384 = class extends SHA512 {
|
|
786
|
+
constructor() {
|
|
787
|
+
super(48);
|
|
788
|
+
this.Ah = SHA384_IV[0] | 0;
|
|
789
|
+
this.Al = SHA384_IV[1] | 0;
|
|
790
|
+
this.Bh = SHA384_IV[2] | 0;
|
|
791
|
+
this.Bl = SHA384_IV[3] | 0;
|
|
792
|
+
this.Ch = SHA384_IV[4] | 0;
|
|
793
|
+
this.Cl = SHA384_IV[5] | 0;
|
|
794
|
+
this.Dh = SHA384_IV[6] | 0;
|
|
795
|
+
this.Dl = SHA384_IV[7] | 0;
|
|
796
|
+
this.Eh = SHA384_IV[8] | 0;
|
|
797
|
+
this.El = SHA384_IV[9] | 0;
|
|
798
|
+
this.Fh = SHA384_IV[10] | 0;
|
|
799
|
+
this.Fl = SHA384_IV[11] | 0;
|
|
800
|
+
this.Gh = SHA384_IV[12] | 0;
|
|
801
|
+
this.Gl = SHA384_IV[13] | 0;
|
|
802
|
+
this.Hh = SHA384_IV[14] | 0;
|
|
803
|
+
this.Hl = SHA384_IV[15] | 0;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
/**
|
|
807
|
+
* SHA2-256 hash function from RFC 4634.
|
|
808
|
+
*
|
|
809
|
+
* It is the fastest JS hash, even faster than Blake3.
|
|
810
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
811
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
812
|
+
*/
|
|
813
|
+
var sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
814
|
+
/** SHA2-224 hash function from RFC 4634 */
|
|
815
|
+
var sha224$1 = /* @__PURE__ */ createHasher(() => new SHA224());
|
|
816
|
+
/** SHA2-512 hash function from RFC 4634. */
|
|
817
|
+
var sha512$1 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
818
|
+
/** SHA2-384 hash function from RFC 4634. */
|
|
819
|
+
var sha384$1 = /* @__PURE__ */ createHasher(() => new SHA384());
|
|
820
|
+
/**
|
|
821
|
+
* SHA3 (keccak) hash function, based on a new "Sponge function" design.
|
|
822
|
+
* Different from older hashes, the internal state is bigger than output size.
|
|
823
|
+
*
|
|
824
|
+
* Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
|
|
825
|
+
* [Website](https://keccak.team/keccak.html),
|
|
826
|
+
* [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
|
|
827
|
+
*
|
|
828
|
+
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
|
829
|
+
* @module
|
|
830
|
+
*/
|
|
831
|
+
var _0n = BigInt(0);
|
|
832
|
+
var _1n = BigInt(1);
|
|
833
|
+
var _2n = BigInt(2);
|
|
834
|
+
var _7n = BigInt(7);
|
|
835
|
+
var _256n = BigInt(256);
|
|
836
|
+
var _0x71n = BigInt(113);
|
|
837
|
+
var SHA3_PI = [];
|
|
838
|
+
var SHA3_ROTL = [];
|
|
839
|
+
var _SHA3_IOTA = [];
|
|
840
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
841
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
842
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
843
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
844
|
+
let t = _0n;
|
|
845
|
+
for (let j = 0; j < 7; j++) {
|
|
846
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
847
|
+
if (R & _2n) t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
848
|
+
}
|
|
849
|
+
_SHA3_IOTA.push(t);
|
|
850
|
+
}
|
|
851
|
+
var IOTAS = split(_SHA3_IOTA, true);
|
|
852
|
+
var SHA3_IOTA_H = IOTAS[0];
|
|
853
|
+
var SHA3_IOTA_L = IOTAS[1];
|
|
854
|
+
var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
855
|
+
var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
856
|
+
/** `keccakf1600` internal function, additionally allows to adjust round count. */
|
|
857
|
+
function keccakP(s, rounds = 24) {
|
|
858
|
+
const B = /* @__PURE__ */ new Uint32Array(10);
|
|
859
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
860
|
+
for (let x = 0; x < 10; x++) B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
861
|
+
for (let x = 0; x < 10; x += 2) {
|
|
862
|
+
const idx1 = (x + 8) % 10;
|
|
863
|
+
const idx0 = (x + 2) % 10;
|
|
864
|
+
const B0 = B[idx0];
|
|
865
|
+
const B1 = B[idx0 + 1];
|
|
866
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
867
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
868
|
+
for (let y = 0; y < 50; y += 10) {
|
|
869
|
+
s[x + y] ^= Th;
|
|
870
|
+
s[x + y + 1] ^= Tl;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
let curH = s[2];
|
|
874
|
+
let curL = s[3];
|
|
875
|
+
for (let t = 0; t < 24; t++) {
|
|
876
|
+
const shift = SHA3_ROTL[t];
|
|
877
|
+
const Th = rotlH(curH, curL, shift);
|
|
878
|
+
const Tl = rotlL(curH, curL, shift);
|
|
879
|
+
const PI = SHA3_PI[t];
|
|
880
|
+
curH = s[PI];
|
|
881
|
+
curL = s[PI + 1];
|
|
882
|
+
s[PI] = Th;
|
|
883
|
+
s[PI + 1] = Tl;
|
|
884
|
+
}
|
|
885
|
+
for (let y = 0; y < 50; y += 10) {
|
|
886
|
+
for (let x = 0; x < 10; x++) B[x] = s[y + x];
|
|
887
|
+
for (let x = 0; x < 10; x++) s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
888
|
+
}
|
|
889
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
890
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
891
|
+
}
|
|
892
|
+
clean(B);
|
|
893
|
+
}
|
|
894
|
+
/** Keccak sponge function. */
|
|
895
|
+
var Keccak = class Keccak extends Hash {
|
|
896
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
897
|
+
super();
|
|
898
|
+
this.pos = 0;
|
|
899
|
+
this.posOut = 0;
|
|
900
|
+
this.finished = false;
|
|
901
|
+
this.destroyed = false;
|
|
902
|
+
this.enableXOF = false;
|
|
903
|
+
this.blockLen = blockLen;
|
|
904
|
+
this.suffix = suffix;
|
|
905
|
+
this.outputLen = outputLen;
|
|
906
|
+
this.enableXOF = enableXOF;
|
|
907
|
+
this.rounds = rounds;
|
|
908
|
+
anumber(outputLen);
|
|
909
|
+
if (!(0 < blockLen && blockLen < 200)) throw new Error("only keccak-f1600 function is supported");
|
|
910
|
+
this.state = /* @__PURE__ */ new Uint8Array(200);
|
|
911
|
+
this.state32 = u32(this.state);
|
|
912
|
+
}
|
|
913
|
+
clone() {
|
|
914
|
+
return this._cloneInto();
|
|
915
|
+
}
|
|
916
|
+
keccak() {
|
|
917
|
+
swap32IfBE(this.state32);
|
|
918
|
+
keccakP(this.state32, this.rounds);
|
|
919
|
+
swap32IfBE(this.state32);
|
|
920
|
+
this.posOut = 0;
|
|
921
|
+
this.pos = 0;
|
|
922
|
+
}
|
|
923
|
+
update(data) {
|
|
924
|
+
aexists(this);
|
|
925
|
+
data = toBytes(data);
|
|
926
|
+
abytes(data);
|
|
927
|
+
const { blockLen, state } = this;
|
|
928
|
+
const len = data.length;
|
|
929
|
+
for (let pos = 0; pos < len;) {
|
|
930
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
931
|
+
for (let i = 0; i < take; i++) state[this.pos++] ^= data[pos++];
|
|
932
|
+
if (this.pos === blockLen) this.keccak();
|
|
933
|
+
}
|
|
934
|
+
return this;
|
|
935
|
+
}
|
|
936
|
+
finish() {
|
|
937
|
+
if (this.finished) return;
|
|
938
|
+
this.finished = true;
|
|
939
|
+
const { state, suffix, pos, blockLen } = this;
|
|
940
|
+
state[pos] ^= suffix;
|
|
941
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1) this.keccak();
|
|
942
|
+
state[blockLen - 1] ^= 128;
|
|
943
|
+
this.keccak();
|
|
944
|
+
}
|
|
945
|
+
writeInto(out) {
|
|
946
|
+
aexists(this, false);
|
|
947
|
+
abytes(out);
|
|
948
|
+
this.finish();
|
|
949
|
+
const bufferOut = this.state;
|
|
950
|
+
const { blockLen } = this;
|
|
951
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
952
|
+
if (this.posOut >= blockLen) this.keccak();
|
|
953
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
954
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
955
|
+
this.posOut += take;
|
|
956
|
+
pos += take;
|
|
957
|
+
}
|
|
958
|
+
return out;
|
|
959
|
+
}
|
|
960
|
+
xofInto(out) {
|
|
961
|
+
if (!this.enableXOF) throw new Error("XOF is not possible for this instance");
|
|
962
|
+
return this.writeInto(out);
|
|
963
|
+
}
|
|
964
|
+
xof(bytes) {
|
|
965
|
+
anumber(bytes);
|
|
966
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
967
|
+
}
|
|
968
|
+
digestInto(out) {
|
|
969
|
+
aoutput(out, this);
|
|
970
|
+
if (this.finished) throw new Error("digest() was already called");
|
|
971
|
+
this.writeInto(out);
|
|
972
|
+
this.destroy();
|
|
973
|
+
return out;
|
|
974
|
+
}
|
|
975
|
+
digest() {
|
|
976
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
977
|
+
}
|
|
978
|
+
destroy() {
|
|
979
|
+
this.destroyed = true;
|
|
980
|
+
clean(this.state);
|
|
981
|
+
}
|
|
982
|
+
_cloneInto(to) {
|
|
983
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
984
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
985
|
+
to.state32.set(this.state32);
|
|
986
|
+
to.pos = this.pos;
|
|
987
|
+
to.posOut = this.posOut;
|
|
988
|
+
to.finished = this.finished;
|
|
989
|
+
to.rounds = rounds;
|
|
990
|
+
to.suffix = suffix;
|
|
991
|
+
to.outputLen = outputLen;
|
|
992
|
+
to.enableXOF = enableXOF;
|
|
993
|
+
to.destroyed = this.destroyed;
|
|
994
|
+
return to;
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
var gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
998
|
+
/** SHA3-256 hash function. Different from keccak-256. */
|
|
999
|
+
var sha3_256 = /* @__PURE__ */ (() => gen(6, 136, 32))();
|
|
1000
|
+
/** SHA3-512 hash function. */
|
|
1001
|
+
var sha3_512 = /* @__PURE__ */ (() => gen(6, 72, 64))();
|
|
1002
|
+
var genShake = (suffix, blockLen, outputLen) => createXOFer((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
|
|
1003
|
+
/** SHAKE256 XOF with 256-bit security. */
|
|
1004
|
+
var shake256 = /* @__PURE__ */ (() => genShake(31, 136, 32))();
|
|
1005
|
+
/**
|
|
1006
|
+
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
|
1007
|
+
*
|
|
1008
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
1009
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
1010
|
+
*
|
|
1011
|
+
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
1012
|
+
* @module
|
|
1013
|
+
* @deprecated
|
|
1014
|
+
*/
|
|
1015
|
+
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
1016
|
+
var sha256 = sha256$1;
|
|
1017
|
+
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
1018
|
+
var sha224 = sha224$1;
|
|
1019
|
+
/**
|
|
1020
|
+
* SHA2-512 a.k.a. sha512 and sha384. It is slower than sha256 in js because u64 operations are slow.
|
|
1021
|
+
*
|
|
1022
|
+
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
1023
|
+
* [the paper on truncated SHA512/256](https://eprint.iacr.org/2010/548.pdf).
|
|
1024
|
+
* @module
|
|
1025
|
+
* @deprecated
|
|
1026
|
+
*/
|
|
1027
|
+
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
1028
|
+
var sha512 = sha512$1;
|
|
1029
|
+
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
1030
|
+
var sha384 = sha384$1;
|
|
1031
|
+
//#endregion
|
|
1032
|
+
export { sha3_512 as C, toBytes as D, shake256 as E, wrapConstructor as O, sha3_256 as S, sha512$1 as T, sha224 as _, abytes as a, sha384 as b, anumber as c, concatBytes as d, createHasher as f, rotl as g, randomBytes as h, Maj as i, bytesToHex as l, isBytes as m, Hash as n, aexists as o, hexToBytes as p, HashMD as r, ahash as s, Chi as t, clean as u, sha256 as v, sha512 as w, sha384$1 as x, sha256$1 as y };
|
|
1033
|
+
|
|
1034
|
+
//# sourceMappingURL=sha512-BYId-G-T.js.map
|