Skip to content

Commit

Permalink
move the try/catch scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoMogg committed Aug 22, 2024
1 parent 82edaa9 commit 4574382
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions apps/web/src/utils/proofs/sybil_resistance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,36 @@ export async function sybilResistantUsernameSigning(
(attestation) => JSON.parse(attestation.decodedDataJson)[0] as VerifiedAccount,
);

try {
let { linkedAddresses, idemKey } = await getLinkedAddresses(address as string);
let { linkedAddresses, idemKey } = await getLinkedAddresses(address as string);

const hasPreviouslyRegistered = await hasRegisteredWithDiscount(linkedAddresses, chainId);
// if any linked address registered previously return an error
if (hasPreviouslyRegistered) {
throw new ProofsException('You have already claimed a discounted basename (onchain).', 409);
}
const hasPreviouslyRegistered = await hasRegisteredWithDiscount(linkedAddresses, chainId);
// if any linked address registered previously return an error
if (hasPreviouslyRegistered) {
throw new ProofsException('You have already claimed a discounted basename (onchain).', 409);
}

const kvKey = `${previousClaimsKVPrefix}${idemKey}`;
//check kv for previous claim entries
let previousClaims = (await kv.get<PreviousClaims>(kvKey)) ?? {};
const previousClaim = previousClaims[discountType];
if (previousClaim) {
if (previousClaim.address != address) {
throw new ProofsException(
'You tried claiming this with a different address, wait a couple minutes to try again.',
400,
);
}
// return previously signed message
return {
signedMessage: previousClaim.signedMessage,
attestations: attestationsRes,
discountValidatorAddress,
expires: EXPIRY.toString(),
};
const kvKey = `${previousClaimsKVPrefix}${idemKey}`;
//check kv for previous claim entries
let previousClaims = (await kv.get<PreviousClaims>(kvKey)) ?? {};
const previousClaim = previousClaims[discountType];
if (previousClaim) {
if (previousClaim.address != address) {
throw new ProofsException(
'You tried claiming this with a different address, wait a couple minutes to try again.',
400,
);
}
// return previously signed message
return {
signedMessage: previousClaim.signedMessage,
attestations: attestationsRes,
discountValidatorAddress,
expires: EXPIRY.toString(),
};
}

const expirationTimeUnix = Math.floor(Date.now() / 1000) + parseInt(EXPIRY);
const expirationTimeUnix = Math.floor(Date.now() / 1000) + parseInt(EXPIRY);
try {
// generate and sign the message
const signedMessage = await signMessageWithTrustedSigner(
address,
Expand Down

0 comments on commit 4574382

Please sign in to comment.