browserify-sha3
Advanced tools
Comparing version 0.0.3 to 0.0.4
22
index.js
const Sha3 = require('js-sha3') | ||
const Buffer = require('safe-buffer').Buffer | ||
const hashLengths = [ 224, 256, 384, 512 ] | ||
var hash = function (bitcount) { | ||
if (bitcount !== undefined && hashLengths.indexOf(bitcount) == -1) | ||
const hash = function (bitcount) { | ||
if (bitcount !== undefined && hashLengths.indexOf(bitcount) === -1) { | ||
throw new Error('Unsupported hash length') | ||
} | ||
this.content = [] | ||
@@ -13,8 +15,9 @@ this.bitcount = bitcount ? 'keccak_' + bitcount : 'keccak_512' | ||
hash.prototype.update = function (i) { | ||
if (Buffer.isBuffer(i)) | ||
if (Buffer.isBuffer(i)) { | ||
this.content.push(i) | ||
else if (typeof i === 'string') | ||
} else if (typeof i === 'string') { | ||
this.content.push(new Buffer(i)) | ||
else | ||
} else { | ||
throw new Error('Unsupported argument to update') | ||
} | ||
return this | ||
@@ -24,9 +27,10 @@ } | ||
hash.prototype.digest = function (encoding) { | ||
var result = Sha3[this.bitcount](Buffer.concat(this.content)) | ||
if (encoding === 'hex') | ||
const result = Sha3[this.bitcount](Buffer.concat(this.content)) | ||
if (encoding === 'hex') { | ||
return result | ||
else if (encoding === 'binary' || encoding === undefined) | ||
} else if (encoding === 'binary' || encoding === undefined) { | ||
return new Buffer(result, 'hex').toString('binary') | ||
else | ||
} else { | ||
throw new Error('Unsupported encoding for digest: ' + encoding) | ||
} | ||
} | ||
@@ -33,0 +37,0 @@ |
{ | ||
"name": "browserify-sha3", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "node-sha3 compatability for browserify", | ||
@@ -28,4 +28,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"js-sha3": "^0.6.1" | ||
"js-sha3": "^0.6.1", | ||
"safe-buffer": "^5.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4580
108
2
+ Addedsafe-buffer@^5.1.1
+ Addedsafe-buffer@5.2.1(transitive)