@quentinadam/hash 0.1.4 → 0.1.6

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.
Files changed (45) hide show
  1. package/dist/Buffer.d.ts +1 -1
  2. package/dist/OptionalBuffer.d.ts +3 -0
  3. package/dist/OptionalBuffer.js +1 -0
  4. package/dist/blake2b128.d.ts +2 -2
  5. package/dist/blake2b128.js +3 -2
  6. package/dist/blake2b160.d.ts +2 -2
  7. package/dist/blake2b160.js +3 -2
  8. package/dist/blake2b224.d.ts +2 -2
  9. package/dist/blake2b224.js +3 -2
  10. package/dist/blake2b256.d.ts +2 -2
  11. package/dist/blake2b256.js +3 -2
  12. package/dist/blake2b512.d.ts +2 -2
  13. package/dist/blake2b512.js +3 -2
  14. package/dist/concat.d.ts +2 -2
  15. package/dist/expectUint8Array.d.ts +1 -0
  16. package/dist/expectUint8Array.js +8 -0
  17. package/dist/generateHmac.d.ts +2 -1
  18. package/dist/generateHmac.js +1 -1
  19. package/dist/hmac-sha1.d.ts +2 -1
  20. package/dist/hmac-sha1.js +1 -1
  21. package/dist/hmac-sha224.d.ts +2 -1
  22. package/dist/hmac-sha224.js +1 -1
  23. package/dist/hmac-sha256.d.ts +2 -1
  24. package/dist/hmac-sha256.js +1 -1
  25. package/dist/hmac-sha384.d.ts +2 -1
  26. package/dist/hmac-sha384.js +1 -1
  27. package/dist/hmac-sha512.d.ts +2 -1
  28. package/dist/hmac-sha512.js +1 -1
  29. package/dist/keccak256.d.ts +2 -2
  30. package/dist/keccak256.js +3 -2
  31. package/dist/md5.d.ts +2 -2
  32. package/dist/md5.js +3 -2
  33. package/dist/ripemd160.d.ts +2 -2
  34. package/dist/ripemd160.js +3 -2
  35. package/dist/sha1.d.ts +2 -2
  36. package/dist/sha1.js +3 -2
  37. package/dist/sha224.d.ts +2 -2
  38. package/dist/sha224.js +3 -2
  39. package/dist/sha256.d.ts +2 -2
  40. package/dist/sha256.js +3 -2
  41. package/dist/sha384.d.ts +2 -2
  42. package/dist/sha384.js +3 -2
  43. package/dist/sha512.d.ts +2 -2
  44. package/dist/sha512.js +3 -2
  45. package/package.json +5 -4
package/dist/Buffer.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- type Buffer = Uint8Array | string;
1
+ type Buffer = Uint8Array<ArrayBuffer> | string;
2
2
  export default Buffer;
