Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Async Crypto Endeavour #1

Merged
merged 9 commits into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ build/Release
node_modules

dist
lib
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- stable

# Make sure we have new NPM.
matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env:
- SAUCE=true
- CXX=g++-4.8
- node_js: stable
env: CXX=g++-4.8

before_install:
- npm install -g npm

Expand All @@ -21,11 +27,8 @@ before_script:
after_success:
- npm run coverage-publish

env:
- CXX=g++-4.8

addons:
firefox: 'latest'
firefox: latest
apt:
sources:
- ubuntu-toolchain-r-test
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
[![Travis CI](https://travis-ci.org/multiformats/js-multihashing-async.svg?branch=master)](https://travis-ci.org/multiformats/js-multihashing-async)
[![Circle CI](https://circleci.com/gh/multiformats/js-multihashing-async.svg?style=svg)](https://circleci.com/gh/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)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/ipfs-js-mh-async.svg)](https://saucelabs.com/u/ipfs-js-mh-async)

> Use all the functions in [multihash](https://github.com/multiformats/multihash).

Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
"name": "multihashing-async",
"version": "0.1.0",
"description": "multiple hash functions",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"browser": {
"./src/crypto.js": "./src/crypto-browser.js",
"./lib/crypto.js": "./lib/crypto-browser.js"
"./src/crypto.js": "./src/crypto-browser.js"
},
"scripts": {
"test": "PHANTOM=off aegir-test",
"test:browser": "PHANTOM=off aegir-test browser",
"test": "aegir-test",
"test:browser": "aegir-test browser",
"test:node": "aegir-test node",
"lint": "aegir-lint",
"release": "PHANTOM=off aegir-release",
"release-minor": "PHANTOM=off aegir-release minor",
"release-major": "PHANTOM=off aegir-release major",
"release": "aegir-release",
"release-minor": "aegir-release minor",
"release-major": "aegir-release major",
"build": "aegir-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish",
Expand All @@ -39,14 +37,18 @@
},
"dependencies": {
"browserify-sha3": "0.0.2",
"multihashes": "^0.2.0",
"multihashes": "^0.2.2",
"nodeify": "^1.0.0",
"sha3": "^1.2.0"
},
"devDependencies": {
"aegir": "^8.1.0",
"benchmark": "^2.1.1",
"aegir": "^9.0.1",
"benchmark": "^2.1.2",
"chai": "^3.5.0",
"pre-commit": "^1.1.2"
"pre-commit": "^1.1.3"
},
"engines": {
"node": ">=4.0.0"
},
"homepage": "https://github.com/multiformats/js-multihashing-async",
"contributors": [
Expand All @@ -58,4 +60,4 @@
"Richard Littauer <richard.littauer@gmail.com>",
"npm-to-cdn-bot (by Forbes Lindesay) <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
8 changes: 5 additions & 3 deletions src/crypto-browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const SHA3 = require('browserify-sha3')
const nodeify = require('nodeify')

const webCrypto = getWebCrypto()

Expand Down Expand Up @@ -34,9 +35,10 @@ function webCryptoHash (type) {
return
}

return res.then((arrbuf) => {
callback(null, new Buffer(new Uint8Array(arrbuf)))
}).catch((err) => callback(err))
nodeify(
res.then((raw) => new Buffer(new Uint8Array(raw))),
callback
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the err?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's how nodeify works: https://www.npmjs.com/package/nodeify It will call callback with err if it catches one, or with the result if no err is caught

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is different though, examples in the npm package show a complete wrap of the Promise, here we are waiting the promise to resolve to convert it to a buffer and then calling the callback through nodeify.

It is missing the res.catch(err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we create a new promise using the then which is passed as the first arg to nodeify and the callback is passed as the second argument, as described in the nodeify docs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, the return values are promises

}
}

Expand Down