Skip to content

Commit

Permalink
Remove third-web related code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Sep 15, 2024
1 parent be24a6a commit 251db3e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 2,447 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"siwe": "^2.3.2",
"thirdweb": "^5.15.0"
"viem": "^2.21.5"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
15 changes: 9 additions & 6 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
Req,
UseGuards,
UnprocessableEntityException,
BadRequestException,
ForbiddenException,
} from '@nestjs/common';

import { AuthService } from './auth.service';
Expand All @@ -23,7 +21,6 @@ import { ApiResponse } from '@nestjs/swagger';
import { AuthedReq } from 'src/utils/types/AuthedReq.type';
import { STAGING_API, generateRandomString } from 'src/utils';
import { FlowService } from 'src/flow/flow.service';
import { OtpDTO } from './dto/otp.dto';

@Controller({ path: 'auth' })
export class AuthController {
Expand Down Expand Up @@ -63,12 +60,18 @@ export class AuthController {

@ApiResponse({ status: 200, description: 'Sets an auth cookie' })
@Post('/login')
async login(@Res() res: Response, @Body() { message, signature }: LoginDTO) {
async login(
@Res() res: Response,
@Body() { message, signature, address }: LoginDTO,
) {
let isNewUser = false;
const isAuthentic = await this.authService.verifyUser(message, signature);
const isAuthentic = await this.authService.verifyUser(
message,
signature as `0x${string}`,
address as `0x${string}`,
);
if (!isAuthentic) throw new UnauthorizedException('Invalid signature');

const { address } = message;
let user = await this.prismaService.user.findFirst({
where: { address },
});
Expand Down
25 changes: 13 additions & 12 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import {
ForbiddenException,
Injectable,
InternalServerErrorException,
Logger,
} from '@nestjs/common';
import { verifySignature } from 'thirdweb/auth';
import { Injectable, Logger } from '@nestjs/common';
import { generateRandomString } from 'src/utils';
import { PrismaService } from 'src/prisma.service';
import { ethers } from 'ethers';
import { SiweMessage } from 'siwe';
import { verifyMessage } from 'viem';
// import { chain, thirdwebClient } from 'src/thirdweb';

@Injectable()
Expand Down Expand Up @@ -146,12 +140,19 @@ export class AuthService {
return user;
};

verifyUser = async (message: SiweMessage, signature: any) => {
const siweMessage = new SiweMessage(message);
verifyUser = async (
message: string,
signature: `0x${string}`,
address: `0x${string}`,
) => {
try {
// await this.isNonceValid(message.nonce);
await siweMessage.verify({ signature });
return true;
const valid = await verifyMessage({
address,
message,
signature,
});
return valid;
} catch (err) {
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions src/auth/dto/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ export class SiweMessageClass {
}

export class LoginDTO {
@ApiProperty({ type: SiweMessageClass })
message: SiweMessage;
@ApiProperty()
message: string;

@ApiProperty()
signature: string;

@ApiProperty()
address: string;
}
13 changes: 0 additions & 13 deletions src/thirdweb/index.ts

This file was deleted.

13 changes: 6 additions & 7 deletions src/weighted-api/eas/eas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { optimismSepolia } from 'thirdweb/chains';
import { type Address } from 'viem';

export type EASConfig = {
Expand All @@ -20,12 +19,12 @@ export const EASNetworks: Record<number, Config> = {
gqlUrl: 'https://optimism.easscan.org/graphql',
},
// Optimism Sepolia
[optimismSepolia.id]: {
EASDeployment: '0x4200000000000000000000000000000000000021',
SchemaRegistry: '0x4200000000000000000000000000000000000020',
explorer: `https://optimism-sepolia.blockscout.com`,
gqlUrl: 'https://optimism-sepolia.easscan.org/graphql',
},
// [optimismSepolia.id]: {
// EASDeployment: '0x4200000000000000000000000000000000000021',
// SchemaRegistry: '0x4200000000000000000000000000000000000020',
// explorer: `https://optimism-sepolia.blockscout.com`,
// gqlUrl: 'https://optimism-sepolia.easscan.org/graphql',
// },
};

export const SCHEMA_UID = process.env.SCHEMA_UID;
3 changes: 2 additions & 1 deletion src/weighted-api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
initializeWeightList,
sortWeightedList,
} from './utils';
import { chain } from 'src/thirdweb';
// import { chain } from 'src/thirdweb';
import { getRankingDistribution } from './algo';
import axios from 'axios';
import { BadgeData } from 'src/utils/badges/readBadges';

const chain = { id: 10 };
const readAllAttestations = async () => {
if (!SCHEMA_UID) throw Error('Please enter an schema UID');
const attestations = await getAllAttestations(
Expand Down
3 changes: 2 additions & 1 deletion src/weighted-api/user-based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
initializeWeightList,
sortWeightedList,
} from './utils';
import { chain } from 'src/thirdweb';
// import { chain } from 'src/thirdweb';
import { getRankingDistribution } from './algo';
import axios from 'axios';
import { BadgeData } from 'src/utils/badges/readBadges';

const chain = { id: 10 };
const readAllAttestations = async (address: string) => {
if (!SCHEMA_UID) throw Error('Please enter an schema UID');
const attestations = await getAllAttestations(
Expand Down
Loading

0 comments on commit 251db3e

Please sign in to comment.