Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandada trial #114

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/lib/bandadaSemaphore/methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Identity } from '@semaphore-protocol/identity';
import { Group as SemaphoreGroup } from '@semaphore-protocol/group';
import { ApiSdk, Group } from '@bandada/api-sdk';

const bandadaApi = new ApiSdk();

const apiKey = process.env.NEXT_PUBLIC_BANDADA_API_KEY!;
const attestationGroupID = process.env.NEXT_PUBLIC_BANDADA_GROUP_ID!;

export const createSemaphoreIdentity = (signature: string): string => {
/* determinsitic Identity from Signature */
const identity = new Identity(signature);
console.log('identity.commitment: ', identity.commitment);
localStorage.setItem('SemaphoreIdentity', identity.commitment.toString());
return identity.commitment.toString();
};

export const getUsersInBandadaGroup = async (): Promise<string[] | null> => {
try {
const { members } = await bandadaApi.getGroup(attestationGroupID);
return members;
}
catch (error: any) {
console.error(error);
return null;
}
};

export const getUserBandadaGroup = async (signature: string): Promise<Group | null> => {
const users = await getUsersInBandadaGroup();
let identityString = localStorage.getItem('SemaphoreIdentity');
if (!identityString) {
identityString = createSemaphoreIdentity(signature);
}
if (!users || !users.includes(identityString)) {
/* create bandada group */
try {
await bandadaApi.addMemberByApiKey(attestationGroupID, identityString, apiKey);
/* create group using semaphore */
const groupArray = await getUsersInBandadaGroup();
/* store the root in DB */
if (!groupArray) {
return null;
}
const group = new SemaphoreGroup(groupArray);
const groupRoot = group.root;
/* save group root in database */
return (await bandadaApi.getGroup(attestationGroupID));
}
catch (error: any) {
console.error(error);
if (error.response) {
console.error(error.response.statusText);
}
return null;
}
}
return (await bandadaApi.getGroup(attestationGroupID));
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix"
},
"dependencies": {
"@bandada/api-sdk": "^2.4.2",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@ethereum-attestation-service/eas-sdk": "^2.7.0",
"@farcaster/auth-kit": "^0.6.0",
"@mui/material": "^6.1.3",
"@semaphore-protocol/group": "^4.5.0",
"@semaphore-protocol/identity": "^4.5.0",
"@smastrom/react-rating": "^1.5.0",
"@stylistic/eslint-plugin": "^2.7.2",
"@tanstack/react-query": "^5.54.1",
Expand Down
Loading