Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

noble-hashes

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noble-hashes - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

lib/sha512_256.d.ts

2

lib/_sha2.d.ts
import { Hash, PartialOpts, Input } from './utils';
export declare abstract class Sha2 extends Hash {
readonly blockLen: number;
readonly outputLen: number;
outputLen: number;
readonly padOffset: number;

@@ -6,0 +6,0 @@ readonly isLE: boolean;

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

}
// Temporary buffer, overwritten on processing
// Temporary buffer, overwritten on processing. See sha256.ts.
const RIPEMD160_W = new Uint32Array(16);

@@ -44,0 +44,0 @@ class RIPEMD160 extends _sha2_1.Sha2 {

@@ -27,3 +27,4 @@ "use strict";

]);
// Temporary buffer, overwritten on processing
// Temporary buffer, overwritten on processing. Only used to store temporary data
// of single function run. Not used to store anything between runs!
const SHA256_W = new Uint32Array(64);

@@ -30,0 +31,0 @@ class _Sha256 extends _sha2_1.Sha2 {

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

const rotlL = (h, l, s) => s > 32 ? u64.rotlBL(h, l, s) : u64.rotlSL(h, l, s);
// Temporary buffer
// Temporary buffer. See sha256.ts
const SHA3_B = new Uint32Array(5 * 2);

@@ -50,0 +50,0 @@ class Sha3 extends utils_1.Hash {

@@ -0,1 +1,43 @@

import { Sha2 } from './_sha2';
import { PartialOpts } from './utils';
export declare class _Sha512 extends Sha2 {
Ah: number;
Al: number;
Bh: number;
Bl: number;
Ch: number;
Cl: number;
Dh: number;
Dl: number;
Eh: number;
El: number;
Fh: number;
Fl: number;
Gh: number;
Gl: number;
Hh: number;
Hl: number;
constructor(opts: PartialOpts);
_get(): [
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number
];
private _set;
_process(view: DataView, offset: number): void;
clean(): void;
}
export declare const sha512: {

@@ -7,1 +49,7 @@ (msg: import("./utils").Input, opts?: Partial<import("./utils").HashOpts> | undefined): Uint8Array;

};
export declare const sha512_256: {
(msg: import("./utils").Input, opts?: Partial<import("./utils").HashOpts> | undefined): Uint8Array;
outputLen: number;
blockLen: number;
init(opts: Partial<import("./utils").HashOpts>): import("./utils").Hash;
};

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.sha512 = void 0;
exports.sha512_256 = exports.sha512 = exports._Sha512 = void 0;
const _sha2_1 = require("./_sha2");

@@ -51,3 +51,3 @@ const u64 = __importStar(require("./_u64"));

]);
// Temporary buffer, overwritten on processing
// Temporary buffer, overwritten on processing. See sha256.ts
const [SHA512_Wh, SHA512_Wl] = [new Uint32Array(80), new Uint32Array(80)];

@@ -180,2 +180,27 @@ class _Sha512 extends _sha2_1.Sha2 {

}
exports._Sha512 = _Sha512;
class _Sha512_256 extends _Sha512 {
constructor(opts) {
super(opts);
// h -- high 32 bits, l -- low 32 bits
this.Ah = 0x22312194 | 0;
this.Al = 0xfc2bf72c | 0;
this.Bh = 0x9f555fa3 | 0;
this.Bl = 0xc84c64c2 | 0;
this.Ch = 0x2393b86b | 0;
this.Cl = 0x6f53b151 | 0;
this.Dh = 0x96387719 | 0;
this.Dl = 0x5940eabd | 0;
this.Eh = 0x96283ee2 | 0;
this.El = 0xa88effe3 | 0;
this.Fh = 0xbe5e1e25 | 0;
this.Fl = 0x53863992 | 0;
this.Gh = 0x2b0199fc | 0;
this.Gl = 0x2c85b8aa | 0;
this.Hh = 0x0eb72ddc | 0;
this.Hl = 0x81c52ca2 | 0;
this.outputLen = 32;
}
}
exports.sha512 = utils_1.wrapConstructor((opts) => new _Sha512(opts));
exports.sha512_256 = utils_1.wrapConstructor((opts) => new _Sha512_256(opts));

@@ -7,3 +7,3 @@ export declare type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;

export declare const isLE: boolean;
export declare const toHex: (buf: Uint8Array) => string;
export declare function bytesToHex(uint8a: Uint8Array): string;
export declare const nextTick: () => Promise<unknown>;

@@ -10,0 +10,0 @@ export declare function asyncLoop(iters: number, tick: number, cb: (i: number) => void): Promise<void>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomBytes = exports.wrapConstructor = exports.cloneHashInto = exports.checkOpts = exports.Hash = exports.assertHash = exports.assertBool = exports.assertNumber = exports.toBytes = exports.asyncLoop = exports.nextTick = exports.toHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
exports.randomBytes = exports.wrapConstructor = exports.cloneHashInto = exports.checkOpts = exports.Hash = exports.assertHash = exports.assertBool = exports.assertNumber = exports.toBytes = exports.asyncLoop = exports.nextTick = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
// Cast array to different type

@@ -20,6 +20,11 @@ const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);

throw new Error('Non little-endian hardware is not supported');
const toHex = (buf) => Array.from(buf)
.map((c) => c.toString(16).padStart(2, '0'))
.join('');
exports.toHex = toHex;
function bytesToHex(uint8a) {
// pre-caching chars could speed this up 6x.
let hex = '';
for (let i = 0; i < uint8a.length; i++) {
hex += uint8a[i].toString(16).padStart(2, '0');
}
return hex;
}
exports.bytesToHex = bytesToHex;
// Currently avoid insertion of polyfills with packers (browserify/webpack/etc)

@@ -26,0 +31,0 @@ // But setTimeout is pretty slow, maybe worth to investigate howto do minimal polyfill here

{
"name": "noble-hashes",
"version": "0.1.0",
"version": "0.1.1",
"description": "Fast 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE, HMAC, HKDF, PBKDF2, Scrypt",

@@ -26,3 +26,3 @@ "main": "lib/index.js",

"type": "git",
"url": "https://github.com/paulmillr/noble-secp256k1.git"
"url": "https://github.com/paulmillr/noble-hashes.git"
},

@@ -29,0 +29,0 @@ "license": "MIT",

@@ -19,2 +19,4 @@ # noble-hashes ![Node CI](https://github.com/paulmillr/noble-hashes/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

The library's initial development was funded by [Ethereum Foundation](https://ethereum.org/).
### This library belongs to *noble* crypto

@@ -47,5 +49,7 @@

// Uint8Array(32) [3, 144, 88, 198, 242, 192, 203, 73, ...]
console.log(sha256('abc'))); // you could also pass strings
const { sha512 } = require('noble-hashes/lib/sha512');
// you could also pass strings that will be UTF8-encoded to Uint8Array
console.log(sha256('abc'))); // == sha256(new TextEncoder().encode('abc'))
const { sha512, sha512_256 } = require('noble-hashes/lib/sha512');
// prettier-ignore

@@ -82,3 +86,3 @@ const {

##### SHA2 (sha256, sha512)
##### SHA2 (sha256, sha512, sha512_256)

@@ -94,7 +98,13 @@ ```typescript

import { sha512 } from 'noble-hashes/lib/sha512.js';
// function sha512(data: Uint8Array): Uint8Array;
const hash3 = sha512('abc');
const hash4 = sha512.init().update(Uint8Array.from([1, 2, 3])).digest();
// SHA512/256 variant
import { sha512_256 } from 'noble-hashes/lib/sha512.js';
const hash3_a = sha512_256('abc');
const hash4_a = sha512_256.init().update(Uint8Array.from([1, 2, 3])).digest();
```
To lean more about SHA512/256, check out [the paper](https://eprint.iacr.org/2010/548.pdf).
##### SHA3 (sha3_256, keccak_256, etc)

@@ -232,4 +242,5 @@

SHA512 32 B x 440,722 ops/sec @ 2μs/op
SHA512-256 32 B x 423,549 ops/sec @ 2μs/op
SHA3 32 B x 184,331 ops/sec @ 5μs/op
BLAKE2s 32 B x 464,468 ops/sec @ 2μs/op
BLAKE2s 32 B x 487,567 ops/sec @ 2μs/op
BLAKE2b 32 B x 282,965 ops/sec @ 3μs/op

@@ -249,2 +260,3 @@ HMAC-SHA256 32 B x 270,343 ops/sec @ 3μs/op

SHA512 32 B node x 551,267 ops/sec @ 1μs/op
SHA512-256 32 B node x 534,473 ops/sec @ 1μs/op
SHA3 32 B node x 545,553 ops/sec @ 1μs/op

@@ -251,0 +263,0 @@ BLAKE2s 32 B node x 545,256 ops/sec @ 1μs/op

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc