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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
25 changes: 25 additions & 0 deletions scripts/generateMaciKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { genKeypair } from "maci-crypto";

import { promises as fs } from "fs";
import * as path from "path";
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
import { promises as fs } from "fs";
import * as path from "path";
import fs from "fs";
import path from "path";


async function generateMaciKeys(): Promise<void> {
const { privKey, pubKey } = genKeypair();

const keys = {
privateKey: privKey.toString(),
publicKey: pubKey.toString(),
};

const outputDir = path.resolve(__dirname, "..", "maci-keys");
try {
await fs.access(outputDir);
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
await fs.access(outputDir);
await fs.promises.access(outputDir);

Copy link
Collaborator

Choose a reason for hiding this comment

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

And the same change for other fs calls

Copy link
Author

Choose a reason for hiding this comment

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

@0xmad done can you check

} 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();
Loading