@@ -0,0 +1,3 @@
1
+ import type Buffer from './Buffer.ts';
2
+ type OptionalBuffer = Buffer | undefined;
3
+ export default OptionalBuffer;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function blake2b128(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function blake2b128(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
- import { blake2b as hash } from '@noble/hashes/blake2';
1
+ import { blake2b as hash } from '@noble/hashes/blake2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function blake2b128(...buffers) {
4
- return hash(concat(buffers), { dkLen: 16 });
5
+ return expectUint8Array(hash(concat(buffers), { dkLen: 16 }));
5
6
  }
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function blake2b160(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function blake2b160(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
- import { blake2b as hash } from '@noble/hashes/blake2';
1
+ import { blake2b as hash } from '@noble/hashes/blake2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function blake2b160(...buffers) {
4
- return hash(concat(buffers), { dkLen: 20 });
5
+ return expectUint8Array(hash(concat(buffers), { dkLen: 20 }));
5
6
  }
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function blake2b224(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function blake2b224(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
- import { blake2b as hash } from '@noble/hashes/blake2';
1
+ import { blake2b as hash } from '@noble/hashes/blake2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function blake2b224(...buffers) {
4
- return hash(concat(buffers), { dkLen: 28 });
5
+ return expectUint8Array(hash(concat(buffers), { dkLen: 28 }));
5
6
  }
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function blake2b256(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function blake2b256(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
- import { blake2b as hash } from '@noble/hashes/blake2';
1
+ import { blake2b as hash } from '@noble/hashes/blake2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function blake2b256(...buffers) {
4
- return hash(concat(buffers), { dkLen: 32 });
5
+ return expectUint8Array(hash(concat(buffers), { dkLen: 32 }));
5
6
  }
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function blake2b512(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function blake2b512(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
- import { blake2b as hash } from '@noble/hashes/blake2';
1
+ import { blake2b as hash } from '@noble/hashes/blake2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function blake2b512(...buffers) {
4
- return hash(concat(buffers), { dkLen: 64 });
5
+ return expectUint8Array(hash(concat(buffers), { dkLen: 64 }));
5
6
  }
package/dist/concat.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function concat(buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function concat(buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -0,0 +1 @@
1
+ export default function expectUint8Array(value: unknown): Uint8Array<ArrayBuffer>;
@@ -0,0 +1,8 @@
1
+ import assert from '@quentinadam/assert';
2
+ function isUint8Array(value) {
3
+ return (value instanceof Uint8Array && value.buffer instanceof ArrayBuffer);
4
+ }
5
+ export default function expectUint8Array(value) {
6
+ assert(isUint8Array(value));
7
+ return value;
8
+ }
@@ -1,2 +1,3 @@
1
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>;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function generateHmac(hash: (buffer: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>, blockSize: number): (secret: Buffer, ...buffers: OptionalBuffer[]) => Uint8Array<ArrayBuffer>;
@@ -16,6 +16,6 @@ export default function generateHmac(hash, blockSize) {
16
16
  innerKey[i] = 0x36 ^ ensure(secret[i]);
17
17
  outerKey[i] = 0x5c ^ ensure(secret[i]);
18
18
  }
19
- return hash(Uint8ArrayExtension.concat([outerKey, hash(Uint8ArrayExtension.concat([innerKey, concat(buffers)]))]));
19
+ return hash(concat([outerKey, hash(concat([innerKey, concat(buffers)]))]));
20
20
  };
21
21
  }
@@ -1,2 +1,3 @@
1
1
  import type Buffer from './Buffer.ts';
2
- export default function hmacSha1(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function hmacSha1(secret: Buffer, ...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/hmac-sha1.js CHANGED
@@ -1,4 +1,4 @@
1
- import { sha1 as hash } from '@noble/hashes/legacy';
1
+ import hash from "./sha1.js";
2
2
  import generateHmac from "./generateHmac.js";
3
3
  export default function hmacSha1(secret, ...buffers) {
4
4
  return generateHmac(hash, 64)(secret, ...buffers);
@@ -1,2 +1,3 @@
1
1
  import type Buffer from './Buffer.ts';
2
- export default function hmacSha224(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function hmacSha224(secret: Buffer, ...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,4 +1,4 @@
1
- import { sha224 as hash } from '@noble/hashes/sha2';
1
+ import hash from "./sha256.js";
2
2
  import generateHmac from "./generateHmac.js";
3
3
  export default function hmacSha224(secret, ...buffers) {
4
4
  return generateHmac(hash, 64)(secret, ...buffers);
@@ -1,2 +1,3 @@
1
1
  import type Buffer from './Buffer.ts';
2
- export default function hmacSha256(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function hmacSha256(secret: Buffer, ...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,4 +1,4 @@
1
- import { sha256 as hash } from '@noble/hashes/sha2';
1
+ import hash from "./sha256.js";
2
2
  import generateHmac from "./generateHmac.js";
3
3
  export default function hmacSha256(secret, ...buffers) {
4
4
  return generateHmac(hash, 64)(secret, ...buffers);
@@ -1,2 +1,3 @@
1
1
  import type Buffer from './Buffer.ts';
2
- export default function hmacSha384(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function hmacSha384(secret: Buffer, ...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,4 +1,4 @@
1
- import { sha384 as hash } from '@noble/hashes/sha2';
1
+ import hash from "./sha384.js";
2
2
  import generateHmac from "./generateHmac.js";
3
3
  export default function hmacSha384(secret, ...buffers) {
4
4
  return generateHmac(hash, 128)(secret, ...buffers);
@@ -1,2 +1,3 @@
1
1
  import type Buffer from './Buffer.ts';
2
- export default function hmacSha512(secret: Buffer, ...buffers: (Buffer | undefined)[]): Uint8Array;
2
+ import type OptionalBuffer from './OptionalBuffer.ts';
3
+ export default function hmacSha512(secret: Buffer, ...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
@@ -1,4 +1,4 @@
1
- import { sha512 as hash } from '@noble/hashes/sha2';
1
+ import hash from "./sha512.js";
2
2
  import generateHmac from "./generateHmac.js";
3
3
  export default function hmacSha512(secret, ...buffers) {
4
4
  return generateHmac(hash, 128)(secret, ...buffers);
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function keccak256(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function keccak256(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/keccak256.js CHANGED
@@ -1,5 +1,6 @@
1
- import { keccak_256 as hash } from '@noble/hashes/sha3';
1
+ import { keccak_256 as hash } from '@noble/hashes/sha3.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function keccak256(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/md5.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function md5(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function md5(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/md5.js CHANGED
@@ -1,5 +1,6 @@
1
- import { md5 as hash } from '@noble/hashes/legacy';
1
+ import { md5 as hash } from '@noble/hashes/legacy.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function md5(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function ripemd160(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function ripemd160(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/ripemd160.js CHANGED
@@ -1,5 +1,6 @@
1
- import { ripemd160 as hash } from '@noble/hashes/legacy';
1
+ import { ripemd160 as hash } from '@noble/hashes/legacy.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function ripemd160(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/sha1.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function sha1(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function sha1(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/sha1.js CHANGED
@@ -1,5 +1,6 @@
1
- import { sha1 as hash } from '@noble/hashes/legacy';
1
+ import { sha1 as hash } from '@noble/hashes/legacy.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function sha1(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/sha224.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function sha224(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function sha224(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/sha224.js CHANGED
@@ -1,5 +1,6 @@
1
- import { sha224 as hash } from '@noble/hashes/sha2';
1
+ import { sha224 as hash } from '@noble/hashes/sha2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function sha224(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/sha256.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function sha256(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function sha256(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/sha256.js CHANGED
@@ -1,5 +1,6 @@
1
- import { sha256 as hash } from '@noble/hashes/sha2';
1
+ import { sha256 as hash } from '@noble/hashes/sha2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function sha256(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/sha384.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function sha384(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function sha384(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/sha384.js CHANGED
@@ -1,5 +1,6 @@
1
- import { sha384 as hash } from '@noble/hashes/sha2';
1
+ import { sha384 as hash } from '@noble/hashes/sha2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function sha384(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/dist/sha512.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type Buffer from './Buffer.ts';
2
- export default function sha512(...buffers: (Buffer | undefined)[]): Uint8Array;
1
+ import type OptionalBuffer from './OptionalBuffer.ts';
2
+ export default function sha512(...buffers: OptionalBuffer[]): Uint8Array<ArrayBuffer>;
package/dist/sha512.js CHANGED
@@ -1,5 +1,6 @@
1
- import { sha512 as hash } from '@noble/hashes/sha2';
1
+ import { sha512 as hash } from '@noble/hashes/sha2.js';
2
2
  import concat from "./concat.js";
3
+ import expectUint8Array from "./expectUint8Array.js";
3
4
  export default function sha512(...buffers) {
4
- return hash(concat(buffers));
5
+ return expectUint8Array(hash(concat(buffers)));
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quentinadam/hash",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "A simple hash library that wraps npm:@noble/hashes",
5
5
  "license": "MIT",
6
6
  "author": "Quentin Adam",
@@ -35,8 +35,9 @@
35
35
  "README.md"
36
36
  ],
37
37
  "dependencies": {
38
- "@noble/hashes": "^1.8.0",
39
- "@quentinadam/ensure": "^0.1.0",
40
- "@quentinadam/uint8array-extension": "^0.1.6"
38
+ "@noble/hashes": "^2.0.0",
39
+ "@quentinadam/assert": "^0.1.12",
40
+ "@quentinadam/ensure": "^0.1.1",
41
+ "@quentinadam/uint8array-extension": "^0.1.7"
41
42
  }
42
43
  }