Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new interface replaces relation service #9666

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/web3-providers/src/NextID/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export const KV_BASE_URL_DEV = 'https://kv-service.nextnext.id'
export const KV_BASE_URL_PROD = 'https://kv-service.next.id'
export const PROOF_BASE_URL_DEV = 'https://proof-service.nextnext.id/'
export const PROOF_BASE_URL_PROD = 'https://proof-service.next.id/'
export const RELATION_SERVICE_URL = 'https://relation-service.next.id/'
export const RELATION_SERVICE_URL = 'https://relation-service.nextnext.id/'
157 changes: 64 additions & 93 deletions packages/web3-providers/src/NextID/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type NextIDPersonaBindings,
type NextIDEnsRecord,
createBindingProofFromProfileQuery,
EMPTY_LIST,
} from '@masknet/shared-base'
import { PROOF_BASE_URL_DEV, PROOF_BASE_URL_PROD, RELATION_SERVICE_URL } from './constants.js'
import { staleNextIDCached } from './helpers.js'
Expand All @@ -23,6 +24,40 @@ import type { NextIDBaseAPI } from '../entry-types.js'
const BASE_URL =
process.env.channel === 'stable' && process.env.NODE_ENV === 'production' ? PROOF_BASE_URL_PROD : PROOF_BASE_URL_DEV

const relationServiceQuery = ` domain(domainSystem: "ENS", name: $identity) {
source
system
name
fetcher
resolved {
identity
platform
displayName
}
owner {
identity
platform
displayName
neighborWithTraversal(depth: 5) {
... on ProofRecord {
__typename
source
from {
uuid
platform
identity
displayName
}
to {
uuid
platform
identity
displayName
}
}
}
}
}`
interface CreatePayloadBody {
action: string
platform: string
Expand Down Expand Up @@ -200,10 +235,11 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
async queryProfilesByAddress(address: string) {
const { data } = await fetchJSON<{
data: {
identity: {
nft: NextIDEnsRecord[]
neighborWithTraversal: NeighborList
}
domain: {
owner: {
neighborWithTraversal: NeighborList
}
} | null
}
}>(
RELATION_SERVICE_URL,
Expand All @@ -212,41 +248,19 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
mode: 'cors',
body: JSON.stringify({
operationName: 'GET_PROFILES_QUERY',
variables: { platform: 'ethereum', identity: address.toLowerCase() },
variables: { identity: address.toLowerCase() },
query: `
query GET_PROFILES_QUERY($platform: String, $identity: String) {
identity(platform: $platform, identity: $identity) {
nft(category: ["ENS"]) {
uuid
category
chain
address
id
}
neighborWithTraversal(depth: 5) {
source
to {
uuid
platform
identity
displayName
}
from {
uuid
platform
identity
displayName
}
}
}
query GET_PROFILES_QUERY($identity: String) {
${relationServiceQuery}
}
`,
}),
},
{ enableSquash: true },
)

const bindings = createBindProofsFromNeighbor(data.identity.neighborWithTraversal, data.identity.nft)
if (!data.domain) return EMPTY_LIST
const bindings = createBindProofsFromNeighbor(data.domain.owner.neighborWithTraversal, [])

return uniqWith(bindings, (a, b) => a.identity === b.identity && a.platform === b.platform).filter(
(x) => ![NextIDPlatform.Ethereum, NextIDPlatform.NextID].includes(x.platform) && x.identity,
Expand All @@ -256,10 +270,11 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
async queryProfilesByTwitterId(twitterId: string) {
const { data } = await fetchJSON<{
data: {
identity: {
nft: NextIDEnsRecord[]
neighborWithTraversal: NeighborList
}
domain: {
owner: {
neighborWithTraversal: NeighborList
}
} | null
}
}>(
RELATION_SERVICE_URL,
Expand All @@ -268,41 +283,19 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
mode: 'cors',
body: JSON.stringify({
operationName: 'GET_PROFILES_BY_TWITTER_ID',
variables: { platform: 'twitter', identity: twitterId.toLowerCase() },
variables: { identity: twitterId.toLowerCase() },
query: `
query GET_PROFILES_BY_TWITTER_ID($platform: String, $identity: String) {
identity(platform: $platform, identity: $identity) {
nft(category: ["ENS"]) {
uuid
category
chain
address
id
}
neighborWithTraversal(depth: 5) {
source
to {
uuid
platform
identity
displayName
}
from {
uuid
platform
identity
displayName
}
}
}
query GET_PROFILES_BY_TWITTER_ID($identity: String) {
${relationServiceQuery}
}
`,
}),
},
{ enableSquash: true },
)

const bindings = createBindProofsFromNeighbor(data.identity.neighborWithTraversal, data.identity.nft)
if (!data.domain) return EMPTY_LIST
const bindings = createBindProofsFromNeighbor(data.domain.owner.neighborWithTraversal, [])

return uniqWith(bindings, (a, b) => a.identity === b.identity && a.platform === b.platform).filter(
(x) => ![NextIDPlatform.Ethereum, NextIDPlatform.NextID].includes(x.platform) && x.identity,
Expand All @@ -313,9 +306,10 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
const lowerCaseId = twitterId.toLowerCase()
const { data } = await fetchJSON<{
data: {
identity: {
nft: NextIDEnsRecord[]
neighborWithTraversal: NeighborList
domain: {
owner: {
neighborWithTraversal: NeighborList
}
} | null
}
}>(
Expand All @@ -325,33 +319,10 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
mode: 'cors',
body: JSON.stringify({
operationName: 'GET_LENS_PROFILES',
variables: { platform: 'twitter', identity: lowerCaseId },
variables: { identity: lowerCaseId },
query: `
query GET_LENS_PROFILES($platform: String, $identity: String) {
identity(platform: $platform, identity: $identity) {
nft(category: ["ENS"]) {
uuid
category
chain
address
id
}
neighborWithTraversal(depth: 5) {
source
to {
uuid
platform
identity
displayName
}
from {
uuid
platform
identity
displayName
}
}
}
query GET_LENS_PROFILES($identity: String) {
${relationServiceQuery}
}
`,
}),
Expand All @@ -360,10 +331,10 @@ export class NextIDProofAPI implements NextIDBaseAPI.Proof {
)

const connectionsTo =
data.identity?.neighborWithTraversal.filter((x) => x.to.platform === NextIDPlatform.LENS) || []
data.domain?.owner.neighborWithTraversal.filter((x) => x.to.platform === NextIDPlatform.LENS) || []

const connectionsFrom =
data.identity?.neighborWithTraversal.filter((x) => x.from.platform === NextIDPlatform.LENS) || []
data.domain?.owner.neighborWithTraversal.filter((x) => x.from.platform === NextIDPlatform.LENS) || []

const id = lowerCaseId as keyof typeof PRESET_LENS
if (connectionsTo.length === 0 && connectionsFrom.length === 0 && PRESET_LENS[id]) {
Expand Down