Adding file integrity check

This commit is contained in:
sairaj mote 2023-12-03 22:15:59 +05:30
parent 2352960418
commit 2cf55956f2
3 changed files with 227 additions and 143 deletions

View File

@ -65,7 +65,6 @@
</sm-popup>
<script src="scripts/components.min.js"></script>
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
<script src="scripts/octokit.js" type="module"></script>
<script>
const { html, svg, render: renderElem } = uhtml;
const uiGlobals = {}
@ -119,7 +118,7 @@
}
})
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
function notify(message, mode, options = {}) {
function notify(message, mode, options = { timeout, pinned }) {
let icon
switch (mode) {
case 'success':
@ -127,7 +126,7 @@
break;
case 'error':
icon = `<svg class="icon icon--error" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>`
if (typeof options.pinned === 'undefined')
if (!options.hasOwnProperty('timeout'))
options.pinned = true
break;
}
@ -329,17 +328,32 @@
if (!page)
page = 'home'
const preventDownloadInfoPopup = localStorage.getItem('dontShowDownloadInfo')
if (preventDownloadInfoPopup === null)
document.querySelectorAll('.dapp-download-button').forEach(elem => {
elem.onclick = (e) => openPopup('download_info_popup')
})
document.querySelectorAll('.dapp-download-button').forEach(elem => {
elem.onclick = (e) => {
e.preventDefault()
// check dapp hash before downloading and show error if hash doesn't match
const { hash: knownHash, appLink } = elem.closest('.dapp-card').dataset;
getRepoHash(appLink.split('/').pop()).then(latestHash => {
if (latestHash !== knownHash) {
notify(`The dapp you are trying to download has been modified. Dapp won't be downloaded.`, 'error')
} else {
if (preventDownloadInfoPopup === null || preventDownloadInfoPopup === 'false')
openPopup('download_info_popup')
// initiate download
window.location.href = elem.href
}
}).catch(e => {
console.error(e)
notify('There was an error while trying to download the dapp. Please try again later.', 'error', {
timeout: 10000,
})
})
}
})
}
})
function dontShowInfoAgain() {
localStorage.setItem('dontShowDownloadInfo', true);
document.querySelectorAll('.dapp-download-button').forEach(elem => {
elem.onclick = null
})
closePopup()
}
window.addEventListener('load', () => {
@ -359,149 +373,226 @@
<h1>Page not found</h1>
`)
})
const dappsList = [
let dappsList = [
{
name: 'Messenger',
description: 'Chat with your Bitcoin, Ethereum and FLO friends or use Bitcoin and FLO multisig.',
icon: ``,
appLink: 'https://ranchimall.github.io/messenger',
moreLink: '#/dapps/messenger',
tags: ['messenger', 'chat', 'bitcoin', 'ethereum', 'flo', 'multisig'],
category: 'social'
"name": "BTC Mortgage",
"description": "Borrow or Lend USD against Bitcoin",
"icon": "",
"appLink": "https://ranchimall.github.io/btcmortgage",
"moreLink": "#/dapps/btc-mortgage",
"tags": [
"bitcoin",
"mortgage",
"lend",
"borrow"
],
"category": "finance",
"hash": "197f0c491e8cabf866603d03c437f9b96ad5b58ce55de2f6bc0d39a633fdf5e1"
},
{
name: 'FLO Wallet',
description: 'A wallet for FLO',
icon: ``,
appLink: 'https://ranchimall.github.io/flowallet',
moreLink: '#/dapps/flo-wallet',
tags: ['flo', 'wallet'],
category: 'wallet'
"name": "BTC Wallet",
"description": "Send and receive Bitcoin and track transactions.",
"icon": "",
"appLink": "https://ranchimall.github.io/btcwallet",
"moreLink": "#/dapps/btc-wallet",
"tags": [
"bitcoin",
"wallet"
],
"category": "wallet",
"hash": "20f12011d57e157e24b6388b3bb5d7f5970880babe99947dcf50749e08299cc0"
},
{
name: 'FLO Scout',
description: 'Track FLO token transactions and utilize smart contracts.',
icon: ``,
appLink: 'https://ranchimall.github.io/floscout',
moreLink: '#/dapps/flo-scout',
tags: ['flo', 'scout', 'smart contracts'],
category: 'blockchain-explorer'
"name": "Certify",
"description": "Create and distribute blockchain based certificates",
"icon": "",
"appLink": "https://ranchimall.github.io/certify",
"moreLink": "#/dapps/certify",
"tags": [
"certificates",
"certify",
"certification"
],
"category": "identity",
"hash": "99f2b66dcd62b2156b4f64cd4eab8a4efc182284fe13cdb8e2a9876d865c0123"
},
{
name: 'BTC Wallet',
description: 'Send and receive Bitcoin and track transactions.',
icon: ``,
appLink: 'https://ranchimall.github.io/btcwallet',
moreLink: '#/dapps/btc-wallet',
tags: ['bitcoin', 'wallet'],
category: 'wallet'
"name": "Content Collaboration",
"description": "A writing app that allows you to collaborate with others",
"icon": "",
"appLink": "https://ranchimall.github.io/cc",
"moreLink": "#/dapps/content-collaboration",
"tags": [
"collaboration",
"writing",
"content"
],
"category": "content",
"hash": "debdda5bd18f0f4d06876967de5f6dd55f514b9048ec978d435acdbe720a5ff8"
},
{
name: 'Taproot wallet',
description: 'A Bitcoin wallet with Taproot support.',
icon: ``,
appLink: 'https://ranchimall.github.io/taprootwallet',
moreLink: '#/dapps/taproot-wallet',
tags: ['bitcoin', 'wallet', 'taproot'],
category: 'wallet'
"name": "Exchange",
"description": "Trade FLO and FLO tokens with rupee tokens",
"icon": "",
"appLink": "https://ranchimall.github.io/exchangemarket",
"moreLink": "#/dapps/exchange",
"tags": [
"exchange",
"trade",
"flo",
"rupee"
],
"category": "finance",
"hash": "a5dbba6043d82ae04e99a8a522f4ab2d1ba2a2779cdcf4f28c1da2b2acf11df6"
},
{
name: 'FLO Ethereum',
description: 'A Ethereum wallet that works with FLO',
icon: ``,
appLink: 'https://ranchimall.github.io/floethereum',
moreLink: '#/dapps/flo-ethereum',
tags: ['ethereum', 'wallet', 'flo'],
category: 'wallet'
"name": "FLO Ethereum",
"description": "A Ethereum wallet that works with FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/floethereum",
"moreLink": "#/dapps/flo-ethereum",
"tags": [
"ethereum",
"wallet",
"flo"
],
"category": "wallet",
"hash": "6e647729eb0f179045f764d08c44d61178bb84e36e327d026c34a701a9875132"
},
{
name: 'KYC',
description: 'An app to verify your identity',
icon: ``,
appLink: 'https://ranchimall.github.io/kyc',
moreLink: '#/dapps/kyc',
tags: ['kyc', 'identity'],
category: 'identity'
"name": "FLO Scout",
"description": "Track FLO token transactions and utilize smart contracts.",
"icon": "",
"appLink": "https://ranchimall.github.io/floscout",
"moreLink": "#/dapps/flo-scout",
"tags": [
"flo",
"scout",
"smart contracts"
],
"category": "blockchain-explorer",
"hash": "cb84c51f35d03e224b4a76d1a27dd19a75f4ac9b785e059696c16206557cfee3"
},
{
name: 'BTC Mortgage',
description: 'Borrow or Lend USD against Bitcoin',
icon: ``,
appLink: 'https://ranchimall.github.io/btcmortgage',
moreLink: '#/dapps/btc-mortgage',
tags: ['bitcoin', 'mortgage', 'lend', 'borrow'],
category: 'finance'
"name": "FLO Wallet",
"description": "A wallet for FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/flowallet",
"moreLink": "#/dapps/flo-wallet",
"tags": [
"flo",
"wallet"
],
"category": "wallet",
"hash": "a6ba8112b57a033cc0124aa3f1761e27b2066226b6604d035e8596d2c662b6b6"
},
{
name: 'FLOpay',
description: 'A rupee token payments app based on FLO',
icon: ``,
appLink: 'https://ranchimall.github.io/flopay',
moreLink: '#/dapps/flopay',
tags: ['flo', 'payments', 'rupee'],
category: 'wallet'
"name": "FLOpay",
"description": "A rupee token payments app based on FLO",
"icon": "",
"appLink": "https://ranchimall.github.io/flopay",
"moreLink": "#/dapps/flopay",
"tags": [
"flo",
"payments",
"rupee"
],
"category": "wallet",
"hash": "8cc4313d43468138f26cf13a776876fc21560714d8e5eb1217599af585105a8f"
},
{
name: 'Content Collaboration',
description: 'A writing app that allows you to collaborate with others',
icon: ``,
appLink: 'https://ranchimall.github.io/cc',
moreLink: '#/dapps/content-collaboration',
tags: ['collaboration', 'writing', 'content'],
category: 'content'
"name": "KYC",
"description": "An app to verify your identity",
"icon": "",
"appLink": "https://ranchimall.github.io/kyc",
"moreLink": "#/dapps/kyc",
"tags": [
"kyc",
"identity"
],
"category": "identity",
"hash": "247423654e501dab943296ab9a55e60bf4204164aee469f401cecf0b53290671"
},
{
name: 'RIBC',
description: 'RanchiMall Internship Blockchain Contract (RIBC) allows you hire and manage interns.',
icon: ``,
appLink: 'https://ranchimall.github.io/ribc',
moreLink: '#/dapps/ribc',
tags: ['internship', 'contract', 'ribc'],
category: 'management'
"name": "LogSheet",
"description": "Create and manage public and private log sheets",
"icon": "",
"appLink": "https://ranchimall.github.io/flologsheet",
"moreLink": "#/dapps/log-sheet",
"tags": [
"log",
"sheet",
"logsheets"
],
"category": "content",
"hash": "5c04711bbeaede85010e26d281a0a246a6f7f104e07a7bfcc5bc5208908647b6"
},
{
name: 'LogSheet',
description: 'Create and manage public and private log sheets',
icon: ``,
appLink: 'https://ranchimall.github.io/logsheet',
moreLink: '#/dapps/log-sheet',
tags: ['log', 'sheet', 'logsheets'],
category: 'content'
"name": "Messenger",
"description": "Chat with your Bitcoin, Ethereum and FLO friends or use Bitcoin and FLO multisig.",
"icon": "",
"appLink": "https://ranchimall.github.io/messenger",
"moreLink": "#/dapps/messenger",
"tags": [
"messenger",
"chat",
"bitcoin",
"ethereum",
"flo",
"multisig"
],
"category": "social",
"hash": "8713c516c826f10a5258a0962c87e3a26bd54f25d9034d7d2b7dbb7a33e4e914"
},
{
name: 'Exchange',
description: 'Trade FLO and FLO tokens with rupee tokens',
icon: ``,
appLink: 'https://ranchimall.github.io/exchangemarket',
moreLink: '#/dapps/exchange',
tags: ['exchange', 'trade', 'flo', 'rupee'],
category: 'finance'
"name": "RanchiMall Times",
"description": "A news app that showcases articles created with Content Collaboration app",
"icon": "",
"appLink": "https://ranchimall.github.io/rmtimes",
"moreLink": "#/dapps/ranchimall-times",
"tags": [
"news",
"articles",
"content"
],
"category": "content",
"hash": "840823abe525a8be560d58e45af2499de6f45eaf973ce69a500b1df31ca295be"
},
{
name: 'RanchiMall Times',
description: 'A news app that showcases articles created with Content Collaboration app',
icon: ``,
appLink: 'https://ranchimall.github.io/rmtimes',
moreLink: '#/dapps/ranchimall-times',
tags: ['news', 'articles', 'content'],
category: 'content'
"name": "RIBC",
"description": "RanchiMall Internship Blockchain Contract (RIBC) allows you hire and manage interns.",
"icon": "",
"appLink": "https://ranchimall.github.io/ribc",
"moreLink": "#/dapps/ribc",
"tags": [
"internship",
"contract",
"ribc"
],
"category": "management",
"hash": "9e0e44c5d50d7a0f28fb0f8ac4a168b5a1ec93a6e29e41503e1a6a579c567ed8"
},
{
name: 'Certify',
description: 'Create and distribute blockchain based certificates',
icon: ``,
appLink: 'https://ranchimall.github.io/certify',
moreLink: '#/dapps/certify',
tags: ['certificates', 'certify', 'certification'],
category: 'identity'
},
].sort((a, b) => a.name.localeCompare(b.name))
"name": "Taproot wallet",
"description": "A Bitcoin wallet with Taproot support.",
"icon": "",
"appLink": "https://ranchimall.github.io/taprootwallet",
"moreLink": "#/dapps/taproot-wallet",
"tags": [
"bitcoin",
"wallet",
"taproot"
],
"category": "wallet",
"hash": "592bdad38e1b45e41247f054de33b9d71c58d4178d70ca03c22f1def7c97e2c0"
}
].sort((a, b) => a.name.localeCompare(b.name));
router.addRoute('home', renderHome)
router.addRoute('', renderHome)
function renderDappCard(dapp) {
const { name, description, icon, appLink, moreLink, tags, category } = dapp;
const { name, description, icon, appLink, moreLink, tags, category, hash } = dapp;
return html`
<li class="dapp-card">
<li class="dapp-card" .dataset=${{ appLink, hash }}>
<div class="flex space-between">
<div class="dapp-card__icon">
${icon}
@ -603,8 +694,7 @@
const linkToVerify = getRef('link_verification__input').value.trim();
if (linkToVerify === '')
return notify('Please enter a link to verify', 'error', {
timeout: 5000,
pinned: false
timeout: 5000
})
const linkIsHostedCorrectly = linkToVerify.startsWith('https://ranchimall.github.io/')
const linkIsAuthorized = dappsList.some(({ appLink }) => linkToVerify.includes(appLink))
@ -744,6 +834,21 @@
);
})
})
async function getRepoHash(repoName = 'messenger') {
const response = await fetch(`https://api.github.com/repos/ranchimall/${repoName}/contents/`)
const json = await response.json()
const combinedSHA = json.reduce((acc, { sha }) => acc + sha, '')
return await calculateSHA256(new Blob([combinedSHA]))
}
async function calculateSHA256(blob) {
const buffer = await blob.arrayBuffer();
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
return hashHex;
}
</script>
</body>

View File

@ -1,20 +0,0 @@
import { Octokit, App } from "https://esm.sh/octokit";
async function some() {
const octokit = new Octokit({
auth: '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'
})
const owner = 'ranchimall';
const repo = 'messenger';
return await octokit.request('GET /repos/{owner}/{repo}', {
owner,
repo,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
}
console.log(new Octokit({
auth: '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'
}))
// console.log(await some())

View File

@ -1 +0,0 @@
import{Octokit,App}from"https://esm.sh/octokit";async function some(){const octokit=new Octokit({auth:"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"});return await octokit.request("GET /repos/{owner}/{repo}",{owner:"ranchimall",repo:"messenger",headers:{"X-GitHub-Api-Version":"2022-11-28"}})}console.log(new Octokit({auth:"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"}));