@stryke/hash 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/digest.cjs +36 -0
- package/dist/digest.d.ts +28 -0
- package/dist/digest.mjs +1 -0
- package/dist/hash-files.cjs +8 -8
- package/dist/hash-files.d.ts +1 -1
- package/dist/hash-files.mjs +1 -1
- package/dist/index.cjs +12 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{hash.cjs → murmurhash.cjs} +2 -2
- package/dist/murmurhash.d.ts +19 -0
- package/dist/murmurhash.mjs +1 -0
- package/dist/neutral.cjs +49 -0
- package/dist/neutral.d.ts +4 -0
- package/dist/neutral.mjs +1 -0
- package/package.json +39 -29
- package/dist/hash.d.ts +0 -16
- package/dist/hash.mjs +0 -1
- package/dist/hasher.cjs +0 -100
- package/dist/hasher.d.ts +0 -35
- package/dist/hasher.mjs +0 -1
- package/dist/sha-256.cjs +0 -154
- package/dist/sha-256.d.ts +0 -67
- package/dist/sha-256.mjs +0 -1
package/dist/digest.cjs
ADDED
|
@@ -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;
|
package/dist/digest.d.ts
ADDED
|
@@ -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
|
+
}
|
package/dist/digest.mjs
ADDED
|
@@ -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/hash-files.cjs
CHANGED
|
@@ -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
|
|
11
|
-
async function hashFiles(
|
|
12
|
-
const
|
|
13
|
-
return await Promise.all(
|
|
14
|
-
|
|
15
|
-
})), (0,
|
|
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(
|
|
18
|
-
return
|
|
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
|
}
|
package/dist/hash-files.d.ts
CHANGED
package/dist/hash-files.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{listFiles as o}from"@stryke/fs/list-files";import{readFile as e}from"@stryke/fs/read-file";import{
|
|
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,25 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
Object.keys(
|
|
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] ===
|
|
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
|
|
13
|
+
return _digest[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
var
|
|
18
|
-
Object.keys(
|
|
17
|
+
var _etag = require("./etag.cjs");
|
|
18
|
+
Object.keys(_etag).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] ===
|
|
20
|
+
if (key in exports && exports[key] === _etag[key]) return;
|
|
21
21
|
Object.defineProperty(exports, key, {
|
|
22
22
|
enumerable: true,
|
|
23
23
|
get: function () {
|
|
24
|
-
return
|
|
24
|
+
return _etag[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
@@ -47,14 +47,14 @@ Object.keys(_md).forEach(function (key) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
-
var
|
|
51
|
-
Object.keys(
|
|
50
|
+
var _murmurhash = require("./murmurhash.cjs");
|
|
51
|
+
Object.keys(_murmurhash).forEach(function (key) {
|
|
52
52
|
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] ===
|
|
53
|
+
if (key in exports && exports[key] === _murmurhash[key]) return;
|
|
54
54
|
Object.defineProperty(exports, key, {
|
|
55
55
|
enumerable: true,
|
|
56
56
|
get: function () {
|
|
57
|
-
return
|
|
57
|
+
return _murmurhash[key];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
|
+
export * from "./digest";
|
|
9
10
|
export * from "./etag";
|
|
10
|
-
export * from "./hash";
|
|
11
11
|
export * from "./hash-files";
|
|
12
12
|
export * from "./md5";
|
|
13
|
-
export * from "./
|
|
13
|
+
export * from "./murmurhash";
|
|
14
14
|
export * from "./xx-hash";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./
|
|
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.
|
|
6
|
+
exports.murmurhash = murmurhash;
|
|
7
7
|
var _ohash = require("ohash");
|
|
8
|
-
function
|
|
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}
|
package/dist/neutral.cjs
ADDED
|
@@ -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
|
+
});
|
package/dist/neutral.mjs
ADDED
|
@@ -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.
|
|
3
|
+
"version": "0.12.1",
|
|
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/
|
|
15
|
+
"@stryke/convert": "^0.6.0",
|
|
16
|
+
"@stryke/fs": "^0.32.10"
|
|
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
|
-
"./
|
|
77
|
+
"./neutral": {
|
|
77
78
|
"import": {
|
|
78
|
-
"types": "./dist/
|
|
79
|
-
"default": "./dist/
|
|
79
|
+
"types": "./dist/neutral.d.ts",
|
|
80
|
+
"default": "./dist/neutral.mjs"
|
|
80
81
|
},
|
|
81
82
|
"require": {
|
|
82
|
-
"types": "./dist/
|
|
83
|
-
"default": "./dist/
|
|
83
|
+
"types": "./dist/neutral.d.ts",
|
|
84
|
+
"default": "./dist/neutral.cjs"
|
|
84
85
|
},
|
|
85
86
|
"default": {
|
|
86
|
-
"types": "./dist/
|
|
87
|
-
"default": "./dist/
|
|
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,25 +115,6 @@
|
|
|
100
115
|
},
|
|
101
116
|
"default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
|
|
102
117
|
},
|
|
103
|
-
"./hasher": {
|
|
104
|
-
"import": {
|
|
105
|
-
"types": "./dist/hasher.d.ts",
|
|
106
|
-
"default": "./dist/hasher.mjs"
|
|
107
|
-
},
|
|
108
|
-
"require": {
|
|
109
|
-
"types": "./dist/hasher.d.ts",
|
|
110
|
-
"default": "./dist/hasher.cjs"
|
|
111
|
-
},
|
|
112
|
-
"default": {
|
|
113
|
-
"types": "./dist/hasher.d.ts",
|
|
114
|
-
"default": "./dist/hasher.mjs"
|
|
115
|
-
}
|
|
116
|
-
},
|
|
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" }
|
|
121
|
-
},
|
|
122
118
|
"./hash-files": {
|
|
123
119
|
"import": {
|
|
124
120
|
"types": "./dist/hash-files.d.ts",
|
|
@@ -138,6 +134,20 @@
|
|
|
138
134
|
"require": { "types": "./dist/etag.d.ts", "default": "./dist/etag.cjs" },
|
|
139
135
|
"default": { "types": "./dist/etag.d.ts", "default": "./dist/etag.mjs" }
|
|
140
136
|
},
|
|
137
|
+
"./digest": {
|
|
138
|
+
"import": {
|
|
139
|
+
"types": "./dist/digest.d.ts",
|
|
140
|
+
"default": "./dist/digest.mjs"
|
|
141
|
+
},
|
|
142
|
+
"require": {
|
|
143
|
+
"types": "./dist/digest.d.ts",
|
|
144
|
+
"default": "./dist/digest.cjs"
|
|
145
|
+
},
|
|
146
|
+
"default": {
|
|
147
|
+
"types": "./dist/digest.d.ts",
|
|
148
|
+
"default": "./dist/digest.mjs"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
141
151
|
".": {
|
|
142
152
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
143
153
|
"require": {
|
|
@@ -151,5 +161,5 @@
|
|
|
151
161
|
"main": "./dist/index.cjs",
|
|
152
162
|
"module": "./dist/index.mjs",
|
|
153
163
|
"types": "./dist/index.d.ts",
|
|
154
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "906d6304c09a8964297fa784f96377535fca6769"
|
|
155
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)}
|