From ffad24babfdbcd58a1c8400a72572fafd27a7d44 Mon Sep 17 00:00:00 2001 From: sethfork Date: Sun, 30 Jun 2019 02:39:53 -0400 Subject: [PATCH] Replace sha3 with keccak; Update ethereumjs-util --- README.md | 6 +-- dist/index.d.ts | 6 +-- dist/index.js | 6 +-- index.ts | 32 ++++++++-------- package-lock.json | 83 +++++++++++++++++++++++------------------ package.json | 2 +- test/merkletree.test.js | 72 +++++++++++++++++------------------ 7 files changed, 109 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index c25b88a..c0fd896 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ function sha256(data) { return crypto.createHash('sha256').update(data).digest() } -const leaves = ['a', 'b', 'c'].map(x => sha3(x)) +const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256) ``` @@ -323,8 +323,8 @@ const proof = tree.getProof(leaves[2]) *__example__*: ```js -const leaves = ['a', 'b', 'a'].map(x => sha3(x)) -const tree = new MerkleTree(leaves, sha3) +const leaves = ['a', 'b', 'a'].map(x => keccak(x)) +const tree = new MerkleTree(leaves, keccak) const proof = tree.getProof(leaves[2], 2) ``` diff --git a/dist/index.d.ts b/dist/index.d.ts index f33a3e4..ae35a87 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -43,7 +43,7 @@ export declare class MerkleTree { * return crypto.createHash('sha256').update(data).digest() *} * - *const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + *const leaves = ['a', 'b', 'c'].map(x => keccak(x)) * *const tree = new MerkleTree(leaves, sha256) *``` @@ -96,8 +96,8 @@ export declare class MerkleTree { * * @example *```js - *const leaves = ['a', 'b', 'a'].map(x => sha3(x)) - *const tree = new MerkleTree(leaves, sha3) + *const leaves = ['a', 'b', 'a'].map(x => keccak(x)) + *const tree = new MerkleTree(leaves, keccak) *const proof = tree.getProof(leaves[2], 2) *``` */ diff --git a/dist/index.js b/dist/index.js index 797bccf..40bfed7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -25,7 +25,7 @@ var MerkleTree = /** @class */ (function () { * return crypto.createHash('sha256').update(data).digest() *} * - *const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + *const leaves = ['a', 'b', 'c'].map(x => keccak(x)) * *const tree = new MerkleTree(leaves, sha256) *``` @@ -159,8 +159,8 @@ var MerkleTree = /** @class */ (function () { * * @example *```js - *const leaves = ['a', 'b', 'a'].map(x => sha3(x)) - *const tree = new MerkleTree(leaves, sha3) + *const leaves = ['a', 'b', 'a'].map(x => keccak(x)) + *const tree = new MerkleTree(leaves, keccak) *const proof = tree.getProof(leaves[2], 2) *``` */ diff --git a/index.ts b/index.ts index 29eafda..d87a409 100644 --- a/index.ts +++ b/index.ts @@ -24,7 +24,7 @@ interface Options { */ export class MerkleTree { duplicateOdd: boolean - hashAlgo: (value:any) => any + hashAlgo: (value: any) => any hashLeaves: boolean isBitcoinTree: boolean leaves: any[] @@ -50,12 +50,12 @@ export class MerkleTree { * return crypto.createHash('sha256').update(data).digest() *} * - *const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + *const leaves = ['a', 'b', 'c'].map(x => keccak(x)) * *const tree = new MerkleTree(leaves, sha256) *``` */ - constructor(leaves, hashAlgorithm, options:Options={} as any) { + constructor(leaves, hashAlgorithm, options: Options = {} as any) { this.isBitcoinTree = !!options.isBitcoinTree this.hashLeaves = !!options.hashLeaves this.sortLeaves = !!options.sortLeaves @@ -92,9 +92,9 @@ export class MerkleTree { for (let i = 0; i < nodes.length; i += 2) { - if (i+1 === nodes.length) { + if (i + 1 === nodes.length) { if (nodes.length % 2 === 1) { - let data = nodes[nodes.length-1] + let data = nodes[nodes.length - 1] let hash = data // is bitcoin tree @@ -183,7 +183,7 @@ export class MerkleTree { *``` */ getRoot() { - return this.layers[this.layers.length-1][0] || Buffer.from([]) + return this.layers[this.layers.length - 1][0] || Buffer.from([]) } // TODO: documentation @@ -206,8 +206,8 @@ export class MerkleTree { * * @example *```js - *const leaves = ['a', 'b', 'a'].map(x => sha3(x)) - *const tree = new MerkleTree(leaves, sha3) + *const leaves = ['a', 'b', 'a'].map(x => keccak(x)) + *const tree = new MerkleTree(leaves, keccak) *const proof = tree.getProof(leaves[2], 2) *``` */ @@ -235,8 +235,8 @@ export class MerkleTree { for (let i = 0; i < this.layers.length - 1; i++) { const layer = this.layers[i] const isRightNode = index % 2 - const pairIndex = (isRightNode ? index - 1: index) - const position = isRightNode ? 'left': 'right' + const pairIndex = (isRightNode ? index - 1 : index) + const position = isRightNode ? 'left' : 'right' if (pairIndex < layer.length) { proof.push({ @@ -245,7 +245,7 @@ export class MerkleTree { } // set index to parent index - index = (index / 2)|0 + index = (index / 2) | 0 } return proof @@ -260,13 +260,13 @@ export class MerkleTree { if (pairIndex < layer.length) { proof.push({ - position: isRightNode ? 'left': 'right', + position: isRightNode ? 'left' : 'right', data: layer[pairIndex] }) } // set index to parent index - index = (index / 2)|0 + index = (index / 2) | 0 } @@ -406,8 +406,8 @@ export class MerkleTree { } } -function bufferToHex(value:Buffer) { - return '0x'+value.toString('hex') +function bufferToHex(value: Buffer) { + return '0x' + value.toString('hex') } function bufferify(x) { @@ -425,7 +425,7 @@ function bufferify(x) { return x } -function bufferifyFn (f) { +function bufferifyFn(f) { return function (x) { const v = f(x) if (Buffer.isBuffer(v)) { diff --git a/package-lock.json b/package-lock.json index 31743f1..d79c1a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "merkletreejs", - "version": "0.1.4", + "version": "0.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -206,10 +206,13 @@ } }, "bindings": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", - "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==", - "dev": true + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "requires": { + "file-uri-to-path": "1.0.0" + } }, "bip66": { "version": "1.1.5", @@ -518,9 +521,9 @@ } }, "elliptic": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", - "integrity": "sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz", + "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==", "dev": true, "requires": { "bn.js": "^4.4.0", @@ -598,14 +601,14 @@ "dev": true }, "ethereumjs-util": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", - "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz", + "integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==", "dev": true, "requires": { "bn.js": "^4.11.0", "create-hash": "^1.1.2", - "ethjs-util": "^0.1.3", + "ethjs-util": "0.1.6", "keccak": "^1.0.2", "rlp": "^2.0.0", "safe-buffer": "^5.1.1", @@ -662,6 +665,12 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true + }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -794,13 +803,13 @@ } }, "hash.js": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.4.tgz", - "integrity": "sha512-A6RlQvvZEtFS5fLU43IDu0QUmBy+fDO9VMdTXvufKwIkt/rFfvICAViCax5fbDO4zdNzaC3/27ZhKUok5bAJyw==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", "dev": true, "requires": { "inherits": "^2.0.3", - "minimalistic-assert": "^1.0.0" + "minimalistic-assert": "^1.0.1" } }, "highlight.js": { @@ -1085,13 +1094,14 @@ "optional": true }, "md5.js": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", - "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=", + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", + "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", "dev": true, "requires": { "hash-base": "^3.0.0", - "inherits": "^2.0.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.1.2" } }, "merkle-lib": { @@ -1142,9 +1152,9 @@ "dev": true }, "nan": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", - "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", "dev": true }, "nwsapi": { @@ -1393,11 +1403,12 @@ } }, "rlp": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.1.0.tgz", - "integrity": "sha512-93U7IKH5j7nmXFVg19MeNBGzQW5uXW1pmCuKY8veeKIhYTE32C2d0mOegfiIAfXcHOKJjjPlJisn8iHDF5AezA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.3.tgz", + "integrity": "sha512-l6YVrI7+d2vpW6D6rS05x2Xrmq8oW7v3pieZOJKBEdjuTF4Kz/iwk55Zyh1Zaz+KOB2kC8+2jZlp2u9L4tTzCQ==", "dev": true, "requires": { + "bn.js": "^4.11.1", "safe-buffer": "^5.1.1" } }, @@ -1420,19 +1431,19 @@ "dev": true }, "secp256k1": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.5.0.tgz", - "integrity": "sha512-e5QIJl8W7Y4tT6LHffVcZAxJjvpgE5Owawv6/XCYPQljE9aP2NFFddQ8OYMKhdLshNu88FfL3qCN3/xYkXGRsA==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.7.1.tgz", + "integrity": "sha512-1cf8sbnRreXrQFdH6qsg2H71Xw91fCCS9Yp021GnUNJzWJS/py96fS4lHbnTnouLp08Xj6jBoBB6V78Tdbdu5g==", "dev": true, "requires": { - "bindings": "^1.2.1", - "bip66": "^1.1.3", - "bn.js": "^4.11.3", - "create-hash": "^1.1.2", + "bindings": "^1.5.0", + "bip66": "^1.1.5", + "bn.js": "^4.11.8", + "create-hash": "^1.2.0", "drbg.js": "^1.0.1", - "elliptic": "^6.2.3", - "nan": "^2.2.1", - "safe-buffer": "^5.1.0" + "elliptic": "^6.4.1", + "nan": "^2.14.0", + "safe-buffer": "^5.1.2" } }, "sha.js": { diff --git a/package.json b/package.json index 97d9d64..53b6b3d 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "devDependencies": { "@types/node": "^11.12.1", "crypto": "0.0.3", - "ethereumjs-util": "^5.1.2", + "ethereumjs-util": "6.1.0", "sha1": "^1.1.1", "tape": "^4.9.2", "typedoc": "^0.14.2", diff --git a/test/merkletree.test.js b/test/merkletree.test.js index a5af767..4360f9b 100644 --- a/test/merkletree.test.js +++ b/test/merkletree.test.js @@ -1,5 +1,5 @@ const test = require('tape') -const {sha3} = require('ethereumjs-util') +const {keccak} = require('ethereumjs-util') const crypto = require('crypto') const CryptoJS = require('crypto-js') const SHA256 = require('crypto-js/sha256') @@ -10,20 +10,20 @@ const { MerkleTree } = require('../') const sha256 = (data) => crypto.createHash('sha256').update(data).digest() -test('sha256 with sha3 leaves', t => { +test('sha256 with keccak leaves', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256) const root = '311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae' t.equal(tree.getRoot().toString('hex'), root) }) -test('sha256 with sha3 leaves with duplicate odd option', t => { +test('sha256 with keccak leaves with duplicate odd option', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256, {duplicateOdd: true}) const root = 'bcdd0f60308db788712205115fe4273bfda49fa0925611fee765a63df9ab96a1' @@ -33,7 +33,7 @@ test('sha256 with sha3 leaves with duplicate odd option', t => { test('crypto-js - sha256', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, SHA256) const root = '311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae' @@ -50,21 +50,21 @@ test('sha256 with sort pairs option', t => { t.equal(tree.getRoot().toString('hex'), root) }) -test('sha3 with sort leaves and sort pairs option', t => { +test('keccak with sort leaves and sort pairs option', t => { t.plan(1) - const leaves = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].map(x => sha3(x)) - const tree = new MerkleTree(leaves, sha3, {sortLeaves: true, sortPairs: true}) + const leaves = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].map(x => keccak(x)) + const tree = new MerkleTree(leaves, keccak, {sortLeaves: true, sortPairs: true}) const root = '60219f87561939610b484575e45c6e81156a53b86d7cd16640d930d14f21758e' t.equal(tree.getRoot().toString('hex'), root) }) -test('sha3 with sort option', t => { +test('keccak with sort option', t => { t.plan(1) - const leaves = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].map(x => sha3(x)) - const tree = new MerkleTree(leaves, sha3, {sort: true}) + const leaves = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].map(x => keccak(x)) + const tree = new MerkleTree(leaves, keccak, {sort: true}) const root = '60219f87561939610b484575e45c6e81156a53b86d7cd16640d930d14f21758e' t.equal(tree.getRoot().toString('hex'), root) @@ -100,7 +100,7 @@ test('sha256 with hash leaves option and duplicate odd option', t => { t.equal(tree.getRoot().toString('hex'), root) }) -test('crypto-js - sha256 with sha3 leaves', t => { +test('crypto-js - sha256 with keccak leaves', t => { t.plan(1) const leaves = ['a', 'b', 'c'].map(SHA256) @@ -110,10 +110,10 @@ test('crypto-js - sha256 with sha3 leaves', t => { t.equal(tree.getRoot().toString('hex'), root) }) -test('crypto-js - sha256 with sha3 leaves and duplicate odd option', t => { +test('crypto-js - sha256 with keccak leaves and duplicate odd option', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, SHA256, {duplicateOdd: true}) const root = 'bcdd0f60308db788712205115fe4273bfda49fa0925611fee765a63df9ab96a1' @@ -141,20 +141,20 @@ test('crypto-js - SHA256 with SHA3 leaves', t => { t.equal(tree.getRoot().toString('hex'), root) }) -test('crypto-js - SHA256 with sha3 leaves and duplicate odd option', t => { +test('crypto-js - SHA256 with keccak leaves and duplicate odd option', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, SHA256, {duplicateOdd: true}) const root = 'bcdd0f60308db788712205115fe4273bfda49fa0925611fee765a63df9ab96a1' t.equal(tree.getRoot().toString('hex'), root) }) -test('solidity sha3 [keccak-256]', t => { +test('solidity keccak [keccak-256]', t => { t.plan(20) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const a_hash = '3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb' const b_hash = 'b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510' @@ -162,11 +162,11 @@ test('solidity sha3 [keccak-256]', t => { t.deepEqual(leaves.map(x => x.toString('hex')), [a_hash, b_hash, c_hash]) - const tree = new MerkleTree(leaves, sha3) + const tree = new MerkleTree(leaves, keccak) const layers = tree.getLayers().slice(1) // no leaves - const layer_1 = sha3(Buffer.concat([leaves[0], leaves[1]])).toString('hex') + const layer_1 = keccak(Buffer.concat([leaves[0], leaves[1]])).toString('hex') t.equal(layers[0][0].toString('hex'), layer_1) t.equal(layers[0][1].toString('hex'), c_hash) @@ -200,10 +200,10 @@ test('solidity sha3 [keccak-256]', t => { t.equal(tree.verify(proof_2, leaves[2], root), true) }) -test('solidity sha3 [keccak-256] with duplicate odd option', t => { +test('solidity keccak [keccak-256] with duplicate odd option', t => { t.plan(20) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const a_hash = '3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb' const b_hash = 'b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510' @@ -211,10 +211,10 @@ test('solidity sha3 [keccak-256] with duplicate odd option', t => { t.deepEqual(leaves.map(x => x.toString('hex')), [a_hash, b_hash, c_hash]) - const tree = new MerkleTree(leaves, sha3, {duplicateOdd: true}) + const tree = new MerkleTree(leaves, keccak, {duplicateOdd: true}) const layers = tree.getLayers().slice(1) // no leaves - const layer_1 = sha3(Buffer.concat([leaves[0], leaves[1]])).toString('hex') - const layer_2 = sha3(Buffer.concat([leaves[2], leaves[2]])).toString('hex') + const layer_1 = keccak(Buffer.concat([leaves[0], leaves[1]])).toString('hex') + const layer_2 = keccak(Buffer.concat([leaves[2], leaves[2]])).toString('hex') t.equal(layers[0][0].toString('hex'), layer_1) t.equal(layers[0][1].toString('hex'), layer_2) @@ -247,22 +247,22 @@ test('solidity sha3 [keccak-256] with duplicate odd option', t => { t.equal(tree.verify(proof_2, layer_2, root), true) }) -test('solidity sha3 [keccak-256] with duplicate leaves', t => { +test('solidity keccak [keccak-256] with duplicate leaves', t => { t.plan(5) - const leaves = ['a', 'b', 'a'].map(x => sha3(x)) + const leaves = ['a', 'b', 'a'].map(x => keccak(x)) const a_hash = '3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb' const b_hash = 'b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510' - const tree = new MerkleTree(leaves, sha3) + const tree = new MerkleTree(leaves, keccak) t.deepEqual(leaves.map(x => x.toString('hex')), [a_hash, b_hash, a_hash]) const root = Buffer.from('b8912f7269068901f231a965adfefbc10f0eedcfa61852b103efd54dac7db3d7', 'hex') t.equal(tree.getRoot().toString('hex'), root.toString('hex')) - const layer_1 = sha3(Buffer.concat([leaves[0], leaves[1]])).toString('hex') + const layer_1 = keccak(Buffer.concat([leaves[0], leaves[1]])).toString('hex') const proof_0 = tree.getProof(leaves[2], 2) t.equal(proof_0.length, 1) @@ -389,9 +389,9 @@ test('sha-256 with option.isBitcoinTree', t => { t.equal(tree.verify(proof_0, leaves[0], root), true) }) -test('sha3 - hex strings', t => { +test('keccak - hex strings', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x).toString('hex')) + const leaves = ['a', 'b', 'c'].map(x => keccak(x).toString('hex')) const tree = new MerkleTree(leaves, SHA256) const root = '311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae' t.equal(tree.getRoot().toString('hex'), root) @@ -473,7 +473,7 @@ test('sha1', t => { test('getLayersAsObject', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256) const obj = tree.getLayersAsObject() t.deepEqual(obj, { @@ -492,7 +492,7 @@ test('getLayersAsObject', t => { test('getLayersAsObject with duplicate odd option', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256, {duplicateOdd: true}) const obj = tree.getLayersAsObject() @@ -512,7 +512,7 @@ test('getLayersAsObject with duplicate odd option', t => { test('print', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256) t.equal(tree.toString(), @@ -528,7 +528,7 @@ test('print', t => { test('print with duplicate odd option', t => { t.plan(1) - const leaves = ['a', 'b', 'c'].map(x => sha3(x)) + const leaves = ['a', 'b', 'c'].map(x => keccak(x)) const tree = new MerkleTree(leaves, sha256, {duplicateOdd: true}) t.equal(tree.toString(),