mirror of
https://github.com/zkitter/zkitterd.git
synced 2026-01-09 13:47:56 -05:00
fix interrep onboarding
This commit is contained in:
@@ -44,6 +44,20 @@ const semaphore = (sequelize: Sequelize) => {
|
||||
return result?.toJSON() as SemaphoreModel;
|
||||
}
|
||||
|
||||
const findOne = async (id_commitment: string, group_id: string): Promise<SemaphoreModel|null> => {
|
||||
let result = await model.findOne({
|
||||
where: {
|
||||
id_commitment,
|
||||
group_id,
|
||||
},
|
||||
order: [
|
||||
['createdAt', 'DESC'],
|
||||
],
|
||||
});
|
||||
|
||||
return result?.toJSON() as SemaphoreModel;
|
||||
}
|
||||
|
||||
const findAllByCommitment = async (id_commitment: string): Promise<SemaphoreModel[]> => {
|
||||
let result = await model.findAll({
|
||||
where: {
|
||||
@@ -89,6 +103,7 @@ const semaphore = (sequelize: Sequelize) => {
|
||||
|
||||
return {
|
||||
model,
|
||||
findOne,
|
||||
findOneByCommitment,
|
||||
findAllByCommitment,
|
||||
addID,
|
||||
|
||||
@@ -31,6 +31,19 @@ export default class InterrepService extends GenericService {
|
||||
this.groups = {};
|
||||
}
|
||||
|
||||
syncOne = async (group: string) => {
|
||||
const [protocol, groupType, groupName] = group.split('_');
|
||||
// @ts-ignore
|
||||
const resp = await fetch(`${config.interrepAPI}/api/v1/groups/${groupType}/${groupName}`);
|
||||
const json = await resp.json();
|
||||
const data = json.data;
|
||||
const existing = await this.interepGroups!.getGroup(groupType, groupName);
|
||||
if (existing?.root_hash !== data.root) {
|
||||
await this.fetchMembersFromGroup(data.root, groupType, groupName);
|
||||
await this.interepGroups?.addHash(data.root, groupType, groupName);
|
||||
}
|
||||
}
|
||||
|
||||
sync = async () => {
|
||||
try {
|
||||
if (this.timeout) {
|
||||
|
||||
@@ -76,10 +76,19 @@ export default class MerkleService extends GenericService {
|
||||
if (!row) throw new Error(`${idCommitment} is not in any groups`);
|
||||
group = row.group_id;
|
||||
}
|
||||
|
||||
const exist = await this.semaphore.findOne(idCommitment, group);
|
||||
|
||||
if (!exist) {
|
||||
await this.call('interrep', 'syncOne', group);
|
||||
}
|
||||
|
||||
const tree = await this.makeTree(group);
|
||||
const proof = await tree.createProof(tree.indexOf(BigInt('0x' + idCommitment)));
|
||||
|
||||
if (!proof) throw new Error(`${idCommitment} is not in ${group}`);
|
||||
if (!proof) {
|
||||
throw new Error(`${idCommitment} is not in ${group}`);
|
||||
}
|
||||
|
||||
const root = '0x' + proof.root.toString(16);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user