mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 09:27:58 -05:00
# 🤖 Linear Closes 0XB-72 Closes 0XB-70 Closes 0XB-69 --------- Co-authored-by: drgorillamd <83670532+drgorillamd@users.noreply.github.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Circomkit } from "circomkit";
|
|
import { poseidon } from "../../../../node_modules/maci-crypto/build/ts/hashing.js";
|
|
|
|
export interface Commitment {
|
|
value: bigint;
|
|
label: bigint;
|
|
nullifier: bigint;
|
|
secret: bigint;
|
|
}
|
|
|
|
export const circomkit = new Circomkit({
|
|
verbose: false,
|
|
protocol: "groth16",
|
|
include: ["../../node_modules/circomlib/circuits", "../../node_modules/maci-circuits/circom"],
|
|
});
|
|
|
|
export function hashCommitment(input: Commitment): [bigint, bigint, bigint] {
|
|
const precommitment = poseidon([BigInt(input.nullifier), BigInt(input.secret)]);
|
|
const nullifierHash = poseidon([BigInt(input.nullifier)]);
|
|
const commitmentHash = poseidon([BigInt(input.value), BigInt(input.label), precommitment]);
|
|
return [commitmentHash, precommitment, nullifierHash];
|
|
}
|
|
|
|
export function randomBigInt(): bigint {
|
|
return BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER));
|
|
}
|
|
|
|
export function padSiblings(siblings: bigint[], targetDepth: number): bigint[] {
|
|
const paddedSiblings = [...siblings];
|
|
while (paddedSiblings.length < targetDepth) {
|
|
paddedSiblings.push(BigInt(0));
|
|
}
|
|
return paddedSiblings;
|
|
}
|