From b86f140ca927635311841483db279b5069ab9853 Mon Sep 17 00:00:00 2001 From: AlexNi245 Date: Fri, 29 Sep 2023 12:03:19 +0200 Subject: [PATCH] add read endpoint for link --- packages/offchain-resolver/src/http/link.ts | 19 +++++++ .../offchain-resolver/src/http/profile.ts | 50 ------------------- .../profile/getProfileContainer.ts | 1 + 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/packages/offchain-resolver/src/http/link.ts b/packages/offchain-resolver/src/http/link.ts index 7e5f3c5f1..75cc8c9ab 100644 --- a/packages/offchain-resolver/src/http/link.ts +++ b/packages/offchain-resolver/src/http/link.ts @@ -56,6 +56,25 @@ export function link(web3Provider: ethers.providers.BaseProvider) { } }, ); + router.get( + '/:name', + //@ts-ignore + async (req: express.Request & { app: WithLocals }, res, next) => { + const { address } = req.params; + if (!ethers.utils.isAddress(address)) { + return res.status(400).send(); + } + + const profileContainer = + await req.app.locals.db.getProfileContainerByAddress(address); + + if (!profileContainer) { + return res.send(404); + } + + return res.status(200).send(profileContainer.links); + }, + ); return router; } diff --git a/packages/offchain-resolver/src/http/profile.ts b/packages/offchain-resolver/src/http/profile.ts index 83fea3461..7618c1006 100644 --- a/packages/offchain-resolver/src/http/profile.ts +++ b/packages/offchain-resolver/src/http/profile.ts @@ -167,56 +167,6 @@ export function profile(web3Provider: ethers.providers.BaseProvider) { } }, ); - router.post( - '/link', - //@ts-ignore - async (req: express.Request & { app: WithLocals }, res, next) => { - try { - const { ownerName, lspName, linkMessage, signature } = req.body; - - if (!ownerName || !lspName || !linkMessage || !signature) { - return res.status(400).send({ - error: 'invalid schema', - }); - } - logInfo({ text: `POST link`, ensName: lspName }); - - //check owner address to ensure that ownerName and the signed signature belong together - const ownerAddress = await web3Provider.resolveName(ownerName); - - if (!ownerAddress) { - return res.status(400).send({ - error: 'could not resolve owner address', - }); - } - - //Check if the request comes from the owner of the name - const sigIsValid = await ethersHelper.checkSignature( - linkMessage, - ownerAddress, - signature, - ); - - if (!sigIsValid) { - global.logger.warn('signature invalid'); - - return res.status(400).send({ - error: 'signature invalid', - }); - } - - if (!(await req.app.locals.db.setLink(ownerName, lspName))) { - return res - .status(400) - .send({ error: 'Could not create alias' }); - } - - return res.sendStatus(200); - } catch (e) { - next(e); - } - }, - ); router.post( '/deleteName', //@ts-ignore diff --git a/packages/offchain-resolver/src/persistance/profile/getProfileContainer.ts b/packages/offchain-resolver/src/persistance/profile/getProfileContainer.ts index 6eefcb4bc..f9d23e5a6 100644 --- a/packages/offchain-resolver/src/persistance/profile/getProfileContainer.ts +++ b/packages/offchain-resolver/src/persistance/profile/getProfileContainer.ts @@ -10,6 +10,7 @@ export type ProfileContainer = { profile: SignedUserProfile; ensName: string; address: string; + links: string[]; }; export function getProfileContainer(db: PrismaClient) {