Skip to content

Instantly share code, notes, and snippets.

@sivsivsree
Last active November 9, 2021 07:42
Show Gist options
  • Save sivsivsree/070c2601252912e52f355d663d63ac8f to your computer and use it in GitHub Desktop.
Save sivsivsree/070c2601252912e52f355d663d63ac8f to your computer and use it in GitHub Desktop.
/*(()=>{let e="#shahada *{box-sizing:border-box;padding:0;margin:0;font-family:Tahoma,sans-serif}\n#shahada .grid{display:flex;font-family:Tahoma,sans-serif}\n#shahada .grid .grid-list ul{padding:16px}\n#shahada .grid .grid-list li{list-style:none;font-size:12px;margin-bottom:1.3em}\n#shahada .grid .grid-list li div{margin-bottom:.5em;text-overflow:ellipsis;line-break:anywhere;font-size:12px}\n#shahada .hr{border-top:1px solid #f1f2f3}\n#shahada .verified{padding:10px;box-sizing:border-box;border-left:3px solid;margin:16px}\n#shahada .is-success{background-color:rgba(42,178,123,0.1);border-color:#2ab27b}\n#shahada .is-error{background-color:rgba(245,17,17,0.1);border-color:#f90e0e}\n#shahada .check:before{display:inline-block;vertical-align:top;line-height:1em;width:1em;height:1em;margin-right:.3em;text-align:center;content:'✔';color:#2ab27b}\n#shahada .shahda-footer{height:50px;margin:10px}\n#shahada .shahda-footer img{height:100%}";const i=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");i.appendChild(t),t.type="text/css",t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e));const d=document.getElementById("shahada"),n=document.createElement("div");n.setAttribute("style","font-family: Tahoma,sans-serif;");const a=document.createElement("div");a.setAttribute("style","padding: 8px;");const s=document.createElement("input");s.setAttribute("type","file"),s.id="file-selector",s.setAttribute("style","display: none"),s.setAttribute("accept","application/pdf");const l=document.createElement("div");l.id="progressBar",l.setAttribute("style","background-color: #f1f1f1!important;display:none;"),l.innerHTML='<div id="myBar" style="height:4px;width:0;color: #fff!important; background-color: #1185c6!important;"></div>';const o=document.createElement("label");o.id="file-label",o.setAttribute("for","file-selector"),o.setAttribute("style","padding: 16px; width:100%; color:#1185c6; font-size: 14px;display: block;font-family: Tahoma,sans-serif; border: 1px solid #1185c6;"),o.innerText="Select Certificate for Verification",a.append(s,l,o);const r=document.createElement("div");r.setAttribute("style","padding: 8px; margin-top: 4px; display: flex;");const c=document.createElement("img");c.setAttribute("style","height: 30px;"),c.setAttribute("src","https://shahada.azurewebsites.net/wp-content/uploads/2020/01/Shahada-logo-2.svg");const p=document.createElement("div");p.setAttribute("style","margin-left:7px; padding-left:7px; font-size: 10px; border-left: 1px solid #ddd;");const g=document.createElement("div");g.setAttribute("style","padding: 2px;"),g.innerHTML='Verification powered by <a style="text-decoration: none;color: #00732f" href="https://www.shahada.ae">Shahada</a>';const v=document.createElement("div");v.setAttribute("style","padding: 2px;"),v.innerHTML='<a style="text-decoration: none; color: #b2b2b2" target="_blank" href="https://www.shahada.ae/terms">Terms and Conditions</a>',p.append(g,v),r.append(c,p),n.append(a,r),d.append(n),s.addEventListener("change",e=>{h(e)});const h=e=>{const i=f(),t=e.target.files,d=t[0];document.getElementById("file-label").innerText="Verifying "+d.name;const n=new FormData;n.append("file",t[0]),fetch("http://shahadauoduat.uaenorth.cloudapp.azure.com:5052/v1/certificate-verify",{method:"POST",body:n,redirect:"follow"}).then(e=>e.json()).then(e=>{e&&e.status?e.valid?(m(e,null),document.getElementById("pdf-preview").src=e.url):m(null,"Not a valid Credential."):m(null,"Invalid Credential")}).catch(e=>{console.error(e),m(null,"Verification failed")}).finally(()=>{y(i)})},m=(e,i)=>{const t=document.createElement("div");t.id="dialogue",t.setAttribute("style","display: block; position: absolute; width: 100%; height:100%; top:0; left: 0; background: #fff;");let n="";if(console.log(e,e),e){const i=new Date(e.json.issuedOn),t=e.json.badge.issuer;n=`\n ${(e=>{let i="";return e.pdf||(i='<div class="verified is-error">\n <div style="display:flex">\n <div></div>\n <div style="padding-left: 8px;padding-top: 3px;">Credential Not valid</div>\n </div>\n <div style="font-size: 12px; margin-top:8px;">\n <div class="">PDF is invalid or tampered</div>\n </div>\n </div>'),e.cjson||(i='<div class="verified is-error">\n <div style="display:flex">\n <div></div>\n <div style="padding-left: 8px;padding-top: 3px;">Credential Not valid</div>\n </div>\n <div style="font-size: 12px; margin-top:8px;">\n <div class="">JSON data invalid</div>\n </div>\n </div>'),e.isRevoked&&(i='<div class="verified is-error">\n <div style="display:flex">\n <div></div>\n <div style="padding-left: 8px;padding-top: 3px;">Credential Revoked</div>\n </div>\n <div style="font-size: 12px; margin-top:8px;">\n <div class="check">PDF signed and not tampered</div>\n <div class="check">Format Validation</div>\n <div class="">Credential is revoked</div>\n </div>\n </div>'),e.pdf&&e.cjson&&!e.isRevoked&&(i='<div class="verified is-success">\n <div style="display:flex">\n <div><img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyM3B4IiB2aWV3Qm94PSIwIDAgMjAgMjMiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8ZyBpZD0iVmVyaWZpY2F0aW9uIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgICAgICA8ZyBpZD0iMyIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTI1NC4wMDAwMDAsIC00NzQuMDAwMDAwKSIgZmlsbD0iIzJBQjI3QiI+CiAgICAgICAgICAgIDxnIGlkPSJHcm91cCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMjQ4LjAwMDAwMCwgNDY5LjAwMDAwMCkiPgogICAgICAgICAgICAgICAgPHBhdGggZD0iTTE2LDUgTDYsOS4xODE4MTgxOCBMNiwxNS40NTQ1NDU1IEM2LDIxLjI1NjgxODIgMTAuMjY2NjY2NywyNi42ODI3MjczIDE2LDI4IEMyMS43MzMzMzMzLDI2LjY4MjcyNzMgMjYsMjEuMjU2ODE4MiAyNiwxNS40NTQ1NDU1IEwyNiw5LjE4MTgxODE4IEwxNiw1IEwxNiw1IFogTTksMTcuNzUzNzE1NSBMMTAuNTI3NSwxNi4yNTY5MDAyIEwxMy4zMzMzMzMzLDE4Ljk5NTc1MzcgTDIwLjQ3MjUsMTIgTDIyLDEzLjUwNzQzMSBMMTMuMzMzMzMzMywyMiBMOSwxNy43NTM3MTU1IFoiIGlkPSJTaGFwZSI+PC9wYXRoPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4="></div>\n <div style="padding-left: 8px;padding-top: 3px;">Certificate Valid</div>\n </div>\n <div style="font-size: 12px; margin-top:8px;">\n <div class="check">PDF signed and not tampered</div>\n <div class="check">Format Validation</div>\n <div class="check">Credential Status</div>\n </div>\n </div>'),i})(e.verification)}\n <ul>\n <li>\n <div><b>ISSUE DATE</b></div>\n <div>${i.toDateString()}</div>\n </li>\n\n <li>\n <div><b>ISSUER</b></div>\n <div>${t.name}</div>\n </li>\n\n <li>\n <div><b>ISSUED TO</b></div>\n <div>${e.json.recipientProfile.name}</div>\n </li>\n\n <li>\n <div><b>TRANSACTION ID</b></div>\n <div>${e.json.verification.publicKey}</div>\n </li>\n </ul>\n <div class="hr"></div> <div class="shahda-footer"><img src="https://shahada.azurewebsites.net/wp-content/uploads/2020/01/Shahada-logo-2.svg"></div>`}else n='\n <div class="verified is-error">\n <div style="display:flex">\n <div><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgdmlld0JveD0iMCAwIDE4IDE4IiBmaWxsPSIjRjVBNjIzIj48cGF0aCBkPSJNLjUgMTZoMTdMOSAxIC41IDE2em05LjUtMkg4di0yaDJ2MnptMC0zSDhWN2gydjR6Ii8+PC9zdmc+IA=="></div>\n <div style="padding-left: 8px;padding-top: 3px;">Invalid Certificate</div>\n </div>\n </div>\n <div class="hr"></div> <div><img class="shahda-footer" src="https://shahada.azurewebsites.net/wp-content/uploads/2020/01/Shahada-logo-2.svg"></div>';t.innerHTML=`\n <div class="grid">\n <div class="grid-list" style="width: 350px; border-left: 1px solid #f1f2f3;">\n <div style="text-align: left">\n <button style="background: #ddd; border: 1px solid #ddd; width: 30px; height: 30px;" onclick="document.getElementById('dialogue').remove();document.getElementById('file-selector').value = '' ">\n X\n </button>\n </div>${n}</div>\n <div class="grid-list" style="width:100%; height: 100vh">\n <embed id='pdf-preview' src="" type="application/pdf" height="100%" width="100%">\n </div>\n </div>`,d.appendChild(t)},f=()=>{document.getElementById("progressBar").style.display="block";const e=document.getElementById("myBar");let i=0;return setInterval((function(){i>=100?i=1:(i+=.05,e.style.width=i+"%")}),10)},y=e=>{clearInterval(e);const i=document.getElementById("progressBar");document.getElementById("file-label").innerText="Select Certificate for Verification",i.style.display="none"}})();*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment