市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
7.4 KiB

  1. function serialize(o) {
  2. return typeof o == "string" ? `'${o}'` : new c().serialize(o);
  3. }
  4. const c = /* @__PURE__ */ function() {
  5. class o {
  6. #t = new Map();
  7. compare(t, r$1) {
  8. const e = typeof t, n = typeof r$1;
  9. return e === "string" && n === "string" ? t.localeCompare(r$1) : e === "number" && n === "number" ? t - r$1 : String.prototype.localeCompare.call(this.serialize(t, true), this.serialize(r$1, true));
  10. }
  11. serialize(t, r$1) {
  12. if (t === null) return "null";
  13. switch (typeof t) {
  14. case "string": return r$1 ? t : `'${t}'`;
  15. case "bigint": return `${t}n`;
  16. case "object": return this.$object(t);
  17. case "function": return this.$function(t);
  18. }
  19. return String(t);
  20. }
  21. serializeObject(t) {
  22. const r$1 = Object.prototype.toString.call(t);
  23. if (r$1 !== "[object Object]") return this.serializeBuiltInType(r$1.length < 10 ? `unknown:${r$1}` : r$1.slice(8, -1), t);
  24. const e = t.constructor, n = e === Object || e === void 0 ? "" : e.name;
  25. if (n !== "" && globalThis[n] === e) return this.serializeBuiltInType(n, t);
  26. if (typeof t.toJSON == "function") {
  27. const i = t.toJSON();
  28. return n + (i !== null && typeof i == "object" ? this.$object(i) : `(${this.serialize(i)})`);
  29. }
  30. return this.serializeObjectEntries(n, Object.entries(t));
  31. }
  32. serializeBuiltInType(t, r$1) {
  33. const e = this["$" + t];
  34. if (e) return e.call(this, r$1);
  35. if (typeof r$1?.entries == "function") return this.serializeObjectEntries(t, r$1.entries());
  36. throw new Error(`Cannot serialize ${t}`);
  37. }
  38. serializeObjectEntries(t, r$1) {
  39. const e = Array.from(r$1).sort((i, a) => this.compare(i[0], a[0]));
  40. let n = `${t}{`;
  41. for (let i = 0; i < e.length; i++) {
  42. const [a, l$1] = e[i];
  43. n += `${this.serialize(a, true)}:${this.serialize(l$1)}`, i < e.length - 1 && (n += ",");
  44. }
  45. return n + "}";
  46. }
  47. $object(t) {
  48. let r$1 = this.#t.get(t);
  49. return r$1 === void 0 && (this.#t.set(t, `#${this.#t.size}`), r$1 = this.serializeObject(t), this.#t.set(t, r$1)), r$1;
  50. }
  51. $function(t) {
  52. const r$1 = Function.prototype.toString.call(t);
  53. return r$1.slice(-15) === "[native code] }" ? `${t.name || ""}()[native]` : `${t.name}(${t.length})${r$1.replace(/\s*\n\s*/g, "")}`;
  54. }
  55. $Array(t) {
  56. let r$1 = "[";
  57. for (let e = 0; e < t.length; e++) r$1 += this.serialize(t[e]), e < t.length - 1 && (r$1 += ",");
  58. return r$1 + "]";
  59. }
  60. $Date(t) {
  61. try {
  62. return `Date(${t.toISOString()})`;
  63. } catch {
  64. return "Date(null)";
  65. }
  66. }
  67. $ArrayBuffer(t) {
  68. return `ArrayBuffer[${new Uint8Array(t).join(",")}]`;
  69. }
  70. $Set(t) {
  71. return `Set${this.$Array(Array.from(t).sort((r$1, e) => this.compare(r$1, e)))}`;
  72. }
  73. $Map(t) {
  74. return this.serializeObjectEntries("Map", t.entries());
  75. }
  76. }
  77. for (const s of [
  78. "Error",
  79. "RegExp",
  80. "URL"
  81. ]) o.prototype["$" + s] = function(t) {
  82. return `${s}(${t})`;
  83. };
  84. for (const s of [
  85. "Int8Array",
  86. "Uint8Array",
  87. "Uint8ClampedArray",
  88. "Int16Array",
  89. "Uint16Array",
  90. "Int32Array",
  91. "Uint32Array",
  92. "Float32Array",
  93. "Float64Array"
  94. ]) o.prototype["$" + s] = function(t) {
  95. return `${s}[${t.join(",")}]`;
  96. };
  97. for (const s of ["BigInt64Array", "BigUint64Array"]) o.prototype["$" + s] = function(t) {
  98. return `${s}[${t.join("n,")}${t.length > 0 ? "n" : ""}]`;
  99. };
  100. return o;
  101. }();
  102. const z = [
  103. 1779033703,
  104. -1150833019,
  105. 1013904242,
  106. -1521486534,
  107. 1359893119,
  108. -1694144372,
  109. 528734635,
  110. 1541459225
  111. ], R = [
  112. 1116352408,
  113. 1899447441,
  114. -1245643825,
  115. -373957723,
  116. 961987163,
  117. 1508970993,
  118. -1841331548,
  119. -1424204075,
  120. -670586216,
  121. 310598401,
  122. 607225278,
  123. 1426881987,
  124. 1925078388,
  125. -2132889090,
  126. -1680079193,
  127. -1046744716,
  128. -459576895,
  129. -272742522,
  130. 264347078,
  131. 604807628,
  132. 770255983,
  133. 1249150122,
  134. 1555081692,
  135. 1996064986,
  136. -1740746414,
  137. -1473132947,
  138. -1341970488,
  139. -1084653625,
  140. -958395405,
  141. -710438585,
  142. 113926993,
  143. 338241895,
  144. 666307205,
  145. 773529912,
  146. 1294757372,
  147. 1396182291,
  148. 1695183700,
  149. 1986661051,
  150. -2117940946,
  151. -1838011259,
  152. -1564481375,
  153. -1474664885,
  154. -1035236496,
  155. -949202525,
  156. -778901479,
  157. -694614492,
  158. -200395387,
  159. 275423344,
  160. 430227734,
  161. 506948616,
  162. 659060556,
  163. 883997877,
  164. 958139571,
  165. 1322822218,
  166. 1537002063,
  167. 1747873779,
  168. 1955562222,
  169. 2024104815,
  170. -2067236844,
  171. -1933114872,
  172. -1866530822,
  173. -1538233109,
  174. -1090935817,
  175. -965641998
  176. ], S = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", r = [];
  177. var k = class {
  178. _data = new l();
  179. _hash = new l([...z]);
  180. _nDataBytes = 0;
  181. _minBufferSize = 0;
  182. finalize(e) {
  183. e && this._append(e);
  184. const s = this._nDataBytes * 8, t = this._data.sigBytes * 8;
  185. return this._data.words[t >>> 5] |= 128 << 24 - t % 32, this._data.words[(t + 64 >>> 9 << 4) + 14] = Math.floor(s / 4294967296), this._data.words[(t + 64 >>> 9 << 4) + 15] = s, this._data.sigBytes = this._data.words.length * 4, this._process(), this._hash;
  186. }
  187. _doProcessBlock(e, s) {
  188. const t = this._hash.words;
  189. let i = t[0], o = t[1], a = t[2], c$1 = t[3], h = t[4], g = t[5], f = t[6], y = t[7];
  190. for (let n = 0; n < 64; n++) {
  191. if (n < 16) r[n] = e[s + n] | 0;
  192. else {
  193. const d = r[n - 15], j = (d << 25 | d >>> 7) ^ (d << 14 | d >>> 18) ^ d >>> 3, B = r[n - 2], x = (B << 15 | B >>> 17) ^ (B << 13 | B >>> 19) ^ B >>> 10;
  194. r[n] = j + r[n - 7] + x + r[n - 16];
  195. }
  196. const m = h & g ^ ~h & f, p = i & o ^ i & a ^ o & a, u = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), b = (h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25), w = y + b + m + R[n] + r[n], M = u + p;
  197. y = f, f = g, g = h, h = c$1 + w | 0, c$1 = a, a = o, o = i, i = w + M | 0;
  198. }
  199. t[0] = t[0] + i | 0, t[1] = t[1] + o | 0, t[2] = t[2] + a | 0, t[3] = t[3] + c$1 | 0, t[4] = t[4] + h | 0, t[5] = t[5] + g | 0, t[6] = t[6] + f | 0, t[7] = t[7] + y | 0;
  200. }
  201. _append(e) {
  202. typeof e == "string" && (e = l.fromUtf8(e)), this._data.concat(e), this._nDataBytes += e.sigBytes;
  203. }
  204. _process(e) {
  205. let s, t = this._data.sigBytes / 64;
  206. e ? t = Math.ceil(t) : t = Math.max((t | 0) - this._minBufferSize, 0);
  207. const i = t * 16, o = Math.min(i * 4, this._data.sigBytes);
  208. if (i) {
  209. for (let a = 0; a < i; a += 16) this._doProcessBlock(this._data.words, a);
  210. s = this._data.words.splice(0, i), this._data.sigBytes -= o;
  211. }
  212. return new l(s, o);
  213. }
  214. };
  215. var l = class l {
  216. words;
  217. sigBytes;
  218. constructor(e, s) {
  219. e = this.words = e || [], this.sigBytes = s === void 0 ? e.length * 4 : s;
  220. }
  221. static fromUtf8(e) {
  222. const s = unescape(encodeURIComponent(e)), t = s.length, i = [];
  223. for (let o = 0; o < t; o++) i[o >>> 2] |= (s.charCodeAt(o) & 255) << 24 - o % 4 * 8;
  224. return new l(i, t);
  225. }
  226. toBase64() {
  227. const e = [];
  228. for (let s = 0; s < this.sigBytes; s += 3) {
  229. const t = this.words[s >>> 2] >>> 24 - s % 4 * 8 & 255, i = this.words[s + 1 >>> 2] >>> 24 - (s + 1) % 4 * 8 & 255, o = this.words[s + 2 >>> 2] >>> 24 - (s + 2) % 4 * 8 & 255, a = t << 16 | i << 8 | o;
  230. for (let c$1 = 0; c$1 < 4 && s * 8 + c$1 * 6 < this.sigBytes * 8; c$1++) e.push(S.charAt(a >>> 6 * (3 - c$1) & 63));
  231. }
  232. return e.join("");
  233. }
  234. concat(e) {
  235. if (this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8, this.words.length = Math.ceil(this.sigBytes / 4), this.sigBytes % 4) for (let s = 0; s < e.sigBytes; s++) {
  236. const t = e.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
  237. this.words[this.sigBytes + s >>> 2] |= t << 24 - (this.sigBytes + s) % 4 * 8;
  238. }
  239. else for (let s = 0; s < e.sigBytes; s += 4) this.words[this.sigBytes + s >>> 2] = e.words[s >>> 2];
  240. this.sigBytes += e.sigBytes;
  241. }
  242. };
  243. function digest(_) {
  244. return new k().finalize(_).toBase64();
  245. }
  246. function hash(input) {
  247. return digest(serialize(input));
  248. }
  249. export { hash };