initial commit
This commit is contained in:
21
node_modules/ohash/LICENSE
generated
vendored
Normal file
21
node_modules/ohash/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
140
node_modules/ohash/README.md
generated
vendored
Normal file
140
node_modules/ohash/README.md
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
# ohash
|
||||
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![Github Actions][github-actions-src]][github-actions-href]
|
||||
[![Codecov][codecov-src]][codecov-href]
|
||||
[![bundle size][bundle-src]][bundle-href]
|
||||
|
||||
> Super fast hashing library written in Vanilla JS
|
||||
|
||||
## Usage
|
||||
|
||||
Install package:
|
||||
|
||||
```sh
|
||||
# npm
|
||||
npm install ohash
|
||||
|
||||
# yarn
|
||||
yarn add ohash
|
||||
|
||||
# pnpm
|
||||
pnpm install ohash
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import { hash, objectHash, murmurHash, sha256 } from 'ohash'
|
||||
|
||||
// CommonJS
|
||||
const { hash, objectHash, murmurHash, sha256 } = require('ohash')
|
||||
```
|
||||
|
||||
### `hash(object, options?)`
|
||||
|
||||
Converts object value into a string hash using `objectHash` and then applies `sha256` with Base64 encoding (trimmed by length of 10).
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
import { hash } from 'ohash'
|
||||
|
||||
// "dZbtA7f0lK"
|
||||
console.log(hash({ foo: 'bar' }))
|
||||
```
|
||||
|
||||
### `objectHash(object, options?)`
|
||||
|
||||
Converts a nest object value into a stable and safe string for hashing.
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
import { objectHash } from 'ohash'
|
||||
|
||||
// "object:1:string:3:foo:string:3:bar,"
|
||||
console.log(objectHash({ foo: 'bar'}))
|
||||
```
|
||||
|
||||
### `isEqual(obj1, obj2, options?)`
|
||||
|
||||
Compare two objects using reference equality and stable object hashing.
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
import { isEqual } from 'ohash'
|
||||
|
||||
// true
|
||||
console.log(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
||||
```
|
||||
|
||||
### `murmurHash(str)`
|
||||
|
||||
Converts input string (of any length) into a 32-bit positive integer using [MurmurHash3]((https://en.wikipedia.org/wiki/MurmurHash)).
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
import { murmurHash } from 'ohash'
|
||||
|
||||
// "2708020327"
|
||||
console.log(murmurHash('Hello World'))
|
||||
```
|
||||
|
||||
### `sha256`
|
||||
|
||||
Create a secure [SHA 256](https://en.wikipedia.org/wiki/SHA-2) digest from input string.
|
||||
|
||||
```js
|
||||
import { sha256 } from 'ohash'
|
||||
|
||||
// "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"
|
||||
console.log(sha256('Hello World'))
|
||||
```
|
||||
|
||||
### `sha256base64`
|
||||
|
||||
Create a secure [SHA 256](https://en.wikipedia.org/wiki/SHA-2) digest in Base64 encoding from input string.
|
||||
|
||||
```js
|
||||
import { sha256base64 } from 'ohash'
|
||||
|
||||
// "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4"
|
||||
console.log(sha256base64('Hello World'))
|
||||
```
|
||||
|
||||
## 💻 Development
|
||||
|
||||
- Clone this repository
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run interactive tests using `pnpm dev`
|
||||
|
||||
## License
|
||||
|
||||
Made with 💛
|
||||
|
||||
Published under [MIT License](./LICENSE).
|
||||
|
||||
Based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/), and implementations from [perezd/node-murmurhash](perezd/node-murmurhash) and
|
||||
[garycourt/murmurhash-js](https://github.com/garycourt/murmurhash-js) by [Gary Court](mailto:gary.court@gmail.com) and [Austin Appleby](mailto:aappleby@gmail.com) and [brix/crypto-js](https://github.com/brix/crypto-js).
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/v/ohash?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/ohash
|
||||
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/ohash?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/ohash
|
||||
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ohash/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/ohash/actions?query=workflow%3Aci
|
||||
|
||||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ohash/main?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/unjs/ohash
|
||||
|
||||
[bundle-src]: https://flat.badgen.net/bundlephobia/minzip/ohash
|
||||
[bundle-href]: https://bundlephobia.com/package/ohash
|
||||
551
node_modules/ohash/dist/index.cjs
generated
vendored
Normal file
551
node_modules/ohash/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,551 @@
|
||||
'use strict';
|
||||
|
||||
const defaults = {
|
||||
ignoreUnknown: false,
|
||||
respectType: false,
|
||||
respectFunctionNames: false,
|
||||
respectFunctionProperties: false,
|
||||
unorderedObjects: true,
|
||||
unorderedArrays: false,
|
||||
unorderedSets: false
|
||||
};
|
||||
function objectHash(object, options = {}) {
|
||||
options = { ...defaults, ...options };
|
||||
const hasher = createHasher(options);
|
||||
hasher.dispatch(object);
|
||||
return hasher.toString();
|
||||
}
|
||||
function createHasher(options) {
|
||||
const buff = [];
|
||||
let context = [];
|
||||
const write = (str) => {
|
||||
buff.push(str);
|
||||
};
|
||||
return {
|
||||
toString() {
|
||||
return buff.join("");
|
||||
},
|
||||
getContext() {
|
||||
return context;
|
||||
},
|
||||
dispatch(value) {
|
||||
if (options.replacer) {
|
||||
value = options.replacer(value);
|
||||
}
|
||||
const type = value === null ? "null" : typeof value;
|
||||
return this["_" + type](value);
|
||||
},
|
||||
_object(object) {
|
||||
const pattern = /\[object (.*)]/i;
|
||||
const objString = Object.prototype.toString.call(object);
|
||||
const _objType = pattern.exec(objString);
|
||||
const objType = _objType ? _objType[1].toLowerCase() : "unknown:[" + objString.toLowerCase() + "]";
|
||||
let objectNumber = null;
|
||||
if ((objectNumber = context.indexOf(object)) >= 0) {
|
||||
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
||||
} else {
|
||||
context.push(object);
|
||||
}
|
||||
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
||||
write("buffer:");
|
||||
return write(object.toString("utf8"));
|
||||
}
|
||||
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
||||
if (this["_" + objType]) {
|
||||
this["_" + objType](object);
|
||||
} else if (options.ignoreUnknown) {
|
||||
return write("[" + objType + "]");
|
||||
} else {
|
||||
throw new Error('Unknown object type "' + objType + '"');
|
||||
}
|
||||
} else {
|
||||
let keys = Object.keys(object);
|
||||
if (options.unorderedObjects) {
|
||||
keys = keys.sort();
|
||||
}
|
||||
if (options.respectType !== false && !isNativeFunction(object)) {
|
||||
keys.splice(0, 0, "prototype", "__proto__", "letructor");
|
||||
}
|
||||
if (options.excludeKeys) {
|
||||
keys = keys.filter(function(key) {
|
||||
return !options.excludeKeys(key);
|
||||
});
|
||||
}
|
||||
write("object:" + keys.length + ":");
|
||||
for (const key of keys) {
|
||||
this.dispatch(key);
|
||||
write(":");
|
||||
if (!options.excludeValues) {
|
||||
this.dispatch(object[key]);
|
||||
}
|
||||
write(",");
|
||||
}
|
||||
}
|
||||
},
|
||||
_array(arr, unordered) {
|
||||
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
||||
write("array:" + arr.length + ":");
|
||||
if (!unordered || arr.length <= 1) {
|
||||
for (const entry of arr) {
|
||||
this.dispatch(entry);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const contextAdditions = [];
|
||||
const entries = arr.map((entry) => {
|
||||
const hasher = createHasher(options);
|
||||
hasher.dispatch(entry);
|
||||
contextAdditions.push(hasher.getContext());
|
||||
return hasher.toString();
|
||||
});
|
||||
context = [...context, ...contextAdditions];
|
||||
entries.sort();
|
||||
return this._array(entries, false);
|
||||
},
|
||||
_date(date) {
|
||||
return write("date:" + date.toJSON());
|
||||
},
|
||||
_symbol(sym) {
|
||||
return write("symbol:" + sym.toString());
|
||||
},
|
||||
_error(err) {
|
||||
return write("error:" + err.toString());
|
||||
},
|
||||
_boolean(bool) {
|
||||
return write("bool:" + bool.toString());
|
||||
},
|
||||
_string(string) {
|
||||
write("string:" + string.length + ":");
|
||||
write(string.toString());
|
||||
},
|
||||
_function(fn) {
|
||||
write("fn:");
|
||||
if (isNativeFunction(fn)) {
|
||||
this.dispatch("[native]");
|
||||
} else {
|
||||
this.dispatch(fn.toString());
|
||||
}
|
||||
if (options.respectFunctionNames !== false) {
|
||||
this.dispatch("function-name:" + String(fn.name));
|
||||
}
|
||||
if (options.respectFunctionProperties) {
|
||||
this._object(fn);
|
||||
}
|
||||
},
|
||||
_number(number) {
|
||||
return write("number:" + number.toString());
|
||||
},
|
||||
_xml(xml) {
|
||||
return write("xml:" + xml.toString());
|
||||
},
|
||||
_null() {
|
||||
return write("Null");
|
||||
},
|
||||
_undefined() {
|
||||
return write("Undefined");
|
||||
},
|
||||
_regexp(regex) {
|
||||
return write("regex:" + regex.toString());
|
||||
},
|
||||
_uint8array(arr) {
|
||||
write("uint8array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint8clampedarray(arr) {
|
||||
write("uint8clampedarray:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int8array(arr) {
|
||||
write("int8array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint16array(arr) {
|
||||
write("uint16array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int16array(arr) {
|
||||
write("int16array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint32array(arr) {
|
||||
write("uint32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int32array(arr) {
|
||||
write("int32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float32array(arr) {
|
||||
write("float32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float64array(arr) {
|
||||
write("float64array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_arraybuffer(arr) {
|
||||
write("arraybuffer:");
|
||||
return this.dispatch(new Uint8Array(arr));
|
||||
},
|
||||
_url(url) {
|
||||
return write("url:" + url.toString());
|
||||
},
|
||||
_map(map) {
|
||||
write("map:");
|
||||
const arr = [...map];
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_set(set) {
|
||||
write("set:");
|
||||
const arr = [...set];
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_file(file) {
|
||||
write("file:");
|
||||
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
||||
},
|
||||
_blob() {
|
||||
if (options.ignoreUnknown) {
|
||||
return write("[blob]");
|
||||
}
|
||||
throw new Error('Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n');
|
||||
},
|
||||
_domwindow() {
|
||||
return write("domwindow");
|
||||
},
|
||||
_bigint(number) {
|
||||
return write("bigint:" + number.toString());
|
||||
},
|
||||
_process() {
|
||||
return write("process");
|
||||
},
|
||||
_timer() {
|
||||
return write("timer");
|
||||
},
|
||||
_pipe() {
|
||||
return write("pipe");
|
||||
},
|
||||
_tcp() {
|
||||
return write("tcp");
|
||||
},
|
||||
_udp() {
|
||||
return write("udp");
|
||||
},
|
||||
_tty() {
|
||||
return write("tty");
|
||||
},
|
||||
_statwatcher() {
|
||||
return write("statwatcher");
|
||||
},
|
||||
_securecontext() {
|
||||
return write("securecontext");
|
||||
},
|
||||
_connection() {
|
||||
return write("connection");
|
||||
},
|
||||
_zlib() {
|
||||
return write("zlib");
|
||||
},
|
||||
_context() {
|
||||
return write("context");
|
||||
},
|
||||
_nodescript() {
|
||||
return write("nodescript");
|
||||
},
|
||||
_httpparser() {
|
||||
return write("httpparser");
|
||||
},
|
||||
_dataview() {
|
||||
return write("dataview");
|
||||
},
|
||||
_signal() {
|
||||
return write("signal");
|
||||
},
|
||||
_fsevent() {
|
||||
return write("fsevent");
|
||||
},
|
||||
_tlswrap() {
|
||||
return write("tlswrap");
|
||||
}
|
||||
};
|
||||
}
|
||||
function isNativeFunction(f) {
|
||||
if (typeof f !== "function") {
|
||||
return false;
|
||||
}
|
||||
const exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code]\s+}$/i;
|
||||
return exp.exec(Function.prototype.toString.call(f)) != null;
|
||||
}
|
||||
|
||||
class WordArray {
|
||||
constructor(words, sigBytes) {
|
||||
words = this.words = words || [];
|
||||
this.sigBytes = sigBytes !== void 0 ? sigBytes : words.length * 4;
|
||||
}
|
||||
toString(encoder) {
|
||||
return (encoder || Hex).stringify(this);
|
||||
}
|
||||
concat(wordArray) {
|
||||
this.clamp();
|
||||
if (this.sigBytes % 4) {
|
||||
for (let i = 0; i < wordArray.sigBytes; i++) {
|
||||
const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < wordArray.sigBytes; j += 4) {
|
||||
this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
|
||||
}
|
||||
}
|
||||
this.sigBytes += wordArray.sigBytes;
|
||||
return this;
|
||||
}
|
||||
clamp() {
|
||||
this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
|
||||
this.words.length = Math.ceil(this.sigBytes / 4);
|
||||
}
|
||||
clone() {
|
||||
return new WordArray([...this.words]);
|
||||
}
|
||||
}
|
||||
const Hex = {
|
||||
stringify(wordArray) {
|
||||
const hexChars = [];
|
||||
for (let i = 0; i < wordArray.sigBytes; i++) {
|
||||
const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
hexChars.push(
|
||||
(bite >>> 4).toString(16),
|
||||
(bite & 15).toString(16)
|
||||
);
|
||||
}
|
||||
return hexChars.join("");
|
||||
}
|
||||
};
|
||||
const Base64 = {
|
||||
stringify(wordArray) {
|
||||
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const base64Chars = [];
|
||||
for (let i = 0; i < wordArray.sigBytes; i += 3) {
|
||||
const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
||||
const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
||||
const triplet = byte1 << 16 | byte2 << 8 | byte3;
|
||||
for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
|
||||
base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
|
||||
}
|
||||
}
|
||||
return base64Chars.join("");
|
||||
}
|
||||
};
|
||||
const Latin1 = {
|
||||
parse(latin1Str) {
|
||||
const latin1StrLength = latin1Str.length;
|
||||
const words = [];
|
||||
for (let i = 0; i < latin1StrLength; i++) {
|
||||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
||||
}
|
||||
return new WordArray(words, latin1StrLength);
|
||||
}
|
||||
};
|
||||
const Utf8 = {
|
||||
parse(utf8Str) {
|
||||
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
||||
}
|
||||
};
|
||||
class BufferedBlockAlgorithm {
|
||||
constructor() {
|
||||
this._minBufferSize = 0;
|
||||
this.blockSize = 512 / 32;
|
||||
this.reset();
|
||||
}
|
||||
reset() {
|
||||
this._data = new WordArray();
|
||||
this._nDataBytes = 0;
|
||||
}
|
||||
_append(data) {
|
||||
if (typeof data === "string") {
|
||||
data = Utf8.parse(data);
|
||||
}
|
||||
this._data.concat(data);
|
||||
this._nDataBytes += data.sigBytes;
|
||||
}
|
||||
_doProcessBlock(_dataWords, _offset) {
|
||||
}
|
||||
_process(doFlush) {
|
||||
let processedWords;
|
||||
let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
|
||||
if (doFlush) {
|
||||
nBlocksReady = Math.ceil(nBlocksReady);
|
||||
} else {
|
||||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
||||
}
|
||||
const nWordsReady = nBlocksReady * this.blockSize;
|
||||
const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
|
||||
if (nWordsReady) {
|
||||
for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
|
||||
this._doProcessBlock(this._data.words, offset);
|
||||
}
|
||||
processedWords = this._data.words.splice(0, nWordsReady);
|
||||
this._data.sigBytes -= nBytesReady;
|
||||
}
|
||||
return new WordArray(processedWords, nBytesReady);
|
||||
}
|
||||
}
|
||||
class Hasher extends BufferedBlockAlgorithm {
|
||||
update(messageUpdate) {
|
||||
this._append(messageUpdate);
|
||||
this._process();
|
||||
return this;
|
||||
}
|
||||
finalize(messageUpdate) {
|
||||
if (messageUpdate) {
|
||||
this._append(messageUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const H = [1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225];
|
||||
const K = [1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998];
|
||||
const W = [];
|
||||
class SHA256 extends Hasher {
|
||||
constructor() {
|
||||
super();
|
||||
this.reset();
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._hash = new WordArray([...H]);
|
||||
}
|
||||
_doProcessBlock(M, offset) {
|
||||
const H2 = this._hash.words;
|
||||
let a = H2[0];
|
||||
let b = H2[1];
|
||||
let c = H2[2];
|
||||
let d = H2[3];
|
||||
let e = H2[4];
|
||||
let f = H2[5];
|
||||
let g = H2[6];
|
||||
let h = H2[7];
|
||||
for (let i = 0; i < 64; i++) {
|
||||
if (i < 16) {
|
||||
W[i] = M[offset + i] | 0;
|
||||
} else {
|
||||
const gamma0x = W[i - 15];
|
||||
const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
||||
const gamma1x = W[i - 2];
|
||||
const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
||||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
||||
}
|
||||
const ch = e & f ^ ~e & g;
|
||||
const maj = a & b ^ a & c ^ b & c;
|
||||
const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
||||
const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
|
||||
const t1 = h + sigma1 + ch + K[i] + W[i];
|
||||
const t2 = sigma0 + maj;
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1 | 0;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2 | 0;
|
||||
}
|
||||
H2[0] = H2[0] + a | 0;
|
||||
H2[1] = H2[1] + b | 0;
|
||||
H2[2] = H2[2] + c | 0;
|
||||
H2[3] = H2[3] + d | 0;
|
||||
H2[4] = H2[4] + e | 0;
|
||||
H2[5] = H2[5] + f | 0;
|
||||
H2[6] = H2[6] + g | 0;
|
||||
H2[7] = H2[7] + h | 0;
|
||||
}
|
||||
finalize(messageUpdate) {
|
||||
super.finalize(messageUpdate);
|
||||
const nBitsTotal = this._nDataBytes * 8;
|
||||
const nBitsLeft = this._data.sigBytes * 8;
|
||||
this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
||||
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
|
||||
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
||||
this._data.sigBytes = this._data.words.length * 4;
|
||||
this._process();
|
||||
return this._hash;
|
||||
}
|
||||
}
|
||||
function sha256(message) {
|
||||
return new SHA256().finalize(message).toString();
|
||||
}
|
||||
function sha256base64(message) {
|
||||
return new SHA256().finalize(message).toString(Base64);
|
||||
}
|
||||
|
||||
function hash(object, options = {}) {
|
||||
const hashed = typeof object === "string" ? object : objectHash(object, options);
|
||||
return sha256base64(hashed).slice(0, 10);
|
||||
}
|
||||
|
||||
function murmurHash(key, seed = 0) {
|
||||
if (typeof key === "string") {
|
||||
key = createBuffer(key);
|
||||
}
|
||||
let i = 0;
|
||||
let h1 = seed;
|
||||
let k1;
|
||||
let h1b;
|
||||
const remainder = key.length & 3;
|
||||
const bytes = key.length - remainder;
|
||||
const c1 = 3432918353;
|
||||
const c2 = 461845907;
|
||||
while (i < bytes) {
|
||||
k1 = key[i] & 255 | (key[++i] & 255) << 8 | (key[++i] & 255) << 16 | (key[++i] & 255) << 24;
|
||||
++i;
|
||||
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
|
||||
k1 = k1 << 15 | k1 >>> 17;
|
||||
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
|
||||
h1 ^= k1;
|
||||
h1 = h1 << 13 | h1 >>> 19;
|
||||
h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
|
||||
h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
|
||||
}
|
||||
k1 = 0;
|
||||
switch (remainder) {
|
||||
case 3:
|
||||
k1 ^= (key[i + 2] & 255) << 16;
|
||||
break;
|
||||
case 2:
|
||||
k1 ^= (key[i + 1] & 255) << 8;
|
||||
break;
|
||||
case 1:
|
||||
k1 ^= key[i] & 255;
|
||||
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
|
||||
k1 = k1 << 15 | k1 >>> 17;
|
||||
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
|
||||
h1 ^= k1;
|
||||
}
|
||||
h1 ^= key.length;
|
||||
h1 ^= h1 >>> 16;
|
||||
h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
|
||||
h1 ^= h1 >>> 13;
|
||||
h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
|
||||
h1 ^= h1 >>> 16;
|
||||
return h1 >>> 0;
|
||||
}
|
||||
function createBuffer(val) {
|
||||
return new TextEncoder().encode(val);
|
||||
}
|
||||
|
||||
function isEqual(object1, object2, hashOptions = {}) {
|
||||
if (object1 === object2) {
|
||||
return true;
|
||||
}
|
||||
if (objectHash(object1, hashOptions) === objectHash(object2, hashOptions)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
exports.hash = hash;
|
||||
exports.isEqual = isEqual;
|
||||
exports.murmurHash = murmurHash;
|
||||
exports.objectHash = objectHash;
|
||||
exports.sha256 = sha256;
|
||||
82
node_modules/ohash/dist/index.d.ts
generated
vendored
Normal file
82
node_modules/ohash/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
interface HashOptions {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
excludeKeys?: ((key: string) => boolean) | undefined;
|
||||
/**
|
||||
* hash object keys, values ignored
|
||||
*/
|
||||
excludeValues?: boolean | undefined;
|
||||
/**
|
||||
* ignore unknown object types
|
||||
*/
|
||||
ignoreUnknown?: boolean | undefined;
|
||||
/**
|
||||
* optional function that replaces values before hashing
|
||||
*/
|
||||
replacer?: ((value: any) => any) | undefined;
|
||||
/**
|
||||
* consider 'name' property of functions for hashing
|
||||
*/
|
||||
respectFunctionNames?: boolean | undefined;
|
||||
/**
|
||||
* consider function properties when hashing
|
||||
*/
|
||||
respectFunctionProperties?: boolean | undefined;
|
||||
/**
|
||||
* Respect special properties (prototype, letructor) when hashing to distinguish between types
|
||||
*/
|
||||
respectType?: boolean | undefined;
|
||||
/**
|
||||
* Sort all arrays before hashing
|
||||
*/
|
||||
unorderedArrays?: boolean | undefined;
|
||||
/**
|
||||
* Sort `Set` and `Map` instances before hashing
|
||||
*/
|
||||
unorderedObjects?: boolean | undefined;
|
||||
/**
|
||||
* Sort `Set` and `Map` instances before hashing
|
||||
*/
|
||||
unorderedSets?: boolean | undefined;
|
||||
}
|
||||
/**
|
||||
* Hash any JS value into a string with murmur v3 hash
|
||||
* @param {object} object value to hash
|
||||
* @param {HashOptions} options hashing options
|
||||
* @return {string} hash value
|
||||
* @api public
|
||||
*/
|
||||
declare function objectHash(object: any, options?: HashOptions): string;
|
||||
|
||||
/**
|
||||
* Hash any JS value into a string
|
||||
* @param {object} object value to hash
|
||||
* @param {HashOptions} options hashing options
|
||||
* @return {string} hash value
|
||||
* @api public
|
||||
*/
|
||||
declare function hash(object: any, options?: HashOptions): string;
|
||||
|
||||
/**
|
||||
* JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
|
||||
*
|
||||
* @param {Uint8Array | string} key ASCII only
|
||||
* @param {number} seed Positive integer only
|
||||
* @return {number} 32-bit positive integer hash
|
||||
*/
|
||||
declare function murmurHash(key: Uint8Array | string, seed?: number): number;
|
||||
|
||||
declare function sha256(message: string): any;
|
||||
|
||||
/**
|
||||
* Compare two objects using reference equality and stable deep hashing.
|
||||
* @param {any} object1 First object
|
||||
* @param {any} object2 Second object
|
||||
* @param {HashOptions} hash options
|
||||
* @return {boolean} true if equal and false if not
|
||||
* @api public
|
||||
*/
|
||||
declare function isEqual(object1: any, object2: any, hashOptions?: HashOptions): boolean;
|
||||
|
||||
export { hash, isEqual, murmurHash, objectHash, sha256 };
|
||||
545
node_modules/ohash/dist/index.mjs
generated
vendored
Normal file
545
node_modules/ohash/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,545 @@
|
||||
const defaults = {
|
||||
ignoreUnknown: false,
|
||||
respectType: false,
|
||||
respectFunctionNames: false,
|
||||
respectFunctionProperties: false,
|
||||
unorderedObjects: true,
|
||||
unorderedArrays: false,
|
||||
unorderedSets: false
|
||||
};
|
||||
function objectHash(object, options = {}) {
|
||||
options = { ...defaults, ...options };
|
||||
const hasher = createHasher(options);
|
||||
hasher.dispatch(object);
|
||||
return hasher.toString();
|
||||
}
|
||||
function createHasher(options) {
|
||||
const buff = [];
|
||||
let context = [];
|
||||
const write = (str) => {
|
||||
buff.push(str);
|
||||
};
|
||||
return {
|
||||
toString() {
|
||||
return buff.join("");
|
||||
},
|
||||
getContext() {
|
||||
return context;
|
||||
},
|
||||
dispatch(value) {
|
||||
if (options.replacer) {
|
||||
value = options.replacer(value);
|
||||
}
|
||||
const type = value === null ? "null" : typeof value;
|
||||
return this["_" + type](value);
|
||||
},
|
||||
_object(object) {
|
||||
const pattern = /\[object (.*)]/i;
|
||||
const objString = Object.prototype.toString.call(object);
|
||||
const _objType = pattern.exec(objString);
|
||||
const objType = _objType ? _objType[1].toLowerCase() : "unknown:[" + objString.toLowerCase() + "]";
|
||||
let objectNumber = null;
|
||||
if ((objectNumber = context.indexOf(object)) >= 0) {
|
||||
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
||||
} else {
|
||||
context.push(object);
|
||||
}
|
||||
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
||||
write("buffer:");
|
||||
return write(object.toString("utf8"));
|
||||
}
|
||||
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
||||
if (this["_" + objType]) {
|
||||
this["_" + objType](object);
|
||||
} else if (options.ignoreUnknown) {
|
||||
return write("[" + objType + "]");
|
||||
} else {
|
||||
throw new Error('Unknown object type "' + objType + '"');
|
||||
}
|
||||
} else {
|
||||
let keys = Object.keys(object);
|
||||
if (options.unorderedObjects) {
|
||||
keys = keys.sort();
|
||||
}
|
||||
if (options.respectType !== false && !isNativeFunction(object)) {
|
||||
keys.splice(0, 0, "prototype", "__proto__", "letructor");
|
||||
}
|
||||
if (options.excludeKeys) {
|
||||
keys = keys.filter(function(key) {
|
||||
return !options.excludeKeys(key);
|
||||
});
|
||||
}
|
||||
write("object:" + keys.length + ":");
|
||||
for (const key of keys) {
|
||||
this.dispatch(key);
|
||||
write(":");
|
||||
if (!options.excludeValues) {
|
||||
this.dispatch(object[key]);
|
||||
}
|
||||
write(",");
|
||||
}
|
||||
}
|
||||
},
|
||||
_array(arr, unordered) {
|
||||
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
||||
write("array:" + arr.length + ":");
|
||||
if (!unordered || arr.length <= 1) {
|
||||
for (const entry of arr) {
|
||||
this.dispatch(entry);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const contextAdditions = [];
|
||||
const entries = arr.map((entry) => {
|
||||
const hasher = createHasher(options);
|
||||
hasher.dispatch(entry);
|
||||
contextAdditions.push(hasher.getContext());
|
||||
return hasher.toString();
|
||||
});
|
||||
context = [...context, ...contextAdditions];
|
||||
entries.sort();
|
||||
return this._array(entries, false);
|
||||
},
|
||||
_date(date) {
|
||||
return write("date:" + date.toJSON());
|
||||
},
|
||||
_symbol(sym) {
|
||||
return write("symbol:" + sym.toString());
|
||||
},
|
||||
_error(err) {
|
||||
return write("error:" + err.toString());
|
||||
},
|
||||
_boolean(bool) {
|
||||
return write("bool:" + bool.toString());
|
||||
},
|
||||
_string(string) {
|
||||
write("string:" + string.length + ":");
|
||||
write(string.toString());
|
||||
},
|
||||
_function(fn) {
|
||||
write("fn:");
|
||||
if (isNativeFunction(fn)) {
|
||||
this.dispatch("[native]");
|
||||
} else {
|
||||
this.dispatch(fn.toString());
|
||||
}
|
||||
if (options.respectFunctionNames !== false) {
|
||||
this.dispatch("function-name:" + String(fn.name));
|
||||
}
|
||||
if (options.respectFunctionProperties) {
|
||||
this._object(fn);
|
||||
}
|
||||
},
|
||||
_number(number) {
|
||||
return write("number:" + number.toString());
|
||||
},
|
||||
_xml(xml) {
|
||||
return write("xml:" + xml.toString());
|
||||
},
|
||||
_null() {
|
||||
return write("Null");
|
||||
},
|
||||
_undefined() {
|
||||
return write("Undefined");
|
||||
},
|
||||
_regexp(regex) {
|
||||
return write("regex:" + regex.toString());
|
||||
},
|
||||
_uint8array(arr) {
|
||||
write("uint8array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint8clampedarray(arr) {
|
||||
write("uint8clampedarray:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int8array(arr) {
|
||||
write("int8array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint16array(arr) {
|
||||
write("uint16array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int16array(arr) {
|
||||
write("int16array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint32array(arr) {
|
||||
write("uint32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int32array(arr) {
|
||||
write("int32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float32array(arr) {
|
||||
write("float32array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float64array(arr) {
|
||||
write("float64array:");
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_arraybuffer(arr) {
|
||||
write("arraybuffer:");
|
||||
return this.dispatch(new Uint8Array(arr));
|
||||
},
|
||||
_url(url) {
|
||||
return write("url:" + url.toString());
|
||||
},
|
||||
_map(map) {
|
||||
write("map:");
|
||||
const arr = [...map];
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_set(set) {
|
||||
write("set:");
|
||||
const arr = [...set];
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_file(file) {
|
||||
write("file:");
|
||||
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
||||
},
|
||||
_blob() {
|
||||
if (options.ignoreUnknown) {
|
||||
return write("[blob]");
|
||||
}
|
||||
throw new Error('Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n');
|
||||
},
|
||||
_domwindow() {
|
||||
return write("domwindow");
|
||||
},
|
||||
_bigint(number) {
|
||||
return write("bigint:" + number.toString());
|
||||
},
|
||||
_process() {
|
||||
return write("process");
|
||||
},
|
||||
_timer() {
|
||||
return write("timer");
|
||||
},
|
||||
_pipe() {
|
||||
return write("pipe");
|
||||
},
|
||||
_tcp() {
|
||||
return write("tcp");
|
||||
},
|
||||
_udp() {
|
||||
return write("udp");
|
||||
},
|
||||
_tty() {
|
||||
return write("tty");
|
||||
},
|
||||
_statwatcher() {
|
||||
return write("statwatcher");
|
||||
},
|
||||
_securecontext() {
|
||||
return write("securecontext");
|
||||
},
|
||||
_connection() {
|
||||
return write("connection");
|
||||
},
|
||||
_zlib() {
|
||||
return write("zlib");
|
||||
},
|
||||
_context() {
|
||||
return write("context");
|
||||
},
|
||||
_nodescript() {
|
||||
return write("nodescript");
|
||||
},
|
||||
_httpparser() {
|
||||
return write("httpparser");
|
||||
},
|
||||
_dataview() {
|
||||
return write("dataview");
|
||||
},
|
||||
_signal() {
|
||||
return write("signal");
|
||||
},
|
||||
_fsevent() {
|
||||
return write("fsevent");
|
||||
},
|
||||
_tlswrap() {
|
||||
return write("tlswrap");
|
||||
}
|
||||
};
|
||||
}
|
||||
function isNativeFunction(f) {
|
||||
if (typeof f !== "function") {
|
||||
return false;
|
||||
}
|
||||
const exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code]\s+}$/i;
|
||||
return exp.exec(Function.prototype.toString.call(f)) != null;
|
||||
}
|
||||
|
||||
class WordArray {
|
||||
constructor(words, sigBytes) {
|
||||
words = this.words = words || [];
|
||||
this.sigBytes = sigBytes !== void 0 ? sigBytes : words.length * 4;
|
||||
}
|
||||
toString(encoder) {
|
||||
return (encoder || Hex).stringify(this);
|
||||
}
|
||||
concat(wordArray) {
|
||||
this.clamp();
|
||||
if (this.sigBytes % 4) {
|
||||
for (let i = 0; i < wordArray.sigBytes; i++) {
|
||||
const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < wordArray.sigBytes; j += 4) {
|
||||
this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
|
||||
}
|
||||
}
|
||||
this.sigBytes += wordArray.sigBytes;
|
||||
return this;
|
||||
}
|
||||
clamp() {
|
||||
this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
|
||||
this.words.length = Math.ceil(this.sigBytes / 4);
|
||||
}
|
||||
clone() {
|
||||
return new WordArray([...this.words]);
|
||||
}
|
||||
}
|
||||
const Hex = {
|
||||
stringify(wordArray) {
|
||||
const hexChars = [];
|
||||
for (let i = 0; i < wordArray.sigBytes; i++) {
|
||||
const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
hexChars.push(
|
||||
(bite >>> 4).toString(16),
|
||||
(bite & 15).toString(16)
|
||||
);
|
||||
}
|
||||
return hexChars.join("");
|
||||
}
|
||||
};
|
||||
const Base64 = {
|
||||
stringify(wordArray) {
|
||||
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const base64Chars = [];
|
||||
for (let i = 0; i < wordArray.sigBytes; i += 3) {
|
||||
const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
||||
const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
||||
const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
||||
const triplet = byte1 << 16 | byte2 << 8 | byte3;
|
||||
for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
|
||||
base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
|
||||
}
|
||||
}
|
||||
return base64Chars.join("");
|
||||
}
|
||||
};
|
||||
const Latin1 = {
|
||||
parse(latin1Str) {
|
||||
const latin1StrLength = latin1Str.length;
|
||||
const words = [];
|
||||
for (let i = 0; i < latin1StrLength; i++) {
|
||||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
||||
}
|
||||
return new WordArray(words, latin1StrLength);
|
||||
}
|
||||
};
|
||||
const Utf8 = {
|
||||
parse(utf8Str) {
|
||||
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
||||
}
|
||||
};
|
||||
class BufferedBlockAlgorithm {
|
||||
constructor() {
|
||||
this._minBufferSize = 0;
|
||||
this.blockSize = 512 / 32;
|
||||
this.reset();
|
||||
}
|
||||
reset() {
|
||||
this._data = new WordArray();
|
||||
this._nDataBytes = 0;
|
||||
}
|
||||
_append(data) {
|
||||
if (typeof data === "string") {
|
||||
data = Utf8.parse(data);
|
||||
}
|
||||
this._data.concat(data);
|
||||
this._nDataBytes += data.sigBytes;
|
||||
}
|
||||
_doProcessBlock(_dataWords, _offset) {
|
||||
}
|
||||
_process(doFlush) {
|
||||
let processedWords;
|
||||
let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
|
||||
if (doFlush) {
|
||||
nBlocksReady = Math.ceil(nBlocksReady);
|
||||
} else {
|
||||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
||||
}
|
||||
const nWordsReady = nBlocksReady * this.blockSize;
|
||||
const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
|
||||
if (nWordsReady) {
|
||||
for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
|
||||
this._doProcessBlock(this._data.words, offset);
|
||||
}
|
||||
processedWords = this._data.words.splice(0, nWordsReady);
|
||||
this._data.sigBytes -= nBytesReady;
|
||||
}
|
||||
return new WordArray(processedWords, nBytesReady);
|
||||
}
|
||||
}
|
||||
class Hasher extends BufferedBlockAlgorithm {
|
||||
update(messageUpdate) {
|
||||
this._append(messageUpdate);
|
||||
this._process();
|
||||
return this;
|
||||
}
|
||||
finalize(messageUpdate) {
|
||||
if (messageUpdate) {
|
||||
this._append(messageUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const H = [1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225];
|
||||
const K = [1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998];
|
||||
const W = [];
|
||||
class SHA256 extends Hasher {
|
||||
constructor() {
|
||||
super();
|
||||
this.reset();
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._hash = new WordArray([...H]);
|
||||
}
|
||||
_doProcessBlock(M, offset) {
|
||||
const H2 = this._hash.words;
|
||||
let a = H2[0];
|
||||
let b = H2[1];
|
||||
let c = H2[2];
|
||||
let d = H2[3];
|
||||
let e = H2[4];
|
||||
let f = H2[5];
|
||||
let g = H2[6];
|
||||
let h = H2[7];
|
||||
for (let i = 0; i < 64; i++) {
|
||||
if (i < 16) {
|
||||
W[i] = M[offset + i] | 0;
|
||||
} else {
|
||||
const gamma0x = W[i - 15];
|
||||
const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
||||
const gamma1x = W[i - 2];
|
||||
const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
||||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
||||
}
|
||||
const ch = e & f ^ ~e & g;
|
||||
const maj = a & b ^ a & c ^ b & c;
|
||||
const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
||||
const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
|
||||
const t1 = h + sigma1 + ch + K[i] + W[i];
|
||||
const t2 = sigma0 + maj;
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1 | 0;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2 | 0;
|
||||
}
|
||||
H2[0] = H2[0] + a | 0;
|
||||
H2[1] = H2[1] + b | 0;
|
||||
H2[2] = H2[2] + c | 0;
|
||||
H2[3] = H2[3] + d | 0;
|
||||
H2[4] = H2[4] + e | 0;
|
||||
H2[5] = H2[5] + f | 0;
|
||||
H2[6] = H2[6] + g | 0;
|
||||
H2[7] = H2[7] + h | 0;
|
||||
}
|
||||
finalize(messageUpdate) {
|
||||
super.finalize(messageUpdate);
|
||||
const nBitsTotal = this._nDataBytes * 8;
|
||||
const nBitsLeft = this._data.sigBytes * 8;
|
||||
this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
||||
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
|
||||
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
||||
this._data.sigBytes = this._data.words.length * 4;
|
||||
this._process();
|
||||
return this._hash;
|
||||
}
|
||||
}
|
||||
function sha256(message) {
|
||||
return new SHA256().finalize(message).toString();
|
||||
}
|
||||
function sha256base64(message) {
|
||||
return new SHA256().finalize(message).toString(Base64);
|
||||
}
|
||||
|
||||
function hash(object, options = {}) {
|
||||
const hashed = typeof object === "string" ? object : objectHash(object, options);
|
||||
return sha256base64(hashed).slice(0, 10);
|
||||
}
|
||||
|
||||
function murmurHash(key, seed = 0) {
|
||||
if (typeof key === "string") {
|
||||
key = createBuffer(key);
|
||||
}
|
||||
let i = 0;
|
||||
let h1 = seed;
|
||||
let k1;
|
||||
let h1b;
|
||||
const remainder = key.length & 3;
|
||||
const bytes = key.length - remainder;
|
||||
const c1 = 3432918353;
|
||||
const c2 = 461845907;
|
||||
while (i < bytes) {
|
||||
k1 = key[i] & 255 | (key[++i] & 255) << 8 | (key[++i] & 255) << 16 | (key[++i] & 255) << 24;
|
||||
++i;
|
||||
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
|
||||
k1 = k1 << 15 | k1 >>> 17;
|
||||
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
|
||||
h1 ^= k1;
|
||||
h1 = h1 << 13 | h1 >>> 19;
|
||||
h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
|
||||
h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
|
||||
}
|
||||
k1 = 0;
|
||||
switch (remainder) {
|
||||
case 3:
|
||||
k1 ^= (key[i + 2] & 255) << 16;
|
||||
break;
|
||||
case 2:
|
||||
k1 ^= (key[i + 1] & 255) << 8;
|
||||
break;
|
||||
case 1:
|
||||
k1 ^= key[i] & 255;
|
||||
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
|
||||
k1 = k1 << 15 | k1 >>> 17;
|
||||
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
|
||||
h1 ^= k1;
|
||||
}
|
||||
h1 ^= key.length;
|
||||
h1 ^= h1 >>> 16;
|
||||
h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
|
||||
h1 ^= h1 >>> 13;
|
||||
h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
|
||||
h1 ^= h1 >>> 16;
|
||||
return h1 >>> 0;
|
||||
}
|
||||
function createBuffer(val) {
|
||||
return new TextEncoder().encode(val);
|
||||
}
|
||||
|
||||
function isEqual(object1, object2, hashOptions = {}) {
|
||||
if (object1 === object2) {
|
||||
return true;
|
||||
}
|
||||
if (objectHash(object1, hashOptions) === objectHash(object2, hashOptions)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export { hash, isEqual, murmurHash, objectHash, sha256 };
|
||||
41
node_modules/ohash/package.json
generated
vendored
Normal file
41
node_modules/ohash/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "ohash",
|
||||
"version": "1.0.0",
|
||||
"description": "Super fast hashing library based on murmurhash3 written in Vanilla JS",
|
||||
"repository": "unjs/ohash",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest dev",
|
||||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
|
||||
"prepack": "unbuild",
|
||||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
||||
"test": "pnpm lint && vitest run"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.9",
|
||||
"c8": "^7.12.0",
|
||||
"eslint": "^8.27.0",
|
||||
"eslint-config-unjs": "^0.0.2",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^4.8.4",
|
||||
"unbuild": "^0.9.4",
|
||||
"vitest": "^0.25.2"
|
||||
},
|
||||
"packageManager": "pnpm@7.13.1"
|
||||
}
|
||||
Reference in New Issue
Block a user