tornado-core/src/mimc.ts
Tornado Contrib a9035f1579
Initial commit
Exported from tornado-cli 1.0.3
2024-04-29 15:54:32 +00:00

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();