-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from hoprnet/jjpa/address-and-flattened
Adding flattened and per address api query
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18f7221
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: