Skip to content

Commit

Permalink
add read endpoint for link
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Sep 29, 2023
1 parent c1110bf commit b86f140
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 50 deletions.
19 changes: 19 additions & 0 deletions packages/offchain-resolver/src/http/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
50 changes: 0 additions & 50 deletions packages/offchain-resolver/src/http/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ProfileContainer = {
profile: SignedUserProfile;
ensName: string;
address: string;
links: string[];
};

export function getProfileContainer(db: PrismaClient) {
Expand Down

0 comments on commit b86f140

Please sign in to comment.