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 1.3.1 to 1.3.2

13

_assert.d.ts

@@ -1,4 +0,4 @@

export declare function number(n: number): void;
export declare function bool(b: boolean): void;
export declare function bytes(b: Uint8Array | undefined, ...lengths: number[]): void;
declare function number(n: number): void;
declare function bool(b: boolean): void;
declare function bytes(b: Uint8Array | undefined, ...lengths: number[]): void;
type Hash = {

@@ -10,5 +10,6 @@ (data: Uint8Array): Uint8Array;

};
export declare function hash(hash: Hash): void;
export declare function exists(instance: any, checkFinished?: boolean): void;
export declare function output(out: any, instance: any): void;
declare function hash(hash: Hash): void;
declare function exists(instance: any, checkFinished?: boolean): void;
declare function output(out: any, instance: any): void;
export { number, bool, bytes, hash, exists, output };
declare const assert: {

@@ -15,0 +16,0 @@ number: typeof number;

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

exports.output = output;
const assert = {
number,
bool,
bytes,
hash,
exists,
output,
};
const assert = { number, bool, bytes, hash, exists, output };
exports.default = assert;
//# sourceMappingURL=_assert.js.map

@@ -6,2 +6,3 @@ "use strict";

const utils_js_1 = require("./utils.js");
// Blake is based on ChaCha permutation.
// For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].

@@ -32,5 +33,5 @@ // prettier-ignore

this.destroyed = false;
_assert_js_1.default.number(blockLen);
_assert_js_1.default.number(outputLen);
_assert_js_1.default.number(keyLen);
(0, _assert_js_1.number)(blockLen);
(0, _assert_js_1.number)(outputLen);
(0, _assert_js_1.number)(keyLen);
if (outputLen < 0 || outputLen > keyLen)

@@ -47,3 +48,3 @@ throw new Error('outputLen bigger than keyLen');

update(data) {
_assert_js_1.default.exists(this);
(0, _assert_js_1.exists)(this);
// Main difference with other hashes: there is flag for last block,

@@ -83,4 +84,4 @@ // so we cannot process current block before we know that there

digestInto(out) {
_assert_js_1.default.exists(this);
_assert_js_1.default.output(out, this);
(0, _assert_js_1.exists)(this);
(0, _assert_js_1.output)(out, this);
const { pos, buffer32 } = this;

@@ -87,0 +88,0 @@ this.finished = true;

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

update(data) {
_assert_js_1.default.exists(this);
(0, _assert_js_1.exists)(this);
const { view, buffer, blockLen } = this;

@@ -62,4 +62,4 @@ data = (0, utils_js_1.toBytes)(data);

digestInto(out) {
_assert_js_1.default.exists(this);
_assert_js_1.default.output(out, this);
(0, _assert_js_1.exists)(this);
(0, _assert_js_1.output)(out, this);
this.finished = true;

@@ -66,0 +66,0 @@ // Padding

@@ -1,11 +0,30 @@

export declare function fromBig(n: bigint, le?: boolean): {
declare function fromBig(n: bigint, le?: boolean): {
h: number;
l: number;
};
export declare function split(lst: bigint[], le?: boolean): Uint32Array[];
export declare const toBig: (h: number, l: number) => bigint;
export declare function add(Ah: number, Al: number, Bh: number, Bl: number): {
declare function split(lst: bigint[], le?: boolean): Uint32Array[];
declare const toBig: (h: number, l: number) => bigint;
declare const shrSH: (h: number, _l: number, s: number) => number;
declare const shrSL: (h: number, l: number, s: number) => number;
declare const rotrSH: (h: number, l: number, s: number) => number;
declare const rotrSL: (h: number, l: number, s: number) => number;
declare const rotrBH: (h: number, l: number, s: number) => number;
declare const rotrBL: (h: number, l: number, s: number) => number;
declare const rotr32H: (_h: number, l: number) => number;
declare const rotr32L: (h: number, _l: number) => number;
declare const rotlSH: (h: number, l: number, s: number) => number;
declare const rotlSL: (h: number, l: number, s: number) => number;
declare const rotlBH: (h: number, l: number, s: number) => number;
declare const rotlBL: (h: number, l: number, s: number) => number;
declare function add(Ah: number, Al: number, Bh: number, Bl: number): {
h: number;
l: number;
};
declare const add3L: (Al: number, Bl: number, Cl: number) => number;
declare const add3H: (low: number, Ah: number, Bh: number, Ch: number) => number;
declare const add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number;
declare const add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number;
declare const add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number;
declare const add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number;
export { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, };
declare const u64: {

@@ -15,3 +34,3 @@ fromBig: typeof fromBig;

toBig: (h: number, l: number) => bigint;
shrSH: (h: number, l: number, s: number) => number;
shrSH: (h: number, _l: number, s: number) => number;
shrSL: (h: number, l: number, s: number) => number;

@@ -22,4 +41,4 @@ rotrSH: (h: number, l: number, s: number) => number;

rotrBL: (h: number, l: number, s: number) => number;
rotr32H: (h: number, l: number) => number;
rotr32L: (h: number, l: number) => number;
rotr32H: (_h: number, l: number) => number;
rotr32L: (h: number, _l: number) => number;
rotlSH: (h: number, l: number, s: number) => number;

@@ -26,0 +45,0 @@ rotlSL: (h: number, l: number, s: number) => number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.add = exports.toBig = exports.split = exports.fromBig = void 0;
const U32_MASK64 = BigInt(2 ** 32 - 1);
const _32n = BigInt(32);
exports.add5L = exports.add5H = exports.add4H = exports.add4L = exports.add3H = exports.add3L = exports.add = exports.rotlBL = exports.rotlBH = exports.rotlSL = exports.rotlSH = exports.rotr32L = exports.rotr32H = exports.rotrBL = exports.rotrBH = exports.rotrSL = exports.rotrSH = exports.shrSL = exports.shrSH = exports.toBig = exports.split = exports.fromBig = void 0;
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
const _32n = /* @__PURE__ */ BigInt(32);
// We are not using BigUint64Array, because they are extremely slow as per 2022

@@ -26,22 +26,33 @@ function fromBig(n, le = false) {

// for Shift in [0, 32)
const shrSH = (h, l, s) => h >>> s;
const shrSH = (h, _l, s) => h >>> s;
exports.shrSH = shrSH;
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
exports.shrSL = shrSL;
// Right rotate for Shift in [1, 32)
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
exports.rotrSH = rotrSH;
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
exports.rotrSL = rotrSL;
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
exports.rotrBH = rotrBH;
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
exports.rotrBL = rotrBL;
// Right rotate for shift===32 (just swaps l&h)
const rotr32H = (h, l) => l;
const rotr32L = (h, l) => h;
const rotr32H = (_h, l) => l;
exports.rotr32H = rotr32H;
const rotr32L = (h, _l) => h;
exports.rotr32L = rotr32L;
// Left rotate for Shift in [1, 32)
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
exports.rotlSH = rotlSH;
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
exports.rotlSL = rotlSL;
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
exports.rotlBH = rotlBH;
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
exports.rotlBL = rotlBL;
// JS uses 32-bit signed integers for bitwise operations which means we cannot
// simple take carry out of low bit sum by shift, we need to use division.
// Removing "export" has 5% perf penalty -_-
function add(Ah, Al, Bh, Bl) {

@@ -54,10 +65,16 @@ const l = (Al >>> 0) + (Bl >>> 0);

const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
exports.add3L = add3L;
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
exports.add3H = add3H;
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
exports.add4L = add4L;
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
exports.add4H = add4H;
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
exports.add5L = add5L;
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
exports.add5H = add5H;
// prettier-ignore
const u64 = {
fromBig, split, toBig: exports.toBig,
fromBig, split, toBig,
shrSH, shrSL,

@@ -64,0 +81,0 @@ rotrSH, rotrSL, rotrBH, rotrBL,

@@ -8,9 +8,2 @@ "use strict";

const _u64_js_1 = require("./_u64.js");
// Experimental Argon2 RFC 9106 implementation. It may be removed at any time.
var Types;
(function (Types) {
Types[Types["Argond2d"] = 0] = "Argond2d";
Types[Types["Argon2i"] = 1] = "Argon2i";
Types[Types["Argon2id"] = 2] = "Argon2id";
})(Types || (Types = {}));
const ARGON2_SYNC_POINTS = 4;

@@ -43,4 +36,4 @@ const toBytesOptional = (buf) => (buf !== undefined ? (0, utils_js_1.toBytes)(buf) : new Uint8Array([]));

// A + B + (2 * A * B)
const Rll = _u64_js_1.default.add3L(Al, Bl, Cl);
return { h: _u64_js_1.default.add3H(Rll, Ah, Bh, Ch), l: Rll | 0 };
const Rll = (0, _u64_js_1.add3L)(Al, Bl, Cl);
return { h: (0, _u64_js_1.add3H)(Rll, Ah, Bh, Ch), l: Rll | 0 };
}

@@ -56,12 +49,12 @@ // Temporary block buffer

({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: _u64_js_1.default.rotr32H(Dh, Dl), Dl: _u64_js_1.default.rotr32L(Dh, Dl) });
({ Dh, Dl } = { Dh: (0, _u64_js_1.rotr32H)(Dh, Dl), Dl: (0, _u64_js_1.rotr32L)(Dh, Dl) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: _u64_js_1.default.rotrSH(Bh, Bl, 24), Bl: _u64_js_1.default.rotrSL(Bh, Bl, 24) });
({ Bh, Bl } = { Bh: (0, _u64_js_1.rotrSH)(Bh, Bl, 24), Bl: (0, _u64_js_1.rotrSL)(Bh, Bl, 24) });
({ h: Ah, l: Al } = blamka(Ah, Al, Bh, Bl));
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: _u64_js_1.default.rotrSH(Dh, Dl, 16), Dl: _u64_js_1.default.rotrSL(Dh, Dl, 16) });
({ Dh, Dl } = { Dh: (0, _u64_js_1.rotrSH)(Dh, Dl, 16), Dl: (0, _u64_js_1.rotrSL)(Dh, Dl, 16) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: _u64_js_1.default.rotrBH(Bh, Bl, 63), Bl: _u64_js_1.default.rotrBL(Bh, Bl, 63) });
({ Bh, Bl } = { Bh: (0, _u64_js_1.rotrBH)(Bh, Bl, 63), Bl: (0, _u64_js_1.rotrBL)(Bh, Bl, 63) });
(BUF[2 * a] = Al), (BUF[2 * a + 1] = Ah);

@@ -155,12 +148,12 @@ (BUF[2 * b] = Bl), (BUF[2 * b + 1] = Bh);

// Validation
_assert_js_1.default.number(p);
_assert_js_1.default.number(dkLen);
_assert_js_1.default.number(m);
_assert_js_1.default.number(t);
_assert_js_1.default.number(version);
(0, _assert_js_1.number)(p);
(0, _assert_js_1.number)(dkLen);
(0, _assert_js_1.number)(m);
(0, _assert_js_1.number)(t);
(0, _assert_js_1.number)(version);
if (dkLen < 4 || dkLen >= 2 ** 32)
throw new Error('Argon2: dkLen should be at least 4 bytes');
if (dkLen < 1 || p >= 2 ** 32)
throw new Error('Argon2: p (paralllelism) should be at least 1');
if (dkLen < 1 || p >= 2 ** 32)
if (p < 1 || p >= 2 ** 32)
throw new Error('Argon2: p (parallelism) should be at least 1');
if (t < 1 || t >= 2 ** 32)
throw new Error('Argon2: t (iterations) should be at least 1');

@@ -282,3 +275,3 @@ if (m < 8 * p)

address[256 + 4] = s;
const dataIndependent = type == Types.Argon2i || (type == Types.Argon2id && r === 0 && s < 2);
const dataIndependent = type == 1 /* Types.Argon2i */ || (type == 2 /* Types.Argon2id */ && r === 0 && s < 2);
for (let l = 0; l < p; l++) {

@@ -309,8 +302,8 @@ address[256 + 2] = l;

}
const argon2d = (password, salt, opts) => argon2(Types.Argond2d, password, salt, opts);
const argon2d = (password, salt, opts) => argon2(0 /* Types.Argond2d */, password, salt, opts);
exports.argon2d = argon2d;
const argon2i = (password, salt, opts) => argon2(Types.Argon2i, password, salt, opts);
const argon2i = (password, salt, opts) => argon2(1 /* Types.Argon2i */, password, salt, opts);
exports.argon2i = argon2i;
const argon2id = (password, salt, opts) => argon2(Types.Argon2id, password, salt, opts);
const argon2id = (password, salt, opts) => argon2(2 /* Types.Argon2id */, password, salt, opts);
exports.argon2id = argon2id;
//# sourceMappingURL=argon2.js.map

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

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */ new Uint32Array([
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,

@@ -15,3 +15,3 @@ 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19

// Temporary buffer
const BUF = new Uint32Array(32);
const BUF = /* @__PURE__ */ new Uint32Array(32);
// Mixing function G splitted in two halfs

@@ -18,0 +18,0 @@ function G1(a, b, c, d, msg, x) {

@@ -11,5 +11,3 @@ "use strict";

// prettier-ignore
exports.IV = new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
]);
exports.IV = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
// Mixing function G splitted in two halfs

@@ -101,3 +99,3 @@ function G1(a, b, c, d, x) {

compress(msg, offset, isLast) {
const { h, l } = _u64_js_1.default.fromBig(BigInt(this.length));
const { h, l } = (0, _u64_js_1.fromBig)(BigInt(this.length));
// prettier-ignore

@@ -104,0 +102,0 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(_blake2_js_1.SIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, exports.IV[0], exports.IV[1], exports.IV[2], exports.IV[3], l ^ exports.IV[4], h ^ exports.IV[5], isLast ? ~exports.IV[6] : exports.IV[6], exports.IV[7]);

@@ -9,14 +9,3 @@ "use strict";

const utils_js_1 = require("./utils.js");
// Flag bitset
var Flags;
(function (Flags) {
Flags[Flags["CHUNK_START"] = 1] = "CHUNK_START";
Flags[Flags["CHUNK_END"] = 2] = "CHUNK_END";
Flags[Flags["PARENT"] = 4] = "PARENT";
Flags[Flags["ROOT"] = 8] = "ROOT";
Flags[Flags["KEYED_HASH"] = 16] = "KEYED_HASH";
Flags[Flags["DERIVE_KEY_CONTEXT"] = 32] = "DERIVE_KEY_CONTEXT";
Flags[Flags["DERIVE_KEY_MATERIAL"] = 64] = "DERIVE_KEY_MATERIAL";
})(Flags || (Flags = {}));
const SIGMA = (() => {
const SIGMA = /* @__PURE__ */ (() => {
const Id = Array.from({ length: 16 }, (_, i) => i);

@@ -50,3 +39,3 @@ const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);

this.outputLen = opts.dkLen === undefined ? 32 : opts.dkLen;
_assert_js_1.default.number(this.outputLen);
(0, _assert_js_1.number)(this.outputLen);
if (opts.key !== undefined && opts.context !== undefined)

@@ -59,10 +48,10 @@ throw new Error('Blake3: only key or context can be specified at same time');

this.IV = (0, utils_js_1.u32)(key);
this.flags = flags | Flags.KEYED_HASH;
this.flags = flags | 16 /* Flags.KEYED_HASH */;
}
else if (opts.context !== undefined) {
const context_key = new BLAKE3({ dkLen: 32 }, Flags.DERIVE_KEY_CONTEXT)
const context_key = new BLAKE3({ dkLen: 32 }, 32 /* Flags.DERIVE_KEY_CONTEXT */)
.update(opts.context)
.digest();
this.IV = (0, utils_js_1.u32)(context_key);
this.flags = flags | Flags.DERIVE_KEY_MATERIAL;
this.flags = flags | 64 /* Flags.DERIVE_KEY_MATERIAL */;
}

@@ -83,3 +72,3 @@ else {

const { state: s, pos } = this;
const { h, l } = _u64_js_1.default.fromBig(BigInt(counter), true);
const { h, l } = (0, _u64_js_1.fromBig)(BigInt(counter), true);
// prettier-ignore

@@ -100,5 +89,5 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = (0, blake2s_js_1.compress)(SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], blake2s_js_1.IV[0], blake2s_js_1.IV[1], blake2s_js_1.IV[2], blake2s_js_1.IV[3], h, l, pos, flags);

if (!this.chunkPos)
flags |= Flags.CHUNK_START;
flags |= 1 /* Flags.CHUNK_START */;
if (this.chunkPos === 15 || isLast)
flags |= Flags.CHUNK_END;
flags |= 2 /* Flags.CHUNK_END */;
if (!isLast)

@@ -124,3 +113,3 @@ this.pos = this.blockLen;

this.pos = this.blockLen;
this.b2Compress(0, this.flags | Flags.PARENT, this.buffer32, 0);
this.b2Compress(0, this.flags | 4 /* Flags.PARENT */, this.buffer32, 0);
chunk = this.state;

@@ -162,3 +151,3 @@ this.state = this.IV.slice();

const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
const { h, l } = _u64_js_1.default.fromBig(BigInt(this.chunkOut++));
const { h, l } = (0, _u64_js_1.fromBig)(BigInt(this.chunkOut++));
// prettier-ignore

@@ -191,5 +180,5 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = (0, blake2s_js_1.compress)(SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], blake2s_js_1.IV[0], blake2s_js_1.IV[1], blake2s_js_1.IV[2], blake2s_js_1.IV[3], l, h, pos, flags);

// Process last chunk
let flags = this.flags | Flags.ROOT;
let flags = this.flags | 8 /* Flags.ROOT */;
if (this.stack.length) {
flags |= Flags.PARENT;
flags |= 4 /* Flags.PARENT */;
this.compress(this.buffer32, 0, true);

@@ -200,3 +189,3 @@ this.chunksDone = 0;

else {
flags |= (!this.chunkPos ? Flags.CHUNK_START : 0) | Flags.CHUNK_END;
flags |= (!this.chunkPos ? 1 /* Flags.CHUNK_START */ : 0) | 2 /* Flags.CHUNK_END */;
}

@@ -207,4 +196,4 @@ this.flags = flags;

writeInto(out) {
_assert_js_1.default.exists(this, false);
_assert_js_1.default.bytes(out);
(0, _assert_js_1.exists)(this, false);
(0, _assert_js_1.bytes)(out);
this.finish();

@@ -228,7 +217,7 @@ const { blockLen, bufferOut } = this;

xof(bytes) {
_assert_js_1.default.number(bytes);
(0, _assert_js_1.number)(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out) {
_assert_js_1.default.output(out, this);
(0, _assert_js_1.output)(out, this);
if (this.finished)

@@ -235,0 +224,0 @@ throw new Error('digest() was already called');

@@ -1,10 +0,10 @@

export function number(n) {
function number(n) {
if (!Number.isSafeInteger(n) || n < 0)
throw new Error(`Wrong positive integer: ${n}`);
}
export function bool(b) {
function bool(b) {
if (typeof b !== 'boolean')
throw new Error(`Expected boolean, not ${b}`);
}
export function bytes(b, ...lengths) {
function bytes(b, ...lengths) {
if (!(b instanceof Uint8Array))

@@ -15,3 +15,3 @@ throw new Error('Expected Uint8Array');

}
export function hash(hash) {
function hash(hash) {
if (typeof hash !== 'function' || typeof hash.create !== 'function')

@@ -22,3 +22,3 @@ throw new Error('Hash should be wrapped by utils.wrapConstructor');

}
export function exists(instance, checkFinished = true) {
function exists(instance, checkFinished = true) {
if (instance.destroyed)

@@ -29,3 +29,3 @@ throw new Error('Hash instance has been destroyed');

}
export function output(out, instance) {
function output(out, instance) {
bytes(out);

@@ -37,11 +37,5 @@ const min = instance.outputLen;

}
const assert = {
number,
bool,
bytes,
hash,
exists,
output,
};
export { number, bool, bytes, hash, exists, output };
const assert = { number, bool, bytes, hash, exists, output };
export default assert;
//# sourceMappingURL=_assert.js.map

@@ -1,6 +0,7 @@

import assert from './_assert.js';
import { number, exists, output } from './_assert.js';
import { Hash, toBytes, u32 } from './utils.js';
// Blake is based on ChaCha permutation.
// For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
// prettier-ignore
export const SIGMA = new Uint8Array([
export const SIGMA = /* @__PURE__ */ new Uint8Array([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

@@ -28,5 +29,5 @@ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,

this.destroyed = false;
assert.number(blockLen);
assert.number(outputLen);
assert.number(keyLen);
number(blockLen);
number(outputLen);
number(keyLen);
if (outputLen < 0 || outputLen > keyLen)

@@ -43,3 +44,3 @@ throw new Error('outputLen bigger than keyLen');

update(data) {
assert.exists(this);
exists(this);
// Main difference with other hashes: there is flag for last block,

@@ -79,4 +80,4 @@ // so we cannot process current block before we know that there

digestInto(out) {
assert.exists(this);
assert.output(out, this);
exists(this);
output(out, this);
const { pos, buffer32 } = this;

@@ -83,0 +84,0 @@ this.finished = true;

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { exists, output } from './_assert.js';
import { Hash, createView, toBytes } from './utils.js';

@@ -32,3 +32,3 @@ // Polyfill for Safari 14

update(data) {
assert.exists(this);
exists(this);
const { view, buffer, blockLen } = this;

@@ -59,4 +59,4 @@ data = toBytes(data);

digestInto(out) {
assert.exists(this);
assert.output(out, this);
exists(this);
output(out, this);
this.finished = true;

@@ -63,0 +63,0 @@ // Padding

@@ -1,5 +0,5 @@

const U32_MASK64 = BigInt(2 ** 32 - 1);
const _32n = BigInt(32);
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
const _32n = /* @__PURE__ */ BigInt(32);
// We are not using BigUint64Array, because they are extremely slow as per 2022
export function fromBig(n, le = false) {
function fromBig(n, le = false) {
if (le)

@@ -9,3 +9,3 @@ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };

}
export function split(lst, le = false) {
function split(lst, le = false) {
let Ah = new Uint32Array(lst.length);

@@ -19,5 +19,5 @@ let Al = new Uint32Array(lst.length);

}
export const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
// for Shift in [0, 32)
const shrSH = (h, l, s) => h >>> s;
const shrSH = (h, _l, s) => h >>> s;
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);

@@ -31,4 +31,4 @@ // Right rotate for Shift in [1, 32)

// Right rotate for shift===32 (just swaps l&h)
const rotr32H = (h, l) => l;
const rotr32L = (h, l) => h;
const rotr32H = (_h, l) => l;
const rotr32L = (h, _l) => h;
// Left rotate for Shift in [1, 32)

@@ -42,4 +42,3 @@ const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));

// simple take carry out of low bit sum by shift, we need to use division.
// Removing "export" has 5% perf penalty -_-
export function add(Ah, Al, Bh, Bl) {
function add(Ah, Al, Bh, Bl) {
const l = (Al >>> 0) + (Bl >>> 0);

@@ -56,2 +55,4 @@ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };

// prettier-ignore
export { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, };
// prettier-ignore
const u64 = {

@@ -58,0 +59,0 @@ fromBig, split, toBig,

@@ -1,12 +0,5 @@

import assert from './_assert.js';
import { number as assertNumber } from './_assert.js';
import { toBytes, u8, u32 } from './utils.js';
import { blake2b } from './blake2b.js';
import u64 from './_u64.js';
// Experimental Argon2 RFC 9106 implementation. It may be removed at any time.
var Types;
(function (Types) {
Types[Types["Argond2d"] = 0] = "Argond2d";
Types[Types["Argon2i"] = 1] = "Argon2i";
Types[Types["Argon2id"] = 2] = "Argon2id";
})(Types || (Types = {}));
import { add3H, add3L, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL } from './_u64.js';
const ARGON2_SYNC_POINTS = 4;

@@ -39,4 +32,4 @@ const toBytesOptional = (buf) => (buf !== undefined ? toBytes(buf) : new Uint8Array([]));

// A + B + (2 * A * B)
const Rll = u64.add3L(Al, Bl, Cl);
return { h: u64.add3H(Rll, Ah, Bh, Ch), l: Rll | 0 };
const Rll = add3L(Al, Bl, Cl);
return { h: add3H(Rll, Ah, Bh, Ch), l: Rll | 0 };
}

@@ -52,12 +45,12 @@ // Temporary block buffer

({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: u64.rotr32H(Dh, Dl), Dl: u64.rotr32L(Dh, Dl) });
({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh, Dl) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 24), Bl: u64.rotrSL(Bh, Bl, 24) });
({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
({ h: Ah, l: Al } = blamka(Ah, Al, Bh, Bl));
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: u64.rotrSH(Dh, Dl, 16), Dl: u64.rotrSL(Dh, Dl, 16) });
({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: u64.rotrBH(Bh, Bl, 63), Bl: u64.rotrBL(Bh, Bl, 63) });
({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });
(BUF[2 * a] = Al), (BUF[2 * a + 1] = Ah);

@@ -151,12 +144,12 @@ (BUF[2 * b] = Bl), (BUF[2 * b + 1] = Bh);

// Validation
assert.number(p);
assert.number(dkLen);
assert.number(m);
assert.number(t);
assert.number(version);
assertNumber(p);
assertNumber(dkLen);
assertNumber(m);
assertNumber(t);
assertNumber(version);
if (dkLen < 4 || dkLen >= 2 ** 32)
throw new Error('Argon2: dkLen should be at least 4 bytes');
if (dkLen < 1 || p >= 2 ** 32)
throw new Error('Argon2: p (paralllelism) should be at least 1');
if (dkLen < 1 || p >= 2 ** 32)
if (p < 1 || p >= 2 ** 32)
throw new Error('Argon2: p (parallelism) should be at least 1');
if (t < 1 || t >= 2 ** 32)
throw new Error('Argon2: t (iterations) should be at least 1');

@@ -278,3 +271,3 @@ if (m < 8 * p)

address[256 + 4] = s;
const dataIndependent = type == Types.Argon2i || (type == Types.Argon2id && r === 0 && s < 2);
const dataIndependent = type == 1 /* Types.Argon2i */ || (type == 2 /* Types.Argon2id */ && r === 0 && s < 2);
for (let l = 0; l < p; l++) {

@@ -305,5 +298,5 @@ address[256 + 2] = l;

}
export const argon2d = (password, salt, opts) => argon2(Types.Argond2d, password, salt, opts);
export const argon2i = (password, salt, opts) => argon2(Types.Argon2i, password, salt, opts);
export const argon2id = (password, salt, opts) => argon2(Types.Argon2id, password, salt, opts);
export const argon2d = (password, salt, opts) => argon2(0 /* Types.Argond2d */, password, salt, opts);
export const argon2i = (password, salt, opts) => argon2(1 /* Types.Argon2i */, password, salt, opts);
export const argon2id = (password, salt, opts) => argon2(2 /* Types.Argon2id */, password, salt, opts);
//# sourceMappingURL=argon2.js.map

@@ -6,3 +6,3 @@ import { BLAKE2, SIGMA } from './_blake2.js';

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */ new Uint32Array([
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,

@@ -12,3 +12,3 @@ 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19

// Temporary buffer
const BUF = new Uint32Array(32);
const BUF = /* @__PURE__ */ new Uint32Array(32);
// Mixing function G splitted in two halfs

@@ -190,3 +190,3 @@ function G1(a, b, c, d, msg, x) {

*/
export const blake2b = wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
export const blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
//# sourceMappingURL=blake2b.js.map
import { BLAKE2, SIGMA } from './_blake2.js';
import u64 from './_u64.js';
import { fromBig } from './_u64.js';
import { rotr, toBytes, wrapConstructorWithOpts, u32 } from './utils.js';

@@ -8,5 +8,3 @@ // Initial state:

// prettier-ignore
export const IV = new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
]);
export const IV = /* @__PURE__ */ new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
// Mixing function G splitted in two halfs

@@ -97,3 +95,3 @@ function G1(a, b, c, d, x) {

compress(msg, offset, isLast) {
const { h, l } = u64.fromBig(BigInt(this.length));
const { h, l } = fromBig(BigInt(this.length));
// prettier-ignore

@@ -121,3 +119,3 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(SIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, IV[0], IV[1], IV[2], IV[3], l ^ IV[4], h ^ IV[5], isLast ? ~IV[6] : IV[6], IV[7]);

*/
export const blake2s = wrapConstructorWithOpts((opts) => new BLAKE2s(opts));
export const blake2s = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2s(opts));
//# sourceMappingURL=blake2s.js.map

@@ -1,18 +0,7 @@

import assert from './_assert.js';
import u64 from './_u64.js';
import { bytes, exists, number, output } from './_assert.js';
import { fromBig } from './_u64.js';
import { BLAKE2 } from './_blake2.js';
import { compress, IV } from './blake2s.js';
import { u8, u32, toBytes, wrapXOFConstructorWithOpts } from './utils.js';
// Flag bitset
var Flags;
(function (Flags) {
Flags[Flags["CHUNK_START"] = 1] = "CHUNK_START";
Flags[Flags["CHUNK_END"] = 2] = "CHUNK_END";
Flags[Flags["PARENT"] = 4] = "PARENT";
Flags[Flags["ROOT"] = 8] = "ROOT";
Flags[Flags["KEYED_HASH"] = 16] = "KEYED_HASH";
Flags[Flags["DERIVE_KEY_CONTEXT"] = 32] = "DERIVE_KEY_CONTEXT";
Flags[Flags["DERIVE_KEY_MATERIAL"] = 64] = "DERIVE_KEY_MATERIAL";
})(Flags || (Flags = {}));
const SIGMA = (() => {
const SIGMA = /* @__PURE__ */ (() => {
const Id = Array.from({ length: 16 }, (_, i) => i);

@@ -46,3 +35,3 @@ const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);

this.outputLen = opts.dkLen === undefined ? 32 : opts.dkLen;
assert.number(this.outputLen);
number(this.outputLen);
if (opts.key !== undefined && opts.context !== undefined)

@@ -55,10 +44,10 @@ throw new Error('Blake3: only key or context can be specified at same time');

this.IV = u32(key);
this.flags = flags | Flags.KEYED_HASH;
this.flags = flags | 16 /* Flags.KEYED_HASH */;
}
else if (opts.context !== undefined) {
const context_key = new BLAKE3({ dkLen: 32 }, Flags.DERIVE_KEY_CONTEXT)
const context_key = new BLAKE3({ dkLen: 32 }, 32 /* Flags.DERIVE_KEY_CONTEXT */)
.update(opts.context)
.digest();
this.IV = u32(context_key);
this.flags = flags | Flags.DERIVE_KEY_MATERIAL;
this.flags = flags | 64 /* Flags.DERIVE_KEY_MATERIAL */;
}

@@ -79,3 +68,3 @@ else {

const { state: s, pos } = this;
const { h, l } = u64.fromBig(BigInt(counter), true);
const { h, l } = fromBig(BigInt(counter), true);
// prettier-ignore

@@ -96,5 +85,5 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], IV[0], IV[1], IV[2], IV[3], h, l, pos, flags);

if (!this.chunkPos)
flags |= Flags.CHUNK_START;
flags |= 1 /* Flags.CHUNK_START */;
if (this.chunkPos === 15 || isLast)
flags |= Flags.CHUNK_END;
flags |= 2 /* Flags.CHUNK_END */;
if (!isLast)

@@ -120,3 +109,3 @@ this.pos = this.blockLen;

this.pos = this.blockLen;
this.b2Compress(0, this.flags | Flags.PARENT, this.buffer32, 0);
this.b2Compress(0, this.flags | 4 /* Flags.PARENT */, this.buffer32, 0);
chunk = this.state;

@@ -158,3 +147,3 @@ this.state = this.IV.slice();

const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
const { h, l } = u64.fromBig(BigInt(this.chunkOut++));
const { h, l } = fromBig(BigInt(this.chunkOut++));
// prettier-ignore

@@ -187,5 +176,5 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], IV[0], IV[1], IV[2], IV[3], l, h, pos, flags);

// Process last chunk
let flags = this.flags | Flags.ROOT;
let flags = this.flags | 8 /* Flags.ROOT */;
if (this.stack.length) {
flags |= Flags.PARENT;
flags |= 4 /* Flags.PARENT */;
this.compress(this.buffer32, 0, true);

@@ -196,3 +185,3 @@ this.chunksDone = 0;

else {
flags |= (!this.chunkPos ? Flags.CHUNK_START : 0) | Flags.CHUNK_END;
flags |= (!this.chunkPos ? 1 /* Flags.CHUNK_START */ : 0) | 2 /* Flags.CHUNK_END */;
}

@@ -203,4 +192,4 @@ this.flags = flags;

writeInto(out) {
assert.exists(this, false);
assert.bytes(out);
exists(this, false);
bytes(out);
this.finish();

@@ -224,7 +213,7 @@ const { blockLen, bufferOut } = this;

xof(bytes) {
assert.number(bytes);
number(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out) {
assert.output(out, this);
output(out, this);
if (this.finished)

@@ -246,3 +235,3 @@ throw new Error('digest() was already called');

*/
export const blake3 = wrapXOFConstructorWithOpts((opts) => new BLAKE3(opts));
export const blake3 = /* @__PURE__ */ wrapXOFConstructorWithOpts((opts) => new BLAKE3(opts));
//# sourceMappingURL=blake3.js.map

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, number as assertNumber } from './_assert.js';
import { toBytes } from './utils.js';

@@ -15,3 +15,3 @@ import { hmac } from './hmac.js';

export function extract(hash, ikm, salt) {
assert.hash(hash);
assertHash(hash);
// NOTE: some libraries treat zero-length array as 'not provided';

@@ -25,4 +25,4 @@ // we don't, since we have undefined as 'not provided'

// HKDF-Expand(PRK, info, L) -> OKM
const HKDF_COUNTER = new Uint8Array([0]);
const EMPTY_BUFFER = new Uint8Array();
const HKDF_COUNTER = /* @__PURE__ */ new Uint8Array([0]);
const EMPTY_BUFFER = /* @__PURE__ */ new Uint8Array();
/**

@@ -35,4 +35,4 @@ * HKDF-expand from the spec.

export function expand(hash, prk, info, length = 32) {
assert.hash(hash);
assert.number(length);
assertHash(hash);
assertNumber(length);
if (length > 255 * hash.outputLen)

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

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, bytes as assertBytes, exists as assertExists } from './_assert.js';
import { Hash, toBytes } from './utils.js';

@@ -9,3 +9,3 @@ // HMAC (RFC 2104)

this.destroyed = false;
assert.hash(hash);
assertHash(hash);
const key = toBytes(_key);

@@ -33,3 +33,3 @@ this.iHash = hash.create();

update(buf) {
assert.exists(this);
assertExists(this);
this.iHash.update(buf);

@@ -39,4 +39,4 @@ return this;

digestInto(out) {
assert.exists(this);
assert.bytes(out, this.outputLen);
assertExists(this);
assertBytes(out, this.outputLen);
this.finished = true;

@@ -43,0 +43,0 @@ this.iHash.digestInto(out);

{
"type": "module",
"sideEffects": false,
"browser": {

@@ -4,0 +5,0 @@ "node:crypto": false

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, number as assertNumber } from './_assert.js';
import { hmac } from './hmac.js';

@@ -6,8 +6,8 @@ import { createView, toBytes, checkOpts, asyncLoop } from './utils.js';

function pbkdf2Init(hash, _password, _salt, _opts) {
assert.hash(hash);
assertHash(hash);
const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
const { c, dkLen, asyncTick } = opts;
assert.number(c);
assert.number(dkLen);
assert.number(asyncTick);
assertNumber(c);
assertNumber(dkLen);
assertNumber(asyncTick);
if (c < 1)

@@ -78,3 +78,3 @@ throw new Error('PBKDF2: iterations (c) should be >= 1');

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

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

@@ -5,5 +5,5 @@ import { SHA2 } from './_sha2.js';

// https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
const Rho = new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = Id.map((i) => (9 * i + 5) % 16);
const Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = /* @__PURE__ */ Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = /* @__PURE__ */ Id.map((i) => (9 * i + 5) % 16);
let idxL = [Id];

@@ -14,3 +14,3 @@ let idxR = [Pi];

j.push(j[i].map((k) => Rho[k]));
const shifts = [
const shifts = /* @__PURE__ */ [
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],

@@ -22,6 +22,10 @@ [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],

].map((i) => new Uint8Array(i));
const shiftsL = idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = new Uint32Array([0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]);
const Kr = new Uint32Array([0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]);
const shiftsL = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = /* @__PURE__ */ new Uint32Array([
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
]);
const Kr = /* @__PURE__ */ new Uint32Array([
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
]);
// The rotate left (circular left shift) operation for uint32

@@ -43,3 +47,3 @@ const rotl = (word, shift) => (word << shift) | (word >>> (32 - shift));

// Temporary buffer, not used to store anything between runs
const BUF = new Uint32Array(16);
const BUF = /* @__PURE__ */ new Uint32Array(16);
export class RIPEMD160 extends SHA2 {

@@ -103,3 +107,3 @@ constructor() {

*/
export const ripemd160 = wrapConstructor(() => new RIPEMD160());
export const ripemd160 = /* @__PURE__ */ wrapConstructor(() => new RIPEMD160());
//# sourceMappingURL=ripemd160.js.map

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { number as assertNumber } from './_assert.js';
import { sha256 } from './sha256.js';

@@ -100,8 +100,8 @@ import { pbkdf2 } from './pbkdf2.js';

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

@@ -202,3 +202,3 @@ throw new Error('progressCb should be function');

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

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

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

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

@@ -12,6 +12,8 @@ import { SHA2 } from './_sha2.js';

// Initial state
const IV = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
const IV = /* @__PURE__ */ new Uint32Array([
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
]);
// Temporary buffer, not used to store anything between runs
// Named this way because it matches specification.
const SHA1_W = new Uint32Array(80);
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
class SHA1 extends SHA2 {

@@ -85,3 +87,3 @@ constructor() {

}
export const sha1 = wrapConstructor(() => new SHA1());
export const sha1 = /* @__PURE__ */ wrapConstructor(() => new SHA1());
//# sourceMappingURL=sha1.js.map
import { SHA2 } from './_sha2.js';
import { rotr, wrapConstructor } from './utils.js';
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
// BTC network is doing 2^67 hashes/sec as per early 2023.
// Choice: a ? b : c

@@ -10,3 +12,3 @@ const Chi = (a, b, c) => (a & b) ^ (~a & c);

// prettier-ignore
const SHA256_K = new Uint32Array([
const SHA256_K = /* @__PURE__ */ new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,

@@ -23,3 +25,3 @@ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */ new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19

@@ -29,3 +31,3 @@ ]);

// Named this way because it matches specification.
const SHA256_W = new Uint32Array(64);
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
class SHA256 extends SHA2 {

@@ -125,4 +127,4 @@ constructor() {

*/
export const sha256 = wrapConstructor(() => new SHA256());
export const sha224 = wrapConstructor(() => new SHA224());
export const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
export const sha224 = /* @__PURE__ */ wrapConstructor(() => new SHA224());
//# sourceMappingURL=sha256.js.map

@@ -318,3 +318,3 @@ import { number as assertNumber } from './_assert.js';

finish() { }
digestInto(out) {
digestInto(_out) {
throw new Error('KeccakPRG: digest is not allowed, please use .fetch instead.');

@@ -321,0 +321,0 @@ }

@@ -1,12 +0,14 @@

import assert from './_assert.js';
import u64 from './_u64.js';
import { bytes, exists, number, output } from './_assert.js';
import { rotlBH, rotlBL, rotlSH, rotlSL, split } from './_u64.js';
import { Hash, u32, toBytes, wrapConstructor, wrapXOFConstructorWithOpts, } from './utils.js';
// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
// It's called a sponge function.
// Various per round constants calculations
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
const _0n = BigInt(0);
const _1n = BigInt(1);
const _2n = BigInt(2);
const _7n = BigInt(7);
const _256n = BigInt(256);
const _0x71n = BigInt(0x71);
const _0n = /* @__PURE__ */ BigInt(0);
const _1n = /* @__PURE__ */ BigInt(1);
const _2n = /* @__PURE__ */ BigInt(2);
const _7n = /* @__PURE__ */ BigInt(7);
const _256n = /* @__PURE__ */ BigInt(256);
const _0x71n = /* @__PURE__ */ BigInt(0x71);
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {

@@ -23,10 +25,10 @@ // Pi

if (R & _2n)
t ^= _1n << ((_1n << BigInt(j)) - _1n);
t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
}
_SHA3_IOTA.push(t);
}
const [SHA3_IOTA_H, SHA3_IOTA_L] = u64.split(_SHA3_IOTA, true);
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
// Left rotation (without 0, 32, 64)
const rotlH = (h, l, s) => s > 32 ? u64.rotlBH(h, l, s) : u64.rotlSH(h, l, s);
const rotlL = (h, l, s) => s > 32 ? u64.rotlBL(h, l, s) : u64.rotlSL(h, l, s);
const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
// Same as keccakf1600, but allows to skip some rounds

@@ -92,3 +94,3 @@ export function keccakP(s, rounds = 24) {

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

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

update(data) {
assert.exists(this);
exists(this);
const { blockLen, state } = this;

@@ -133,4 +135,4 @@ data = toBytes(data);

writeInto(out) {
assert.exists(this, false);
assert.bytes(out);
exists(this, false);
bytes(out);
this.finish();

@@ -156,7 +158,7 @@ const bufferOut = this.state;

xof(bytes) {
assert.number(bytes);
number(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out) {
assert.output(out, this);
output(out, this);
if (this.finished)

@@ -192,3 +194,3 @@ throw new Error('digest() was already called');

const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
export const sha3_224 = gen(0x06, 144, 224 / 8);
export const sha3_224 = /* @__PURE__ */ gen(0x06, 144, 224 / 8);
/**

@@ -198,6 +200,6 @@ * SHA3-256 hash function

*/
export const sha3_256 = gen(0x06, 136, 256 / 8);
export const sha3_384 = gen(0x06, 104, 384 / 8);
export const sha3_512 = gen(0x06, 72, 512 / 8);
export const keccak_224 = gen(0x01, 144, 224 / 8);
export const sha3_256 = /* @__PURE__ */ gen(0x06, 136, 256 / 8);
export const sha3_384 = /* @__PURE__ */ gen(0x06, 104, 384 / 8);
export const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
export const keccak_224 = /* @__PURE__ */ gen(0x01, 144, 224 / 8);
/**

@@ -207,8 +209,8 @@ * keccak-256 hash function. Different from SHA3-256.

*/
export const keccak_256 = gen(0x01, 136, 256 / 8);
export const keccak_384 = gen(0x01, 104, 384 / 8);
export const keccak_512 = gen(0x01, 72, 512 / 8);
export const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
export const keccak_384 = /* @__PURE__ */ gen(0x01, 104, 384 / 8);
export const keccak_512 = /* @__PURE__ */ gen(0x01, 72, 512 / 8);
const genShake = (suffix, blockLen, outputLen) => wrapXOFConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
export const shake128 = genShake(0x1f, 168, 128 / 8);
export const shake256 = genShake(0x1f, 136, 256 / 8);
export const shake128 = /* @__PURE__ */ genShake(0x1f, 168, 128 / 8);
export const shake256 = /* @__PURE__ */ genShake(0x1f, 136, 256 / 8);
//# sourceMappingURL=sha3.js.map

@@ -6,3 +6,3 @@ import { SHA2 } from './_sha2.js';

// prettier-ignore
const [SHA512_Kh, SHA512_Kl] = u64.split([
const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',

@@ -28,6 +28,6 @@ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',

'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
].map(n => BigInt(n)));
].map(n => BigInt(n))))();
// Temporary buffer, not used to store anything between runs
const SHA512_W_H = new Uint32Array(80);
const SHA512_W_L = new Uint32Array(80);
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
export class SHA512 extends SHA2 {

@@ -229,6 +229,6 @@ constructor() {

}
export const sha512 = wrapConstructor(() => new SHA512());
export const sha512_224 = wrapConstructor(() => new SHA512_224());
export const sha512_256 = wrapConstructor(() => new SHA512_256());
export const sha384 = wrapConstructor(() => new SHA384());
export const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
export const sha512_224 = /* @__PURE__ */ wrapConstructor(() => new SHA512_224());
export const sha512_256 = /* @__PURE__ */ wrapConstructor(() => new SHA512_256());
export const sha384 = /* @__PURE__ */ wrapConstructor(() => new SHA384());
//# sourceMappingURL=sha512.js.map

@@ -22,3 +22,3 @@ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */

throw new Error('Non little-endian hardware is not supported');
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
/**

@@ -115,6 +115,5 @@ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'

}
// Check if object doens't have custom constructor (like Uint8Array/Array)
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
const toStr = {}.toString;
export function checkOpts(defaults, opts) {
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
if (opts !== undefined && toStr.call(opts) !== '[object Object]')
throw new Error('Options should be object or undefined');

@@ -121,0 +120,0 @@ const merged = Object.assign(defaults, opts);

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

function extract(hash, ikm, salt) {
_assert_js_1.default.hash(hash);
(0, _assert_js_1.hash)(hash);
// NOTE: some libraries treat zero-length array as 'not provided';

@@ -29,4 +29,4 @@ // we don't, since we have undefined as 'not provided'

// HKDF-Expand(PRK, info, L) -> OKM
const HKDF_COUNTER = new Uint8Array([0]);
const EMPTY_BUFFER = new Uint8Array();
const HKDF_COUNTER = /* @__PURE__ */ new Uint8Array([0]);
const EMPTY_BUFFER = /* @__PURE__ */ new Uint8Array();
/**

@@ -39,4 +39,4 @@ * HKDF-expand from the spec.

function expand(hash, prk, info, length = 32) {
_assert_js_1.default.hash(hash);
_assert_js_1.default.number(length);
(0, _assert_js_1.hash)(hash);
(0, _assert_js_1.number)(length);
if (length > 255 * hash.outputLen)

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

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

this.destroyed = false;
_assert_js_1.default.hash(hash);
(0, _assert_js_1.hash)(hash);
const key = (0, utils_js_1.toBytes)(_key);

@@ -36,3 +36,3 @@ this.iHash = hash.create();

update(buf) {
_assert_js_1.default.exists(this);
(0, _assert_js_1.exists)(this);
this.iHash.update(buf);

@@ -42,4 +42,4 @@ return this;

digestInto(out) {
_assert_js_1.default.exists(this);
_assert_js_1.default.bytes(out, this.outputLen);
(0, _assert_js_1.exists)(this);
(0, _assert_js_1.bytes)(out, this.outputLen);
this.finished = true;

@@ -46,0 +46,0 @@ this.iHash.digestInto(out);

{
"name": "@noble/hashes",
"version": "1.3.1",
"version": "1.3.2",
"description": "Audited & minimal 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt",

@@ -32,2 +32,3 @@ "files": [

"license": "MIT",
"sideEffects": false,
"browser": {

@@ -34,0 +35,0 @@ "node:crypto": false,

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

function pbkdf2Init(hash, _password, _salt, _opts) {
_assert_js_1.default.hash(hash);
(0, _assert_js_1.hash)(hash);
const opts = (0, utils_js_1.checkOpts)({ dkLen: 32, asyncTick: 10 }, _opts);
const { c, dkLen, asyncTick } = opts;
_assert_js_1.default.number(c);
_assert_js_1.default.number(dkLen);
_assert_js_1.default.number(asyncTick);
(0, _assert_js_1.number)(c);
(0, _assert_js_1.number)(dkLen);
(0, _assert_js_1.number)(asyncTick);
if (c < 1)

@@ -82,3 +82,3 @@ throw new Error('PBKDF2: iterations (c) should be >= 1');

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

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

@@ -22,9 +22,10 @@ # noble-hashes

- Auditable TypeScript / JS code
- Supported in all major browsers and stable node.js versions
- All releases are signed with PGP keys
- Supported on all major platforms
- Releases are signed with PGP keys and built transparently with NPM provenance
- Check out [homepage](https://paulmillr.com/noble/) & all libraries:
[curves](https://github.com/paulmillr/noble-curves)
(4kb versions [secp256k1](https://github.com/paulmillr/noble-secp256k1),
[ed25519](https://github.com/paulmillr/noble-ed25519)),
[hashes](https://github.com/paulmillr/noble-hashes)
[ciphers](https://github.com/paulmillr/noble-ciphers),
[curves](https://github.com/paulmillr/noble-curves),
[hashes](https://github.com/paulmillr/noble-hashes),
4kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /
[ed25519](https://github.com/paulmillr/noble-ed25519)

@@ -40,7 +41,4 @@ ## Usage

The library is tree-shaking-friendly and does not expose root entry point as
`@noble/hashes`. Instead, you need to import specific primitives.
This is done to ensure small size of your apps.
```js
// import * from '@noble/hashes'; // Error: use sub-imports, to ensure small app size
import { sha256 } from '@noble/hashes/sha256'; // ECMAScript modules (ESM) and Common.js

@@ -47,0 +45,0 @@ // import { sha256 } from 'npm:@noble/hashes@1.3.0/sha256'; // Deno

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

// https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
const Rho = new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = Id.map((i) => (9 * i + 5) % 16);
const Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = /* @__PURE__ */ Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = /* @__PURE__ */ Id.map((i) => (9 * i + 5) % 16);
let idxL = [Id];

@@ -17,3 +17,3 @@ let idxR = [Pi];

j.push(j[i].map((k) => Rho[k]));
const shifts = [
const shifts = /* @__PURE__ */ [
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],

@@ -25,6 +25,10 @@ [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],

].map((i) => new Uint8Array(i));
const shiftsL = idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = new Uint32Array([0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]);
const Kr = new Uint32Array([0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]);
const shiftsL = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = /* @__PURE__ */ new Uint32Array([
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
]);
const Kr = /* @__PURE__ */ new Uint32Array([
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
]);
// The rotate left (circular left shift) operation for uint32

@@ -46,3 +50,3 @@ const rotl = (word, shift) => (word << shift) | (word >>> (32 - shift));

// Temporary buffer, not used to store anything between runs
const BUF = new Uint32Array(16);
const BUF = /* @__PURE__ */ new Uint32Array(16);
class RIPEMD160 extends _sha2_js_1.SHA2 {

@@ -49,0 +53,0 @@ constructor() {

@@ -103,8 +103,8 @@ "use strict";

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

@@ -206,3 +206,3 @@ throw new Error('progressCb should be function');

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

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

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

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

@@ -15,6 +15,8 @@ "use strict";

// Initial state
const IV = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
const IV = /* @__PURE__ */ new Uint32Array([
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
]);
// Temporary buffer, not used to store anything between runs
// Named this way because it matches specification.
const SHA1_W = new Uint32Array(80);
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
class SHA1 extends _sha2_js_1.SHA2 {

@@ -21,0 +23,0 @@ constructor() {

@@ -6,2 +6,4 @@ "use strict";

const utils_js_1 = require("./utils.js");
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
// BTC network is doing 2^67 hashes/sec as per early 2023.
// Choice: a ? b : c

@@ -14,3 +16,3 @@ const Chi = (a, b, c) => (a & b) ^ (~a & c);

// prettier-ignore
const SHA256_K = new Uint32Array([
const SHA256_K = /* @__PURE__ */ new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,

@@ -27,3 +29,3 @@ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */ new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19

@@ -33,3 +35,3 @@ ]);

// Named this way because it matches specification.
const SHA256_W = new Uint32Array(64);
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
class SHA256 extends _sha2_js_1.SHA2 {

@@ -36,0 +38,0 @@ constructor() {

@@ -131,3 +131,3 @@ import { Input, Hash, HashXOF } from './utils.js';

protected finish(): void;
digestInto(out: Uint8Array): Uint8Array;
digestInto(_out: Uint8Array): Uint8Array;
fetch(bytes: number): Uint8Array;

@@ -134,0 +134,0 @@ forget(): void;

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

finish() { }
digestInto(out) {
digestInto(_out) {
throw new Error('KeccakPRG: digest is not allowed, please use .fetch instead.');

@@ -324,0 +324,0 @@ }

@@ -7,10 +7,12 @@ "use strict";

const utils_js_1 = require("./utils.js");
// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
// It's called a sponge function.
// Various per round constants calculations
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
const _0n = BigInt(0);
const _1n = BigInt(1);
const _2n = BigInt(2);
const _7n = BigInt(7);
const _256n = BigInt(256);
const _0x71n = BigInt(0x71);
const _0n = /* @__PURE__ */ BigInt(0);
const _1n = /* @__PURE__ */ BigInt(1);
const _2n = /* @__PURE__ */ BigInt(2);
const _7n = /* @__PURE__ */ BigInt(7);
const _256n = /* @__PURE__ */ BigInt(256);
const _0x71n = /* @__PURE__ */ BigInt(0x71);
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {

@@ -27,10 +29,10 @@ // Pi

if (R & _2n)
t ^= _1n << ((_1n << BigInt(j)) - _1n);
t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
}
_SHA3_IOTA.push(t);
}
const [SHA3_IOTA_H, SHA3_IOTA_L] = _u64_js_1.default.split(_SHA3_IOTA, true);
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ (0, _u64_js_1.split)(_SHA3_IOTA, true);
// Left rotation (without 0, 32, 64)
const rotlH = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBH(h, l, s) : _u64_js_1.default.rotlSH(h, l, s);
const rotlL = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBL(h, l, s) : _u64_js_1.default.rotlSL(h, l, s);
const rotlH = (h, l, s) => (s > 32 ? (0, _u64_js_1.rotlBH)(h, l, s) : (0, _u64_js_1.rotlSH)(h, l, s));
const rotlL = (h, l, s) => (s > 32 ? (0, _u64_js_1.rotlBL)(h, l, s) : (0, _u64_js_1.rotlSL)(h, l, s));
// Same as keccakf1600, but allows to skip some rounds

@@ -97,3 +99,3 @@ function keccakP(s, rounds = 24) {

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

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

update(data) {
_assert_js_1.default.exists(this);
(0, _assert_js_1.exists)(this);
const { blockLen, state } = this;

@@ -138,4 +140,4 @@ data = (0, utils_js_1.toBytes)(data);

writeInto(out) {
_assert_js_1.default.exists(this, false);
_assert_js_1.default.bytes(out);
(0, _assert_js_1.exists)(this, false);
(0, _assert_js_1.bytes)(out);
this.finish();

@@ -161,7 +163,7 @@ const bufferOut = this.state;

xof(bytes) {
_assert_js_1.default.number(bytes);
(0, _assert_js_1.number)(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out) {
_assert_js_1.default.output(out, this);
(0, _assert_js_1.output)(out, this);
if (this.finished)

@@ -168,0 +170,0 @@ throw new Error('digest() was already called');

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

// prettier-ignore
const [SHA512_Kh, SHA512_Kl] = _u64_js_1.default.split([
const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => _u64_js_1.default.split([
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',

@@ -31,6 +31,6 @@ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',

'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
].map(n => BigInt(n)));
].map(n => BigInt(n))))();
// Temporary buffer, not used to store anything between runs
const SHA512_W_H = new Uint32Array(80);
const SHA512_W_L = new Uint32Array(80);
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
class SHA512 extends _sha2_js_1.SHA2 {

@@ -37,0 +37,0 @@ constructor() {

@@ -1,10 +0,10 @@

export function number(n: number) {
function number(n: number) {
if (!Number.isSafeInteger(n) || n < 0) throw new Error(`Wrong positive integer: ${n}`);
}
export function bool(b: boolean) {
function bool(b: boolean) {
if (typeof b !== 'boolean') throw new Error(`Expected boolean, not ${b}`);
}
export function bytes(b: Uint8Array | undefined, ...lengths: number[]) {
function bytes(b: Uint8Array | undefined, ...lengths: number[]) {
if (!(b instanceof Uint8Array)) throw new Error('Expected Uint8Array');

@@ -21,3 +21,3 @@ if (lengths.length > 0 && !lengths.includes(b.length))

};
export function hash(hash: Hash) {
function hash(hash: Hash) {
if (typeof hash !== 'function' || typeof hash.create !== 'function')

@@ -29,7 +29,7 @@ throw new Error('Hash should be wrapped by utils.wrapConstructor');

export function exists(instance: any, checkFinished = true) {
function exists(instance: any, checkFinished = true) {
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
}
export function output(out: any, instance: any) {
function output(out: any, instance: any) {
bytes(out);

@@ -42,11 +42,5 @@ const min = instance.outputLen;

const assert = {
number,
bool,
bytes,
hash,
exists,
output,
};
export { number, bool, bytes, hash, exists, output };
const assert = { number, bool, bytes, hash, exists, output };
export default assert;

@@ -1,6 +0,9 @@

import assert from './_assert.js';
import { number, exists, output } from './_assert.js';
import { Hash, Input, toBytes, u32 } from './utils.js';
// Blake is based on ChaCha permutation.
// For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
// prettier-ignore
export const SIGMA = new Uint8Array([
export const SIGMA = /* @__PURE__ */ new Uint8Array([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

@@ -48,5 +51,5 @@ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,

super();
assert.number(blockLen);
assert.number(outputLen);
assert.number(keyLen);
number(blockLen);
number(outputLen);
number(keyLen);
if (outputLen < 0 || outputLen > keyLen) throw new Error('outputLen bigger than keyLen');

@@ -62,3 +65,3 @@ if (opts.key !== undefined && (opts.key.length < 1 || opts.key.length > keyLen))

update(data: Input) {
assert.exists(this);
exists(this);
// Main difference with other hashes: there is flag for last block,

@@ -98,4 +101,4 @@ // so we cannot process current block before we know that there

digestInto(out: Uint8Array) {
assert.exists(this);
assert.output(out, this);
exists(this);
output(out, this);
const { pos, buffer32 } = this;

@@ -102,0 +105,0 @@ this.finished = true;

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { exists, output } from './_assert.js';
import { Hash, createView, Input, toBytes } from './utils.js';

@@ -43,3 +43,3 @@

update(data: Input): this {
assert.exists(this);
exists(this);
const { view, buffer, blockLen } = this;

@@ -69,4 +69,4 @@ data = toBytes(data);

digestInto(out: Uint8Array) {
assert.exists(this);
assert.output(out, this);
exists(this);
output(out, this);
this.finished = true;

@@ -73,0 +73,0 @@ // Padding

@@ -1,6 +0,6 @@

const U32_MASK64 = BigInt(2 ** 32 - 1);
const _32n = BigInt(32);
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
const _32n = /* @__PURE__ */ BigInt(32);
// We are not using BigUint64Array, because they are extremely slow as per 2022
export function fromBig(n: bigint, le = false) {
function fromBig(n: bigint, le = false) {
if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };

@@ -10,3 +10,3 @@ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };

export function split(lst: bigint[], le = false) {
function split(lst: bigint[], le = false) {
let Ah = new Uint32Array(lst.length);

@@ -21,5 +21,5 @@ let Al = new Uint32Array(lst.length);

export const toBig = (h: number, l: number) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
const toBig = (h: number, l: number) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
// for Shift in [0, 32)
const shrSH = (h: number, l: number, s: number) => h >>> s;
const shrSH = (h: number, _l: number, s: number) => h >>> s;
const shrSL = (h: number, l: number, s: number) => (h << (32 - s)) | (l >>> s);

@@ -33,4 +33,4 @@ // Right rotate for Shift in [1, 32)

// Right rotate for shift===32 (just swaps l&h)
const rotr32H = (h: number, l: number) => l;
const rotr32L = (h: number, l: number) => h;
const rotr32H = (_h: number, l: number) => l;
const rotr32L = (h: number, _l: number) => h;
// Left rotate for Shift in [1, 32)

@@ -45,4 +45,3 @@ const rotlSH = (h: number, l: number, s: number) => (h << s) | (l >>> (32 - s));

// simple take carry out of low bit sum by shift, we need to use division.
// Removing "export" has 5% perf penalty -_-
export function add(Ah: number, Al: number, Bh: number, Bl: number) {
function add(Ah: number, Al: number, Bh: number, Bl: number) {
const l = (Al >>> 0) + (Bl >>> 0);

@@ -65,2 +64,11 @@ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };

// prettier-ignore
export {
fromBig, split, toBig,
shrSH, shrSL,
rotrSH, rotrSL, rotrBH, rotrBL,
rotr32H, rotr32L,
rotlSH, rotlSL, rotlBH, rotlBL,
add, add3L, add3H, add4L, add4H, add5H, add5L,
};
// prettier-ignore
const u64 = {

@@ -67,0 +75,0 @@ fromBig, split, toBig,

@@ -1,8 +0,8 @@

import assert from './_assert.js';
import { number as assertNumber } from './_assert.js';
import { Input, toBytes, u8, u32 } from './utils.js';
import { blake2b } from './blake2b.js';
import u64 from './_u64.js';
import { add3H, add3L, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL } from './_u64.js';
// Experimental Argon2 RFC 9106 implementation. It may be removed at any time.
enum Types {
const enum Types {
Argond2d = 0,

@@ -45,4 +45,4 @@ Argon2i = 1,

// A + B + (2 * A * B)
const Rll = u64.add3L(Al, Bl, Cl);
return { h: u64.add3H(Rll, Ah, Bh, Ch), l: Rll | 0 };
const Rll = add3L(Al, Bl, Cl);
return { h: add3H(Rll, Ah, Bh, Ch), l: Rll | 0 };
}

@@ -61,15 +61,15 @@

({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: u64.rotr32H(Dh, Dl), Dl: u64.rotr32L(Dh, Dl) });
({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh, Dl) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 24), Bl: u64.rotrSL(Bh, Bl, 24) });
({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
({ h: Ah, l: Al } = blamka(Ah, Al, Bh, Bl));
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
({ Dh, Dl } = { Dh: u64.rotrSH(Dh, Dl, 16), Dl: u64.rotrSL(Dh, Dl, 16) });
({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
({ Bh, Bl } = { Bh: u64.rotrBH(Bh, Bl, 63), Bl: u64.rotrBL(Bh, Bl, 63) });
({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });

@@ -189,10 +189,10 @@ (BUF[2 * a] = Al), (BUF[2 * a + 1] = Ah);

// Validation
assert.number(p);
assert.number(dkLen);
assert.number(m);
assert.number(t);
assert.number(version);
assertNumber(p);
assertNumber(dkLen);
assertNumber(m);
assertNumber(t);
assertNumber(version);
if (dkLen < 4 || dkLen >= 2 ** 32) throw new Error('Argon2: dkLen should be at least 4 bytes');
if (dkLen < 1 || p >= 2 ** 32) throw new Error('Argon2: p (paralllelism) should be at least 1');
if (dkLen < 1 || p >= 2 ** 32) throw new Error('Argon2: t (iterations) should be at least 1');
if (p < 1 || p >= 2 ** 32) throw new Error('Argon2: p (parallelism) should be at least 1');
if (t < 1 || t >= 2 ** 32) throw new Error('Argon2: t (iterations) should be at least 1');
if (m < 8 * p) throw new Error(`Argon2: memory should be at least 8*p bytes`);

@@ -199,0 +199,0 @@ if (version !== 16 && version !== 19) throw new Error(`Argon2: unknown version=${version}`);

@@ -7,3 +7,3 @@ import { BLAKE2, BlakeOpts, SIGMA } from './_blake2.js';

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */ new Uint32Array([
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,

@@ -13,3 +13,3 @@ 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19

// Temporary buffer
const BUF = new Uint32Array(32);
const BUF = /* @__PURE__ */ new Uint32Array(32);

@@ -205,2 +205,4 @@ // Mixing function G splitted in two halfs

*/
export const blake2b = wrapConstructorWithOpts<BLAKE2b, BlakeOpts>((opts) => new BLAKE2b(opts));
export const blake2b = /* @__PURE__ */ wrapConstructorWithOpts<BLAKE2b, BlakeOpts>(
(opts) => new BLAKE2b(opts)
);
import { BLAKE2, BlakeOpts, SIGMA } from './_blake2.js';
import u64 from './_u64.js';
import { fromBig } from './_u64.js';
import { rotr, toBytes, wrapConstructorWithOpts, u32 } from './utils.js';

@@ -9,5 +9,3 @@

// prettier-ignore
export const IV = new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
]);
export const IV = /* @__PURE__ */new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);

@@ -108,3 +106,3 @@ // Mixing function G splitted in two halfs

protected compress(msg: Uint32Array, offset: number, isLast: boolean) {
const { h, l } = u64.fromBig(BigInt(this.length));
const { h, l } = fromBig(BigInt(this.length));
// prettier-ignore

@@ -138,2 +136,4 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =

*/
export const blake2s = wrapConstructorWithOpts<BLAKE2s, BlakeOpts>((opts) => new BLAKE2s(opts));
export const blake2s = /* @__PURE__ */ wrapConstructorWithOpts<BLAKE2s, BlakeOpts>(
(opts) => new BLAKE2s(opts)
);

@@ -1,3 +0,3 @@

import assert from './_assert.js';
import u64 from './_u64.js';
import { bytes, exists, number, output } from './_assert.js';
import { fromBig } from './_u64.js';
import { BLAKE2 } from './_blake2.js';

@@ -7,4 +7,6 @@ import { compress, IV } from './blake2s.js';

// Blake3 is single-option Blake2 with reduced security (round count).
// Flag bitset
enum Flags {
const enum Flags {
CHUNK_START = 1 << 0,

@@ -19,3 +21,3 @@ CHUNK_END = 1 << 1,

const SIGMA: Uint8Array = (() => {
const SIGMA: Uint8Array = /* @__PURE__ */ (() => {
const Id = Array.from({ length: 16 }, (_, i) => i);

@@ -60,3 +62,3 @@ const permute = (arr: number[]) =>

this.outputLen = opts.dkLen === undefined ? 32 : opts.dkLen;
assert.number(this.outputLen);
number(this.outputLen);
if (opts.key !== undefined && opts.context !== undefined)

@@ -89,3 +91,3 @@ throw new Error('Blake3: only key or context can be specified at same time');

const { state: s, pos } = this;
const { h, l } = u64.fromBig(BigInt(counter), true);
const { h, l } = fromBig(BigInt(counter), true);
// prettier-ignore

@@ -166,3 +168,3 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =

const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
const { h, l } = u64.fromBig(BigInt(this.chunkOut++));
const { h, l } = fromBig(BigInt(this.chunkOut++));
// prettier-ignore

@@ -212,4 +214,4 @@ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =

private writeInto(out: Uint8Array) {
assert.exists(this, false);
assert.bytes(out);
exists(this, false);
bytes(out);
this.finish();

@@ -231,7 +233,7 @@ const { blockLen, bufferOut } = this;

xof(bytes: number): Uint8Array {
assert.number(bytes);
number(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out: Uint8Array) {
assert.output(out, this);
output(out, this);
if (this.finished) throw new Error('digest() was already called');

@@ -253,2 +255,4 @@ this.enableXOF = false;

*/
export const blake3 = wrapXOFConstructorWithOpts<BLAKE3, Blake3Opts>((opts) => new BLAKE3(opts));
export const blake3 = /* @__PURE__ */ wrapXOFConstructorWithOpts<BLAKE3, Blake3Opts>(
(opts) => new BLAKE3(opts)
);

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, number as assertNumber } from './_assert.js';
import { CHash, Input, toBytes } from './utils.js';

@@ -17,3 +17,3 @@ import { hmac } from './hmac.js';

export function extract(hash: CHash, ikm: Input, salt?: Input) {
assert.hash(hash);
assertHash(hash);
// NOTE: some libraries treat zero-length array as 'not provided';

@@ -27,4 +27,4 @@ // we don't, since we have undefined as 'not provided'

// HKDF-Expand(PRK, info, L) -> OKM
const HKDF_COUNTER = new Uint8Array([0]);
const EMPTY_BUFFER = new Uint8Array();
const HKDF_COUNTER = /* @__PURE__ */ new Uint8Array([0]);
const EMPTY_BUFFER = /* @__PURE__ */ new Uint8Array();

@@ -38,4 +38,4 @@ /**

export function expand(hash: CHash, prk: Input, info?: Input, length: number = 32) {
assert.hash(hash);
assert.number(length);
assertHash(hash);
assertNumber(length);
if (length > 255 * hash.outputLen) throw new Error('Length should be <= 255*HashLen');

@@ -42,0 +42,0 @@ const blocks = Math.ceil(length / hash.outputLen);

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, bytes as assertBytes, exists as assertExists } from './_assert.js';
import { Hash, CHash, Input, toBytes } from './utils.js';

@@ -14,3 +14,3 @@ // HMAC (RFC 2104)

super();
assert.hash(hash);
assertHash(hash);
const key = toBytes(_key);

@@ -36,3 +36,3 @@ this.iHash = hash.create() as T;

update(buf: Input) {
assert.exists(this);
assertExists(this);
this.iHash.update(buf);

@@ -42,4 +42,4 @@ return this;

digestInto(out: Uint8Array) {
assert.exists(this);
assert.bytes(out, this.outputLen);
assertExists(this);
assertBytes(out, this.outputLen);
this.finished = true;

@@ -46,0 +46,0 @@ this.iHash.digestInto(out);

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { hash as assertHash, number as assertNumber } from './_assert.js';
import { hmac } from './hmac.js';

@@ -13,8 +13,8 @@ import { Hash, CHash, Input, createView, toBytes, checkOpts, asyncLoop } from './utils.js';

function pbkdf2Init(hash: CHash, _password: Input, _salt: Input, _opts: Pbkdf2Opt) {
assert.hash(hash);
assertHash(hash);
const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
const { c, dkLen, asyncTick } = opts;
assert.number(c);
assert.number(dkLen);
assert.number(asyncTick);
assertNumber(c);
assertNumber(dkLen);
assertNumber(asyncTick);
if (c < 1) throw new Error('PBKDF2: iterations (c) should be >= 1');

@@ -91,3 +91,3 @@ const password = toBytes(_password);

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

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

@@ -6,5 +6,5 @@ import { SHA2 } from './_sha2.js';

// https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
const Rho = new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = Id.map((i) => (9 * i + 5) % 16);
const Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
const Id = /* @__PURE__ */ Uint8Array.from({ length: 16 }, (_, i) => i);
const Pi = /* @__PURE__ */ Id.map((i) => (9 * i + 5) % 16);
let idxL = [Id];

@@ -14,3 +14,3 @@ let idxR = [Pi];

const shifts = [
const shifts = /* @__PURE__ */ [
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],

@@ -22,8 +22,10 @@ [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],

].map((i) => new Uint8Array(i));
const shiftsL = idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = new Uint32Array([0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]);
const Kr = new Uint32Array([0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]);
const shiftsL = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts[i][j]));
const shiftsR = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts[i][j]));
const Kl = /* @__PURE__ */ new Uint32Array([
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
]);
const Kr = /* @__PURE__ */ new Uint32Array([
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
]);
// The rotate left (circular left shift) operation for uint32

@@ -40,3 +42,3 @@ const rotl = (word: number, shift: number) => (word << shift) | (word >>> (32 - shift));

// Temporary buffer, not used to store anything between runs
const BUF = new Uint32Array(16);
const BUF = /* @__PURE__ */ new Uint32Array(16);
export class RIPEMD160 extends SHA2<RIPEMD160> {

@@ -112,2 +114,2 @@ private h0 = 0x67452301 | 0;

*/
export const ripemd160 = wrapConstructor(() => new RIPEMD160());
export const ripemd160 = /* @__PURE__ */ wrapConstructor(() => new RIPEMD160());

@@ -1,2 +0,2 @@

import assert from './_assert.js';
import { number as assertNumber } from './_assert.js';
import { sha256 } from './sha256.js';

@@ -102,8 +102,8 @@ import { pbkdf2 } from './pbkdf2.js';

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

@@ -226,3 +226,3 @@ throw new Error('progressCb should be function');

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

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

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

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

@@ -15,7 +15,9 @@ import { SHA2 } from './_sha2.js';

// Initial state
const IV = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
const IV = /* @__PURE__ */ new Uint32Array([
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
]);
// Temporary buffer, not used to store anything between runs
// Named this way because it matches specification.
const SHA1_W = new Uint32Array(80);
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
class SHA1 extends SHA2<SHA1> {

@@ -87,2 +89,2 @@ private A = IV[0] | 0;

export const sha1 = wrapConstructor(() => new SHA1());
export const sha1 = /* @__PURE__ */ wrapConstructor(() => new SHA1());
import { SHA2 } from './_sha2.js';
import { rotr, wrapConstructor } from './utils.js';
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
// BTC network is doing 2^67 hashes/sec as per early 2023.
// Choice: a ? b : c

@@ -12,3 +15,3 @@ const Chi = (a: number, b: number, c: number) => (a & b) ^ (~a & c);

// prettier-ignore
const SHA256_K = new Uint32Array([
const SHA256_K = /* @__PURE__ */new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,

@@ -26,3 +29,3 @@ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,

// prettier-ignore
const IV = new Uint32Array([
const IV = /* @__PURE__ */new Uint32Array([
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19

@@ -33,3 +36,3 @@ ]);

// Named this way because it matches specification.
const SHA256_W = new Uint32Array(64);
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
class SHA256 extends SHA2<SHA256> {

@@ -132,3 +135,3 @@ // We cannot use array here since array allows indexing by variable

*/
export const sha256 = wrapConstructor(() => new SHA256());
export const sha224 = wrapConstructor(() => new SHA224());
export const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
export const sha224 = /* @__PURE__ */ wrapConstructor(() => new SHA224());

@@ -371,3 +371,3 @@ import { number as assertNumber } from './_assert.js';

protected finish() {}
digestInto(out: Uint8Array): Uint8Array {
digestInto(_out: Uint8Array): Uint8Array {
throw new Error('KeccakPRG: digest is not allowed, please use .fetch instead.');

@@ -374,0 +374,0 @@ }

@@ -1,3 +0,3 @@

import assert from './_assert.js';
import u64 from './_u64.js';
import { bytes, exists, number, output } from './_assert.js';
import { rotlBH, rotlBL, rotlSH, rotlSL, split } from './_u64.js';
import {

@@ -13,10 +13,13 @@ Hash,

// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
// It's called a sponge function.
// Various per round constants calculations
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA]: [number[], number[], bigint[]] = [[], [], []];
const _0n = BigInt(0);
const _1n = BigInt(1);
const _2n = BigInt(2);
const _7n = BigInt(7);
const _256n = BigInt(256);
const _0x71n = BigInt(0x71);
const _0n = /* @__PURE__ */ BigInt(0);
const _1n = /* @__PURE__ */ BigInt(1);
const _2n = /* @__PURE__ */ BigInt(2);
const _7n = /* @__PURE__ */ BigInt(7);
const _256n = /* @__PURE__ */ BigInt(256);
const _0x71n = /* @__PURE__ */ BigInt(0x71);
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {

@@ -32,13 +35,11 @@ // Pi

R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
if (R & _2n) t ^= _1n << ((_1n << BigInt(j)) - _1n);
if (R & _2n) t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
}
_SHA3_IOTA.push(t);
}
const [SHA3_IOTA_H, SHA3_IOTA_L] = u64.split(_SHA3_IOTA, true);
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
// Left rotation (without 0, 32, 64)
const rotlH = (h: number, l: number, s: number) =>
s > 32 ? u64.rotlBH(h, l, s) : u64.rotlSH(h, l, s);
const rotlL = (h: number, l: number, s: number) =>
s > 32 ? u64.rotlBL(h, l, s) : u64.rotlSL(h, l, s);
const rotlH = (h: number, l: number, s: number) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
const rotlL = (h: number, l: number, s: number) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));

@@ -106,3 +107,3 @@ // Same as keccakf1600, but allows to skip some rounds

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

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

update(data: Input) {
assert.exists(this);
exists(this);
const { blockLen, state } = this;

@@ -143,4 +144,4 @@ data = toBytes(data);

protected writeInto(out: Uint8Array): Uint8Array {
assert.exists(this, false);
assert.bytes(out);
exists(this, false);
bytes(out);
this.finish();

@@ -164,7 +165,7 @@ const bufferOut = this.state;

xof(bytes: number): Uint8Array {
assert.number(bytes);
number(bytes);
return this.xofInto(new Uint8Array(bytes));
}
digestInto(out: Uint8Array) {
assert.output(out, this);
output(out, this);
if (this.finished) throw new Error('digest() was already called');

@@ -202,3 +203,3 @@ this.writeInto(out);

export const sha3_224 = gen(0x06, 144, 224 / 8);
export const sha3_224 = /* @__PURE__ */ gen(0x06, 144, 224 / 8);
/**

@@ -208,6 +209,6 @@ * SHA3-256 hash function

*/
export const sha3_256 = gen(0x06, 136, 256 / 8);
export const sha3_384 = gen(0x06, 104, 384 / 8);
export const sha3_512 = gen(0x06, 72, 512 / 8);
export const keccak_224 = gen(0x01, 144, 224 / 8);
export const sha3_256 = /* @__PURE__ */ gen(0x06, 136, 256 / 8);
export const sha3_384 = /* @__PURE__ */ gen(0x06, 104, 384 / 8);
export const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
export const keccak_224 = /* @__PURE__ */ gen(0x01, 144, 224 / 8);
/**

@@ -217,5 +218,5 @@ * keccak-256 hash function. Different from SHA3-256.

*/
export const keccak_256 = gen(0x01, 136, 256 / 8);
export const keccak_384 = gen(0x01, 104, 384 / 8);
export const keccak_512 = gen(0x01, 72, 512 / 8);
export const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
export const keccak_384 = /* @__PURE__ */ gen(0x01, 104, 384 / 8);
export const keccak_512 = /* @__PURE__ */ gen(0x01, 72, 512 / 8);

@@ -230,3 +231,3 @@ export type ShakeOpts = { dkLen?: number };

export const shake128 = genShake(0x1f, 168, 128 / 8);
export const shake256 = genShake(0x1f, 136, 256 / 8);
export const shake128 = /* @__PURE__ */ genShake(0x1f, 168, 128 / 8);
export const shake256 = /* @__PURE__ */ genShake(0x1f, 136, 256 / 8);

@@ -7,3 +7,3 @@ import { SHA2 } from './_sha2.js';

// prettier-ignore
const [SHA512_Kh, SHA512_Kl] = u64.split([
const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',

@@ -29,8 +29,7 @@ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',

'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
].map(n => BigInt(n)));
].map(n => BigInt(n))))();
// Temporary buffer, not used to store anything between runs
const SHA512_W_H = new Uint32Array(80);
const SHA512_W_L = new Uint32Array(80);
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
export class SHA512 extends SHA2<SHA512> {

@@ -246,5 +245,5 @@ // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.

export const sha512 = wrapConstructor(() => new SHA512());
export const sha512_224 = wrapConstructor(() => new SHA512_224());
export const sha512_256 = wrapConstructor(() => new SHA512_256());
export const sha384 = wrapConstructor(() => new SHA384());
export const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
export const sha512_224 = /* @__PURE__ */ wrapConstructor(() => new SHA512_224());
export const sha512_256 = /* @__PURE__ */ wrapConstructor(() => new SHA512_256());
export const sha384 = /* @__PURE__ */ wrapConstructor(() => new SHA384());

@@ -33,3 +33,5 @@ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */

const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>
i.toString(16).padStart(2, '0')
);
/**

@@ -161,6 +163,3 @@ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'

// Check if object doens't have custom constructor (like Uint8Array/Array)
const isPlainObject = (obj: any) =>
Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
const toStr = {}.toString;
type EmptyObj = {};

@@ -171,3 +170,3 @@ export function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(

): T1 & T2 {
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
if (opts !== undefined && toStr.call(opts) !== '[object Object]')
throw new Error('Options should be object or undefined');

@@ -174,0 +173,0 @@ const merged = Object.assign(defaults, opts);

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

throw new Error('Non little-endian hardware is not supported');
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
/**

@@ -130,6 +130,5 @@ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'

exports.Hash = Hash;
// Check if object doens't have custom constructor (like Uint8Array/Array)
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
const toStr = {}.toString;
function checkOpts(defaults, opts) {
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
if (opts !== undefined && toStr.call(opts) !== '[object Object]')
throw new Error('Options should be object or undefined');

@@ -136,0 +135,0 @@ const merged = Object.assign(defaults, opts);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc