@devtion/actions 0.0.0-92056fa → 0.0.0-9239207

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 (36) hide show
  1. package/README.md +1 -1
  2. package/dist/index.mjs +346 -277
  3. package/dist/index.node.js +345 -274
  4. package/dist/types/src/helpers/constants.d.ts +5 -2
  5. package/dist/types/src/helpers/constants.d.ts.map +1 -1
  6. package/dist/types/src/helpers/contracts.d.ts.map +1 -1
  7. package/dist/types/src/helpers/crypto.d.ts +1 -0
  8. package/dist/types/src/helpers/crypto.d.ts.map +1 -1
  9. package/dist/types/src/helpers/database.d.ts +8 -0
  10. package/dist/types/src/helpers/database.d.ts.map +1 -1
  11. package/dist/types/src/helpers/security.d.ts +1 -1
  12. package/dist/types/src/helpers/security.d.ts.map +1 -1
  13. package/dist/types/src/helpers/storage.d.ts +5 -2
  14. package/dist/types/src/helpers/storage.d.ts.map +1 -1
  15. package/dist/types/src/helpers/utils.d.ts +34 -20
  16. package/dist/types/src/helpers/utils.d.ts.map +1 -1
  17. package/dist/types/src/helpers/verification.d.ts +3 -2
  18. package/dist/types/src/helpers/verification.d.ts.map +1 -1
  19. package/dist/types/src/helpers/vm.d.ts.map +1 -1
  20. package/dist/types/src/index.d.ts +2 -2
  21. package/dist/types/src/index.d.ts.map +1 -1
  22. package/dist/types/src/types/index.d.ts +9 -3
  23. package/dist/types/src/types/index.d.ts.map +1 -1
  24. package/package.json +3 -8
  25. package/src/helpers/constants.ts +39 -31
  26. package/src/helpers/contracts.ts +3 -3
  27. package/src/helpers/database.ts +13 -0
  28. package/src/helpers/functions.ts +1 -1
  29. package/src/helpers/security.ts +11 -10
  30. package/src/helpers/services.ts +3 -3
  31. package/src/helpers/storage.ts +15 -3
  32. package/src/helpers/utils.ts +316 -272
  33. package/src/helpers/verification.ts +6 -6
  34. package/src/helpers/vm.ts +18 -7
  35. package/src/index.ts +5 -3
  36. package/src/types/index.ts +32 -8
@@ -1,5 +1,4 @@
1
1
  import { Contract, ContractFactory, Signer } from "ethers"
2
- import { utils as ffUtils } from "ffjavascript"
3
2
  import { Firestore, where } from "firebase/firestore"
4
3
  import { Functions } from "firebase/functions"
5
4
  import fs from "fs"
@@ -16,6 +15,7 @@ import {
16
15
  import { compareHashes } from "./crypto"
17
16
  import { commonTerms, finalContributionIndex, verificationKeyAcronym, verifierSmartContractAcronym } from "./constants"
18
17
  import { fromQueryToFirebaseDocumentInfo, queryCollection } from "./database"
18
+ import { unstringifyBigInts } from "./utils"
19
19
 
20
20
  /**
21
21
  * Formats part of a GROTH16 SNARK proof
@@ -41,11 +41,11 @@ export const p256 = (proofPart: any) => {
41
41
  */
42
42
  export const formatSolidityCalldata = (circuitInput: string[], _proof: any): any => {
43
43
  try {
44
- const proof = ffUtils.unstringifyBigInts(_proof)
44
+ const proof = unstringifyBigInts(_proof) as any
45
45
  // format the public inputs to the circuit
46
46
  const formattedCircuitInput = []
47
47
  for (const cInput of circuitInput) {
48
- formattedCircuitInput.push(p256(ffUtils.unstringifyBigInts(cInput)))
48
+ formattedCircuitInput.push(p256(unstringifyBigInts(cInput)))
49
49
  }
50
50
  // construct calldata
51
51
  const calldata = {
@@ -219,3 +219,16 @@ export const getClosedCeremonies = async (firestoreDatabase: Firestore): Promise
219
219
 
220
220
  return fromQueryToFirebaseDocumentInfo(closedCeremoniesQuerySnap.docs)
221
221
  }
222
+
223
+ /**
224
+ * Query all ceremonies
225
+ * @notice get all ceremonies from the database.
226
+ * @dev this is a helper for the CLI ceremony methods.
227
+ * @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application.
228
+ * @returns <Promise<Array<FirebaseDocumentInfo>>> - the list of all ceremonies.
229
+ */
230
+ export const getAllCeremonies = async (firestoreDatabase: Firestore): Promise<Array<FirebaseDocumentInfo>> => {
231
+ const ceremoniesQuerySnap = await queryCollection(firestoreDatabase, commonTerms.collections.ceremonies.name, [])
232
+
233
+ return fromQueryToFirebaseDocumentInfo(ceremoniesQuerySnap.docs)
234
+ }
@@ -435,4 +435,4 @@ export const finalizeCeremony = async (functions: Functions, ceremonyId: string)
435
435
  await cf({
436
436
  ceremonyId
437
437
  })
438
- }
438
+ }
@@ -1,5 +1,4 @@
1
1
  import fetch from "@adobe/node-fetch-retry"
2
-
3
2
  /**
4
3
  * This function queries the GitHub API to fetch users statistics
5
4
  * @param user {string} the user uid
@@ -12,20 +11,20 @@ const getGitHubStats = async (user: string): Promise<any> => {
12
11
  Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN!}`
13
12
  }
14
13
  })
15
-
16
14
  if (response.status !== 200)
17
15
  throw new Error("It was not possible to retrieve the user's statistic. Please try again.")
18
16
 
19
17
  const jsonData: any = await response.json()
20
18
 
21
- const data = {
19
+ const data = {
22
20
  following: jsonData.following,
23
21
  followers: jsonData.followers,
24
22
  publicRepos: jsonData.public_repos,
25
- avatarUrl: jsonData.avatar_url
23
+ avatarUrl: jsonData.avatar_url,
24
+ age: jsonData.created_at
26
25
  }
27
26
 
28
- return data
27
+ return data
29
28
  }
30
29
 
31
30
  /**
@@ -40,27 +39,29 @@ export const githubReputation = async (
40
39
  userLogin: string,
41
40
  minimumAmountOfFollowing: number,
42
41
  minimumAmountOfFollowers: number,
43
- minimumAmountOfPublicRepos: number
42
+ minimumAmountOfPublicRepos: number,
43
+ minimumAge: number
44
44
  ): Promise<any> => {
45
45
  if (!process.env.GITHUB_ACCESS_TOKEN)
46
46
  throw new Error(
47
47
  "The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again."
48
48
  )
49
49
 
50
- const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin)
50
+ const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin)
51
51
 
52
52
  if (
53
53
  following < minimumAmountOfFollowing ||
54
54
  publicRepos < minimumAmountOfPublicRepos ||
55
- followers < minimumAmountOfFollowers
55
+ followers < minimumAmountOfFollowers ||
56
+ new Date(age) > new Date(Date.now() - minimumAge)
56
57
  )
57
58
  return {
58
59
  reputable: false,
59
60
  avatarUrl: ""
60
61
  }
61
-
62
+
62
63
  return {
63
64
  reputable: true,
64
- avatarUrl: avatarUrl
65
+ avatarUrl
65
66
  }
66
67
  }
@@ -22,7 +22,7 @@ export const getFirestoreDatabase = (app: FirebaseApp): Firestore => getFirestor
22
22
  * @param app <FirebaseApp> - the Firebase application.
23
23
  * @returns <Functions> - the Cloud Functions associated to the application.
24
24
  */
25
- export const getFirebaseFunctions = (app: FirebaseApp): Functions => getFunctions(app, 'europe-west1')
25
+ export const getFirebaseFunctions = (app: FirebaseApp): Functions => getFunctions(app, "europe-west1")
26
26
 
27
27
  /**
28
28
  * Retrieve the configuration variables for the AWS services (S3, EC2).
@@ -33,7 +33,7 @@ export const getAWSVariables = (): AWSVariables => {
33
33
  !process.env.AWS_ACCESS_KEY_ID ||
34
34
  !process.env.AWS_SECRET_ACCESS_KEY ||
35
35
  !process.env.AWS_REGION ||
36
- !process.env.AWS_ROLE_ARN ||
36
+ !process.env.AWS_INSTANCE_PROFILE_ARN ||
37
37
  !process.env.AWS_AMI_ID
38
38
  )
39
39
  throw new Error(
@@ -44,7 +44,7 @@ export const getAWSVariables = (): AWSVariables => {
44
44
  accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
45
45
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
46
46
  region: process.env.AWS_REGION || "us-east-1",
47
- roleArn: process.env.AWS_ROLE_ARN!,
47
+ instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN!,
48
48
  amiId: process.env.AWS_AMI_ID!
49
49
  }
50
50
  }
@@ -3,6 +3,7 @@ import mime from "mime-types"
3
3
  import fs, { createWriteStream } from "fs"
4
4
  import fetch from "@adobe/node-fetch-retry"
5
5
  import https from "https"
6
+ import { GenericBar } from "cli-progress"
6
7
  import { ETagWithPartNumber, ChunkWithUrl, TemporaryParticipantContributionData } from "../types/index"
7
8
  import { commonTerms } from "./constants"
8
9
  import {
@@ -80,6 +81,7 @@ export const getChunksAndPreSignedUrls = async (
80
81
  * @param cloudFunctions <Functions> - the Firebase Cloud Functions service instance.
81
82
  * @param ceremonyId <string> - the unique identifier of the ceremony.
82
83
  * @param alreadyUploadedChunks Array<ETagWithPartNumber> - the temporary information about the already uploaded chunks.
84
+ * @param logger <GenericBar> - an optional logger to show progress.
83
85
  * @returns <Promise<Array<ETagWithPartNumber>>> - the completed (uploaded) chunks information.
84
86
  */
85
87
  export const uploadParts = async (
@@ -87,11 +89,15 @@ export const uploadParts = async (
87
89
  contentType: string | false,
88
90
  cloudFunctions?: Functions,
89
91
  ceremonyId?: string,
90
- alreadyUploadedChunks?: Array<ETagWithPartNumber>
92
+ alreadyUploadedChunks?: Array<ETagWithPartNumber>,
93
+ logger?: GenericBar
91
94
  ): Promise<Array<ETagWithPartNumber>> => {
92
95
  // Keep track of uploaded chunks.
93
96
  const uploadedChunks: Array<ETagWithPartNumber> = alreadyUploadedChunks || []
94
97
 
98
+ // if we were passed a logger, start it
99
+ if (logger) logger.start(chunksWithUrls.length, 0)
100
+
95
101
  // Loop through remaining chunks.
96
102
  for (let i = alreadyUploadedChunks ? alreadyUploadedChunks.length : 0; i < chunksWithUrls.length; i += 1) {
97
103
  // Consume the pre-signed url to upload the chunk.
@@ -128,6 +134,9 @@ export const uploadParts = async (
128
134
  // nb. this must be done only when contributing (not finalizing).
129
135
  if (!!ceremonyId && !!cloudFunctions)
130
136
  await temporaryStoreCurrentContributionUploadedChunkData(cloudFunctions, ceremonyId, chunk)
137
+
138
+ // increment the count on the logger
139
+ if (logger) logger.increment()
131
140
  }
132
141
 
133
142
  return uploadedChunks
@@ -150,6 +159,7 @@ export const uploadParts = async (
150
159
  * @param configStreamChunkSize <number> - size of each chunk into which the artifact is going to be splitted (nb. will be converted in MB).
151
160
  * @param [ceremonyId] <string> - the unique identifier of the ceremony (used as a double-edge sword - as identifier and as a check if current contributor is the coordinator finalizing the ceremony).
152
161
  * @param [temporaryDataToResumeMultiPartUpload] <TemporaryParticipantContributionData> - the temporary information necessary to resume an already started multi-part upload.
162
+ * @param logger <GenericBar> - an optional logger to show progress.
153
163
  */
154
164
  export const multiPartUpload = async (
155
165
  cloudFunctions: Functions,
@@ -158,7 +168,8 @@ export const multiPartUpload = async (
158
168
  localFilePath: string,
159
169
  configStreamChunkSize: number,
160
170
  ceremonyId?: string,
161
- temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData
171
+ temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData,
172
+ logger?: GenericBar
162
173
  ) => {
163
174
  // The unique identifier of the multi-part upload.
164
175
  let multiPartUploadId: string = ""
@@ -198,7 +209,8 @@ export const multiPartUpload = async (
198
209
  mime.lookup(localFilePath), // content-type.
199
210
  cloudFunctions,
200
211
  ceremonyId,
201
- alreadyUploadedChunks
212
+ alreadyUploadedChunks,
213
+ logger
202
214
  )
203
215
 
204
216
  // Step (3).