From 1ae8ad1616f4aed286f59879898bc3078564e87f Mon Sep 17 00:00:00 2001 From: programmerraja Date: Thu, 24 Oct 2024 04:57:17 +0530 Subject: [PATCH 1/5] feat(scripts): add MACI key generation script - Add generateMaciKeys.js script - Update package.json with new script command - Update .gitignore to exclude maci-keys directory --- .gitignore | 3 +++ package.json | 3 ++- scripts/generateMaciKeys.js | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 scripts/generateMaciKeys.js diff --git a/.gitignore b/.gitignore index 2c07d300e8..fdfc83f251 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,6 @@ packages/cli/contractAddresses.old.json packages/circuits/circom/test **/ts/__benchmarks__/results/** + +# MACI keys +maci-keys/ diff --git a/package.json b/package.json index fcb2b003bd..0e1b0e9329 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "test": "lerna run test --ignore maci-integrationtests --ignore maci-cli", "types": "lerna run types", "docs": "lerna run docs", - "prepare": "is-ci || husky" + "prepare": "is-ci || husky", + "generate-maci-keys": "node scripts/generateMaciKeys.js" }, "author": "PSE", "devDependencies": { diff --git a/scripts/generateMaciKeys.js b/scripts/generateMaciKeys.js new file mode 100644 index 0000000000..a18dbf9b0d --- /dev/null +++ b/scripts/generateMaciKeys.js @@ -0,0 +1,24 @@ +const { genKeypair } = require('maci-crypto'); +const fs = require('fs'); +const path = require('path'); + +function generateMaciKeys() { + const { privKey, pubKey } = genKeypair(); + + const keys = { + privateKey: privKey.toString(), + publicKey: pubKey.toString() + }; + + const outputDir = path.join(__dirname, '..', 'maci-keys'); + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, { recursive: true }); + } + + const outputFile = path.join(outputDir, 'maci-keys.json'); + fs.writeFileSync(outputFile, JSON.stringify(keys, null, 2)); + + console.log('MACI keys generated and saved to:', outputFile); +} + +generateMaciKeys(); From 9cc4a09b960c16d3aa1fb96a466b29434fe12cb8 Mon Sep 17 00:00:00 2001 From: programmerraja Date: Thu, 24 Oct 2024 05:28:17 +0530 Subject: [PATCH 2/5] Fix (prettier) run a prettier fix --- scripts/generateMaciKeys.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/generateMaciKeys.js b/scripts/generateMaciKeys.js index a18dbf9b0d..8de83bd2a8 100644 --- a/scripts/generateMaciKeys.js +++ b/scripts/generateMaciKeys.js @@ -1,24 +1,24 @@ -const { genKeypair } = require('maci-crypto'); -const fs = require('fs'); -const path = require('path'); +const { genKeypair } = require("maci-crypto"); +const fs = require("fs"); +const path = require("path"); function generateMaciKeys() { const { privKey, pubKey } = genKeypair(); const keys = { privateKey: privKey.toString(), - publicKey: pubKey.toString() + publicKey: pubKey.toString(), }; - const outputDir = path.join(__dirname, '..', 'maci-keys'); + const outputDir = path.join(__dirname, "..", "maci-keys"); if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); } - const outputFile = path.join(outputDir, 'maci-keys.json'); + const outputFile = path.join(outputDir, "maci-keys.json"); fs.writeFileSync(outputFile, JSON.stringify(keys, null, 2)); - console.log('MACI keys generated and saved to:', outputFile); + console.log("MACI keys generated and saved to:", outputFile); } generateMaciKeys(); From 4d38399575d3c7455562e2a919dd4308875b5b97 Mon Sep 17 00:00:00 2001 From: programmerraja Date: Sat, 26 Oct 2024 09:14:01 +0530 Subject: [PATCH 3/5] Feat (script) converted the scrpit to ts --- scripts/generateMaciKeys.js | 24 ------------------------ scripts/generateMaciKeys.ts | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 scripts/generateMaciKeys.js create mode 100644 scripts/generateMaciKeys.ts diff --git a/scripts/generateMaciKeys.js b/scripts/generateMaciKeys.js deleted file mode 100644 index 8de83bd2a8..0000000000 --- a/scripts/generateMaciKeys.js +++ /dev/null @@ -1,24 +0,0 @@ -const { genKeypair } = require("maci-crypto"); -const fs = require("fs"); -const path = require("path"); - -function generateMaciKeys() { - const { privKey, pubKey } = genKeypair(); - - const keys = { - privateKey: privKey.toString(), - publicKey: pubKey.toString(), - }; - - const outputDir = path.join(__dirname, "..", "maci-keys"); - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); - } - - const outputFile = path.join(outputDir, "maci-keys.json"); - fs.writeFileSync(outputFile, JSON.stringify(keys, null, 2)); - - console.log("MACI keys generated and saved to:", outputFile); -} - -generateMaciKeys(); diff --git a/scripts/generateMaciKeys.ts b/scripts/generateMaciKeys.ts new file mode 100644 index 0000000000..32b4403bb7 --- /dev/null +++ b/scripts/generateMaciKeys.ts @@ -0,0 +1,25 @@ +import { genKeypair } from "maci-crypto"; + +import { promises as fs } from "fs"; +import * as path from "path"; + +async function generateMaciKeys(): Promise { + const { privKey, pubKey } = genKeypair(); + + const keys = { + privateKey: privKey.toString(), + publicKey: pubKey.toString(), + }; + + const outputDir = path.resolve(__dirname, "..", "maci-keys"); + try { + await fs.access(outputDir); + } catch (error) { + await fs.mkdir(outputDir, { recursive: true }); + } + + const outputFile = path.resolve(outputDir, "maci-keys.json"); + await fs.writeFile(outputFile, JSON.stringify(keys, null, 2)); +} + +generateMaciKeys(); From 176b57586d7db66bbe506df0df225cfbb3e68a9b Mon Sep 17 00:00:00 2001 From: programmerraja Date: Mon, 28 Oct 2024 20:29:47 +0530 Subject: [PATCH 4/5] Fix (maci) changed fs import way --- scripts/generateMaciKeys.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/generateMaciKeys.ts b/scripts/generateMaciKeys.ts index 32b4403bb7..2c13f959d5 100644 --- a/scripts/generateMaciKeys.ts +++ b/scripts/generateMaciKeys.ts @@ -1,7 +1,7 @@ import { genKeypair } from "maci-crypto"; -import { promises as fs } from "fs"; -import * as path from "path"; +import fs from "fs"; +import path from "path"; async function generateMaciKeys(): Promise { const { privKey, pubKey } = genKeypair(); @@ -13,13 +13,13 @@ async function generateMaciKeys(): Promise { const outputDir = path.resolve(__dirname, "..", "maci-keys"); try { - await fs.access(outputDir); + await fs.promises.access(outputDir); } catch (error) { - await fs.mkdir(outputDir, { recursive: true }); + await fs.promises.mkdir(outputDir, { recursive: true }); } const outputFile = path.resolve(outputDir, "maci-keys.json"); - await fs.writeFile(outputFile, JSON.stringify(keys, null, 2)); + await fs.promises.writeFile(outputFile, JSON.stringify(keys, null, 2)); } generateMaciKeys(); From e5995a25a7c0b64aad5629c49abfdd4bb0304dc0 Mon Sep 17 00:00:00 2001 From: programmerraja Date: Mon, 28 Oct 2024 20:32:18 +0530 Subject: [PATCH 5/5] Fix (pkg) updated pkg json for maci script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e1b0e9329..1b75ce2dc9 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "types": "lerna run types", "docs": "lerna run docs", "prepare": "is-ci || husky", - "generate-maci-keys": "node scripts/generateMaciKeys.js" + "generate-maci-keys": "ts-node scripts/generateMaciKeys.ts" }, "author": "PSE", "devDependencies": {