mirror of
https://github.com/oceanprotocol/ens-proxy.git
synced 2024-12-02 05:57:34 +01:00
28 lines
829 B
TypeScript
28 lines
829 B
TypeScript
import type { VercelRequest, VercelResponse } from '@vercel/node'
|
|
import { getProvider } from './_utils'
|
|
|
|
export async function getEnsName(accountId: string) {
|
|
const provider = await getProvider()
|
|
let name = await provider.lookupAddress(accountId)
|
|
|
|
// Check to be sure the reverse record is correct.
|
|
const reverseAccountId = await provider.resolveName(name)
|
|
if (accountId.toLowerCase() !== reverseAccountId.toLowerCase()) name = null
|
|
return name
|
|
}
|
|
|
|
export default async function nameApi(
|
|
request: VercelRequest,
|
|
response: VercelResponse
|
|
) {
|
|
try {
|
|
const accountId = String(request.query.accountId)
|
|
const name = await getEnsName(accountId)
|
|
|
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
|
response.status(200).send({ name })
|
|
} catch (error) {
|
|
response.send({ error })
|
|
}
|
|
}
|