UNPKG

@ieigen/zkzru

Version:

An implementation of [ZK-ZKRollup](https://github.com/ieigen/ZKZRU) in which the relayer **does not** publish transaction data to the main chain, but only publishes the new Merkle root at every update. This provides gas savings but not data availability g

29 lines (24 loc) 637 B
const Tree = require("./tree.js"); module.exports = class TxTree extends Tree { constructor( _txs ) { super(_txs.map((x) => x.hashTx())) this.txs = _txs } checkTxExistence(tx, txProof) { const txIdx = this.findTxIdx(tx.hash); if (!this.verifyProof(tx.hash, txIdx, txProof)) { throw new Error("tx does not exist") } } getTxProofAndProofPos(tx) { const txIdx = this.findTxIdx(tx.hash) const proofObj = this.getProof(txIdx) return [proofObj.proof, proofObj.proofPos] } findTxIdx(txHash) { const txIdx = this.txs.findIndex((tx) => tx.hash == txHash) return txIdx } }