Socket
Socket
Sign inDemoInstall

@noble/hashes

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@noble/hashes - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

12

lib/_blake2.js

@@ -30,5 +30,5 @@ "use strict";

this.destroyed = false;
utils_1.assertNumber(blockLen);
utils_1.assertNumber(outputLen);
utils_1.assertNumber(keyLen);
(0, utils_1.assertNumber)(blockLen);
(0, utils_1.assertNumber)(outputLen);
(0, utils_1.assertNumber)(keyLen);
if (outputLen < 0 || outputLen > keyLen)

@@ -42,3 +42,3 @@ throw new Error('Blake2: outputLen bigger than keyLen');

throw new Error(`Personalization should be ${persLen} byte long or undefined`);
this.buffer32 = utils_1.u32((this.buffer = new Uint8Array(blockLen)));
this.buffer32 = (0, utils_1.u32)((this.buffer = new Uint8Array(blockLen)));
}

@@ -55,3 +55,3 @@ update(data) {

throw new Error('digest() was already called');
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
const len = data.length;

@@ -94,3 +94,3 @@ for (let pos = 0; pos < len;) {

this.compress(buffer32, 0, true);
const out32 = utils_1.u32(out);
const out32 = (0, utils_1.u32)(out);
this.get().forEach((v, i) => (out32[i] = v));

@@ -97,0 +97,0 @@ }

@@ -28,3 +28,3 @@ "use strict";

this.buffer = new Uint8Array(blockLen);
this.view = utils_1.createView(this.buffer);
this.view = (0, utils_1.createView)(this.buffer);
}

@@ -37,3 +37,3 @@ update(data) {

throw new Error('digest() was already called');
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
const len = data.length;

@@ -44,3 +44,3 @@ for (let pos = 0; pos < len;) {

if (take === blockLen) {
const dataView = utils_1.createView(data);
const dataView = (0, utils_1.createView)(data);
for (; blockLen <= len - pos; pos += blockLen)

@@ -91,3 +91,3 @@ this.process(dataView, pos);

this.process(view, 0);
const oview = utils_1.createView(out);
const oview = (0, utils_1.createView)(out);
this.get().forEach((v, i) => oview.setUint32(4 * i, v, isLE));

@@ -94,0 +94,0 @@ }

@@ -106,3 +106,3 @@ "use strict";

if (opts.salt) {
const salt = utils_1.u32(utils_1.toBytes(opts.salt));
const salt = (0, utils_1.u32)((0, utils_1.toBytes)(opts.salt));
this.v4l ^= salt[0];

@@ -114,3 +114,3 @@ this.v4h ^= salt[1];

if (opts.personalization) {
const pers = utils_1.u32(utils_1.toBytes(opts.personalization));
const pers = (0, utils_1.u32)((0, utils_1.toBytes)(opts.personalization));
this.v6l ^= pers[0];

@@ -124,3 +124,3 @@ this.v6h ^= pers[1];

const tmp = new Uint8Array(this.blockLen);
tmp.set(utils_1.toBytes(opts.key));
tmp.set((0, utils_1.toBytes)(opts.key));
this.update(tmp);

@@ -208,2 +208,2 @@ }

}
exports.blake2b = utils_1.wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
exports.blake2b = (0, utils_1.wrapConstructorWithOpts)((opts) => new BLAKE2b(opts));

@@ -36,5 +36,5 @@ "use strict";

a = (a + b + x) | 0;
d = utils_1.rotr(d ^ a, 16);
d = (0, utils_1.rotr)(d ^ a, 16);
c = (c + d) | 0;
b = utils_1.rotr(b ^ c, 12);
b = (0, utils_1.rotr)(b ^ c, 12);
return { a, b, c, d };

@@ -44,5 +44,5 @@ }

a = (a + b + x) | 0;
d = utils_1.rotr(d ^ a, 8);
d = (0, utils_1.rotr)(d ^ a, 8);
c = (c + d) | 0;
b = utils_1.rotr(b ^ c, 7);
b = (0, utils_1.rotr)(b ^ c, 7);
return { a, b, c, d };

@@ -89,3 +89,3 @@ }

