@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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -0
  3. package/dist/src/functions/index.js +2884 -0
  4. package/dist/src/functions/index.mjs +2834 -0
  5. package/dist/types/functions/bandada.d.ts +4 -0
  6. package/dist/types/functions/bandada.d.ts.map +1 -0
  7. package/dist/types/functions/ceremony.d.ts +33 -0
  8. package/dist/types/functions/ceremony.d.ts.map +1 -0
  9. package/dist/types/functions/circuit.d.ts +63 -0
  10. package/dist/types/functions/circuit.d.ts.map +1 -0
  11. package/dist/types/functions/index.d.ts +9 -0
  12. package/dist/types/functions/index.d.ts.map +1 -0
  13. package/dist/types/functions/participant.d.ts +58 -0
  14. package/dist/types/functions/participant.d.ts.map +1 -0
  15. package/dist/types/functions/siwe.d.ts +4 -0
  16. package/dist/types/functions/siwe.d.ts.map +1 -0
  17. package/dist/types/functions/storage.d.ts +37 -0
  18. package/dist/types/functions/storage.d.ts.map +1 -0
  19. package/dist/types/functions/timeout.d.ts +26 -0
  20. package/dist/types/functions/timeout.d.ts.map +1 -0
  21. package/dist/types/functions/user.d.ts +15 -0
  22. package/dist/types/functions/user.d.ts.map +1 -0
  23. package/dist/types/lib/errors.d.ts +76 -0
  24. package/dist/types/lib/errors.d.ts.map +1 -0
  25. package/dist/types/lib/services.d.ts +16 -0
  26. package/dist/types/lib/services.d.ts.map +1 -0
  27. package/dist/types/lib/utils.d.ts +141 -0
  28. package/dist/types/lib/utils.d.ts.map +1 -0
  29. package/dist/types/types/enums.d.ts +13 -0
  30. package/dist/types/types/enums.d.ts.map +1 -0
  31. package/dist/types/types/index.d.ts +186 -0
  32. package/dist/types/types/index.d.ts.map +1 -0
  33. package/package.json +90 -0
  34. package/src/functions/bandada.ts +155 -0
  35. package/src/functions/ceremony.ts +338 -0
  36. package/src/functions/circuit.ts +1044 -0
  37. package/src/functions/index.ts +38 -0
  38. package/src/functions/participant.ts +526 -0
  39. package/src/functions/siwe.ts +77 -0
  40. package/src/functions/storage.ts +551 -0
  41. package/src/functions/timeout.ts +296 -0
  42. package/src/functions/user.ts +167 -0
  43. package/src/lib/errors.ts +242 -0
  44. package/src/lib/services.ts +64 -0
  45. package/src/lib/utils.ts +474 -0
  46. package/src/types/declarations.d.ts +1 -0
  47. package/src/types/enums.ts +12 -0
  48. package/src/types/index.ts +200 -0
  49. package/test/index.test.ts +62 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ethereum Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ <p align="center">
