@devtion/actions 0.0.0-7e983e3

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -0
  3. package/dist/index.mjs +2608 -0
  4. package/dist/index.node.js +2714 -0
  5. package/dist/types/hardhat.config.d.ts +6 -0
  6. package/dist/types/hardhat.config.d.ts.map +1 -0
  7. package/dist/types/src/helpers/authentication.d.ts +21 -0
  8. package/dist/types/src/helpers/authentication.d.ts.map +1 -0
  9. package/dist/types/src/helpers/constants.d.ts +194 -0
  10. package/dist/types/src/helpers/constants.d.ts.map +1 -0
  11. package/dist/types/src/helpers/contracts.d.ts +57 -0
  12. package/dist/types/src/helpers/contracts.d.ts.map +1 -0
  13. package/dist/types/src/helpers/crypto.d.ts +27 -0
  14. package/dist/types/src/helpers/crypto.d.ts.map +1 -0
  15. package/dist/types/src/helpers/database.d.ts +105 -0
  16. package/dist/types/src/helpers/database.d.ts.map +1 -0
  17. package/dist/types/src/helpers/functions.d.ts +145 -0
  18. package/dist/types/src/helpers/functions.d.ts.map +1 -0
  19. package/dist/types/src/helpers/security.d.ts +10 -0
  20. package/dist/types/src/helpers/security.d.ts.map +1 -0
  21. package/dist/types/src/helpers/services.d.ts +38 -0
  22. package/dist/types/src/helpers/services.d.ts.map +1 -0
  23. package/dist/types/src/helpers/storage.d.ts +121 -0
  24. package/dist/types/src/helpers/storage.d.ts.map +1 -0
  25. package/dist/types/src/helpers/tasks.d.ts +2 -0
  26. package/dist/types/src/helpers/tasks.d.ts.map +1 -0
  27. package/dist/types/src/helpers/utils.d.ts +139 -0
  28. package/dist/types/src/helpers/utils.d.ts.map +1 -0
  29. package/dist/types/src/helpers/verification.d.ts +95 -0
  30. package/dist/types/src/helpers/verification.d.ts.map +1 -0
  31. package/dist/types/src/helpers/vm.d.ts +112 -0
  32. package/dist/types/src/helpers/vm.d.ts.map +1 -0
  33. package/dist/types/src/index.d.ts +15 -0
  34. package/dist/types/src/index.d.ts.map +1 -0
  35. package/dist/types/src/types/enums.d.ts +133 -0
  36. package/dist/types/src/types/enums.d.ts.map +1 -0
  37. package/dist/types/src/types/index.d.ts +603 -0
  38. package/dist/types/src/types/index.d.ts.map +1 -0
  39. package/package.json +87 -0
  40. package/src/helpers/authentication.ts +37 -0
  41. package/src/helpers/constants.ts +312 -0
  42. package/src/helpers/contracts.ts +268 -0
  43. package/src/helpers/crypto.ts +55 -0
  44. package/src/helpers/database.ts +221 -0
  45. package/src/helpers/functions.ts +438 -0
  46. package/src/helpers/security.ts +86 -0
  47. package/src/helpers/services.ts +83 -0
  48. package/src/helpers/storage.ts +329 -0
  49. package/src/helpers/tasks.ts +56 -0
  50. package/src/helpers/utils.ts +743 -0
  51. package/src/helpers/verification.ts +354 -0
  52. package/src/helpers/vm.ts +392 -0
  53. package/src/index.ts +162 -0
  54. package/src/types/enums.ts +141 -0
  55. package/src/types/index.ts +650 -0
