Skip to content

Commit

Permalink
Merge pull request #18 from decentldotland/ark-api
Browse files Browse the repository at this point in the history
ark-api: `/oat` endpoint
  • Loading branch information
charmful0x authored Jan 10, 2023
2 parents e13e662 + cd3ba52 commit 909d3fe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ark-protocol",
"version": "0.7.1",
"version": "0.7.2",
"type": "module",
"description": "Verifiable multichain identities",
"main": "./src/app.js",
Expand Down
10 changes: 10 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getDomainsOf } from "./utils/endpoints/domains.js";
import { getNftsOf } from "./utils/endpoints/nfts.js";
import { evmHybridNfts } from "./utils/endpoints/evm-nfts.js";
import { getProfileMetadata } from "./utils/endpoints/metadata.js";
import { getOatsOf } from "./utils/endpoints/oat.js";
import express from "express";
import base64url from "base64url";
import cors from "cors";
Expand Down Expand Up @@ -97,6 +98,15 @@ app.get("/v2/allnft/:network/:address", async (req, res) => {
return;
});

app.get("/v2/oat/:network/:address", async (req, res) => {
res.setHeader("Content-Type", "application/json");
const { network, address } = req.params;
const response = await getOatsOf(network, address);
const jsonRes = JSON.parse(base64url.decode(response));
res.send(jsonRes);
return;
});

app.get("/v2/profile-metadata/:network/:address", async (req, res) => {
res.setHeader("Content-Type", "application/json");
const { network, address } = req.params;
Expand Down
60 changes: 60 additions & 0 deletions src/utils/endpoints/oat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { evaluateOracleState } from "../arweave/exm-rwx.js";
import { getGitPoaps, getAllPoaps, getGalaxyCreds } from "../server-utils.js";
import base64url from "base64url";

export async function getOatsOf(network, address) {
try {
let userProfile;
const responseProfile = {};
const state = (await evaluateOracleState())?.identities;
if (!state) {
return "e30";
}

if (!["arweave", "evm", "exotic"].includes(network)) {
return "e30";
}

if (network === "arweave") {
userProfile = state.find(
(user) =>
user["arweave_address"].toUpperCase() === address.toUpperCase() &&
!!user.is_verified
);
} else {
userProfile = state.find(
(user) => user["primary_address"] === address && !!user.is_verified
);
}

if (!userProfile) {
return "e30";
}

const verifiedEvmAddresses = userProfile.addresses.filter(
(addr) => !!addr.is_verified && addr.ark_key === "EVM"
);
responseProfile.GITPOAPS = [];
responseProfile.POAPS = [];
responseProfile.GALAXY_CREDS = [];

for (const linkage of verifiedEvmAddresses) {
const gitpoap = await getGitPoaps(linkage.address);
const poap = await getAllPoaps(linkage.address);
const oat = await getGalaxyCreds(linkage.address);

responseProfile.GITPOAPS = responseProfile.GITPOAPS.concat(gitpoap);
responseProfile.POAPS = responseProfile.POAPS.concat(poap);
responseProfile.GALAXY_CREDS = responseProfile.GALAXY_CREDS.concat(oat);
}

responseProfile.GITPOAPS.flat();
responseProfile.POAPS.flat();
responseProfile.GALAXY_CREDS.flat();

return base64url(JSON.stringify(responseProfile));
} catch (error) {
console.log(error);
return "e30";
}
}

0 comments on commit 909d3fe

Please sign in to comment.