@devtion/backend 0.0.0-a9e4cd4 → 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
|
|
@@ -27,10 +27,13 @@ var path = require('path');
|
|
|
27
27
|
var os = require('os');
|
|
28
28
|
var clientSsm = require('@aws-sdk/client-ssm');
|
|
29
29
|
var clientEc2 = require('@aws-sdk/client-ec2');
|
|
30
|
+
var ethers = require('ethers');
|
|
30
31
|
var functionsV1 = require('firebase-functions/v1');
|
|
31
32
|
var functionsV2 = require('firebase-functions/v2');
|
|
32
33
|
var timerNode = require('timer-node');
|
|
33
34
|
var snarkjs = require('snarkjs');
|
|
35
|
+
var apiSdk = require('@bandada/api-sdk');
|
|
36
|
+
var auth = require('firebase-admin/auth');
|
|
34
37
|
|
|
35
38
|
function _interopNamespaceDefault(e) {
|
|
36
39
|
var n = Object.create(null);
|
|
@@ -72,7 +75,7 @@ var LogLevel;
|
|
|
72
75
|
* @notice the set of Firebase Functions status codes. The codes are the same at the
|
|
73
76
|
* ones exposed by {@link https://github.com/grpc/grpc/blob/master/doc/statuscodes.md | gRPC}.
|
|
74
77
|
* @param errorCode <FunctionsErrorCode> - the set of possible error codes.
|
|
75
|
-
* @param message <string> - the error
|
|
78
|
+
* @param message <string> - the error message.
|
|
76
79
|
* @param [details] <string> - the details of the error (optional).
|
|
77
80
|
* @returns <HttpsError>
|
|
78
81
|
*/
|
|
@@ -164,6 +167,8 @@ const COMMON_ERRORS = {
|
|
|
164
167
|
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.")
|
|
165
168
|
};
|
|
166
169
|
|
|
170
|
+
dotenv.config();
|
|
171
|
+
let provider;
|
|
167
172
|
/**
|
|
168
173
|
* Return a configured and connected instance of the AWS S3 client.
|
|
169
174
|
* @dev this method check and utilize the environment variables to configure the connection
|
|
@@ -186,6 +191,36 @@ const getS3Client = async () => {
|
|
|
186
191
|
region: process.env.AWS_REGION
|
|
187
192
|
});
|
|
188
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Returns a Prvider, connected via a configured JSON URL or else
|
|
196
|
+
* the ethers.js default provider, using configured API keys.
|
|
197
|
+
* @returns <ethers.providers.Provider> An Eth node provider
|
|
198
|
+
*/
|
|
199
|
+
const setEthProvider = () => {
|
|
200
|
+
if (provider)
|
|
201
|
+
return provider;
|
|
202
|
+
console.log(`setting new provider`);
|
|
203
|
+
// Use JSON URL if defined
|
|
204
|
+
// if ((hardhat as any).ethers) {
|
|
205
|
+
// console.log(`using hardhat.ethers provider`)
|
|
206
|
+
// provider = (hardhat as any).ethers.provider
|
|
207
|
+
// } else
|
|
208
|
+
if (process.env.ETH_PROVIDER_JSON_URL) {
|
|
209
|
+
console.log(`JSON URL provider at ${process.env.ETH_PROVIDER_JSON_URL}`);
|
|
210
|
+
provider = new ethers.providers.JsonRpcProvider({
|
|
211
|
+
url: process.env.ETH_PROVIDER_JSON_URL,
|
|
212
|
+
skipFetchSetup: true
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// Otherwise, connect the default provider with ALchemy, Infura, or both
|
|
217
|
+
provider = ethers.providers.getDefaultProvider("homestead", {
|
|
218
|
+
alchemy: process.env.ETH_PROVIDER_ALCHEMY_API_KEY,
|
|
219
|
+
infura: process.env.ETH_PROVIDER_INFURA_API_KEY
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return provider;
|
|
223
|
+
};
|
|
189
224
|
|
|
190
225
|
dotenv.config();
|
|
191
226
|
/**
|
|
@@ -524,7 +559,7 @@ dotenv.config();
|
|
|
524
559
|
const registerAuthUser = functions__namespace
|
|
525
560
|
.region("europe-west1")
|
|
526
561
|
.runWith({
|
|
527
|
-
memory: "
|
|
562
|
+
memory: "1GB"
|
|
528
563
|
})
|
|
529
564
|
.auth.user()
|
|
530
565
|
.onCreate(async (user) => {
|
|
@@ -556,7 +591,7 @@ const registerAuthUser = functions__namespace
|
|
|
556
591
|
email === process.env.CUSTOM_CLAIMS_COORDINATOR_EMAIL_ADDRESS_OR_DOMAIN)) {
|
|
557
592
|
const auth = admin.auth();
|
|
558
593
|
// if provider == github.com let's use our functions to check the user's reputation
|
|
559
|
-
if (user.providerData[0].providerId === "github.com") {
|
|
594
|
+
if (user.providerData.length > 0 && user.providerData[0].providerId === "github.com") {
|
|
560
595
|
const vars = getGitHubVariables();
|
|
561
596
|
// this return true or false
|
|
562
597
|
try {
|
|
@@ -588,7 +623,7 @@ const registerAuthUser = functions__namespace
|
|
|
588
623
|
encodedDisplayName,
|
|
589
624
|
// Metadata.
|
|
590
625
|
creationTime,
|
|
591
|
-
lastSignInTime,
|
|
626
|
+
lastSignInTime: lastSignInTime || creationTime,
|
|
592
627
|
// Optional.
|
|
593
628
|
email: email || "",
|
|
594
629
|
emailVerified: emailVerified || false,
|
|
@@ -611,7 +646,7 @@ const registerAuthUser = functions__namespace
|
|
|
611
646
|
const processSignUpWithCustomClaims = functions__namespace
|
|
612
647
|
.region("europe-west1")
|
|
613
648
|
.runWith({
|
|
614
|
-
memory: "
|
|
649
|
+
memory: "1GB"
|
|
615
650
|
})
|
|
616
651
|
.auth.user()
|
|
617
652
|
.onCreate(async (user) => {
|
|
@@ -652,7 +687,7 @@ dotenv.config();
|
|
|
652
687
|
const startCeremony = functions__namespace
|
|
653
688
|
.region("europe-west1")
|
|
654
689
|
.runWith({
|
|
655
|
-
memory: "
|
|
690
|
+
memory: "1GB"
|
|
656
691
|
})
|
|
657
692
|
.pubsub.schedule(`every 30 minutes`)
|
|
658
693
|
.onRun(async () => {
|
|
@@ -674,7 +709,7 @@ const startCeremony = functions__namespace
|
|
|
674
709
|
const stopCeremony = functions__namespace
|
|
675
710
|
.region("europe-west1")
|
|
676
711
|
.runWith({
|
|
677
|
-
memory: "
|
|
712
|
+
memory: "1GB"
|
|
678
713
|
})
|
|
679
714
|
.pubsub.schedule(`every 30 minutes`)
|
|
680
715
|
.onRun(async () => {
|
|
@@ -696,7 +731,7 @@ const stopCeremony = functions__namespace
|
|
|
696
731
|
const setupCeremony = functions__namespace
|
|
697
732
|
.region("europe-west1")
|
|
698
733
|
.runWith({
|
|
699
|
-
memory: "
|
|
734
|
+
memory: "1GB"
|
|
700
735
|
})
|
|
701
736
|
.https.onCall(async (data, context) => {
|
|
702
737
|
// Check if the user has the coordinator claim.
|
|
@@ -821,7 +856,7 @@ const initEmptyWaitingQueueForCircuit = functions__namespace
|
|
|
821
856
|
const finalizeCeremony = functions__namespace
|
|
822
857
|
.region("europe-west1")
|
|
823
858
|
.runWith({
|
|
824
|
-
memory: "
|
|
859
|
+
memory: "1GB"
|
|
825
860
|
})
|
|
826
861
|
.https.onCall(async (data, context) => {
|
|
827
862
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -897,7 +932,7 @@ dotenv.config();
|
|
|
897
932
|
const checkParticipantForCeremony = functions__namespace
|
|
898
933
|
.region("europe-west1")
|
|
899
934
|
.runWith({
|
|
900
|
-
memory: "
|
|
935
|
+
memory: "1GB"
|
|
901
936
|
})
|
|
902
937
|
.https.onCall(async (data, context) => {
|
|
903
938
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1001,7 +1036,7 @@ const checkParticipantForCeremony = functions__namespace
|
|
|
1001
1036
|
const progressToNextCircuitForContribution = functions__namespace
|
|
1002
1037
|
.region("europe-west1")
|
|
1003
1038
|
.runWith({
|
|
1004
|
-
memory: "
|
|
1039
|
+
memory: "1GB"
|
|
1005
1040
|
})
|
|
1006
1041
|
.https.onCall(async (data, context) => {
|
|
1007
1042
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1048,7 +1083,7 @@ const progressToNextCircuitForContribution = functions__namespace
|
|
|
1048
1083
|
const progressToNextContributionStep = functions__namespace
|
|
1049
1084
|
.region("europe-west1")
|
|
1050
1085
|
.runWith({
|
|
1051
|
-
memory: "
|
|
1086
|
+
memory: "1GB"
|
|
1052
1087
|
})
|
|
1053
1088
|
.https.onCall(async (data, context) => {
|
|
1054
1089
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1099,7 +1134,7 @@ const progressToNextContributionStep = functions__namespace
|
|
|
1099
1134
|
const permanentlyStoreCurrentContributionTimeAndHash = functions__namespace
|
|
1100
1135
|
.region("europe-west1")
|
|
1101
1136
|
.runWith({
|
|
1102
|
-
memory: "
|
|
1137
|
+
memory: "1GB"
|
|
1103
1138
|
})
|
|
1104
1139
|
.https.onCall(async (data, context) => {
|
|
1105
1140
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1141,7 +1176,7 @@ const permanentlyStoreCurrentContributionTimeAndHash = functions__namespace
|
|
|
1141
1176
|
const temporaryStoreCurrentContributionMultiPartUploadId = functions__namespace
|
|
1142
1177
|
.region("europe-west1")
|
|
1143
1178
|
.runWith({
|
|
1144
|
-
memory: "
|
|
1179
|
+
memory: "1GB"
|
|
1145
1180
|
})
|
|
1146
1181
|
.https.onCall(async (data, context) => {
|
|
1147
1182
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1179,7 +1214,7 @@ const temporaryStoreCurrentContributionMultiPartUploadId = functions__namespace
|
|
|
1179
1214
|
const temporaryStoreCurrentContributionUploadedChunkData = functions__namespace
|
|
1180
1215
|
.region("europe-west1")
|
|
1181
1216
|
.runWith({
|
|
1182
|
-
memory: "
|
|
1217
|
+
memory: "1GB"
|
|
1183
1218
|
})
|
|
1184
1219
|
.https.onCall(async (data, context) => {
|
|
1185
1220
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1221,7 +1256,7 @@ const temporaryStoreCurrentContributionUploadedChunkData = functions__namespace
|
|
|
1221
1256
|
const checkAndPrepareCoordinatorForFinalization = functions__namespace
|
|
1222
1257
|
.region("europe-west1")
|
|
1223
1258
|
.runWith({
|
|
1224
|
-
memory: "
|
|
1259
|
+
memory: "1GB"
|
|
1225
1260
|
})
|
|
1226
1261
|
.https.onCall(async (data, context) => {
|
|
1227
1262
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -1461,7 +1496,7 @@ const waitForVMCommandExecution = (ssm, vmInstanceId, commandId) => new Promise(
|
|
|
1461
1496
|
const coordinateCeremonyParticipant = functionsV1__namespace
|
|
1462
1497
|
.region("europe-west1")
|
|
1463
1498
|
.runWith({
|
|
1464
|
-
memory: "
|
|
1499
|
+
memory: "1GB"
|
|
1465
1500
|
})
|
|
1466
1501
|
.firestore.document(`${actions.commonTerms.collections.ceremonies.name}/{ceremonyId}/${actions.commonTerms.collections.participants.name}/{participantId}`)
|
|
1467
1502
|
.onUpdate(async (participantChanges) => {
|
|
@@ -1861,7 +1896,7 @@ const verifycontribution = functionsV2__namespace.https.onCall({ memory: "16GiB"
|
|
|
1861
1896
|
const refreshParticipantAfterContributionVerification = functionsV1__namespace
|
|
1862
1897
|
.region("europe-west1")
|
|
1863
1898
|
.runWith({
|
|
1864
|
-
memory: "
|
|
1899
|
+
memory: "1GB"
|
|
1865
1900
|
})
|
|
1866
1901
|
.firestore.document(`/${actions.commonTerms.collections.ceremonies.name}/{ceremony}/${actions.commonTerms.collections.circuits.name}/{circuit}/${actions.commonTerms.collections.contributions.name}/{contributions}`)
|
|
1867
1902
|
.onCreate(async (createdContribution) => {
|
|
@@ -1922,7 +1957,7 @@ const refreshParticipantAfterContributionVerification = functionsV1__namespace
|
|
|
1922
1957
|
const finalizeCircuit = functionsV1__namespace
|
|
1923
1958
|
.region("europe-west1")
|
|
1924
1959
|
.runWith({
|
|
1925
|
-
memory: "
|
|
1960
|
+
memory: "1GB"
|
|
1926
1961
|
})
|
|
1927
1962
|
.https.onCall(async (data, context) => {
|
|
1928
1963
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -2066,7 +2101,7 @@ const checkIfBucketIsDedicatedToCeremony = async (bucketName) => {
|
|
|
2066
2101
|
const createBucket = functions__namespace
|
|
2067
2102
|
.region("europe-west1")
|
|
2068
2103
|
.runWith({
|
|
2069
|
-
memory: "
|
|
2104
|
+
memory: "1GB"
|
|
2070
2105
|
})
|
|
2071
2106
|
.https.onCall(async (data, context) => {
|
|
2072
2107
|
// Check if the user has the coordinator claim.
|
|
@@ -2156,7 +2191,7 @@ const createBucket = functions__namespace
|
|
|
2156
2191
|
const checkIfObjectExist = functions__namespace
|
|
2157
2192
|
.region("europe-west1")
|
|
2158
2193
|
.runWith({
|
|
2159
|
-
memory: "
|
|
2194
|
+
memory: "1GB"
|
|
2160
2195
|
})
|
|
2161
2196
|
.https.onCall(async (data, context) => {
|
|
2162
2197
|
// Check if the user has the coordinator claim.
|
|
@@ -2202,7 +2237,7 @@ const checkIfObjectExist = functions__namespace
|
|
|
2202
2237
|
const generateGetObjectPreSignedUrl = functions__namespace
|
|
2203
2238
|
.region("europe-west1")
|
|
2204
2239
|
.runWith({
|
|
2205
|
-
memory: "
|
|
2240
|
+
memory: "1GB"
|
|
2206
2241
|
})
|
|
2207
2242
|
.https.onCall(async (data, context) => {
|
|
2208
2243
|
if (!context.auth)
|
|
@@ -2242,7 +2277,7 @@ const generateGetObjectPreSignedUrl = functions__namespace
|
|
|
2242
2277
|
const startMultiPartUpload = functions__namespace
|
|
2243
2278
|
.region("europe-west1")
|
|
2244
2279
|
.runWith({
|
|
2245
|
-
memory: "
|
|
2280
|
+
memory: "2GB"
|
|
2246
2281
|
})
|
|
2247
2282
|
.https.onCall(async (data, context) => {
|
|
2248
2283
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2297,7 +2332,7 @@ const startMultiPartUpload = functions__namespace
|
|
|
2297
2332
|
const generatePreSignedUrlsParts = functions__namespace
|
|
2298
2333
|
.region("europe-west1")
|
|
2299
2334
|
.runWith({
|
|
2300
|
-
memory: "
|
|
2335
|
+
memory: "1GB",
|
|
2301
2336
|
timeoutSeconds: 300
|
|
2302
2337
|
})
|
|
2303
2338
|
.https.onCall(async (data, context) => {
|
|
@@ -2358,7 +2393,7 @@ const generatePreSignedUrlsParts = functions__namespace
|
|
|
2358
2393
|
const completeMultiPartUpload = functions__namespace
|
|
2359
2394
|
.region("europe-west1")
|
|
2360
2395
|
.runWith({
|
|
2361
|
-
memory: "
|
|
2396
|
+
memory: "2GB"
|
|
2362
2397
|
})
|
|
2363
2398
|
.https.onCall(async (data, context) => {
|
|
2364
2399
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2407,6 +2442,216 @@ const completeMultiPartUpload = functions__namespace
|
|
|
2407
2442
|
}
|
|
2408
2443
|
});
|
|
2409
2444
|
|
|
2445
|
+
const VKEY_DATA = {
|
|
2446
|
+
protocol: "groth16",
|
|
2447
|
+
curve: "bn128",
|
|
2448
|
+
nPublic: 3,
|
|
2449
|
+
vk_alpha_1: [
|
|
2450
|
+
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
|
2451
|
+
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
|
2452
|
+
"1"
|
|
2453
|
+
],
|
|
2454
|
+
vk_beta_2: [
|
|
2455
|
+
[
|
|
2456
|
+
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
|
2457
|
+
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
|
2458
|
+
],
|
|
2459
|
+
[
|
|
2460
|
+
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
|
2461
|
+
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
|
2462
|
+
],
|
|
2463
|
+
["1", "0"]
|
|
2464
|
+
],
|
|
2465
|
+
vk_gamma_2: [
|
|
2466
|
+
[
|
|
2467
|
+
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
|
2468
|
+
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
|
2469
|
+
],
|
|
2470
|
+
[
|
|
2471
|
+
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
|
2472
|
+
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
|
2473
|
+
],
|
|
2474
|
+
["1", "0"]
|
|
2475
|
+
],
|
|
2476
|
+
vk_delta_2: [
|
|
2477
|
+
[
|
|
2478
|
+
"3697618915467790705869942236922063775466274665053173890632463796679068973252",
|
|
2479
|
+
"14948341351907992175709156460547989243732741534604949238422596319735704165658"
|
|
2480
|
+
],
|
|
2481
|
+
[
|
|
2482
|
+
"3028459181652799888716942141752307629938889957960373621898607910203491239368",
|
|
2483
|
+
"11380736494786911280692284374675752681598754560757720296073023058533044108340"
|
|
2484
|
+
],
|
|
2485
|
+
["1", "0"]
|
|
2486
|
+
],
|
|
2487
|
+
vk_alphabeta_12: [
|
|
2488
|
+
[
|
|
2489
|
+
[
|
|
2490
|
+
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
|
2491
|
+
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
|
2492
|
+
],
|
|
2493
|
+
[
|
|
2494
|
+
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
|
2495
|
+
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
|
2496
|
+
],
|
|
2497
|
+
[
|
|
2498
|
+
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
|
2499
|
+
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
|
2500
|
+
]
|
|
2501
|
+
],
|
|
2502
|
+
[
|
|
2503
|
+
[
|
|
2504
|
+
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
|
2505
|
+
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
|
2506
|
+
],
|
|
2507
|
+
[
|
|
2508
|
+
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
|
2509
|
+
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
|
2510
|
+
],
|
|
2511
|
+
[
|
|
2512
|
+
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
|
2513
|
+
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
|
2514
|
+
]
|
|
2515
|
+
]
|
|
2516
|
+
],
|
|
2517
|
+
IC: [
|
|
2518
|
+
[
|
|
2519
|
+
"12951059800758687233303204819298121944551181861362200875212570257618182506154",
|
|
2520
|
+
"5751958719396509176593242305268064754837298673622815112953832050159760501392",
|
|
2521
|
+
"1"
|
|
2522
|
+
],
|
|
2523
|
+
[
|
|
2524
|
+
"9561588427935871983444704959674198910445823619407211599507208879011862515257",
|
|
2525
|
+
"14576201570478094842467636169770180675293504492823217349086195663150934064643",
|
|
2526
|
+
"1"
|
|
2527
|
+
],
|
|
2528
|
+
[
|
|
2529
|
+
"4811967233483727873912563574622036989372099129165459921963463310078093941559",
|
|
2530
|
+
"1874883809855039536107616044787862082553628089593740724610117059083415551067",
|
|
2531
|
+
"1"
|
|
2532
|
+
],
|
|
2533
|
+
[
|
|
2534
|
+
"12252730267779308452229639835051322390696643456253768618882001876621526827161",
|
|
2535
|
+
"7899194018737016222260328309937800777948677569409898603827268776967707173231",
|
|
2536
|
+
"1"
|
|
2537
|
+
]
|
|
2538
|
+
]
|
|
2539
|
+
};
|
|
2540
|
+
dotenv.config();
|
|
2541
|
+
const { BANDADA_API_URL, BANDADA_GROUP_ID } = process.env;
|
|
2542
|
+
const bandadaApi = new apiSdk.ApiSdk(BANDADA_API_URL);
|
|
2543
|
+
const bandadaValidateProof = functions__namespace
|
|
2544
|
+
.region("europe-west1")
|
|
2545
|
+
.runWith({
|
|
2546
|
+
memory: "512MB"
|
|
2547
|
+
})
|
|
2548
|
+
.https.onCall(async (data) => {
|
|
2549
|
+
if (!BANDADA_GROUP_ID)
|
|
2550
|
+
throw new Error("BANDADA_GROUP_ID is not defined in .env");
|
|
2551
|
+
const { proof, publicSignals } = data;
|
|
2552
|
+
const isCorrect = snarkjs.groth16.verify(VKEY_DATA, publicSignals, proof);
|
|
2553
|
+
if (!isCorrect)
|
|
2554
|
+
return {
|
|
2555
|
+
valid: false,
|
|
2556
|
+
message: "Invalid proof",
|
|
2557
|
+
token: ""
|
|
2558
|
+
};
|
|
2559
|
+
const commitment = data.publicSignals[1];
|
|
2560
|
+
const isMember = await bandadaApi.isGroupMember(BANDADA_GROUP_ID, commitment);
|
|
2561
|
+
if (!isMember)
|
|
2562
|
+
return {
|
|
2563
|
+
valid: false,
|
|
2564
|
+
message: "Not a member of the group",
|
|
2565
|
+
token: ""
|
|
2566
|
+
};
|
|
2567
|
+
const auth$1 = auth.getAuth();
|
|
2568
|
+
try {
|
|
2569
|
+
await admin.auth().createUser({
|
|
2570
|
+
uid: commitment
|
|
2571
|
+
});
|
|
2572
|
+
}
|
|
2573
|
+
catch (error) {
|
|
2574
|
+
// if user already exist then just pass
|
|
2575
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
2576
|
+
throw new Error(error);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
const token = await auth$1.createCustomToken(commitment);
|
|
2580
|
+
return {
|
|
2581
|
+
valid: true,
|
|
2582
|
+
message: "Valid proof and group member",
|
|
2583
|
+
token
|
|
2584
|
+
};
|
|
2585
|
+
});
|
|
2586
|
+
|
|
2587
|
+
dotenv.config();
|
|
2588
|
+
const checkNonceOfSIWEAddress = functions__namespace
|
|
2589
|
+
.region("europe-west1")
|
|
2590
|
+
.runWith({ memory: "1GB" })
|
|
2591
|
+
.https.onCall(async (data) => {
|
|
2592
|
+
try {
|
|
2593
|
+
const { auth0Token } = data;
|
|
2594
|
+
const result = (await fetch(`${process.env.AUTH0_APPLICATION_URL}/userinfo`, {
|
|
2595
|
+
method: "GET",
|
|
2596
|
+
headers: {
|
|
2597
|
+
"content-type": "application/json",
|
|
2598
|
+
authorization: `Bearer ${auth0Token}`
|
|
2599
|
+
}
|
|
2600
|
+
}).then((_res) => _res.json()));
|
|
2601
|
+
if (!result.sub) {
|
|
2602
|
+
return {
|
|
2603
|
+
valid: false,
|
|
2604
|
+
message: "No user detected. Please check device flow token"
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
const auth$1 = auth.getAuth();
|
|
2608
|
+
// check nonce
|
|
2609
|
+
const parts = result.sub.split("|");
|
|
2610
|
+
const address = decodeURIComponent(parts[2]).split(":")[2];
|
|
2611
|
+
const minimumNonce = Number(process.env.ETH_MINIMUM_NONCE);
|
|
2612
|
+
const nonceBlockHeight = "latest"; // process.env.ETH_NONCE_BLOCK_HEIGHT
|
|
2613
|
+
// look up nonce for address @block
|
|
2614
|
+
let nonceOk = true;
|
|
2615
|
+
if (minimumNonce > 0) {
|
|
2616
|
+
const provider = setEthProvider();
|
|
2617
|
+
console.log(`got provider - block # ${await provider.getBlockNumber()}`);
|
|
2618
|
+
const nonce = await provider.getTransactionCount(address, nonceBlockHeight);
|
|
2619
|
+
console.log(`nonce ${nonce}`);
|
|
2620
|
+
nonceOk = nonce >= minimumNonce;
|
|
2621
|
+
}
|
|
2622
|
+
console.log(`checking nonce ${nonceOk}`);
|
|
2623
|
+
if (!nonceOk) {
|
|
2624
|
+
return {
|
|
2625
|
+
valid: false,
|
|
2626
|
+
message: "Eth address does not meet the nonce requirements"
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
try {
|
|
2630
|
+
await admin.auth().createUser({
|
|
2631
|
+
displayName: address,
|
|
2632
|
+
uid: address
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
catch (error) {
|
|
2636
|
+
// if user already exist then just pass
|
|
2637
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
2638
|
+
throw new Error(error);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
const token = await auth$1.createCustomToken(address);
|
|
2642
|
+
return {
|
|
2643
|
+
valid: true,
|
|
2644
|
+
token
|
|
2645
|
+
};
|
|
2646
|
+
}
|
|
2647
|
+
catch (error) {
|
|
2648
|
+
return {
|
|
2649
|
+
valid: false,
|
|
2650
|
+
message: `Something went wrong ${error}`
|
|
2651
|
+
};
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
|
|
2410
2655
|
dotenv.config();
|
|
2411
2656
|
/**
|
|
2412
2657
|
* Check and remove the current contributor if it doesn't complete the contribution on the specified amount of time.
|
|
@@ -2429,7 +2674,7 @@ dotenv.config();
|
|
|
2429
2674
|
const checkAndRemoveBlockingContributor = functions__namespace
|
|
2430
2675
|
.region("europe-west1")
|
|
2431
2676
|
.runWith({
|
|
2432
|
-
memory: "
|
|
2677
|
+
memory: "1GB"
|
|
2433
2678
|
})
|
|
2434
2679
|
.pubsub.schedule("every 1 minutes")
|
|
2435
2680
|
.onRun(async () => {
|
|
@@ -2498,7 +2743,8 @@ const checkAndRemoveBlockingContributor = functions__namespace
|
|
|
2498
2743
|
if (timeoutExpirationDateInMsForBlockingContributor < currentServerTimestamp &&
|
|
2499
2744
|
(contributionStep === "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */ ||
|
|
2500
2745
|
contributionStep === "COMPUTING" /* ParticipantContributionStep.COMPUTING */ ||
|
|
2501
|
-
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */
|
|
2746
|
+
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */ ||
|
|
2747
|
+
contributionStep === "COMPLETED" /* ParticipantContributionStep.COMPLETED */))
|
|
2502
2748
|
timeoutType = "BLOCKING_CONTRIBUTION" /* TimeoutType.BLOCKING_CONTRIBUTION */;
|
|
2503
2749
|
if (timeoutExpirationDateInMsForVerificationCloudFunction > 0 &&
|
|
2504
2750
|
timeoutExpirationDateInMsForVerificationCloudFunction < currentServerTimestamp &&
|
|
@@ -2575,7 +2821,7 @@ const checkAndRemoveBlockingContributor = functions__namespace
|
|
|
2575
2821
|
const resumeContributionAfterTimeoutExpiration = functions__namespace
|
|
2576
2822
|
.region("europe-west1")
|
|
2577
2823
|
.runWith({
|
|
2578
|
-
memory: "
|
|
2824
|
+
memory: "1GB"
|
|
2579
2825
|
})
|
|
2580
2826
|
.https.onCall(async (data, context) => {
|
|
2581
2827
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2608,9 +2854,11 @@ const resumeContributionAfterTimeoutExpiration = functions__namespace
|
|
|
2608
2854
|
|
|
2609
2855
|
admin.initializeApp();
|
|
2610
2856
|
|
|
2857
|
+
exports.bandadaValidateProof = bandadaValidateProof;
|
|
2611
2858
|
exports.checkAndPrepareCoordinatorForFinalization = checkAndPrepareCoordinatorForFinalization;
|
|
2612
2859
|
exports.checkAndRemoveBlockingContributor = checkAndRemoveBlockingContributor;
|
|
2613
2860
|
exports.checkIfObjectExist = checkIfObjectExist;
|
|
2861
|
+
exports.checkNonceOfSIWEAddress = checkNonceOfSIWEAddress;
|
|
2614
2862
|
exports.checkParticipantForCeremony = checkParticipantForCeremony;
|
|
2615
2863
|
exports.completeMultiPartUpload = completeMultiPartUpload;
|
|
2616
2864
|
exports.coordinateCeremonyParticipant = coordinateCeremonyParticipant;
|