use mimc from circomlibjs
This commit is contained in:
parent
ad634a6b3a
commit
e9f123a8b2
9710
package-lock.json
generated
9710
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,6 @@
|
||||
"mocha": "^9.2.1",
|
||||
"ts-mocha": "^9.0.2",
|
||||
"typescript": "^4.5.5",
|
||||
"circomlib": "git+https://github.com/tornadocash/circomlib.git#5beb6aee94923052faeecea40135d45b6ce6172c"
|
||||
"circomlibjs": "^0.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,20 @@
|
||||
import { MerkleTree, TreeEdge } from '../src'
|
||||
import { assert, should } from 'chai'
|
||||
import { mimcsponge } from 'circomlib'
|
||||
import { buildMimcSponge } from 'circomlibjs'
|
||||
import { createHash } from 'crypto'
|
||||
import { it } from 'mocha'
|
||||
|
||||
const sha256Hash = (left, right) => createHash('sha256').update(`${left}${right}`).digest('hex')
|
||||
const mimcHash = (left, right) => mimcsponge.multiHash([BigInt(left), BigInt(right)]).toString()
|
||||
const ZERO_ELEMENT = '21663839004416932945382355908790599225266501822907911457504978515578255421292'
|
||||
|
||||
describe('MerkleTree', () => {
|
||||
|
||||
describe('#constructor', () => {
|
||||
let mimcSponge
|
||||
|
||||
before(async () => {
|
||||
mimcSponge = await buildMimcSponge()
|
||||
})
|
||||
|
||||
it('should have correct zero root', () => {
|
||||
const tree = new MerkleTree(10, [])
|
||||
@ -47,6 +51,7 @@ describe('MerkleTree', () => {
|
||||
})
|
||||
|
||||
it('should work with mimc hash function and zero element', () => {
|
||||
const mimcHash = (left, right) => mimcSponge.F.toString(mimcSponge.multiHash([BigInt(left), BigInt(right)]))
|
||||
const tree = new MerkleTree(10, [1, 2, 3], { hashFunction: mimcHash, zeroElement: ZERO_ELEMENT })
|
||||
should().equal(tree.root, '13605252518346649016266481317890801910232739395710162921320863289825142055129')
|
||||
})
|
||||
|
@ -3,7 +3,7 @@
|
||||
"lib": [
|
||||
"es2019"
|
||||
],
|
||||
"target": "es2018",
|
||||
"target": "es2020",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"outDir": "./lib",
|
||||
|
Loading…
Reference in New Issue
Block a user