Socket
Socket
Sign inDemoInstall

multihashing-async

Package Overview
Dependencies
Maintainers
3
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 1.0.0 to 2.0.0

10

CHANGELOG.md

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

<a name="2.0.0"></a>
# [2.0.0](https://github.com/multiformats/js-multihashing-async/compare/v1.0.0...v2.0.0) (2020-08-03)
### Bug Fixes
* replace node buffers with uint8arrays ([#78](https://github.com/multiformats/js-multihashing-async/issues/78)) ([eb612f3](https://github.com/multiformats/js-multihashing-async/commit/eb612f3))
<a name="1.0.0"></a>

@@ -2,0 +12,0 @@ # [1.0.0](https://github.com/multiformats/js-multihashing-async/compare/v0.8.2...v1.0.0) (2020-06-23)

14

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

@@ -38,7 +38,7 @@ "keywords": [

"blakejs": "^1.1.0",
"buffer": "^5.4.3",
"err-code": "^2.0.0",
"js-sha3": "^0.8.0",
"multihashes": "^1.0.1",
"murmurhash3js-revisited": "^3.0.0"
"multihashes": "^2.0.0",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^1.0.0"
},

@@ -48,4 +48,2 @@ "devDependencies": {

"benchmark": "^2.1.4",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"sinon": "^9.0.2"

@@ -66,3 +64,2 @@ },

"Victor Bjelkholm <victorbjelkholm@gmail.com>",
"Mitar <mitar.github@tnode.com>",
"Richard Schneider <makaretu@gmail.com>",

@@ -77,4 +74,5 @@ "Volker Mische <volker.mische@gmail.com>",

"Matteo Collina <matteo.collina@gmail.com>",
"Mikeal Rogers <mikeal.rogers@gmail.com>"
"Mikeal Rogers <mikeal.rogers@gmail.com>",
"Mitar <mitar.github@tnode.com>"
]
}

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

# js-multihashing-async
# js-multihashing-async <!-- omit in toc -->

@@ -8,3 +8,3 @@ [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)

[![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)
[![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)

@@ -15,11 +15,11 @@ [![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)

## Lead Maintainer
## Lead Maintainer <!-- omit in toc -->
[Hugo Dias](https://github.com/hugomrdias)
### Notice
> This module is moving to async/await starting from 0.7.0.
### Notice <!-- omit in toc -->
> This module is moving to async/await starting from 0.7.0.
> The last minor version to support callbacks is 0.6.0, any backports will merged to the branch `callbacks` and released under `>0.6.0 <0.7.0`.
#### Wait, why, how is this different from Node `crypto`?
#### Wait, why, how is this different from Node `crypto`? <!-- omit in toc -->

@@ -34,17 +34,14 @@ This module just makes working with multihashes a bit nicer.

## Table of Contents
## Table of Contents <!-- omit in toc -->
* [Table of Contents](#table-of-contents)
* [Install](#install)
+ [In Node.js through npm](#in-nodejs-through-npm)
+ [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
+ [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
- [Gotchas](#gotchas)
* [Usage](#usage)
* [Examples](#examples)
+ [Multihash output](#multihash-output)
* [API](#api)
* [Maintainers](#maintainers)
* [Contribute](#contribute)
* [License](#license)
- [Install](#install)
- [In Node.js through npm](#in-nodejs-through-npm)
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
- [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
- [Usage](#usage)
- [Examples](#examples)
- [Multihash output](#multihash-output)
- [API](#api)
- [Contribute](#contribute)
- [License](#license)

@@ -84,6 +81,2 @@ ## Install

#### Gotchas
You will need to use Node.js `Buffer` API compatible, if you are running inside the browser, you can access it by `multihashing.Buffer` or you can install Feross's [Buffer](https://github.com/feross/buffer).
## Usage

@@ -93,12 +86,12 @@

const multihashing = require('multihashing-async')
const buf = Buffer.from('beep boop')
const bytes = new TextEncoder().encode('beep boop')
const mh = await multihashing(buf, 'sha1')
const mh = await multihashing(bytes, 'sha1')
// Use `.digest(...)` if you want only the hash digest (drops the prefix indicating the hash type).
const digest = await multihashing.digest(buf, 'sha1')
const digest = await multihashing.digest(bytes, 'sha1')
// Use `.createHash(...)` for the raw hash functions
const hash = multihashing.createHash('sha1')
const digest = await hash(buf)
const digest = await hash(bytes)
```

@@ -112,15 +105,15 @@

const multihashing = require('multihashing-async')
const buf = Buffer.from('beep boop')
const bytes = new TextEncoder().encode('beep boop')
const mh = await multihashing(buf, 'sha1')
const mh = await multihashing(bytes, 'sha1')
console.log(mh)
// => <Buffer 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
// => <Uint8Array 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
const mh = await multihashing(buf, 'sha2-256')
const mh = await multihashing(bytes, 'sha2-256')
console.log(mh)
// => <Buffer 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
// => <Uint8Array 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
const mh = await multihashing(buf, 'sha2-512')
const mh = await multihashing(bytes, 'sha2-512')
console.log(mh)
// => <Buffer 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>
// => <Uint8Array 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>
```

@@ -127,0 +120,0 @@

'use strict'
const { Buffer } = require('buffer')
const blake = require('blakejs')

@@ -28,3 +27,3 @@

hf.update(ctx, data)
return Buffer.from(hf.digest(ctx))
return hf.digest(ctx)
}

@@ -31,0 +30,0 @@

'use strict'
const { Buffer } = require('buffer')
const sha3 = require('js-sha3')

@@ -8,2 +7,3 @@ const mur = require('murmurhash3js-revisited')

const { fromNumberTo32BitBuf } = require('./utils')
const uint8ArrayFromString = require('uint8arrays/from-string')

@@ -17,23 +17,23 @@ // Note that although this function doesn't do any asynchronous work, we mark

case 'sha3-224':
return Buffer.from(sha3.sha3_224.arrayBuffer(data))
return new Uint8Array(sha3.sha3_224.arrayBuffer(data))
case 'sha3-256':
return Buffer.from(sha3.sha3_256.arrayBuffer(data))
return new Uint8Array(sha3.sha3_256.arrayBuffer(data))
case 'sha3-384':
return Buffer.from(sha3.sha3_384.arrayBuffer(data))
return new Uint8Array(sha3.sha3_384.arrayBuffer(data))
case 'sha3-512':
return Buffer.from(sha3.sha3_512.arrayBuffer(data))
return new Uint8Array(sha3.sha3_512.arrayBuffer(data))
case 'shake-128':
return Buffer.from(sha3.shake128.create(128).update(data).arrayBuffer())
return new Uint8Array(sha3.shake128.create(128).update(data).arrayBuffer())
case 'shake-256':
return Buffer.from(sha3.shake256.create(256).update(data).arrayBuffer())
return new Uint8Array(sha3.shake256.create(256).update(data).arrayBuffer())
case 'keccak-224':
return Buffer.from(sha3.keccak224.arrayBuffer(data))
return new Uint8Array(sha3.keccak224.arrayBuffer(data))
case 'keccak-256':
return Buffer.from(sha3.keccak256.arrayBuffer(data))
return new Uint8Array(sha3.keccak256.arrayBuffer(data))
case 'keccak-384':
return Buffer.from(sha3.keccak384.arrayBuffer(data))
return new Uint8Array(sha3.keccak384.arrayBuffer(data))
case 'keccak-512':
return Buffer.from(sha3.keccak512.arrayBuffer(data))
return new Uint8Array(sha3.keccak512.arrayBuffer(data))
case 'murmur3-128':
return Buffer.from(mur.x64.hash128(data), 'hex')
return uint8ArrayFromString(mur.x64.hash128(data), 'base16')
case 'murmur3-32':

@@ -47,3 +47,3 @@ return fromNumberTo32BitBuf(mur.x86.hash32(data))

const identity = data => Buffer.from(data)
const identity = data => data

@@ -50,0 +50,0 @@ module.exports = {

'use strict'
const { Buffer } = require('buffer')
const errcode = require('err-code')
const multihash = require('multihashes')
const crypto = require('./crypto')
const equals = require('uint8arrays/equals')
/**
* Hash the given `buf` using the algorithm specified by `alg`.
* @param {Buffer} buf - The value to hash.
* @param {Uint8Array} buf - The value to hash.
* @param {number|string} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Buffer>}
* @returns {Promise<Uint8Array>}
*/

@@ -21,9 +21,2 @@ async function Multihashing (buf, alg, length) {

/**
* The `buffer` module for easy use in the browser.
*
* @type {Buffer}
*/
Multihashing.Buffer = Buffer // for browser things
/**
* Expose multihash itself, to avoid silly double requires.

@@ -34,6 +27,6 @@ */

/**
* @param {Buffer} buf - The value to hash.
* @param {Uint8Array} buf - The value to hash.
* @param {number|string} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Buffer>}
* @returns {Promise<Uint8Array>}
*/

@@ -113,5 +106,5 @@ Multihashing.digest = async (buf, alg, length) => {

return Buffer.compare(hash, newHash) === 0
return equals(hash, newHash)
}
module.exports = Multihashing
/* eslint-disable require-await */
'use strict'
const { Buffer } = require('buffer')
const multihash = require('multihashes')

@@ -17,10 +16,10 @@

case 'sha1':
return Buffer.from(await crypto.subtle.digest({ name: 'SHA-1' }, data))
return new Uint8Array(await crypto.subtle.digest({ name: 'SHA-1' }, data))
case 'sha2-256':
return Buffer.from(await crypto.subtle.digest({ name: 'SHA-256' }, data))
return new Uint8Array(await crypto.subtle.digest({ name: 'SHA-256' }, data))
case 'sha2-512':
return Buffer.from(await crypto.subtle.digest({ name: 'SHA-512' }, data))
return new Uint8Array(await crypto.subtle.digest({ name: 'SHA-512' }, data))
case 'dbl-sha2-256': {
const d = await crypto.subtle.digest({ name: 'SHA-256' }, data)
return Buffer.from(await crypto.subtle.digest({ name: 'SHA-256' }, d))
return new Uint8Array(await crypto.subtle.digest({ name: 'SHA-256' }, d))
}

@@ -27,0 +26,0 @@ default:

'use strict'
const { Buffer } = require('buffer')
const fromNumberTo32BitBuf = (number) => {
const bytes = new Array(4)
const bytes = new Uint8Array(4)

@@ -13,3 +11,3 @@ for (let i = 0; i < 4; i++) {

return Buffer.from(bytes)
return bytes
}

@@ -16,0 +14,0 @@

Sorry, the diff of this file is too big to display

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