diff --git a/.eslintrc.js b/.eslintrc.js index a13a8dc2..afac71f6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,36 +6,53 @@ const OFF = 0; * @type {import("eslint").Linter.Config} */ module.exports = { + // Define the environment env: { browser: false, es2021: true, mocha: true, node: true, }, + // Use recommended Prettier configuration extends: ["plugin:prettier/recommended"], + // Use TypeScript parser parser: "@typescript-eslint/parser", parserOptions: { ecmaVersion: 12, }, + // Define ESLint plugins. plugins: ["@typescript-eslint", "prettier", "simple-import-sort", "sort-keys-fix", "typescript-sort-keys"], + // Define ESLint rules rules: { + // Enable sorting of type union/intersection members "@typescript-eslint/sort-type-union-intersection-members": "error", + // Disable camelcase rule camelcase: "off", + // Disable no-console rule "no-console": OFF, + // Enable sorting of exports "simple-import-sort/exports": "error", + // Enable sorting of imports "simple-import-sort/imports": "error", + // Enable sorting of object keys "sort-keys-fix/sort-keys-fix": "error", + // Enable sorting of interface keys "typescript-sort-keys/interface": "error", + // Enable sorting of string enum keys "typescript-sort-keys/string-enum": "error", }, + // Define ESLint settings settings: { + // Configure import parser for TypeScript "import/parsers": { "@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx", ".d.ts"], }, + // Configure import resolver for TypeScript "import/resolver": { node: { extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], }, + // Specify the TypeScript project path typescript: { project: path.join(__dirname, "tsconfig.json"), }, diff --git a/scripts/setup-tutorial.ts b/scripts/setup-tutorial.ts index 5e56cdde..0118d634 100644 --- a/scripts/setup-tutorial.ts +++ b/scripts/setup-tutorial.ts @@ -2,13 +2,15 @@ import { Wallet } from "ethers"; import * as fs from "fs"; import * as https from "https"; +// Path to the JSON file storing wallet information const jsonPath = "scripts/.wallet.json"; +// Interface defining the structure of the wallet configuration interface WalletConfig { address: string; privateKey: string; } - +// Function to save environment files with wallet information function saveEnvFiles(address: string, privateKey: string): void { const value: string = ` PRIVATE_KEY=${privateKey} @@ -16,6 +18,7 @@ ZETA_NETWORK=athens EXECUTE_PROGRAMMATICALLY=true`; const filePaths: string[] = ["packages/example-contracts/.env", "packages/zevm-example-contracts/.env"]; + // Write wallet information to each environment file filePaths.forEach((filePath: string) => { fs.writeFile(filePath, value, (err: NodeJS.ErrnoException | null) => { if (err) { @@ -26,6 +29,8 @@ EXECUTE_PROGRAMMATICALLY=true`; }); }); } + +// Function to save wallet information to a JSON file function saveWalletFile(address: string, privateKey: string, jsonPath: string): void { const data = `{"address": "${address}", "privateKey": "${privateKey}"}`; @@ -42,6 +47,8 @@ function saveWalletFile(address: string, privateKey: string, jsonPath: string): } }); } + +// Function to call the faucet and request testnet assets function callFaucet(address: string): void { // Hit Faucet to get some testnet Zeta console.log("Requesting testnet assets from the faucet..."); @@ -67,6 +74,7 @@ function callFaucet(address: string): void { req.end(); } +// Function to check if the wallet file exists, and execute a callback if it does function createWallet(filePath: string, callback: () => void): void { fs.access(filePath, (err) => { if (!err) { @@ -75,6 +83,7 @@ function createWallet(filePath: string, callback: () => void): void { }); } +// Function to get or create a wallet based on the wallet file async function getOrCreateWallet(filePath: string): Promise { let wallet: Wallet; @@ -96,6 +105,7 @@ async function getOrCreateWallet(filePath: string): Promise { return wallet; } +// Main function to get or create a wallet, and perform necessary actions const wallet = getOrCreateWallet(jsonPath).then(async (wallet) => { console.log(`Your Wallet Address: ${wallet.address}`); console.log(`Your Private Key: ${wallet.privateKey.substring(2)}`); diff --git a/scripts/slither.ts b/scripts/slither.ts index 92c0c7a2..9ac3e0f6 100644 --- a/scripts/slither.ts +++ b/scripts/slither.ts @@ -2,11 +2,18 @@ import inquirer from "inquirer"; import { execSync } from "node:child_process"; import path from "node:path"; +// Root directory of the project const projectRoot = path.join(__dirname, "../"); + +// Solidity compiler version const solcVersion = "0.8.7"; +// Timestamp for unique file naming const timestamp = Date.now(); + +// List of package names to choose from const packageNames = ["protocol-contracts", "example-contracts"]; +// Function to get the package name based on user input async function getPackageName() { let packageName; @@ -21,7 +28,7 @@ async function getPackageName() { return packageName; } else { - packageName = await inquirer.prompt([ + const { contracts } = await inquirer.prompt([ { choices: packageNames, message: "Which set of contracts would you like to test?", @@ -30,17 +37,18 @@ async function getPackageName() { }, ]); - return packageName.contracts; + return contracts; } } +// Function to get the filter paths based on user input async function getFilterPaths() { if (process.env.CI) return ""; - const { confirm: includeLibraries } = await inquirer.prompt([ + const { includeLibraries } = await inquirer.prompt([ { message: "Do you want to include OpenZeppelin & Uniswap libraries in this scan?", - name: "confirm", + name: "includeLibraries", type: "confirm", }, ]); @@ -48,7 +56,8 @@ async function getFilterPaths() { return includeLibraries ? "" : `--filter-paths "node_modules/@openzeppelin/","node_modules/@uniswap/"`; } -const run = async (command: string) => { +// Function to execute a shell command +const run = async (command) => { try { console.log("Starting -- This may take a few minutes..."); @@ -63,19 +72,24 @@ const run = async (command: string) => { console.error(`${error}`); } }; -function runSlither(packageName: string, filterPaths: string) { + +// Function to run Slither analysis +function runSlither(packageName, filterPaths) { const dockerCommand = `cd /home/trufflecon/packages/${packageName} && \ solc-select use ${solcVersion} && \ slither --json ../../scripts/slither-results/${packageName}-${timestamp}.json \ --sarif ../../scripts/slither-results/${packageName}-${timestamp}.sarif \ --checklist ./ ${filterPaths} | tee ../../scripts/slither-results/${packageName}-${timestamp}.md`; + run(`docker run -v "${projectRoot}":/home/trufflecon trailofbits/eth-security-toolbox -c "${dockerCommand}"`); } +// Main function to orchestrate Slither analysis async function main() { runSlither(await getPackageName(), await getFilterPaths()); } +// Execute the main function and handle errors main() .then(() => process.exit(0)) .catch((error) => {