From 39e29f7519a455ea98568b185dd98104d9e4b1e4 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sat, 16 Dec 2023 01:03:06 +0530 Subject: [PATCH] added better error reporting --- index.html | 99 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/index.html b/index.html index b5b869c..7a3d456 100644 --- a/index.html +++ b/index.html @@ -748,7 +748,7 @@ pseudoDisable(e.target, true) renderElem(e.target, html`Checking...`) const { hasValidHash, knownHash, latestHash } = await hasAKnownHash(appLink) - const hashes = html` + const hashes = latestHash && knownHash && html`

Authorized hash for private key usage

@@ -770,14 +770,33 @@ Failed integrity check `) renderElem(getRef('integrity_check_popup__content'), html` -
- -

Failed integrity check

+
+
+
+ +

Failed integrity check

+
+

+ The dapp has failed integrity check. Please don't use it. +

+
+
+

Failed checks

+
    + ${!latestHash ? html` +
  1. + Couldn't generate hash for the link. +
  2. + ` : ''} + ${latestHash && latestHash !== knownHash ? html` +
  3. + The content of the site has been modified through unauthorized means. +
  4. + `: ''} +
+
+ ${hashes}
-

- The dapp has failed integrity check. Please don't use it. -

- ${hashes} `) } else { renderElem(getRef('integrity_check_popup__content'), html` @@ -947,7 +966,7 @@ let knownHash, latestHash, hasValidHash const dappInfo = dappsList.find(({ appLink }) => linkToVerify.includes(appLink)) if (!dappInfo) return false - const { appHash, repoHash } = dappInfo + const { appHash, repoHash, automatedChecking = false } = dappInfo if (linkToVerify.includes('https://blockbook.ranchimall.net')) { // blockbook is special case // it is a server side rendered app @@ -957,16 +976,22 @@ knownHash = repoHash hasValidHash = latestHash === knownHash } else { - const [contentHash, latestRepoHash] = await Promise.all([ - getLinkContentHash(linkToVerify), - getRepoHash(dappInfo.appLink.split('/').pop()) - ]) - latestHash = contentHash[0].hash - knownHash = appHash - hasValidHash = latestHash === knownHash && repoHash === latestRepoHash; - if (!hasValidHash && repoHash !== latestRepoHash) { - latestHash = latestRepoHash - knownHash = repoHash + if (automatedChecking) { + const latestRepoHash = await getRepoHash(dappInfo.appLink.split('/').pop()) + latestHash = knownHash = latestRepoHash + hasValidHash = true + } else { + const [contentHash, latestRepoHash] = await Promise.all([ + getLinkContentHash(linkToVerify), + getRepoHash(dappInfo.appLink.split('/').pop()) + ]) + latestHash = contentHash[0].hash + knownHash = appHash + hasValidHash = latestHash === knownHash && repoHash === latestRepoHash; + if (!hasValidHash && repoHash !== latestRepoHash) { + latestHash = latestRepoHash + knownHash = repoHash + } } } return { hasValidHash, latestHash, knownHash } @@ -1026,12 +1051,38 @@ `) } else { getRef('verification_form').after(html.node/*html*/` -
- -

Danger!

+
+
+
+ +

Danger!

+
+

+ Please don't enter your private key on this link. +

+
+
+

Failed checks

+
    + ${!linkIsAuthorized ? html` +
  1. + This link is not authorized by us. +
  2. + ` : ''} + ${linkIsAuthorized && !latestHash ? html` +
  3. + Couldn't generate hash for the link. +
  4. + ` : ''} + ${linkIsAuthorized && latestHash && latestHash !== knownHash ? html` +
  5. + The content of the site has been modified through unauthorized means. +
  6. + `: ''} +
+ ${hashes} +
-

Link you provided is not genuine

- ${hashes} `) } } catch (e) {