@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 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
@@ -0,0 +1,2 @@
1
+ type Buffer = Uint8Array | string;
2
+ export default Buffer;
package/dist/Buffer.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function blake2b128(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { blake2b as hash } from '@noble/hashes/blake2b';
2
+ import concat from "./concat.js";
3
+ export default function blake2b128(...buffers) {
4
+ return hash(concat(buffers), { dkLen: 16 });
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function blake2b160(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { blake2b as hash } from '@noble/hashes/blake2b';
2
+ import concat from "./concat.js";
3
+ export default function blake2b160(...buffers) {
4
+ return hash(concat(buffers), { dkLen: 20 });
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function blake2b224(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { blake2b as hash } from '@noble/hashes/blake2b';
2
+ import concat from "./concat.js";
3
+ export default function blake2b224(...buffers) {
4
+ return hash(concat(buffers), { dkLen: 28 });
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function blake2b256(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { blake2b as hash } from '@noble/hashes/blake2b';
2
+ import concat from "./concat.js";
3
+ export default function blake2b256(...buffers) {
4
+ return hash(concat(buffers), { dkLen: 32 });
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function blake2b512(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { blake2b as hash } from '@noble/hashes/blake2b';
2
+ import concat from "./concat.js";
3
+ export default function blake2b512(...buffers) {
4
+ return hash(concat(buffers), { dkLen: 64 });
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function concat(buffers: (Buffer | undefined)[]): Uint8Array;
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,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function generateHmac(hash: (buffer: Uint8Array) => Uint8Array, blockSize: number): (secret: string | Uint8Array, ...buffers: (Buffer | undefined)[]) => Uint8Array<ArrayBufferLike>;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function hmacSha1(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { sha1 as hash } from '@noble/hashes/sha1';
2
+ import generateHmac from "./generateHmac.js";
3
+ export default function hmacSha1(secret, ...buffers) {
4
+ return generateHmac(hash, 64)(secret, ...buffers);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function hmacSha224(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { sha224 as hash } from '@noble/hashes/sha256';
2
+ import generateHmac from "./generateHmac.js";
3
+ export default function hmacSha224(secret, ...buffers) {
4
+ return generateHmac(hash, 64)(secret, ...buffers);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function hmacSha256(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { sha256 as hash } from '@noble/hashes/sha256';
2
+ import generateHmac from "./generateHmac.js";
3
+ export default function hmacSha256(secret, ...buffers) {
4
+ return generateHmac(hash, 64)(secret, ...buffers);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function hmacSha384(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { sha384 as hash } from '@noble/hashes/sha512';
2
+ import generateHmac from "./generateHmac.js";
3
+ export default function hmacSha384(secret, ...buffers) {
4
+ return generateHmac(hash, 128)(secret, ...buffers);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function hmacSha512(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { sha512 as hash } from '@noble/hashes/sha512';
2
+ import generateHmac from "./generateHmac.js";
3
+ export default function hmacSha512(secret, ...buffers) {
4
+ return generateHmac(hash, 128)(secret, ...buffers);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function keccak256(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { keccak_256 as hash } from '@noble/hashes/sha3';
2
+ import concat from "./concat.js";
3
+ export default function keccak256(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
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, };
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function ripemd160(...buffers: (Buffer | undefined)[]): Uint8Array;
@@ -0,0 +1,5 @@
1
+ import { ripemd160 as hash } from '@noble/hashes/ripemd160';
2
+ import concat from "./concat.js";
3
+ export default function ripemd160(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
package/dist/sha1.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function sha1(...buffers: (Buffer | undefined)[]): Uint8Array;
package/dist/sha1.js ADDED
@@ -0,0 +1,5 @@
1
+ import { sha1 as hash } from '@noble/hashes/sha1';
2
+ import concat from "./concat.js";
3
+ export default function sha1(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function sha224(...buffers: (Buffer | undefined)[]): Uint8Array;
package/dist/sha224.js ADDED
@@ -0,0 +1,5 @@
1
+ import { sha224 as hash } from '@noble/hashes/sha256';
2
+ import concat from "./concat.js";
3
+ export default function sha224(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function sha256(...buffers: (Buffer | undefined)[]): Uint8Array;
package/dist/sha256.js ADDED
@@ -0,0 +1,5 @@
1
+ import { sha256 as hash } from '@noble/hashes/sha256';
2
+ import concat from "./concat.js";
3
+ export default function sha256(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function sha384(...buffers: (Buffer | undefined)[]): Uint8Array;
package/dist/sha384.js ADDED
@@ -0,0 +1,5 @@
1
+ import { sha384 as hash } from '@noble/hashes/sha512';
2
+ import concat from "./concat.js";
3
+ export default function sha384(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
@@ -0,0 +1,2 @@
1
+ import type Buffer from './Buffer.ts';
2
+ export default function sha512(...buffers: (Buffer | undefined)[]): Uint8Array;
package/dist/sha512.js ADDED
@@ -0,0 +1,5 @@
1
+ import { sha512 as hash } from '@noble/hashes/sha512';
2
+ import concat from "./concat.js";
3
+ export default function sha512(...buffers) {
4
+ return hash(concat(buffers));
5
+ }
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
+ }