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

Use sha.js instead of full crypto in browser #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
},
"dependencies": {
"multihashes": "^0.2.0",
"webcrypto": "^0.1.0"
"sha.js": "^2.4.5",
"detect-node": "^2.0.3"
},
"devDependencies": {
"aegir": "^2.1.1",
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const isNode = require('detect-node')
const multihash = require('multihashes')
const crypto = require('webcrypto')
const createHash = (isNode ? require('crypto').createHash : require('sha.js'))

const mh = module.exports = Multihashing

Expand Down Expand Up @@ -43,13 +43,13 @@ mh.functions = {
}

function gsha1 () {
return crypto.createHash('sha1')
return createHash('sha1')
}

function gsha2_256 () {
return crypto.createHash('sha256')
return createHash('sha256')
}

function gsha2_512 () {
return crypto.createHash('sha512')
return createHash('sha512')
}