@devtion/backend 0.0.0-b499eaf → 0.0.0-bbc217a
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/src/functions/index.js +277 -29
- package/dist/src/functions/index.mjs +277 -31
- package/dist/types/functions/bandada.d.ts +4 -0
- package/dist/types/functions/bandada.d.ts.map +1 -0
- package/dist/types/functions/index.d.ts +2 -0
- package/dist/types/functions/index.d.ts.map +1 -1
- package/dist/types/functions/siwe.d.ts +4 -0
- package/dist/types/functions/siwe.d.ts.map +1 -0
- package/dist/types/functions/timeout.d.ts.map +1 -1
- package/dist/types/lib/errors.d.ts +1 -1
- package/dist/types/lib/services.d.ts +7 -0
- package/dist/types/lib/services.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +56 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/functions/bandada.ts +155 -0
- package/src/functions/ceremony.ts +4 -4
- package/src/functions/circuit.ts +3 -3
- package/src/functions/index.ts +2 -0
- package/src/functions/participant.ts +7 -7
- package/src/functions/siwe.ts +77 -0
- package/src/functions/storage.ts +6 -6
- package/src/functions/timeout.ts +4 -3
- package/src/functions/user.ts +4 -4
- package/src/lib/errors.ts +1 -1
- package/src/lib/services.ts +36 -0
- package/src/types/declarations.d.ts +1 -0
- package/src/types/index.ts +60 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @p0tion/backend
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.2.4
|
|
4
4
|
* @file MPC Phase 2 backend for Firebase services management
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -25,10 +25,13 @@ import path from 'path';
|
|
|
25
25
|
import os from 'os';
|
|
26
26
|
import { SSMClient, CommandInvocationStatus } from '@aws-sdk/client-ssm';
|
|
27
27
|
import { EC2Client } from '@aws-sdk/client-ec2';
|
|
28
|
+
import ethers from 'ethers';
|
|
28
29
|
import * as functionsV1 from 'firebase-functions/v1';
|
|
29
30
|
import * as functionsV2 from 'firebase-functions/v2';
|
|
30
31
|
import { Timer } from 'timer-node';
|
|
31
|
-
import { zKey } from 'snarkjs';
|
|
32
|
+
import { zKey, groth16 } from 'snarkjs';
|
|
33
|
+
import { ApiSdk } from '@bandada/api-sdk';
|
|
34
|
+
import { getAuth } from 'firebase-admin/auth';
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Log levels.
|
|
@@ -49,7 +52,7 @@ var LogLevel;
|
|
|
49
52
|
* @notice the set of Firebase Functions status codes. The codes are the same at the
|
|
50
53
|
* ones exposed by {@link https://github.com/grpc/grpc/blob/master/doc/statuscodes.md | gRPC}.
|
|
51
54
|
* @param errorCode <FunctionsErrorCode> - the set of possible error codes.
|
|
52
|
-
* @param message <string> - the error
|
|
55
|
+
* @param message <string> - the error message.
|
|
53
56
|
* @param [details] <string> - the details of the error (optional).
|
|
54
57
|
* @returns <HttpsError>
|
|
55
58
|
*/
|
|
@@ -141,6 +144,8 @@ const COMMON_ERRORS = {
|
|
|
141
144
|
CM_INVALID_COMMAND_EXECUTION: makeError("unknown", "There was an error while executing the command on the VM", "Please, contact the coordinator if the error persists.")
|
|
142
145
|
};
|
|
143
146
|
|
|
147
|
+
dotenv.config();
|
|
148
|
+
let provider;
|
|
144
149
|
/**
|
|
145
150
|
* Return a configured and connected instance of the AWS S3 client.
|
|
146
151
|
* @dev this method check and utilize the environment variables to configure the connection
|
|
@@ -163,6 +168,36 @@ const getS3Client = async () => {
|
|
|
163
168
|
region: process.env.AWS_REGION
|
|
164
169
|
});
|
|
165
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Returns a Prvider, connected via a configured JSON URL or else
|
|
173
|
+
* the ethers.js default provider, using configured API keys.
|
|
174
|
+
* @returns <ethers.providers.Provider> An Eth node provider
|
|
175
|
+
*/
|
|
176
|
+
const setEthProvider = () => {
|
|
177
|
+
if (provider)
|
|
178
|
+
return provider;
|
|
179
|
+
console.log(`setting new provider`);
|
|
180
|
+
// Use JSON URL if defined
|
|
181
|
+
// if ((hardhat as any).ethers) {
|
|
182
|
+
// console.log(`using hardhat.ethers provider`)
|
|
183
|
+
// provider = (hardhat as any).ethers.provider
|
|
184
|
+
// } else
|
|
185
|
+
if (process.env.ETH_PROVIDER_JSON_URL) {
|
|
186
|
+
console.log(`JSON URL provider at ${process.env.ETH_PROVIDER_JSON_URL}`);
|
|
187
|
+
provider = new ethers.providers.JsonRpcProvider({
|
|
188
|
+
url: process.env.ETH_PROVIDER_JSON_URL,
|
|
189
|
+
skipFetchSetup: true
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Otherwise, connect the default provider with ALchemy, Infura, or both
|
|
194
|
+
provider = ethers.providers.getDefaultProvider("homestead", {
|
|
195
|
+
alchemy: process.env.ETH_PROVIDER_ALCHEMY_API_KEY,
|
|
196
|
+
infura: process.env.ETH_PROVIDER_INFURA_API_KEY
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return provider;
|
|
200
|
+
};
|
|
166
201
|
|
|
167
202
|
dotenv.config();
|
|
168
203
|
/**
|
|
@@ -501,7 +536,7 @@ dotenv.config();
|
|
|
501
536
|
const registerAuthUser = functions
|
|
502
537
|
.region("europe-west1")
|
|
503
538
|
.runWith({
|
|
504
|
-
memory: "
|
|
539
|
+
memory: "1GB"
|
|
505
540
|
})
|
|
506
541
|
.auth.user()
|
|
507
542
|
.onCreate(async (user) => {
|
|
@@ -533,7 +568,7 @@ const registerAuthUser = functions
|
|
|
533
568
|
email === process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN)) {
|
|
534
569
|
const auth = admin.auth();
|
|
535
570
|
// if provider == github.com let's use our functions to check the user's reputation
|
|
536
|
-
if (user.providerData[0].providerId === "github.com") {
|
|
571
|
+
if (user.providerData.length > 0 && user.providerData[0].providerId === "github.com") {
|
|
537
572
|
const vars = getGitHubVariables();
|
|
538
573
|
// this return true or false
|
|
539
574
|
try {
|
|
@@ -565,7 +600,7 @@ const registerAuthUser = functions
|
|
|
565
600
|
encodedDisplayName,
|
|
566
601
|
// Metadata.
|
|
567
602
|
creationTime,
|
|
568
|
-
lastSignInTime,
|
|
603
|
+
lastSignInTime: lastSignInTime || creationTime,
|
|
569
604
|
// Optional.
|
|
570
605
|
email: email || "",
|
|
571
606
|
emailVerified: emailVerified || false,
|
|
@@ -588,7 +623,7 @@ const registerAuthUser = functions
|
|
|
588
623
|
const processSignUpWithCustomClaims = functions
|
|
589
624
|
.region("europe-west1")
|
|
590
625
|
.runWith({
|
|
591
|
-
memory: "
|
|
626
|
+
memory: "1GB"
|
|
592
627
|
})
|
|
593
628
|
.auth.user()
|
|
594
629
|
.onCreate(async (user) => {
|
|
@@ -629,7 +664,7 @@ dotenv.config();
|
|
|
629
664
|
const startCeremony = functions
|
|
630
665
|
.region("europe-west1")
|
|
631
666
|
.runWith({
|
|
632
|
-
memory: "
|
|
667
|
+
memory: "1GB"
|
|
633
668
|
})
|
|
634
669
|
.pubsub.schedule(`every 30 minutes`)
|
|
635
670
|
.onRun(async () => {
|
|
@@ -651,7 +686,7 @@ const startCeremony = functions
|
|
|
651
686
|
const stopCeremony = functions
|
|
652
687
|
.region("europe-west1")
|
|
653
688
|
.runWith({
|
|
654
|
-
memory: "
|
|
689
|
+
memory: "1GB"
|
|
655
690
|
})
|
|
656
691
|
.pubsub.schedule(`every 30 minutes`)
|
|
657
692
|
.onRun(async () => {
|
|
@@ -673,7 +708,7 @@ const stopCeremony = functions
|
|
|
673
708
|
const setupCeremony = functions
|
|
674
709
|
.region("europe-west1")
|
|
675
710
|
.runWith({
|
|
676
|
-
memory: "
|
|
711
|
+
memory: "1GB"
|
|
677
712
|
})
|
|
678
713
|
.https.onCall(async (data, context) => {
|
|
679
714
|
// Check if the user has the coordinator claim.
|
|
@@ -798,7 +833,7 @@ const initEmptyWaitingQueueForCircuit = functions
|
|
|
798
833
|
const finalizeCeremony = functions
|
|
799
834
|
.region("europe-west1")
|
|
800
835
|
.runWith({
|
|
801
|
-
memory: "
|
|
836
|
+
memory: "1GB"
|
|
802
837
|
})
|
|
803
838
|
.https.onCall(async (data, context) => {
|
|
804
839
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -874,7 +909,7 @@ dotenv.config();
|
|
|
874
909
|
const checkParticipantForCeremony = functions
|
|
875
910
|
.region("europe-west1")
|
|
876
911
|
.runWith({
|
|
877
|
-
memory: "
|
|
912
|
+
memory: "1GB"
|
|
878
913
|
})
|
|
879
914
|
.https.onCall(async (data, context) => {
|
|
880
915
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -978,7 +1013,7 @@ const checkParticipantForCeremony = functions
|
|
|
978
1013
|
const progressToNextCircuitForContribution = functions
|
|
979
1014
|
.region("europe-west1")
|
|
980
1015
|
.runWith({
|
|
981
|
-
memory: "
|
|
1016
|
+
memory: "1GB"
|
|
982
1017
|
})
|
|
983
1018
|
.https.onCall(async (data, context) => {
|
|
984
1019
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1025,7 +1060,7 @@ const progressToNextCircuitForContribution = functions
|
|
|
1025
1060
|
const progressToNextContributionStep = functions
|
|
1026
1061
|
.region("europe-west1")
|
|
1027
1062
|
.runWith({
|
|
1028
|
-
memory: "
|
|
1063
|
+
memory: "1GB"
|
|
1029
1064
|
})
|
|
1030
1065
|
.https.onCall(async (data, context) => {
|
|
1031
1066
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1076,7 +1111,7 @@ const progressToNextContributionStep = functions
|
|
|
1076
1111
|
const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
1077
1112
|
.region("europe-west1")
|
|
1078
1113
|
.runWith({
|
|
1079
|
-
memory: "
|
|
1114
|
+
memory: "1GB"
|
|
1080
1115
|
})
|
|
1081
1116
|
.https.onCall(async (data, context) => {
|
|
1082
1117
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1118,7 +1153,7 @@ const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
|
1118
1153
|
const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
1119
1154
|
.region("europe-west1")
|
|
1120
1155
|
.runWith({
|
|
1121
|
-
memory: "
|
|
1156
|
+
memory: "1GB"
|
|
1122
1157
|
})
|
|
1123
1158
|
.https.onCall(async (data, context) => {
|
|
1124
1159
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1156,7 +1191,7 @@ const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
|
1156
1191
|
const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
1157
1192
|
.region("europe-west1")
|
|
1158
1193
|
.runWith({
|
|
1159
|
-
memory: "
|
|
1194
|
+
memory: "1GB"
|
|
1160
1195
|
})
|
|
1161
1196
|
.https.onCall(async (data, context) => {
|
|
1162
1197
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1198,7 +1233,7 @@ const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
|
1198
1233
|
const checkAndPrepareCoordinatorForFinalization = functions
|
|
1199
1234
|
.region("europe-west1")
|
|
1200
1235
|
.runWith({
|
|
1201
|
-
memory: "
|
|
1236
|
+
memory: "1GB"
|
|
1202
1237
|
})
|
|
1203
1238
|
.https.onCall(async (data, context) => {
|
|
1204
1239
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -1438,7 +1473,7 @@ const waitForVMCommandExecution = (ssm, vmInstanceId, commandId) => new Promise(
|
|
|
1438
1473
|
const coordinateCeremonyParticipant = functionsV1
|
|
1439
1474
|
.region("europe-west1")
|
|
1440
1475
|
.runWith({
|
|
1441
|
-
memory: "
|
|
1476
|
+
memory: "1GB"
|
|
1442
1477
|
})
|
|
1443
1478
|
.firestore.document(`${commonTerms.collections.ceremonies.name}/{ceremonyId}/${commonTerms.collections.participants.name}/{participantId}`)
|
|
1444
1479
|
.onUpdate(async (participantChanges) => {
|
|
@@ -1838,7 +1873,7 @@ const verifycontribution = functionsV2.https.onCall({ memory: "16GiB", timeoutSe
|
|
|
1838
1873
|
const refreshParticipantAfterContributionVerification = functionsV1
|
|
1839
1874
|
.region("europe-west1")
|
|
1840
1875
|
.runWith({
|
|
1841
|
-
memory: "
|
|
1876
|
+
memory: "1GB"
|
|
1842
1877
|
})
|
|
1843
1878
|
.firestore.document(`/${commonTerms.collections.ceremonies.name}/{ceremony}/${commonTerms.collections.circuits.name}/{circuit}/${commonTerms.collections.contributions.name}/{contributions}`)
|
|
1844
1879
|
.onCreate(async (createdContribution) => {
|
|
@@ -1899,7 +1934,7 @@ const refreshParticipantAfterContributionVerification = functionsV1
|
|
|
1899
1934
|
const finalizeCircuit = functionsV1
|
|
1900
1935
|
.region("europe-west1")
|
|
1901
1936
|
.runWith({
|
|
1902
|
-
memory: "
|
|
1937
|
+
memory: "1GB"
|
|
1903
1938
|
})
|
|
1904
1939
|
.https.onCall(async (data, context) => {
|
|
1905
1940
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -2043,7 +2078,7 @@ const checkIfBucketIsDedicatedToCeremony = async (bucketName) => {
|
|
|
2043
2078
|
const createBucket = functions
|
|
2044
2079
|
.region("europe-west1")
|
|
2045
2080
|
.runWith({
|
|
2046
|
-
memory: "
|
|
2081
|
+
memory: "1GB"
|
|
2047
2082
|
})
|
|
2048
2083
|
.https.onCall(async (data, context) => {
|
|
2049
2084
|
// Check if the user has the coordinator claim.
|
|
@@ -2133,7 +2168,7 @@ const createBucket = functions
|
|
|
2133
2168
|
const checkIfObjectExist = functions
|
|
2134
2169
|
.region("europe-west1")
|
|
2135
2170
|
.runWith({
|
|
2136
|
-
memory: "
|
|
2171
|
+
memory: "1GB"
|
|
2137
2172
|
})
|
|
2138
2173
|
.https.onCall(async (data, context) => {
|
|
2139
2174
|
// Check if the user has the coordinator claim.
|
|
@@ -2179,7 +2214,7 @@ const checkIfObjectExist = functions
|
|
|
2179
2214
|
const generateGetObjectPreSignedUrl = functions
|
|
2180
2215
|
.region("europe-west1")
|
|
2181
2216
|
.runWith({
|
|
2182
|
-
memory: "
|
|
2217
|
+
memory: "1GB"
|
|
2183
2218
|
})
|
|
2184
2219
|
.https.onCall(async (data, context) => {
|
|
2185
2220
|
if (!context.auth)
|
|
@@ -2219,7 +2254,7 @@ const generateGetObjectPreSignedUrl = functions
|
|
|
2219
2254
|
const startMultiPartUpload = functions
|
|
2220
2255
|
.region("europe-west1")
|
|
2221
2256
|
.runWith({
|
|
2222
|
-
memory: "
|
|
2257
|
+
memory: "2GB"
|
|
2223
2258
|
})
|
|
2224
2259
|
.https.onCall(async (data, context) => {
|
|
2225
2260
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2274,7 +2309,7 @@ const startMultiPartUpload = functions
|
|
|
2274
2309
|
const generatePreSignedUrlsParts = functions
|
|
2275
2310
|
.region("europe-west1")
|
|
2276
2311
|
.runWith({
|
|
2277
|
-
memory: "
|
|
2312
|
+
memory: "1GB",
|
|
2278
2313
|
timeoutSeconds: 300
|
|
2279
2314
|
})
|
|
2280
2315
|
.https.onCall(async (data, context) => {
|
|
@@ -2335,7 +2370,7 @@ const generatePreSignedUrlsParts = functions
|
|
|
2335
2370
|
const completeMultiPartUpload = functions
|
|
2336
2371
|
.region("europe-west1")
|
|
2337
2372
|
.runWith({
|
|
2338
|
-
memory: "
|
|
2373
|
+
memory: "2GB"
|
|
2339
2374
|
})
|
|
2340
2375
|
.https.onCall(async (data, context) => {
|
|
2341
2376
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2384,6 +2419,216 @@ const completeMultiPartUpload = functions
|
|
|
2384
2419
|
}
|
|
2385
2420
|
});
|
|
2386
2421
|
|
|
2422
|
+
const VKEY_DATA = {
|
|
2423
|
+
protocol: "groth16",
|
|
2424
|
+
curve: "bn128",
|
|
2425
|
+
nPublic: 3,
|
|
2426
|
+
vk_alpha_1: [
|
|
2427
|
+
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
|
2428
|
+
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
|
2429
|
+
"1"
|
|
2430
|
+
],
|
|
2431
|
+
vk_beta_2: [
|
|
2432
|
+
[
|
|
2433
|
+
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
|
2434
|
+
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
|
2435
|
+
],
|
|
2436
|
+
[
|
|
2437
|
+
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
|
2438
|
+
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
|
2439
|
+
],
|
|
2440
|
+
["1", "0"]
|
|
2441
|
+
],
|
|
2442
|
+
vk_gamma_2: [
|
|
2443
|
+
[
|
|
2444
|
+
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
|
2445
|
+
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
|
2446
|
+
],
|
|
2447
|
+
[
|
|
2448
|
+
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
|
2449
|
+
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
|
2450
|
+
],
|
|
2451
|
+
["1", "0"]
|
|
2452
|
+
],
|
|
2453
|
+
vk_delta_2: [
|
|
2454
|
+
[
|
|
2455
|
+
"3697618915467790705869942236922063775466274665053173890632463796679068973252",
|
|
2456
|
+
"14948341351907992175709156460547989243732741534604949238422596319735704165658"
|
|
2457
|
+
],
|
|
2458
|
+
[
|
|
2459
|
+
"3028459181652799888716942141752307629938889957960373621898607910203491239368",
|
|
2460
|
+
"11380736494786911280692284374675752681598754560757720296073023058533044108340"
|
|
2461
|
+
],
|
|
2462
|
+
["1", "0"]
|
|
2463
|
+
],
|
|
2464
|
+
vk_alphabeta_12: [
|
|
2465
|
+
[
|
|
2466
|
+
[
|
|
2467
|
+
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
|
2468
|
+
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
|
2469
|
+
],
|
|
2470
|
+
[
|
|
2471
|
+
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
|
2472
|
+
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
|
2473
|
+
],
|
|
2474
|
+
[
|
|
2475
|
+
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
|
2476
|
+
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
|
2477
|
+
]
|
|
2478
|
+
],
|
|
2479
|
+
[
|
|
2480
|
+
[
|
|
2481
|
+
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
|
2482
|
+
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
|
2483
|
+
],
|
|
2484
|
+
[
|
|
2485
|
+
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
|
2486
|
+
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
|
2487
|
+
],
|
|
2488
|
+
[
|
|
2489
|
+
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
|
2490
|
+
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
|
2491
|
+
]
|
|
2492
|
+
]
|
|
2493
|
+
],
|
|
2494
|
+
IC: [
|
|
2495
|
+
[
|
|
2496
|
+
"12951059800758687233303204819298121944551181861362200875212570257618182506154",
|
|
2497
|
+
"5751958719396509176593242305268064754837298673622815112953832050159760501392",
|
|
2498
|
+
"1"
|
|
2499
|
+
],
|
|
2500
|
+
[
|
|
2501
|
+
"9561588427935871983444704959674198910445823619407211599507208879011862515257",
|
|
2502
|
+
"14576201570478094842467636169770180675293504492823217349086195663150934064643",
|
|
2503
|
+
"1"
|
|
2504
|
+
],
|
|
2505
|
+
[
|
|
2506
|
+
"4811967233483727873912563574622036989372099129165459921963463310078093941559",
|
|
2507
|
+
"1874883809855039536107616044787862082553628089593740724610117059083415551067",
|
|
2508
|
+
"1"
|
|
2509
|
+
],
|
|
2510
|
+
[
|
|
2511
|
+
"12252730267779308452229639835051322390696643456253768618882001876621526827161",
|
|
2512
|
+
"7899194018737016222260328309937800777948677569409898603827268776967707173231",
|
|
2513
|
+
"1"
|
|
2514
|
+
]
|
|
2515
|
+
]
|
|
2516
|
+
};
|
|
2517
|
+
dotenv.config();
|
|
2518
|
+
const { BANDADA_API_URL, BANDADA_GROUP_ID } = process.env;
|
|
2519
|
+
const bandadaApi = new ApiSdk(BANDADA_API_URL);
|
|
2520
|
+
const bandadaValidateProof = functions
|
|
2521
|
+
.region("europe-west1")
|
|
2522
|
+
.runWith({
|
|
2523
|
+
memory: "512MB"
|
|
2524
|
+
})
|
|
2525
|
+
.https.onCall(async (data) => {
|
|
2526
|
+
if (!BANDADA_GROUP_ID)
|
|
2527
|
+
throw new Error("BANDADA_GROUP_ID is not defined in .env");
|
|
2528
|
+
const { proof, publicSignals } = data;
|
|
2529
|
+
const isCorrect = groth16.verify(VKEY_DATA, publicSignals, proof);
|
|
2530
|
+
if (!isCorrect)
|
|
2531
|
+
return {
|
|
2532
|
+
valid: false,
|
|
2533
|
+
message: "Invalid proof",
|
|
2534
|
+
token: ""
|
|
2535
|
+
};
|
|
2536
|
+
const commitment = data.publicSignals[1];
|
|
2537
|
+
const isMember = await bandadaApi.isGroupMember(BANDADA_GROUP_ID, commitment);
|
|
2538
|
+
if (!isMember)
|
|
2539
|
+
return {
|
|
2540
|
+
valid: false,
|
|
2541
|
+
message: "Not a member of the group",
|
|
2542
|
+
token: ""
|
|
2543
|
+
};
|
|
2544
|
+
const auth = getAuth();
|
|
2545
|
+
try {
|
|
2546
|
+
await admin.auth().createUser({
|
|
2547
|
+
uid: commitment
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
catch (error) {
|
|
2551
|
+
// if user already exist then just pass
|
|
2552
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
2553
|
+
throw new Error(error);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
const token = await auth.createCustomToken(commitment);
|
|
2557
|
+
return {
|
|
2558
|
+
valid: true,
|
|
2559
|
+
message: "Valid proof and group member",
|
|
2560
|
+
token
|
|
2561
|
+
};
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
dotenv.config();
|
|
2565
|
+
const checkNonceOfSIWEAddress = functions
|
|
2566
|
+
.region("europe-west1")
|
|
2567
|
+
.runWith({ memory: "1GB" })
|
|
2568
|
+
.https.onCall(async (data) => {
|
|
2569
|
+
try {
|
|
2570
|
+
const { auth0Token } = data;
|
|
2571
|
+
const result = (await fetch(`${process.env.AUTH0_APPLICATION_URL}/userinfo`, {
|
|
2572
|
+
method: "GET",
|
|
2573
|
+
headers: {
|
|
2574
|
+
"content-type": "application/json",
|
|
2575
|
+
authorization: `Bearer ${auth0Token}`
|
|
2576
|
+
}
|
|
2577
|
+
}).then((_res) => _res.json()));
|
|
2578
|
+
if (!result.sub) {
|
|
2579
|
+
return {
|
|
2580
|
+
valid: false,
|
|
2581
|
+
message: "No user detected. Please check device flow token"
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2584
|
+
const auth = getAuth();
|
|
2585
|
+
// check nonce
|
|
2586
|
+
const parts = result.sub.split("|");
|
|
2587
|
+
const address = decodeURIComponent(parts[2]).split(":")[2];
|
|
2588
|
+
const minimumNonce = Number(process.env.ETH_MINIMUM_NONCE);
|
|
2589
|
+
const nonceBlockHeight = "latest"; // process.env.ETH_NONCE_BLOCK_HEIGHT
|
|
2590
|
+
// look up nonce for address @block
|
|
2591
|
+
let nonceOk = true;
|
|
2592
|
+
if (minimumNonce > 0) {
|
|
2593
|
+
const provider = setEthProvider();
|
|
2594
|
+
console.log(`got provider - block # ${await provider.getBlockNumber()}`);
|
|
2595
|
+
const nonce = await provider.getTransactionCount(address, nonceBlockHeight);
|
|
2596
|
+
console.log(`nonce ${nonce}`);
|
|
2597
|
+
nonceOk = nonce >= minimumNonce;
|
|
2598
|
+
}
|
|
2599
|
+
console.log(`checking nonce ${nonceOk}`);
|
|
2600
|
+
if (!nonceOk) {
|
|
2601
|
+
return {
|
|
2602
|
+
valid: false,
|
|
2603
|
+
message: "Eth address does not meet the nonce requirements"
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
try {
|
|
2607
|
+
await admin.auth().createUser({
|
|
2608
|
+
displayName: address,
|
|
2609
|
+
uid: address
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
catch (error) {
|
|
2613
|
+
// if user already exist then just pass
|
|
2614
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
2615
|
+
throw new Error(error);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
const token = await auth.createCustomToken(address);
|
|
2619
|
+
return {
|
|
2620
|
+
valid: true,
|
|
2621
|
+
token
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
catch (error) {
|
|
2625
|
+
return {
|
|
2626
|
+
valid: false,
|
|
2627
|
+
message: `Something went wrong ${error}`
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
});
|
|
2631
|
+
|
|
2387
2632
|
dotenv.config();
|
|
2388
2633
|
/**
|
|
2389
2634
|
* Check and remove the current contributor if it doesn't complete the contribution on the specified amount of time.
|
|
@@ -2406,7 +2651,7 @@ dotenv.config();
|
|
|
2406
2651
|
const checkAndRemoveBlockingContributor = functions
|
|
2407
2652
|
.region("europe-west1")
|
|
2408
2653
|
.runWith({
|
|
2409
|
-
memory: "
|
|
2654
|
+
memory: "1GB"
|
|
2410
2655
|
})
|
|
2411
2656
|
.pubsub.schedule("every 1 minutes")
|
|
2412
2657
|
.onRun(async () => {
|
|
@@ -2475,7 +2720,8 @@ const checkAndRemoveBlockingContributor = functions
|
|
|
2475
2720
|
if (timeoutExpirationDateInMsForBlockingContributor < currentServerTimestamp &&
|
|
2476
2721
|
(contributionStep === "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */ ||
|
|
2477
2722
|
contributionStep === "COMPUTING" /* ParticipantContributionStep.COMPUTING */ ||
|
|
2478
|
-
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */
|
|
2723
|
+
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */ ||
|
|
2724
|
+
contributionStep === "COMPLETED" /* ParticipantContributionStep.COMPLETED */))
|
|
2479
2725
|
timeoutType = "BLOCKING_CONTRIBUTION" /* TimeoutType.BLOCKING_CONTRIBUTION */;
|
|
2480
2726
|
if (timeoutExpirationDateInMsForVerificationCloudFunction > 0 &&
|
|
2481
2727
|
timeoutExpirationDateInMsForVerificationCloudFunction < currentServerTimestamp &&
|
|
@@ -2552,7 +2798,7 @@ const checkAndRemoveBlockingContributor = functions
|
|
|
2552
2798
|
const resumeContributionAfterTimeoutExpiration = functions
|
|
2553
2799
|
.region("europe-west1")
|
|
2554
2800
|
.runWith({
|
|
2555
|
-
memory: "
|
|
2801
|
+
memory: "1GB"
|
|
2556
2802
|
})
|
|
2557
2803
|
.https.onCall(async (data, context) => {
|
|
2558
2804
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2585,4 +2831,4 @@ const resumeContributionAfterTimeoutExpiration = functions
|
|
|
2585
2831
|
|
|
2586
2832
|
admin.initializeApp();
|
|
2587
2833
|
|
|
2588
|
-
export { checkAndPrepareCoordinatorForFinalization, checkAndRemoveBlockingContributor, checkIfObjectExist, checkParticipantForCeremony, completeMultiPartUpload, coordinateCeremonyParticipant, createBucket, finalizeCeremony, finalizeCircuit, generateGetObjectPreSignedUrl, generatePreSignedUrlsParts, initEmptyWaitingQueueForCircuit, permanentlyStoreCurrentContributionTimeAndHash, processSignUpWithCustomClaims, progressToNextCircuitForContribution, progressToNextContributionStep, refreshParticipantAfterContributionVerification, registerAuthUser, resumeContributionAfterTimeoutExpiration, setupCeremony, startCeremony, startMultiPartUpload, stopCeremony, temporaryStoreCurrentContributionMultiPartUploadId, temporaryStoreCurrentContributionUploadedChunkData, verifycontribution };
|
|
2834
|
+
export { bandadaValidateProof, checkAndPrepareCoordinatorForFinalization, checkAndRemoveBlockingContributor, checkIfObjectExist, checkNonceOfSIWEAddress, checkParticipantForCeremony, completeMultiPartUpload, coordinateCeremonyParticipant, createBucket, finalizeCeremony, finalizeCircuit, generateGetObjectPreSignedUrl, generatePreSignedUrlsParts, initEmptyWaitingQueueForCircuit, permanentlyStoreCurrentContributionTimeAndHash, processSignUpWithCustomClaims, progressToNextCircuitForContribution, progressToNextContributionStep, refreshParticipantAfterContributionVerification, registerAuthUser, resumeContributionAfterTimeoutExpiration, setupCeremony, startCeremony, startMultiPartUpload, stopCeremony, temporaryStoreCurrentContributionMultiPartUploadId, temporaryStoreCurrentContributionUploadedChunkData, verifycontribution };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bandada.d.ts","sourceRoot":"","sources":["../../../src/functions/bandada.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AA6G/C,eAAO,MAAM,oBAAoB,mDA0C3B,CAAA;AAEN,eAAe,oBAAoB,CAAA"}
|
|
@@ -3,5 +3,7 @@ export { startCeremony, stopCeremony, setupCeremony, initEmptyWaitingQueueForCir
|
|
|
3
3
|
export { checkParticipantForCeremony, progressToNextContributionStep, permanentlyStoreCurrentContributionTimeAndHash, temporaryStoreCurrentContributionMultiPartUploadId, temporaryStoreCurrentContributionUploadedChunkData, progressToNextCircuitForContribution, checkAndPrepareCoordinatorForFinalization } from "./participant";
|
|
4
4
|
export { coordinateCeremonyParticipant, verifycontribution, refreshParticipantAfterContributionVerification, finalizeCircuit } from "./circuit";
|
|
5
5
|
export { createBucket, checkIfObjectExist, generateGetObjectPreSignedUrl, startMultiPartUpload, generatePreSignedUrlsParts, completeMultiPartUpload } from "./storage";
|
|
6
|
+
export { bandadaValidateProof } from "./bandada";
|
|
7
|
+
export { checkNonceOfSIWEAddress } from "./siwe";
|
|
6
8
|
export { checkAndRemoveBlockingContributor, resumeContributionAfterTimeoutExpiration } from "./timeout";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EACH,aAAa,EACb,YAAY,EACZ,aAAa,EACb,+BAA+B,EAC/B,gBAAgB,EACnB,MAAM,YAAY,CAAA;AACnB,OAAO,EACH,2BAA2B,EAC3B,8BAA8B,EAC9B,8CAA8C,EAC9C,kDAAkD,EAClD,kDAAkD,EAClD,oCAAoC,EACpC,yCAAyC,EAC5C,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,6BAA6B,EAC7B,kBAAkB,EAClB,+CAA+C,EAC/C,eAAe,EAClB,MAAM,WAAW,CAAA;AAClB,OAAO,EACH,YAAY,EACZ,kBAAkB,EAClB,6BAA6B,EAC7B,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EAC1B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,iCAAiC,EAAE,wCAAwC,EAAE,MAAM,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EACH,aAAa,EACb,YAAY,EACZ,aAAa,EACb,+BAA+B,EAC/B,gBAAgB,EACnB,MAAM,YAAY,CAAA;AACnB,OAAO,EACH,2BAA2B,EAC3B,8BAA8B,EAC9B,8CAA8C,EAC9C,kDAAkD,EAClD,kDAAkD,EAClD,oCAAoC,EACpC,yCAAyC,EAC5C,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,6BAA6B,EAC7B,kBAAkB,EAClB,+CAA+C,EAC/C,eAAe,EAClB,MAAM,WAAW,CAAA;AAClB,OAAO,EACH,YAAY,EACZ,kBAAkB,EAClB,6BAA6B,EAC7B,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EAC1B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,EAAE,iCAAiC,EAAE,wCAAwC,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siwe.d.ts","sourceRoot":"","sources":["../../../src/functions/siwe.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAQ/C,eAAO,MAAM,uBAAuB,mDAgE9B,CAAA;AAEN,eAAe,uBAAuB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/functions/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAuB/C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iCAAiC,
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/functions/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAuB/C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iCAAiC,kCA8MxC,CAAA;AAEN;;;GAGG;AACH,eAAO,MAAM,wCAAwC,mDA0C/C,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { LogLevel } from "../types/enums";
|
|
|
6
6
|
* @notice the set of Firebase Functions status codes. The codes are the same at the
|
|
7
7
|
* ones exposed by {@link https://github.com/grpc/grpc/blob/master/doc/statuscodes.md | gRPC}.
|
|
8
8
|
* @param errorCode <FunctionsErrorCode> - the set of possible error codes.
|
|
9
|
-
* @param message <string> - the error
|
|
9
|
+
* @param message <string> - the error message.
|
|
10
10
|
* @param [details] <string> - the details of the error (optional).
|
|
11
11
|
* @returns <HttpsError>
|
|
12
12
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ethers from "ethers";
|
|
1
2
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
2
3
|
/**
|
|
3
4
|
* Return a configured and connected instance of the AWS S3 client.
|
|
@@ -6,4 +7,10 @@ import { S3Client } from "@aws-sdk/client-s3";
|
|
|
6
7
|
* @returns <Promise<S3Client>> - the instance of the connected S3 Client instance.
|
|
7
8
|
*/
|
|
8
9
|
export declare const getS3Client: () => Promise<S3Client>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a Prvider, connected via a configured JSON URL or else
|
|
12
|
+
* the ethers.js default provider, using configured API keys.
|
|
13
|
+
* @returns <ethers.providers.Provider> An Eth node provider
|
|
14
|
+
*/
|
|
15
|
+
export declare const setEthProvider: () => ethers.providers.Provider;
|
|
9
16
|
//# sourceMappingURL=services.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/lib/services.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/lib/services.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAM7C;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,QAAQ,QAAQ,CAkBpD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,OAAO,SAAS,CAAC,QAwBlD,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CeremonyInputData, CircuitDocument, ETagWithPartNumber } from "@devtion/actions";
|
|
2
|
+
import type { Groth16Proof, PublicSignals } from "snarkjs";
|
|
2
3
|
/**
|
|
3
4
|
* Group all the necessary data needed for running the `setupCeremony` cloud function.
|
|
4
5
|
* @typedef {Object} SetupCeremonyData
|
|
@@ -127,4 +128,59 @@ export type FinalizeCircuitData = {
|
|
|
127
128
|
bucketName: string;
|
|
128
129
|
beacon: string;
|
|
129
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* Group all the necessary data needed for running the `bandadaValidateProof` cloud function.
|
|
133
|
+
* @typedef {Object} BandadaValidateProof
|
|
134
|
+
* @property {string} merkleTreeRoot - the merkle tree root of the group.
|
|
135
|
+
* @property {string} nullifierHash - the nullifier hash of the member.
|
|
136
|
+
* @property {string} externalNullifier - the external nullifier of the member.
|
|
137
|
+
* @property {PackedProof} proof - the packed proof generated on the client.
|
|
138
|
+
*/
|
|
139
|
+
export type BandadaValidateProof = {
|
|
140
|
+
proof: Groth16Proof;
|
|
141
|
+
publicSignals: PublicSignals;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Define the return object of the function that verifies the Bandada membership and proof.
|
|
145
|
+
* @typedef {Object} VerifiedBandadaResponse
|
|
146
|
+
* @property {boolean} valid - true if the proof is valid and the user is a member of the group; otherwise false.
|
|
147
|
+
* @property {string} message - a message describing the result of the verification.
|
|
148
|
+
* @property {string} token - the custom access token.
|
|
149
|
+
*/
|
|
150
|
+
export type VerifiedBandadaResponse = {
|
|
151
|
+
valid: boolean;
|
|
152
|
+
message: string;
|
|
153
|
+
token: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Define the check nonce object for the cloud function
|
|
157
|
+
* @typedef {Object} CheckNonceOfSIWEAddressRequest
|
|
158
|
+
* @property {string} auth0Token - token from the device flow authentication
|
|
159
|
+
*/
|
|
160
|
+
export type CheckNonceOfSIWEAddressRequest = {
|
|
161
|
+
auth0Token: string;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Define the check nonce response object of the cloud function
|
|
165
|
+
* @typedef {Object} CheckNonceOfSIWEAddressResponse
|
|
166
|
+
* @property {boolean} valid - if the checking result was valid or not
|
|
167
|
+
* @property {string} message - informative message
|
|
168
|
+
* @property {string} token - token to sign in
|
|
169
|
+
*/
|
|
170
|
+
export type CheckNonceOfSIWEAddressResponse = {
|
|
171
|
+
valid: boolean;
|
|
172
|
+
message?: string;
|
|
173
|
+
token?: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Define the response from auth0 /userinfo endpoint
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
export type Auth0UserInfo = {
|
|
180
|
+
sub: string;
|
|
181
|
+
nickname: string;
|
|
182
|
+
name: string;
|
|
183
|
+
picture: string;
|
|
184
|
+
updated_at: string;
|
|
185
|
+
};
|
|
130
186
|
//# sourceMappingURL=index.d.ts.map
|