Skip to content

Commit

Permalink
added fingerprint family verification
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchJitter committed Aug 3, 2024
1 parent 766d291 commit 11bc5b7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composables/registrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class Registrator {
currentLockSize = await this.getCurrentLockSize(auth.userData.address);
}

await auth.getTokenBalance();
await auth.getUsdTokenBalance();
await auth.getTokenBalance(true);
await auth.getUsdTokenBalance(true);

this.setRefreshing(false);
useRegistratorStore().setInitialized(true);
Expand Down
12 changes: 12 additions & 0 deletions composables/relay-registry/relay-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ export class RelayRegistry {
return null;
}

if (!(await auth.familyVerified(fingerprint))) {
this.logger.error('Family not verified.');
toast.add({
id: 'family-not-verified',
icon: 'i-heroicons-information-circle',
title: 'Error',
description: 'Family not verified.',
color: 'amber',
});
return null;
}

const warpSigner = await useWarpSigner();
if (!warpSigner) {
this.logger.error('claim() relay registry warpSigner is null');
Expand Down
29 changes: 29 additions & 0 deletions stores/useUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useUserStore = defineStore('user', {
verifiedRelays: [] as RelayRow[],
claimableRelays: [] as RelayRow[],
registrationCredits: [] as string[],
families: {} as Record<string, string[]>,
relaysMeta: {} as Record<string, RelayMeta>,
nickNames: {} as Record<string, string>,
claimableRewards: 0,
Expand Down Expand Up @@ -210,6 +211,8 @@ export const useUserStore = defineStore('user', {

this.registrationCredits = data.data.registrationCredits;

this.families = data.data.families;

// save to cache
const relayCache = useRelayCache();
await relayCache.saveRelayData(data.data);
Expand All @@ -230,6 +233,32 @@ export const useUserStore = defineStore('user', {
await this.createRelayCache();
}
},
async familyVerified(fingerprint: string) {
if (!this.userData.address) {
return false;
}

const relayCache = useRelayCache();
const cachedData = await relayCache.getRelayData();
if (cachedData) {
if (cachedData.families[fingerprint]) {
var family = cachedData.families[fingerprint] as string[];
for (const member of family) {
if (
this.verifiedRelays.find((relay) => relay.fingerprint === member)
) {
} else {
return false;
}
}
return true;
}
return true;
} else {
// build cache
await this.createRelayCache();
}
},
async clearCache() {
const relayCache = useRelayCache();
this.verifiedRelays = [];
Expand Down
10 changes: 10 additions & 0 deletions utils/warp.read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type RelayData = {
];
nicknames: { [key: string]: string };
registrationCredits: string[];
families: { [key: string]: string[] };
};
};

Expand Down Expand Up @@ -167,6 +168,7 @@ export const getAllRelays = async (
const claimableRelays = [];
const registrationCredits = [];
const nicknames: { [key: string]: any } = {};
const families: { [key: string]: string[] } = {};
const userStore = useUserStore();

for (const [fingerprint, addressRelay] of Object.entries(
Expand Down Expand Up @@ -213,6 +215,13 @@ export const getAllRelays = async (
}
}

for (const [fingerprint, array] of Object.entries(
result.cachedValue.state.families
)) {
var fingerprintArray = array as string[];
families[fingerprint] = fingerprintArray;
}

return {
timestamp: Date.now(),
data: {
Expand All @@ -236,6 +245,7 @@ export const getAllRelays = async (
],
nicknames: nicknames,
registrationCredits: registrationCredits,
families: families,
},
};
} catch (error) {
Expand Down

0 comments on commit 11bc5b7

Please sign in to comment.