Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): add MACI key generation script #1869

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ packages/cli/contractAddresses.old.json
packages/circuits/circom/test

**/ts/__benchmarks__/results/**

# MACI keys
maci-keys/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 24 additions & 0 deletions scripts/generateMaciKeys.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use typescript

Original file line number Diff line number Diff line change
@@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const outputDir = path.join(__dirname, "..", "maci-keys");
const outputDir = path.resolve(__dirname, "..", "maci-keys");

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use async version here


const outputFile = path.join(outputDir, "maci-keys.json");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const outputFile = path.join(outputDir, "maci-keys.json");
const outputFile = path.resolve(outputDir, "maci-keys.json");

fs.writeFileSync(outputFile, JSON.stringify(keys, null, 2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same with async


console.log("MACI keys generated and saved to:", outputFile);
}

generateMaciKeys();
Loading