Skip to content

Commit

Permalink
Added guide for setting up World ID State Replication (#9)
Browse files Browse the repository at this point in the history
* Added the first version of world id state replication setup guide

* Corrected the suggested changes and refactored document

* Added todo comment

* Proofreading

* removed confusing comment

---------

Co-authored-by: Ihor Diachenko <[email protected]>
  • Loading branch information
soulyyyyy and ihordiachenko authored Jan 11, 2024
1 parent 28563aa commit 6153271
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- How-to-Guides:
- Added the Collab.Land integration doc;
- Added RariMe guide for issuers;
- World ID State Replication setup guide;
- Contribution guide to the README;
- Subscription form (w/o functionality)
- Mobile sliders
Expand Down
145 changes: 145 additions & 0 deletions docs/how-to-guides/worldcoin-state-replication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Setting Up Cross-Chain Identity State Replication for World ID

In this guide, we'll set up the cross-chain identity state replication for World ID. It enables the usage of World ID zero-knowledge proofs on any chain supported by Rarimo.

## Pre-Requisites

- [Postgres DB 13+](https://www.postgresql.org/download/) instance for the relayer service;
- [Docker](https://docs.docker.com/engine/install/) and [docker-compose](https://docs.docker.com/compose/install/) (optional)

## Setting Up Relayer

The Relayer service is responsible for replicating the World ID state on demand. It exposes a REST endpoint for the DApps that performs the state replication to the target chain.

### Build

You can pull the pre-build docker image:

```sh
docker pull ghcr.io/rarimo/worldcoin-relayer-svc:v0.1.0
```

Or clone the [worldcoin-relayer-svc repository](https://github.com/rarimo/worldcoin-relayer-svc) and build it from the source:

```sh
git clone [email protected]:rarimo/worldcoin-relayer-svc.git

CGO_ENABLED=1 go build .
```

## Configuration

Service configuration consists of two parts:

### Environment

```shell
export KV_VIPER_FILE=/config.yaml
```

### Config file
<!-- TODO: add a real contract_address in the config (evm -> chains section) -->
```yaml
log:
disable_sentry: true
level: debug

# The port to run on
listener:
addr: :8000

# PostgreSQL DB connect
db:
url: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"

# Rarimo core RPCs
core:
addr: tcp://validator:26657

cosmos:
addr: validator:9090

evm:
chains:
- name: "Avalanche"
## Address of the modified state contract on target chain
contract_address: ""
## Private key HEX (without leading 0x) that will pay the tx fee
submitter_private_key: ""
## RPC address. Example https://mainnet.infura.io/v3/11111
rpc:
## Target chain id
chain_id: 1

relay:
# Flag the indicates should service iterate over all existing transfer operation and fill the database
catchup_disabled: true
```

----

## Run

### Binary Built From Source

```sh
# apply DB migrations and run the service
./relayer-svc migrate up && ./relayer-svc run all
```

### Using `docker-compose`

1. Put the config at `./config.yaml`
1. Create `./docker-compose.yml`:
```yaml
version: "3.7"

services:
relayer-db:
image: postgres:13
restart: unless-stopped
environment:
- POSTGRES_USER=relayer
- POSTGRES_PASSWORD=relayer
- POSTGRES_DB=relayer
- PGDATA=/pgdata
volumes:
- relayer-data:/pgdata

relayer:
image: path/to/image:hash
restart: on-failure
ports:
- "8000:8000"
depends_on:
- relayer-db
volumes:
- ./config/relayer.yaml:/config.yaml
environment:
- KV_VIPER_FILE=/config.yaml
entrypoint: sh -c "relayer-svc migrate up && relayer-svc run all"
volumes:
relayer-data:
```
1. Run the service:
```sh
docker-compose up
```

## Using Service

Execute the POST `/integrations/relayer/state/relay` request with the following body to fetch state publishing:
```json
{
"chain": "Avalanche",
"hash": "0x1851e2c82ba946e9ba978a40571e4c1294a282d24912ff26496106445299f099",
"waitConfirm": true
}
```
`"waitConfirm": true` - indicates if request should wait until transaction will be included into the block. Default - `false`.

The response will be:

- `200` successful relay, tx hash in the response body;
- `404` the state wasn't ingested by Rarimo Core yet; wait a little and repeat the request;
- `400` the state has been relayed before; <!-- TODO: fix me -->
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const sidebars = {
'how-to-guides/poh-galxe',
'how-to-guides/proof-of-humanity-collabland-discord',
'how-to-guides/polygon-id-state-replication',
'how-to-guides/worldcoin-state-replication',
'how-to-guides/add-rarimo-credentials-to-rarime',
],
},
Expand Down

0 comments on commit 6153271

Please sign in to comment.