Skip to content

Commit

Permalink
eigen connector files
Browse files Browse the repository at this point in the history
  • Loading branch information
MujkicA committed Jan 23, 2025
1 parent 736ed04 commit d3dc249
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/adapters/eigenda/Cargo.toml
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 = []
13 changes: 13 additions & 0 deletions packages/adapters/eigenda/src/error.rs
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,
}
6 changes: 6 additions & 0 deletions packages/adapters/eigenda/src/lib.rs
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::*;
63 changes: 63 additions & 0 deletions packages/adapters/eigenda/src/signer.rs
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,
}
}
}

0 comments on commit d3dc249

Please sign in to comment.