@semaphore-protocol/cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ethereum Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ <p align="center">
2
+ <h1 align="center">
3
+ Semaphore CLI
4
+ </h1>
5
+ <p align="center">A command line tool to set up a Semaphore project.</p>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://github.com/semaphore-protocol">
10
+ <img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
11
+ </a>
12
+ <a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
13
+ <img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@semaphore-protocol/cli">
16
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/cli?style=flat-square" />
17
+ </a>
18
+ <a href="https://npmjs.org/package/@semaphore-protocol/cli">
19
+ <img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/cli.svg?style=flat-square" />
20
+ </a>
21
+ <a href="https://eslint.org/">
22
+ <img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
23
+ </a>
24
+ <a href="https://prettier.io/">
25
+ <img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier" />
26
+ </a>
27
+ </p>
28
+
29
+ <div align="center">
30
+ <h4>
31
+ <a href="https://github.com/semaphore-protocol/semaphore/blob/main/CONTRIBUTING.md">
32
+ 👥 Contributing
33
+ </a>
34
+ <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
35
+ <a href="https://github.com/semaphore-protocol/semaphore/blob/main/CODE_OF_CONDUCT.md">
36
+ 🤝 Code of conduct
37
+ </a>
38
+ <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
39
+ <a href="https://github.com/semaphore-protocol/semaphore/contribute">
40
+ 🔎 Issues
41
+ </a>
42
+ <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
43
+ <a href="https://discord.gg/6mSdGHnstH">
44
+ 🗣️ Chat &amp; Support
45
+ </a>
46
+ </h4>
47
+ </div>
48
+
49
+ | ... |
50
+ | --- |
51
+
52
+ ## 🛠 Install
53
+
54
+ ### npm or yarn
55
+
56
+ Install the `@semaphore-protocol/cli` package with npm:
57
+
58
+ ```bash
59
+ npm i @semaphore-protocol/cli
60
+ ```
61
+
62
+ or yarn:
63
+
64
+ ```bash
65
+ yarn add @semaphore-protocol/cli
66
+ ```
67
+
68
+ ## 📜 Usage
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @module @semaphore-protocol/cli
5
+ * @version 0.0.1
6
+ * @file A command line tool to set up a Semaphore project and query groups.
7
+ * @copyright Ethereum Foundation 2022
8
+ * @license MIT
9
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli}
10
+ */
11
+
12
+ import { Subgraph } from '@semaphore-protocol/subgraph';
13
+ import chalk from 'chalk';
14
+ import { program } from 'commander';
15
+ import figlet from 'figlet';
16
+ import { readFileSync } from 'fs';
17
+ import ora from 'ora';
18
+ import { dirname } from 'path';
19
+ import { fileURLToPath } from 'url';
20
+
21
+ /* eslint-disable no-console */
22
+ const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`;
23
+ const { version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"));
24
+ program
25
+ .name("semaphore")
26
+ .description("A command line tool to set up a Semaphore project and query groups.")
27
+ .version(version, "-v, --version", "Show Semaphore CLI version.")
28
+ .addHelpText("before", `${figlet.textSync("Semaphore CLI")}\n`)
29
+ .helpOption(undefined, "Display this help.")
30
+ .addHelpCommand("help [command]", "Display help for a specific command.");
31
+ program
32
+ .command("get-group")
33
+ .description("Get group data from a supported network.")
34
+ .argument("<group-id>", "Identifier of the group.")
35
+ .option("-n, --network <network-name>", "Supported Ethereum network.", "goerli")
36
+ .option("--members", "Show group members.")
37
+ .option("--signals", "Show group signals.")
38
+ .usage("<group-id> [options]")
39
+ .action(async (groupId, { network, members, signals }) => {
40
+ const subgraph = new Subgraph(network);
41
+ const spinner = ora({
42
+ text: `Fetching group ${groupId}`,
43
+ spinner: "boxBounce"
44
+ }).start();
45
+ const group = await subgraph.getGroup(groupId, { members, verifiedProofs: signals });
46
+ let content = `\n ${chalk.bold("Id")}: ${group.id}\n`;
47
+ content += ` ${chalk.bold("Admin")}: ${group.admin}\n`;
48
+ content += ` ${chalk.bold("Merkle tree")}:\n`;
49
+ content += ` Root: ${group.merkleTree.root}\n`;
50
+ content += ` Depth: ${group.merkleTree.depth}\n`;
51
+ content += ` Zero value: ${group.merkleTree.zeroValue}\n`;
52
+ content += ` Number of leaves: ${group.merkleTree.numberOfLeaves}`;
53
+ if (members) {
54
+ content += `\n\n ${chalk.bold("Members")}: \n${group.members
55
+ .map((member, i) => ` [${i}] ${member}`)
56
+ .join("\n")}`;
57
+ }
58
+ if (signals) {
59
+ content += `\n\n ${chalk.bold("Signals")}: \n${group.verifiedProofs
60
+ .map(({ signal }, i) => ` [${i}] ${signal}`)
61
+ .join("\n")}`;
62
+ }
63
+ spinner.stop();
64
+ console.log(`${content}\n`);
65
+ });
66
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@semaphore-protocol/cli",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "A command line tool to set up a Semaphore project and query groups.",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "semaphore": "dist/index.js"
9
+ },
10
+ "types": "dist/types/index.d.ts",
11
+ "files": [
12
+ "dist/",
13
+ "src/",
14
+ "LICENSE",
15
+ "README.md"
16
+ ],
17
+ "repository": "https://github.com/semaphore-protocol/semaphore",
18
+ "homepage": "https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli",
19
+ "bugs": {
20
+ "url": "https://github.com/semaphore-protocol/semaphore.git/issues"
21
+ },
22
+ "engines": {
23
+ "node": ">=14.16"
24
+ },
25
+ "scripts": {
26
+ "start": "ts-node --esm src/index.ts",
27
+ "build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
28
+ "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
29
+ "prepublishOnly": "yarn build"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "devDependencies": {
35
+ "@types/figlet": "^1.5.5",
36
+ "rollup-plugin-cleanup": "^3.2.1",
37
+ "rollup-plugin-typescript2": "^0.31.2",
38
+ "ts-node": "^10.9.1",
39
+ "typedoc": "^0.22.11"
40
+ },
41
+ "dependencies": {
42
+ "@semaphore-protocol/subgraph": "2.6.1",
43
+ "chalk": "^5.1.2",
44
+ "commander": "^9.4.1",
45
+ "figlet": "^1.5.2",
46
+ "ora": "^6.1.2"
47
+ }
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ /* eslint-disable no-console */
2
+ import { Subgraph } from "@semaphore-protocol/subgraph"
3
+ import chalk from "chalk"
4
+ import { program } from "commander"
5
+ import figlet from "figlet"
6
+ import { readFileSync } from "fs"
7
+ import ora from "ora"
8
+ import { dirname } from "path"
9
+ import { fileURLToPath } from "url"
10
+
11
+ const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
12
+ const { version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"))
13
+
14
+ program
15
+ .name("semaphore")
16
+ .description("A command line tool to set up a Semaphore project and query groups.")
17
+ .version(version, "-v, --version", "Show Semaphore CLI version.")
18
+ .addHelpText("before", `${figlet.textSync("Semaphore CLI")}\n`)
19
+ .helpOption(undefined, "Display this help.")
20
+ .addHelpCommand("help [command]", "Display help for a specific command.")
21
+
22
+ program
23
+ .command("get-group")
24
+ .description("Get group data from a supported network.")
25
+ .argument("<group-id>", "Identifier of the group.")
26
+ .option("-n, --network <network-name>", "Supported Ethereum network.", "goerli")
27
+ .option("--members", "Show group members.")
28
+ .option("--signals", "Show group signals.")
29
+ .usage("<group-id> [options]")
30
+ .action(async (groupId, { network, members, signals }) => {
31
+ const subgraph = new Subgraph(network)
32
+
33
+ const spinner = ora({
34
+ text: `Fetching group ${groupId}`,
35
+ spinner: "boxBounce"
36
+ }).start()
37
+
38
+ const group = await subgraph.getGroup(groupId, { members, verifiedProofs: signals })
39
+
40
+ let content = `\n ${chalk.bold("Id")}: ${group.id}\n`
41
+ content += ` ${chalk.bold("Admin")}: ${group.admin}\n`
42
+ content += ` ${chalk.bold("Merkle tree")}:\n`
43
+ content += ` Root: ${group.merkleTree.root}\n`
44
+ content += ` Depth: ${group.merkleTree.depth}\n`
45
+ content += ` Zero value: ${group.merkleTree.zeroValue}\n`
46
+ content += ` Number of leaves: ${group.merkleTree.numberOfLeaves}`
47
+
48
+ if (members) {
49
+ content += `\n\n ${chalk.bold("Members")}: \n${group.members
50
+ .map((member: string, i: number) => ` [${i}] ${member}`)
51
+ .join("\n")}`
52
+ }
53
+
54
+ if (signals) {
55
+ content += `\n\n ${chalk.bold("Signals")}: \n${group.verifiedProofs
56
+ .map(({ signal }: any, i: number) => ` [${i}] ${signal}`)
57
+ .join("\n")}`
58
+ }
59
+
60
+ spinner.stop()
61
+
62
+ console.log(`${content}\n`)
63
+ })
64
+
65
+ program.parse()