@stryke/hash 0.10.0 → 0.12.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.
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Hasher = void 0;
7
+ exports.createHasher = createHasher;
8
+ exports.digest = digest;
9
+ exports.hash = void 0;
10
+ var _neutral = require("@stryke/convert/neutral");
11
+ function createHasher(r) {
12
+ return new Hasher(r);
13
+ }
14
+ async function digest(r, t = "SHA-512") {
15
+ const e = await globalThis.crypto.subtle.digest(t, (0, _neutral.stringToUint8Array)(r));
16
+ return (0, _neutral.arrayBufferToString)(e);
17
+ }
18
+ const hash = exports.hash = digest;
19
+ class Hasher {
20
+ #t = [];
21
+ #r;
22
+ constructor(t) {
23
+ this.#r = t;
24
+ }
25
+ update(t) {
26
+ this.#t.push(t);
27
+ }
28
+ async digest() {
29
+ const t = new Uint8Array(this.#t.reduce((i, s) => i + s.length, 0));
30
+ let e = 0;
31
+ for (const i of this.#t) t.set(i, e), e += i.length;
32
+ const n = await globalThis.crypto.subtle.digest(this.#r, t);
33
+ return new Uint8Array(n);
34
+ }
35
+ }
36
+ exports.Hasher = Hasher;
@@ -0,0 +1,28 @@
1
+ export type AlgorithmIdentifier = "SHA-256" | "SHA-384" | "SHA-512";
2
+ /**
3
+ * Creates a new hash object for the specified algorithm.
4
+ *
5
+ * @param algorithm - The algorithm to use for the hash.
6
+ * @returns A new hash object.
7
+ */
8
+ export declare function createHasher(algorithm: AlgorithmIdentifier): Hasher;
9
+ /**
10
+ * Creates a new hash object for the specified algorithm.
11
+ *
12
+ * @remarks
13
+ * This function uses the Web Crypto API to create a hash of the input data.
14
+ *
15
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
16
+ *
17
+ * @param data - The data to hash.
18
+ * @param algorithm - The algorithm to use for the hash.
19
+ * @returns A hash string representation of the `data` parameter.
20
+ */
21
+ export declare function digest(data: string, algorithm?: AlgorithmIdentifier): Promise<string>;
22
+ export declare const hash: typeof digest;
23
+ export declare class Hasher {
24
+ #private;
25
+ constructor(algorithm: AlgorithmIdentifier);
26
+ update(data: Uint8Array): void;
27
+ digest(): Promise<Uint8Array>;
28
+ }
@@ -0,0 +1 @@
1
+ import{arrayBufferToString as o,stringToUint8Array as a}from"@stryke/convert/neutral";export function createHasher(r){return new Hasher(r)}export async function digest(r,t="SHA-512"){const e=await globalThis.crypto.subtle.digest(t,a(r));return o(e)}export const hash=digest;export class Hasher{#t=[];#r;constructor(t){this.#r=t}update(t){this.#t.push(t)}async digest(){const t=new Uint8Array(this.#t.reduce((i,s)=>i+s.length,0));let e=0;for(const i of this.#t)t.set(i,e),e+=i.length;const n=await globalThis.crypto.subtle.digest(this.#r,t);return new Uint8Array(n)}}
package/dist/etag.cjs ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateETag = exports.fnv1a52 = void 0;
7
+ const fnv1a52 = t => {
8
+ const i = t.length;
9
+ let o = 0,
10
+ x = 0,
11
+ e = 8997,
12
+ l = 0,
13
+ r = 33826,
14
+ n = 0,
15
+ c = 40164,
16
+ s = 0,
17
+ g = 52210;
18
+ for (; o < i;) e ^= t.charCodeAt(o++), x = e * 435, l = r * 435, n = c * 435, s = g * 435, n += e << 8, s += r << 8, l += x >>> 16, e = x & 65535, n += l >>> 16, r = l & 65535, g = s + (n >>> 16) & 65535, c = n & 65535;
19
+ return (g & 15) * 281474976710656 + c * 4294967296 + r * 65536 + (e ^ g >> 4);
20
+ },
21
+ generateETag = (t, i = !1) => `${(i ? 'W/"' : '"') + fnv1a52(t).toString(36) + t.length.toString(36)}"`;
22
+ exports.generateETag = generateETag;
23
+ exports.fnv1a52 = fnv1a52;
package/dist/etag.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * FNV-1a Hash implementation
3
+ *
4
+ * Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js
5
+ *
6
+ * @remarks
7
+ * Simplified, optimized and add modified for 52 bit, which provides a larger hash space
8
+ * and still making use of Javascript's 53-bit integer space.
9
+ */
10
+ export declare const fnv1a52: (str: string) => number;
11
+ /**
12
+ * Generates an ETag for the given payload.
13
+ *
14
+ * @param payload - The payload to generate an ETag for.
15
+ * @param weak - Whether to generate a weak ETag.
16
+ * @returns The generated ETag.
17
+ */
18
+ export declare const generateETag: (payload: string, weak?: boolean) => string;
package/dist/etag.mjs ADDED
@@ -0,0 +1 @@
1
+ export const fnv1a52=t=>{const i=t.length;let o=0,x=0,e=8997,l=0,r=33826,n=0,c=40164,s=0,g=52210;for(;o<i;)e^=t.charCodeAt(o++),x=e*435,l=r*435,n=c*435,s=g*435,n+=e<<8,s+=r<<8,l+=x>>>16,e=x&65535,n+=l>>>16,r=l&65535,g=s+(n>>>16)&65535,c=n&65535;return(g&15)*281474976710656+c*4294967296+r*65536+(e^g>>4)},generateETag=(t,i=!1)=>`${(i?'W/"':'"')+fnv1a52(t).toString(36)+t.length.toString(36)}"`;
@@ -7,13 +7,13 @@ exports.hashDirectory = hashDirectory;
7
7
  exports.hashFiles = hashFiles;
8
8
  var _listFiles = require("@stryke/fs/list-files");
9
9
  var _readFile = require("@stryke/fs/read-file");
10
- var _hash = require("./hash.cjs");
11
- async function hashFiles(t, s) {
12
- const r = {};
13
- return await Promise.all(t.map(async i => {
14
- r[i] = await (0, _readFile.readFile)(i);
15
- })), (0, _hash.hash)(r, s);
10
+ var _murmurhash = require("./murmurhash.cjs");
11
+ async function hashFiles(s, r) {
12
+ const t = {};
13
+ return await Promise.all(s.map(async i => {
14
+ t[i] = await (0, _readFile.readFile)(i);
15
+ })), (0, _murmurhash.murmurhash)(t, r);
16
16
  }
17
- async function hashDirectory(t, s = {}) {
18
- return s.ignore = s.ignore ?? ["**/node_modules/**", "**/.git/**", "**/.nx/**", "**/.cache/**", "**/.storm/**", "**/tmp/**"], hashFiles(await (0, _listFiles.listFiles)(t, s), s);
17
+ async function hashDirectory(s, r = {}) {
18
+ return r.ignore = r.ignore ?? ["**/node_modules/**", "**/.git/**", "**/.nx/**", "**/.cache/**", "**/.storm/**", "**/tmp/**"], hashFiles(await (0, _listFiles.listFiles)(s, r), r);
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import type { ListOptions } from "@stryke/fs/list-files";
2
- import type { HashOptions } from "./hash";
2
+ import type { HashOptions } from "./murmurhash";
3
3
  /**
4
4
  * Hash a list of file paths into a string based on the file content
5
5
  *
@@ -1 +1 @@
1
- import{listFiles as o}from"@stryke/fs/list-files";import{readFile as e}from"@stryke/fs/read-file";import{hash as n}from"./hash";export async function hashFiles(t,s){const r={};return await Promise.all(t.map(async i=>{r[i]=await e(i)})),n(r,s)}export async function hashDirectory(t,s={}){return s.ignore=s.ignore??["**/node_modules/**","**/.git/**","**/.nx/**","**/.cache/**","**/.storm/**","**/tmp/**"],hashFiles(await o(t,s),s)}
1
+ import{listFiles as o}from"@stryke/fs/list-files";import{readFile as e}from"@stryke/fs/read-file";import{murmurhash as n}from"./murmurhash";export async function hashFiles(s,r){const t={};return await Promise.all(s.map(async i=>{t[i]=await e(i)})),n(t,r)}export async function hashDirectory(s,r={}){return r.ignore=r.ignore??["**/node_modules/**","**/.git/**","**/.nx/**","**/.cache/**","**/.storm/**","**/tmp/**"],hashFiles(await o(s,r),r)}
package/dist/index.cjs CHANGED
@@ -3,14 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _hash = require("./hash.cjs");
7
- Object.keys(_hash).forEach(function (key) {
6
+ var _digest = require("./digest.cjs");
7
+ Object.keys(_digest).forEach(function (key) {
8
8
  if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _hash[key]) return;
9
+ if (key in exports && exports[key] === _digest[key]) return;
10
10
  Object.defineProperty(exports, key, {
11
11
  enumerable: true,
12
12
  get: function () {
13
- return _hash[key];
13
+ return _digest[key];
14
+ }
15
+ });
16
+ });
17
+ var _etag = require("./etag.cjs");
18
+ Object.keys(_etag).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _etag[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _etag[key];
14
25
  }
15
26
  });
16
27
  });
@@ -36,14 +47,14 @@ Object.keys(_md).forEach(function (key) {
36
47
  }
37
48
  });
38
49
  });
39
- var _sha = require("./sha-256.cjs");
40
- Object.keys(_sha).forEach(function (key) {
50
+ var _murmurhash = require("./murmurhash.cjs");
51
+ Object.keys(_murmurhash).forEach(function (key) {
41
52
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _sha[key]) return;
53
+ if (key in exports && exports[key] === _murmurhash[key]) return;
43
54
  Object.defineProperty(exports, key, {
44
55
  enumerable: true,
45
56
  get: function () {
46
- return _sha[key];
57
+ return _murmurhash[key];
47
58
  }
48
59
  });
49
60
  });
package/dist/index.d.ts CHANGED
@@ -6,8 +6,9 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
9
- export * from "./hash";
9
+ export * from "./digest";
10
+ export * from "./etag";
10
11
  export * from "./hash-files";
11
12
  export * from "./md5";
12
- export * from "./sha-256";
13
+ export * from "./murmurhash";
13
14
  export * from "./xx-hash";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./hash";export*from"./hash-files";export*from"./md5";export*from"./sha-256";export*from"./xx-hash";
1
+ export*from"./digest";export*from"./etag";export*from"./hash-files";export*from"./md5";export*from"./murmurhash";export*from"./xx-hash";
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hash = hash;
6
+ exports.murmurhash = murmurhash;
7
7
  var _ohash = require("ohash");
8
- function hash(s, e) {
8
+ function murmurhash(s, e) {
9
9
  const t = (0, _ohash.hash)(s),
10
10
  n = e?.maxLength ?? 32;
11
11
  return t.length > n ? t.slice(0, n) : t;
@@ -0,0 +1,19 @@
1
+ export interface HashOptions {
2
+ /**
3
+ * The maximum length of the hash
4
+ *
5
+ * @defaultValue 32
6
+ */
7
+ maxLength?: number;
8
+ }
9
+ /**
10
+ * Use a [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash) based algorithm to hash any JS value into a string.
11
+ *
12
+ * @see https://github.com/ohash/ohash
13
+ * @see https://en.wikipedia.org/wiki/MurmurHash
14
+ *
15
+ * @param content - The value to hash
16
+ * @param options - Hashing options
17
+ * @returns A hashed string value
18
+ */
19
+ export declare function murmurhash(content: any, options?: HashOptions): string;
@@ -0,0 +1 @@
1
+ import{hash as h}from"ohash";export function murmurhash(s,e){const t=h(s),n=e?.maxLength??32;return t.length>n?t.slice(0,n):t}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _digest = require("./digest.cjs");
7
+ Object.keys(_digest).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _digest[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _digest[key];
14
+ }
15
+ });
16
+ });
17
+ var _hashFiles = require("./hash-files.cjs");
18
+ Object.keys(_hashFiles).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _hashFiles[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _hashFiles[key];
25
+ }
26
+ });
27
+ });
28
+ var _murmurhash = require("./murmurhash.cjs");
29
+ Object.keys(_murmurhash).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _murmurhash[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _murmurhash[key];
36
+ }
37
+ });
38
+ });
39
+ var _xxHash = require("./xx-hash.cjs");
40
+ Object.keys(_xxHash).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _xxHash[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _xxHash[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,4 @@
1
+ export * from "./digest";
2
+ export * from "./hash-files";
3
+ export * from "./murmurhash";
4
+ export * from "./xx-hash";
@@ -0,0 +1 @@
1
+ export*from"./digest";export*from"./hash-files";export*from"./murmurhash";export*from"./xx-hash";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hash",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions that hash data using various algorithms.",
6
6
  "repository": {
@@ -12,7 +12,8 @@
12
12
  "dependencies": {
13
13
  "js-xxhash": "^4.0.0",
14
14
  "ohash": "^2.0.11",
15
- "@stryke/fs": "^0.22.6"
15
+ "@stryke/convert": "^0.5.0",
16
+ "@stryke/fs": "^0.28.3"
16
17
  },
17
18
  "publishConfig": { "access": "public" },
18
19
  "devDependencies": {},
@@ -73,18 +74,32 @@
73
74
  "default": "./dist/xx-hash.mjs"
74
75
  }
75
76
  },
76
- "./sha-256": {
77
+ "./neutral": {
77
78
  "import": {
78
- "types": "./dist/sha-256.d.ts",
79
- "default": "./dist/sha-256.mjs"
79
+ "types": "./dist/neutral.d.ts",
80
+ "default": "./dist/neutral.mjs"
80
81
  },
81
82
  "require": {
82
- "types": "./dist/sha-256.d.ts",
83
- "default": "./dist/sha-256.cjs"
83
+ "types": "./dist/neutral.d.ts",
84
+ "default": "./dist/neutral.cjs"
84
85
  },
85
86
  "default": {
86
- "types": "./dist/sha-256.d.ts",
87
- "default": "./dist/sha-256.mjs"
87
+ "types": "./dist/neutral.d.ts",
88
+ "default": "./dist/neutral.mjs"
89
+ }
90
+ },
91
+ "./murmurhash": {
92
+ "import": {
93
+ "types": "./dist/murmurhash.d.ts",
94
+ "default": "./dist/murmurhash.mjs"
95
+ },
96
+ "require": {
97
+ "types": "./dist/murmurhash.d.ts",
98
+ "default": "./dist/murmurhash.cjs"
99
+ },
100
+ "default": {
101
+ "types": "./dist/murmurhash.d.ts",
102
+ "default": "./dist/murmurhash.mjs"
88
103
  }
89
104
  },
90
105
  "./md5": {
@@ -100,37 +115,37 @@
100
115
  },
101
116
  "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
102
117
  },
103
- "./hasher": {
118
+ "./hash-files": {
104
119
  "import": {
105
- "types": "./dist/hasher.d.ts",
106
- "default": "./dist/hasher.mjs"
120
+ "types": "./dist/hash-files.d.ts",
121
+ "default": "./dist/hash-files.mjs"
107
122
  },
108
123
  "require": {
109
- "types": "./dist/hasher.d.ts",
110
- "default": "./dist/hasher.cjs"
124
+ "types": "./dist/hash-files.d.ts",
125
+ "default": "./dist/hash-files.cjs"
111
126
  },
112
127
  "default": {
113
- "types": "./dist/hasher.d.ts",
114
- "default": "./dist/hasher.mjs"
128
+ "types": "./dist/hash-files.d.ts",
129
+ "default": "./dist/hash-files.mjs"
115
130
  }
116
131
  },
117
- "./hash": {
118
- "import": { "types": "./dist/hash.d.ts", "default": "./dist/hash.mjs" },
119
- "require": { "types": "./dist/hash.d.ts", "default": "./dist/hash.cjs" },
120
- "default": { "types": "./dist/hash.d.ts", "default": "./dist/hash.mjs" }
132
+ "./etag": {
133
+ "import": { "types": "./dist/etag.d.ts", "default": "./dist/etag.mjs" },
134
+ "require": { "types": "./dist/etag.d.ts", "default": "./dist/etag.cjs" },
135
+ "default": { "types": "./dist/etag.d.ts", "default": "./dist/etag.mjs" }
121
136
  },
122
- "./hash-files": {
137
+ "./digest": {
123
138
  "import": {
124
- "types": "./dist/hash-files.d.ts",
125
- "default": "./dist/hash-files.mjs"
139
+ "types": "./dist/digest.d.ts",
140
+ "default": "./dist/digest.mjs"
126
141
  },
127
142
  "require": {
128
- "types": "./dist/hash-files.d.ts",
129
- "default": "./dist/hash-files.cjs"
143
+ "types": "./dist/digest.d.ts",
144
+ "default": "./dist/digest.cjs"
130
145
  },
131
146
  "default": {
132
- "types": "./dist/hash-files.d.ts",
133
- "default": "./dist/hash-files.mjs"
147
+ "types": "./dist/digest.d.ts",
148
+ "default": "./dist/digest.mjs"
134
149
  }
135
150
  },
136
151
  ".": {
@@ -146,5 +161,5 @@
146
161
  "main": "./dist/index.cjs",
147
162
  "module": "./dist/index.mjs",
148
163
  "types": "./dist/index.d.ts",
149
- "gitHead": "ea7a3a1d68d4a4361cc04d6f5bf6219a5bc4a2a2"
164
+ "gitHead": "73e8ba817597f78f119c7924d64e609e72f158c4"
150
165
  }
package/dist/hash.d.ts DELETED
@@ -1,16 +0,0 @@
1
- export interface HashOptions {
2
- /**
3
- * The maximum length of the hash
4
- *
5
- * @defaultValue 32
6
- */
7
- maxLength?: number;
8
- }
9
- /**
10
- * Hash any JS value into a string
11
- *
12
- * @param content - The value to hash
13
- * @param options - Hashing options
14
- * @returns A hashed string value
15
- */
16
- export declare function hash(content: any, options?: HashOptions): string;
package/dist/hash.mjs DELETED
@@ -1 +0,0 @@
1
- import{hash as h}from"ohash";export function hash(s,e){const t=h(s),n=e?.maxLength??32;return t.length>n?t.slice(0,n):t}
package/dist/hasher.cjs DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.WordArray = exports.Utf8 = exports.Latin1 = exports.Hex = exports.Hasher = exports.BufferedBlockAlgorithm = exports.Base64 = void 0;
7
- class WordArray {
8
- words;
9
- sigBytes;
10
- constructor(t, s) {
11
- this.words = t ?? [], t = this.words, this.sigBytes = s ?? t.length * 4;
12
- }
13
- toString(t) {
14
- return (t ?? Hex).stringify(this);
15
- }
16
- concat(t) {
17
- if (this.clamp(), this.sigBytes % 4) for (let s = 0; s < t.sigBytes; s++) {
18
- const e = t.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
19
- this.words[this.sigBytes + s >>> 2] |= e << 24 - (this.sigBytes + s) % 4 * 8;
20
- } else for (let s = 0; s < t.sigBytes; s += 4) this.words[this.sigBytes + s >>> 2] = t.words[s >>> 2];
21
- return this.sigBytes += t.sigBytes, this;
22
- }
23
- clamp() {
24
- this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8, this.words.length = Math.ceil(this.sigBytes / 4);
25
- }
26
- clone() {
27
- return new WordArray([...this.words]);
28
- }
29
- }
30
- exports.WordArray = WordArray;
31
- const Hex = exports.Hex = {
32
- stringify(i) {
33
- const t = [];
34
- for (let s = 0; s < i.sigBytes; s++) {
35
- const e = i.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
36
- t.push((e >>> 4).toString(16), (e & 15).toString(16));
37
- }
38
- return t.join("");
39
- }
40
- },
41
- Base64 = exports.Base64 = {
42
- stringify(i) {
43
- const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
44
- s = [];
45
- for (let e = 0; e < i.sigBytes; e += 3) {
46
- const n = i.words[e >>> 2] >>> 24 - e % 4 * 8 & 255,
47
- r = i.words[e + 1 >>> 2] >>> 24 - (e + 1) % 4 * 8 & 255,
48
- o = i.words[e + 2 >>> 2] >>> 24 - (e + 2) % 4 * 8 & 255,
49
- c = n << 16 | r << 8 | o;
50
- for (let h = 0; h < 4 && e * 8 + h * 6 < i.sigBytes * 8; h++) s.push(t.charAt(c >>> 6 * (3 - h) & 63));
51
- }
52
- return s.join("");
53
- }
54
- },
55
- Latin1 = exports.Latin1 = {
56
- parse(i) {
57
- const t = i.length,
58
- s = [];
59
- for (let e = 0; e < t; e++) s[e >>> 2] |= (i.codePointAt(e) & 255) << 24 - e % 4 * 8;
60
- return new WordArray(s, t);
61
- }
62
- },
63
- Utf8 = exports.Utf8 = {
64
- parse(i) {
65
- return Latin1.parse(unescape(encodeURIComponent(i)));
66
- }
67
- };
68
- class BufferedBlockAlgorithm {
69
- _data = new WordArray();
70
- _nDataBytes = 0;
71
- _minBufferSize = 0;
72
- blockSize = 512 / 32;
73
- reset() {
74
- this._data = new WordArray(), this._nDataBytes = 0;
75
- }
76
- _append(t) {
77
- typeof t == "string" && (t = Utf8.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes;
78
- }
79
- _doProcessBlock(t, s) {}
80
- _process(t) {
81
- let s;
82
- const n = (t ? Math.ceil(this._data.sigBytes / (this.blockSize * 4)) : Math.max(Math.trunc(this._data.sigBytes / (this.blockSize * 4)) - this._minBufferSize, 0)) * this.blockSize,
83
- r = Math.min(n * 4, this._data.sigBytes);
84
- if (n) {
85
- for (let o = 0; o < n; o += this.blockSize) this._doProcessBlock(this._data.words, o);
86
- s = this._data.words.splice(0, n), this._data.sigBytes -= r;
87
- }
88
- return new WordArray(s, r);
89
- }
90
- }
91
- exports.BufferedBlockAlgorithm = BufferedBlockAlgorithm;
92
- class Hasher extends BufferedBlockAlgorithm {
93
- update(t) {
94
- return this._append(t), this._process(), this;
95
- }
96
- finalize(t) {
97
- t && this._append(t);
98
- }
99
- }
100
- exports.Hasher = Hasher;
package/dist/hasher.d.ts DELETED
@@ -1,35 +0,0 @@
1
- export declare class WordArray {
2
- words: number[];
3
- sigBytes: number;
4
- constructor(words?: number[], sigBytes?: number);
5
- toString(encoder?: typeof Hex): string;
6
- concat(wordArray: WordArray): this;
7
- clamp(): void;
8
- clone(): WordArray;
9
- }
10
- export declare const Hex: {
11
- stringify(wordArray: WordArray): string;
12
- };
13
- export declare const Base64: {
14
- stringify(wordArray: WordArray): string;
15
- };
16
- export declare const Latin1: {
17
- parse(latin1Str: string): WordArray;
18
- };
19
- export declare const Utf8: {
20
- parse(utf8Str: string): WordArray;
21
- };
22
- export declare class BufferedBlockAlgorithm {
23
- _data: WordArray;
24
- _nDataBytes: number;
25
- _minBufferSize: number;
26
- blockSize: number;
27
- reset(): void;
28
- _append(data: string | WordArray): void;
29
- _doProcessBlock(_dataWords: any, _offset: any): void;
30
- _process(doFlush?: boolean): WordArray;
31
- }
32
- export declare class Hasher extends BufferedBlockAlgorithm {
33
- update(messageUpdate: string): this;
34
- finalize(messageUpdate: string): void;
35
- }
package/dist/hasher.mjs DELETED
@@ -1 +0,0 @@
1
- export class WordArray{words;sigBytes;constructor(t,s){this.words=t??[],t=this.words,this.sigBytes=s??t.length*4}toString(t){return(t??Hex).stringify(this)}concat(t){if(this.clamp(),this.sigBytes%4)for(let s=0;s<t.sigBytes;s++){const e=t.words[s>>>2]>>>24-s%4*8&255;this.words[this.sigBytes+s>>>2]|=e<<24-(this.sigBytes+s)%4*8}else for(let s=0;s<t.sigBytes;s+=4)this.words[this.sigBytes+s>>>2]=t.words[s>>>2];return this.sigBytes+=t.sigBytes,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])}}export const Hex={stringify(i){const t=[];for(let s=0;s<i.sigBytes;s++){const e=i.words[s>>>2]>>>24-s%4*8&255;t.push((e>>>4).toString(16),(e&15).toString(16))}return t.join("")}},Base64={stringify(i){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",s=[];for(let e=0;e<i.sigBytes;e+=3){const n=i.words[e>>>2]>>>24-e%4*8&255,r=i.words[e+1>>>2]>>>24-(e+1)%4*8&255,o=i.words[e+2>>>2]>>>24-(e+2)%4*8&255,c=n<<16|r<<8|o;for(let h=0;h<4&&e*8+h*6<i.sigBytes*8;h++)s.push(t.charAt(c>>>6*(3-h)&63))}return s.join("")}},Latin1={parse(i){const t=i.length,s=[];for(let e=0;e<t;e++)s[e>>>2]|=(i.codePointAt(e)&255)<<24-e%4*8;return new WordArray(s,t)}},Utf8={parse(i){return Latin1.parse(unescape(encodeURIComponent(i)))}};export class BufferedBlockAlgorithm{_data=new WordArray;_nDataBytes=0;_minBufferSize=0;blockSize=512/32;reset(){this._data=new WordArray,this._nDataBytes=0}_append(t){typeof t=="string"&&(t=Utf8.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes}_doProcessBlock(t,s){}_process(t){let s;const n=(t?Math.ceil(this._data.sigBytes/(this.blockSize*4)):Math.max(Math.trunc(this._data.sigBytes/(this.blockSize*4))-this._minBufferSize,0))*this.blockSize,r=Math.min(n*4,this._data.sigBytes);if(n){for(let o=0;o<n;o+=this.blockSize)this._doProcessBlock(this._data.words,o);s=this._data.words.splice(0,n),this._data.sigBytes-=r}return new WordArray(s,r)}}export class Hasher extends BufferedBlockAlgorithm{update(t){return this._append(t),this._process(),this}finalize(t){t&&this._append(t)}}
package/dist/sha-256.cjs DELETED
@@ -1,154 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.WordArray = exports.Utf8 = exports.SHA256 = exports.Latin1 = exports.Hex = exports.Hasher = exports.BufferedBlockAlgorithm = exports.Base64 = void 0;
7
- exports.sha256 = sha256;
8
- exports.sha256base64 = sha256base64;
9
- class WordArray {
10
- words;
11
- sigBytes;
12
- constructor(_, s) {
13
- _ = this.words = _ || [], this.sigBytes = s === void 0 ? _.length * 4 : s;
14
- }
15
- toString(_) {
16
- return (_ || Hex).stringify(this);
17
- }
18
- concat(_) {
19
- if (this.clamp(), this.sigBytes % 4) for (let s = 0; s < _.sigBytes; s++) {
20
- const t = _.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
21
- this.words[this.sigBytes + s >>> 2] |= t << 24 - (this.sigBytes + s) % 4 * 8;
22
- } else for (let s = 0; s < _.sigBytes; s += 4) this.words[this.sigBytes + s >>> 2] = _.words[s >>> 2];
23
- return this.sigBytes += _.sigBytes, this;
24
- }
25
- clamp() {
26
- this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8, this.words.length = Math.ceil(this.sigBytes / 4);
27
- }
28
- clone() {
29
- return new WordArray([...this.words]);
30
- }
31
- }
32
- exports.WordArray = WordArray;
33
- const Hex = exports.Hex = {
34
- stringify(e) {
35
- const _ = [];
36
- for (let s = 0; s < e.sigBytes; s++) {
37
- const t = e.words[s >>> 2] >>> 24 - s % 4 * 8 & 255;
38
- _.push((t >>> 4).toString(16), (t & 15).toString(16));
39
- }
40
- return _.join("");
41
- }
42
- },
43
- Base64 = exports.Base64 = {
44
- stringify(e) {
45
- const _ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
46
- s = [];
47
- for (let t = 0; t < e.sigBytes; t += 3) {
48
- const i = e.words[t >>> 2] >>> 24 - t % 4 * 8 & 255,
49
- a = e.words[t + 1 >>> 2] >>> 24 - (t + 1) % 4 * 8 & 255,
50
- r = e.words[t + 2 >>> 2] >>> 24 - (t + 2) % 4 * 8 & 255,
51
- c = i << 16 | a << 8 | r;
52
- for (let n = 0; n < 4 && t * 8 + n * 6 < e.sigBytes * 8; n++) s.push(_.charAt(c >>> 6 * (3 - n) & 63));
53
- }
54
- return s.join("");
55
- }
56
- },
57
- Latin1 = exports.Latin1 = {
58
- parse(e) {
59
- const _ = e.length,
60
- s = [];
61
- for (let t = 0; t < _; t++) s[t >>> 2] |= (e.charCodeAt(t) & 255) << 24 - t % 4 * 8;
62
- return new WordArray(s, _);
63
- }
64
- },
65
- Utf8 = exports.Utf8 = {
66
- parse(e) {
67
- return Latin1.parse(unescape(encodeURIComponent(e)));
68
- }
69
- };
70
- class BufferedBlockAlgorithm {
71
- _data = new WordArray();
72
- _nDataBytes = 0;
73
- _minBufferSize = 0;
74
- blockSize = 512 / 32;
75
- reset() {
76
- this._data = new WordArray(), this._nDataBytes = 0;
77
- }
78
- _append(_) {
79
- typeof _ == "string" && (_ = Utf8.parse(_)), this._data.concat(_), this._nDataBytes += _.sigBytes;
80
- }
81
- _doProcessBlock(_, s) {}
82
- _process(_) {
83
- let s,
84
- t = this._data.sigBytes / (this.blockSize * 4);
85
- _ ? t = Math.ceil(t) : t = Math.max((t | 0) - this._minBufferSize, 0);
86
- const i = t * this.blockSize,
87
- a = Math.min(i * 4, this._data.sigBytes);
88
- if (i) {
89
- for (let r = 0; r < i; r += this.blockSize) this._doProcessBlock(this._data.words, r);
90
- s = this._data.words.splice(0, i), this._data.sigBytes -= a;
91
- }
92
- return new WordArray(s, a);
93
- }
94
- }
95
- exports.BufferedBlockAlgorithm = BufferedBlockAlgorithm;
96
- class Hasher extends BufferedBlockAlgorithm {
97
- update(_) {
98
- return this._append(_), this._process(), this;
99
- }
100
- finalize(_) {
101
- _ && this._append(_);
102
- }
103
- }
104
- exports.Hasher = Hasher;
105
- const p = [1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225],
106
- 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],
107
- h = [];
108
- class SHA256 extends Hasher {
109
- _hash = new WordArray([...p]);
110
- reset() {
111
- super.reset(), this._hash = new WordArray([...p]);
112
- }
113
- _doProcessBlock(_, s) {
114
- const t = this._hash.words;
115
- let i = t[0],
116
- a = t[1],
117
- r = t[2],
118
- c = t[3],
119
- n = t[4],
120
- g = t[5],
121
- d = t[6],
122
- B = t[7];
123
- for (let o = 0; o < 64; o++) {
124
- if (o < 16) h[o] = _[s + o] | 0;else {
125
- const f = h[o - 15],
126
- S = (f << 25 | f >>> 7) ^ (f << 14 | f >>> 18) ^ f >>> 3,
127
- l = h[o - 2],
128
- z = (l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10;
129
- h[o] = S + h[o - 7] + z + h[o - 16];
130
- }
131
- const u = n & g ^ ~n & d,
132
- x = i & a ^ i & r ^ a & r,
133
- m = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22),
134
- b = (n << 26 | n >>> 6) ^ (n << 21 | n >>> 11) ^ (n << 7 | n >>> 25),
135
- y = B + b + u + k[o] + h[o],
136
- w = m + x;
137
- B = d, d = g, g = n, n = c + y | 0, c = r, r = a, a = i, i = y + w | 0;
138
- }
139
- t[0] = t[0] + i | 0, t[1] = t[1] + a | 0, t[2] = t[2] + r | 0, t[3] = t[3] + c | 0, t[4] = t[4] + n | 0, t[5] = t[5] + g | 0, t[6] = t[6] + d | 0, t[7] = t[7] + B | 0;
140
- }
141
- finalize(_) {
142
- super.finalize(_);
143
- const s = this._nDataBytes * 8,
144
- t = this._data.sigBytes * 8;
145
- 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;
146
- }
147
- }
148
- exports.SHA256 = SHA256;
149
- function sha256(e) {
150
- return new SHA256().finalize(e).toString();
151
- }
152
- function sha256base64(e) {
153
- return new SHA256().finalize(e).toString(Base64);
154
- }
package/dist/sha-256.d.ts DELETED
@@ -1,67 +0,0 @@
1
- export declare class WordArray {
2
- words: number[];
3
- sigBytes: number;
4
- constructor(words?: number[], sigBytes?: number);
5
- toString(encoder?: typeof Hex): string;
6
- concat(wordArray: WordArray): this;
7
- clamp(): void;
8
- clone(): WordArray;
9
- }
10
- export declare const Hex: {
11
- stringify(wordArray: WordArray): string;
12
- };
13
- export declare const Base64: {
14
- stringify(wordArray: WordArray): string;
15
- };
16
- export declare const Latin1: {
17
- parse(latin1Str: string): WordArray;
18
- };
19
- export declare const Utf8: {
20
- parse(utf8Str: string): WordArray;
21
- };
22
- export declare class BufferedBlockAlgorithm {
23
- _data: WordArray;
24
- _nDataBytes: number;
25
- _minBufferSize: number;
26
- blockSize: number;
27
- reset(): void;
28
- _append(data: string | WordArray): void;
29
- _doProcessBlock(_dataWords: any, _offset: any): void;
30
- _process(doFlush?: boolean): WordArray;
31
- }
32
- export declare class Hasher extends BufferedBlockAlgorithm {
33
- update(messageUpdate: string): this;
34
- finalize(messageUpdate: string): void;
35
- }
36
- /**
37
- * SHA-256 hash algorithm.
38
- */
39
- export declare class SHA256 extends Hasher {
40
- _hash: WordArray;
41
- /**
42
- * Resets the internal state of the hash object to initial values.
43
- */
44
- reset(): void;
45
- _doProcessBlock(M: number[], offset: number): void;
46
- /**
47
- * Finishes the hash calculation and returns the hash as a WordArray.
48
- *
49
- * @param {string} messageUpdate - Additional message content to include in the hash.
50
- * @returns {WordArray} The finalised hash as a WordArray.
51
- */
52
- finalize(messageUpdate: string): WordArray;
53
- }
54
- /**
55
- * Calculates the SHA-256 hash of the message provided.
56
- *
57
- * @param {string} message - The message to hash.
58
- * @returns {string} The message hash as a hexadecimal string.
59
- */
60
- export declare function sha256(message: string): string;
61
- /**
62
- * Calculates the SHA-256 hash of the given message and encodes it in Base64.
63
- *
64
- * @param {string} message - The message to hash.
65
- * @returns {string} The base64 encoded hash of the message.
66
- */
67
- export declare function sha256base64(message: string): string;
package/dist/sha-256.mjs DELETED
@@ -1 +0,0 @@
1
- export class WordArray{words;sigBytes;constructor(_,s){_=this.words=_||[],this.sigBytes=s===void 0?_.length*4:s}toString(_){return(_||Hex).stringify(this)}concat(_){if(this.clamp(),this.sigBytes%4)for(let s=0;s<_.sigBytes;s++){const t=_.words[s>>>2]>>>24-s%4*8&255;this.words[this.sigBytes+s>>>2]|=t<<24-(this.sigBytes+s)%4*8}else for(let s=0;s<_.sigBytes;s+=4)this.words[this.sigBytes+s>>>2]=_.words[s>>>2];return this.sigBytes+=_.sigBytes,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])}}export const Hex={stringify(e){const _=[];for(let s=0;s<e.sigBytes;s++){const t=e.words[s>>>2]>>>24-s%4*8&255;_.push((t>>>4).toString(16),(t&15).toString(16))}return _.join("")}},Base64={stringify(e){const _="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",s=[];for(let t=0;t<e.sigBytes;t+=3){const i=e.words[t>>>2]>>>24-t%4*8&255,a=e.words[t+1>>>2]>>>24-(t+1)%4*8&255,r=e.words[t+2>>>2]>>>24-(t+2)%4*8&255,c=i<<16|a<<8|r;for(let n=0;n<4&&t*8+n*6<e.sigBytes*8;n++)s.push(_.charAt(c>>>6*(3-n)&63))}return s.join("")}},Latin1={parse(e){const _=e.length,s=[];for(let t=0;t<_;t++)s[t>>>2]|=(e.charCodeAt(t)&255)<<24-t%4*8;return new WordArray(s,_)}},Utf8={parse(e){return Latin1.parse(unescape(encodeURIComponent(e)))}};export class BufferedBlockAlgorithm{_data=new WordArray;_nDataBytes=0;_minBufferSize=0;blockSize=512/32;reset(){this._data=new WordArray,this._nDataBytes=0}_append(_){typeof _=="string"&&(_=Utf8.parse(_)),this._data.concat(_),this._nDataBytes+=_.sigBytes}_doProcessBlock(_,s){}_process(_){let s,t=this._data.sigBytes/(this.blockSize*4);_?t=Math.ceil(t):t=Math.max((t|0)-this._minBufferSize,0);const i=t*this.blockSize,a=Math.min(i*4,this._data.sigBytes);if(i){for(let r=0;r<i;r+=this.blockSize)this._doProcessBlock(this._data.words,r);s=this._data.words.splice(0,i),this._data.sigBytes-=a}return new WordArray(s,a)}}export class Hasher extends BufferedBlockAlgorithm{update(_){return this._append(_),this._process(),this}finalize(_){_&&this._append(_)}}const p=[1779033703,-1150833019,1013904242,-1521486534,1359893119,-1694144372,528734635,1541459225],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],h=[];export class SHA256 extends Hasher{_hash=new WordArray([...p]);reset(){super.reset(),this._hash=new WordArray([...p])}_doProcessBlock(_,s){const t=this._hash.words;let i=t[0],a=t[1],r=t[2],c=t[3],n=t[4],g=t[5],d=t[6],B=t[7];for(let o=0;o<64;o++){if(o<16)h[o]=_[s+o]|0;else{const f=h[o-15],S=(f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3,l=h[o-2],z=(l<<15|l>>>17)^(l<<13|l>>>19)^l>>>10;h[o]=S+h[o-7]+z+h[o-16]}const u=n&g^~n&d,x=i&a^i&r^a&r,m=(i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22),b=(n<<26|n>>>6)^(n<<21|n>>>11)^(n<<7|n>>>25),y=B+b+u+k[o]+h[o],w=m+x;B=d,d=g,g=n,n=c+y|0,c=r,r=a,a=i,i=y+w|0}t[0]=t[0]+i|0,t[1]=t[1]+a|0,t[2]=t[2]+r|0,t[3]=t[3]+c|0,t[4]=t[4]+n|0,t[5]=t[5]+g|0,t[6]=t[6]+d|0,t[7]=t[7]+B|0}finalize(_){super.finalize(_);const s=this._nDataBytes*8,t=this._data.sigBytes*8;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}}export function sha256(e){return new SHA256().finalize(e).toString()}export function sha256base64(e){return new SHA256().finalize(e).toString(Base64)}