@devtion/devcli 0.0.0-56491a8 → 0.0.0-57a8ab9

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.
@@ -6,7 +6,7 @@ import { showError } from "../lib/errors.js"
6
6
  import { askForConfirmation } from "../lib/prompts.js"
7
7
  import { customSpinner, sleep, terminate } from "../lib/utils.js"
8
8
  import theme from "../lib/theme.js"
9
- import { deleteLocalAccessToken } from "../lib/localConfigs.js"
9
+ import { deleteLocalAccessToken, deleteLocalBandadaIdentity } from "../lib/localConfigs.js"
10
10
 
11
11
  /**
12
12
  * Logout command.
@@ -53,6 +53,7 @@ const logout = async () => {
53
53
 
54
54
  // Delete local token.
55
55
  deleteLocalAccessToken()
56
+ deleteLocalBandadaIdentity()
56
57
 
57
58
  await sleep(3000) // ~3s.
58
59
 
@@ -15,7 +15,7 @@ import { COMMAND_ERRORS, GENERIC_ERRORS, showError } from "../lib/errors.js"
15
15
  import { promptForCeremonySelection } from "../lib/prompts.js"
16
16
  import { bootstrapCommandExecutionAndServices, checkAuth } from "../lib/services.js"
17
17
  import theme from "../lib/theme.js"
18
- import {customSpinner, getSecondsMinutesHoursFromMillis, sleep } from "../lib/utils.js"
18
+ import { customSpinner, getSecondsMinutesHoursFromMillis, sleep } from "../lib/utils.js"
19
19
 
20
20
  /**
21
21
  * Clean cursor lines from current position back to root (default: zero).
@@ -143,7 +143,7 @@ const observe = async () => {
143
143
  // Preserve command execution only for coordinators].
144
144
  if (!(await isCoordinator(user))) showError(COMMAND_ERRORS.COMMAND_NOT_COORDINATOR, true)
145
145
 
146
- // Get running cerimonies info (if any).
146
+ // Get running ceremonies info (if any).
147
147
  const runningCeremoniesDocs = await getOpenedCeremonies(firestoreDatabase)
148
148
 
149
149
  // Ask to select a ceremony.
@@ -2,12 +2,11 @@
2
2
 
3
3
  import { zKey } from "snarkjs"
4
4
  import boxen from "boxen"
5
- import { createWriteStream, Dirent, renameSync } from "fs"
5
+ import { createWriteStream, Dirent, renameSync, existsSync } from "fs"
6
6
  import { pipeline } from "node:stream"
7
7
  import { promisify } from "node:util"
8
8
  import fetch from "node-fetch"
9
9
  import { Functions } from "firebase/functions"
10
- import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
11
10
  import {
12
11
  CeremonyTimeoutType,
13
12
  CircomCompilerData,
@@ -63,7 +62,6 @@ import {
63
62
  getFileStats,
64
63
  checkAndMakeNewDirectoryIfNonexistent
65
64
  } from "../lib/files.js"
66
- import { Readable } from "stream"
67
65
 
68
66
  /**
69
67
  * Handle whatever is needed to obtain the input data for a circuit that the coordinator would like to add to the ceremony.
@@ -183,7 +181,7 @@ export const handleAdditionOfCircuitsToCeremony = async (
183
181
 
184
182
  if (matchingWasms.length !== 1) showError(COMMAND_ERRORS.COMMAND_SETUP_MISMATCH_R1CS_WASM, true)
185
183
 
186
- // Get input data for choosen circuit.
184
+ // Get input data for chosen circuit.
187
185
  const circuitInputData = await getInputDataToAddCircuitToCeremony(
188
186
  choosenCircuitFilename,
189
187
  matchingWasms[0],
@@ -324,7 +322,7 @@ export const checkAndDownloadSmallestPowersOfTau = async (
324
322
  * number of powers greater than or equal to the powers needed by the zKey), the coordinator will be asked
325
323
  * to provide a number of powers manually, ranging from the smallest possible to the largest.
326
324
  * @param neededPowers <number> - the smallest amount of powers needed by the zKey.
327
- * @returns Promise<string, string> - the information about the choosen Powers of Tau file for the pre-computed zKey
325
+ * @returns Promise<string, string> - the information about the chosen Powers of Tau file for the pre-computed zKey
328
326
  * along with related powers.
329
327
  */
