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

Support Smart Wallet login on Devcon Passport #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions devcon-api/src/controllers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,15 @@ async function LoginWeb3(req: Request, res: Response) {
return res.status(400).send({ code: 400, message: 'No session token.' })
}

const address = req.body.address as string
const address = req.body.address as `0x${string}`
const nonce = Number(req.body.nonce)
const msg = req.body.msg as string
const signed = req.body.signed as string
const signed = req.body.signed as `0x${string}`
if (!address || !msg || !signed || !nonce || isNaN(nonce)) {
return res.status(400).send({ code: 400, message: 'Invalid input.' })
}

const validSignature = isValidSignature(address, msg, signed)
const validSignature = await isValidSignature(address, msg, signed)
if (!validSignature) {
return res.status(400).send({ code: 400, message: 'Invalid signature.' })
}
Expand Down
10 changes: 2 additions & 8 deletions devcon-api/src/utils/web3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ethers, verifyMessage } from 'ethers'
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

Expand All @@ -7,14 +6,9 @@ export const publicClient = createPublicClient({
transport: http(`https://mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`),
})

export const isValidSignature = (address: string, message: string, signature: string): boolean => {
export const isValidSignature = async (address: `0x${string}`, message: string, signature: `0x${string}`): Promise<boolean> => {
try {
const recovered = verifyMessage(message, signature)
if (!recovered || ethers.getAddress(recovered) !== ethers.getAddress(address)) {
return false
}

return true
return await publicClient.verifyMessage({ address, message, signature })
} catch (e) {
return false
}
Expand Down