@quentinadam/hash 0.1.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/README.md +12 -0
- package/dist/Buffer.d.ts +2 -0
- package/dist/Buffer.js +1 -0
- package/dist/blake2b128.d.ts +2 -0
- package/dist/blake2b128.js +5 -0
- package/dist/blake2b160.d.ts +2 -0
- package/dist/blake2b160.js +5 -0
- package/dist/blake2b224.d.ts +2 -0
- package/dist/blake2b224.js +5 -0
- package/dist/blake2b256.d.ts +2 -0
- package/dist/blake2b256.js +5 -0
- package/dist/blake2b512.d.ts +2 -0
- package/dist/blake2b512.js +5 -0
- package/dist/concat.d.ts +2 -0
- package/dist/concat.js +6 -0
- package/dist/generateHmac.d.ts +2 -0
- package/dist/generateHmac.js +21 -0
- package/dist/hmac-sha1.d.ts +2 -0
- package/dist/hmac-sha1.js +5 -0
- package/dist/hmac-sha224.d.ts +2 -0
- package/dist/hmac-sha224.js +5 -0
- package/dist/hmac-sha256.d.ts +2 -0
- package/dist/hmac-sha256.js +5 -0
- package/dist/hmac-sha384.d.ts +2 -0
- package/dist/hmac-sha384.js +5 -0
- package/dist/hmac-sha512.d.ts +2 -0
- package/dist/hmac-sha512.js +5 -0
- package/dist/keccak256.d.ts +2 -0
- package/dist/keccak256.js +5 -0
- package/dist/mod.d.ts +18 -0
- package/dist/mod.js +18 -0
- package/dist/ripemd160.d.ts +2 -0
- package/dist/ripemd160.js +5 -0
- package/dist/sha1.d.ts +2 -0
- package/dist/sha1.js +5 -0
- package/dist/sha224.d.ts +2 -0
- package/dist/sha224.js +5 -0
- package/dist/sha256.d.ts +2 -0
- package/dist/sha256.js +5 -0
- package/dist/sha384.d.ts +2 -0
- package/dist/sha384.js +5 -0
- package/dist/sha512.d.ts +2 -0
- package/dist/sha512.js +5 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @quentinadam/hash
|
|
2
|
+
|
|
3
|
+
[![JSR][jsr-image]][jsr-url] [![NPM][npm-image]][npm-url] [![CI][ci-image]][ci-url]
|
|
4
|
+
|
|
5
|
+
A simple hash library that wraps [npm:@noble/hashes](https://www.npmjs.com/package/@noble/hashes).
|
|
6
|
+
|
|
7
|
+
[ci-image]: https://img.shields.io/github/actions/workflow/status/quentinadam/deno-hash/ci.yml?branch=main&logo=github&style=flat-square
|
|
8
|
+
[ci-url]: https://github.com/quentinadam/deno-hash/actions/workflows/ci.yml
|
|
9
|
+
[npm-image]: https://img.shields.io/npm/v/@quentinadam/hash.svg?style=flat-square
|
|
10
|
+
[npm-url]: https://npmjs.org/package/@quentinadam/hash
|
|
11
|
+
[jsr-image]: https://jsr.io/badges/@quentinadam/hash?style=flat-square
|
|
12
|
+
[jsr-url]: https://jsr.io/@quentinadam/hash
|
package/dist/Buffer.d.ts
ADDED
package/dist/Buffer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/concat.d.ts
ADDED
package/dist/concat.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Uint8ArrayExtension from '@quentinadam/uint8array-extension';
|
|
2
|
+
export default function concat(buffers) {
|
|
3
|
+
return Uint8ArrayExtension.concat(buffers.filter((buffer) => buffer !== undefined).map((buffer) => {
|
|
4
|
+
return typeof buffer === 'string' ? new TextEncoder().encode(buffer) : buffer;
|
|
5
|
+
}));
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import require from '@quentinadam/require';
|
|
2
|
+
import Uint8ArrayExtension from '@quentinadam/uint8array-extension';
|
|
3
|
+
import concat from "./concat.js";
|
|
4
|
+
export default function generateHmac(hash, blockSize) {
|
|
5
|
+
return (secret, ...buffers) => {
|
|
6
|
+
if (typeof secret === 'string') {
|
|
7
|
+
secret = new TextEncoder().encode(secret);
|
|
8
|
+
}
|
|
9
|
+
if (secret.length > blockSize) {
|
|
10
|
+
secret = hash(secret);
|
|
11
|
+
}
|
|
12
|
+
secret = new Uint8ArrayExtension(secret).padEnd(blockSize);
|
|
13
|
+
const innerKey = new Uint8Array(blockSize);
|
|
14
|
+
const outerKey = new Uint8Array(blockSize);
|
|
15
|
+
for (let i = 0; i < blockSize; i++) {
|
|
16
|
+
innerKey[i] = 0x36 ^ require(secret[i]);
|
|
17
|
+
outerKey[i] = 0x5c ^ require(secret[i]);
|
|
18
|
+
}
|
|
19
|
+
return hash(Uint8ArrayExtension.concat([outerKey, hash(Uint8ArrayExtension.concat([innerKey, concat(buffers)]))]));
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import blake2b128 from './blake2b128.ts';
|
|
2
|
+
import blake2b160 from './blake2b160.ts';
|
|
3
|
+
import blake2b224 from './blake2b224.ts';
|
|
4
|
+
import blake2b256 from './blake2b256.ts';
|
|
5
|
+
import blake2b512 from './blake2b512.ts';
|
|
6
|
+
import hmacSha1 from './hmac-sha1.ts';
|
|
7
|
+
import hmacSha224 from './hmac-sha224.ts';
|
|
8
|
+
import hmacSha256 from './hmac-sha256.ts';
|
|
9
|
+
import hmacSha384 from './hmac-sha384.ts';
|
|
10
|
+
import hmacSha512 from './hmac-sha512.ts';
|
|
11
|
+
import keccak256 from './keccak256.ts';
|
|
12
|
+
import ripemd160 from './ripemd160.ts';
|
|
13
|
+
import sha1 from './sha1.ts';
|
|
14
|
+
import sha224 from './sha224.ts';
|
|
15
|
+
import sha256 from './sha256.ts';
|
|
16
|
+
import sha384 from './sha384.ts';
|
|
17
|
+
import sha512 from './sha512.ts';
|
|
18
|
+
export { blake2b128, blake2b160, blake2b224, blake2b256, blake2b512, hmacSha1, hmacSha224, hmacSha256, hmacSha384, hmacSha512, keccak256, ripemd160, sha1, sha224, sha256, sha384, sha512, };
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import blake2b128 from "./blake2b128.js";
|
|
2
|
+
import blake2b160 from "./blake2b160.js";
|
|
3
|
+
import blake2b224 from "./blake2b224.js";
|
|
4
|
+
import blake2b256 from "./blake2b256.js";
|
|
5
|
+
import blake2b512 from "./blake2b512.js";
|
|
6
|
+
import hmacSha1 from "./hmac-sha1.js";
|
|
7
|
+
import hmacSha224 from "./hmac-sha224.js";
|
|
8
|
+
import hmacSha256 from "./hmac-sha256.js";
|
|
9
|
+
import hmacSha384 from "./hmac-sha384.js";
|
|
10
|
+
import hmacSha512 from "./hmac-sha512.js";
|
|
11
|
+
import keccak256 from "./keccak256.js";
|
|
12
|
+
import ripemd160 from "./ripemd160.js";
|
|
13
|
+
import sha1 from "./sha1.js";
|
|
14
|
+
import sha224 from "./sha224.js";
|
|
15
|
+
import sha256 from "./sha256.js";
|
|
16
|
+
import sha384 from "./sha384.js";
|
|
17
|
+
import sha512 from "./sha512.js";
|
|
18
|
+
export { blake2b128, blake2b160, blake2b224, blake2b256, blake2b512, hmacSha1, hmacSha224, hmacSha256, hmacSha384, hmacSha512, keccak256, ripemd160, sha1, sha224, sha256, sha384, sha512, };
|
package/dist/sha1.d.ts
ADDED
package/dist/sha1.js
ADDED
package/dist/sha224.d.ts
ADDED
package/dist/sha224.js
ADDED
package/dist/sha256.d.ts
ADDED
package/dist/sha256.js
ADDED
package/dist/sha384.d.ts
ADDED
package/dist/sha384.js
ADDED
package/dist/sha512.d.ts
ADDED
package/dist/sha512.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quentinadam/hash",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A simple hash library that wraps npm:@noble/hashes",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Quentin Adam",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/quentinadam/deno-hash.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/mod.js",
|
|
14
|
+
"./blake2b128": "./dist/blake2b128.js",
|
|
15
|
+
"./blake2b160": "./dist/blake2b160.js",
|
|
16
|
+
"./blake2b224": "./dist/blake2b224.js",
|
|
17
|
+
"./blake2b256": "./dist/blake2b256.js",
|
|
18
|
+
"./blake2b512": "./dist/blake2b512.js",
|
|
19
|
+
"./hmac-sha1": "./dist/hmac-sha1.js",
|
|
20
|
+
"./hmac-sha224": "./dist/hmac-sha224.js",
|
|
21
|
+
"./hmac-sha256": "./dist/hmac-sha256.js",
|
|
22
|
+
"./hmac-sha384": "./dist/hmac-sha384.js",
|
|
23
|
+
"./hmac-sha512": "./dist/hmac-sha512.js",
|
|
24
|
+
"./keccak256": "./dist/keccak256.js",
|
|
25
|
+
"./ripemd160": "./dist/ripemd160.js",
|
|
26
|
+
"./sha1": "./dist/sha1.js",
|
|
27
|
+
"./sha224": "./dist/sha224.js",
|
|
28
|
+
"./sha256": "./dist/sha256.js",
|
|
29
|
+
"./sha384": "./dist/sha384.js",
|
|
30
|
+
"./sha512": "./dist/sha512.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@noble/hashes": "^1.6.1",
|
|
38
|
+
"@quentinadam/require": "^0.1.4",
|
|
39
|
+
"@quentinadam/uint8array-extension": "^0.1.5"
|
|
40
|
+
}
|
|
41
|
+
}
|