-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Luke Mann <[email protected]> Co-authored-by: Miguel Piedrafita <[email protected]>
- Loading branch information
1 parent
d3b7e92
commit 3217997
Showing
5 changed files
with
206 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
# A bridge between the World ID SDK and the World App | ||
# Wallet Bridge | ||
|
||
> **Warning** This project is still in early alpha. | ||
An end-to-end encrypted bridge between the World ID SDK and World App. This bridge is used to pass zero-knowledge proofs for World ID verifications. | ||
|
||
More details in the [docs](https://docs.worldcoin.org/further-reading/protocol-internals). | ||
|
||
## Flow | ||
|
||
```mermaid | ||
sequenceDiagram | ||
IDKit ->> Bridge: POST /request | ||
Bridge ->> IDKit: <id> | ||
IDKit ->> Bridge: Poll for updates GET /response/:id | ||
WorldApp ->> Bridge: GET /request/:id | ||
Bridge ->> WorldApp: <request> | ||
WorldApp ->> Bridge: PUT /response/:id | ||
IDKit ->> Bridge: Poll for updates GET /response/:id | ||
Bridge ->> IDKit: <response> | ||
``` | ||
|
||
```mermaid | ||
flowchart | ||
A[IDKit posts request /request] --> B[Request is stored in the bridge with status = initialized] | ||
B --> C[IDKit starts polling /response/:id] | ||
C --> D[User scans QR code with requestId & decryption key] | ||
D --> E[App fetches request at /request/:id] | ||
E --> F[Bridge updates status = retrieved] | ||
F -- Status updated = retrieved --> C | ||
F --> G[App generates proof and PUTs to /response/:id] | ||
G --> H[Bridge stores response. One-time retrieval] | ||
H -- Response provided --> C | ||
``` | ||
|
||
## Endpoints | ||
|
||
- `POST /request`: Called by IDKit. Initializes a proof verification request. | ||
- `GET /request/:id`: Called by World App. Used to fetch the proof verification request. One time use. | ||
- `PUT /response/:id`: Called by World App. Used to send the proof back to the application. | ||
- `GET /response/:id`: Called by IDKit. Continuous pulling to fetch the status of the request and the response if available. Response can only be retrieved once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::{fmt::Display, str::FromStr}; | ||
|
||
use axum::http::StatusCode; | ||
use redis::RedisError; | ||
|
||
pub const EXPIRE_AFTER_SECONDS: usize = 180; | ||
pub const REQ_STATUS_PREFIX: &str = "req:status:"; | ||
|
||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum RequestStatus { | ||
Initialized, | ||
Retrieved, | ||
Completed, | ||
} | ||
|
||
impl Display for RequestStatus { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Retrieved => write!(f, "retrieved"), | ||
Self::Completed => write!(f, "completed"), | ||
Self::Initialized => write!(f, "initialized"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for RequestStatus { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"initialized" => Ok(Self::Initialized), | ||
"retrieved" => Ok(Self::Retrieved), | ||
"completed" => Ok(Self::Completed), | ||
_ => Err(format!("Invalid status: {s}")), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct RequestPayload { | ||
iv: String, | ||
payload: String, | ||
} | ||
|
||
#[allow(clippy::needless_pass_by_value)] | ||
pub fn handle_redis_error(e: RedisError) -> StatusCode { | ||
tracing::error!("Redis error: {e}"); | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
} |