29 lines
642 B
TypeScript
29 lines
642 B
TypeScript
import { MimcSponge, buildMimcSponge } from 'circomlibjs';
|
|
import type { Element, HashFunction } from '@tornado/fixed-merkle-tree';
|
|
|
|
export class Mimc {
|
|
sponge?: MimcSponge;
|
|
hash?: HashFunction<Element>;
|
|
mimcPromise: Promise<void>;
|
|
|
|
constructor() {
|
|
this.mimcPromise = this.initMimc();
|
|
}
|
|
|
|
async initMimc() {
|
|
this.sponge = await buildMimcSponge();
|
|
this.hash = (left, right) => this.sponge?.F.toString(this.sponge?.multiHash([BigInt(left), BigInt(right)]));
|
|
}
|
|
|
|
async getHash() {
|
|
await this.mimcPromise;
|
|
|
|
return {
|
|
sponge: this.sponge,
|
|
hash: this.hash,
|
|
};
|
|
}
|
|
}
|
|
|
|
export const mimc = new Mimc();
|