@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
|
|
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
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
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
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
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
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
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-
|
|
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": "
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
}
|