Update verifier

- Adding verification for 3 new certificate types
This commit is contained in:
sairajzero 2021-09-25 03:19:00 +05:30
parent 83aa6a5dd4
commit 7a75ebeaa4

View File

@ -14,9 +14,7 @@
//Required for blockchain API operators //Required for blockchain API operators
apiURL: { apiURL: {
FLO: ['https://explorer.mediciland.com/', 'https://livenet.flocha.in/', 'https://flosight.duckdns.org/', FLO: [ 'https://livenet.flocha.in/', 'https://flosight.duckdns.org/'],
'http://livenet-explorer.floexperiments.com/'
],
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/'] FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
}, },
//adminID: null, //adminID: null,
@ -45,9 +43,12 @@ body{
body > * { body > * {
grid-column: 2; grid-column: 2;
} }
h2{ #result_box h2{
text-transform: capitalize; text-transform: capitalize;
} }
#result_box h3{
text-align: center;
}
h4{ h4{
font-weight: 500; font-weight: 500;
font-size: 1.1rem; font-size: 1.1rem;
@ -60,8 +61,9 @@ h4{
text-align: center; text-align: center;
margin-bottom: 2rem; margin-bottom: 2rem;
} }
p{ #result_box p{
font-size: 1.1rem; font-size: 1.1rem;
text-align: justify;
line-height: 1.7; line-height: 1.7;
max-width: 70ch; max-width: 70ch;
opacity: 0.8; opacity: 0.8;
@ -7799,8 +7801,18 @@ Bitcoin.Util = {
console.log(key, value) console.log(key, value)
switch (key) { switch (key) {
case "internCertificate": case "internCertificate":
internVerification(value); verifyCertificate(value, "RIBC certificate", "CERTIFICATE OF INTERNSHIP");
break; break;
case "employeeCertificate":
verifyCertificate(value, "Employee certificate", "CERTIFICATE OF EMPLOYMENT");
break;
case "volunteerCertificate":
verifyCertificate(value, "Volunteer certificate", "CERTIFICATE OF VOLUNTEERSHIP");
break;
case "participationCertificate":
verifyCertificate(value, "Participation certificate", "CERTIFICATE OF PARTICIPATION");
break;
} }
}).catch(e => { }).catch(e => {
console.error(e) console.error(e)
@ -7812,12 +7824,13 @@ Bitcoin.Util = {
const verified = document.getElementById('verified'), const verified = document.getElementById('verified'),
unverified = document.getElementById('unverified'), unverified = document.getElementById('unverified'),
tryagain = document.getElementById('try-again') tryagain = document.getElementById('try-again');
function internVerification(id) { function verifyCertificate(id, certType, verifierContent) {
floBlockchainAPI.getTx(id).then(tx => { floBlockchainAPI.getTx(id).then(tx => {
let iVerify = false, let iVerify = false,
oVerify = false; oVerify = false,
cVerify = false;
for (let i of tx.vin) for (let i of tx.vin)
if (floGlobals.RMcertificateProvider === i.addr) { if (floGlobals.RMcertificateProvider === i.addr) {
iVerify = true; iVerify = true;
@ -7828,40 +7841,45 @@ Bitcoin.Util = {
oVerify = true; oVerify = true;
break; break;
} }
if (iVerify && oVerify) { cVerify = tx.floData.startsWith(verifierContent);
console.log("Internship Certificate Verified") if (iVerify && oVerify && cVerify) {
let link = getBlockchainLink(`tx/${id}`) console.log(`${certType} (${id}) verified`);
outputUI("RIBC certificate", tx.floData, `Issue Date: ${trimDate(tx.time*1000)}`, link) let link = getBlockchainLink(`tx/${id}`),
content = tx.floData.substring(verifierContent.length).trim(),
time = `Issue Date: ${trimDate(tx.time*1000)}`;
outputUI(certType, verifierContent, content, time, link);
verified.classList.remove('hide-completely') verified.classList.remove('hide-completely')
unverified.classList.add('hide-completely') unverified.classList.add('hide-completely')
tryagain.classList.add('hide-completely') tryagain.classList.add('hide-completely')
} else { } else {
console.log("Verification failed") console.log(`${certType} (${id}) verification failed`);
verified.classList.add('hide-completely') verified.classList.add('hide-completely')
unverified.classList.remove('hide-completely') unverified.classList.remove('hide-completely')
tryagain.classList.add('hide-completely') tryagain.classList.add('hide-completely')
} }
}).catch(error => { }).catch(error => {
console.log("Verification failed") console.log(`${certType} (${id}) not verified`);
verified.classList.add('hide-completely') verified.classList.add('hide-completely')
unverified.classList.remove('hide-completely') unverified.classList.remove('hide-completely')
tryagain.classList.add('hide-completely') tryagain.classList.add('hide-completely')
}) })
} }
function outputUI(head, body, foot, link) { function outputUI(head, type, body, foot, link) {
let h = document.createElement('h2') let h = document.createElement('h2');
h.textContent = head h.textContent = head;
let b = document.createElement('p') let t = document.createElement('h3');
b.textContent = body t.textContent = type;
let f = document.createElement('a') let b = document.createElement('p');
f.textContent = foot b.textContent = body;
let f = document.createElement('a');
f.textContent = foot;
if (link) { if (link) {
f.setAttribute('href', link) f.setAttribute('href', link)
f.setAttribute('target', '_blank') f.setAttribute('target', '_blank')
f.setAttribute('title', 'View in blockchain') f.setAttribute('title', 'View in blockchain')
} }
document.getElementById("result_box").append(h, b, f) document.getElementById("result_box").append(h, t, b, f);
} }
function getBlockchainLink(path) { function getBlockchainLink(path) {