Giter VIP home page Giter VIP logo

js-multihashing-async's Introduction

⛔️ DEPRECATED: This module has been superseded by the multiformats module

js-multihashing-async

codecov GitHub Workflow Status

Use all the functions in multihash.

Lead Maintainer

Hugo Dias

Notice

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?

This module just makes working with multihashes a bit nicer. js-multihash is only for encoding/decoding multihashes, and does not depend on other libs. This module will depend on various implementations for each hash. It currently uses crypto and sha3 in Node.js. In the browser webcrypto and browserify-sha3 are used.

Table of Contents

Install

In Node.js through npm

$ npm install --save multihashing-async
const multihashing = require('multihashing-async')

Use in a browser with browserify, webpack or any other bundler

The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.

const multihashing = require('multihashing-async')

Use in a browser Using a script tag

Loading this module through a script tag will make the multihashing obj available in the global namespace.

<script src="https://unpkg.com/multihashing-async/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/multihashing-async/dist/index.js"></script>

Usage

const multihashing = require('multihashing-async')
const bytes = new TextEncoder().encode('beep boop')

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(bytes, 'sha1')

// Use `.createHash(...)` for the raw hash functions
const hash = multihashing.createHash('sha1')
const digest = await hash(bytes)

Examples

Multihash output

const multihashing = require('multihashing-async')
const bytes = new TextEncoder().encode('beep boop')

const mh = await multihashing(bytes, 'sha1')
console.log(mh)
// => <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(bytes, 'sha2-256')
console.log(mh)
// => <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(bytes, 'sha2-512')
console.log(mh)
// => <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 ...>

API

https://multiformats.github.io/js-multihashing-async/

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Protocol Labs Inc.

js-multihashing-async's People

Contributors

achingbrain avatar aknuds1 avatar daviddias avatar dependabot-preview[bot] avatar dignifiedquire avatar dryajov avatar gozala avatar harlantwood avatar hugomrdias avatar jacobheun avatar jbenet avatar lidel avatar mcollina avatar mikeal avatar mitar avatar npmcdn-to-unpkg-bot avatar pgte avatar richardlitt avatar richardschneider avatar satazor avatar vasco-santos avatar victorb avatar vmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-multihashing-async's Issues

Using import() function for code splitting

In order to reduce the impact not the default bundle size, each method should use the import() function to get the crypto library it needs. Since all the methods are already async this wouldn’t require an API change and would result in some very code splitting for the consumers.

feature: validation

This library effectively means I never have to look up a hashing function in order to create a multihash, but I still have to go and lookup a validation function in order to validate block data against that hash :(

Exposing a validation function that accepted a multihash and a buffer and returned true/false would be fantastic :)

An in-range update of aegir is breaking the build 🚨

Version 9.3.2 of aegir just got published.

Branch Build failing 🚨
Dependency aegir
Current Version 9.3.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As aegir is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • ci/circleci Your tests passed on CircleCI! Details

  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

  • coverage/coveralls First build on greenkeeper/aegir-9.3.2 at 96.875% Details

Release Notes v9.3.2

Features

  • deps: use new browserify-zlib-next package (68810c1)
Commits

The new version differs by 5 commits .

  • e501ba3 chore: release version v9.3.2
  • 73d2f9c chore: update contributors
  • 68810c1 feat(deps): use new browserify-zlib-next package
  • a1a0753 Merge pull request #93 from dignifiedquire/greenkeeper/update-all
  • f3e6620 chore(package): update dependencies

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Possible javascript digest fallbacks for insecure (HTTP) sites

I am using js-ipld-dag-cbor which references this package. I would like to be able to calculate hashes even on insecure (HTTP) websites.

When js-multihashing-async tries to access window.crypto.subtle it throws on error in Brave, but works fine in Firefox. Chrome on Android also throws an error.

Is it possible to fallback on a browser implementation to avoid the HTTPS requirement?

Other issue: ipld/js-ipld-dag-cbor#114

Using SPHINCS+ sha256-256f in IPLD Graph Data

