merkletreejs
Advanced tools
Comparing version 0.0.7 to 0.0.8
15
index.js
const reverse = require('buffer-reverse') | ||
const CryptoJS = require('crypto-js') | ||
@@ -32,3 +33,3 @@ /** | ||
constructor(leaves, hashAlgorithm, options={}) { | ||
this.hashAlgo = hashAlgorithm | ||
this.hashAlgo = bufferify(hashAlgorithm) | ||
this.leaves = leaves | ||
@@ -255,2 +256,14 @@ this.layers = [leaves] | ||
function bufferify (f) { | ||
return function (x) { | ||
const v = f(x) | ||
if (Buffer.isBuffer(v)) { | ||
return v | ||
} | ||
// crypto-js support | ||
return Buffer.from(f(CryptoJS.enc.Hex.parse(x.toString('hex'))).toString(CryptoJS.enc.Hex), 'hex') | ||
} | ||
} | ||
module.exports = MerkleTree |
{ | ||
"name": "merkletreejs", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Construct Merkle Trees and verify proofs", | ||
@@ -39,2 +39,3 @@ "main": "index.js", | ||
"crypto": "0.0.3", | ||
"crypto-js": "^3.1.9-1", | ||
"ethereumjs-util": "^5.1.2", | ||
@@ -48,4 +49,5 @@ "jsdoc-to-markdown": "^3.0.0", | ||
"dependencies": { | ||
"buffer-reverse": "^1.0.1" | ||
"buffer-reverse": "^1.0.1", | ||
"is-buffer": "^2.0.3" | ||
} | ||
} |
const test = require('tape') | ||
const {sha3} = require('ethereumjs-util') | ||
const crypto = require('crypto') | ||
const SHA256 = require('crypto-js/sha256') | ||
@@ -22,2 +23,13 @@ const MerkleTree = require('../') | ||
test('crypto-js - sha256', t => { | ||
t.plan(1) | ||
const leaves = ['a', 'b', 'c'].map(x => sha3(x)) | ||
const tree = new MerkleTree(leaves, SHA256) | ||
const root = '311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae' | ||
t.equal(tree.getRoot().toString('hex'), root) | ||
}) | ||
test('solidity sha3 [keccak-256]', t => { | ||
@@ -24,0 +36,0 @@ t.plan(20) |
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
254076
410
2
5
+ Addedis-buffer@^2.0.3
+ Addedis-buffer@2.0.5(transitive)