@noble/hashes
Advanced tools
Comparing version 0.5.2 to 0.5.3
13
eskdf.js
@@ -19,5 +19,2 @@ "use strict"; | ||
const PROTOCOLS_ALLOWING_STR = ['ssh', 'tor', 'file']; | ||
function has32Bytes(a) { | ||
return a instanceof Uint8Array && a.length === 32; | ||
} | ||
function strHasLength(str, min, max) { | ||
@@ -38,4 +35,4 @@ return typeof str === 'string' && str.length >= min && str.length <= max; | ||
function xor32(a, b) { | ||
if (!has32Bytes(a) || !has32Bytes(b)) | ||
throw new Error('invalid xor32 call'); | ||
(0, utils_js_1.assertBytes)(a, 32); | ||
(0, utils_js_1.assertBytes)(b, 32); | ||
const arr = new Uint8Array(32); | ||
@@ -66,4 +63,3 @@ for (let i = 0; i < 32; i++) { | ||
function deriveChildKey(seed, protocol, accountId = 0, keyLength = 32) { | ||
if (!has32Bytes(seed)) | ||
throw new Error('invalid seed'); | ||
(0, utils_js_1.assertBytes)(seed, 32); | ||
// Note that length here also repeats two lines below | ||
@@ -102,4 +98,3 @@ // We do an additional length check here to reduce the scope of DoS attacks | ||
function derive(protocol, accountId = 0) { | ||
if (!has32Bytes(seed)) | ||
throw new Error('invalid seed'); | ||
(0, utils_js_1.assertBytes)(seed, 32); | ||
return deriveChildKey(seed, protocol, accountId); | ||
@@ -106,0 +101,0 @@ } |
@@ -5,3 +5,3 @@ import { hkdf } from './hkdf.js'; | ||
import { scrypt as _scrypt } from './scrypt.js'; | ||
import { createView, toBytes } from './utils.js'; | ||
import { assertBytes, createView, toBytes } from './utils.js'; | ||
// A tiny KDF for various applications like AES key-gen | ||
@@ -17,5 +17,2 @@ // | ||
const PROTOCOLS_ALLOWING_STR = ['ssh', 'tor', 'file']; | ||
function has32Bytes(a) { | ||
return a instanceof Uint8Array && a.length === 32; | ||
} | ||
function strHasLength(str, min, max) { | ||
@@ -34,4 +31,4 @@ return typeof str === 'string' && str.length >= min && str.length <= max; | ||
function xor32(a, b) { | ||
if (!has32Bytes(a) || !has32Bytes(b)) | ||
throw new Error('invalid xor32 call'); | ||
assertBytes(a, 32); | ||
assertBytes(b, 32); | ||
const arr = new Uint8Array(32); | ||
@@ -61,4 +58,3 @@ for (let i = 0; i < 32; i++) { | ||
export function deriveChildKey(seed, protocol, accountId = 0, keyLength = 32) { | ||
if (!has32Bytes(seed)) | ||
throw new Error('invalid seed'); | ||
assertBytes(seed, 32); | ||
// Note that length here also repeats two lines below | ||
@@ -96,4 +92,3 @@ // We do an additional length check here to reduce the scope of DoS attacks | ||
function derive(protocol, accountId = 0) { | ||
if (!has32Bytes(seed)) | ||
throw new Error('invalid seed'); | ||
assertBytes(seed, 32); | ||
return deriveChildKey(seed, protocol, accountId); | ||
@@ -100,0 +95,0 @@ } |
@@ -73,3 +73,3 @@ /*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */ | ||
(!lengths.length || lengths.includes(bytes.length))) { | ||
return; | ||
return true; | ||
} | ||
@@ -76,0 +76,0 @@ throw new TypeError(`Expected ${lengths} bytes, not ${typeof bytes} with length=${bytes.length}`); |
{ | ||
"name": "@noble/hashes", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Fast 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -15,3 +15,3 @@ /*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */ | ||
export declare function assertBool(b: boolean): void; | ||
export declare function assertBytes(bytes: Uint8Array, ...lengths: number[]): void; | ||
export declare function assertBytes(bytes: any, ...lengths: number[]): bytes is Uint8Array; | ||
export declare function assertHash(hash: CHash): void; | ||
@@ -18,0 +18,0 @@ export declare abstract class Hash<T extends Hash<T>> { |
@@ -85,3 +85,3 @@ "use strict"; | ||
(!lengths.length || lengths.includes(bytes.length))) { | ||
return; | ||
return true; | ||
} | ||
@@ -88,0 +88,0 @@ throw new TypeError(`Expected ${lengths} bytes, not ${typeof bytes} with length=${bytes.length}`); |
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
256344
5675