@@ -0,0 +1,392 @@
1
+ import {
2
+ DescribeInstanceStatusCommand,
3
+ RunInstancesCommand,
4
+ StartInstancesCommand,
5
+ StopInstancesCommand,
6
+ TerminateInstancesCommand,
7
+ EC2Client,
8
+ RunInstancesCommandInput
9
+ } from "@aws-sdk/client-ec2"
10
+ import {
11
+ GetCommandInvocationCommand,
12
+ SSMClient,
13
+ SendCommandCommand,
14
+ SendCommandCommandInput
15
+ } from "@aws-sdk/client-ssm"
16
+ import dotenv from "dotenv"
17
+ import { DiskTypeForVM } from "src"
18
+ import { EC2Instance } from "../types"
19
+ import { convertBytesOrKbToGb } from "./utils"
20
+ import { ec2InstanceTag, powersOfTauFiles, vmBootstrapScriptFilename } from "./constants"
21
+ import { getAWSVariables } from "./services"
22
+
23
+ dotenv.config()
24
+
25
+ /**
26
+ * Create a new AWS EC2 client.
27
+ * @returns <Promise<EC2Client>> - the EC2 client instance.
28
+ */
29
+ export const createEC2Client = async (): Promise<EC2Client> => {
30
+ // Get the AWS variables.
31
+ const { accessKeyId, secretAccessKey, region } = getAWSVariables()
32
+
33
+ // Instantiate the new client.
34
+ return new EC2Client({
35
+ credentials: {
36
+ accessKeyId,
37
+ secretAccessKey
38
+ },
39
+ region
40
+ })
41
+ }
42
+
43
+ /**
44
+ * Create a new AWS SSM client.
45
+ * @returns <Promise<SSMClient>> - the SSM client instance.
46
+ */
47
+ export const createSSMClient = async (): Promise<SSMClient> => {
48
+ // Get the AWS variables.
49
+ const { accessKeyId, secretAccessKey, region } = getAWSVariables()
50
+
51
+ // Instantiate the new client.
52
+ return new SSMClient({
53
+ credentials: {
54
+ accessKeyId,
55
+ secretAccessKey
56
+ },
57
+ region
58
+ })
59
+ }
60
+
61
+ /**
62
+ * Return the list of bootstrap commands to be executed.
63
+ * @dev the startup commands must be suitable for a shell script.
64
+ * @param bucketName <string> - the name of the AWS S3 bucket.
65
+ * @returns <Array<string>> - the list of startup commands to be executed.
66
+ */
67
+ export const vmBootstrapCommand = (bucketName: string): Array<string> => [
68
+ "#!/bin/bash", // shabang.
69
+ `aws s3 cp s3://${bucketName}/${vmBootstrapScriptFilename} ${vmBootstrapScriptFilename}`, // copy file from S3 bucket to VM.
70
+ `chmod +x ${vmBootstrapScriptFilename} && bash ${vmBootstrapScriptFilename}` // grant permission and execute.
71
+ ]
72
+
73
+ /**
74
+ * Return the list of Node environment (and packages) installation plus artifact caching for contribution verification.
75
+ * @param zKeyPath <string> - the path to zKey artifact inside AWS S3 bucket.
76
+ * @param potPath <string> - the path to ptau artifact inside AWS S3 bucket.
77
+ * @param snsTopic <string> - the SNS topic ARN.
78
+ * @param region <string> - the AWS region.
79
+ * @returns <Array<string>> - the array of commands to be run by the EC2 instance.
80
+ */
81
+ export const vmDependenciesAndCacheArtifactsCommand = (
82
+ zKeyPath: string,
83
+ potPath: string,
84
+ snsTopic: string,
85
+ region: string
86
+ ): Array<string> => [
87
+ "#!/bin/bash",
88
+ 'MARKER_FILE="/var/run/my_script_ran"',
89
+ // eslint-disable-next-line no-template-curly-in-string
90
+ "if [ -e ${MARKER_FILE} ]; then",
91
+ "exit 0",
92
+ "else",
93
+ // eslint-disable-next-line no-template-curly-in-string
94
+ "touch ${MARKER_FILE}",
95
+ "sudo yum update -y",
96
+ "curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash - ",
97
+ "sudo yum install -y nodejs",
98
+ "npm install -g snarkjs",
99
+ `aws s3 cp s3://${zKeyPath} /var/tmp/genesisZkey.zkey`,
100
+ `aws s3 cp s3://${potPath} /var/tmp/pot.ptau`,
101
+ "wget https://github.com/BLAKE3-team/BLAKE3/releases/download/1.4.0/b3sum_linux_x64_bin -O /var/tmp/blake3.bin",
102
+ "chmod +x /var/tmp/blake3.bin",
103
+ "INSTANCE_ID=$(ec2-metadata -i | awk '{print $2}')",
104
+ `aws sns publish --topic-arn ${snsTopic} --message "$INSTANCE_ID" --region ${region}`,
105
+ "fi"
106
+ ]
107
+
108
+ /**
109
+ * Return the list of commands for contribution verification.
110
+ * @dev this method generates the verification transcript as well.
111
+ * @param bucketName <string> - the name of the AWS S3 bucket.
112
+ * @param lastZkeyStoragePath <string> - the last zKey storage path.
113
+ * @param verificationTranscriptStoragePathAndFilename <string> - the verification transcript storage path.
114
+ * @returns Array<string> - the list of commands for contribution verification.
115
+ */
116
+ export const vmContributionVerificationCommand = (
117
+ bucketName: string,
118
+ lastZkeyStoragePath: string,
119
+ verificationTranscriptStoragePathAndFilename: string
120
+ ): Array<string> => [
121
+ `aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey > /var/tmp/log.txt`,
122
+ `snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey > /var/tmp/verification_transcript.log`,
123
+ `aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} &>/dev/null`,
124
+ `/var/tmp/blake3.bin /var/tmp/verification_transcript.log | awk '{print $1}'`,
125
+ `rm /var/tmp/lastZKey.zkey /var/tmp/verification_transcript.log /var/tmp/log.txt &>/dev/null`
126
+ ]
127
+
128
+ /**
129
+ * Compute the VM disk size.
130
+ * @dev the disk size is computed using the zKey size in bytes taking into consideration
131
+ * the verification task (2 * zKeySize) + ptauSize + OS/VM (~8GB).
132
+ * @param zKeySizeInBytes <number> the size of the zKey in bytes.
133
+ * @param pot <number> the amount of powers needed for the circuit (index of the PPoT file).
134
+ * @return <number> the configuration of the VM disk size in GB.
135
+ */
136
+ export const computeDiskSizeForVM = (zKeySizeInBytes: number, pot: number): number =>
137
+ Math.ceil(2 * convertBytesOrKbToGb(zKeySizeInBytes, true) + powersOfTauFiles[pot - 1].size) + 8
138
+
139
+ /**
140
+ * Creates a new EC2 instance
141
+ * @param ec2 <EC2Client> - the instance of the EC2 client.
142
+ * @param commands <Array<string>> - the list of commands to be run on the EC2 instance.
143
+ * @param instanceType <string> - the type of the EC2 VM instance.
144
+ * @param diskSize <number> - the size of the disk (volume) of the VM.
145
+ * @param diskType <DiskTypeForVM> - the type of the disk (volume) of the VM.
146
+ * @returns <Promise<P0tionEC2Instance>> the instance that was created
147
+ */
148
+ export const createEC2Instance = async (
149
+ ec2: EC2Client,
150
+ commands: string[],
151
+ instanceType: string,
152
+ volumeSize: number,
153
+ diskType: DiskTypeForVM
154
+ ): Promise<EC2Instance> => {
155
+ // Get the AWS variables.
156
+ const { amiId, roleArn } = getAWSVariables()
157
+
158
+ // Parametrize the VM EC2 instance.
159
+ const params: RunInstancesCommandInput = {
160
+ ImageId: amiId,
161
+ InstanceType: instanceType,
162
+ MaxCount: 1,
163
+ MinCount: 1,
164
+ // nb. to find this: iam -> roles -> role_name.
165
+ IamInstanceProfile: {
166
+ Arn: roleArn
167
+ },
168
+ // nb. for running commands at the startup.
169
+ UserData: Buffer.from(commands.join("\n")).toString("base64"),
170
+ BlockDeviceMappings: [
171
+ {
172
+ DeviceName: "/dev/xvda",
173
+ Ebs: {
174
+ DeleteOnTermination: true,
175
+ VolumeSize: volumeSize, // disk size in GB.
176
+ VolumeType: diskType
177
+ }
178
+ }
179
+ ],
180
+ // tag the resource
181
+ TagSpecifications: [
182
+ {
183
+ ResourceType: "instance",
184
+ Tags: [
185
+ {
186
+ Key: "Name",
187
+ Value: ec2InstanceTag
188
+ },
189
+ {
190
+ Key: "Initialized",
191
+ Value: "false"
192
+ }
193
+ ]
194
+ }
195
+ ]
196
+ }
197
+
198
+ try {
199
+ // Create a new command instance.
200
+ const command = new RunInstancesCommand(params)
201
+ // Send the command for execution.
202
+ const response = await ec2.send(command)
203
+
204
+ if (response.$metadata.httpStatusCode !== 200)
205
+ throw new Error(`Something went wrong when creating the EC2 instance. More details ${response}`)
206
+
207
+ // Create a new EC2 VM instance.
208
+ return {
209
+ instanceId: response.Instances![0].InstanceId!,
210
+ imageId: response.Instances![0].ImageId!,
211
+ instanceType: response.Instances![0].InstanceType!,
212
+ keyName: response.Instances![0].KeyName!,
213
+ launchTime: response.Instances![0].LaunchTime!.toISOString()
214
+ }
215
+ } catch (error: any) {
216
+ throw new Error(`Something went wrong when creating the EC2 instance. More details ${error}`)
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Check if the current VM EC2 instance is running by querying the status.
222
+ * @param ec2 <EC2Client> - the instance of the EC2 client.
223
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
224
+ * @returns <Promise<boolean>> - true if the current status of the EC2 VM instance is 'running'; otherwise false.
225
+ */
226
+ export const checkIfRunning = async (ec2Client: EC2Client, instanceId: string): Promise<boolean> => {
227
+ // Generate a new describe status command.
228
+ const command = new DescribeInstanceStatusCommand({
229
+ InstanceIds: [instanceId]
230
+ })
231
+
232
+ // Run the command.
233
+ const response = await ec2Client.send(command)
234
+
235
+ if (response.$metadata.httpStatusCode !== 200)
236
+ throw new Error(
237
+ `Something went wrong when retrieving the EC2 instance (${instanceId}) status. More details ${response}`
238
+ )
239
+
240
+ return response.InstanceStatuses![0].InstanceState!.Name === "running"
241
+ }
242
+
243
+ /**
244
+ * Start an EC2 VM instance.
245
+ * @dev the instance must have been created previously.
246
+ * @param ec2 <EC2Client> - the instance of the EC2 client.
247
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
248
+ */
249
+ export const startEC2Instance = async (ec2: EC2Client, instanceId: string) => {
250
+ // Generate a new start instance command.
251
+ const command = new StartInstancesCommand({
252
+ InstanceIds: [instanceId],
253
+ DryRun: false
254
+ })
255
+
256
+ // Run the command.
257
+ const response = await ec2.send(command)
258
+
259
+ if (response.$metadata.httpStatusCode !== 200)
260
+ throw new Error(`Something went wrong when starting the EC2 instance (${instanceId}). More details ${response}`)
261
+ }
262
+
263
+ /**
264
+ * Stop an EC2 VM instance.
265
+ * @dev the instance must have been in a running status.
266
+ * @param ec2 <EC2Client> - the instance of the EC2 client.
267
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
268
+ */
269
+ export const stopEC2Instance = async (ec2: EC2Client, instanceId: string) => {
270
+ // Generate a new stop instance command.
271
+ const command = new StopInstancesCommand({
272
+ InstanceIds: [instanceId],
273
+ DryRun: false
274
+ })
275
+
276
+ // Run the command.
277
+ const response = await ec2.send(command)
278
+
279
+ if (response.$metadata.httpStatusCode !== 200)
280
+ throw new Error(`Something went wrong when stopping the EC2 instance (${instanceId}). More details ${response}`)
281
+ }
282
+
283
+ /**
284
+ * Terminate an EC2 VM instance.
285
+ * @param ec2 <EC2Client> - the instance of the EC2 client.
286
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
287
+ */
288
+ export const terminateEC2Instance = async (ec2: EC2Client, instanceId: string) => {
289
+ // Generate a new terminate instance command.
290
+ const command = new TerminateInstancesCommand({
291
+ InstanceIds: [instanceId],
292
+ DryRun: false
293
+ })
294
+
295
+ // Run the command.
296
+ const response = await ec2.send(command)
297
+
298
+ if (response.$metadata.httpStatusCode !== 200)
299
+ throw new Error(
300
+ `Something went wrong when terminating the EC2 instance (${instanceId}). More details ${response}`
301
+ )
302
+ }
303
+
304
+ /**
305
+ * Run a command on an EC2 VM instance by using SSM.
306
+ * @dev this method returns the command identifier for checking the status and retrieve
307
+ * the output of the command execution later on.
308
+ * @param ssm <SSMClient> - the instance of the sSM client.
309
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
310
+ * @param commands <Array<string>> - the list of commands.
311
+ * @return <Promise<string>> - the unique identifier of the command.
312
+ */
313
+ export const runCommandUsingSSM = async (
314
+ ssm: SSMClient,
315
+ instanceId: string,
316
+ commands: Array<string>
317
+ ): Promise<string> => {
318
+ // Generate a new send command input command.
319
+ const params: SendCommandCommandInput = {
320
+ DocumentName: "AWS-RunShellScript",
321
+ InstanceIds: [instanceId],
322
+ Parameters: {
323
+ commands
324
+ },
325
+ TimeoutSeconds: 1200
326
+ }
327
+
328
+ try {
329
+ // Run the command.
330
+ const response = await ssm.send(new SendCommandCommand(params))
331
+
332
+ // if (response.$metadata.httpStatusCode !== 200)
333
+ // throw new Error(
334
+ // `Something went wrong when trying to run a command on the EC2 instance (${instanceId}). More details ${response}`
335
+ // )
336
+
337
+ return response.Command!.CommandId!
338
+ } catch (error: any) {
339
+ throw new Error(`Something went wrong when trying to run a command on the EC2 instance. More details ${error}`)
340
+ }
341
+ }
342
+
343
+ /**
344
+ * Get the output of an SSM command executed on an EC2 VM instance.
345
+ * @param ssm <SSMClient> - the instance of the sSM client.
346
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
347
+ * @param commandId <string> - the unique identifier of the command.
348
+ * @return <Promise<string>> - the command output.
349
+ */
350
+ export const retrieveCommandOutput = async (ssm: SSMClient, instanceId: string, commandId: string): Promise<string> => {
351
+ // Generate a new get command invocation command.
352
+ const command = new GetCommandInvocationCommand({
353
+ CommandId: commandId,
354
+ InstanceId: instanceId
355
+ })
356
+
357
+ try {
358
+ // Run the command.
359
+ const response = await ssm.send(command)
360
+
361
+ return response.StandardOutputContent!
362
+ } catch (error: any) {
363
+ throw new Error(
364
+ `Something went wrong when trying to retrieve the command ${commandId} output on the EC2 instance (${instanceId}). More details ${error}`
365
+ )
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Get the status of an SSM command executed on an EC2 VM instance.
371
+ * @param ssm <SSMClient> - the instance of the sSM client.
372
+ * @param instanceId <string> - the unique identifier of the EC2 VM instance.
373
+ * @param commandId <string> - the unique identifier of the command.
374
+ * @return <Promise<string>> - the command status.
375
+ */
376
+ export const retrieveCommandStatus = async (ssm: SSMClient, instanceId: string, commandId: string): Promise<string> => {
377
+ // Generate a new get command invocation command.
378
+ const command = new GetCommandInvocationCommand({
379
+ CommandId: commandId,
380
+ InstanceId: instanceId
381
+ })
382
+
383
+ try {
384
+ // Run the command.
385
+ const response = await ssm.send(command)
386
+ return response.Status!
387
+ } catch (error: any) {
388
+ throw new Error(
389
+ `Something went wrong when trying to retrieve the command ${commandId} status on the EC2 instance (${instanceId}). More details ${error}`
390
+ )
391
+ }
392
+ }
package/src/index.ts ADDED
@@ -0,0 +1,162 @@
1
+ export {
2
+ downloadCeremonyArtifact,
3
+ getBucketName,
4
+ multiPartUpload,
5
+ getR1csStorageFilePath,
6
+ getPotStorageFilePath,
7
+ getZkeyStorageFilePath,
8
+ getVerificationKeyStorageFilePath,
9
+ getVerifierContractStorageFilePath,
10
+ getTranscriptStorageFilePath,
11
+ getWasmStorageFilePath
12
+ } from "./helpers/storage"
13
+ export {
14
+ queryCollection,
15
+ fromQueryToFirebaseDocumentInfo,
16
+ getAllCollectionDocs,
17
+ getCircuitContributionsFromContributor,
18
+ getDocumentById,
19
+ getCurrentActiveParticipantTimeout,
20
+ getClosedCeremonies,
21
+ getParticipantsCollectionPath,
22
+ getCircuitsCollectionPath,
23
+ getContributionsCollectionPath,
24
+ getTimeoutsCollectionPath,
25
+ getOpenedCeremonies,
26
+ getCeremonyCircuits
27
+ } from "./helpers/database"
28
+ export {
29
+ compareCeremonyArtifacts,
30
+ downloadAllCeremonyArtifacts,
31
+ exportVerifierAndVKey,
32
+ exportVerifierContract,
33
+ exportVkey,
34
+ generateGROTH16Proof,
35
+ generateZkeyFromScratch,
36
+ verifyGROTH16Proof,
37
+ verifyZKey
38
+ } from "./helpers/verification"
39
+ export { initializeFirebaseCoreServices } from "./helpers/services"
40
+ export { signInToFirebaseWithCredentials, getCurrentFirebaseAuthUser, isCoordinator } from "./helpers/authentication"
41
+ export {
42
+ commonTerms,
43
+ potFileDownloadMainUrl,
44
+ potFilenameTemplate,
45
+ genesisZkeyIndex,
46
+ numExpIterations,
47
+ solidityVersion,
48
+ finalContributionIndex,
49
+ verificationKeyAcronym,
50
+ verifierSmartContractAcronym,
51
+ ec2InstanceTag,
52
+ vmConfigurationTypes,
53
+ vmBootstrapScriptFilename,
54
+ powersOfTauFiles
55
+ } from "./helpers/constants"
56
+ export {
57
+ extractPrefix,
58
+ extractPoTFromFilename,
59
+ extractR1CSInfoValueForGivenKey,
60
+ formatZkeyIndex,
61
+ autoGenerateEntropy,
62
+ getCircuitBySequencePosition,
63
+ convertBytesOrKbToGb,
64
+ getPublicAttestationPreambleForContributor,
65
+ getContributionsValidityForContributor,
66
+ generateValidContributionsAttestation,
67
+ createCustomLoggerForFile,
68
+ getR1CSInfo,
69
+ computeSmallestPowersOfTauForCircuit,
70
+ convertToDoubleDigits,
71
+ parseCeremonyFile
72
+ } from "./helpers/utils"
73
+ export {
74
+ setupCeremony,
75
+ checkParticipantForCeremony,
76
+ progressToNextCircuitForContribution,
77
+ resumeContributionAfterTimeoutExpiration,
78
+ createS3Bucket,
79
+ generateGetObjectPreSignedUrl,
80
+ progressToNextContributionStep,
81
+ permanentlyStoreCurrentContributionTimeAndHash,
82
+ temporaryStoreCurrentContributionMultiPartUploadId,
83
+ temporaryStoreCurrentContributionUploadedChunkData,
84
+ generatePreSignedUrlsParts,
85
+ completeMultiPartUpload,
86
+ checkIfObjectExist,
87
+ verifyContribution,
88
+ checkAndPrepareCoordinatorForFinalization,
89
+ finalizeCircuit,
90
+ finalizeCeremony
91
+ } from "./helpers/functions"
92
+ export { toHex, blake512FromPath, computeSHA256ToHex, compareHashes } from "./helpers/crypto"
93
+ export {
94
+ compileContract,
95
+ verifyCeremony,
96
+ p256,
97
+ verifyGROTH16ProofOnChain,
98
+ formatSolidityCalldata
99
+ } from "./helpers/contracts"
100
+ export { githubReputation } from "./helpers/security"
101
+ export {
102
+ CeremonyState,
103
+ CeremonyType,
104
+ CeremonyTimeoutType,
105
+ ParticipantStatus,
106
+ ParticipantContributionStep,
107
+ TimeoutType,
108
+ RequestType,
109
+ TestingEnvironment,
110
+ CircuitContributionVerificationMechanism,
111
+ DiskTypeForVM
112
+ } from "./types/enums"
113
+ export {
114
+ FirebaseDocumentInfo,
115
+ ChunkWithUrl,
116
+ ETagWithPartNumber,
117
+ ContributionValidity,
118
+ UserDocument,
119
+ CeremonyInputData,
120
+ CircomCompilerData,
121
+ SourceTemplateData,
122
+ CompilationArtifacts,
123
+ CircuitInputData,
124
+ CeremonyDocument,
125
+ Contribution,
126
+ TemporaryParticipantContributionData,
127
+ ParticipantDocument,
128
+ CircuitMetadata,
129
+ CircuitArtifacts,
130
+ CircuitTimings,
131
+ CircuitWaitingQueue,
132
+ CircuitDocument,
133
+ ContributionFiles,
134
+ ContributionVerificationSoftware,
135
+ BeaconInfo,
136
+ ContributionDocument,
137
+ CircuitDocumentReferenceAndData,
138
+ UserDocumentReferenceAndData,
139
+ CeremonyDocumentReferenceAndData,
140
+ ParticipantDocumentReferenceAndData,
141
+ CeremonyArtifacts,
142
+ ContributionDocumentReferenceAndData,
143
+ FirebaseServices,
144
+ VMConfigurationType,
145
+ AWSVariables
146
+ } from "./types/index"
147
+ export {
148
+ createEC2Instance,
149
+ terminateEC2Instance,
150
+ stopEC2Instance,
151
+ startEC2Instance,
152
+ checkIfRunning,
153
+ vmBootstrapCommand,
154
+ vmDependenciesAndCacheArtifactsCommand,
155
+ retrieveCommandOutput,
156
+ computeDiskSizeForVM,
157
+ createSSMClient,
158
+ runCommandUsingSSM,
159
+ createEC2Client,
160
+ vmContributionVerificationCommand,
161
+ retrieveCommandStatus
162
+ } from "./helpers/vm"
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Define different states of a ceremony.
3
+ * @enum {string}
4
+ * - SCHEDULED: when the ceremony setup has been properly completed but the contribution period has not yet started.
5
+ * - OPENED: when the contribution period has started.
6
+ * - PAUSED: When the coordinator has manually paused the ceremony (NB. currently not possible because the relevant functionality has not yet been implemented).
7
+ * - CLOSED: when the contribution period has finished.
8
+ * - FINALIZED: when the ceremony finalization has been properly completed.
9
+ */
10
+ export const enum CeremonyState {
11
+ SCHEDULED = "SCHEDULED",
12
+ OPENED = "OPENED",
13
+ PAUSED = "PAUSED",
14
+ CLOSED = "CLOSED",
15
+ FINALIZED = "FINALIZED"
16
+ }
17
+
18
+ /**
19
+ * Define the type of Trusted Setup ceremony (Phase 1 or Phase 2).
20
+ * @enum {string}
21
+ * - PHASE1: when the ceremony is a Phase 1 Trusted Setup ceremony.
22
+ * - PHASE2: when the ceremony is a Phase 2 Trusted Setup ceremony.
23
+ */
24
+ export const enum CeremonyType {
25
+ PHASE1 = "PHASE1",
26
+ PHASE2 = "PHASE2"
27
+ }
28
+
29
+ /**
30
+ * Define different status of a participant.
31
+ * @enum {string}
32
+ * - CREATED: when the participant document has been created in the database.
33
+ * - WAITING: when the participant is waiting for a contribution (i.e., is currently queued or is waiting for its status to be checked after a timeout expiration).
34
+ * - READY: when the participant is ready for a contribution.
35
+ * - CONTRIBUTING: when the participant is currently contributing (i.e., not queued anymore, but the current contributor at this time).
36
+ * - CONTRIBUTED: when the participant has completed successfully the contribution for all circuits in a ceremony. The participant may need to wait for the latest contribution verification while having this status.
37
+ * - DONE: when the participant has completed contributions and verifications from coordinator.
38
+ * - FINALIZING: when the coordinator is currently finalizing the ceremony.
39
+ * - FINALIZED: when the coordinator has successfully finalized the ceremony.
40
+ * - TIMEDOUT: when the participant has been timedout while contributing. This may happen due to network or memory issues, un/intentional crash, or contributions lasting for too long.
41
+ * - EXHUMED: when the participant is ready to resume the contribution after a timeout expiration.
42
+ */
43
+ export const enum ParticipantStatus {
44
+ CREATED = "CREATED",
45
+ WAITING = "WAITING",
46
+ READY = "READY",
47
+ CONTRIBUTING = "CONTRIBUTING",
48
+ CONTRIBUTED = "CONTRIBUTED",
49
+ DONE = "DONE",
50
+ FINALIZING = "FINALIZING",
51
+ FINALIZED = "FINALIZED",
52
+ TIMEDOUT = "TIMEDOUT",
53
+ EXHUMED = "EXHUMED"
54
+ }
55
+
56
+ /**
57
+ * Define different steps during which the participant may be during the contribution.
58
+ * @enum {string}
59
+ * - DOWNLOADING: when the participant is doing the download of the last contribution (from previous participant).
60
+ * - COMPUTING: when the participant is actively computing the contribution.
61
+ * - UPLOADING: when the participant is uploading the computed contribution.
62
+ * - VERIFYING: when the participant is waiting from verification results from the coordinator.
63
+ * - COMPLETED: when the participant has received the verification results from the coordinator and completed the contribution steps.
64
+ */
65
+ export const enum ParticipantContributionStep {
66
+ DOWNLOADING = "DOWNLOADING",
67
+ COMPUTING = "COMPUTING",
68
+ UPLOADING = "UPLOADING",
69
+ VERIFYING = "VERIFYING",
70
+ COMPLETED = "COMPLETED"
71
+ }
72
+
73
+ /**
74
+ * Define what type of timeout was performed.
75
+ * @enum {string}
76
+ * - BLOCKING_CONTRIBUTION: when the current contributor was blocking the waiting queue.
77
+ * - BLOCKING_CLOUD_FUNCTION: when the contribution verification has gone beyond the time limit.
78
+ */
79
+ export const enum TimeoutType {
80
+ BLOCKING_CONTRIBUTION = "BLOCKING_CONTRIBUTION",
81
+ BLOCKING_CLOUD_FUNCTION = "BLOCKING_CLOUD_FUNCTION"
82
+ }
83
+
84
+ /**
85
+ * Define what type of timeout mechanism is currently adopted for a ceremony.
86
+ * @enum {string}
87
+ * - DYNAMIC: self-update approach based on latest contribution time.
88
+ * - FIXED: approach based on a fixed amount of time.
89
+ */
90
+ export const enum CeremonyTimeoutType {
91
+ DYNAMIC = "DYNAMIC",
92
+ FIXED = "FIXED"
93
+ }
94
+
95
+ /**
96
+ * Define request type for pre-signed urls.
97
+ */
98
+ export const enum RequestType {
99
+ PUT = "PUT",
100
+ GET = "GET"
101
+ }
102
+
103
+ /**
104
+ * Define the environment in use when testing.
105
+ * @enum {string}
106
+ * - DEVELOPMENT: tests are performed on the local Firebase emulator instance.
107
+ * - PRODUCTION: tests are performed on the remote (deployed) Firebase application.
108
+ */
109
+ export const enum TestingEnvironment {
110
+ DEVELOPMENT = "DEVELOPMENT",
111
+ PRODUCTION = "PRODUCTION"
112
+ }
113
+
114
+ /**
115
+ * Define what type of contribution verification mechanism is currently adopted for a circuit.
116
+ * @enum {string}
117
+ * - CF: Cloud Functions.
118
+ * - VM: Virtual Machine.
119
+ */
120
+ export const enum CircuitContributionVerificationMechanism {
121
+ CF = "CF",
122
+ VM = "VM"
123
+ }
124
+
125
+ /**
126
+ * Define the supported VM volume types.
127
+ * @dev the VM volume types can be retrieved at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html
128
+ * @enum {string}
129
+ * - GP2: General Purpose SSD version 2.
130
+ * - GP3: General Purpose SSD version 3.
131
+ * - IO1: Provisioned IOPS SSD volumes version 1.
132
+ * - ST1: Throughput Optimized HDD volumes.
133
+ * - SC1: Cold HDD volumes.
134
+ */
135
+ export const enum DiskTypeForVM {
136
+ GP2 = "gp2",
137
+ GP3 = "gp3",
138
+ IO1 = "io1",
139
+ ST1 = "st1",
140
+ SC1 = "sc1"
141
+ }