Skip to content

Commit

Permalink
Merge pull request #120 from hoprnet/jjpa/address-and-flattened
Browse files Browse the repository at this point in the history
Adding flattened and per address api query
  • Loading branch information
0xjjpa committed Sep 6, 2021
2 parents 15d075b + ec02038 commit 18f7221
Show file tree
Hide file tree
Showing 2 changed files with 45 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,
});
};
11 changes: 11 additions & 0 deletions pages/api/sign/get/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@ const client = new CeramicClient(CERAMIC_API_URL);
const tileId = CERAMIC_TILE_ID;

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

const records = await TileDocument.load(client, tileId);

if (flattened) {
const ethAddress = Object.values(records.content);
const correspondingHoprNode = Object.keys(records.content);
return res.status(200).json({
status: "ok",
ethAddress,
correspondingHoprNode
})
}

return res.status(200).json({
status: "ok",
tileId,
Expand Down

1 comment on commit 18f7221

@vercel
Copy link

@vercel vercel bot commented on 18f7221 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.