@noble/hashes
Advanced tools
Comparing version 0.4.5 to 0.5.0
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */ | ||
// The import here is via the package name. This is to ensure | ||
// that exports mapping/resolution does fall into place. | ||
import { crypto } from '@noble/hashes/lib/crypto'; | ||
import { crypto } from '@noble/hashes/crypto'; | ||
// Cast array to different type | ||
@@ -6,0 +6,0 @@ export const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength); |
@@ -7,3 +7,3 @@ "use strict"; | ||
// that exports mapping/resolution does fall into place. | ||
const crypto_1 = require("@noble/hashes/lib/crypto"); | ||
const crypto_1 = require("@noble/hashes/crypto"); | ||
// Cast array to different type | ||
@@ -10,0 +10,0 @@ const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength); |
{ | ||
"name": "@noble/hashes", | ||
"version": "0.4.5", | ||
"version": "0.5.0", | ||
"description": "Fast 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt", | ||
@@ -62,7 +62,7 @@ "directories": { | ||
"exports": { | ||
"./lib": { | ||
"./index": { | ||
"import": "./lib/esm/index.js", | ||
"default": "./lib/index.js" | ||
}, | ||
"./lib/crypto": { | ||
"./crypto": { | ||
"browser": { | ||
@@ -75,68 +75,73 @@ "import": "./lib/esm/cryptoBrowser.js", | ||
}, | ||
"./lib/blake2b": { | ||
"./blake2b": { | ||
"import": "./lib/esm/blake2b.js", | ||
"default": "./lib/blake2b.js" | ||
}, | ||
"./lib/blake2b.d.ts": "./lib/blake2b.d.ts", | ||
"./lib/blake2s": { | ||
"./blake2b.d.ts": "./lib/blake2b.d.ts", | ||
"./blake2s": { | ||
"import": "./lib/esm/blake2s.js", | ||
"default": "./lib/blake2s.js" | ||
}, | ||
"./lib/blake2s.d.ts": "./lib/blake2s.d.ts", | ||
"./lib/blake3": { | ||
"./blake2s.d.ts": "./lib/blake2s.d.ts", | ||
"./blake3": { | ||
"import": "./lib/esm/blake3.js", | ||
"default": "./lib/blake3.js" | ||
}, | ||
"./lib/blake3.d.ts": "./lib/blake3.d.ts", | ||
"./lib/hkdf": { | ||
"./blake3.d.ts": "./lib/blake3.d.ts", | ||
"./eskdf": { | ||
"import": "./lib/esm/eskdf.js", | ||
"default": "./lib/eskdf.js" | ||
}, | ||
"./eskdf.d.ts": "./lib/eskdf.d.ts", | ||
"./hkdf": { | ||
"import": "./lib/esm/hkdf.js", | ||
"default": "./lib/hkdf.js" | ||
}, | ||
"./lib/hkdf.d.ts": "./lib/hkdf.d.ts", | ||
"./lib/hmac": { | ||
"./hkdf.d.ts": "./lib/hkdf.d.ts", | ||
"./hmac": { | ||
"import": "./lib/esm/hmac.js", | ||
"default": "./lib/hmac.js" | ||
}, | ||
"./lib/hmac.d.ts": "./lib/hmac.d.ts", | ||
"./lib/pbkdf2": { | ||
"./hmac.d.ts": "./lib/hmac.d.ts", | ||
"./pbkdf2": { | ||
"import": "./lib/esm/pbkdf2.js", | ||
"default": "./lib/pbkdf2.js" | ||
}, | ||
"./lib/pbkdf2.d.ts": "./lib/pbkdf2.d.ts", | ||
"./lib/ripemd160": { | ||
"./pbkdf2.d.ts": "./lib/pbkdf2.d.ts", | ||
"./ripemd160": { | ||
"import": "./lib/esm/ripemd160.js", | ||
"default": "./lib/ripemd160.js" | ||
}, | ||
"./lib/ripemd160.d.ts": "./lib/ripemd160.d.ts", | ||
"./lib/scrypt": { | ||
"./ripemd160.d.ts": "./lib/ripemd160.d.ts", | ||
"./scrypt": { | ||
"import": "./lib/esm/scrypt.js", | ||
"default": "./lib/scrypt.js" | ||
}, | ||
"./lib/scrypt.d.ts": "./lib/scrypt.d.ts", | ||
"./lib/sha3-addons": { | ||
"./scrypt.d.ts": "./lib/scrypt.d.ts", | ||
"./sha3-addons": { | ||
"import": "./lib/esm/sha3-addons.js", | ||
"default": "./lib/sha3-addons.js" | ||
}, | ||
"./lib/sha3-addons.d.ts": "./lib/sha3-addons.d.ts", | ||
"./lib/sha3": { | ||
"./sha3-addons.d.ts": "./lib/sha3-addons.d.ts", | ||
"./sha3": { | ||
"import": "./lib/esm/sha3.js", | ||
"default": "./lib/sha3.js" | ||
}, | ||
"./lib/sha3.d.ts": "./lib/sha3.d.ts", | ||
"./lib/sha256": { | ||
"./sha3.d.ts": "./lib/sha3.d.ts", | ||
"./sha256": { | ||
"import": "./lib/esm/sha256.js", | ||
"default": "./lib/sha256.js" | ||
}, | ||
"./lib/sha256.d.ts": "./lib/sha256.d.ts", | ||
"./lib/sha512": { | ||
"./sha256.d.ts": "./lib/sha256.d.ts", | ||
"./sha512": { | ||
"import": "./lib/esm/sha512.js", | ||
"default": "./lib/sha512.js" | ||
}, | ||
"./lib/sha512.d.ts": "./lib/sha512.d.ts", | ||
"./lib/utils": { | ||
"./sha512.d.ts": "./lib/sha512.d.ts", | ||
"./utils": { | ||
"import": "./lib/esm/utils.js", | ||
"default": "./lib/utils.js" | ||
}, | ||
"./lib/utils.d.ts": "./lib/utils.d.ts" | ||
"./utils.d.ts": "./lib/utils.d.ts" | ||
} | ||
} |
@@ -42,3 +42,3 @@ # noble-hashes ![Node CI](https://github.com/paulmillr/noble-hashes/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
// Common.js and ECMAScript Modules (ESM) | ||
import { sha256 } from '@noble/hashes/lib/sha256'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
console.log(sha256(new Uint8Array([1, 2, 3]))); | ||
@@ -51,3 +51,3 @@ // Uint8Array(32) [3, 144, 88, 198, 242, 192, 203, 73, ...] | ||
// sha384 is here, because it uses same internals as sha512 | ||
const { sha512, sha512_256, sha384 } = require('@noble/hashes/lib/sha512'); | ||
const { sha512, sha512_256, sha384 } = require('@noble/hashes/sha512'); | ||
// prettier-ignore | ||
@@ -58,3 +58,3 @@ const { | ||
shake128, shake256 | ||
} = require('@noble/hashes/lib/sha3'); | ||
} = require('@noble/hashes/sha3'); | ||
// prettier-ignore | ||
@@ -65,14 +65,14 @@ const { | ||
tuplehash256, parallelhash256, keccakprg | ||
} = require('@noble/hashes/lib/sha3-addons'); | ||
const { ripemd160 } = require('@noble/hashes/lib/ripemd160'); | ||
const { blake3 } = require('@noble/hashes/lib/blake3'); | ||
const { blake2b } = require('@noble/hashes/lib/blake2b'); | ||
const { blake2s } = require('@noble/hashes/lib/blake2s'); | ||
const { hmac } = require('@noble/hashes/lib/hmac'); | ||
const { hkdf } = require('@noble/hashes/lib/hkdf'); | ||
const { pbkdf2, pbkdf2Async } = require('@noble/hashes/lib/pbkdf2'); | ||
const { scrypt, scryptAsync } = require('@noble/hashes/lib/scrypt'); | ||
} = require('@noble/hashes/sha3-addons'); | ||
const { ripemd160 } = require('@noble/hashes/ripemd160'); | ||
const { blake3 } = require('@noble/hashes/blake3'); | ||
const { blake2b } = require('@noble/hashes/blake2b'); | ||
const { blake2s } = require('@noble/hashes/blake2s'); | ||
const { hmac } = require('@noble/hashes/hmac'); | ||
const { hkdf } = require('@noble/hashes/hkdf'); | ||
const { pbkdf2, pbkdf2Async } = require('@noble/hashes/pbkdf2'); | ||
const { scrypt, scryptAsync } = require('@noble/hashes/scrypt'); | ||
// small utility method that converts bytes to hex | ||
const { bytesToHex as toHex } = require('@noble/hashes/lib/utils'); | ||
const { bytesToHex as toHex } = require('@noble/hashes/utils'); | ||
console.log(toHex(sha256('abc'))); | ||
@@ -127,2 +127,3 @@ // ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad | ||
- [Scrypt](#scrypt) | ||
- [ESKDF](#eskdf) | ||
- [utils](#utils) | ||
@@ -133,3 +134,3 @@ | ||
```typescript | ||
import { sha256 } from '@noble/hashes/lib/sha256.js'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
const h1a = sha256('abc'); | ||
@@ -143,3 +144,3 @@ const h1b = sha256 | ||
```typescript | ||
import { sha512 } from '@noble/hashes/lib/sha512.js'; | ||
import { sha512 } from '@noble/hashes/sha512'; | ||
const h2a = sha512('abc'); | ||
@@ -152,3 +153,3 @@ const h2b = sha512 | ||
// SHA512/256 variant | ||
import { sha512_256 } from '@noble/hashes/lib/sha512.js'; | ||
import { sha512_256 } from '@noble/hashes/sha512'; | ||
const h3a = sha512_256('abc'); | ||
@@ -161,3 +162,3 @@ const h3b = sha512_256 | ||
// SHA384 | ||
import { sha384 } from '@noble/hashes/lib/sha512.js'; | ||
import { sha384 } from '@noble/hashes/sha512'; | ||
const h4a = sha384('abc'); | ||
@@ -186,3 +187,3 @@ const h4b = sha384 | ||
shake256, | ||
} from '@noble/hashes/lib/sha3.js'; | ||
} from '@noble/hashes/sha3'; | ||
const h5a = sha3_256('abc'); | ||
@@ -217,3 +218,3 @@ const h5b = sha3_256 | ||
keccakprg, | ||
} from '@noble/hashes/lib/sha3-addons.js'; | ||
} from '@noble/hashes/sha3-addons'; | ||
const h7c = cshake128('abc', { personalization: 'def' }); | ||
@@ -243,3 +244,3 @@ const h7d = cshake256('abc', { personalization: 'def' }); | ||
```typescript | ||
import { ripemd160 } from '@noble/hashes/lib/ripemd160.js'; | ||
import { ripemd160 } from '@noble/hashes/ripemd160'; | ||
// function ripemd160(data: Uint8Array): Uint8Array; | ||
@@ -258,4 +259,4 @@ const hash8 = ripemd160('abc'); | ||
```typescript | ||
import { blake2b } from '@noble/hashes/lib/blake2b.js'; | ||
import { blake2s } from '@noble/hashes/lib/blake2s.js'; | ||
import { blake2b } from '@noble/hashes/blake2b'; | ||
import { blake2s } from '@noble/hashes/blake2s'; | ||
const h10a = blake2s('abc'); | ||
@@ -275,3 +276,3 @@ const b2params = { key: new Uint8Array([1]), personalization: t, salt: t, dkLen: 32 }; | ||
```typescript | ||
import { blake3 } from '@noble/hashes/lib/blake3.js'; | ||
import { blake3 } from '@noble/hashes/blake3'; | ||
// All params are optional | ||
@@ -286,4 +287,4 @@ const h11 = blake3('abc', { dkLen: 256, key: 'def', context: 'fji' }); | ||
```typescript | ||
import { hmac } from '@noble/hashes/lib/hmac.js'; | ||
import { sha256 } from '@noble/hashes/lib/sha256.js'; | ||
import { hmac } from '@noble/hashes/hmac'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
const mac1 = hmac(sha256, 'key', 'message'); | ||
@@ -298,5 +299,5 @@ const mac2 = hmac.create(sha256, Uint8Array.from([1, 2, 3])).update(Uint8Array.from([4, 5, 6]).digest(); | ||
```typescript | ||
import { hkdf } from '@noble/hashes/lib/kdf.js'; | ||
import { sha256 } from '@noble/hashes/lib/sha256.js'; | ||
import { randomBytes } from '@noble/hashes/utils.js'; | ||
import { hkdf } from '@noble/hashes/kdf'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
import { randomBytes } from '@noble/hashes/utils'; | ||
const inputKey = randomBytes(32); | ||
@@ -309,4 +310,4 @@ const salt = randomBytes(32); | ||
// == same as | ||
import { hkdf_extract, hkdf_expand } from '@noble/hashes/lib/kdf.js'; | ||
import { sha256 } from '@noble/hashes/lib/sha256.js'; | ||
import { hkdf_extract, hkdf_expand } from '@noble/hashes/kdf'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
const prk = hkdf_extract(sha256, inputKey, salt); | ||
@@ -321,4 +322,4 @@ const hk2 = hkdf_expand(sha256, prk, info, dkLen); | ||
```typescript | ||
import { pbkdf2, pbkdf2Async } from '@noble/hashes/lib/pbkdf2.js'; | ||
import { sha256 } from '@noble/hashes/lib/sha256.js'; | ||
import { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
const pbkey1 = pbkdf2(sha256, 'password', 'salt', { c: 32, dkLen: 32 }); | ||
@@ -337,3 +338,3 @@ const pbkey2 = await pbkdf2Async(sha256, 'password', 'salt', { c: 32, dkLen: 32 }); | ||
```typescript | ||
import { scrypt, scryptAsync } from '@noble/hashes/lib/scrypt.js'; | ||
import { scrypt, scryptAsync } from '@noble/hashes/scrypt'; | ||
const scr1 = scrypt('password', 'salt', { N: 2 ** 16, r: 8, p: 1, dkLen: 32 }); | ||
@@ -368,6 +369,20 @@ const scr2 = await scryptAsync('password', 'salt', { N: 2 ** 16, r: 8, p: 1, dkLen: 32 }); | ||
##### ESKDF | ||
A tiny stretched KDF for various applications like AES key-gen. Takes >= 2 seconds to execute. | ||
Takes username and password, then takes protocol name and account id. | ||
```typescript | ||
import { eskdf } from '@noble/hashes/eskdf'; | ||
const kdf = await eskdf('example-university', 'beginning-new-example'); | ||
const key = kdf.deriveChildKey('aes', 0); | ||
console.log(kdf.fingerprint); | ||
kdf.expire(); | ||
``` | ||
##### utils | ||
```typescript | ||
import { bytesToHex as toHex, randomBytes } from '@noble/hashes/lib/scrypt.js'; | ||
import { bytesToHex as toHex, randomBytes } from '@noble/hashes/scrypt'; | ||
console.log(toHex(randomBytes(32))); | ||
@@ -374,0 +389,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256725
64
5677
455