@devtion/backend 0.0.0-004e6ad
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/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/src/functions/index.js +2884 -0
- package/dist/src/functions/index.mjs +2834 -0
- package/dist/types/functions/bandada.d.ts +4 -0
- package/dist/types/functions/bandada.d.ts.map +1 -0
- package/dist/types/functions/ceremony.d.ts +33 -0
- package/dist/types/functions/ceremony.d.ts.map +1 -0
- package/dist/types/functions/circuit.d.ts +63 -0
- package/dist/types/functions/circuit.d.ts.map +1 -0
- package/dist/types/functions/index.d.ts +9 -0
- package/dist/types/functions/index.d.ts.map +1 -0
- package/dist/types/functions/participant.d.ts +58 -0
- package/dist/types/functions/participant.d.ts.map +1 -0
- package/dist/types/functions/siwe.d.ts +4 -0
- package/dist/types/functions/siwe.d.ts.map +1 -0
- package/dist/types/functions/storage.d.ts +37 -0
- package/dist/types/functions/storage.d.ts.map +1 -0
- package/dist/types/functions/timeout.d.ts +26 -0
- package/dist/types/functions/timeout.d.ts.map +1 -0
- package/dist/types/functions/user.d.ts +15 -0
- package/dist/types/functions/user.d.ts.map +1 -0
- package/dist/types/lib/errors.d.ts +76 -0
- package/dist/types/lib/errors.d.ts.map +1 -0
- package/dist/types/lib/services.d.ts +16 -0
- package/dist/types/lib/services.d.ts.map +1 -0
- package/dist/types/lib/utils.d.ts +141 -0
- package/dist/types/lib/utils.d.ts.map +1 -0
- package/dist/types/types/enums.d.ts +13 -0
- package/dist/types/types/enums.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +186 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +90 -0
- package/src/functions/bandada.ts +155 -0
- package/src/functions/ceremony.ts +338 -0
- package/src/functions/circuit.ts +1044 -0
- package/src/functions/index.ts +38 -0
- package/src/functions/participant.ts +526 -0
- package/src/functions/siwe.ts +77 -0
- package/src/functions/storage.ts +551 -0
- package/src/functions/timeout.ts +296 -0
- package/src/functions/user.ts +167 -0
- package/src/lib/errors.ts +242 -0
- package/src/lib/services.ts +64 -0
- package/src/lib/utils.ts +474 -0
- package/src/types/declarations.d.ts +1 -0
- package/src/types/enums.ts +12 -0
- package/src/types/index.ts +200 -0
- package/test/index.test.ts +62 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { CeremonyInputData, CircuitDocument, ETagWithPartNumber } from "@devtion/actions";
|
|
2
|
+
import type { Groth16Proof, PublicSignals } from "snarkjs";
|
|
3
|
+
/**
|
|
4
|
+
* Group all the necessary data needed for running the `setupCeremony` cloud function.
|
|
5
|
+
* @typedef {Object} SetupCeremonyData
|
|
6
|
+
* @property {CeremonyInputData} ceremonyInputData - the necessary input data for setup a new ceremony.
|
|
7
|
+
* @property {string} ceremonyPrefix - the ceremony prefix.
|
|
8
|
+
* @property {Array<CircuitDocument>} circuits - the necessary input data for setup the related ceremony circuits.
|
|
9
|
+
*/
|
|
10
|
+
export type SetupCeremonyData = {
|
|
11
|
+
ceremonyInputData: CeremonyInputData;
|
|
12
|
+
ceremonyPrefix: string;
|
|
13
|
+
circuits: Array<CircuitDocument>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Group all the necessary data needed for running the `createBucket` cloud function.
|
|
17
|
+
* @typedef {Object} CreateBucketData
|
|
18
|
+
* @property {string} bucketName - the name of the bucket.
|
|
19
|
+
*/
|
|
20
|
+
export type CreateBucketData = {
|
|
21
|
+
bucketName: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Group all the necessary data needed for running the `checkIfObjectExist` or `generateGetObjectPreSignedUrl` cloud functions.
|
|
25
|
+
* @typedef {Object} BucketAndObjectKeyData
|
|
26
|
+
* @property {string} bucketName - the name of the bucket.
|
|
27
|
+
* @property {string} objectKey - the unique key to identify the object inside the given AWS S3 bucket.
|
|
28
|
+
*/
|
|
29
|
+
export type BucketAndObjectKeyData = {
|
|
30
|
+
bucketName: string;
|
|
31
|
+
objectKey: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Group all the necessary data needed for running the `startMultiPartUpload` cloud function.
|
|
35
|
+
* @typedef {Object} StartMultiPartUploadData
|
|
36
|
+
* @property {string} bucketName - the name of the bucket.
|
|
37
|
+
* @property {string} objectKey - the unique key to identify the object inside the given AWS S3 bucket.
|
|
38
|
+
* @property {string} ceremonyId - the prefix of the ceremony.
|
|
39
|
+
*/
|
|
40
|
+
export type StartMultiPartUploadData = BucketAndObjectKeyData & {
|
|
41
|
+
ceremonyId?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Group all the necessary data needed for running the `generatePreSignedUrlsParts` cloud function.
|
|
45
|
+
* @typedef {Object} GeneratePreSignedUrlsPartsData
|
|
46
|
+
* @property {string} bucketName - the name of the bucket.
|
|
47
|
+
* @property {string} objectKey - the unique key to identify the object inside the given AWS S3 bucket.
|
|
48
|
+
* @property {string} uploadId - the identifier of the initiated multi-part upload.
|
|
49
|
+
* @property {number} numberOfParts - the amount of chunks for which pre-signed urls are to be generated.
|
|
50
|
+
* @property {string} ceremonyId - the prefix of the ceremony.
|
|
51
|
+
*/
|
|
52
|
+
export type GeneratePreSignedUrlsPartsData = BucketAndObjectKeyData & {
|
|
53
|
+
uploadId: string;
|
|
54
|
+
numberOfParts: number;
|
|
55
|
+
ceremonyId?: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Group all the necessary data needed for running the `completeMultiPartUpload` cloud function.
|
|
59
|
+
* @typedef {Object} GeneratePreSignedUrlsPartsData
|
|
60
|
+
* @property {string} bucketName - the name of the bucket.
|
|
61
|
+
* @property {string} objectKey - the unique key to identify the object inside the given AWS S3 bucket.
|
|
62
|
+
* @property {string} uploadId - the identifier of the initiated multi-part upload.
|
|
63
|
+
* @property {Array<ETagWithPartNumber>} parts - the chunks of the file related to the multi-part upload.
|
|
64
|
+
* @property {string} [ceremonyId] - the unique identifier of the ceremony.
|
|
65
|
+
*/
|
|
66
|
+
export type CompleteMultiPartUploadData = BucketAndObjectKeyData & {
|
|
67
|
+
uploadId: string;
|
|
68
|
+
parts: Array<ETagWithPartNumber>;
|
|
69
|
+
ceremonyId?: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Group all the necessary data needed for running the `permanentlyStoreCurrentContributionTimeAndHash` cloud function.
|
|
73
|
+
* @typedef {Object} PermanentlyStoreCurrentContributionTimeAndHash
|
|
74
|
+
* @property {string} ceremonyId - the unique identifier of the ceremony.
|
|
75
|
+
* @property {number} contributionComputationTime - the time spent by the contributor to compute the contribution.
|
|
76
|
+
* @property {string} contributionHash - the hash of the contribution.
|
|
77
|
+
*/
|
|
78
|
+
export type PermanentlyStoreCurrentContributionTimeAndHash = {
|
|
79
|
+
ceremonyId: string;
|
|
80
|
+
contributionComputationTime: number;
|
|
81
|
+
contributionHash: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Group all the necessary data needed for running the `temporaryStoreCurrentContributionMultiPartUploadId` cloud function.
|
|
85
|
+
* @typedef {Object} TemporaryStoreCurrentContributionMultiPartUploadId
|
|
86
|
+
* @property {string} ceremonyId - the unique identifier of the ceremony.
|
|
87
|
+
* @property {number} uploadId - the unique identifier of the already started multi-part upload.
|
|
88
|
+
*/
|
|
89
|
+
export type TemporaryStoreCurrentContributionMultiPartUploadId = {
|
|
90
|
+
ceremonyId: string;
|
|
91
|
+
uploadId: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Group all the necessary data needed for running the `temporaryStoreCurrentContributionUploadedChunkData` cloud function.
|
|
95
|
+
* @typedef {Object} TemporaryStoreCurrentContributionUploadedChunkData
|
|
96
|
+
* @property {string} ceremonyId - the unique identifier of the ceremony.
|
|
97
|
+
* @property {number} uploadId - the unique identifier of the already started multi-part upload.
|
|
98
|
+
*/
|
|
99
|
+
export type TemporaryStoreCurrentContributionUploadedChunkData = {
|
|
100
|
+
ceremonyId: string;
|
|
101
|
+
chunk: ETagWithPartNumber;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Group all the necessary data needed for running the `verifycontribution` cloud function.
|
|
105
|
+
* @typedef {Object} VerifyContributionData
|
|
106
|
+
* @property {string} ceremonyId - the unique identifier of the ceremony.
|
|
107
|
+
* @property {string} circuitId - the unique identifier of the circuit.
|
|
108
|
+
* @property {string} bucketName - the name of the bucket.
|
|
109
|
+
* @property {string} contributorOrCoordinatorIdentifier - the identifier of the contributor or coordinator (only when finalizing).
|
|
110
|
+
*/
|
|
111
|
+
export type VerifyContributionData = {
|
|
112
|
+
ceremonyId: string;
|
|
113
|
+
circuitId: string;
|
|
114
|
+
bucketName: string;
|
|
115
|
+
contributorOrCoordinatorIdentifier: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Group all the necessary data needed for running the `finalizeCircuit` cloud function.
|
|
119
|
+
* @typedef {Object} FinalizeCircuitData
|
|
120
|
+
* @property {string} ceremonyId - the unique identifier of the ceremony.
|
|
121
|
+
* @property {string} circuitId - the unique identifier of the circuit.
|
|
122
|
+
* @property {string} bucketName - the name of the bucket.
|
|
123
|
+
* @property {string} beacon - the value used to compute the final contribution while finalizing the ceremony.
|
|
124
|
+
*/
|
|
125
|
+
export type FinalizeCircuitData = {
|
|
126
|
+
ceremonyId: string;
|
|
127
|
+
circuitId: string;
|
|
128
|
+
bucketName: string;
|
|
129
|
+
beacon: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Group all the necessary data needed for running the `bandadaValidateProof` cloud function.
|
|
133
|
+
* @typedef {Object} BandadaValidateProof
|
|
134
|
+
* @property {string} merkleTreeRoot - the merkle tree root of the group.
|
|
135
|
+
* @property {string} nullifierHash - the nullifier hash of the member.
|
|
136
|
+
* @property {string} externalNullifier - the external nullifier of the member.
|
|
137
|
+
* @property {PackedProof} proof - the packed proof generated on the client.
|
|
138
|
+
*/
|
|
139
|
+
export type BandadaValidateProof = {
|
|
140
|
+
proof: Groth16Proof;
|
|
141
|
+
publicSignals: PublicSignals;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Define the return object of the function that verifies the Bandada membership and proof.
|
|
145
|
+
* @typedef {Object} VerifiedBandadaResponse
|
|
146
|
+
* @property {boolean} valid - true if the proof is valid and the user is a member of the group; otherwise false.
|
|
147
|
+
* @property {string} message - a message describing the result of the verification.
|
|
148
|
+
* @property {string} token - the custom access token.
|
|
149
|
+
*/
|
|
150
|
+
export type VerifiedBandadaResponse = {
|
|
151
|
+
valid: boolean;
|
|
152
|
+
message: string;
|
|
153
|
+
token: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Define the check nonce object for the cloud function
|
|
157
|
+
* @typedef {Object} CheckNonceOfSIWEAddressRequest
|
|
158
|
+
* @property {string} auth0Token - token from the device flow authentication
|
|
159
|
+
*/
|
|
160
|
+
export type CheckNonceOfSIWEAddressRequest = {
|
|
161
|
+
auth0Token: string;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Define the check nonce response object of the cloud function
|
|
165
|
+
* @typedef {Object} CheckNonceOfSIWEAddressResponse
|
|
166
|
+
* @property {boolean} valid - if the checking result was valid or not
|
|
167
|
+
* @property {string} message - informative message
|
|
168
|
+
* @property {string} token - token to sign in
|
|
169
|
+
*/
|
|
170
|
+
export type CheckNonceOfSIWEAddressResponse = {
|
|
171
|
+
valid: boolean;
|
|
172
|
+
message?: string;
|
|
173
|
+
token?: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Define the response from auth0 /userinfo endpoint
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
export type Auth0UserInfo = {
|
|
180
|
+
sub: string;
|
|
181
|
+
nickname: string;
|
|
182
|
+
name: string;
|
|
183
|
+
picture: string;
|
|
184
|
+
updated_at: string;
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtion/backend",
|
|
3
|
+
"version": "0.0.0-004e6ad",
|
|
4
|
+
"description": "MPC Phase 2 backend for Firebase services management",
|
|
5
|
+
"repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
|
|
6
|
+
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
|
|
7
|
+
"bugs": "https://github.com/privacy-scaling-explorations/p0tion/issues",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "./dist/src/functions/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
"import": "./dist/src/functions/index.mjs",
|
|
12
|
+
"require": "./dist/src/functions/index.js"
|
|
13
|
+
},
|
|
14
|
+
"types": "dist/types/types/index.d.ts",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "16"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/",
|
|
20
|
+
"src/",
|
|
21
|
+
"test/",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"typescript",
|
|
26
|
+
"zero-knowledge",
|
|
27
|
+
"zk-snarks",
|
|
28
|
+
"phase-2",
|
|
29
|
+
"trusted-setup",
|
|
30
|
+
"ceremony",
|
|
31
|
+
"snarkjs",
|
|
32
|
+
"circom"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
|
36
|
+
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
|
37
|
+
"firebase:login": "firebase login",
|
|
38
|
+
"firebase:logout": "firebase logout",
|
|
39
|
+
"firebase:init": "firebase init",
|
|
40
|
+
"firebase:deploy": "yarn firestore:get-indexes && firebase deploy --project prod",
|
|
41
|
+
"firebase:deploy-functions": "firebase deploy --only functions --project prod",
|
|
42
|
+
"firebase:deploy-firestore": "yarn firestore:get-indexes && firebase deploy --only firestore --project prod",
|
|
43
|
+
"firebase:log-functions": "firebase functions:log --project prod",
|
|
44
|
+
"firestore:get-indexes": "firebase firestore:indexes --project prod > firestore.indexes.json",
|
|
45
|
+
"emulator:serve": "yarn build && firebase emulators:start",
|
|
46
|
+
"emulator:serve-functions": "yarn build && firebase emulators:start --only functions",
|
|
47
|
+
"emulator:shell": "yarn build && firebase functions:shell",
|
|
48
|
+
"emulator:exec-test": "firebase --project dev emulators:exec \"yarn test:emulator\"",
|
|
49
|
+
"test:emulator": "jest --config=../../jest.json --detectOpenHandles --forceExit --coverage=false --watchAll=false --no-cache",
|
|
50
|
+
"docs": "typedoc src/**/*.ts --out ../../docs/backend"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@firebase/rules-unit-testing": "^2.0.7",
|
|
54
|
+
"@types/rollup-plugin-auto-external": "^2.0.2",
|
|
55
|
+
"@types/uuid": "^9.0.1",
|
|
56
|
+
"firebase-functions-test": "^3.1.0",
|
|
57
|
+
"firebase-tools": "^12.0.0",
|
|
58
|
+
"rollup-plugin-auto-external": "^2.0.0",
|
|
59
|
+
"rollup-plugin-cleanup": "^3.2.1",
|
|
60
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
61
|
+
"typescript": "^5.0.4"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@adobe/node-fetch-retry": "^2.2.0",
|
|
65
|
+
"@aws-sdk/client-ec2": "^3.357.0",
|
|
66
|
+
"@aws-sdk/client-s3": "^3.329.0",
|
|
67
|
+
"@aws-sdk/client-ssm": "^3.357.0",
|
|
68
|
+
"@aws-sdk/middleware-endpoint": "^3.329.0",
|
|
69
|
+
"@aws-sdk/s3-request-presigner": "^3.329.0",
|
|
70
|
+
"@bandada/api-sdk": "^1.0.0-beta.1",
|
|
71
|
+
"@devtion/actions": "latest",
|
|
72
|
+
"blakejs": "^1.2.1",
|
|
73
|
+
"dotenv": "^16.0.3",
|
|
74
|
+
"ethers": "5.7.2",
|
|
75
|
+
"firebase-admin": "^11.8.0",
|
|
76
|
+
"firebase-functions": "^4.4.0",
|
|
77
|
+
"html-entities": "^2.3.3",
|
|
78
|
+
"rimraf": "^5.0.0",
|
|
79
|
+
"rollup": "^3.21.6",
|
|
80
|
+
"snarkjs": "0.7.3",
|
|
81
|
+
"solc": "^0.8.19",
|
|
82
|
+
"timer-node": "^5.0.7",
|
|
83
|
+
"uuid": "^9.0.0",
|
|
84
|
+
"winston": "^3.8.2"
|
|
85
|
+
},
|
|
86
|
+
"publishConfig": {
|
|
87
|
+
"access": "public"
|
|
88
|
+
},
|
|
89
|
+
"gitHead": "8f3da5596cd864cdd387a32c05622efeaf0c10f7"
|
|
90
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import dotenv from "dotenv"
|
|
2
|
+
import * as functions from "firebase-functions"
|
|
3
|
+
import { ApiSdk } from "@bandada/api-sdk"
|
|
4
|
+
import { groth16 } from "snarkjs"
|
|
5
|
+
import { getAuth } from "firebase-admin/auth"
|
|
6
|
+
import admin from "firebase-admin"
|
|
7
|
+
import { BandadaValidateProof, VerifiedBandadaResponse } from "../types/index"
|
|
8
|
+
|
|
9
|
+
const VKEY_DATA = {
|
|
10
|
+
protocol: "groth16",
|
|
11
|
+
curve: "bn128",
|
|
12
|
+
nPublic: 3,
|
|
13
|
+
vk_alpha_1: [
|
|
14
|
+
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
|
15
|
+
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
|
16
|
+
"1"
|
|
17
|
+
],
|
|
18
|
+
vk_beta_2: [
|
|
19
|
+
[
|
|
20
|
+
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
|
21
|
+
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
|
25
|
+
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
|
26
|
+
],
|
|
27
|
+
["1", "0"]
|
|
28
|
+
],
|
|
29
|
+
vk_gamma_2: [
|
|
30
|
+
[
|
|
31
|
+
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
|
32
|
+
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
|
36
|
+
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
|
37
|
+
],
|
|
38
|
+
["1", "0"]
|
|
39
|
+
],
|
|
40
|
+
vk_delta_2: [
|
|
41
|
+
[
|
|
42
|
+
"3697618915467790705869942236922063775466274665053173890632463796679068973252",
|
|
43
|
+
"14948341351907992175709156460547989243732741534604949238422596319735704165658"
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
"3028459181652799888716942141752307629938889957960373621898607910203491239368",
|
|
47
|
+
"11380736494786911280692284374675752681598754560757720296073023058533044108340"
|
|
48
|
+
],
|
|
49
|
+
["1", "0"]
|
|
50
|
+
],
|
|
51
|
+
vk_alphabeta_12: [
|
|
52
|
+
[
|
|
53
|
+
[
|
|
54
|
+
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
|
55
|
+
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
|
59
|
+
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
|
63
|
+
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
|
64
|
+
]
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
[
|
|
68
|
+
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
|
69
|
+
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
|
73
|
+
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
|
77
|
+
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
|
78
|
+
]
|
|
79
|
+
]
|
|
80
|
+
],
|
|
81
|
+
IC: [
|
|
82
|
+
[
|
|
83
|
+
"12951059800758687233303204819298121944551181861362200875212570257618182506154",
|
|
84
|
+
"5751958719396509176593242305268064754837298673622815112953832050159760501392",
|
|
85
|
+
"1"
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"9561588427935871983444704959674198910445823619407211599507208879011862515257",
|
|
89
|
+
"14576201570478094842467636169770180675293504492823217349086195663150934064643",
|
|
90
|
+
"1"
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
"4811967233483727873912563574622036989372099129165459921963463310078093941559",
|
|
94
|
+
"1874883809855039536107616044787862082553628089593740724610117059083415551067",
|
|
95
|
+
"1"
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
"12252730267779308452229639835051322390696643456253768618882001876621526827161",
|
|
99
|
+
"7899194018737016222260328309937800777948677569409898603827268776967707173231",
|
|
100
|
+
"1"
|
|
101
|
+
]
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
dotenv.config()
|
|
106
|
+
|
|
107
|
+
const { BANDADA_API_URL, BANDADA_GROUP_ID } = process.env
|
|
108
|
+
|
|
109
|
+
const bandadaApi = new ApiSdk(BANDADA_API_URL)
|
|
110
|
+
|
|
111
|
+
export const bandadaValidateProof = functions
|
|
112
|
+
.region("europe-west1")
|
|
113
|
+
.runWith({
|
|
114
|
+
memory: "512MB"
|
|
115
|
+
})
|
|
116
|
+
.https.onCall(async (data: BandadaValidateProof): Promise<VerifiedBandadaResponse> => {
|
|
117
|
+
if (!BANDADA_GROUP_ID) throw new Error("BANDADA_GROUP_ID is not defined in .env")
|
|
118
|
+
|
|
119
|
+
const { proof, publicSignals } = data
|
|
120
|
+
const isCorrect = groth16.verify(VKEY_DATA, publicSignals, proof)
|
|
121
|
+
if (!isCorrect)
|
|
122
|
+
return {
|
|
123
|
+
valid: false,
|
|
124
|
+
message: "Invalid proof",
|
|
125
|
+
token: ""
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const commitment = data.publicSignals[1]
|
|
129
|
+
const isMember = await bandadaApi.isGroupMember(BANDADA_GROUP_ID, commitment)
|
|
130
|
+
if (!isMember)
|
|
131
|
+
return {
|
|
132
|
+
valid: false,
|
|
133
|
+
message: "Not a member of the group",
|
|
134
|
+
token: ""
|
|
135
|
+
}
|
|
136
|
+
const auth = getAuth()
|
|
137
|
+
try {
|
|
138
|
+
await admin.auth().createUser({
|
|
139
|
+
uid: commitment
|
|
140
|
+
})
|
|
141
|
+
} catch (error: any) {
|
|
142
|
+
// if user already exist then just pass
|
|
143
|
+
if (error.code !== "auth/uid-already-exists") {
|
|
144
|
+
throw new Error(error)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const token = await auth.createCustomToken(commitment)
|
|
148
|
+
return {
|
|
149
|
+
valid: true,
|
|
150
|
+
message: "Valid proof and group member",
|
|
151
|
+
token
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
export default bandadaValidateProof
|