|
@ -10,7 +10,6 @@ const Web3 = require("web3"); |
|
|
// const buildBn128 = require("wasmsnark").buildBn128;
|
|
|
// const buildBn128 = require("wasmsnark").buildBn128;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const nLevels = 17; |
|
|
|
|
|
const coinCode = "0"; // refearing to ETH
|
|
|
const coinCode = "0"; // refearing to ETH
|
|
|
const ethAmount = '1'; |
|
|
const ethAmount = '1'; |
|
|
const amount = Web3.utils.toWei(ethAmount, 'ether'); |
|
|
const amount = Web3.utils.toWei(ethAmount, 'ether'); |
|
@ -26,12 +25,12 @@ exports.calcCommitment = (key, secret) => { |
|
|
return commitment; |
|
|
return commitment; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
exports.calcDepositWitness = async (wasm, key, secret, commitments) => { |
|
|
|
|
|
|
|
|
exports.calcDepositWitness = async (wasm, nLevels, key, secret, commitments) => { |
|
|
const poseidon = circomlib.poseidon.createHash(6, 8, 57); |
|
|
const poseidon = circomlib.poseidon.createHash(6, 8, 57); |
|
|
const nullifier = poseidon([key, secret]).toString(); |
|
|
const nullifier = poseidon([key, secret]).toString(); |
|
|
const commitment = poseidon([coinCode, amount, secret, nullifier]).toString(); |
|
|
const commitment = poseidon([coinCode, amount, secret, nullifier]).toString(); |
|
|
|
|
|
|
|
|
console.log("PROVA", poseidon([key, commitment]).toString()); |
|
|
|
|
|
|
|
|
console.log("Commitment", commitment.toString()); |
|
|
|
|
|
|
|
|
// rebuild the tree
|
|
|
// rebuild the tree
|
|
|
let tree = await smt.newMemEmptyTrie(); |
|
|
let tree = await smt.newMemEmptyTrie(); |
|
@ -79,7 +78,6 @@ exports.calcDepositWitness = async (wasm, key, secret, commitments) => { |
|
|
"coinCode": coinCode, |
|
|
"coinCode": coinCode, |
|
|
"amount": amount, |
|
|
"amount": amount, |
|
|
"secret": secret, |
|
|
"secret": secret, |
|
|
"nullifier": nullifier, |
|
|
|
|
|
"oldKey": oldKey, |
|
|
"oldKey": oldKey, |
|
|
"oldValue": oldValue, |
|
|
"oldValue": oldValue, |
|
|
"siblingsOld": siblingsOld, |
|
|
"siblingsOld": siblingsOld, |
|
@ -120,7 +118,7 @@ exports.calcDepositWitness = async (wasm, key, secret, commitments) => { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
exports.calcWithdrawWitness = async (wasm, key, secret, commitments, addr) => { |
|
|
|
|
|
|
|
|
exports.calcWithdrawWitness = async (wasm, nLevels, key, secret, commitments, addr) => { |
|
|
const poseidon = circomlib.poseidon.createHash(6, 8, 57); |
|
|
const poseidon = circomlib.poseidon.createHash(6, 8, 57); |
|
|
const nullifier = poseidon([key, secret]).toString(); |
|
|
const nullifier = poseidon([key, secret]).toString(); |
|
|
const commitment = poseidon([coinCode, amount, secret, nullifier]).toString(); |
|
|
const commitment = poseidon([coinCode, amount, secret, nullifier]).toString(); |
|
|