import type { BigNumber } from "ethers" ; import { Claim , claimHash } from "../claim" ; import MerkleTree from "./merkle-tree" ; export default class BalanceTree { private readonly tree : MerkleTree ; constructor ( balances ) { this . tree = new MerkleTree ( balances . map ( ( claim , index ) => { return BalanceTree . toNode ( index , claim ) ; } ) ) ; } public static verifyProof ( index , claim , proof , root ) { let pair = BalanceTree . toNode ( index , claim ) ; for ( const item of proof ) { pair = MerkleTree . combinedHash ( pair , item ) ; } return pair . equals ( root ) ; } public static toNode ( index , claim ) { return claimHash ( index , claim ) ; } public getHexRoot ( ) { return this . tree . getHexRoot ( ) ; } public getProof ( index , claim ) { return this . tree . getHexProof ( BalanceTree . toNode ( index , claim ) ) ; } }