if (opts.salt) {
const salt = utils_1.u32(utils_1.toBytes(opts.salt));
const salt = (0, utils_1.u32)((0, utils_1.toBytes)(opts.salt));
this.v4 ^= salt[0];

@@ -95,3 +95,3 @@ this.v5 ^= salt[1];

if (opts.personalization) {
const pers = utils_1.u32(utils_1.toBytes(opts.personalization));
const pers = (0, utils_1.u32)((0, utils_1.toBytes)(opts.personalization));
this.v6 ^= pers[0];

@@ -103,3 +103,3 @@ this.v7 ^= pers[1];

const tmp = new Uint8Array(this.blockLen);
tmp.set(utils_1.toBytes(opts.key));
tmp.set((0, utils_1.toBytes)(opts.key));
this.update(tmp);

@@ -142,2 +142,2 @@ }

}
exports.blake2s = utils_1.wrapConstructorWithOpts((opts) => new BLAKE2s(opts));
exports.blake2s = (0, utils_1.wrapConstructorWithOpts)((opts) => new BLAKE2s(opts));

@@ -67,10 +67,10 @@ "use strict";

this.outputLen = opts.dkLen === undefined ? 32 : opts.dkLen;
utils_1.assertNumber(this.outputLen);
(0, utils_1.assertNumber)(this.outputLen);
if (opts.key !== undefined && opts.context !== undefined)
throw new Error('Blake3: only key or context can be specified at same time');
else if (opts.key !== undefined) {
const key = utils_1.toBytes(opts.key);
const key = (0, utils_1.toBytes)(opts.key);
if (key.length !== 32)
throw new Error('Blake3: key should be 32 byte');
this.IV = utils_1.u32(key);
this.IV = (0, utils_1.u32)(key);
this.flags = flags | Flags.KEYED_HASH;

@@ -82,3 +82,3 @@ }

.digest();
this.IV = utils_1.u32(context_key);
this.IV = (0, utils_1.u32)(context_key);
this.flags = flags | Flags.DERIVE_KEY_MATERIAL;

@@ -91,3 +91,3 @@ }

this.state = this.IV.slice();
this.bufferOut = utils_1.u8(this.bufferOut32);
this.bufferOut = (0, utils_1.u8)(this.bufferOut32);
}

@@ -241,3 +241,3 @@ // Unused

XOF(bytes) {
utils_1.assertNumber(bytes);
(0, utils_1.assertNumber)(bytes);
return this.XOFInto(new Uint8Array(bytes));

@@ -259,2 +259,2 @@ }

}
exports.blake3 = utils_1.wrapConstructorWithOpts((opts) => new BLAKE3(opts));
exports.blake3 = (0, utils_1.wrapConstructorWithOpts)((opts) => new BLAKE3(opts));

@@ -10,3 +10,3 @@ "use strict";

function hkdf_extract(hash, ikm, salt) {
utils_1.assertHash(hash);
(0, utils_1.assertHash)(hash);
// NOTE: some libraries treats zero-length array as 'not provided', we don't, since we have undefined as 'not provided'

@@ -16,3 +16,3 @@ // More info: https://github.com/RustCrypto/KDFs/issues/15

salt = new Uint8Array(hash.outputLen); // if not provided, it is set to a string of HashLen zeros
return hmac_1.hmac(hash, utils_1.toBytes(salt), utils_1.toBytes(ikm));
return (0, hmac_1.hmac)(hash, (0, utils_1.toBytes)(salt), (0, utils_1.toBytes)(ikm));
}

@@ -27,4 +27,4 @@ exports.hkdf_extract = hkdf_extract;

) {
utils_1.assertHash(hash);
utils_1.assertNumber(length);
(0, utils_1.assertHash)(hash);
(0, utils_1.assertNumber)(length);
if (length > 255 * hash.outputLen)

@@ -31,0 +31,0 @@ throw new Error('Length should be <= 255*HashLen');

@@ -18,5 +18,5 @@ import { Hash, CHash, Input } from './utils';

(hash: CHash, key: Input, message: Input): Uint8Array;
create(hash: CHash, key: Input): HMAC<Hash<unknown>>;
init: (hash: CHash, key: Input) => HMAC<Hash<unknown>>;
create(hash: CHash, key: Input): HMAC<any>;
init: (hash: CHash, key: Input) => HMAC<any>;
};
export {};

@@ -11,4 +11,4 @@ "use strict";

this.destroyed = false;
utils_1.assertHash(hash);
const key = utils_1.toBytes(_key);
(0, utils_1.assertHash)(hash);
const key = (0, utils_1.toBytes)(_key);
this.iHash = hash.create();

@@ -15,0 +15,0 @@ if (!(this.iHash instanceof utils_1.Hash))

@@ -9,12 +9,12 @@ "use strict";

