From b3de092808d633b32f65faa144467400cf301423 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Wed, 24 Jan 2024 02:52:16 +0530 Subject: [PATCH] Creating script to update hashes list --- .gitignore | 3 + index.html | 323 +----------------------------- index.min.html | 253 ----------------------- scripts/dappList.js | 311 ++++++++++++++++++++++++++++ scripts/updateAuthorizedHashes.js | 87 ++++++++ 5 files changed, 409 insertions(+), 568 deletions(-) create mode 100644 .gitignore delete mode 100644 index.min.html create mode 100644 scripts/dappList.js create mode 100644 scripts/updateAuthorizedHashes.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..83de7d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +scripts/dappList.min.js +scripts/updateAuthorizedHashes.min.js diff --git a/index.html b/index.html index 1dd2715..3204fc7 100644 --- a/index.html +++ b/index.html @@ -81,6 +81,7 @@ + \ No newline at end of file diff --git a/scripts/dappList.js b/scripts/dappList.js new file mode 100644 index 0000000..ecee144 --- /dev/null +++ b/scripts/dappList.js @@ -0,0 +1,311 @@ +dappsList = [ + { + "name": "Blockbook", + "description": "A blockchain explorer for FLO", + "icon": "", + "appLink": "https://blockbook.ranchimall.net/", + "moreLink": "#/dapps/blockbook", + "tags": [ + "blockbook", + "flo", + "blockchain" + ], + "category": "blockchain-explorer", + "allowDownload": false, + "repoHash": "1d5cc442744f429fba5ad97ada001bfed2556d0ec7e1443b4ededb65f6ba5c61", + "repoLink": "https://github.com/ranchimall/blockbook", + "appHash": "f4db3585488e27e1c0fafdffc2935d61aa66be3bfc468280de3c08ef27341d12" + }, + { + "name": "Blockchain Bonds", + "description": "Monitor Bitcoin bonds performance", + "icon": " ", + "appLink": "https://ranchimall.github.io/blockchainbonds", + "moreLink": "#/dapps/blockchain-bonds", + "tags": [ + "bitcoin", + "bonds", + "blockchain" + ], + "category": "finance", + "repoHash": "7250f70ac910600ab2b1c77cc13e829aac22c032f0da1f1686e680f48f85fb0a", + "appHash": "929dcd994982bee55bcdd5c6f77f73acfa63d6889253e261f4d1985626ca7e45" + }, + { + "name": "Bob's Fund", + "description": "A 20 year Bitcoin fund with 100% profit sharing", + "icon": "", + "appLink": "https://ranchimall.github.io/bobsfund", + "moreLink": "#/dapps/bobs-fund", + "tags": [ + "fund", + "bobs", + "bitcoin" + ], + "category": "finance", + "repoHash": "232846d9000726c0ff00ee66f453e44c4a246c2e532f16194c69267aa4a5e3ec", + "appHash": "b28325b8c26814c21bf93aeca1c1eaa02cbfd27c603a738e1af2c14c89266b27" + }, + { + "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", + "repoHash": "c606e37d2ab869d3c15f6b44711c07cefffa965692c91309652872812164fc85", + "appHash": "c9bc50e7f10757303a9ea0c77bccf8ef1e8fd1d0af7611dbc630c577b93e6d19" + }, + { + "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", + "repoHash": null, + "appHash": "d31dd62e942354a0cd781def19d80c5268958b20a7e29335c7337cdc32cc315e" + }, + { + "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", + "repoHash": null, + "appHash": "563a97cc5be968d5ffc1511925766bc624df5ae3f71dca5ef48a5030ebe3b5ba" + }, + { + "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", + "repoHash": null, + "appHash": "f91a7cfd7aeba549efe6f8e2fb095007f28fe6c07ca572974bdbc9a7c42afd80" + }, + { + "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", + "repoHash": null, + "appHash": "64aa230e742d106e0daa007924e27669abe809278ce8109f357dbe35e5402f7b" + }, + { + "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", + "repoHash": "252e0ecb55cee82826d9efb188e503d762606251800cf000e10d59af5c2d9698", + "appHash": "a114bbb742a2b26694d2417ab893c3539462804580f3bc77170a5a66547f86ce" + }, + { + "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", + "repoHash": "4aac65c3e9718523e231af0b4b603dd2b70f0b56dbcca46d836e354cdeb96c78", + "appHash": "0d81003141a2b586bd2272a64341e118b70746da35ef7d66662c282173c1752e" + }, + { + "name": "FLO Wallet", + "description": "A wallet for FLO", + "icon": " ", + "appLink": "https://ranchimall.github.io/flowallet", + "moreLink": "#/dapps/flo-wallet", + "tags": [ + "flo", + "wallet" + ], + "category": "wallet", + "repoHash": null, + "appHash": "8bb27f947a357a901961df1d948c23d107d8340960604502f8bf57eb3a49b00c" + }, + { + "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", + "repoHash": "c8cfe34221bc04ebd26d9c5480a229e7d168dfe398fb4dcf9f61ffbb77b413f8", + "appHash": "bff105c11ecc096adefcb94e67487708499de72ebcb9423693a57f986a4d8c87" + }, + { + "name": "ICO Exchange", + "description": "An exchange for ICO token trading", + "icon": "", + "appLink": "https://ranchimall.net/exchange", + "moreLink": "#/dapps/ico-exchange", + "tags": [ + "exchange", + "ICO", + "RMT", + "RanchiMall", + "tokens" + ], + "category": "finance", + "allowDownload": false, + "repoHash": "bcd943193b9a76991e8d1ebd4bd88a30ece97f69efe80c37f3c5a733c76a2b6b", + "repoLink": "https://github.com/ranchimall/flo-exchange", + "appHash": "435e7c9a7624f252c1c5f8b77fe1fd7a786577c48fbea93b33f8c13758b0b17b" + }, + { + "name": "Intern payments", + "description": "An app to view payments made to interns", + "icon": "", + "appLink": "https://ranchimall.github.io/ribcpayments", + "moreLink": "#/dapps/intern-payments", + "tags": [ + "payments", + "intern", + "ribc" + ], + "category": "finance", + "repoHash": "e9041db6c77162570690c64bf0ebebe1872dccbf9f53e3ce4fb7f5c4552c2815", + "appHash": "69038e99dbfa11787ec13b4747cae6ddd02a99f7210a3859f53080b7b25e06a3" + }, + { + "name": "KYC", + "description": "An app to verify your identity", + "icon": "", + "appLink": "https://ranchimall.github.io/kyc", + "moreLink": "#/dapps/kyc", + "tags": [ + "kyc", + "identity" + ], + "category": "identity", + "repoHash": "1f7b34d905149195534f84f017e67375842197d247ba93267243b47502c04ccc", + "appHash": "a818c088017066f70d9545e1ec2e030c64beb4dd5f9aa66f281fd4759a5d438b" + }, + { + "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", + "repoHash": null, + "appHash": "1650c9888e9b418507d41af3ba76ee14753cfa0faa4f9753dff46fcd2a44047d" + }, + { + "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", + "repoHash": null, + "appHash": "cbcfca5dee607f5450a19c7e77ef83115ee17ea3ade89c3d8ec2681a6996ac96" + }, + { + "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", + "repoHash": "ebb8ed672eb4081c83e37000ca51c3b9e92701a51495c59ce1893568fbc7513b", + "appHash": "4a7cc4207c1f57f89875fbdb44a03b2eb674328d297a7b82ed8735386d821742" + }, + { + "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", + "repoHash": "a54626ac0746dd08e913287ee76351aae5e6c14735d42b0cd877f69ba259868e", + "appHash": "cd582bcee4043de02d97383ee9f0cb8f39710a8743bc752dbf2e9e738e70ac02" + }, + { + "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", + "repoHash": "2c8c1a065fcba4f9352317e6718d6364f354ed96eb77af9d4c092a6e523060e6", + "appHash": "ffe0a9c8a09b5b1499d6827ef74074026655f0679c497d015118a0d98c2b78fe", + "automatedChecking": true + } +] \ No newline at end of file diff --git a/scripts/updateAuthorizedHashes.js b/scripts/updateAuthorizedHashes.js new file mode 100644 index 0000000..2e034ee --- /dev/null +++ b/scripts/updateAuthorizedHashes.js @@ -0,0 +1,87 @@ +const fs = require('fs'); +const path = require('path'); + +// Step 1: Read the dappList.js file +const dappListPath = path.join(__dirname, 'dappList.js'); +let dappListContent = fs.readFileSync(dappListPath, 'utf-8'); + +// Step 2: Parse the dappList.js file +const dappList = dappListContent.replace('dappsList =', ''); +const dappListJSON = eval(dappList); + +// Step 3: Loop through the dappList.js file +Promise.all(dappListJSON.map(async (dapp) => { + const { repoLink, appLink } = dapp + const promises = [getRepoHash((repoLink || appLink).split('/').pop())] + if (appLink) { + promises.push(getLinkContentHash(appLink)); + } + const [repoHash, appHash = null] = await Promise.all(promises) + const update = { repoHash } + if (appHash) { + update.appHash = appHash[0].hash + } + return { + ...dapp, + ...update + } +})).then(dappListWithHashes => { + // Step 5: Write the string to the dappList.js file + const dappListWithHashesString = `dappsList = ${JSON.stringify(dappListWithHashes, null, 2)}` + fs.writeFileSync(dappListPath, dappListWithHashesString, 'utf-8') + console.log('Updated dappList.js') +}).catch(e => { + console.error(e) +}) + + +async function getRepoHash(repoName) { + if (!repoName) return null; + try { + const response = await fetch(`https://api.github.com/repos/ranchimall/${repoName}/contents/`) + if (!response.ok) { + if (response.status === 403) { + console.log('Github API rate limit exceeded. Try again after some time.') + } else { + console.log(`Error fetching repo contents for ${repoName}. Status: ${response.status}`) + } + return null + }; + const json = await response.json() + const combinedSHA = json.reduce((acc, { sha }) => acc + sha, '') + return await calculateSHA256(new Blob([combinedSHA])) + } catch (e) { + console.error(e) + return null + } +} + +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; +} + +/** + * @param { string | []} a single link or array of links + */ +async function getLinkContentHash(link) { + try { + if (!link) return null + if (!Array.isArray(link)) + link = [link] + const data = JSON.stringify({ urls: link }) + return await (await fetch('https://utility-api.ranchimall.net/hash', { + headers: { + "Content-Type": "application/json", + }, + method: "POST", + body: data + })).json() + } catch (e) { + console.error(e) + return null + } +} \ No newline at end of file