rln-interep-contract/common/interep-utils.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-25 11:38:38 +05:30
import { utils } from "ethers";
export const sToBytes32 = (str: string): string => {
2022-11-25 11:38:38 +05:30
return utils.formatBytes32String(str);
};
2022-11-28 15:01:35 +05:30
// zerokit can only use 15, 19, and 20 depth
export const merkleTreeDepth = 15;
2022-11-28 10:32:09 +05:30
export const SNARK_SCALAR_FIELD = BigInt(
2022-11-25 11:38:38 +05:30
"21888242871839275222246405745257275088548364400416034343698204186575808495617"
);
export const createGroupId = (provider: string, name: string): bigint => {
2022-11-25 11:38:38 +05:30
const providerBytes = sToBytes32(provider);
const nameBytes = sToBytes32(name);
return (
BigInt(
utils.solidityKeccak256(
["bytes32", "bytes32"],
[providerBytes, nameBytes]
)
) % SNARK_SCALAR_FIELD
);
};
2022-11-25 11:38:38 +05:30
const providers = ["github", "twitter", "reddit"];
const tiers = ["bronze", "silver", "gold"];
export const getGroups = () => {
2022-11-25 11:38:38 +05:30
return providers.flatMap((provider) =>
tiers.map((tier) => {
return {
provider: sToBytes32(provider),
name: sToBytes32(tier),
root: 1,
2022-11-28 10:32:09 +05:30
depth: merkleTreeDepth,
2022-11-25 11:38:38 +05:30
};
})
);
};
export const getValidGroups = () => {
2022-11-25 11:38:38 +05:30
return getGroups().filter((group) => group.name !== sToBytes32("bronze"));
};