-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "eigenda" | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
version = { workspace = true } | ||
publish = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
signers = { workspace = true } | ||
services = { workspace = true } | ||
hex = { workspace = true } | ||
k256 = { workspace = true, features = ["ecdsa"] } | ||
futures = { workspace = true } | ||
prost = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true } | ||
tonic = { workspace = true, features = ["tls", "transport", "tls-roots", "codegen", "prost"] } | ||
tonic-build = { workspace = true } | ||
url = { workspace = true } | ||
|
||
[dev-dependencies] | ||
|
||
|
||
[features] | ||
test-helpers = [] |
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,13 @@ | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum ConnectorError { | ||
#[error("Transport error: {0}")] | ||
Transport(#[from] tonic::transport::Error), | ||
#[error("RPC error: {0}")] | ||
Rpc(#[from] tonic::Status), | ||
#[error("Authentication failed")] | ||
AuthenticationFailed, | ||
#[error("Blob processing failed: {0}")] | ||
BlobProcessingFailed(String), | ||
#[error("Timeout waiting for blob status")] | ||
Timeout, | ||
} |
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,6 @@ | ||
mod bindings; | ||
mod connector; | ||
mod error; | ||
mod signer; | ||
|
||
pub use connector::*; |
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,63 @@ | ||
use signers::{AwsKmsClient, KeySource}; | ||
|
||
use crate::error::ConnectorError; | ||
|
||
pub struct SignedMessage { | ||
pub data: Vec<u8>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum EigenDASigner { | ||
AwsKms(AwsSigner), | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct AwsSigner { | ||
key_id: String, | ||
client: AwsKmsClient, | ||
} | ||
|
||
impl AwsSigner { | ||
async fn new(key_id: String) -> Self { | ||
let client = AwsKmsClient::new().await; | ||
|
||
Self { key_id, client } | ||
} | ||
|
||
async fn sign(&self, message: &[u8]) -> Result<SignedMessage, ConnectorError> { | ||
// TODO unwrap | ||
let signed = self.client.sign(&self.key_id, message).await.unwrap(); | ||
|
||
Ok(SignedMessage { data: signed }) | ||
} | ||
|
||
async fn account_id(&self) -> String { | ||
let pk = self.client.get_public_key(&self.key_id).await.unwrap(); | ||
format!("0x{}", hex::encode(pk)) | ||
} | ||
} | ||
|
||
// get the public key from the signing key | ||
// let public_key = signing_key.verifying_key().to_encoded_point(false); | ||
// let account_id = format!("0x{}", hex::encode(public_key.as_bytes())); | ||
|
||
impl EigenDASigner { | ||
pub async fn new(key: KeySource) -> Self { | ||
match key { | ||
KeySource::Kms(key_id) => Self::AwsKms(AwsSigner::new(key_id).await), | ||
_ => unimplemented!(), | ||
} | ||
} | ||
|
||
pub async fn sign(&self, message: &[u8]) -> Result<SignedMessage, ConnectorError> { | ||
match self { | ||
Self::AwsKms(signer) => signer.sign(message).await, | ||
} | ||
} | ||
|
||
pub async fn account_id(&self) -> String { | ||
match self { | ||
Self::AwsKms(signer) => signer.account_id().await, | ||
} | ||
} | ||
} |