I posted this question at discuss and would like to contribute code in this library to enable this type of encryption in multiformats - and was directed here. This is a tracking issue that should be closed if my pull-request is merged or if the approach is inappropriate. Discussion is welcome!

An in-range update of multihashes is breaking the build 🚨

Version 0.4.4 of multihashes just got published.

Branch Build failing 🚨
Dependency multihashes
Current Version 0.4.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As multihashes is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • ci/circleci Your tests passed on CircleCI! Details

  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 4 commits .

  • 78ef8de chore: release version v0.4.4
  • f039a2f chore: update contributors
  • f6da734 chore: release version v0.3.4
  • e5c581c chore: update aegir, fix new linting

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Make sha3 an optional dependency

In some environments sha3 won't compile. We should make it optional and fall back to the pure JavaScript version instead of failing in this case.

Multihashing.functions is missing dbl-sha2-256

js-multihashing-async has its own set of functions that need to be updated if a new hash algorithm is added. For Bitcoin/Zcash support dbl-sha2-256 was added. That one needs to be added.

Question? Bug? About `Multihashing` func

Hi there! I'm working on a large project, where multihashing gets depended on. I'm not sure if this is a bug isolated in this package, or if it's introduced from some outer-dep (I don't expect this to be true but in this case, its [email protected]).

The Multihashing.digest func, in the code comments, is supposed to return a Uint8Array. yet when I log digest instanceof Uint8Array, it returns false. This causes the following multihash.encode call to throw the error: digest should be a Uint8Array

The alg param in this instance is 0x18 or shake-128

For more clarity:

async function Multihashing (buf, alg, length) {
  console.log('buff instance of Uint8Array? ', buf instanceof Uint8Array) // => logs true
  const digest = await Multihashing.digest(buf, alg, length)
  console.log('digest instance of Uint8Array?', digest instanceof Uint8Array) // => logs false
  return multihash.encode(digest, alg, length)
}

This is obviously not going to play nicely with this line

Why the requirement on webcrypto?

It would be fairly simple to import native-crypto or a similar library that falls back on js libraries for crypto in the absence of webcrypto; in the meantime, js-ipfs doesn't work in a webworker in safari, and in other bad browsers.

The npm distribution is not transpiled to es5

The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.

This does not seem to be the case. When I look through the code in the dist folder, I do see a bunch of let statements in there.

A manifestation of the problem for me is that building an app made via create-react-app fails with the following error:

Failed to compile.

Failed to minify the code from this file: 

 	./node_modules/multihashing-async/src/index.js:28 

I believe the minifier is expecting transpiled ES5 code.

As a work-around, I could just bring the js-multihashing-async into my own codebase so that my transpiler will transpile it, but this is not ideal and not the accepted best practice. Furthermore, I'm not even using the lib directly. It's a dependency of libp2p-crypto.

An in-range update of aegir is breaking the build 🚨

Version 9.3.1 of aegir just got published.

Branch Build failing 🚨
Dependency aegir
Current Version 9.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As aegir is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • ci/circleci Your tests passed on CircleCI! Details

  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

  • coverage/coveralls First build on greenkeeper/aegir-9.3.1 at 96.875% Details

Release Notes v9.3.1

Bug Fixes

  • deps: add correct browserify-zlib dependency (78b8cbd)
Commits

The new version differs by 7 commits .

  • a26305b chore: release version v9.3.1
  • ecddaa7 chore: update contributors
  • 5f92b68 Merge pull request #89 from dignifiedquire/greenkeeper-gulp-filter-5.0.0
  • a556f28 Merge pull request #92 from dignifiedquire/greenkeeper-webpack-merge-2.4.0
  • 78b8cbd fix(deps): add correct browserify-zlib dependency
  • cbc1abd chore(package): update webpack-merge to version 2.4.0
  • f178dca chore(package): update gulp-filter to version 5.0.0

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

SHAKE digest size

The shake-128 and shake-256 digests size are double what they should be. From examining the NIST test vectors, shake-128 is 16 bytes (128 bits) and shake-256 is 32 bytes (256 bits).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.