diff --git a/api/v0/index.js b/api/v0/index.js index 54c3de5..a129ed4 100644 --- a/api/v0/index.js +++ b/api/v0/index.js @@ -134,6 +134,16 @@ const apiProfileSchema = { verification: { type: "object" }, + summary: { + type: "object", + properties: { + profileName: { type: "string" }, + profileURL: { type: "string" }, + serviceProviderName: { type: "string" }, + isVerificationDone: { type: "boolean" }, + isVerified: { type: "boolean" }, + } + } } } }, @@ -153,6 +163,12 @@ const apiProfileSchema = { }, }, }, + keyoxide: { + type: "object", + properties: { + url: { type: "string" }, + } + }, extra: { type: "object", properties: { @@ -163,7 +179,7 @@ const apiProfileSchema = { type: "array" }, }, - required: ["keyData", "extra", "errors"], + required: ["keyData", "keyoxide", "extra", "errors"], additionalProperties: false } @@ -237,6 +253,33 @@ const sanitize = (data) => { return data } +const addSummaryToClaims = (data) => { + // To be removed when data is added by DOIP library + for (let userIndex = 0; userIndex < data.keyData.users.length; userIndex++) { + const user = data.keyData.users[userIndex] + + for (let claimIndex = 0; claimIndex < user.claims.length; claimIndex++) { + const claim = user.claims[claimIndex] + + const isVerificationDone = claim.status === "verified" + const isVerified = isVerificationDone ? claim.verification.result : false + const isAmbiguous = isVerified + ? false + : claim.matches.length > 1 || claim.matches[0].match.isAmbiguous + + data.keyData.users[userIndex].claims[claimIndex].summary = { + profileName: !isAmbiguous ? claim.matches[0].profile.display : claim.uri, + profileURL: !isAmbiguous ? claim.matches[0].profile.uri : "", + serviceProviderName: !isAmbiguous ? claim.matches[0].serviceprovider.name : "", + isVerificationDone: isVerificationDone, + isVerified: isVerified, + } + } + } + + return data +} + router.get('/profile/fetch', check('query').exists(), check('protocol').optional().toLowerCase().isIn(["hkp", "wkd"]), @@ -291,6 +334,9 @@ router.get('/profile/fetch', data.extra = {} data.errors = [error.message] } + + // Add missing data + data = addSummaryToClaims(data) let statusCode = 200 if (data.errors.length > 0) { @@ -321,6 +367,9 @@ router.get('/profile/verify', data.extra = {} data.errors = [error.message] } + + // Add missing data + data = addSummaryToClaims(data) let statusCode = 200 if (data.errors.length > 0) { diff --git a/server/index.js b/server/index.js index d5ef3f4..a856f1e 100644 --- a/server/index.js +++ b/server/index.js @@ -41,9 +41,13 @@ const generateWKDProfile = async (id) => { keyData.key.data = {} keyData = processKeyData(keyData) + let keyoxideData = {} + keyoxideData.url = `https://${process.env.DOMAIN}/wkd/${id}` + return { key: key, keyData: keyData, + keyoxide: keyoxideData, extra: await computeExtraData(key, keyData), errors: [] } @@ -52,6 +56,7 @@ const generateWKDProfile = async (id) => { return { key: {}, keyData: {}, + keyoxide: {}, extra: {}, errors: [err.message] } @@ -68,9 +73,17 @@ const generateHKPProfile = async (id, keyserverDomain) => { keyData.key.data = {} keyData = processKeyData(keyData) + let keyoxideData = {} + if (!keyserverDomain || keyserverDomain === 'keys.openpgp.org') { + keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${id}` + } else { + keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${keyserverDomain}/${id}` + } + return { key: key, keyData: keyData, + keyoxide: keyoxideData, extra: await computeExtraData(key, keyData), errors: [] } @@ -79,6 +92,7 @@ const generateHKPProfile = async (id, keyserverDomain) => { return { key: {}, keyData: {}, + keyoxide: {}, extra: {}, errors: [err.message] } @@ -94,9 +108,12 @@ const generateSignatureProfile = async (signature) => { keyData.key.data = {} keyData = processKeyData(keyData) + let keyoxideData = {} + return { key: key, keyData: keyData, + keyoxide: keyoxideData, extra: await computeExtraData(key, keyData), errors: [] } @@ -105,6 +122,7 @@ const generateSignatureProfile = async (signature) => { return { key: {}, keyData: {}, + keyoxide: {}, extra: {}, errors: [err.message] } @@ -121,9 +139,13 @@ const generateKeybaseProfile = async (username, fingerprint) => { keyData.key.data = {} keyData = processKeyData(keyData) + let keyoxideData = {} + keyoxideData.url = `https://${process.env.DOMAIN}/keybase/${username}/${fingerprint}` + return { key: key, keyData: keyData, + keyoxide: keyoxideData, extra: await computeExtraData(key, keyData), errors: [] } @@ -132,6 +154,7 @@ const generateKeybaseProfile = async (username, fingerprint) => { return { key: {}, keyData: {}, + keyoxide: {}, extra: {}, errors: [err.message] }