@devtion/backend 0.0.0-57a8ab9 → 0.0.0-5fad82d
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 +129 -26
- package/dist/src/functions/index.mjs +129 -27
- package/dist/types/functions/bandada.d.ts.map +1 -1
- package/dist/types/functions/index.d.ts +1 -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/services.d.ts +7 -0
- package/dist/types/lib/services.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +31 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/functions/bandada.ts +1 -2
- package/src/functions/ceremony.ts +4 -4
- package/src/functions/circuit.ts +3 -3
- package/src/functions/index.ts +1 -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 +2 -2
- package/src/lib/services.ts +36 -0
- package/src/types/index.ts +33 -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,6 +27,7 @@ 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');
|
|
@@ -166,6 +167,8 @@ const COMMON_ERRORS = {
|
|
|
166
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.")
|
|
167
168
|
};
|
|
168
169
|
|
|
170
|
+
dotenv.config();
|
|
171
|
+
let provider;
|
|
169
172
|
/**
|
|
170
173
|
* Return a configured and connected instance of the AWS S3 client.
|
|
171
174
|
* @dev this method check and utilize the environment variables to configure the connection
|
|
@@ -188,6 +191,36 @@ const getS3Client = async () => {
|
|
|
188
191
|
region: process.env.AWS_REGION
|
|
189
192
|
});
|
|
190
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
|
+
};
|
|
191
224
|
|
|
192
225
|
dotenv.config();
|
|
193
226
|
/**
|
|
@@ -526,7 +559,7 @@ dotenv.config();
|
|
|
526
559
|
const registerAuthUser = functions__namespace
|
|
527
560
|
.region("europe-west1")
|
|
528
561
|
.runWith({
|
|
529
|
-
memory: "
|
|
562
|
+
memory: "1GB"
|
|
530
563
|
})
|
|
531
564
|
.auth.user()
|
|
532
565
|
.onCreate(async (user) => {
|
|
@@ -613,7 +646,7 @@ const registerAuthUser = functions__namespace
|
|
|
613
646
|
const processSignUpWithCustomClaims = functions__namespace
|
|
614
647
|
.region("europe-west1")
|
|
615
648
|
.runWith({
|
|
616
|
-
memory: "
|
|
649
|
+
memory: "1GB"
|
|
617
650
|
})
|
|
618
651
|
.auth.user()
|
|
619
652
|
.onCreate(async (user) => {
|
|
@@ -654,7 +687,7 @@ dotenv.config();
|
|
|
654
687
|
const startCeremony = functions__namespace
|
|
655
688
|
.region("europe-west1")
|
|
656
689
|
.runWith({
|
|
657
|
-
memory: "
|
|
690
|
+
memory: "1GB"
|
|
658
691
|
})
|
|
659
692
|
.pubsub.schedule(`every 30 minutes`)
|
|
660
693
|
.onRun(async () => {
|
|
@@ -676,7 +709,7 @@ const startCeremony = functions__namespace
|
|
|
676
709
|
const stopCeremony = functions__namespace
|
|
677
710
|
.region("europe-west1")
|
|
678
711
|
.runWith({
|
|
679
|
-
memory: "
|
|
712
|
+
memory: "1GB"
|
|
680
713
|
})
|
|
681
714
|
.pubsub.schedule(`every 30 minutes`)
|
|
682
715
|
.onRun(async () => {
|
|
@@ -698,7 +731,7 @@ const stopCeremony = functions__namespace
|
|
|
698
731
|
const setupCeremony = functions__namespace
|
|
699
732
|
.region("europe-west1")
|
|
700
733
|
.runWith({
|
|
701
|
-
memory: "
|
|
734
|
+
memory: "1GB"
|
|
702
735
|
})
|
|
703
736
|
.https.onCall(async (data, context) => {
|
|
704
737
|
// Check if the user has the coordinator claim.
|
|
@@ -823,7 +856,7 @@ const initEmptyWaitingQueueForCircuit = functions__namespace
|
|
|
823
856
|
const finalizeCeremony = functions__namespace
|
|
824
857
|
.region("europe-west1")
|
|
825
858
|
.runWith({
|
|
826
|
-
memory: "
|
|
859
|
+
memory: "1GB"
|
|
827
860
|
})
|
|
828
861
|
.https.onCall(async (data, context) => {
|
|
829
862
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -899,7 +932,7 @@ dotenv.config();
|
|
|
899
932
|
const checkParticipantForCeremony = functions__namespace
|
|
900
933
|
.region("europe-west1")
|
|
901
934
|
.runWith({
|
|
902
|
-
memory: "
|
|
935
|
+
memory: "1GB"
|
|
903
936
|
})
|
|
904
937
|
.https.onCall(async (data, context) => {
|
|
905
938
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1003,7 +1036,7 @@ const checkParticipantForCeremony = functions__namespace
|
|
|
1003
1036
|
const progressToNextCircuitForContribution = functions__namespace
|
|
1004
1037
|
.region("europe-west1")
|
|
1005
1038
|
.runWith({
|
|
1006
|
-
memory: "
|
|
1039
|
+
memory: "1GB"
|
|
1007
1040
|
})
|
|
1008
1041
|
.https.onCall(async (data, context) => {
|
|
1009
1042
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1050,7 +1083,7 @@ const progressToNextCircuitForContribution = functions__namespace
|
|
|
1050
1083
|
const progressToNextContributionStep = functions__namespace
|
|
1051
1084
|
.region("europe-west1")
|
|
1052
1085
|
.runWith({
|
|
1053
|
-
memory: "
|
|
1086
|
+
memory: "1GB"
|
|
1054
1087
|
})
|
|
1055
1088
|
.https.onCall(async (data, context) => {
|
|
1056
1089
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1101,7 +1134,7 @@ const progressToNextContributionStep = functions__namespace
|
|
|
1101
1134
|
const permanentlyStoreCurrentContributionTimeAndHash = functions__namespace
|
|
1102
1135
|
.region("europe-west1")
|
|
1103
1136
|
.runWith({
|
|
1104
|
-
memory: "
|
|
1137
|
+
memory: "1GB"
|
|
1105
1138
|
})
|
|
1106
1139
|
.https.onCall(async (data, context) => {
|
|
1107
1140
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1143,7 +1176,7 @@ const permanentlyStoreCurrentContributionTimeAndHash = functions__namespace
|
|
|
1143
1176
|
const temporaryStoreCurrentContributionMultiPartUploadId = functions__namespace
|
|
1144
1177
|
.region("europe-west1")
|
|
1145
1178
|
.runWith({
|
|
1146
|
-
memory: "
|
|
1179
|
+
memory: "1GB"
|
|
1147
1180
|
})
|
|
1148
1181
|
.https.onCall(async (data, context) => {
|
|
1149
1182
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1181,7 +1214,7 @@ const temporaryStoreCurrentContributionMultiPartUploadId = functions__namespace
|
|
|
1181
1214
|
const temporaryStoreCurrentContributionUploadedChunkData = functions__namespace
|
|
1182
1215
|
.region("europe-west1")
|
|
1183
1216
|
.runWith({
|
|
1184
|
-
memory: "
|
|
1217
|
+
memory: "1GB"
|
|
1185
1218
|
})
|
|
1186
1219
|
.https.onCall(async (data, context) => {
|
|
1187
1220
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1223,7 +1256,7 @@ const temporaryStoreCurrentContributionUploadedChunkData = functions__namespace
|
|
|
1223
1256
|
const checkAndPrepareCoordinatorForFinalization = functions__namespace
|
|
1224
1257
|
.region("europe-west1")
|
|
1225
1258
|
.runWith({
|
|
1226
|
-
memory: "
|
|
1259
|
+
memory: "1GB"
|
|
1227
1260
|
})
|
|
1228
1261
|
.https.onCall(async (data, context) => {
|
|
1229
1262
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -1463,7 +1496,7 @@ const waitForVMCommandExecution = (ssm, vmInstanceId, commandId) => new Promise(
|
|
|
1463
1496
|
const coordinateCeremonyParticipant = functionsV1__namespace
|
|
1464
1497
|
.region("europe-west1")
|
|
1465
1498
|
.runWith({
|
|
1466
|
-
memory: "
|
|
1499
|
+
memory: "1GB"
|
|
1467
1500
|
})
|
|
1468
1501
|
.firestore.document(`${actions.commonTerms.collections.ceremonies.name}/{ceremonyId}/${actions.commonTerms.collections.participants.name}/{participantId}`)
|
|
1469
1502
|
.onUpdate(async (participantChanges) => {
|
|
@@ -1863,7 +1896,7 @@ const verifycontribution = functionsV2__namespace.https.onCall({ memory: "16GiB"
|
|
|
1863
1896
|
const refreshParticipantAfterContributionVerification = functionsV1__namespace
|
|
1864
1897
|
.region("europe-west1")
|
|
1865
1898
|
.runWith({
|
|
1866
|
-
memory: "
|
|
1899
|
+
memory: "1GB"
|
|
1867
1900
|
})
|
|
1868
1901
|
.firestore.document(`/${actions.commonTerms.collections.ceremonies.name}/{ceremony}/${actions.commonTerms.collections.circuits.name}/{circuit}/${actions.commonTerms.collections.contributions.name}/{contributions}`)
|
|
1869
1902
|
.onCreate(async (createdContribution) => {
|
|
@@ -1924,7 +1957,7 @@ const refreshParticipantAfterContributionVerification = functionsV1__namespace
|
|
|
1924
1957
|
const finalizeCircuit = functionsV1__namespace
|
|
1925
1958
|
.region("europe-west1")
|
|
1926
1959
|
.runWith({
|
|
1927
|
-
memory: "
|
|
1960
|
+
memory: "1GB"
|
|
1928
1961
|
})
|
|
1929
1962
|
.https.onCall(async (data, context) => {
|
|
1930
1963
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -2068,7 +2101,7 @@ const checkIfBucketIsDedicatedToCeremony = async (bucketName) => {
|
|
|
2068
2101
|
const createBucket = functions__namespace
|
|
2069
2102
|
.region("europe-west1")
|
|
2070
2103
|
.runWith({
|
|
2071
|
-
memory: "
|
|
2104
|
+
memory: "1GB"
|
|
2072
2105
|
})
|
|
2073
2106
|
.https.onCall(async (data, context) => {
|
|
2074
2107
|
// Check if the user has the coordinator claim.
|
|
@@ -2158,7 +2191,7 @@ const createBucket = functions__namespace
|
|
|
2158
2191
|
const checkIfObjectExist = functions__namespace
|
|
2159
2192
|
.region("europe-west1")
|
|
2160
2193
|
.runWith({
|
|
2161
|
-
memory: "
|
|
2194
|
+
memory: "1GB"
|
|
2162
2195
|
})
|
|
2163
2196
|
.https.onCall(async (data, context) => {
|
|
2164
2197
|
// Check if the user has the coordinator claim.
|
|
@@ -2204,7 +2237,7 @@ const checkIfObjectExist = functions__namespace
|
|
|
2204
2237
|
const generateGetObjectPreSignedUrl = functions__namespace
|
|
2205
2238
|
.region("europe-west1")
|
|
2206
2239
|
.runWith({
|
|
2207
|
-
memory: "
|
|
2240
|
+
memory: "1GB"
|
|
2208
2241
|
})
|
|
2209
2242
|
.https.onCall(async (data, context) => {
|
|
2210
2243
|
if (!context.auth)
|
|
@@ -2244,7 +2277,7 @@ const generateGetObjectPreSignedUrl = functions__namespace
|
|
|
2244
2277
|
const startMultiPartUpload = functions__namespace
|
|
2245
2278
|
.region("europe-west1")
|
|
2246
2279
|
.runWith({
|
|
2247
|
-
memory: "
|
|
2280
|
+
memory: "2GB"
|
|
2248
2281
|
})
|
|
2249
2282
|
.https.onCall(async (data, context) => {
|
|
2250
2283
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2299,7 +2332,7 @@ const startMultiPartUpload = functions__namespace
|
|
|
2299
2332
|
const generatePreSignedUrlsParts = functions__namespace
|
|
2300
2333
|
.region("europe-west1")
|
|
2301
2334
|
.runWith({
|
|
2302
|
-
memory: "
|
|
2335
|
+
memory: "1GB",
|
|
2303
2336
|
timeoutSeconds: 300
|
|
2304
2337
|
})
|
|
2305
2338
|
.https.onCall(async (data, context) => {
|
|
@@ -2360,7 +2393,7 @@ const generatePreSignedUrlsParts = functions__namespace
|
|
|
2360
2393
|
const completeMultiPartUpload = functions__namespace
|
|
2361
2394
|
.region("europe-west1")
|
|
2362
2395
|
.runWith({
|
|
2363
|
-
memory: "
|
|
2396
|
+
memory: "2GB"
|
|
2364
2397
|
})
|
|
2365
2398
|
.https.onCall(async (data, context) => {
|
|
2366
2399
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2551,6 +2584,74 @@ const bandadaValidateProof = functions__namespace
|
|
|
2551
2584
|
};
|
|
2552
2585
|
});
|
|
2553
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
|
+
|
|
2554
2655
|
dotenv.config();
|
|
2555
2656
|
/**
|
|
2556
2657
|
* Check and remove the current contributor if it doesn't complete the contribution on the specified amount of time.
|
|
@@ -2573,7 +2674,7 @@ dotenv.config();
|
|
|
2573
2674
|
const checkAndRemoveBlockingContributor = functions__namespace
|
|
2574
2675
|
.region("europe-west1")
|
|
2575
2676
|
.runWith({
|
|
2576
|
-
memory: "
|
|
2677
|
+
memory: "1GB"
|
|
2577
2678
|
})
|
|
2578
2679
|
.pubsub.schedule("every 1 minutes")
|
|
2579
2680
|
.onRun(async () => {
|
|
@@ -2642,7 +2743,8 @@ const checkAndRemoveBlockingContributor = functions__namespace
|
|
|
2642
2743
|
if (timeoutExpirationDateInMsForBlockingContributor < currentServerTimestamp &&
|
|
2643
2744
|
(contributionStep === "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */ ||
|
|
2644
2745
|
contributionStep === "COMPUTING" /* ParticipantContributionStep.COMPUTING */ ||
|
|
2645
|
-
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */
|
|
2746
|
+
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */ ||
|
|
2747
|
+
contributionStep === "COMPLETED" /* ParticipantContributionStep.COMPLETED */))
|
|
2646
2748
|
timeoutType = "BLOCKING_CONTRIBUTION" /* TimeoutType.BLOCKING_CONTRIBUTION */;
|
|
2647
2749
|
if (timeoutExpirationDateInMsForVerificationCloudFunction > 0 &&
|
|
2648
2750
|
timeoutExpirationDateInMsForVerificationCloudFunction < currentServerTimestamp &&
|
|
@@ -2719,7 +2821,7 @@ const checkAndRemoveBlockingContributor = functions__namespace
|
|
|
2719
2821
|
const resumeContributionAfterTimeoutExpiration = functions__namespace
|
|
2720
2822
|
.region("europe-west1")
|
|
2721
2823
|
.runWith({
|
|
2722
|
-
memory: "
|
|
2824
|
+
memory: "1GB"
|
|
2723
2825
|
})
|
|
2724
2826
|
.https.onCall(async (data, context) => {
|
|
2725
2827
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2756,6 +2858,7 @@ exports.bandadaValidateProof = bandadaValidateProof;
|
|
|
2756
2858
|
exports.checkAndPrepareCoordinatorForFinalization = checkAndPrepareCoordinatorForFinalization;
|
|
2757
2859
|
exports.checkAndRemoveBlockingContributor = checkAndRemoveBlockingContributor;
|
|
2758
2860
|
exports.checkIfObjectExist = checkIfObjectExist;
|
|
2861
|
+
exports.checkNonceOfSIWEAddress = checkNonceOfSIWEAddress;
|
|
2759
2862
|
exports.checkParticipantForCeremony = checkParticipantForCeremony;
|
|
2760
2863
|
exports.completeMultiPartUpload = completeMultiPartUpload;
|
|
2761
2864
|
exports.coordinateCeremonyParticipant = coordinateCeremonyParticipant;
|
|
@@ -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,6 +25,7 @@ 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';
|
|
@@ -143,6 +144,8 @@ const COMMON_ERRORS = {
|
|
|
143
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.")
|
|
144
145
|
};
|
|
145
146
|
|
|
147
|
+
dotenv.config();
|
|
148
|
+
let provider;
|
|
146
149
|
/**
|
|
147
150
|
* Return a configured and connected instance of the AWS S3 client.
|
|
148
151
|
* @dev this method check and utilize the environment variables to configure the connection
|
|
@@ -165,6 +168,36 @@ const getS3Client = async () => {
|
|
|
165
168
|
region: process.env.AWS_REGION
|
|
166
169
|
});
|
|
167
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
|
+
};
|
|
168
201
|
|
|
169
202
|
dotenv.config();
|
|
170
203
|
/**
|
|
@@ -503,7 +536,7 @@ dotenv.config();
|
|
|
503
536
|
const registerAuthUser = functions
|
|
504
537
|
.region("europe-west1")
|
|
505
538
|
.runWith({
|
|
506
|
-
memory: "
|
|
539
|
+
memory: "1GB"
|
|
507
540
|
})
|
|
508
541
|
.auth.user()
|
|
509
542
|
.onCreate(async (user) => {
|
|
@@ -590,7 +623,7 @@ const registerAuthUser = functions
|
|
|
590
623
|
const processSignUpWithCustomClaims = functions
|
|
591
624
|
.region("europe-west1")
|
|
592
625
|
.runWith({
|
|
593
|
-
memory: "
|
|
626
|
+
memory: "1GB"
|
|
594
627
|
})
|
|
595
628
|
.auth.user()
|
|
596
629
|
.onCreate(async (user) => {
|
|
@@ -631,7 +664,7 @@ dotenv.config();
|
|
|
631
664
|
const startCeremony = functions
|
|
632
665
|
.region("europe-west1")
|
|
633
666
|
.runWith({
|
|
634
|
-
memory: "
|
|
667
|
+
memory: "1GB"
|
|
635
668
|
})
|
|
636
669
|
.pubsub.schedule(`every 30 minutes`)
|
|
637
670
|
.onRun(async () => {
|
|
@@ -653,7 +686,7 @@ const startCeremony = functions
|
|
|
653
686
|
const stopCeremony = functions
|
|
654
687
|
.region("europe-west1")
|
|
655
688
|
.runWith({
|
|
656
|
-
memory: "
|
|
689
|
+
memory: "1GB"
|
|
657
690
|
})
|
|
658
691
|
.pubsub.schedule(`every 30 minutes`)
|
|
659
692
|
.onRun(async () => {
|
|
@@ -675,7 +708,7 @@ const stopCeremony = functions
|
|
|
675
708
|
const setupCeremony = functions
|
|
676
709
|
.region("europe-west1")
|
|
677
710
|
.runWith({
|
|
678
|
-
memory: "
|
|
711
|
+
memory: "1GB"
|
|
679
712
|
})
|
|
680
713
|
.https.onCall(async (data, context) => {
|
|
681
714
|
// Check if the user has the coordinator claim.
|
|
@@ -800,7 +833,7 @@ const initEmptyWaitingQueueForCircuit = functions
|
|
|
800
833
|
const finalizeCeremony = functions
|
|
801
834
|
.region("europe-west1")
|
|
802
835
|
.runWith({
|
|
803
|
-
memory: "
|
|
836
|
+
memory: "1GB"
|
|
804
837
|
})
|
|
805
838
|
.https.onCall(async (data, context) => {
|
|
806
839
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -876,7 +909,7 @@ dotenv.config();
|
|
|
876
909
|
const checkParticipantForCeremony = functions
|
|
877
910
|
.region("europe-west1")
|
|
878
911
|
.runWith({
|
|
879
|
-
memory: "
|
|
912
|
+
memory: "1GB"
|
|
880
913
|
})
|
|
881
914
|
.https.onCall(async (data, context) => {
|
|
882
915
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -980,7 +1013,7 @@ const checkParticipantForCeremony = functions
|
|
|
980
1013
|
const progressToNextCircuitForContribution = functions
|
|
981
1014
|
.region("europe-west1")
|
|
982
1015
|
.runWith({
|
|
983
|
-
memory: "
|
|
1016
|
+
memory: "1GB"
|
|
984
1017
|
})
|
|
985
1018
|
.https.onCall(async (data, context) => {
|
|
986
1019
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1027,7 +1060,7 @@ const progressToNextCircuitForContribution = functions
|
|
|
1027
1060
|
const progressToNextContributionStep = functions
|
|
1028
1061
|
.region("europe-west1")
|
|
1029
1062
|
.runWith({
|
|
1030
|
-
memory: "
|
|
1063
|
+
memory: "1GB"
|
|
1031
1064
|
})
|
|
1032
1065
|
.https.onCall(async (data, context) => {
|
|
1033
1066
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1078,7 +1111,7 @@ const progressToNextContributionStep = functions
|
|
|
1078
1111
|
const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
1079
1112
|
.region("europe-west1")
|
|
1080
1113
|
.runWith({
|
|
1081
|
-
memory: "
|
|
1114
|
+
memory: "1GB"
|
|
1082
1115
|
})
|
|
1083
1116
|
.https.onCall(async (data, context) => {
|
|
1084
1117
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1120,7 +1153,7 @@ const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
|
1120
1153
|
const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
1121
1154
|
.region("europe-west1")
|
|
1122
1155
|
.runWith({
|
|
1123
|
-
memory: "
|
|
1156
|
+
memory: "1GB"
|
|
1124
1157
|
})
|
|
1125
1158
|
.https.onCall(async (data, context) => {
|
|
1126
1159
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1158,7 +1191,7 @@ const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
|
1158
1191
|
const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
1159
1192
|
.region("europe-west1")
|
|
1160
1193
|
.runWith({
|
|
1161
|
-
memory: "
|
|
1194
|
+
memory: "1GB"
|
|
1162
1195
|
})
|
|
1163
1196
|
.https.onCall(async (data, context) => {
|
|
1164
1197
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -1200,7 +1233,7 @@ const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
|
1200
1233
|
const checkAndPrepareCoordinatorForFinalization = functions
|
|
1201
1234
|
.region("europe-west1")
|
|
1202
1235
|
.runWith({
|
|
1203
|
-
memory: "
|
|
1236
|
+
memory: "1GB"
|
|
1204
1237
|
})
|
|
1205
1238
|
.https.onCall(async (data, context) => {
|
|
1206
1239
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -1440,7 +1473,7 @@ const waitForVMCommandExecution = (ssm, vmInstanceId, commandId) => new Promise(
|
|
|
1440
1473
|
const coordinateCeremonyParticipant = functionsV1
|
|
1441
1474
|
.region("europe-west1")
|
|
1442
1475
|
.runWith({
|
|
1443
|
-
memory: "
|
|
1476
|
+
memory: "1GB"
|
|
1444
1477
|
})
|
|
1445
1478
|
.firestore.document(`${commonTerms.collections.ceremonies.name}/{ceremonyId}/${commonTerms.collections.participants.name}/{participantId}`)
|
|
1446
1479
|
.onUpdate(async (participantChanges) => {
|
|
@@ -1840,7 +1873,7 @@ const verifycontribution = functionsV2.https.onCall({ memory: "16GiB", timeoutSe
|
|
|
1840
1873
|
const refreshParticipantAfterContributionVerification = functionsV1
|
|
1841
1874
|
.region("europe-west1")
|
|
1842
1875
|
.runWith({
|
|
1843
|
-
memory: "
|
|
1876
|
+
memory: "1GB"
|
|
1844
1877
|
})
|
|
1845
1878
|
.firestore.document(`/${commonTerms.collections.ceremonies.name}/{ceremony}/${commonTerms.collections.circuits.name}/{circuit}/${commonTerms.collections.contributions.name}/{contributions}`)
|
|
1846
1879
|
.onCreate(async (createdContribution) => {
|
|
@@ -1901,7 +1934,7 @@ const refreshParticipantAfterContributionVerification = functionsV1
|
|
|
1901
1934
|
const finalizeCircuit = functionsV1
|
|
1902
1935
|
.region("europe-west1")
|
|
1903
1936
|
.runWith({
|
|
1904
|
-
memory: "
|
|
1937
|
+
memory: "1GB"
|
|
1905
1938
|
})
|
|
1906
1939
|
.https.onCall(async (data, context) => {
|
|
1907
1940
|
if (!context.auth || !context.auth.token.coordinator)
|
|
@@ -2045,7 +2078,7 @@ const checkIfBucketIsDedicatedToCeremony = async (bucketName) => {
|
|
|
2045
2078
|
const createBucket = functions
|
|
2046
2079
|
.region("europe-west1")
|
|
2047
2080
|
.runWith({
|
|
2048
|
-
memory: "
|
|
2081
|
+
memory: "1GB"
|
|
2049
2082
|
})
|
|
2050
2083
|
.https.onCall(async (data, context) => {
|
|
2051
2084
|
// Check if the user has the coordinator claim.
|
|
@@ -2135,7 +2168,7 @@ const createBucket = functions
|
|
|
2135
2168
|
const checkIfObjectExist = functions
|
|
2136
2169
|
.region("europe-west1")
|
|
2137
2170
|
.runWith({
|
|
2138
|
-
memory: "
|
|
2171
|
+
memory: "1GB"
|
|
2139
2172
|
})
|
|
2140
2173
|
.https.onCall(async (data, context) => {
|
|
2141
2174
|
// Check if the user has the coordinator claim.
|
|
@@ -2181,7 +2214,7 @@ const checkIfObjectExist = functions
|
|
|
2181
2214
|
const generateGetObjectPreSignedUrl = functions
|
|
2182
2215
|
.region("europe-west1")
|
|
2183
2216
|
.runWith({
|
|
2184
|
-
memory: "
|
|
2217
|
+
memory: "1GB"
|
|
2185
2218
|
})
|
|
2186
2219
|
.https.onCall(async (data, context) => {
|
|
2187
2220
|
if (!context.auth)
|
|
@@ -2221,7 +2254,7 @@ const generateGetObjectPreSignedUrl = functions
|
|
|
2221
2254
|
const startMultiPartUpload = functions
|
|
2222
2255
|
.region("europe-west1")
|
|
2223
2256
|
.runWith({
|
|
2224
|
-
memory: "
|
|
2257
|
+
memory: "2GB"
|
|
2225
2258
|
})
|
|
2226
2259
|
.https.onCall(async (data, context) => {
|
|
2227
2260
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2276,7 +2309,7 @@ const startMultiPartUpload = functions
|
|
|
2276
2309
|
const generatePreSignedUrlsParts = functions
|
|
2277
2310
|
.region("europe-west1")
|
|
2278
2311
|
.runWith({
|
|
2279
|
-
memory: "
|
|
2312
|
+
memory: "1GB",
|
|
2280
2313
|
timeoutSeconds: 300
|
|
2281
2314
|
})
|
|
2282
2315
|
.https.onCall(async (data, context) => {
|
|
@@ -2337,7 +2370,7 @@ const generatePreSignedUrlsParts = functions
|
|
|
2337
2370
|
const completeMultiPartUpload = functions
|
|
2338
2371
|
.region("europe-west1")
|
|
2339
2372
|
.runWith({
|
|
2340
|
-
memory: "
|
|
2373
|
+
memory: "2GB"
|
|
2341
2374
|
})
|
|
2342
2375
|
.https.onCall(async (data, context) => {
|
|
2343
2376
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2528,6 +2561,74 @@ const bandadaValidateProof = functions
|
|
|
2528
2561
|
};
|
|
2529
2562
|
});
|
|
2530
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
|
+
|
|
2531
2632
|
dotenv.config();
|
|
2532
2633
|
/**
|
|
2533
2634
|
* Check and remove the current contributor if it doesn't complete the contribution on the specified amount of time.
|
|
@@ -2550,7 +2651,7 @@ dotenv.config();
|
|
|
2550
2651
|
const checkAndRemoveBlockingContributor = functions
|
|
2551
2652
|
.region("europe-west1")
|
|
2552
2653
|
.runWith({
|
|
2553
|
-
memory: "
|
|
2654
|
+
memory: "1GB"
|
|
2554
2655
|
})
|
|
2555
2656
|
.pubsub.schedule("every 1 minutes")
|
|
2556
2657
|
.onRun(async () => {
|
|
@@ -2619,7 +2720,8 @@ const checkAndRemoveBlockingContributor = functions
|
|
|
2619
2720
|
if (timeoutExpirationDateInMsForBlockingContributor < currentServerTimestamp &&
|
|
2620
2721
|
(contributionStep === "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */ ||
|
|
2621
2722
|
contributionStep === "COMPUTING" /* ParticipantContributionStep.COMPUTING */ ||
|
|
2622
|
-
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */
|
|
2723
|
+
contributionStep === "UPLOADING" /* ParticipantContributionStep.UPLOADING */ ||
|
|
2724
|
+
contributionStep === "COMPLETED" /* ParticipantContributionStep.COMPLETED */))
|
|
2623
2725
|
timeoutType = "BLOCKING_CONTRIBUTION" /* TimeoutType.BLOCKING_CONTRIBUTION */;
|
|
2624
2726
|
if (timeoutExpirationDateInMsForVerificationCloudFunction > 0 &&
|
|
2625
2727
|
timeoutExpirationDateInMsForVerificationCloudFunction < currentServerTimestamp &&
|
|
@@ -2696,7 +2798,7 @@ const checkAndRemoveBlockingContributor = functions
|
|
|
2696
2798
|
const resumeContributionAfterTimeoutExpiration = functions
|
|
2697
2799
|
.region("europe-west1")
|
|
2698
2800
|
.runWith({
|
|
2699
|
-
memory: "
|
|
2801
|
+
memory: "1GB"
|
|
2700
2802
|
})
|
|
2701
2803
|
.https.onCall(async (data, context) => {
|
|
2702
2804
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -2729,4 +2831,4 @@ const resumeContributionAfterTimeoutExpiration = functions
|
|
|
2729
2831
|
|
|
2730
2832
|
admin.initializeApp();
|
|
2731
2833
|
|
|
2732
|
-
export { bandadaValidateProof, 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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bandada.d.ts","sourceRoot":"","sources":["../../../src/functions/bandada.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;
|
|
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"}
|
|
@@ -4,5 +4,6 @@ export { checkParticipantForCeremony, progressToNextContributionStep, permanentl
|
|
|
4
4
|
export { coordinateCeremonyParticipant, verifycontribution, refreshParticipantAfterContributionVerification, finalizeCircuit } from "./circuit";
|
|
5
5
|
export { createBucket, checkIfObjectExist, generateGetObjectPreSignedUrl, startMultiPartUpload, generatePreSignedUrlsParts, completeMultiPartUpload } from "./storage";
|
|
6
6
|
export { bandadaValidateProof } from "./bandada";
|
|
7
|
+
export { checkNonceOfSIWEAddress } from "./siwe";
|
|
7
8
|
export { checkAndRemoveBlockingContributor, resumeContributionAfterTimeoutExpiration } from "./timeout";
|
|
8
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,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,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"}
|
|
@@ -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"}
|
|
@@ -152,4 +152,35 @@ export type VerifiedBandadaResponse = {
|
|
|
152
152
|
message: string;
|
|
153
153
|
token: string;
|
|
154
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
|
+
};
|
|
155
186
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,CAAA;CACnC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,8BAA8B,GAAG,sBAAsB,GAAG;IAClE,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAAG;IAC/D,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IACzD,UAAU,EAAE,MAAM,CAAA;IAClB,2BAA2B,EAAE,MAAM,CAAA;IACnC,gBAAgB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC7D,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC7D,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,kBAAkB,CAAA;CAC5B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,kCAAkC,EAAE,MAAM,CAAA;CAC7C,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,KAAK,EAAE,YAAY,CAAA;IACnB,aAAa,EAAE,aAAa,CAAA;CAC/B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,CAAA;CACnC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,8BAA8B,GAAG,sBAAsB,GAAG;IAClE,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAAG;IAC/D,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IACzD,UAAU,EAAE,MAAM,CAAA;IAClB,2BAA2B,EAAE,MAAM,CAAA;IACnC,gBAAgB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC7D,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC7D,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,kBAAkB,CAAA;CAC5B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,kCAAkC,EAAE,MAAM,CAAA;CAC7C,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,KAAK,EAAE,YAAY,CAAA;IACnB,aAAa,EAAE,aAAa,CAAA;CAC/B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,8BAA8B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AACD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtion/backend",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5fad82d",
|
|
4
4
|
"description": "MPC Phase 2 backend for Firebase services management",
|
|
5
5
|
"repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
|
|
6
6
|
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "32fddd9a2d6199f1b0701cb4b8c3bc418660df31"
|
|
90
90
|
}
|
package/src/functions/bandada.ts
CHANGED
|
@@ -3,9 +3,8 @@ import * as functions from "firebase-functions"
|
|
|
3
3
|
import { ApiSdk } from "@bandada/api-sdk"
|
|
4
4
|
import { groth16 } from "snarkjs"
|
|
5
5
|
import { getAuth } from "firebase-admin/auth"
|
|
6
|
-
import { BandadaValidateProof, VerifiedBandadaResponse } from "../types/index"
|
|
7
|
-
|
|
8
6
|
import admin from "firebase-admin"
|
|
7
|
+
import { BandadaValidateProof, VerifiedBandadaResponse } from "../types/index"
|
|
9
8
|
|
|
10
9
|
const VKEY_DATA = {
|
|
11
10
|
protocol: "groth16",
|
|
@@ -46,7 +46,7 @@ dotenv.config()
|
|
|
46
46
|
export const startCeremony = functions
|
|
47
47
|
.region("europe-west1")
|
|
48
48
|
.runWith({
|
|
49
|
-
memory: "
|
|
49
|
+
memory: "1GB"
|
|
50
50
|
})
|
|
51
51
|
.pubsub.schedule(`every 30 minutes`)
|
|
52
52
|
.onRun(async () => {
|
|
@@ -71,7 +71,7 @@ export const startCeremony = functions
|
|
|
71
71
|
export const stopCeremony = functions
|
|
72
72
|
.region("europe-west1")
|
|
73
73
|
.runWith({
|
|
74
|
-
memory: "
|
|
74
|
+
memory: "1GB"
|
|
75
75
|
})
|
|
76
76
|
.pubsub.schedule(`every 30 minutes`)
|
|
77
77
|
.onRun(async () => {
|
|
@@ -96,7 +96,7 @@ export const stopCeremony = functions
|
|
|
96
96
|
export const setupCeremony = functions
|
|
97
97
|
.region("europe-west1")
|
|
98
98
|
.runWith({
|
|
99
|
-
memory: "
|
|
99
|
+
memory: "1GB"
|
|
100
100
|
})
|
|
101
101
|
.https.onCall(async (data: SetupCeremonyData, context: functions.https.CallableContext): Promise<any> => {
|
|
102
102
|
// Check if the user has the coordinator claim.
|
|
@@ -273,7 +273,7 @@ export const initEmptyWaitingQueueForCircuit = functions
|
|
|
273
273
|
export const finalizeCeremony = functions
|
|
274
274
|
.region("europe-west1")
|
|
275
275
|
.runWith({
|
|
276
|
-
memory: "
|
|
276
|
+
memory: "1GB"
|
|
277
277
|
})
|
|
278
278
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext): Promise<any> => {
|
|
279
279
|
if (!context.auth || !context.auth.token.coordinator) logAndThrowError(COMMON_ERRORS.CM_NOT_COORDINATOR_ROLE)
|
package/src/functions/circuit.ts
CHANGED
|
@@ -312,7 +312,7 @@ const waitForVMCommandExecution = (ssm: SSMClient, vmInstanceId: string, command
|
|
|
312
312
|
export const coordinateCeremonyParticipant = functionsV1
|
|
313
313
|
.region("europe-west1")
|
|
314
314
|
.runWith({
|
|
315
|
-
memory: "
|
|
315
|
+
memory: "1GB"
|
|
316
316
|
})
|
|
317
317
|
.firestore.document(
|
|
318
318
|
`${commonTerms.collections.ceremonies.name}/{ceremonyId}/${commonTerms.collections.participants.name}/{participantId}`
|
|
@@ -883,7 +883,7 @@ export const verifycontribution = functionsV2.https.onCall(
|
|
|
883
883
|
export const refreshParticipantAfterContributionVerification = functionsV1
|
|
884
884
|
.region("europe-west1")
|
|
885
885
|
.runWith({
|
|
886
|
-
memory: "
|
|
886
|
+
memory: "1GB"
|
|
887
887
|
})
|
|
888
888
|
.firestore.document(
|
|
889
889
|
`/${commonTerms.collections.ceremonies.name}/{ceremony}/${commonTerms.collections.circuits.name}/{circuit}/${commonTerms.collections.contributions.name}/{contributions}`
|
|
@@ -966,7 +966,7 @@ export const refreshParticipantAfterContributionVerification = functionsV1
|
|
|
966
966
|
export const finalizeCircuit = functionsV1
|
|
967
967
|
.region("europe-west1")
|
|
968
968
|
.runWith({
|
|
969
|
-
memory: "
|
|
969
|
+
memory: "1GB"
|
|
970
970
|
})
|
|
971
971
|
.https.onCall(async (data: FinalizeCircuitData, context: functionsV1.https.CallableContext) => {
|
|
972
972
|
if (!context.auth || !context.auth.token.coordinator) logAndThrowError(COMMON_ERRORS.CM_NOT_COORDINATOR_ROLE)
|
package/src/functions/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ export {
|
|
|
32
32
|
completeMultiPartUpload
|
|
33
33
|
} from "./storage"
|
|
34
34
|
export { bandadaValidateProof } from "./bandada"
|
|
35
|
+
export { checkNonceOfSIWEAddress } from "./siwe"
|
|
35
36
|
export { checkAndRemoveBlockingContributor, resumeContributionAfterTimeoutExpiration } from "./timeout"
|
|
36
37
|
|
|
37
38
|
admin.initializeApp()
|
|
@@ -46,7 +46,7 @@ dotenv.config()
|
|
|
46
46
|
export const checkParticipantForCeremony = functions
|
|
47
47
|
.region("europe-west1")
|
|
48
48
|
.runWith({
|
|
49
|
-
memory: "
|
|
49
|
+
memory: "1GB"
|
|
50
50
|
})
|
|
51
51
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext) => {
|
|
52
52
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -177,7 +177,7 @@ export const checkParticipantForCeremony = functions
|
|
|
177
177
|
export const progressToNextCircuitForContribution = functions
|
|
178
178
|
.region("europe-west1")
|
|
179
179
|
.runWith({
|
|
180
|
-
memory: "
|
|
180
|
+
memory: "1GB"
|
|
181
181
|
})
|
|
182
182
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext): Promise<void> => {
|
|
183
183
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -235,7 +235,7 @@ export const progressToNextCircuitForContribution = functions
|
|
|
235
235
|
export const progressToNextContributionStep = functions
|
|
236
236
|
.region("europe-west1")
|
|
237
237
|
.runWith({
|
|
238
|
-
memory: "
|
|
238
|
+
memory: "1GB"
|
|
239
239
|
})
|
|
240
240
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext) => {
|
|
241
241
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -298,7 +298,7 @@ export const progressToNextContributionStep = functions
|
|
|
298
298
|
export const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
299
299
|
.region("europe-west1")
|
|
300
300
|
.runWith({
|
|
301
|
-
memory: "
|
|
301
|
+
memory: "1GB"
|
|
302
302
|
})
|
|
303
303
|
.https.onCall(
|
|
304
304
|
async (data: PermanentlyStoreCurrentContributionTimeAndHash, context: functions.https.CallableContext) => {
|
|
@@ -357,7 +357,7 @@ export const permanentlyStoreCurrentContributionTimeAndHash = functions
|
|
|
357
357
|
export const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
358
358
|
.region("europe-west1")
|
|
359
359
|
.runWith({
|
|
360
|
-
memory: "
|
|
360
|
+
memory: "1GB"
|
|
361
361
|
})
|
|
362
362
|
.https.onCall(
|
|
363
363
|
async (data: TemporaryStoreCurrentContributionMultiPartUploadId, context: functions.https.CallableContext) => {
|
|
@@ -411,7 +411,7 @@ export const temporaryStoreCurrentContributionMultiPartUploadId = functions
|
|
|
411
411
|
export const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
412
412
|
.region("europe-west1")
|
|
413
413
|
.runWith({
|
|
414
|
-
memory: "
|
|
414
|
+
memory: "1GB"
|
|
415
415
|
})
|
|
416
416
|
.https.onCall(
|
|
417
417
|
async (data: TemporaryStoreCurrentContributionUploadedChunkData, context: functions.https.CallableContext) => {
|
|
@@ -471,7 +471,7 @@ export const temporaryStoreCurrentContributionUploadedChunkData = functions
|
|
|
471
471
|
export const checkAndPrepareCoordinatorForFinalization = functions
|
|
472
472
|
.region("europe-west1")
|
|
473
473
|
.runWith({
|
|
474
|
-
memory: "
|
|
474
|
+
memory: "1GB"
|
|
475
475
|
})
|
|
476
476
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext): Promise<boolean> => {
|
|
477
477
|
if (!context.auth || !context.auth.token.coordinator) logAndThrowError(COMMON_ERRORS.CM_NOT_COORDINATOR_ROLE)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import dotenv from "dotenv"
|
|
2
|
+
import fetch from "@adobe/node-fetch-retry"
|
|
3
|
+
import * as functions from "firebase-functions"
|
|
4
|
+
import { getAuth } from "firebase-admin/auth"
|
|
5
|
+
import admin from "firebase-admin"
|
|
6
|
+
import { Auth0UserInfo, CheckNonceOfSIWEAddressRequest, CheckNonceOfSIWEAddressResponse } from "../types"
|
|
7
|
+
import { setEthProvider } from "../lib/services"
|
|
8
|
+
|
|
9
|
+
dotenv.config()
|
|
10
|
+
|
|
11
|
+
export const checkNonceOfSIWEAddress = functions
|
|
12
|
+
.region("europe-west1")
|
|
13
|
+
.runWith({ memory: "1GB" })
|
|
14
|
+
.https.onCall(async (data: CheckNonceOfSIWEAddressRequest): Promise<CheckNonceOfSIWEAddressResponse> => {
|
|
15
|
+
try {
|
|
16
|
+
const { auth0Token } = data
|
|
17
|
+
const result = (await fetch(`${process.env.AUTH0_APPLICATION_URL}/userinfo`, {
|
|
18
|
+
method: "GET",
|
|
19
|
+
headers: {
|
|
20
|
+
"content-type": "application/json",
|
|
21
|
+
authorization: `Bearer ${auth0Token}`
|
|
22
|
+
}
|
|
23
|
+
}).then((_res) => _res.json())) as Auth0UserInfo
|
|
24
|
+
if (!result.sub) {
|
|
25
|
+
return {
|
|
26
|
+
valid: false,
|
|
27
|
+
message: "No user detected. Please check device flow token"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const auth = getAuth()
|
|
31
|
+
// check nonce
|
|
32
|
+
const parts = result.sub.split("|")
|
|
33
|
+
const address = decodeURIComponent(parts[2]).split(":")[2]
|
|
34
|
+
|
|
35
|
+
const minimumNonce = Number(process.env.ETH_MINIMUM_NONCE)
|
|
36
|
+
const nonceBlockHeight = "latest" // process.env.ETH_NONCE_BLOCK_HEIGHT
|
|
37
|
+
// look up nonce for address @block
|
|
38
|
+
let nonceOk = true
|
|
39
|
+
if (minimumNonce > 0) {
|
|
40
|
+
const provider = setEthProvider()
|
|
41
|
+
console.log(`got provider - block # ${await provider.getBlockNumber()}`)
|
|
42
|
+
const nonce = await provider.getTransactionCount(address, nonceBlockHeight)
|
|
43
|
+
console.log(`nonce ${nonce}`)
|
|
44
|
+
nonceOk = nonce >= minimumNonce
|
|
45
|
+
}
|
|
46
|
+
console.log(`checking nonce ${nonceOk}`)
|
|
47
|
+
if (!nonceOk) {
|
|
48
|
+
return {
|
|
49
|
+
valid: false,
|
|
50
|
+
message: "Eth address does not meet the nonce requirements"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await admin.auth().createUser({
|
|
55
|
+
displayName: address,
|
|
56
|
+
uid: address
|
|
57
|
+
})
|
|
58
|
+
} catch (error: any) {
|
|
59
|
+
// if user already exist then just pass
|
|
60
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
61
|
+
throw new Error(error)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const token = await auth.createCustomToken(address)
|
|
65
|
+
return {
|
|
66
|
+
valid: true,
|
|
67
|
+
token
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
return {
|
|
71
|
+
valid: false,
|
|
72
|
+
message: `Something went wrong ${error}`
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export default checkNonceOfSIWEAddress
|
package/src/functions/storage.ts
CHANGED
|
@@ -134,7 +134,7 @@ const checkIfBucketIsDedicatedToCeremony = async (bucketName: string) => {
|
|
|
134
134
|
export const createBucket = functions
|
|
135
135
|
.region("europe-west1")
|
|
136
136
|
.runWith({
|
|
137
|
-
memory: "
|
|
137
|
+
memory: "1GB"
|
|
138
138
|
})
|
|
139
139
|
.https.onCall(async (data: CreateBucketData, context: functions.https.CallableContext) => {
|
|
140
140
|
// Check if the user has the coordinator claim.
|
|
@@ -238,7 +238,7 @@ export const createBucket = functions
|
|
|
238
238
|
export const checkIfObjectExist = functions
|
|
239
239
|
.region("europe-west1")
|
|
240
240
|
.runWith({
|
|
241
|
-
memory: "
|
|
241
|
+
memory: "1GB"
|
|
242
242
|
})
|
|
243
243
|
.https.onCall(async (data: BucketAndObjectKeyData, context: functions.https.CallableContext): Promise<boolean> => {
|
|
244
244
|
// Check if the user has the coordinator claim.
|
|
@@ -294,7 +294,7 @@ export const checkIfObjectExist = functions
|
|
|
294
294
|
export const generateGetObjectPreSignedUrl = functions
|
|
295
295
|
.region("europe-west1")
|
|
296
296
|
.runWith({
|
|
297
|
-
memory: "
|
|
297
|
+
memory: "1GB"
|
|
298
298
|
})
|
|
299
299
|
.https.onCall(async (data: BucketAndObjectKeyData, context: functions.https.CallableContext): Promise<any> => {
|
|
300
300
|
if (!context.auth) logAndThrowError(COMMON_ERRORS.CM_NOT_AUTHENTICATED)
|
|
@@ -341,7 +341,7 @@ export const generateGetObjectPreSignedUrl = functions
|
|
|
341
341
|
export const startMultiPartUpload = functions
|
|
342
342
|
.region("europe-west1")
|
|
343
343
|
.runWith({
|
|
344
|
-
memory: "
|
|
344
|
+
memory: "2GB"
|
|
345
345
|
})
|
|
346
346
|
.https.onCall(async (data: StartMultiPartUploadData, context: functions.https.CallableContext): Promise<any> => {
|
|
347
347
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
|
@@ -409,7 +409,7 @@ export const startMultiPartUpload = functions
|
|
|
409
409
|
export const generatePreSignedUrlsParts = functions
|
|
410
410
|
.region("europe-west1")
|
|
411
411
|
.runWith({
|
|
412
|
-
memory: "
|
|
412
|
+
memory: "1GB",
|
|
413
413
|
timeoutSeconds: 300
|
|
414
414
|
})
|
|
415
415
|
.https.onCall(
|
|
@@ -487,7 +487,7 @@ export const generatePreSignedUrlsParts = functions
|
|
|
487
487
|
export const completeMultiPartUpload = functions
|
|
488
488
|
.region("europe-west1")
|
|
489
489
|
.runWith({
|
|
490
|
-
memory: "
|
|
490
|
+
memory: "2GB"
|
|
491
491
|
})
|
|
492
492
|
.https.onCall(async (data: CompleteMultiPartUploadData, context: functions.https.CallableContext): Promise<any> => {
|
|
493
493
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
package/src/functions/timeout.ts
CHANGED
|
@@ -42,7 +42,7 @@ dotenv.config()
|
|
|
42
42
|
export const checkAndRemoveBlockingContributor = functions
|
|
43
43
|
.region("europe-west1")
|
|
44
44
|
.runWith({
|
|
45
|
-
memory: "
|
|
45
|
+
memory: "1GB"
|
|
46
46
|
})
|
|
47
47
|
.pubsub.schedule("every 1 minutes")
|
|
48
48
|
.onRun(async () => {
|
|
@@ -144,7 +144,8 @@ export const checkAndRemoveBlockingContributor = functions
|
|
|
144
144
|
timeoutExpirationDateInMsForBlockingContributor < currentServerTimestamp &&
|
|
145
145
|
(contributionStep === ParticipantContributionStep.DOWNLOADING ||
|
|
146
146
|
contributionStep === ParticipantContributionStep.COMPUTING ||
|
|
147
|
-
contributionStep === ParticipantContributionStep.UPLOADING
|
|
147
|
+
contributionStep === ParticipantContributionStep.UPLOADING ||
|
|
148
|
+
contributionStep === ParticipantContributionStep.COMPLETED)
|
|
148
149
|
)
|
|
149
150
|
timeoutType = TimeoutType.BLOCKING_CONTRIBUTION
|
|
150
151
|
|
|
@@ -253,7 +254,7 @@ export const checkAndRemoveBlockingContributor = functions
|
|
|
253
254
|
export const resumeContributionAfterTimeoutExpiration = functions
|
|
254
255
|
.region("europe-west1")
|
|
255
256
|
.runWith({
|
|
256
|
-
memory: "
|
|
257
|
+
memory: "1GB"
|
|
257
258
|
})
|
|
258
259
|
.https.onCall(async (data: { ceremonyId: string }, context: functions.https.CallableContext): Promise<void> => {
|
|
259
260
|
if (!context.auth || (!context.auth.token.participant && !context.auth.token.coordinator))
|
package/src/functions/user.ts
CHANGED
|
@@ -18,7 +18,7 @@ dotenv.config()
|
|
|
18
18
|
export const registerAuthUser = functions
|
|
19
19
|
.region("europe-west1")
|
|
20
20
|
.runWith({
|
|
21
|
-
memory: "
|
|
21
|
+
memory: "1GB"
|
|
22
22
|
})
|
|
23
23
|
.auth.user()
|
|
24
24
|
.onCreate(async (user: UserRecord) => {
|
|
@@ -136,7 +136,7 @@ export const registerAuthUser = functions
|
|
|
136
136
|
export const processSignUpWithCustomClaims = functions
|
|
137
137
|
.region("europe-west1")
|
|
138
138
|
.runWith({
|
|
139
|
-
memory: "
|
|
139
|
+
memory: "1GB"
|
|
140
140
|
})
|
|
141
141
|
.auth.user()
|
|
142
142
|
.onCreate(async (user: UserRecord) => {
|
package/src/lib/services.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import dotenv from "dotenv"
|
|
2
|
+
import ethers from "ethers"
|
|
1
3
|
import { S3Client } from "@aws-sdk/client-s3"
|
|
2
4
|
import { COMMON_ERRORS, logAndThrowError } from "./errors"
|
|
3
5
|
|
|
6
|
+
dotenv.config()
|
|
7
|
+
let provider: ethers.providers.Provider
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Return a configured and connected instance of the AWS S3 client.
|
|
6
11
|
* @dev this method check and utilize the environment variables to configure the connection
|
|
@@ -26,3 +31,34 @@ export const getS3Client = async (): Promise<S3Client> => {
|
|
|
26
31
|
region: process.env.AWS_REGION!
|
|
27
32
|
})
|
|
28
33
|
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns a Prvider, connected via a configured JSON URL or else
|
|
37
|
+
* the ethers.js default provider, using configured API keys.
|
|
38
|
+
* @returns <ethers.providers.Provider> An Eth node provider
|
|
39
|
+
*/
|
|
40
|
+
export const setEthProvider = (): ethers.providers.Provider => {
|
|
41
|
+
if (provider) return provider
|
|
42
|
+
console.log(`setting new provider`)
|
|
43
|
+
|
|
44
|
+
// Use JSON URL if defined
|
|
45
|
+
// if ((hardhat as any).ethers) {
|
|
46
|
+
// console.log(`using hardhat.ethers provider`)
|
|
47
|
+
// provider = (hardhat as any).ethers.provider
|
|
48
|
+
// } else
|
|
49
|
+
if (process.env.ETH_PROVIDER_JSON_URL) {
|
|
50
|
+
console.log(`JSON URL provider at ${process.env.ETH_PROVIDER_JSON_URL}`)
|
|
51
|
+
provider = new ethers.providers.JsonRpcProvider({
|
|
52
|
+
url: process.env.ETH_PROVIDER_JSON_URL,
|
|
53
|
+
skipFetchSetup: true
|
|
54
|
+
})
|
|
55
|
+
} else {
|
|
56
|
+
// Otherwise, connect the default provider with ALchemy, Infura, or both
|
|
57
|
+
provider = ethers.providers.getDefaultProvider("homestead", {
|
|
58
|
+
alchemy: process.env.ETH_PROVIDER_ALCHEMY_API_KEY!,
|
|
59
|
+
infura: process.env.ETH_PROVIDER_INFURA_API_KEY!
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return provider
|
|
64
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -165,3 +165,36 @@ export type VerifiedBandadaResponse = {
|
|
|
165
165
|
message: string
|
|
166
166
|
token: string
|
|
167
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Define the check nonce object for the cloud function
|
|
171
|
+
* @typedef {Object} CheckNonceOfSIWEAddressRequest
|
|
172
|
+
* @property {string} auth0Token - token from the device flow authentication
|
|
173
|
+
*/
|
|
174
|
+
export type CheckNonceOfSIWEAddressRequest = {
|
|
175
|
+
auth0Token: string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Define the check nonce response object of the cloud function
|
|
180
|
+
* @typedef {Object} CheckNonceOfSIWEAddressResponse
|
|
181
|
+
* @property {boolean} valid - if the checking result was valid or not
|
|
182
|
+
* @property {string} message - informative message
|
|
183
|
+
* @property {string} token - token to sign in
|
|
184
|
+
*/
|
|
185
|
+
export type CheckNonceOfSIWEAddressResponse = {
|
|
186
|
+
valid: boolean
|
|
187
|
+
message?: string
|
|
188
|
+
token?: string
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Define the response from auth0 /userinfo endpoint
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
export type Auth0UserInfo = {
|
|
195
|
+
sub: string
|
|
196
|
+
nickname: string
|
|
197
|
+
name: string
|
|
198
|
+
picture: string
|
|
199
|
+
updated_at: string
|
|
200
|
+
}
|