mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-21 17:27:08 +01:00
remove mimc and snarkjs dependency
This commit is contained in:
parent
3e31a2f875
commit
a0c40b2138
3866
package-lock.json
generated
3866
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "fixed-merkle-tree",
|
||||
"version": "0.6.0",
|
||||
"version": "1.0.0",
|
||||
"description": "Fixed depth merkle tree implementation with sequential inserts",
|
||||
"repository": "https://github.com/tornadocash/fixed-merkle-tree.git",
|
||||
"main": "src/merkleTree.js",
|
||||
@ -18,10 +18,6 @@
|
||||
"files": [
|
||||
"src/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
|
||||
"circomlib": "git+https://github.com/tornadocash/circomlib.git#5beb6aee94923052faeecea40135d45b6ce6172c"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^10.1.0",
|
||||
"chai": "^4.2.0",
|
||||
|
@ -1,9 +1,5 @@
|
||||
// keccak256("tornado") % BN254_FIELD_SIZE
|
||||
const DEFAULT_ZERO = '21663839004416932945382355908790599225266501822907911457504978515578255421292'
|
||||
const defaultHash = require('./mimc')
|
||||
|
||||
const defaultHash = require('./sha256')
|
||||
// todo ensure consistent types in tree and inserted elements?
|
||||
// todo make sha3 default hasher (and update tests) to get rid of mimc/snarkjs/circomlib dependency
|
||||
|
||||
/**
|
||||
* @callback hashFunction
|
||||
@ -22,7 +18,7 @@ class MerkleTree {
|
||||
* @param {hashFunction} [options.hashFunction] Function used to hash 2 leaves
|
||||
* @param [options.zeroElement] Value for non-existent leaves
|
||||
*/
|
||||
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
|
||||
constructor(levels, elements = [], { hashFunction, zeroElement = 0 } = {}) {
|
||||
this.levels = levels
|
||||
this.capacity = 2 ** levels
|
||||
if (elements.length > this.capacity) {
|
||||
|
@ -1,3 +0,0 @@
|
||||
const { mimcsponge } = require('circomlib')
|
||||
const { bigInt } = require('snarkjs')
|
||||
module.exports = (left, right) => mimcsponge.multiHash([bigInt(left), bigInt(right)]).toString()
|
15
src/sha256.js
Normal file
15
src/sha256.js
Normal file
@ -0,0 +1,15 @@
|
||||
const crypto = require('crypto')
|
||||
|
||||
function toBuffer256(number) {
|
||||
return Buffer.from(number.toString(16).padStart(512, '0'), 'hex')
|
||||
}
|
||||
|
||||
function sha256(left, right) {
|
||||
return crypto
|
||||
.createHash('sha256')
|
||||
.update(toBuffer256(left))
|
||||
.update(toBuffer256(right))
|
||||
.digest('hex')
|
||||
}
|
||||
|
||||
module.exports = sha256
|
Loading…
Reference in New Issue
Block a user