-
Notifications
You must be signed in to change notification settings - Fork 63
Add api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add api #1
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,138 @@ | ||
| openapi: "3.0.2" | ||
| info: | ||
| title: Signer API | ||
| version: "0.1.0" | ||
| description: API that allows commit modules to request generic signatures from validators | ||
| tags: | ||
| - name: Signer | ||
| paths: | ||
| /signer/v1/get_pubkeys: | ||
| get: | ||
| summary: Get a list of public keys for which signatures may be requested | ||
| tags: | ||
| - Signer | ||
| responses: | ||
| "200": | ||
| description: A list of Bls pubkeys | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| consensus: | ||
| description: Consensus validator pubkeys | ||
| type: array | ||
| items: | ||
| type: string | ||
| format: hex | ||
| pattern: "^0x[a-fA-F0-9]{96}$" | ||
| example: "0xa3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989" | ||
| proxy: | ||
| description: Proxy validator pubkeys | ||
| type: array | ||
| items: | ||
| type: string | ||
| format: hex | ||
| pattern: "^0x[a-fA-F0-9]{96}$" | ||
| example: "0xa3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989" | ||
|
|
||
| "500": | ||
| description: Internal error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - code | ||
| - message | ||
| properties: | ||
| code: | ||
| type: number | ||
| example: 500 | ||
| message: | ||
| type: string | ||
| example: "Internal error" | ||
|
|
||
| /signer/v1/request_signature: | ||
| post: | ||
| summary: Send a signature request | ||
| tags: | ||
| - Signer | ||
| security: | ||
| - BearerAuth: [] | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| id: | ||
| description: The module ID | ||
| type: string | ||
| example: "MY_MODULE_ID" | ||
| pubkey: | ||
| description: BLS public key of validator | ||
| type: string | ||
| format: hex | ||
| pattern: "^0x[a-fA-F0-9]{96}$" | ||
| example: "0xa3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989" | ||
| is_proxy: | ||
| description: Whether the request is for a proxy pubkey | ||
| type: boolean | ||
| example: false | ||
| object_root: | ||
| description: The root of the object to be signed | ||
| type: string | ||
| format: hex | ||
| pattern: "^0x[a-fA-F0-9]{64}$" | ||
| example: "0x3e9f4a78b5c21d64f0b8e3d9a7f5c02b4d1e67a3c8f29b5d6e4a3b1c8f72e6d9" | ||
| responses: | ||
| "200": | ||
| description: Successs | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| description: The validator signature | ||
| format: hex | ||
| pattern: "^0x[a-fA-F0-9]{192}$" | ||
| example: "0xa3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989a3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989" | ||
| "404": | ||
| description: Unknown value (pubkey, module id) | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - code | ||
| - message | ||
| properties: | ||
| code: | ||
| type: number | ||
| example: 404 | ||
| message: | ||
| type: string | ||
| example: "Unknown pubkey" | ||
| "500": | ||
| description: Internal error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - code | ||
| - message | ||
| properties: | ||
| code: | ||
| type: number | ||
| example: 500 | ||
| message: | ||
| type: string | ||
| example: "Internal error" | ||
| components: | ||
| securitySchemes: | ||
| BearerAuth: | ||
| type: http | ||
| scheme: bearer | ||
| bearerFormat: JWT |
This file contains hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
| use std::{net::SocketAddr, sync::Arc}; | ||
|
|
||
| use alloy_rpc_types_beacon::{BlsPublicKey, BlsSignature}; | ||
| use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use super::{ | ||
| constants::{GET_PUBKEYS_PATH, REQUEST_SIGNATURE_PATH}, | ||
| error::SignerClientError, | ||
| request::SignRequest, | ||
| }; | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| pub struct GetPubkeysResponse { | ||
| pub consensus: Vec<BlsPublicKey>, | ||
| pub proxy: Vec<BlsPublicKey>, | ||
| } | ||
|
|
||
| /// Client used by commit modules to request signatures via the Signer API | ||
| #[derive(Debug, Clone)] | ||
| pub struct SignerClient { | ||
| /// Url endpoint of the Signer Module | ||
| url: Arc<str>, | ||
| client: reqwest::Client, | ||
| } | ||
|
|
||
| impl SignerClient { | ||
| /// Create a new SignerClient | ||
| pub fn new(signer_address: SocketAddr, jwt: &str) -> Result<Self, SignerClientError> { | ||
| let url = format!("http://{}", signer_address); | ||
| let mut headers = HeaderMap::new(); | ||
|
|
||
| let mut auth_value = HeaderValue::from_str(&format!("Bearer {}", jwt))?; | ||
| auth_value.set_sensitive(true); | ||
| headers.insert(AUTHORIZATION, auth_value); | ||
|
|
||
| let client = reqwest::ClientBuilder::new().default_headers(headers).build()?; | ||
|
|
||
| Ok(Self { url: url.into(), client }) | ||
| } | ||
|
|
||
| /// Request a list of validator pubkeys for which signatures can be requested. | ||
| /// TODO: add more docs on how proxy keys work | ||
| pub async fn get_pubkeys(&self) -> Result<GetPubkeysResponse, SignerClientError> { | ||
| let url = format!("{}{}", self.url, GET_PUBKEYS_PATH); | ||
| let res = self.client.get(&url).send().await?; | ||
|
|
||
| let status = res.status(); | ||
| let response_bytes = res.bytes().await?; | ||
|
|
||
| if !status.is_success() { | ||
| return Err(SignerClientError::FailedRequest { | ||
| status: status.as_u16(), | ||
| error_msg: String::from_utf8_lossy(&response_bytes).into_owned(), | ||
| }); | ||
| } | ||
|
|
||
| let parsed_response: GetPubkeysResponse = serde_json::from_slice(&response_bytes)?; | ||
|
|
||
| Ok(parsed_response) | ||
| } | ||
|
|
||
| /// Send a signature request | ||
| pub async fn request_signature( | ||
| &self, | ||
| request: &SignRequest, | ||
| ) -> Result<BlsSignature, SignerClientError> { | ||
| let url = format!("{}{}", self.url, REQUEST_SIGNATURE_PATH); | ||
| let res = self.client.post(&url).json(&request).send().await?; | ||
|
|
||
| let status = res.status(); | ||
| let response_bytes = res.bytes().await?; | ||
|
|
||
| if !status.is_success() { | ||
| return Err(SignerClientError::FailedRequest { | ||
| status: status.as_u16(), | ||
| error_msg: String::from_utf8_lossy(&response_bytes).into_owned(), | ||
| }); | ||
| } | ||
|
|
||
| let signature: BlsSignature = serde_json::from_slice(&response_bytes)?; | ||
|
|
||
| Ok(signature) | ||
| } | ||
| } |
This file contains hidden or 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,2 @@ | ||
| pub const GET_PUBKEYS_PATH: &str = "/signer/v1/get_pubkeys"; | ||
| pub const REQUEST_SIGNATURE_PATH: &str = "/signer/v1/request_signature"; |
This file contains hidden or 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,14 @@ | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum SignerClientError { | ||
| #[error("reqwest error: {0}")] | ||
| ReqwestError(#[from] reqwest::Error), | ||
|
|
||
| #[error("invalid header value: {0}")] | ||
| InvalidHeader(#[from] reqwest::header::InvalidHeaderValue), | ||
|
|
||
| #[error("failed request: status {status} msg {error_msg}")] | ||
| FailedRequest { status: u16, error_msg: String }, | ||
|
|
||
| #[error("serde decode error: {0}")] | ||
| SerdeDecodeError(#[from] serde_json::Error), | ||
| } |
This file contains hidden or 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,4 @@ | ||
| pub mod client; | ||
| pub mod constants; | ||
| pub mod error; | ||
| pub mod request; |
3 changes: 2 additions & 1 deletion
3
crates/crypto/src/types.rs → crates/common/src/commit/request.rs
This file contains hidden or 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 hidden or 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 hidden or 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,3 +1,4 @@ | ||
| pub mod commit; | ||
| pub mod config; | ||
| pub mod constants; | ||
| pub mod pbs; | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.