diff --git a/static/scripts.js b/static/scripts.js index 25afe18..254138b 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -231,11 +231,13 @@ async function verifyProofs(opts) { } async function displayProfile(opts) { - let keyData, keyLink, feedback = "", notation, isVerified, verifications = []; + let keyData, keyLink, fingerprint, feedback = "", notation, isVerified, verifications = []; let icon_qr = ''; try { - keyData = await fetchKeys(opts); + keyData = await doip.keys.fetch.uri(`${opts.mode}:${opts.input}`); + fingerprint = keyData.keyPacket.getFingerprint(); + // keyData = await fetchKeys(opts); } catch (e) { feedback += `

There was a problem fetching the keys.

`; feedback += `${e}`; @@ -244,29 +246,13 @@ async function displayProfile(opts) { return; } - let userData = keyData.user.user.userId; - let userName = userData.name ? userData.name : userData.email; - let userMail = userData.email ? userData.email : null; + const userPrimary = await keyData.getPrimaryUser(); + const userData = userPrimary.user.userId; + const userName = userData.name ? userData.name : userData.email; + const userMail = userData.email ? userData.email : null; let imgUri = null; - let notations = [], notationsRaw = []; - for (var i = 0; i < keyData.publicKey.users.length; i++) { - if (keyData.publicKey.users[i].selfCertifications.length == 0) { continue; } - - notationsRaw = notationsRaw.concat(keyData.publicKey.users[i].selfCertifications[0].notations); - - if (keyData.publicKey.users[i].userAttribute != null && keyData.publicKey.users[i].userAttribute.attributes[0][0] === String.fromCharCode(1)) { - imgUri = "data:image/jpeg;base64," + btoa(keyData.publicKey.users[i].userAttribute.attributes[0].substring(17)); - } - } - notationsRaw.forEach((item, i) => { - if (item[0] == "proof@metacode.biz") { - notations.push(item[1]); - } - }); - notations = Array.from(new Set(notations)); // Deduplicate (ES6) - // Determine WKD or HKP link switch (opts.mode) { case "wkd": @@ -325,49 +311,21 @@ async function displayProfile(opts) { feedback += `
`; feedback += `
general information
`; feedback += ``; - if (userMail) { - feedback += `
`; - feedback += `
primary email
`; - feedback += `
${userMail}
`; - feedback += `
`; - } - for (var i = 0; i < keyData.publicKey.users.length; i++) { - if (keyData.publicKey.users[i].userId && 'email' in keyData.publicKey.users[i].userId && keyData.publicKey.users[i].userId.email && keyData.publicKey.users[i].revocationSignatures.length == 0 && keyData.publicKey.users[i].userId.email != userMail) { - feedback += `
`; - feedback += `
email
`; - feedback += `
${keyData.publicKey.users[i].userId.email}
`; - feedback += `
`; - } - } + feedback += `
`; feedback += `
fingerprint
`; - feedback += `
${keyData.fingerprint}`; + feedback += `
${fingerprint}`; if (opts.mode == "hkp") { - feedback += `${icon_qr}`; + feedback += `${icon_qr}`; } feedback += `
`; - // if (opts.mode == "hkp") { - // feedback += `
`; - // feedback += `
qrcode
`; - // feedback += ``; - // feedback += `
`; - // } - - if (notations.length > 0) { - feedback += `
`; - feedback += `
`; - feedback += `
proofs
`; - feedback += `
`; - - feedback += `
`; - feedback += `
`; - feedback += `
`; - feedback += `
Verifying proofs…
`; - feedback += `
`; - feedback += `
`; - } - + feedback += `
`; + feedback += `
`; + feedback += `
`; + feedback += `
Verifying proofs…
`; + feedback += `
`; + feedback += `
`; feedback += `
`; feedback += `
`; feedback += `
actions
`; @@ -384,49 +342,152 @@ async function displayProfile(opts) { // Display feedback document.body.querySelector('#profileData').innerHTML = feedback; - // Exit if no notations are available - if (notations.length == 0) { + try { + verifications = await doip.claims.verify(keyData, fingerprint, {'proxyPolicy':'adaptive'}) + } catch (e) { + feedback += `

There was a problem verifying the claims.

`; + feedback += `${e}`; + document.body.querySelector('#profileData').innerHTML = feedback; + document.body.querySelector('#profileName').innerHTML = "Could not load profile"; return; } - // Verify identity proofs - let proofResult; - for (var i = 0; i < notations.length; i++) { - notation = notations[i]; - proofResult = await verifyProof(notation, keyData.fingerprint); - if (!proofResult || !proofResult.display) { continue; } - verifications.push(proofResult); + // Exit if no notations are available + if (verifications.length == 0) { + return; } - // One-line sorting function (order verifications by type) - verifications = verifications.sort((a,b) => (a.type > b.type) ? 1 : ((b.type > a.type) ? -1 : 0)); - feedback = ""; - if (verifications.length > 0) { - for (var i = 0; i < verifications.length; i++) { - if (!verifications[i].type) { continue; } - feedback += `
`; - feedback += `
${verifications[i].type}
`; - feedback += `
`; - feedback += `${verifications[i].display}`; - if (verifications[i].isVerified) { - feedback += `verified ✔`; - } else { - feedback += `unverified`; + if (userMail) { + verifications.forEach((userId, i) => { + if (keyData.users[i].userId.email != userMail) { + return; } - if (verifications[i].isVerified && verifications[i].qr) { - feedback += `${icon_qr}`; + + feedback += `
`; + feedback += `
`; + // feedback += ``; + feedback += `
${keyData.users[i].userId.email} (primary)
`; + feedback += `
`; + + if (userId.length == 0) { + feedback += `
`; + feedback += `
`; + feedback += `
No claims associated
`; + feedback += `
`; + return; } - feedback += `
`; - feedback += `
`; - } - } else { - feedback += `
`; - feedback += `
`; - feedback += `
No proofs found in key
`; - feedback += `
`; + + userId = userId.sort((a,b) => (a.serviceproviderData.serviceprovider.name > b.serviceproviderData.serviceprovider.name) ? 1 : ((b.serviceproviderData.serviceprovider.name > a.serviceproviderData.serviceprovider.name) ? -1 : 0)); + + userId.forEach((claim, i) => { + const claimData = claim.serviceproviderData; + if (!claimData.serviceprovider.name) { + return; + } + feedback += `
`; + feedback += `
${claimData.serviceprovider.name}
`; + feedback += `
`; + feedback += `${claimData.profile.display}`; + if (claim.isVerified) { + feedback += `verified ✔`; + } else { + feedback += `unverified`; + } + if (claim.isVerified && claimData.profile.qr) { + feedback += `${icon_qr}`; + } + feedback += `
`; + feedback += `
`; + }); + }); } + verifications.forEach((userId, i) => { + if (userMail && keyData.users[i].userId.email == userMail) { + return; + } + + feedback += `
`; + feedback += `
`; + feedback += `
${keyData.users[i].userId.email}
`; + feedback += `
`; + + if (userId.length == 0) { + feedback += `
`; + feedback += `
`; + feedback += `
No claims associated
`; + feedback += `
`; + return; + } + + userId = userId.sort((a,b) => (a.serviceproviderData.serviceprovider.name > b.serviceproviderData.serviceprovider.name) ? 1 : ((b.serviceproviderData.serviceprovider.name > a.serviceproviderData.serviceprovider.name) ? -1 : 0)); + + userId.forEach((claim, i) => { + const claimData = claim.serviceproviderData; + if (!claimData.serviceprovider.name) { + return; + } + feedback += `
`; + feedback += `
${claimData.serviceprovider.name}
`; + feedback += `
`; + feedback += `${claimData.profile.display}`; + if (claim.isVerified) { + feedback += `verified ✔`; + } else { + feedback += `unverified`; + } + if (claim.isVerified && claimData.profile.qr) { + feedback += `${icon_qr}`; + } + feedback += `
`; + feedback += `
`; + }); + }); + + // userId.forEach((claim, i) => { + // feedback += `
`; + // feedback += `
${verifications[i].type}
`; + // feedback += `
`; + // feedback += `${verifications[i].display}`; + // if (verifications[i].isVerified) { + // feedback += `verified ✔`; + // } else { + // feedback += `unverified`; + // } + // if (verifications[i].isVerified && verifications[i].qr) { + // feedback += `${icon_qr}`; + // } + // feedback += `
`; + // feedback += `
`; + // }); + + + // if (verifications.length > 0) { + // for (var i = 0; i < verifications.length; i++) { + // if (!verifications[i].type) { continue; } + // feedback += `
`; + // feedback += `
${verifications[i].type}
`; + // feedback += `
`; + // feedback += `${verifications[i].display}`; + // if (verifications[i].isVerified) { + // feedback += `verified ✔`; + // } else { + // feedback += `unverified`; + // } + // if (verifications[i].isVerified && verifications[i].qr) { + // feedback += `${icon_qr}`; + // } + // feedback += `
`; + // feedback += `
`; + // } + // } else { + // feedback += `
`; + // feedback += `
`; + // feedback += `
No proofs found in key
`; + // feedback += `
`; + // } + // Display feedback document.body.querySelector('#profileProofs').innerHTML = feedback; } @@ -795,7 +856,7 @@ async function verifyProof(url, fingerprint) { } catch (e) { console.warn(e); } - + // Return output without confirmed proof return output; }