Skip to content

Commit

Permalink
support smart wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrosario committed Nov 11, 2024
1 parent 25c92f7 commit 5125b69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
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

0 comments on commit 5125b69

Please sign in to comment.