Skip to content

Commit

Permalink
Merge pull request #65 from Unirep/easy-deploy
Browse files Browse the repository at this point in the history
feat: change router to serverless function to be deployed in vercel
  • Loading branch information
vivianjeng authored Mar 12, 2024
2 parents 1dd968a + 171805f commit e429d3a
Show file tree
Hide file tree
Showing 31 changed files with 545 additions and 372 deletions.
7 changes: 4 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ step_defs:
- run: &node_version
name: Set Node version
command: |
nvm install v16
nvm alias default v16
nvm install v18
nvm alias default v18
echo "nvm use default" >> $BASH_ENV
- run: &check_version
name: Check Node version
command: node -v | grep v16
command: node -v | grep v18
- run: &install_circom
name: Install Circom
command: |
Expand Down Expand Up @@ -61,6 +61,7 @@ jobs:
- packages/contracts/cache
- packages/contracts/typechain-types
- packages/contracts/contracts
- packages/contracts/.env
lint:
machine:
image: ubuntu-2204:2022.04.1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
create-unirep-app:
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -27,7 +27,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/

.DS_Store
/config.ts
.env
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/build
**/artifacts
**/cache
**/typechain-types
**/typechain-types
**/abi
119 changes: 110 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
# create-unirep-app

This is a demo app of a [unirep](https://github.com/Unirep/Unirep) attester. In this demo app, users can request data from the example attester. After transition, user can prove how much data he has.

> See: [Users and Attesters](https://developer.unirep.io/docs/protocol/users-and-attesters)
## 1. Installation
<p align="center">
<h1 align="center">create-unirep-app</h1>
</p>

<p align="center">
<a href="https://github.com/unirep/unirep">
<img src="https://img.shields.io/badge/project-unirep-blue.svg?style=flat-square">
</a>
<a href="https://github.com/unirep/unirep/blob/master/LICENSE">
<img alt="Github license" src="https://img.shields.io/github/license/unirep/unirep.svg?style=flat-square">
</a>
<a href="https://eslint.org/">
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint">
</a>
<a href="https://prettier.io/">
<img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier">
</a>
<a href="https://dl.circleci.com/status-badge/redirect/gh/Unirep/create-unirep-app/tree/main">
<img alt="Circle CI" src="https://img.shields.io/circleci/build/github/Unirep/create-unirep-app/main?style=flat-square">
</a>
</p>

This is a demo app of a [unirep](https://github.com/Unirep/Unirep) attester. In this demo app, users can request data from the example [attester](https://developer.unirep.io/docs/protocol/users-and-attesters). After transition, users can prove how much data they have.

Learn more about [how to build with create-unirep-app](https://developer.unirep.io/docs/getting-started/create-unirep-app)!

## 🔋 Requirements

- Node.js >=18
- To write custom circuits: install [rust](https://www.rust-lang.org/tools/install) and [circom 2](https://docs.circom.io/getting-started/installation/)

## 🛠 1. Installation

```shell
npx create-unirep-app
```

Then `cd` into the directory that was created.

## 2 Start with each daemon
## 📦 2. Local Development

### 2.1 Build the files

```shell
yarn build
```

> [!TIP]
> To overwrite circuit keys, delete `.wasm`, `.zkey` and `.vkey.json` objects in `packages/circuits/zksnarkBuild` and run:
>
> ```shell
> yarn circuits buildsnark
> ```
### 2.2 Start a node
```shell
Expand Down Expand Up @@ -50,7 +82,7 @@ yarn frontend start

It will be running at: http://localhost:3000/

## 3. Linter
## 🎁 3. Linting

### 3.1 Format the code

Expand All @@ -63,3 +95,72 @@ yarn lint:fix
```shell
yarn lint:check
```

## 🛜 4. Deployment

### 4.1 Deploy smart contract

- Edit the `packages/contracts/.env` after `yarn build`.
- Get your `ETH_PROVIDER_URL` from [infura](https://www.infura.io/), [alchemy](https://alchemy.com/), or other provider services.
- Get your `PRIVATE_KEY` and paste it in `.env` starting with `0x`.
- Run
```sh
yarn contracts deploy --network custom
```
from root directory

### 4.2 Deploy the frontend

[Vercel](https://vercel.com/) is a Frontend Cloud. You can easily deploy the frontend and relay service with Vercel.

> [!CAUTION]
> It will be a serverless relay. Learn more about [serverless functions](https://vercel.com/docs/functions/serverless-functions).

- **Deploy serverless relay:**

- <a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FUnirep%2Fcreate-unirep-app%2Ftree%2Feasy-deploy"><img src="https://vercel.com/button" alt="Deploy with Vercel"/></a><br/>
Click the `Deploy` button, and add the following settings
- Go to **Settings > Environment Variables**<br/>
set<br/>
| key | value |
|--|--|
| `PRIVATE_KEY` | 0x... |
| `ETH_PROVIDER_URL` |https://... |
| `APP_ADDRESS` | 0x... |
| `UNIREP_ADDRESS` | 0x... |

from `packages/relay/.env`

- Go to **Deployments**, choose the deployment and click ...<br/>
Click **Redeploy**
- Redeploy the relay, you will get a `https://{RELAY_APP_NAME}.vercel.app` as the relay server.
- View demo: https://create-unirep-app-relay.vercel.app/

- **Deploy frontend:**

- Go to vercel [dashboard](https://vercel.com/dashboard) and click **Add New... > Project**
- Choose the same repo as you created before.
- Set <br/>
**Framework Preset:** `Create React App`<br/>
**Build Command:** `yarn build`<br/>
**Output Directory:** `packages/frontend/build`<br/>
**Environment Variables:**
| key | value |
|--|--|
| `SERVER` |`https://{RELAY_APP_NAME}.vercel.app` |

and leave other settings as default.

- Deploy the frontend, you will get a `https://{FRONTEND_APP_NAME}.vercel.app` app!
- View demo: https://create-unirep-app-frontend.vercel.app/

## 🙌🏻 Join our community

- Discord server: <a href="https://discord.gg/VzMMDJmYc5"><img src="https://img.shields.io/discord/931582072152281188?label=Discord&style=flat-square&logo=discord"></a>
- Twitter account: <a href="https://twitter.com/UniRep_Protocol"><img src="https://img.shields.io/twitter/follow/UniRep_Protocol?style=flat-square&logo=twitter"></a>
- Telegram group: <a href="https://t.me/unirep"><img src="https://img.shields.io/badge/[email protected]?style=flat-square&logo=telegram"></a>

## <img height="24" src="https://pse.dev/_next/static/media/header-logo.bf6fc8c1.svg"> Privacy & Scaling Explorations

This project is supported by [Privacy & Scaling Explorations](https://pse.dev/) and the Ethereum Foundation.
See more projects on: https://pse.dev/projects.
3 changes: 3 additions & 0 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import app from '../packages/relay/src/app'

export default app
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"copyUnirep": "sh ./scripts/copyUnirep.sh",
"lint": "prettier .",
"lint:fix": "prettier . --write",
"lint:check": "prettier . --check"
"lint:check": "prettier . --check",
"vercel-build": "echo hello"
},
"devDependencies": {
"lerna": "6.6.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ETH_PROVIDER_URL=http://127.0.0.1:8545
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
117 changes: 1 addition & 116 deletions packages/contracts/abi/UnirepApp.json
Original file line number Diff line number Diff line change
@@ -1,116 +1 @@
[
{
"inputs": [
{
"internalType": "contract Unirep",
"name": "_unirep",
"type": "address"
},
{
"internalType": "contract IVerifier",
"name": "_dataVerifier",
"type": "address"
},
{
"internalType": "uint48",
"name": "_epochLength",
"type": "uint48"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "epochKey",
"type": "uint256"
},
{
"internalType": "uint48",
"name": "targetEpoch",
"type": "uint48"
},
{
"internalType": "uint256",
"name": "fieldIndex",
"type": "uint256"
},
{ "internalType": "uint256", "name": "val", "type": "uint256" }
],
"name": "submitAttestation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "epochKey",
"type": "uint256"
},
{
"internalType": "uint48",
"name": "targetEpoch",
"type": "uint48"
},
{
"internalType": "uint256[]",
"name": "fieldIndices",
"type": "uint256[]"
},
{ "internalType": "uint256[]", "name": "vals", "type": "uint256[]" }
],
"name": "submitManyAttestations",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "unirep",
"outputs": [
{ "internalType": "contract Unirep", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "publicSignals",
"type": "uint256[]"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
}
],
"name": "userSignUp",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[7]",
"name": "publicSignals",
"type": "uint256[7]"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
}
],
"name": "verifyDataProof",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
}
]
[{"inputs":[{"internalType":"contract Unirep","name":"_unirep","type":"address"},{"internalType":"contract IVerifier","name":"_dataVerifier","type":"address"},{"internalType":"uint48","name":"_epochLength","type":"uint48"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"epochKey","type":"uint256"},{"internalType":"uint48","name":"targetEpoch","type":"uint48"},{"internalType":"uint256","name":"fieldIndex","type":"uint256"},{"internalType":"uint256","name":"val","type":"uint256"}],"name":"submitAttestation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochKey","type":"uint256"},{"internalType":"uint48","name":"targetEpoch","type":"uint48"},{"internalType":"uint256[]","name":"fieldIndices","type":"uint256[]"},{"internalType":"uint256[]","name":"vals","type":"uint256[]"}],"name":"submitManyAttestations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unirep","outputs":[{"internalType":"contract Unirep","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"publicSignals","type":"uint256[]"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"}],"name":"userSignUp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[7]","name":"publicSignals","type":"uint256[7]"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"}],"name":"verifyDataProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
6 changes: 6 additions & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import '@typechain/hardhat'
import '@nomiclabs/hardhat-ethers'
import { config } from 'dotenv'
config()

export default {
defaultNetwork: 'local',
Expand All @@ -14,6 +16,10 @@ export default {
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
],
},
custom: {
url: process.env.ETH_PROVIDER_URL,
accounts: [process.env.PRIVATE_KEY],
},
},
solidity: {
compilers: [
Expand Down
6 changes: 4 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"main": "build/src/index.js",
"repository": "git+https://github.com/Unirep/create-unirep-app.git",
"scripts": {
"build": "yarn buildVerifier && hardhat compile && yarn abi",
"build": "yarn env && yarn buildVerifier && hardhat compile && yarn abi",
"buildVerifier": "ts-node ./scripts/genVerifier.ts ",
"abi": "ts-node scripts/abi",
"hardhat": "hardhat",
"deploy": "hardhat run scripts/deploy.ts",
"test": "hardhat test --network hardhat"
"test": "hardhat test --network hardhat",
"env": "cp ./.env.example ./.env"
},
"bugs": {
"url": "https://github.com/Unirep/create-unirep-app/issue"
Expand All @@ -27,6 +28,7 @@
"@types/node": "^18.15.11",
"@unirep-app/circuits": "1.0.0",
"@unirep/contracts": "2.0.1",
"dotenv": "^16.4.0",
"hardhat": "^2.12.0",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
Expand Down
Loading

0 comments on commit e429d3a

Please sign in to comment.