2
+ <h1 align="center">
3
+ Backend ⚙️
4
+ </h1>
5
+ <p align="center">An easy-to-configure, deploy and maintain cloud infrastructure solution for automating the coordination, scalability, and storage of your Groth16 zkSNARKs Phase 2 Trusted Setup ceremonies.</p>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://github.com/privacy-scaling-explorations/p0tion">
10
+ <img src="https://img.shields.io/badge/project-p0tion-blue.svg?style=flat-square">
11
+ </a>
12
+ <a href="https://github.com/privacy-scaling-explorations/p0tion/blob/main/LICENSE">
13
+ <img alt="Github License" src="https://img.shields.io/github/license/privacy-scaling-explorations/p0tion.svg?style=flat-square">
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@p0tion/backend">
16
+ <img alt="NPM Version" src="https://img.shields.io/npm/v/@p0tion/backend?style=flat-square" />
17
+ </a>
18
+ <a href="https://npmjs.org/package/@p0tion/backend">
19
+ <img alt="Downloads" src="https://img.shields.io/npm/dm/@p0tion/backend.svg?style=flat-square" />
20
+ </a>
21
+ <a href="https://eslint.org/">
22
+ <img alt="Linter" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
23
+ </a>
24
+ <a href="https://prettier.io/">
25
+ <img alt="Prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier" />
26
+ </a>
27
+ </p>
28
+
29
+ <div align="center">
30
+ <h4>
31
+ <a href="https://github.com/privacy-scaling-explorations/p0tion/blob/main/CONTRIBUTING.md">
32
+ 👥 Contributing
33
+ </a>
34
+ <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
35
+ <a href="https://github.com/privacy-scaling-explorations/p0tion/blob/main/CODE_OF_CONDUCT.md">
36
+ 🤝 Code of conduct
37
+ </a>
38
+ <span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
39
+ <a href="https://discord.gg/sF5CT5rzrR">
40
+ 🗣️ Chat &amp; Support
41
+ </a>
42
+ </h4>
43
+ </div>
44
+
45
+ | This library provides everything needed to configure, deploy and manage the infrastructure required to run one or more Phase 2 Trusted Setup ceremonies. |
46
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
47
+
48
+ Launching the ready-to-run customized scripts everyone could handle whatever is needed to accomplish the users authentication, ceremony setup, coordination and finalization. You could count on the combination of services provided by the far most popular cloud solutions in the market, as AWS for S3 Storage and GCP Firebase for Authentication, Firestore DB and, Cloud Functions services.
49
+
50
+ ![Components Diagram]("https://github.com/privacy-scaling-explorations/p0tion/blob/main/packages/backend/assets/components.png")
51
+
52
+ ## 🛠 Installation
53
+
54
+ **Prerequisites**
55
+
56
+ - Node.js version 16.0 or higher.
57
+ - Yarn version 3.5.0 or higher.
58
+ - A Firebase Application w/ active billing (Blaze Plan) in order to support Cloud Functions deployment.
59
+ - Follow the [Installation](https://github.com/privacy-scaling-explorations/p0tion/blob/main/README.md#installation) and [Usage](https://github.com/privacy-scaling-explorations/p0tion/blob/main/README.md#usage) guide.
60
+ - Generate and store a configuration file with your service account's credentials as stated in this [documentation](https://firebase.google.com/docs/admin/setup#set-up-project-and-service-account) inside the `packages/backend/serviceAccountKey.json` file.
61
+ - Rename the `.firebaserc` production project alias with your Firebase project name.
62
+
63
+ Navigate to backend package by running
64
+
65
+ ```bash
66
+ cd packages/backend
67
+ ```
68
+
69
+ Copy the `.default.env` file as `.env`:
70
+
71
+ ```bash
72
+ cp .env.default .env
73
+ ```
74
+
75
+ And add your environment variables.
76
+
77
+ ## 📜 Usage
78
+
79
+ ### Authorization
80
+
81
+ Login using your Google Account to Firebase CLI running
82
+
83
+ ```bash
84
+ yarn firebase:login
85
+ ```
86
+
87
+ Run the following to logout
88
+
89
+ ```bash
90
+ yarn firebase:logout
91
+ ```
92
+
93
+ ### Initialization
94
+
95
+ Initialize a new Firebase project interactively
96
+
97
+ ```bash
98
+ yarn firebase:init
99
+ ```
100
+
101
+ ### Deployment
102
+
103
+ #### AWS Infrastructure
104
+
105
+ 0. Login or create a [new AWS Account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=header_signup&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start/email).
106
+ - The AWS free tier account will cover a good number of requests for ceremonies but there could be some costs based on your ceremony circuits size.
107
+ 1. Create an access key for a user with Admin privileges (**NOT ROOT USER**)
108
+ 2. Setup the `awscli` ([docs](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)) and add the keys for this user.
109
+ 3. Install `terraform` ([docs](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli))
110
+ 4. Decide on an AWS region (by default this is **us-east-1**) - if you want to change you will need to do the following:
111
+ 1. update **aws/lambda/index.mjs** ([exact line](https://github.com/privacy-scaling-explorations/p0tion/blob/dev/packages/backend/aws/lambda/index.mjs#L3)) to the new region
112
+ 2. update **main.tf** ([exact line](https://github.com/privacy-scaling-explorations/p0tion/blob/dev/packages/backend/aws/main.tf#L2)) to the new region
113
+ 5. zip the Lambda folder:
114
+ 1. `cd lambda`
115
+ 2. `zip -r ../lambda.zip .`
116
+ 6. Run terraform:
117
+ 1. `terraform init`
118
+ 2. `terraform plan`
119
+ 3. `terraform apply`
120
+ 4. `terraform output secret_key`
121
+ - To print the secret access key for the IAM user
122
+ 5. Store the other values (sns_topic_arn etc.)
123
+ - These will be needed for the .env file configuration
124
+
125
+ The IAM user created with the steps above can be used for all p0tion's features.
126
+
127
+ #### Firebase
128
+
129
+ Deploy the current configuration to the `prod` project running
130
+
131
+ ```bash
132
+ yarn firebase:deploy
133
+ ```
134
+
135
+ To deploy only the latest Cloud Functions run
136
+
137
+ ```bash
138
+ yarn firebase:deploy-functions
139
+ ```
140
+
141
+ To deploy only the latest Firestore configuration and rules run
142
+
143
+ ```bash
144
+ yarn firebase:deploy-firestore
145
+ ```
146
+
147
+ ### Local Emulator
148
+
149
+ Firebase provides a [Local Emulator Suite](https://firebase.google.com/docs/emulator-suite) as a set of advanced dev-tools w/ a rich user-interface to build and test apps locally using Firebase services as Cloud Functions, Firestore and Authentication.
150
+
151
+ **Prerequisites**
152
+
153
+ - You will need Java JDK version 11 or higher to run the Firebase Local Emulator.
154
+
155
+ To start the Emulator run
156
+
157
+ ```bash
158
+ yarn emulator:serve
159
+ ```
160
+
161
+ To emulate only Cloud Functions service run
162
+
163
+ ```bash
164
+ yarn emulator:serve-functions
165
+ ```
166
+
167
+ To run the Emulator shell in a new command line window run
168
+
169
+ ```bash
170
+ yarn emulator:shell
171
+ ```
172
+
173
+ To run tests (e2e/unit) locally in the Emulator run
174
+
175
+ ```bash
176
+ yarn test:emulator
177
+ ```