mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 06:44:35 +00:00
Add remotekey API support (#3162)
## Issue Addressed #3068 ## Proposed Changes Adds support for remote key API. ## Additional Info Needed to add `is_local_keystore` argument to `delete_definition_and_keystore` to know if we want to delete local or remote key. Previously this wasn't necessary because remotekeys(web3signers) could be deleted.
This commit is contained in:
@@ -476,6 +476,16 @@ impl ValidatorClientHttpClient {
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
fn make_remotekeys_url(&self) -> Result<Url, Error> {
|
||||
let mut url = self.server.full.clone();
|
||||
url.path_segments_mut()
|
||||
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
|
||||
.push("eth")
|
||||
.push("v1")
|
||||
.push("remotekeys");
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
/// `GET lighthouse/auth`
|
||||
pub async fn get_auth(&self) -> Result<AuthResponse, Error> {
|
||||
let mut url = self.server.full.clone();
|
||||
@@ -509,6 +519,30 @@ impl ValidatorClientHttpClient {
|
||||
let url = self.make_keystores_url()?;
|
||||
self.delete_with_unsigned_response(url, req).await
|
||||
}
|
||||
|
||||
/// `GET eth/v1/remotekeys`
|
||||
pub async fn get_remotekeys(&self) -> Result<ListRemotekeysResponse, Error> {
|
||||
let url = self.make_remotekeys_url()?;
|
||||
self.get_unsigned(url).await
|
||||
}
|
||||
|
||||
/// `POST eth/v1/remotekeys`
|
||||
pub async fn post_remotekeys(
|
||||
&self,
|
||||
req: &ImportRemotekeysRequest,
|
||||
) -> Result<ImportRemotekeysResponse, Error> {
|
||||
let url = self.make_remotekeys_url()?;
|
||||
self.post_with_unsigned_response(url, req).await
|
||||
}
|
||||
|
||||
/// `DELETE eth/v1/remotekeys`
|
||||
pub async fn delete_remotekeys(
|
||||
&self,
|
||||
req: &DeleteRemotekeysRequest,
|
||||
) -> Result<DeleteRemotekeysResponse, Error> {
|
||||
let url = self.make_remotekeys_url()?;
|
||||
self.delete_with_unsigned_response(url, req).await
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `Ok(response)` if the response is a `200 OK` response. Otherwise, creates an
|
||||
|
||||
@@ -102,3 +102,59 @@ pub enum DeleteKeystoreStatus {
|
||||
NotFound,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub struct ListRemotekeysResponse {
|
||||
pub data: Vec<SingleListRemotekeysResponse>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub struct SingleListRemotekeysResponse {
|
||||
pub pubkey: PublicKeyBytes,
|
||||
pub url: String,
|
||||
pub readonly: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ImportRemotekeysRequest {
|
||||
pub remote_keys: Vec<SingleImportRemotekeysRequest>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||
pub struct SingleImportRemotekeysRequest {
|
||||
pub pubkey: PublicKeyBytes,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ImportRemotekeyStatus {
|
||||
Imported,
|
||||
Duplicate,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ImportRemotekeysResponse {
|
||||
pub data: Vec<Status<ImportRemotekeyStatus>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DeleteRemotekeysRequest {
|
||||
pub pubkeys: Vec<PublicKeyBytes>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DeleteRemotekeyStatus {
|
||||
Deleted,
|
||||
NotFound,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct DeleteRemotekeysResponse {
|
||||
pub data: Vec<Status<DeleteRemotekeyStatus>>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user