refactor: remove namespace imports (#969)

* refactor: remove namespace imports

* refactor: use named fs imports

* refactor(app): replace path and fs namespace imports

* format

* format
This commit is contained in:
Justin Hernandez
2025-08-27 20:59:26 -07:00
committed by GitHub
parent dba8ee1951
commit fc472915e6
37 changed files with 385 additions and 378 deletions

View File

@@ -1,7 +1,6 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { artifacts, ethers } from "hardhat";
import hre from "hardhat";
import fs from "fs";
import path from "path";
function getHubInitializeData() {

View File

@@ -1,6 +1,6 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
import { ethers } from "ethers";
@@ -9,8 +9,7 @@ export default buildModule("UpdatePCR0", (m) => {
const journalPath = path.join(__dirname, "../../deployments", `chain-${networkName}`, "journal.jsonl");
// Read and parse the journal file
const journal = fs
.readFileSync(journalPath, "utf8")
const journal = readFileSync(journalPath, "utf8")
.split("\n")
.filter(Boolean)
.map((line) => JSON.parse(line));

View File

@@ -1,6 +1,6 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
import { getCscaTreeRoot } from "@selfxyz/common/utils/trees";
import serialized_csca_tree from "../../../../common/pubkeys/serialized_csca_tree.json";
@@ -9,7 +9,7 @@ module.exports = buildModule("UpdateRegistryCscaRoot", (m) => {
const networkName = hre.network.config.chainId;
const deployedAddressesPath = path.join(__dirname, `../../deployments/chain-${networkName}/deployed_addresses.json`);
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];

View File

@@ -1,13 +1,13 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
module.exports = buildModule("UpdateRegistryHub", (m) => {
const networkName = hre.network.config.chainId;
const deployedAddressesPath = path.join(__dirname, `../../deployments/chain-${networkName}/deployed_addresses.json`);
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
const hubAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];

View File

@@ -1,6 +1,5 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
import fs from "fs";
import path from "path";
module.exports = buildModule("UpdateVerifyAllAddresses", (m) => {

View File

@@ -1,7 +1,7 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { artifacts, ethers } from "hardhat";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
function getTestHubInitializeData() {
@@ -13,7 +13,7 @@ export default buildModule("DeployNewHubAndUpgrade", (m) => {
const networkName = hre.network.config.chainId;
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
const hubProxyAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];
if (!hubProxyAddress) {

View File

@@ -1,7 +1,7 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { artifacts, ethers } from "hardhat";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
function getTestRegistryInitializeData() {
@@ -13,7 +13,7 @@ export default buildModule("DeployNewHubAndUpgrade", (m) => {
const networkName = hre.network.config.chainId;
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
const registryProxyAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
if (!registryProxyAddress) {

View File

@@ -1,13 +1,13 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
export default buildModule("DeployVerifyAll", (m) => {
const networkName = hre.network.config.chainId;
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
const hubAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];

View File

@@ -1,4 +1,4 @@
import fs from "fs";
import { readdirSync, statSync, readFileSync, writeFileSync } from "fs";
import path from "path";
import { keccak256 } from "ethers";
@@ -17,11 +17,11 @@ function findSolidityFiles(dir: string): string[] {
const files: string[] = [];
function traverse(currentDir: string) {
const items = fs.readdirSync(currentDir);
const items = readdirSync(currentDir);
for (const item of items) {
const fullPath = path.join(currentDir, item);
const stat = fs.statSync(fullPath);
const stat = statSync(fullPath);
if (stat.isDirectory()) {
// Skip node_modules, .git, and other common directories
@@ -42,7 +42,7 @@ function findSolidityFiles(dir: string): string[] {
* Extract custom errors from Solidity file content
*/
function extractCustomErrors(filePath: string): CustomError[] {
const content = fs.readFileSync(filePath, "utf8");
const content = readFileSync(filePath, "utf8");
const lines = content.split("\n");
const errors: CustomError[] = [];
@@ -162,7 +162,7 @@ async function findAllErrorSelectors(targetSelector?: string) {
// Save results to JSON file for future reference
const outputFile = "error-selectors.json";
fs.writeFileSync(outputFile, JSON.stringify(allErrors, null, 2));
writeFileSync(outputFile, JSON.stringify(allErrors, null, 2));
console.log(`\n💾 Results saved to ${outputFile}`);
return allErrors;

View File

@@ -13,7 +13,6 @@ import { Formatter, CircuitAttributeHandler } from "../utils/formatter";
import { formatCountriesList, reverseBytes, reverseCountryBytes } from "@selfxyz/common/utils/circuits/formatInputs";
import { getPackedForbiddenCountries } from "@selfxyz/common/utils/sanctions";
import { countries, Country3LetterCode } from "@selfxyz/common/constants/countries";
import fs from "fs";
import path from "path";
describe("VC and Disclose", () => {

View File

@@ -1,6 +1,6 @@
import { LeanIMT } from "@openpassport/zk-kit-lean-imt";
import { ChildNodes, SMT } from "@openpassport/zk-kit-smt";
import fs from "fs";
import { readFileSync } from "fs";
import path from "path";
import { poseidon2, poseidon3 } from "poseidon-lite";
import type { CircuitSignals, Groth16Proof, PublicSignals } from "snarkjs";
@@ -73,9 +73,7 @@ export async function generateRegisterProof(secret: string, passportData: Passpo
);
// Verify the proof
const vKey = JSON.parse(
fs.readFileSync(registerCircuits["register_sha256_sha256_sha256_rsa_65537_4096"].vkey, "utf8"),
);
const vKey = JSON.parse(readFileSync(registerCircuits["register_sha256_sha256_sha256_rsa_65537_4096"].vkey, "utf8"));
const isValid = await groth16.verify(vKey, registerProof.publicSignals, registerProof.proof);
if (!isValid) {
throw new Error("Generated register proof verification failed");
@@ -126,7 +124,7 @@ export async function generateRegisterIdProof(
);
// Verify the proof
const vKey = JSON.parse(fs.readFileSync(circuitArtifacts[artifactKey].vkey, "utf8"));
const vKey = JSON.parse(readFileSync(circuitArtifacts[artifactKey].vkey, "utf8"));
const isValid = await groth16.verify(vKey, registerProof.publicSignals, registerProof.proof);
if (!isValid) {
throw new Error("Generated register ID proof verification failed");
@@ -148,7 +146,7 @@ export async function generateDscProof(passportData: PassportData): Promise<DscC
);
// Verify the proof
const vKey = JSON.parse(fs.readFileSync(dscCircuits["dsc_sha256_rsa_65537_4096"].vkey, "utf8"));
const vKey = JSON.parse(readFileSync(dscCircuits["dsc_sha256_rsa_65537_4096"].vkey, "utf8"));
const isValid = await groth16.verify(vKey, dscProof.publicSignals, dscProof.proof);
if (!isValid) {
throw new Error("Generated DSC proof verification failed");
@@ -211,7 +209,7 @@ export async function generateVcAndDiscloseRawProof(
);
// Verify the proof
const vKey = JSON.parse(fs.readFileSync(vcAndDiscloseCircuits["vc_and_disclose"].vkey, "utf8"));
const vKey = JSON.parse(readFileSync(vcAndDiscloseCircuits["vc_and_disclose"].vkey, "utf8"));
const isValid = await groth16.verify(vKey, vcAndDiscloseProof.publicSignals, vcAndDiscloseProof.proof);
if (!isValid) {
throw new Error("Generated VC and Disclose proof verification failed");
@@ -395,7 +393,7 @@ export async function generateVcAndDiscloseIdProof(
);
// Verify the proof
const vKey = JSON.parse(fs.readFileSync(vcAndDiscloseIdCircuits["vc_and_disclose_id"].vkey, "utf8"));
const vKey = JSON.parse(readFileSync(vcAndDiscloseIdCircuits["vc_and_disclose_id"].vkey, "utf8"));
const isValid = await groth16.verify(vKey, vcAndDiscloseProof.publicSignals, vcAndDiscloseProof.proof);
if (!isValid) {
throw new Error("Generated VC and Disclose ID proof verification failed");
@@ -446,7 +444,7 @@ export function getSMTs() {
function importSMTFromJsonFile(filePath?: string): SMT | null {
try {
const jsonString = fs.readFileSync(path.resolve(process.cwd(), filePath as string), "utf8");
const jsonString = readFileSync(path.resolve(process.cwd(), filePath as string), "utf8");
const data = JSON.parse(jsonString);