@devtion/devcli 0.0.0-57a8ab9 → 0.0.0-67a4629

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/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { createCommand } from 'commander';
12
12
  import fs, { readFileSync, createWriteStream, existsSync, renameSync } from 'fs';
13
- import path, { dirname } from 'path';
13
+ import { dirname } from 'path';
14
14
  import { fileURLToPath } from 'url';
15
15
  import { zKey, groth16 } from 'snarkjs';
16
16
  import boxen from 'boxen';
@@ -2285,66 +2285,75 @@ const isGroupMember = async (groupId, identity) => {
2285
2285
 
2286
2286
  const { BANDADA_DASHBOARD_URL, BANDADA_GROUP_ID } = process.env;
2287
2287
  const authBandada = async () => {
2288
- const { firebaseFunctions } = await bootstrapCommandExecutionAndServices();
2289
- const spinner = customSpinner(`Checking identity string for Semaphore...`, `clock`);
2290
- spinner.start();
2291
- // 1. check if _identity string exists in local storage
2292
- let identityString;
2293
- const isIdentityStringStored = checkLocalBandadaIdentity();
2294
- if (isIdentityStringStored) {
2295
- identityString = getLocalBandadaIdentity();
2296
- spinner.succeed(`Identity seed found\n`);
2297
- }
2298
- else {
2299
- spinner.warn(`Identity seed not found\n`);
2300
- // 2. generate a random _identity string and save it in local storage
2301
- const { seed } = await prompts({
2302
- type: "text",
2303
- name: "seed",
2304
- message: theme.text.bold(`Enter a secret string to use as your identity seed in Semaphore:`),
2305
- initial: false
2288
+ try {
2289
+ const { firebaseFunctions } = await bootstrapCommandExecutionAndServices();
2290
+ const spinner = customSpinner(`Checking identity string for Semaphore...`, `clock`);
2291
+ spinner.start();
2292
+ // 1. check if _identity string exists in local storage
2293
+ let identityString;
2294
+ const isIdentityStringStored = checkLocalBandadaIdentity();
2295
+ if (isIdentityStringStored) {
2296
+ identityString = getLocalBandadaIdentity();
2297
+ spinner.succeed(`Identity seed found\n`);
2298
+ }
2299
+ else {
2300
+ spinner.warn(`Identity seed not found\n`);
2301
+ // 2. generate a random _identity string and save it in local storage
2302
+ const { seed } = await prompts({
2303
+ type: "text",
2304
+ name: "seed",
2305
+ message: theme.text.bold(`Enter a secret string to use as your identity seed in Semaphore:`),
2306
+ initial: false
2307
+ });
2308
+ identityString = seed;
2309
+ setLocalBandadaIdentity(identityString);
2310
+ }
2311
+ // 3. create a semaphore identity with _identity string as a seed
2312
+ const identity = new Identity(identityString);
2313
+ // 4. check if the user is a member of the group
2314
+ console.log(`Checking Bandada membership...`);
2315
+ const isMember = await isGroupMember(BANDADA_GROUP_ID, identity);
2316
+ if (!isMember) {
2317
+ await addMemberToGroup(BANDADA_GROUP_ID, BANDADA_DASHBOARD_URL, identity);
2318
+ }
2319
+ // 5. generate a proof that the user owns the commitment.
2320
+ spinner.text = `Generating proof of identity...`;
2321
+ spinner.start();
2322
+ // publicSignals = [hash(externalNullifier, identityNullifier), commitment]
2323
+ const { proof, publicSignals } = await groth16.fullProve({
2324
+ identityTrapdoor: identity.trapdoor,
2325
+ identityNullifier: identity.nullifier,
2326
+ externalNullifier: BANDADA_GROUP_ID
2327
+ }, `${dirname(fileURLToPath(import.meta.url))}/public/mini-semaphore.wasm`, `${dirname(fileURLToPath(import.meta.url))}/public/mini-semaphore.zkey`);
2328
+ spinner.succeed(`Proof generated.\n`);
2329
+ spinner.text = `Sending proof to verification...`;
2330
+ spinner.start();
2331
+ // 6. send proof to a cloud function that verifies it and checks membership
2332
+ const cf = httpsCallable(firebaseFunctions, commonTerms.cloudFunctionsNames.bandadaValidateProof);
2333
+ const result = await cf({
2334
+ proof,
2335
+ publicSignals
2306
2336
  });
2307
- identityString = seed;
2308
- setLocalBandadaIdentity(identityString);
2309
- }
2310
- // 3. create a semaphore identity with _identity string as a seed
2311
- const identity = new Identity(identityString);
2312
- // 4. check if the user is a member of the group
2313
- console.log(`Checking Bandada membership...`);
2314
- const isMember = await isGroupMember(BANDADA_GROUP_ID, identity);
2315
- if (!isMember) {
2316
- await addMemberToGroup(BANDADA_GROUP_ID, BANDADA_DASHBOARD_URL, identity);
2337
+ const { valid, token, message } = result.data;
2338
+ if (!valid) {
2339
+ showError(message, true);
2340
+ }
2341
+ spinner.succeed(`Proof verified.\n`);
2342
+ spinner.text = `Authenticating...`;
2343
+ spinner.start();
2344
+ // 7. Auth to p0tion firebase
2345
+ const userCredentials = await signInWithCustomToken(getAuth(), token);
2346
+ setLocalAccessToken(token);
2347
+ spinner.succeed(`Authenticated as ${theme.text.bold(userCredentials.user.uid)}.`);
2348
+ console.log(`\n${theme.symbols.warning} You can always log out by running the ${theme.text.bold(`phase2cli logout`)} command`);
2317
2349
  }
2318
- // 5. generate a proof that the user owns the commitment.
2319
- spinner.text = `Generating proof of identity...`;
2320
- spinner.start();
2321
- // publicSignals = [hash(externalNullifier, identityNullifier), commitment]
2322
- const { proof, publicSignals } = await groth16.fullProve({
2323
- identityTrapdoor: identity.trapdoor,
2324
- identityNullifier: identity.nullifier,
2325
- externalNullifier: BANDADA_GROUP_ID
2326
- }, path.join(path.resolve(), "/public/mini-semaphore.wasm"), path.join(path.resolve(), "/public/mini-semaphore.zkey"));
2327
- spinner.succeed(`Proof generated.\n`);
2328
- spinner.text = `Sending proof to verification...`;
2329
- spinner.start();
2330
- // 6. send proof to a cloud function that verifies it and checks membership
2331
- const cf = httpsCallable(firebaseFunctions, commonTerms.cloudFunctionsNames.bandadaValidateProof);
2332
- const result = await cf({
2333
- proof,
2334
- publicSignals
2335
- });
2336
- const { valid, token, message } = result.data;
2337
- if (!valid) {
2338
- showError(message, true);
2350
+ catch (error) {
2351
+ // Delete local token.
2352
+ console.log("An error crashed the process. Deleting local token and identity.");
2353
+ console.error(error);
2354
+ deleteLocalAccessToken();
2355
+ deleteLocalBandadaIdentity();
2339
2356
  }
2340
- spinner.succeed(`Proof verified.\n`);
2341
- spinner.text = `Authenticating...`;
2342
- spinner.start();
2343
- // 7. Auth to p0tion firebase
2344
- const userCredentials = await signInWithCustomToken(getAuth(), token);
2345
- setLocalAccessToken(token);
2346
- spinner.succeed(`Authenticated as ${theme.text.bold(userCredentials.user.uid)}.`);
2347
- console.log(`\n${theme.symbols.warning} You can always log out by running the ${theme.text.bold(`phase2cli logout`)} command`);
2348
2357
  process.exit(0);
2349
2358
  };
2350
2359
 
Binary file
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@devtion/devcli",
3
3
  "type": "module",
4
- "version": "0.0.0-57a8ab9",
4
+ "version": "0.0.0-67a4629",
5
5
  "description": "All-in-one interactive command-line for interfacing with zkSNARK Phase 2 Trusted Setup ceremonies",
6
6
  "repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
7
7
  "homepage": "https://github.com/privacy-scaling-explorations/p0tion",
@@ -59,6 +59,7 @@
59
59
  "@types/winston": "^2.4.4",
60
60
  "rollup-plugin-auto-external": "^2.0.0",
61
61
  "rollup-plugin-cleanup": "^3.2.1",
62
+ "rollup-plugin-copy": "^3.5.0",
62
63
  "rollup-plugin-typescript2": "^0.34.1",
63
64
  "solc": "^0.8.19",
64
65
  "ts-node": "^10.9.1",
@@ -102,5 +103,5 @@
102
103
  "publishConfig": {
103
104
  "access": "public"
104
105
  },
105
- "gitHead": "6bddf60f1121786c19ad4437e0448de4c859b829"
106
+ "gitHead": "74b2b41e243efd4386fd93aba889348ce95e35a7"
106
107
  }
@@ -3,8 +3,10 @@ import { Identity } from "@semaphore-protocol/identity"
3
3
  import { commonTerms } from "@devtion/actions"
4
4
  import { httpsCallable } from "firebase/functions"
5
5
  import { groth16 } from "snarkjs"
6
- import path from "path"
6
+ import { dirname } from "path"
7
7
  import { getAuth, signInWithCustomToken } from "firebase/auth"
8
+ import prompts from "prompts"
9
+ import { fileURLToPath } from "url"
8
10
  import theme from "../lib/theme.js"
9
11
  import { customSpinner } from "../lib/utils.js"
10
12
  import { VerifiedBandadaResponse } from "../types/index.js"
@@ -13,85 +15,94 @@ import { bootstrapCommandExecutionAndServices } from "../lib/services.js"
13
15
  import { addMemberToGroup, isGroupMember } from "../lib/bandada.js"
14
16
  import {
15
17
  checkLocalBandadaIdentity,
18
+ deleteLocalAccessToken,
19
+ deleteLocalBandadaIdentity,
16
20
  getLocalBandadaIdentity,
17
21
  setLocalAccessToken,
18
22
  setLocalBandadaIdentity
19
23
  } from "../lib/localConfigs.js"
20
- import prompts from "prompts"
21
24
 
22
25
  const { BANDADA_DASHBOARD_URL, BANDADA_GROUP_ID } = process.env
23
26
 
24
27
  const authBandada = async () => {
25
- const { firebaseFunctions } = await bootstrapCommandExecutionAndServices()
26
- const spinner = customSpinner(`Checking identity string for Semaphore...`, `clock`)
27
- spinner.start()
28
- // 1. check if _identity string exists in local storage
29
- let identityString: string | unknown
30
- const isIdentityStringStored = checkLocalBandadaIdentity()
31
- if (isIdentityStringStored) {
32
- identityString = getLocalBandadaIdentity()
33
- spinner.succeed(`Identity seed found\n`)
34
- } else {
35
- spinner.warn(`Identity seed not found\n`)
36
- // 2. generate a random _identity string and save it in local storage
37
- const { seed } = await prompts({
38
- type: "text",
39
- name: "seed",
40
- message: theme.text.bold(`Enter a secret string to use as your identity seed in Semaphore:`),
41
- initial: false
42
- })
43
- identityString = seed as string
44
- setLocalBandadaIdentity(identityString as string)
45
- }
46
- // 3. create a semaphore identity with _identity string as a seed
47
- const identity = new Identity(identityString as string)
28
+ try {
29
+ const { firebaseFunctions } = await bootstrapCommandExecutionAndServices()
30
+ const spinner = customSpinner(`Checking identity string for Semaphore...`, `clock`)
31
+ spinner.start()
32
+ // 1. check if _identity string exists in local storage
33
+ let identityString: string | unknown
34
+ const isIdentityStringStored = checkLocalBandadaIdentity()
35
+ if (isIdentityStringStored) {
36
+ identityString = getLocalBandadaIdentity()
37
+ spinner.succeed(`Identity seed found\n`)
38
+ } else {
39
+ spinner.warn(`Identity seed not found\n`)
40
+ // 2. generate a random _identity string and save it in local storage
41
+ const { seed } = await prompts({
42
+ type: "text",
43
+ name: "seed",
44
+ message: theme.text.bold(`Enter a secret string to use as your identity seed in Semaphore:`),
45
+ initial: false
46
+ })
47
+ identityString = seed as string
48
+ setLocalBandadaIdentity(identityString as string)
49
+ }
50
+ // 3. create a semaphore identity with _identity string as a seed
51
+ const identity = new Identity(identityString as string)
48
52
 
49
- // 4. check if the user is a member of the group
50
- console.log(`Checking Bandada membership...`)
51
- const isMember = await isGroupMember(BANDADA_GROUP_ID, identity)
52
- if (!isMember) {
53
- await addMemberToGroup(BANDADA_GROUP_ID, BANDADA_DASHBOARD_URL, identity)
54
- }
53
+ // 4. check if the user is a member of the group
54
+ console.log(`Checking Bandada membership...`)
55
+ const isMember = await isGroupMember(BANDADA_GROUP_ID, identity)
56
+ if (!isMember) {
57
+ await addMemberToGroup(BANDADA_GROUP_ID, BANDADA_DASHBOARD_URL, identity)
58
+ }
55
59
 
56
- // 5. generate a proof that the user owns the commitment.
57
- spinner.text = `Generating proof of identity...`
58
- spinner.start()
59
- // publicSignals = [hash(externalNullifier, identityNullifier), commitment]
60
- const { proof, publicSignals } = await groth16.fullProve(
61
- {
62
- identityTrapdoor: identity.trapdoor,
63
- identityNullifier: identity.nullifier,
64
- externalNullifier: BANDADA_GROUP_ID
65
- },
66
- path.join(path.resolve(), "/public/mini-semaphore.wasm"),
67
- path.join(path.resolve(), "/public/mini-semaphore.zkey")
68
- )
69
- spinner.succeed(`Proof generated.\n`)
70
- spinner.text = `Sending proof to verification...`
71
- spinner.start()
72
- // 6. send proof to a cloud function that verifies it and checks membership
73
- const cf = httpsCallable(firebaseFunctions, commonTerms.cloudFunctionsNames.bandadaValidateProof)
74
- const result = await cf({
75
- proof,
76
- publicSignals
77
- })
78
- const { valid, token, message } = result.data as VerifiedBandadaResponse
79
- if (!valid) {
80
- showError(message, true)
81
- }
82
- spinner.succeed(`Proof verified.\n`)
83
- spinner.text = `Authenticating...`
84
- spinner.start()
85
- // 7. Auth to p0tion firebase
86
- const userCredentials = await signInWithCustomToken(getAuth(), token)
87
- setLocalAccessToken(token)
88
- spinner.succeed(`Authenticated as ${theme.text.bold(userCredentials.user.uid)}.`)
60
+ // 5. generate a proof that the user owns the commitment.
61
+ spinner.text = `Generating proof of identity...`
62
+ spinner.start()
63
+ // publicSignals = [hash(externalNullifier, identityNullifier), commitment]
64
+ const { proof, publicSignals } = await groth16.fullProve(
65
+ {
66
+ identityTrapdoor: identity.trapdoor,
67
+ identityNullifier: identity.nullifier,
68
+ externalNullifier: BANDADA_GROUP_ID
69
+ },
70
+ `${dirname(fileURLToPath(import.meta.url))}/public/mini-semaphore.wasm`,
71
+ `${dirname(fileURLToPath(import.meta.url))}/public/mini-semaphore.zkey`
72
+ )
73
+ spinner.succeed(`Proof generated.\n`)
74
+ spinner.text = `Sending proof to verification...`
75
+ spinner.start()
76
+ // 6. send proof to a cloud function that verifies it and checks membership
77
+ const cf = httpsCallable(firebaseFunctions, commonTerms.cloudFunctionsNames.bandadaValidateProof)
78
+ const result = await cf({
79
+ proof,
80
+ publicSignals
81
+ })
82
+ const { valid, token, message } = result.data as VerifiedBandadaResponse
83
+ if (!valid) {
84
+ showError(message, true)
85
+ }
86
+ spinner.succeed(`Proof verified.\n`)
87
+ spinner.text = `Authenticating...`
88
+ spinner.start()
89
+ // 7. Auth to p0tion firebase
90
+ const userCredentials = await signInWithCustomToken(getAuth(), token)
91
+ setLocalAccessToken(token)
92
+ spinner.succeed(`Authenticated as ${theme.text.bold(userCredentials.user.uid)}.`)
89
93
 
90
- console.log(
91
- `\n${theme.symbols.warning} You can always log out by running the ${theme.text.bold(
92
- `phase2cli logout`
93
- )} command`
94
- )
94
+ console.log(
95
+ `\n${theme.symbols.warning} You can always log out by running the ${theme.text.bold(
96
+ `phase2cli logout`
97
+ )} command`
98
+ )
99
+ } catch (error) {
100
+ // Delete local token.
101
+ console.log("An error crashed the process. Deleting local token and identity.")
102
+ console.error(error)
103
+ deleteLocalAccessToken()
104
+ deleteLocalBandadaIdentity()
105
+ }
95
106
 
96
107
  process.exit(0)
97
108
  }