330
328
  export const handlePreComputedZkeyPowersOfTauSelection = async (
@@ -468,7 +466,7 @@ export const handleCircuitArtifactUploadToStorage = async (
468
466
  * from Hermez's ceremony Phase 1 Reliable Setup Ceremony.
469
467
  * @param cmd? <any> - the path to the ceremony setup file.
470
468
  */
471
- const setup = async (cmd: { template?: string, auth?: string}) => {
469
+ const setup = async (cmd: { template?: string; auth?: string }) => {
472
470
  // Setup command state.
473
471
  const circuits: Array<CircuitDocument> = [] // Circuits.
474
472
  let ceremonyId: string = "" // The unique identifier of the ceremony.
@@ -476,8 +474,10 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
476
474
  const { firebaseApp, firebaseFunctions, firestoreDatabase } = await bootstrapCommandExecutionAndServices()
477
475
 
478
476
  // Check for authentication.
479
- const { user, providerUserId } = cmd.auth ? await authWithToken(firebaseApp, cmd.auth) : await checkAuth(firebaseApp)
480
-
477
+ const { user, providerUserId } = cmd.auth
478
+ ? await authWithToken(firebaseApp, cmd.auth)
479
+ : await checkAuth(firebaseApp)
480
+
481
481
  // Preserve command execution only for coordinators.
482
482
  if (!(await isCoordinator(user))) showError(COMMAND_ERRORS.COMMAND_NOT_COORDINATOR, true)
483
483
 
@@ -503,7 +503,7 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
503
503
  // if there is the file option, then set up the non interactively
504
504
  if (cmd.template) {
505
505
  // 1. parse the file
506
- // tmp data - do not cleanup files as we need them
506
+ // tmp data - do not cleanup files as we need them
507
507
  const spinner = customSpinner(`Parsing ${theme.text.bold(cmd.template!)} setup configuration file...`, `clock`)
508
508
  spinner.start()
509
509
  const setupCeremonyData = await parseCeremonyFile(cmd.template!)
@@ -526,18 +526,44 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
526
526
  const zkeyLocalPathAndFileName = getZkeyLocalFilePath(circuit.files.initialZkeyFilename)
527
527
 
528
528
  // 2. download the pot and wasm files
529
- await checkAndDownloadSmallestPowersOfTau(convertToDoubleDigits(circuit.metadata?.pot!), circuit.files.potFilename)
530
-
529
+ await checkAndDownloadSmallestPowersOfTau(
530
+ convertToDoubleDigits(circuit.metadata?.pot!),
531
+ circuit.files.potFilename
532
+ )
533
+
531
534
  // 3. generate the zKey
532
- const spinner = customSpinner(`Generating genesis zKey for circuit ${theme.text.bold(circuit.name)}...`, `clock`)
535
+ const spinner = customSpinner(
536
+ `Generating genesis zKey for circuit ${theme.text.bold(circuit.name)}...`,
537
+ `clock`
538
+ )
533
539
  spinner.start()
534
- await zKey.newZKey(r1csLocalPathAndFileName, getPotLocalFilePath(circuit.files.potFilename), zkeyLocalPathAndFileName, undefined)
535
- spinner.succeed(`Generation of the genesis zKey for citcui ${theme.text.bold(circuit.name)} completed successfully`)
536
540
 
541
+ if (existsSync(zkeyLocalPathAndFileName)) {
542
+ spinner.succeed(
543
+ `The genesis zKey for circuit ${theme.text.bold(circuit.name)} is already present on disk`
544
+ )
545
+ } else {
546
+ await zKey.newZKey(
547
+ r1csLocalPathAndFileName,
548
+ getPotLocalFilePath(circuit.files.potFilename),
549
+ zkeyLocalPathAndFileName,
550
+ undefined
551
+ )
552
+ spinner.succeed(
553
+ `Generation of the genesis zKey for circuit ${theme.text.bold(circuit.name)} completed successfully`
554
+ )
555
+ }
556
+
557
+ const hashSpinner = customSpinner(
558
+ `Calculating hashes for circuit ${theme.text.bold(circuit.name)}...`,
559
+ `clock`
560
+ )
561
+ hashSpinner.start()
537
562
  // 4. calculate the hashes
538
563
  const wasmBlake2bHash = await blake512FromPath(wasmLocalPathAndFileName)
539
564
  const potBlake2bHash = await blake512FromPath(getPotLocalFilePath(circuit.files.potFilename))
540
565
  const initialZkeyBlake2bHash = await blake512FromPath(zkeyLocalPathAndFileName)
566
+ hashSpinner.succeed(`Hashes for circuit ${theme.text.bold(circuit.name)} calculated successfully`)
541
567
 
542
568
  // 5. upload the artifacts
543
569
 
@@ -549,7 +575,7 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
549
575
  zkeyLocalPathAndFileName,
550
576
  circuit.files.initialZkeyFilename
551
577
  )
552
-
578
+
553
579
  // Check if PoT file has been already uploaded to storage.
554
580
  const alreadyUploadedPot = await checkIfObjectExist(
555
581
  firebaseFunctions,
@@ -590,25 +616,31 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
590
616
  // 6 update the setup data object
591
617
  ceremonySetupData.circuits[index].files = {
592
618
  ...circuit.files,
593
- potBlake2bHash: potBlake2bHash,
594
- wasmBlake2bHash: wasmBlake2bHash,
595
- initialZkeyBlake2bHash: initialZkeyBlake2bHash
619
+ potBlake2bHash,
620
+ wasmBlake2bHash,
621
+ initialZkeyBlake2bHash
596
622
  }
597
623
 
598
624
  ceremonySetupData.circuits[index].zKeySizeInBytes = getFileStats(zkeyLocalPathAndFileName).size
599
625
  }
600
-
601
626
 
602
627
  // 7. setup the ceremony
603
- const ceremonyId = await setupCeremony(firebaseFunctions, ceremonySetupData.ceremonyInputData, ceremonySetupData.ceremonyPrefix, ceremonySetupData.circuits)
604
- console.log( `Congratulations, the setup of ceremony ${theme.text.bold(
605
- ceremonySetupData.ceremonyInputData.title
606
- )} (${`UID: ${theme.text.bold(ceremonyId)}`}) has been successfully completed ${
607
- theme.emojis.tada
608
- }. You will be able to find all the files and info respectively in the ceremony bucket and database document.`)
609
-
628
+ const ceremonyId = await setupCeremony(
629
+ firebaseFunctions,
630
+ ceremonySetupData.ceremonyInputData,
631
+ ceremonySetupData.ceremonyPrefix,
632
+ ceremonySetupData.circuits
633
+ )
634
+ console.log(
635
+ `Congratulations, the setup of ceremony ${theme.text.bold(
636
+ ceremonySetupData.ceremonyInputData.title
637
+ )} (${`UID: ${theme.text.bold(ceremonyId)}`}) has been successfully completed ${
638
+ theme.emojis.tada
639
+ }. You will be able to find all the files and info respectively in the ceremony bucket and database document.`
640
+ )
641
+
610
642
  terminate(providerUserId)
611
- }
643
+ }
612
644
 
613
645
  // Look for R1CS files.
614
646
  const r1csFilePaths = await filterDirectoryFilesByExtension(cwd, `.r1cs`)
@@ -4,7 +4,7 @@ import { showError } from "../lib/errors.js"
4
4
  /**
5
5
  * Validate ceremony setup command.
6
6
  */
7
- const validate = async (cmd: { template: string, constraints?: number }) => {
7
+ const validate = async (cmd: { template: string; constraints?: number }) => {
8
8
  try {
9
9
  // parse the file and cleanup after
10
10
  const parsedFile = await parseCeremonyFile(cmd.template, true)
@@ -18,7 +18,6 @@ const validate = async (cmd: { template: string, constraints?: number }) => {
18
18
  }
19
19
 
20
20
  console.log(true)
21
-
22
21
  } catch (err: any) {
23
22
  showError(`${err.toString()}`, false)
24
23
  // we want to exit with a non-zero exit code
package/src/index.ts CHANGED
@@ -4,7 +4,19 @@ import { createCommand } from "commander"
4
4
  import { readFileSync } from "fs"
5
5
  import { dirname } from "path"
6
6
  import { fileURLToPath } from "url"
7
- import { setup, auth, contribute, observe, finalize, clean, logout, validate, listCeremonies } from "./commands/index.js"
7
+ import {
8
+ setup,
9
+ auth,
10
+ authBandada,
11
+ contribute,
12
+ observe,
13
+ finalize,
14
+ clean,
15
+ logout,
16
+ validate,
17
+ listCeremonies
18
+ } from "./commands/index.js"
19
+ import setCeremonyCommands from "./commands/ceremony/index.js"
8
20
 
9
21
  // Get pkg info (e.g., name, version).
10
22
  const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
@@ -16,51 +28,56 @@ program.name(name).description(description).version(version)
16
28
 
17
29
  // User commands.
18
30
  program.command("auth").description("authenticate yourself using your Github account (OAuth 2.0)").action(auth)
31
+ program
32
+ .command("auth-bandada")
33
+ .description("authenticate yourself in a privacy-perserving manner using Bandada")
34
+ .action(authBandada)
19
35
  program
20
36
  .command("contribute")
21
37
  .description("compute contributions for a Phase2 Trusted Setup ceremony circuits")
22
38
  .option("-c, --ceremony <string>", "the prefix of the ceremony you want to contribute for", "")
23
39
  .option("-e, --entropy <string>", "the entropy (aka toxic waste) of your contribution", "")
40
+ .option("-a, --auth <string>", "the Github OAuth 2.0 token", "")
24
41
  .action(contribute)
25
42
  program
26
43
  .command("clean")
27
44
  .description("clean up output generated by commands from the current working directory")
28
45
  .action(clean)
29
- program
30
- .command("list")
31
- .description("List all ceremonies prefixes")
32
- .action(listCeremonies)
46
+ program.command("list").description("List all ceremonies prefixes").action(listCeremonies)
33
47
  program
34
48
  .command("logout")
35
49
  .description("sign out from Firebae Auth service and delete Github OAuth 2.0 token from local storage")
36
50
  .action(logout)
37
51
  program
38
52
  .command("validate")
39
- .description("Validate that a Ceremony Setup file is correct")
53
+ .description("validate that a Ceremony Setup file is correct")
40
54
  .requiredOption("-t, --template <path>", "The path to the ceremony setup template", "")
41
55
  .option("-c, --constraints <number>", "The number of constraints to check against")
42
56
  .action(validate)
43
57
 
44
58
  // Only coordinator commands.
45
- const ceremony = program.command("coordinate").description("commands for coordinating a ceremony")
59
+ const coordinate = program.command("coordinate").description("commands for coordinating a ceremony")
46
60
 
47
- ceremony
61
+ coordinate
48
62
  .command("setup")
49
63
  .description("setup a Groth16 Phase 2 Trusted Setup ceremony for zk-SNARK circuits")
50
- .option('-t, --template <path>', 'The path to the ceremony setup template', '')
51
- .option('-a, --auth <string>', 'The Github OAuth 2.0 token', '')
64
+ .option("-t, --template <path>", "The path to the ceremony setup template", "")
65
+ .option("-a, --auth <string>", "The Github OAuth 2.0 token", "")
52
66
  .action(setup)
53
-
54
- ceremony
67
+
68
+ coordinate
55
69
  .command("observe")
56
70
  .description("observe in real-time the waiting queue of each ceremony circuit")
57
71
  .action(observe)
58
72
 
59
- ceremony
73
+ coordinate
60
74
  .command("finalize")
61
75
  .description(
62
76
  "finalize a Phase2 Trusted Setup ceremony by applying a beacon, exporting verification key and verifier contract"
63
77
  )
78
+ .option("-a, --auth <string>", "the Github OAuth 2.0 token", "")
64
79
  .action(finalize)
65
80
 
81
+ setCeremonyCommands(program)
82
+
66
83
  program.parseAsync(process.argv)
@@ -0,0 +1,51 @@
1
+ import { ApiSdk, GroupResponse } from "@bandada/api-sdk"
2
+ import { Identity } from "@semaphore-protocol/identity"
3
+ import open from "open"
4
+
5
+ import { askForConfirmation } from "../lib/prompts.js"
6
+ import { showError } from "./errors.js"
7
+ import theme from "../lib/theme.js"
8
+
9
+ const { BANDADA_API_URL } = process.env
10
+
11
+ const bandadaApi = new ApiSdk(BANDADA_API_URL)
12
+
13
+ export const getGroup = async (groupId: string): Promise<GroupResponse | null> => {
14
+ try {
15
+ const group = await bandadaApi.getGroup(groupId)
16
+ return group
17
+ } catch (error: any) {
18
+ showError(`Bandada getGroup error: ${error}`, true)
19
+ return null
20
+ }
21
+ }
22
+
23
+ export const getMembersOfGroup = async (groupId: string): Promise<string[] | null> => {
24
+ try {
25
+ const group = await bandadaApi.getGroup(groupId)
26
+ return group.members
27
+ } catch (error: any) {
28
+ showError(`Bandada getMembersOfGroup error: ${error}`, true)
29
+ return null
30
+ }
31
+ }
32
+
33
+ export const addMemberToGroup = async (groupId: string, dashboardUrl: string, identity: Identity) => {
34
+ const commitment = identity.commitment.toString()
35
+ const group = await bandadaApi.getGroup(groupId)
36
+ const providerName = group.credentials.id.split("_")[0].toLowerCase()
37
+
38
+ // 6. open a new window with the url:
39
+ const url = `${dashboardUrl}credentials?group=${groupId}&member=${commitment}&provider=${providerName}`
40
+ console.log(`${theme.text.bold(`Verification URL:`)} ${theme.text.underlined(url)}`)
41
+ open(url)
42
+
43
+ const { confirmation } = await askForConfirmation("Did you join the Bandada group in the browser?")
44
+ if (!confirmation) showError("You must join the Bandada group to continue the login process", true)
45
+ }
46
+
47
+ export const isGroupMember = async (groupId: string, identity: Identity): Promise<boolean> => {
48
+ const commitment = identity.commitment.toString()
49
+ const isMember: boolean = await bandadaApi.isGroupMember(groupId, commitment)
50
+ return isMember
51
+ }
package/src/lib/errors.ts CHANGED
@@ -6,7 +6,7 @@ export const CORE_SERVICES_ERRORS = {
6
6
  FIREBASE_TOKEN_EXPIRED_REMOVED_PERMISSIONS: `The Github authorization has failed due to lack of association between your account and the CLI`,
7
7
  FIREBASE_USER_DISABLED: `The Github account has been suspended by the ceremony coordinator(s), blocking the possibility of contribution. Please, contact them to understand the motivation behind it.`,
8
8
  FIREBASE_FAILED_CREDENTIALS_VERIFICATION: `Firebase cannot verify your Github credentials due to network errors. Please, try once again later.`,
9
- FIREBASE_NETWORK_ERROR: `Unable to reach Firebase due to network erros. Please, try once again later and make sure your Internet connection is stable.`,
9
+ FIREBASE_NETWORK_ERROR: `Unable to reach Firebase due to network errors. Please, try once again later and make sure your Internet connection is stable.`,
10
10
  FIREBASE_CEREMONY_NOT_OPENED: `There are no ceremonies opened to contributions`,
11
11
  FIREBASE_CEREMONY_NOT_CLOSED: `There are no ceremonies ready to finalization`,
12
12
  AWS_CEREMONY_BUCKET_CREATION: `Unable to create a new bucket for the ceremony. Something went wrong during the creation. Please, repeat the process by providing a new ceremony name of the ceremony.`,
@@ -24,6 +24,10 @@ const config = new Conf({
24
24
  accessToken: {
25
25
  type: "string",
26
26
  default: ""
27
+ },
28
+ bandadaIdentity: {
29
+ type: "string",
30
+ default: ""
27
31
  }
28
32
  }
29
33
  })
@@ -91,6 +95,29 @@ export const setLocalAccessToken = (token: string) => config.set("accessToken",
91
95
  */
92
96
  export const deleteLocalAccessToken = () => config.delete("accessToken")
93
97
 
98
+ /**
99
+ * Return the Bandada identity, if present.
100
+ * @returns <string | undefined> - the Bandada identity if present, otherwise undefined.
101
+ */
102
+ export const getLocalBandadaIdentity = (): string | unknown => config.get("bandadaIdentity")
103
+
104
+ /**
105
+ * Check if the Bandada identity exists in the local storage.
106
+ * @returns <boolean>
107
+ */
108
+ export const checkLocalBandadaIdentity = (): boolean => config.has("bandadaIdentity") && !!config.get("bandadaIdentity")
109
+
110
+ /**
111
+ * Set the Bandada identity.
112
+ * @param identity <string> - the Bandada identity to be stored.
113
+ */
114
+ export const setLocalBandadaIdentity = (identity: string) => config.set("bandadaIdentity", identity)
115
+
116
+ /**
117
+ * Delete the stored Bandada identity.
118
+ */
119
+ export const deleteLocalBandadaIdentity = () => config.delete("bandadaIdentity")
120
+
94
121
  /**
95
122
  * Get the complete local file path.
96
123
  * @param cwd <string> - the current working directory path.
@@ -203,7 +203,7 @@ export const promptCircomCompiler = async (): Promise<CircomCompilerData> => {
203
203
  * Shows a list of circuits for a single option selection.
204
204
  * @dev the circuit names are derived from local R1CS files.
205
205
  * @param options <Array<string>> - an array of circuits names.
206
- * @returns Promise<string> - the name of the choosen circuit.
206
+ * @returns Promise<string> - the name of the chosen circuit.
207
207
  */
208
208
  export const promptCircuitSelector = async (options: Array<string>): Promise<string> => {
209
209
  const { circuitFilename } = await prompts({
@@ -223,7 +223,7 @@ export const promptCircuitSelector = async (options: Array<string>): Promise<str
223
223
  * Shows a list of standard EC2 VM instance types for a single option selection.
224
224
  * @notice the suggested VM configuration type is calculated based on circuit constraint size.
225
225
  * @param constraintSize <number> - the amount of circuit constraints
226
- * @returns Promise<string> - the name of the choosen VM type.
226
+ * @returns Promise<string> - the name of the chosen VM type.
227
227
  */
228
228
  export const promptVMTypeSelector = async (constraintSize): Promise<string> => {
229
229
  let suggestedConfiguration: number = 0
@@ -325,7 +325,7 @@ export const promptVMDiskTypeSelector = async (): Promise<DiskTypeForVM> => {
325
325
  /**
326
326
  * Show a series of questions about the circuits.
327
327
  * @param constraintSize <number> - the amount of circuit constraints.
328
- * @param timeoutMechanismType <CeremonyTimeoutType> - the choosen timeout mechanism type for the ceremony.
328
+ * @param timeoutMechanismType <CeremonyTimeoutType> - the chosen timeout mechanism type for the ceremony.
329
329
  * @param needPromptCircomCompiler <boolean> - a boolean value indicating if the questions related to the Circom compiler version and commit hash must be asked.
330
330
  * @param enforceVM <boolean> - a boolean value indicating if the contribution verification could be supported by VM-only approach or not.
331
331
  * @returns Promise<Array<Circuit>> - circuit info prompted by the coordinator.
@@ -343,7 +343,7 @@ export const promptCircuitInputData = async (
343
343
  let circomVersion: string = ""
344
344
  let circomCommitHash: string = ""
345
345
  let circuitInputData: CircuitInputData
346
- let useCfOrVm: CircuitContributionVerificationMechanism
346
+ let cfOrVm: CircuitContributionVerificationMechanism
347
347
  let vmDiskType: DiskTypeForVM
348
348
  let vmConfigurationType: string = ""
349
349
 
@@ -422,19 +422,23 @@ export const promptCircuitInputData = async (
422
422
  circomCommitHash = commitHash
423
423
  }
424
424
 
425
- // Ask for prefered contribution verification method (CF vs VM).
425
+ // Ask for preferred contribution verification method (CF vs VM).
426
426
  if (!enforceVM) {
427
427
  const { confirmation } = await askForConfirmation(
428
428
  `The contribution verification can be performed using Cloud Functions (CF, cheaper for small contributions but limited to 1M constraints) or custom virtual machines (expensive but could scale up to 30M constraints). Be aware about VM costs and if you wanna learn more, please visit the documentation to have a complete overview about cost estimation of the two mechanisms.\nChoose the contribution verification mechanism`,
429
429
  `CF`, // eq. true.
430
430
  `VM` // eq. false.
431
431
  )
432
- useCfOrVm = confirmation
433
- } else useCfOrVm = CircuitContributionVerificationMechanism.VM
432
+ cfOrVm = confirmation
433
+ ? CircuitContributionVerificationMechanism.CF
434
+ : CircuitContributionVerificationMechanism.VM
435
+ } else {
436
+ cfOrVm = CircuitContributionVerificationMechanism.VM
437
+ }
434
438
 
435
- if (useCfOrVm === undefined) showError(COMMAND_ERRORS.COMMAND_ABORT_PROMPT, true)
439
+ if (cfOrVm === undefined) showError(COMMAND_ERRORS.COMMAND_ABORT_PROMPT, true)
436
440
 
437
- if (!useCfOrVm) {
441
+ if (cfOrVm === CircuitContributionVerificationMechanism.VM) {
438
442
  // Ask for selecting the specific VM configuration type.
439
443
  vmConfigurationType = await promptVMTypeSelector(constraintSize)
440
444
 
@@ -478,9 +482,7 @@ export const promptCircuitInputData = async (
478
482
  paramsConfiguration: circuitConfigurationValues
479
483
  },
480
484
  verification: {
481
- cfOrVm: useCfOrVm
482
- ? CircuitContributionVerificationMechanism.CF
483
- : CircuitContributionVerificationMechanism.VM,
485
+ cfOrVm,
484
486
  vm: {
485
487
  vmConfigurationType,
486
488
  vmDiskType
@@ -520,9 +522,7 @@ export const promptCircuitInputData = async (
520
522
  paramsConfiguration: circuitConfigurationValues
521
523
  },
522
524
  verification: {
523
- cfOrVm: useCfOrVm
524
- ? CircuitContributionVerificationMechanism.CF
525
- : CircuitContributionVerificationMechanism.VM,
525
+ cfOrVm,
526
526
  vm: {
527
527
  vmConfigurationType,
528
528
  vmDiskType
@@ -586,7 +586,7 @@ export const promptCircuitAddition = async (): Promise<boolean> => {
586
586
  * Shows a list of pre-computed zKeys for a single option selection.
587
587
  * @dev the names are derived from local zKeys files.
588
588
  * @param options <Array<string>> - an array of pre-computed zKeys names.
589
- * @returns Promise<string> - the name of the choosen pre-computed zKey.
589
+ * @returns Promise<string> - the name of the chosen pre-computed zKey.
590
590
  */
591
591
  export const promptPreComputedZkeySelector = async (options: Array<string>): Promise<string> => {
592
592
  const { preComputedZkeyFilename } = await prompts({
@@ -633,13 +633,13 @@ export const promptNeededPowersForCircuit = async (suggestedSmallestNeededPowers
633
633
  * Shows a list of PoT files for a single option selection.
634
634
  * @dev the names are derived from local PoT files.
635
635
  * @param options <Array<string>> - an array of PoT file names.
636
- * @returns Promise<string> - the name of the choosen PoT.
636
+ * @returns Promise<string> - the name of the chosen PoT.
637
637
  */
638
638
  export const promptPotSelector = async (options: Array<string>): Promise<string> => {
639
639
  const { potFilename } = await prompts({
640
640
  type: "select",
641
641
  name: "potFilename",
642
- message: theme.text.bold("Select the Powers of Tau file choosen for the circuit"),
642
+ message: theme.text.bold("Select the Powers of Tau file chosen for the circuit"),
643
643
  choices: options.map((option: string) => {
644
644
  console.log(option)
645
645
  return { title: option, value: option }
@@ -731,7 +731,7 @@ export const promptToTypeEntropyOrBeacon = async (isEntropy = true): Promise<str
731
731
  * @return <Promise<string>> - the entropy.
732
732
  */
733
733
  export const promptForEntropy = async (): Promise<string> => {
734
- // Prompt for entropy generation prefered method.
734
+ // Prompt for entropy generation preferred method.
735
735
  const { confirmation } = await askForConfirmation(
736
736
  `Do you prefer to type your entropy or generate it randomly?`,
737
737
  "Manually",
@@ -6,13 +6,18 @@ import {
6
6
  import clear from "clear"
7
7
  import figlet from "figlet"
8
8
  import { FirebaseApp } from "firebase/app"
9
- import { OAuthCredential } from "firebase/auth"
9
+ import { OAuthCredential, getAuth, signInWithCustomToken } from "firebase/auth"
10
10
  import dotenv from "dotenv"
11
11
  import { fileURLToPath } from "url"
12
12
  import { dirname } from "path"
13
13
  import { AuthUser } from "../types/index.js"
14
14
  import { CONFIG_ERRORS, CORE_SERVICES_ERRORS, showError, THIRD_PARTY_SERVICES_ERRORS } from "./errors.js"
15
- import { checkLocalAccessToken, deleteLocalAccessToken, getLocalAccessToken } from "./localConfigs.js"
15
+ import {
16
+ checkLocalAccessToken,
17
+ checkLocalBandadaIdentity,
18
+ deleteLocalAccessToken,
19
+ getLocalAccessToken
20
+ } from "./localConfigs.js"
16
21
  import theme from "./theme.js"
17
22
  import { exchangeGithubTokenForCredentials, getGithubProviderUserId, getUserHandleFromProviderUserId } from "./utils.js"
18
23
 
@@ -117,8 +122,6 @@ export const signInToFirebase = async (firebaseApp: FirebaseApp, credentials: OA
117
122
  }
118
123
  }
119
124
 
120
-
121
-
122
125
  /**
123
126
  * Ensure that the callee is an authenticated user.
124
127
  * @notice The token will be passed as parameter.
@@ -166,22 +169,30 @@ export const checkAuth = async (firebaseApp: FirebaseApp): Promise<AuthUser> =>
166
169
  // Retrieve local access token.
167
170
  const token = String(getLocalAccessToken())
168
171
 
169
- // Get credentials.
170
- const credentials = exchangeGithubTokenForCredentials(token)
171
-
172
- // Sign in to Firebase using credentials.
173
- await signInToFirebase(firebaseApp, credentials)
172
+ let providerUserId: string
173
+ let username: string
174
+ const isLocalBandadaIdentityStored = checkLocalBandadaIdentity()
175
+ if (isLocalBandadaIdentityStored) {
176
+ const userCredentials = await signInWithCustomToken(getAuth(), token)
177
+ providerUserId = userCredentials.user.uid
178
+ username = providerUserId
179
+ } else {
180
+ // Get credentials.
181
+ const credentials = exchangeGithubTokenForCredentials(token)
182
+
183
+ // Sign in to Firebase using credentials.
184
+ await signInToFirebase(firebaseApp, credentials)
185
+
186
+ // Get Github unique identifier (handle-id).
187
+ providerUserId = await getGithubProviderUserId(String(token))
188
+ username = getUserHandleFromProviderUserId(providerUserId)
189
+ }
174
190
 
175
191
  // Get current authenticated user.
176
192
  const user = getCurrentFirebaseAuthUser(firebaseApp)
177
193
 
178
- // Get Github unique identifier (handle-id).
179
- const providerUserId = await getGithubProviderUserId(String(token))
180
-
181
194
  // Greet the user.
182
- console.log(
183
- `Greetings, @${theme.text.bold(getUserHandleFromProviderUserId(providerUserId))} ${theme.emojis.wave}\n`
184
- )
195
+ console.log(`Greetings, @${theme.text.bold(username)} ${theme.emojis.wave}\n`)
185
196
 
186
197
  return {
187
198
  user,