updated backend for brightId (#362)

* updated backend for brightId

* updated schema

* removed unwanted console logs

* made brightId context constant
This commit is contained in:
dan13ram
2021-03-01 12:06:52 +05:30
committed by GitHub
parent c7111fe3fd
commit b0ab6f1e2d
7 changed files with 100 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ interface IConfig {
imgixToken: string;
infuraId: string;
pSEEDAddress: string;
brightIdNodeUrl: string;
}
function parseEnv<T extends string | number>(
@@ -45,4 +46,8 @@ export const CONFIG: IConfig = {
process.env.NEXT_PUBLIC_INFURA_ID,
'781d8466252d47508e177b8637b1c2fd',
),
brightIdNodeUrl: parseEnv(
process.env.BRIGHTID_NODE_URL,
'https://app.brightid.org',
),
};

View File

@@ -0,0 +1,22 @@
import { CONFIG } from '../../../../config';
import { QueryResolvers } from '../../autogen/types';
const CONTEXT = 'MetaGame';
const ENDPOINT = `${CONFIG.brightIdNodeUrl}/node/v5/verifications/${CONTEXT}`;
export const getBrightIdStatus: QueryResolvers['getBrightIdStatus'] = async (
_,
{ contextId },
) => {
if (!contextId) return null;
try {
const response = await fetch(`${ENDPOINT}/${contextId}`);
if (!response.ok) return null;
const responseData = await response.json();
return responseData.data;
} catch (err) {
return null;
}
};

View File

@@ -1,14 +1,18 @@
import { makeExecutableSchema } from 'graphql-tools';
import { getBrightIdStatus } from './resolvers/brightId/resolver';
import { getDaoHausMemberships } from './resolvers/daohaus/resolver';
import { getBoxProfile } from './resolvers/getBoxProfile/resolver';
import { typeDefs } from './typeDefs';
import { uuid } from './types/uuid';
const resolvers = {
Query: {
getBoxProfile,
getDaoHausMemberships,
getBrightIdStatus,
},
uuid,
};
export const schema = makeExecutableSchema({ typeDefs, resolvers });

View File

@@ -1,9 +1,19 @@
import { gql } from 'graphql-request/dist';
export const typeDefs = gql`
scalar uuid
type Query {
getBoxProfile(address: String): BoxProfile
getDaoHausMemberships(memberAddress: String): [Member!]!
getBrightIdStatus(contextId: uuid): BrightIdStatus
}
type BrightIdStatus {
unique: Boolean!
app: String!
context: String!
contextIds: [String!]!
}
type BoxProfile {

View File

@@ -0,0 +1,38 @@
import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const nilUUID = '00000000-0000-0000-0000-000000000000';
const isUUID = (value: string) => {
return uuidRegex.test(value) || nilUUID === value;
};
export const uuid = new GraphQLScalarType({
name: 'uuid',
description:
'The `uuid` scalar type represents UUID values as specified by [RFC 4122](https://tools.ietf.org/html/rfc4122).',
serialize: (value) => {
if (!isUUID(value)) {
throw new TypeError(`UUID cannot represent non-UUID value: ${value}`);
}
return value.toLowerCase();
},
parseValue: (value) => {
if (!isUUID(value)) {
throw new TypeError(`UUID cannot represent non-UUID value: ${value}`);
}
return value.toLowerCase();
},
parseLiteral: (ast) => {
if (ast.kind === Kind.STRING) {
if (isUUID(ast.value)) {
return ast.value;
}
}
return undefined;
},
});