Socket
Socket
Sign inDemoInstall

multihashing-async

Package Overview
Dependencies
Maintainers
5
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multihashing-async - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

dist/src/blake.d.ts

9

CHANGELOG.md

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

# [2.1.0](https://github.com/multiformats/js-multihashing-async/compare/v2.0.1...v2.1.0) (2021-02-02)
### Features
* add types to the library ([#92](https://github.com/multiformats/js-multihashing-async/issues/92)) ([4b16057](https://github.com/multiformats/js-multihashing-async/commit/4b1605755df620d0a5193ad0d682206e000ccb06))
<a name="2.0.1"></a>

@@ -2,0 +11,0 @@ ## [2.0.1](https://github.com/multiformats/js-multihashing-async/compare/v2.0.0...v2.0.1) (2020-08-05)

25

package.json
{
"name": "multihashing-async",
"version": "2.0.1",
"version": "2.1.0",
"description": "multiple hash functions",

@@ -23,2 +23,3 @@ "keywords": [

},
"types": "dist/src/index.d.ts",
"repository": "github:multiformats/js-multihashing-async",

@@ -30,2 +31,4 @@ "scripts": {

"lint": "aegir lint",
"check": "aegir ts -p check",
"prepare": "aegir build --no-bundle",
"docs": "aegir docs",

@@ -40,13 +43,17 @@ "release": "aegir release --docs",

"blakejs": "^1.1.0",
"err-code": "^2.0.0",
"err-code": "^3.0.0",
"js-sha3": "^0.8.0",
"multihashes": "^3.0.1",
"multihashes": "^3.1.2",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^1.0.0"
"uint8arrays": "^2.0.5"
},
"devDependencies": {
"aegir": "^25.0.0",
"@types/sinon": "^9.0.10",
"aegir": "^30.3.0",
"benchmark": "^2.1.4",
"sinon": "^9.0.2"
},
"eslintConfig": {
"extends": "ipfs"
},
"engines": {

@@ -64,4 +71,4 @@ "node": ">=10.0.0",

"Pedro Teixeira <i@pgte.me>",
"Victor Bjelkholm <victorbjelkholm@gmail.com>",
"Richard Schneider <makaretu@gmail.com>",
"Irakli Gozalishvili <contact@gozala.io>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Volker Mische <volker.mische@gmail.com>",

@@ -71,3 +78,2 @@ "André Cruz <andremiguelcruz@msn.com>",

"Dmitriy Ryajov <dryajov@gmail.com>",
"Irakli Gozalishvili <contact@gozala.io>",
"Jacob Heun <jacobheun@gmail.com>",

@@ -77,4 +83,5 @@ "Marcin Rataj <lidel@lidel.org>",

"Mikeal Rogers <mikeal.rogers@gmail.com>",
"Mitar <mitar.github@tnode.com>"
"Mitar <mitar.github@tnode.com>",
"Richard Schneider <makaretu@gmail.com>"
]
}

@@ -6,7 +6,4 @@ # js-multihashing-async <!-- omit in toc -->

[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/multiformats/js-multihashing-async/badge.svg?branch=master)](https://coveralls.io/github/multiformats/js-multihashing-async?branch=master)
[![Travis CI](https://flat.badgen.net/travis/ipfs/js-multihashing-async)](https://travis-ci.com/ipfs/js-multihashing-async)
[![Dependency Status](https://david-dm.org/multiformats/js-multihashing-async.svg?style=flat-square)](https://david-dm.org/multiformats/js-multihashing-async)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multihashing-async.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multihashing-async)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/multiformats/js-multihashing-async/ci?label=ci&style=flat-square)](https://github.com/multiformats/js-multihashing-async/actions?query=branch%3Amaster+workflow%3Aci+)

@@ -13,0 +10,0 @@ > Use all the functions in [multihash](https://github.com/multiformats/multihash).

'use strict'
// @ts-ignore - no types available
const blake = require('blakejs')

@@ -24,2 +25,8 @@

// eslint-disable-next-line
/**
* @param {number} size
* @param {any} hf
* @returns {import('./types').Digest}
*/
const makeB2Hash = (size, hf) => async (data) => {

@@ -31,2 +38,5 @@ const ctx = hf.init(size, null)

/**
* @param {Record<number, import('./types').Digest>} table
*/
module.exports = (table) => {

@@ -33,0 +43,0 @@ for (let i = 0; i < 64; i++) {

'use strict'
const sha3 = require('js-sha3')
// @ts-ignore - no types available
const mur = require('murmurhash3js-revisited')

@@ -13,2 +14,6 @@ const { factory: sha } = require('./sha')

// eslint-disable-next-line
/**
* @param {string} algorithm
* @returns {import('./types').Digest}
*/
const hash = (algorithm) => async (data) => {

@@ -46,2 +51,3 @@ switch (algorithm) {

/** @type {import('./types').Digest} */
const identity = data => data

@@ -48,0 +54,0 @@

@@ -9,10 +9,16 @@ 'use strict'

/**
* Hash the given `buf` using the algorithm specified by `alg`.
* @param {Uint8Array} buf - The value to hash.
* @param {number|string} alg - The algorithm to use eg 'sha1'
* @typedef {import("./types").Digest} Digest
* @typedef {import("multihashes").HashName} HashName
*/
/**
* Hash the given `bytes` using the algorithm specified by `alg`.
*
* @param {Uint8Array} bytes - The value to hash.
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Uint8Array>}
*/
async function Multihashing (buf, alg, length) {
const digest = await Multihashing.digest(buf, alg, length)
async function Multihashing (bytes, alg, length) {
const digest = await Multihashing.digest(bytes, alg, length)
return multihash.encode(digest, alg, length)

@@ -27,10 +33,10 @@ }

/**
* @param {Uint8Array} buf - The value to hash.
* @param {number|string} alg - The algorithm to use eg 'sha1'
* @param {Uint8Array} bytes - The value to hash.
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Uint8Array>}
*/
Multihashing.digest = async (buf, alg, length) => {
Multihashing.digest = async (bytes, alg, length) => {
const hash = Multihashing.createHash(alg)
const digest = await hash(buf)
const digest = await hash(bytes)
return length ? digest.slice(0, length) : digest

@@ -42,17 +48,17 @@ }

*
* @param {string|number} alg - The algorithm to use eg 'sha1'
*
* @returns {function} - The hash function corresponding to `alg`
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @returns {Digest} - The hash function corresponding to `alg`
*/
Multihashing.createHash = function (alg) {
if (!alg) {
throw errcode(new Error('hash algorithm must be specified'), 'ERR_HASH_ALGORITHM_NOT_SPECIFIED')
const e = errcode(new Error('hash algorithm must be specified'), 'ERR_HASH_ALGORITHM_NOT_SPECIFIED')
throw e
}
alg = multihash.coerceCode(alg)
if (!Multihashing.functions[alg]) {
const code = multihash.coerceCode(alg)
if (!Multihashing.functions[code]) {
throw errcode(new Error(`multihash function '${alg}' not yet supported`), 'ERR_HASH_ALGORITHM_NOT_SUPPORTED')
}
return Multihashing.functions[alg]
return Multihashing.functions[code]
}

@@ -62,4 +68,6 @@

* Mapping of multihash codes to their hashing functions.
* @type {Object}
*
* @type {Record<number, Digest>}
*/
// @ts-ignore - most of those functions aren't typed
Multihashing.functions = {

@@ -105,4 +113,9 @@ // identity

Multihashing.validate = async (buf, hash) => {
const newHash = await Multihashing(buf, multihash.decode(hash).name)
/**
* @param {Uint8Array} bytes
* @param {Uint8Array} hash
* @returns {Promise<boolean>}
*/
Multihashing.validate = async (bytes, hash) => {
const newHash = await Multihashing(bytes, multihash.decode(hash).name)

@@ -109,0 +122,0 @@ return equals(hash, newHash)

@@ -5,7 +5,24 @@ /* eslint-disable require-await */

const multihash = require('multihashes')
/**
* @typedef {import('multihashes').HashName} HashName
* @typedef {import('./types').Digest} Digest
*/
const crypto = self.crypto || self.msCrypto
/**
* @type {Crypto}
*/
const crypto =
self.crypto ||
/** @type {typeof window.crypto} */
// @ts-ignore - unknown property
(self.msCrypto)
/**
*
* @param {Uint8Array} data
* @param {HashName} alg
* @returns {Promise<Uint8Array>}
*/
const digest = async (data, alg) => {
if (typeof self === 'undefined' || (!self.crypto && !self.msCrypto)) {
if (typeof self === 'undefined' || !crypto) {
throw new Error(

@@ -32,2 +49,6 @@ 'Please use a browser with webcrypto support and ensure the code has been delivered securely via HTTPS/TLS and run within a Secure Context'

module.exports = {
/**
* @param {HashName} alg
* @returns {Digest}
*/
factory: (alg) => async (data) => {

@@ -37,6 +58,11 @@ return digest(data, alg)

digest,
/**
* @param {Uint8Array} buf
* @param {HashName} alg
* @param {number} [length]
*/
multihashing: async (buf, alg, length) => {
const h = await digest(buf, alg, length)
const h = await digest(buf, alg)
return multihash.encode(h, alg, length)
}
}

@@ -6,2 +6,7 @@ /* eslint-disable require-await */

/**
* @typedef {import('multihashes').HashName} HashName
* @typedef {import('./types').Digest} Digest
*/
// Note that although this function doesn't do any asynchronous work, we mark

@@ -11,2 +16,8 @@ // the function as async because it must return a Promise to match the API

// eslint-disable-next-line
/**
* @param {Uint8Array} data
* @param {HashName} alg
* @returns {Promise<Uint8Array>}
*/
const digest = async (data, alg) => {

@@ -30,2 +41,6 @@ switch (alg) {

module.exports = {
/**
* @param {HashName} alg
* @returns {Digest}
*/
factory: (alg) => async (data) => {

@@ -35,6 +50,11 @@ return digest(data, alg)

digest,
/**
* @param {Uint8Array} buf
* @param {HashName} alg
* @param {number} [length]
*/
multihashing: async (buf, alg, length) => {
const h = await digest(buf, alg, length)
const h = await digest(buf, alg)
return multihash.encode(h, alg, length)
}
}
'use strict'
/**
* @param {number} number
* @returns {Uint8Array}
*/
const fromNumberTo32BitBuf = (number) => {

@@ -4,0 +8,0 @@ const bytes = new Uint8Array(4)

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