Skip to content

Commit

Permalink
feat: Added missing [address] endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjjpa committed Sep 6, 2021
1 parent 50756e2 commit ec02038
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pages/api/sign/get/[address].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Ed25519Provider } from "key-did-provider-ed25519";
import KeyResolver from "key-did-resolver";
import { DID } from "dids";
import CeramicClient from "@ceramicnetwork/http-client";
import { TileDocument } from "@ceramicnetwork/stream-tile";
import {
CERAMIC_API_URL,
CERAMIC_TILE_ID,
} from "../../../../constants/ceramic";

import { utils } from "ethers";

const secretKey = Uint8Array.from(
utils.arrayify(`0x${process.env.HOPR_DASHBOARD_API_PRIVATE_KEY}`)
);
const provider = new Ed25519Provider(secretKey);
const did = new DID({ provider, resolver: KeyResolver.getResolver() });
const client = new CeramicClient(CERAMIC_API_URL);
const tileId = CERAMIC_TILE_ID;

export default async (req, res) => {
const { address } = req.query;
await did.authenticate();
client.setDID(did);

const records = await TileDocument.load(client, tileId);
const addressRecords = Object.keys(records.content).filter(hoprNode => records.content[hoprNode] == address);

return res.status(200).json({
status: "ok",
tileId,
records: addressRecords,
});
};

0 comments on commit ec02038

Please sign in to comment.