index-CBBYARnU.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. const defaults = Object.freeze({
  2. ignoreUnknown: false,
  3. respectType: false,
  4. respectFunctionNames: false,
  5. respectFunctionProperties: false,
  6. unorderedObjects: true,
  7. unorderedArrays: false,
  8. unorderedSets: false,
  9. excludeKeys: void 0,
  10. excludeValues: void 0,
  11. replacer: void 0
  12. });
  13. function objectHash(object, options) {
  14. if (options) {
  15. options = { ...defaults, ...options };
  16. } else {
  17. options = defaults;
  18. }
  19. const hasher = createHasher(options);
  20. hasher.dispatch(object);
  21. return hasher.toString();
  22. }
  23. const defaultPrototypesKeys = Object.freeze([
  24. "prototype",
  25. "__proto__",
  26. "constructor"
  27. ]);
  28. function createHasher(options) {
  29. let buff = "";
  30. let context = /* @__PURE__ */ new Map();
  31. const write = (str) => {
  32. buff += str;
  33. };
  34. return {
  35. toString() {
  36. return buff;
  37. },
  38. getContext() {
  39. return context;
  40. },
  41. dispatch(value) {
  42. if (options.replacer) {
  43. value = options.replacer(value);
  44. }
  45. const type = value === null ? "null" : typeof value;
  46. return this[type](value);
  47. },
  48. object(object) {
  49. if (object && typeof object.toJSON === "function") {
  50. return this.object(object.toJSON());
  51. }
  52. const objString = Object.prototype.toString.call(object);
  53. let objType = "";
  54. const objectLength = objString.length;
  55. if (objectLength < 10) {
  56. objType = "unknown:[" + objString + "]";
  57. } else {
  58. objType = objString.slice(8, objectLength - 1);
  59. }
  60. objType = objType.toLowerCase();
  61. let objectNumber = null;
  62. if ((objectNumber = context.get(object)) === void 0) {
  63. context.set(object, context.size);
  64. } else {
  65. return this.dispatch("[CIRCULAR:" + objectNumber + "]");
  66. }
  67. if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
  68. write("buffer:");
  69. return write(object.toString("utf8"));
  70. }
  71. if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
  72. if (this[objType]) {
  73. this[objType](object);
  74. } else if (!options.ignoreUnknown) {
  75. this.unkown(object, objType);
  76. }
  77. } else {
  78. let keys = Object.keys(object);
  79. if (options.unorderedObjects) {
  80. keys = keys.sort();
  81. }
  82. let extraKeys = [];
  83. if (options.respectType !== false && !isNativeFunction(object)) {
  84. extraKeys = defaultPrototypesKeys;
  85. }
  86. if (options.excludeKeys) {
  87. keys = keys.filter((key) => {
  88. return !options.excludeKeys(key);
  89. });
  90. extraKeys = extraKeys.filter((key) => {
  91. return !options.excludeKeys(key);
  92. });
  93. }
  94. write("object:" + (keys.length + extraKeys.length) + ":");
  95. const dispatchForKey = (key) => {
  96. this.dispatch(key);
  97. write(":");
  98. if (!options.excludeValues) {
  99. this.dispatch(object[key]);
  100. }
  101. write(",");
  102. };
  103. for (const key of keys) {
  104. dispatchForKey(key);
  105. }
  106. for (const key of extraKeys) {
  107. dispatchForKey(key);
  108. }
  109. }
  110. },
  111. array(arr, unordered) {
  112. unordered = unordered === void 0 ? options.unorderedArrays !== false : unordered;
  113. write("array:" + arr.length + ":");
  114. if (!unordered || arr.length <= 1) {
  115. for (const entry of arr) {
  116. this.dispatch(entry);
  117. }
  118. return;
  119. }
  120. const contextAdditions = /* @__PURE__ */ new Map();
  121. const entries = arr.map((entry) => {
  122. const hasher = createHasher(options);
  123. hasher.dispatch(entry);
  124. for (const [key, value] of hasher.getContext()) {
  125. contextAdditions.set(key, value);
  126. }
  127. return hasher.toString();
  128. });
  129. context = contextAdditions;
  130. entries.sort();
  131. return this.array(entries, false);
  132. },
  133. date(date) {
  134. return write("date:" + date.toJSON());
  135. },
  136. symbol(sym) {
  137. return write("symbol:" + sym.toString());
  138. },
  139. unkown(value, type) {
  140. write(type);
  141. if (!value) {
  142. return;
  143. }
  144. write(":");
  145. if (value && typeof value.entries === "function") {
  146. return this.array(
  147. Array.from(value.entries()),
  148. true
  149. /* ordered */
  150. );
  151. }
  152. },
  153. error(err) {
  154. return write("error:" + err.toString());
  155. },
  156. boolean(bool) {
  157. return write("bool:" + bool);
  158. },
  159. string(string) {
  160. write("string:" + string.length + ":");
  161. write(string);
  162. },
  163. function(fn) {
  164. write("fn:");
  165. if (isNativeFunction(fn)) {
  166. this.dispatch("[native]");
  167. } else {
  168. this.dispatch(fn.toString());
  169. }
  170. if (options.respectFunctionNames !== false) {
  171. this.dispatch("function-name:" + String(fn.name));
  172. }
  173. if (options.respectFunctionProperties) {
  174. this.object(fn);
  175. }
  176. },
  177. number(number) {
  178. return write("number:" + number);
  179. },
  180. xml(xml) {
  181. return write("xml:" + xml.toString());
  182. },
  183. null() {
  184. return write("Null");
  185. },
  186. undefined() {
  187. return write("Undefined");
  188. },
  189. regexp(regex) {
  190. return write("regex:" + regex.toString());
  191. },
  192. uint8array(arr) {
  193. write("uint8array:");
  194. return this.dispatch(Array.prototype.slice.call(arr));
  195. },
  196. uint8clampedarray(arr) {
  197. write("uint8clampedarray:");
  198. return this.dispatch(Array.prototype.slice.call(arr));
  199. },
  200. int8array(arr) {
  201. write("int8array:");
  202. return this.dispatch(Array.prototype.slice.call(arr));
  203. },
  204. uint16array(arr) {
  205. write("uint16array:");
  206. return this.dispatch(Array.prototype.slice.call(arr));
  207. },
  208. int16array(arr) {
  209. write("int16array:");
  210. return this.dispatch(Array.prototype.slice.call(arr));
  211. },
  212. uint32array(arr) {
  213. write("uint32array:");
  214. return this.dispatch(Array.prototype.slice.call(arr));
  215. },
  216. int32array(arr) {
  217. write("int32array:");
  218. return this.dispatch(Array.prototype.slice.call(arr));
  219. },
  220. float32array(arr) {
  221. write("float32array:");
  222. return this.dispatch(Array.prototype.slice.call(arr));
  223. },
  224. float64array(arr) {
  225. write("float64array:");
  226. return this.dispatch(Array.prototype.slice.call(arr));
  227. },
  228. arraybuffer(arr) {
  229. write("arraybuffer:");
  230. return this.dispatch(new Uint8Array(arr));
  231. },
  232. url(url) {
  233. return write("url:" + url.toString());
  234. },
  235. map(map) {
  236. write("map:");
  237. const arr = [...map];
  238. return this.array(arr, options.unorderedSets !== false);
  239. },
  240. set(set) {
  241. write("set:");
  242. const arr = [...set];
  243. return this.array(arr, options.unorderedSets !== false);
  244. },
  245. file(file) {
  246. write("file:");
  247. return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
  248. },
  249. blob() {
  250. if (options.ignoreUnknown) {
  251. return write("[blob]");
  252. }
  253. throw new Error(
  254. 'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
  255. );
  256. },
  257. domwindow() {
  258. return write("domwindow");
  259. },
  260. bigint(number) {
  261. return write("bigint:" + number.toString());
  262. },
  263. /* Node.js standard native objects */
  264. process() {
  265. return write("process");
  266. },
  267. timer() {
  268. return write("timer");
  269. },
  270. pipe() {
  271. return write("pipe");
  272. },
  273. tcp() {
  274. return write("tcp");
  275. },
  276. udp() {
  277. return write("udp");
  278. },
  279. tty() {
  280. return write("tty");
  281. },
  282. statwatcher() {
  283. return write("statwatcher");
  284. },
  285. securecontext() {
  286. return write("securecontext");
  287. },
  288. connection() {
  289. return write("connection");
  290. },
  291. zlib() {
  292. return write("zlib");
  293. },
  294. context() {
  295. return write("context");
  296. },
  297. nodescript() {
  298. return write("nodescript");
  299. },
  300. httpparser() {
  301. return write("httpparser");
  302. },
  303. dataview() {
  304. return write("dataview");
  305. },
  306. signal() {
  307. return write("signal");
  308. },
  309. fsevent() {
  310. return write("fsevent");
  311. },
  312. tlswrap() {
  313. return write("tlswrap");
  314. }
  315. };
  316. }
  317. const nativeFunc = "[native code] }";
  318. const nativeFuncLength = nativeFunc.length;
  319. function isNativeFunction(f) {
  320. if (typeof f !== "function") {
  321. return false;
  322. }
  323. return Function.prototype.toString.call(f).slice(-nativeFuncLength) === nativeFunc;
  324. }
  325. var __defProp$1 = Object.defineProperty;
  326. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  327. var __publicField$1 = (obj, key, value) => {
  328. __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
  329. return value;
  330. };
  331. class WordArray {
  332. constructor(words, sigBytes) {
  333. __publicField$1(this, "words");
  334. __publicField$1(this, "sigBytes");
  335. words = this.words = words || [];
  336. this.sigBytes = sigBytes === void 0 ? words.length * 4 : sigBytes;
  337. }
  338. toString(encoder) {
  339. return (encoder || Hex).stringify(this);
  340. }
  341. concat(wordArray) {
  342. this.clamp();
  343. if (this.sigBytes % 4) {
  344. for (let i = 0; i < wordArray.sigBytes; i++) {
  345. const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  346. this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
  347. }
  348. } else {
  349. for (let j = 0; j < wordArray.sigBytes; j += 4) {
  350. this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
  351. }
  352. }
  353. this.sigBytes += wordArray.sigBytes;
  354. return this;
  355. }
  356. clamp() {
  357. this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
  358. this.words.length = Math.ceil(this.sigBytes / 4);
  359. }
  360. clone() {
  361. return new WordArray([...this.words]);
  362. }
  363. }
  364. const Hex = {
  365. stringify(wordArray) {
  366. const hexChars = [];
  367. for (let i = 0; i < wordArray.sigBytes; i++) {
  368. const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  369. hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
  370. }
  371. return hexChars.join("");
  372. }
  373. };
  374. const Base64 = {
  375. stringify(wordArray) {
  376. const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  377. const base64Chars = [];
  378. for (let i = 0; i < wordArray.sigBytes; i += 3) {
  379. const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  380. const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
  381. const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
  382. const triplet = byte1 << 16 | byte2 << 8 | byte3;
  383. for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
  384. base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
  385. }
  386. }
  387. return base64Chars.join("");
  388. }
  389. };
  390. const Latin1 = {
  391. parse(latin1Str) {
  392. const latin1StrLength = latin1Str.length;
  393. const words = [];
  394. for (let i = 0; i < latin1StrLength; i++) {
  395. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
  396. }
  397. return new WordArray(words, latin1StrLength);
  398. }
  399. };
  400. const Utf8 = {
  401. parse(utf8Str) {
  402. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  403. }
  404. };
  405. class BufferedBlockAlgorithm {
  406. constructor() {
  407. __publicField$1(this, "_data", new WordArray());
  408. __publicField$1(this, "_nDataBytes", 0);
  409. __publicField$1(this, "_minBufferSize", 0);
  410. __publicField$1(this, "blockSize", 512 / 32);
  411. }
  412. reset() {
  413. this._data = new WordArray();
  414. this._nDataBytes = 0;
  415. }
  416. _append(data) {
  417. if (typeof data === "string") {
  418. data = Utf8.parse(data);
  419. }
  420. this._data.concat(data);
  421. this._nDataBytes += data.sigBytes;
  422. }
  423. _doProcessBlock(_dataWords, _offset) {
  424. }
  425. _process(doFlush) {
  426. let processedWords;
  427. let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
  428. if (doFlush) {
  429. nBlocksReady = Math.ceil(nBlocksReady);
  430. } else {
  431. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  432. }
  433. const nWordsReady = nBlocksReady * this.blockSize;
  434. const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
  435. if (nWordsReady) {
  436. for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
  437. this._doProcessBlock(this._data.words, offset);
  438. }
  439. processedWords = this._data.words.splice(0, nWordsReady);
  440. this._data.sigBytes -= nBytesReady;
  441. }
  442. return new WordArray(processedWords, nBytesReady);
  443. }
  444. }
  445. class Hasher extends BufferedBlockAlgorithm {
  446. update(messageUpdate) {
  447. this._append(messageUpdate);
  448. this._process();
  449. return this;
  450. }
  451. finalize(messageUpdate) {
  452. if (messageUpdate) {
  453. this._append(messageUpdate);
  454. }
  455. }
  456. }
  457. var __defProp = Object.defineProperty;
  458. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  459. var __publicField = (obj, key, value) => {
  460. __defNormalProp(obj, key + "" , value);
  461. return value;
  462. };
  463. const H = [
  464. 1779033703,
  465. -1150833019,
  466. 1013904242,
  467. -1521486534,
  468. 1359893119,
  469. -1694144372,
  470. 528734635,
  471. 1541459225
  472. ];
  473. const K = [
  474. 1116352408,
  475. 1899447441,
  476. -1245643825,
  477. -373957723,
  478. 961987163,
  479. 1508970993,
  480. -1841331548,
  481. -1424204075,
  482. -670586216,
  483. 310598401,
  484. 607225278,
  485. 1426881987,
  486. 1925078388,
  487. -2132889090,
  488. -1680079193,
  489. -1046744716,
  490. -459576895,
  491. -272742522,
  492. 264347078,
  493. 604807628,
  494. 770255983,
  495. 1249150122,
  496. 1555081692,
  497. 1996064986,
  498. -1740746414,
  499. -1473132947,
  500. -1341970488,
  501. -1084653625,
  502. -958395405,
  503. -710438585,
  504. 113926993,
  505. 338241895,
  506. 666307205,
  507. 773529912,
  508. 1294757372,
  509. 1396182291,
  510. 1695183700,
  511. 1986661051,
  512. -2117940946,
  513. -1838011259,
  514. -1564481375,
  515. -1474664885,
  516. -1035236496,
  517. -949202525,
  518. -778901479,
  519. -694614492,
  520. -200395387,
  521. 275423344,
  522. 430227734,
  523. 506948616,
  524. 659060556,
  525. 883997877,
  526. 958139571,
  527. 1322822218,
  528. 1537002063,
  529. 1747873779,
  530. 1955562222,
  531. 2024104815,
  532. -2067236844,
  533. -1933114872,
  534. -1866530822,
  535. -1538233109,
  536. -1090935817,
  537. -965641998
  538. ];
  539. const W = [];
  540. class SHA256 extends Hasher {
  541. constructor() {
  542. super(...arguments);
  543. __publicField(this, "_hash", new WordArray([...H]));
  544. }
  545. /**
  546. * Resets the internal state of the hash object to initial values.
  547. */
  548. reset() {
  549. super.reset();
  550. this._hash = new WordArray([...H]);
  551. }
  552. _doProcessBlock(M, offset) {
  553. const H2 = this._hash.words;
  554. let a = H2[0];
  555. let b = H2[1];
  556. let c = H2[2];
  557. let d = H2[3];
  558. let e = H2[4];
  559. let f = H2[5];
  560. let g = H2[6];
  561. let h = H2[7];
  562. for (let i = 0; i < 64; i++) {
  563. if (i < 16) {
  564. W[i] = M[offset + i] | 0;
  565. } else {
  566. const gamma0x = W[i - 15];
  567. const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
  568. const gamma1x = W[i - 2];
  569. const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
  570. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  571. }
  572. const ch = e & f ^ ~e & g;
  573. const maj = a & b ^ a & c ^ b & c;
  574. const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
  575. const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
  576. const t1 = h + sigma1 + ch + K[i] + W[i];
  577. const t2 = sigma0 + maj;
  578. h = g;
  579. g = f;
  580. f = e;
  581. e = d + t1 | 0;
  582. d = c;
  583. c = b;
  584. b = a;
  585. a = t1 + t2 | 0;
  586. }
  587. H2[0] = H2[0] + a | 0;
  588. H2[1] = H2[1] + b | 0;
  589. H2[2] = H2[2] + c | 0;
  590. H2[3] = H2[3] + d | 0;
  591. H2[4] = H2[4] + e | 0;
  592. H2[5] = H2[5] + f | 0;
  593. H2[6] = H2[6] + g | 0;
  594. H2[7] = H2[7] + h | 0;
  595. }
  596. /**
  597. * Finishes the hash calculation and returns the hash as a WordArray.
  598. *
  599. * @param {string} messageUpdate - Additional message content to include in the hash.
  600. * @returns {WordArray} The finalised hash as a WordArray.
  601. */
  602. finalize(messageUpdate) {
  603. super.finalize(messageUpdate);
  604. const nBitsTotal = this._nDataBytes * 8;
  605. const nBitsLeft = this._data.sigBytes * 8;
  606. this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
  607. this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
  608. nBitsTotal / 4294967296
  609. );
  610. this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
  611. this._data.sigBytes = this._data.words.length * 4;
  612. this._process();
  613. return this._hash;
  614. }
  615. }
  616. function sha256base64(message) {
  617. return new SHA256().finalize(message).toString(Base64);
  618. }
  619. function hash(object, options = {}) {
  620. const hashed = typeof object === "string" ? object : objectHash(object, options);
  621. return sha256base64(hashed).slice(0, 10);
  622. }
  623. /* Injected with object hook! */
  624. export { hash, objectHash, sha256base64 };