function pbkdf2Init(hash, _password, _salt, _opts) {
utils_1.assertHash(hash);
const opts = utils_1.checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
(0, utils_1.assertHash)(hash);
const opts = (0, utils_1.checkOpts)({ dkLen: 32, asyncTick: 10 }, _opts);
const { c, dkLen, asyncTick } = opts;
utils_1.assertNumber(c);
utils_1.assertNumber(dkLen);
utils_1.assertNumber(asyncTick);
(0, utils_1.assertNumber)(c);
(0, utils_1.assertNumber)(dkLen);
(0, utils_1.assertNumber)(asyncTick);
if (c < 1)
throw new Error('PBKDF2: iterations (c) should be >= 1');
const password = utils_1.toBytes(_password);
const salt = utils_1.toBytes(_salt);
const password = (0, utils_1.toBytes)(_password);
const salt = (0, utils_1.toBytes)(_salt);
// DK = PBKDF2(PRF, Password, Salt, c, dkLen);

@@ -39,3 +39,3 @@ const DK = new Uint8Array(dkLen);

const arr = new Uint8Array(4);
const view = utils_1.createView(arr);
const view = (0, utils_1.createView)(arr);
const u = new Uint8Array(PRF.outputLen);

@@ -65,3 +65,3 @@ // DK = T1 + T2 + ⋯ + Tdklen/hlen

const arr = new Uint8Array(4);
const view = utils_1.createView(arr);
const view = (0, utils_1.createView)(arr);
const u = new Uint8Array(PRF.outputLen);

@@ -77,3 +77,3 @@ // DK = T1 + T2 + ⋯ + Tdklen/hlen

Ti.set(u.subarray(0, Ti.length));
await utils_1.asyncLoop(c - 1, asyncTick, (i) => {
await (0, utils_1.asyncLoop)(c - 1, asyncTick, (i) => {
// Uc = PRF(Password, Uc−1)

@@ -80,0 +80,0 @@ PRF._cloneInto(prfW).update(u).digestInto(u);

@@ -98,2 +98,2 @@ "use strict";

exports.RIPEMD160 = RIPEMD160;
exports.ripemd160 = utils_1.wrapConstructor(() => new RIPEMD160());
exports.ripemd160 = (0, utils_1.wrapConstructor)(() => new RIPEMD160());

@@ -92,3 +92,3 @@ "use strict";

// Maxmem - 1GB+1KB by default
const opts = utils_1.checkOpts({
const opts = (0, utils_1.checkOpts)({
dkLen: 32,

@@ -99,8 +99,8 @@ asyncTick: 10,

const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts;
utils_1.assertNumber(N);
utils_1.assertNumber(r);
utils_1.assertNumber(p);
utils_1.assertNumber(dkLen);
utils_1.assertNumber(asyncTick);
utils_1.assertNumber(maxmem);
(0, utils_1.assertNumber)(N);
(0, utils_1.assertNumber)(r);
(0, utils_1.assertNumber)(p);
(0, utils_1.assertNumber)(dkLen);
(0, utils_1.assertNumber)(asyncTick);
(0, utils_1.assertNumber)(maxmem);
if (onProgress !== undefined && typeof onProgress !== 'function')

@@ -127,7 +127,7 @@ throw new Error('progressCb should be function');

// Since it has only one iteration there is no reason to use async variant
const B = pbkdf2_1.pbkdf2(sha256_1.sha256, password, salt, { c: 1, dkLen: blockSize * p });
const B32 = utils_1.u32(B);
const B = (0, pbkdf2_1.pbkdf2)(sha256_1.sha256, password, salt, { c: 1, dkLen: blockSize * p });
const B32 = (0, utils_1.u32)(B);
// Re-used between parallel iterations. Array(iterations) of B
const V = utils_1.u32(new Uint8Array(blockSize * N));
const tmp = utils_1.u32(new Uint8Array(blockSize));
const V = (0, utils_1.u32)(new Uint8Array(blockSize * N));
const tmp = (0, utils_1.u32)(new Uint8Array(blockSize));
let blockMixCb = () => { };

@@ -149,3 +149,3 @@ if (onProgress) {

function scryptOutput(password, dkLen, B, V, tmp) {
const res = pbkdf2_1.pbkdf2(sha256_1.sha256, password, B, { c: 1, dkLen });
const res = (0, pbkdf2_1.pbkdf2)(sha256_1.sha256, password, B, { c: 1, dkLen });
B.fill(0);

@@ -187,3 +187,3 @@ V.fill(0);

let pos = 0;
await utils_1.asyncLoop(N - 1, asyncTick, (i) => {
await (0, utils_1.asyncLoop)(N - 1, asyncTick, (i) => {
BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]);

@@ -194,3 +194,3 @@ blockMixCb();

blockMixCb();
await utils_1.asyncLoop(N, asyncTick, (i) => {
await (0, utils_1.asyncLoop)(N, asyncTick, (i) => {
// First u32 of the last 64-byte block (u32 is LE)

@@ -197,0 +197,0 @@ const j = B32[Pi + blockSize32 - 16] % N; // j = Integrify(X) % iterations

@@ -67,4 +67,4 @@ "use strict";

const W2 = SHA256_W[i - 2];
const s0 = utils_1.rotr(W15, 7) ^ utils_1.rotr(W15, 18) ^ (W15 >>> 3);
const s1 = utils_1.rotr(W2, 17) ^ utils_1.rotr(W2, 19) ^ (W2 >>> 10);
const s0 = (0, utils_1.rotr)(W15, 7) ^ (0, utils_1.rotr)(W15, 18) ^ (W15 >>> 3);
const s1 = (0, utils_1.rotr)(W2, 17) ^ (0, utils_1.rotr)(W2, 19) ^ (W2 >>> 10);
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;

@@ -75,5 +75,5 @@ }

for (let i = 0; i < 64; i++) {
const sigma1 = utils_1.rotr(E, 6) ^ utils_1.rotr(E, 11) ^ utils_1.rotr(E, 25);
const sigma1 = (0, utils_1.rotr)(E, 6) ^ (0, utils_1.rotr)(E, 11) ^ (0, utils_1.rotr)(E, 25);
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
const sigma0 = utils_1.rotr(A, 2) ^ utils_1.rotr(A, 13) ^ utils_1.rotr(A, 22);
const sigma0 = (0, utils_1.rotr)(A, 2) ^ (0, utils_1.rotr)(A, 13) ^ (0, utils_1.rotr)(A, 22);
const T2 = (sigma0 + Maj(A, B, C)) | 0;

@@ -108,2 +108,2 @@ H = G;

}
exports.sha256 = utils_1.wrapConstructor(() => new SHA256());
exports.sha256 = (0, utils_1.wrapConstructor)(() => new SHA256());

@@ -23,3 +23,3 @@ "use strict";

}
const toBytesOptional = (buf) => (buf !== undefined ? utils_1.toBytes(buf) : new Uint8Array([]));
const toBytesOptional = (buf) => (buf !== undefined ? (0, utils_1.toBytes)(buf) : new Uint8Array([]));
// NOTE: second modulo is necessary since we don't need to add padding if current element takes whole block

@@ -46,3 +46,3 @@ const getPadding = (len, block) => new Uint8Array((block - (len % block)) % block);

}
const gencShake = (suffix, blockLen, outputLen) => utils_1.wrapConstructorWithOpts((opts = {}) => cshakePers(new sha3_1.Keccak(blockLen, suffix, opts.dkLen !== undefined ? opts.dkLen : outputLen, true), opts));
const gencShake = (suffix, blockLen, outputLen) => (0, utils_1.wrapConstructorWithOpts)((opts = {}) => cshakePers(new sha3_1.Keccak(blockLen, suffix, opts.dkLen !== undefined ? opts.dkLen : outputLen, true), opts));
exports.cshake128 = gencShake(0x1f, 168, 128 / 8);

@@ -54,3 +54,3 @@ exports.cshake256 = gencShake(0x1f, 136, 256 / 8);

cshakePers(this, { NISTfn: 'KMAC', personalization: opts.personalization });
key = utils_1.toBytes(key);
key = (0, utils_1.toBytes)(key);
// 1. newX = bytepad(encode_string(K), 168) || X || right_encode(L).

@@ -75,3 +75,3 @@ const blockLenBytes = leftEncode(this.blockLen);

to.blockLen = this.blockLen;
to.state32 = utils_1.u32(to.state);
to.state32 = (0, utils_1.u32)(to.state);
}

@@ -102,3 +102,3 @@ return super._cloneInto(to);

this.update = (data) => {
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
super.update(leftEncode(data.length * 8));

@@ -146,3 +146,3 @@ super.update(data);

B || (B = 8);
utils_1.assertNumber(B);
(0, utils_1.assertNumber)(B);
this.chunkLen = B;

@@ -152,3 +152,3 @@ super.update(leftEncode(B));

this.update = (data) => {
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
const { chunkLen, leafCons } = this;

@@ -232,3 +232,3 @@ for (let pos = 0, len = data.length; pos < len;) {

update(data) {
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
const { chunkLen, blockLen, leafLen, rounds } = this;

@@ -295,5 +295,5 @@ for (let pos = 0, len = data.length; pos < len;) {

// Default to 32 bytes, so it can be used without opts
exports.k12 = utils_1.wrapConstructorWithOpts((opts = {}) => new KangarooTwelve(168, 32, opts.dkLen !== undefined ? opts.dkLen : 32, 12, opts));
exports.k12 = (0, utils_1.wrapConstructorWithOpts)((opts = {}) => new KangarooTwelve(168, 32, opts.dkLen !== undefined ? opts.dkLen : 32, 12, opts));
// MarsupilamiFourteen
exports.m14 = utils_1.wrapConstructorWithOpts((opts = {}) => new KangarooTwelve(136, 64, opts.dkLen !== undefined ? opts.dkLen : 64, 14, opts));
exports.m14 = (0, utils_1.wrapConstructorWithOpts)((opts = {}) => new KangarooTwelve(136, 64, opts.dkLen !== undefined ? opts.dkLen : 64, 14, opts));
// https://keccak.team/files/CSF-0.1.pdf

@@ -303,3 +303,3 @@ // + https://github.com/XKCP/XKCP/tree/master/lib/high/Keccak/PRG

constructor(capacity) {
utils_1.assertNumber(capacity);
(0, utils_1.assertNumber)(capacity);
// Rho should be full bytes

@@ -306,0 +306,0 @@ if (capacity < 0 || capacity > 1600 - 10 || (1600 - capacity - 2) % 8)

@@ -107,3 +107,3 @@ "use strict";

// Can be passed from user as dkLen
utils_1.assertNumber(outputLen);
(0, utils_1.assertNumber)(outputLen);
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes

@@ -113,3 +113,3 @@ if (0 >= this.blockLen || this.blockLen >= 200)

this.state = new Uint8Array(200);
this.state32 = utils_1.u32(this.state);
this.state32 = (0, utils_1.u32)(this.state);
}

@@ -127,3 +127,3 @@ keccak() {

const { blockLen, state } = this;
data = utils_1.toBytes(data);
data = (0, utils_1.toBytes)(data);
const len = data.length;

@@ -174,3 +174,3 @@ for (let pos = 0; pos < len;) {

XOF(bytes) {
utils_1.assertNumber(bytes);
(0, utils_1.assertNumber)(bytes);
return this.XOFInto(new Uint8Array(bytes));

@@ -212,3 +212,3 @@ }

exports.Keccak = Keccak;
const gen = (suffix, blockLen, outputLen) => utils_1.wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
const gen = (suffix, blockLen, outputLen) => (0, utils_1.wrapConstructor)(() => new Keccak(blockLen, suffix, outputLen));
exports.sha3_224 = gen(0x06, 144, 224 / 8);

@@ -222,4 +222,4 @@ exports.sha3_256 = gen(0x06, 136, 256 / 8);

exports.keccak_512 = gen(0x01, 72, 512 / 8);
const genShake = (suffix, blockLen, outputLen) => utils_1.wrapConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen !== undefined ? opts.dkLen : outputLen, true));
const genShake = (suffix, blockLen, outputLen) => (0, utils_1.wrapConstructorWithOpts)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen !== undefined ? opts.dkLen : outputLen, true));
exports.shake128 = genShake(0x1f, 168, 128 / 8);
exports.shake256 = genShake(0x1f, 136, 256 / 8);

@@ -227,4 +227,4 @@ "use strict";

}
exports.sha512 = utils_1.wrapConstructor(() => new SHA512());
exports.sha512_256 = utils_1.wrapConstructor(() => new SHA512_256());
exports.sha384 = utils_1.wrapConstructor(() => new SHA384());
exports.sha512 = (0, utils_1.wrapConstructor)(() => new SHA512());
exports.sha512_256 = (0, utils_1.wrapConstructor)(() => new SHA512_256());
exports.sha384 = (0, utils_1.wrapConstructor)(() => new SHA384());

@@ -55,3 +55,3 @@ "use strict";

continue;
await exports.nextTick();
await (0, exports.nextTick)();
ts += diff;

@@ -58,0 +58,0 @@ }

{
"name": "@noble/hashes",
"version": "0.4.0",
"version": "0.4.1",
"description": "Fast 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc