diff --git a/Cargo.lock b/Cargo.lock index 7efc9e2fa..a50c09d11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1306,7 +1306,6 @@ dependencies = [ "eigensdk-contract-bindings", "eigensdk-crypto-bls", "eigensdk-crypto-bn254", - "ethers", ] [[package]] @@ -1393,7 +1392,6 @@ dependencies = [ "ark-ec", "ark-ff 0.4.2", "eigensdk-crypto-bn254", - "ethers-core", "thiserror", ] @@ -1416,7 +1414,6 @@ dependencies = [ "ark-ff 0.4.2", "eigensdk-crypto-bls", "eigensdk-crypto-bn254", - "ethers", ] [[package]] @@ -1426,8 +1423,6 @@ dependencies = [ "eigensdk-client-avsregistry", "eigensdk-client-elcontracts", "ethers", - "ethers-core", - "ethers-signers", ] [[package]] @@ -1435,8 +1430,6 @@ name = "eigensdk-metrics-collectors-rpc-calls" version = "0.0.1-alpha" dependencies = [ "ethers", - "ethers-core", - "ethers-signers", ] [[package]] @@ -1451,8 +1444,6 @@ dependencies = [ "eigensdk-types", "eth-keystore", "ethers", - "ethers-core", - "ethers-signers", "thiserror", ] @@ -1466,8 +1457,6 @@ dependencies = [ "eigensdk-types", "eth-keystore", "ethers", - "ethers-core", - "ethers-signers", "parking_lot", "thiserror", "tokio", @@ -1484,24 +1473,10 @@ dependencies = [ "eigensdk-types", "eth-keystore", "ethers", - "ethers-core", - "ethers-providers", - "ethers-signers", "thiserror", "tokio", ] -[[package]] -name = "eigensdk-signerv2" -version = "0.0.1-alpha" -dependencies = [ - "eth-keystore", - "ethers", - "ethers-core", - "ethers-signers", - "thiserror", -] - [[package]] name = "eigensdk-types" version = "0.0.1-alpha" @@ -1839,7 +1814,6 @@ dependencies = [ "const-hex", "enr", "ethers-core", - "futures-channel", "futures-core", "futures-timer", "futures-util", @@ -4034,10 +4008,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "signer" -version = "0.0.1-alpha" - [[package]] name = "simple_asn1" version = "0.6.2" diff --git a/Cargo.toml b/Cargo.toml index 6800ac28a..2556bd0e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ members = [ "crates/chainio/clients/avsregistry/", "crates/chainio/clients/eth/", "crates/chainio/clients/fireblocks/", "crates/contracts/bindings/", -"crates/signerv2/", "crates/chainio/utils/", "crates/crypto/bn254/", "crates/utils/", @@ -16,8 +15,7 @@ members = [ "crates/chainio/clients/avsregistry/", "crates/services/operatorsinfo/", "crates/types/", "crates/metrics/", -"crates/types/", -"crates/signer/"] +"crates/types/"] resolver = "2" @@ -43,8 +41,6 @@ rustdoc.all = "warn" [workspace.dependencies] ethers = "2.0.14" ark-ff = "0.4.0" -ethers-providers ="2.0.14" -ethers-core = "2.0.14" reth = {git = "https://github.com/paradigmxyz/reth"} prometheus-client = "0.22.2" bn254 = {git = "https://github.com/sedaprotocol/bn254"} @@ -59,9 +55,7 @@ eigensdk-contract-bindings = {version = "0.0.1-alpha", path = "crates/contracts/ eigensdk-types = {version = "0.0.1-alpha",path = "crates/types/"} eigensdk-crypto-bls = {path = "crates/crypto/bls/"} eigensdk-crypto-bn254 = {version = "0.0.1-alpha",path = "crates/crypto/bn254/"} -eigensdk-signerv2 = {version = "0.0.1-alpha",path = "crates/signerv2/"} eigensdk-utils = {version = "0.0.1-alpha" , path = "crates/utils/"} -ethers-signers = "2.0.14" eigensdk-metrics-collectors-economic = {version = "0.0.1-alpha",path = "crates/metrics/collectors/economic"} eigensdk-metrics-collectors-rpc-calls = {version = "0.0.1-alpha",path = "crates/metrics/collectors/rpc_calls"} eigensdk-services-avsregistry = {path = "crates/services/avsregistry"} diff --git a/crates/chainio/clients/avsregistry/src/lib.rs b/crates/chainio/clients/avsregistry/src/lib.rs index 8ed7b7734..e04fac003 100644 --- a/crates/chainio/clients/avsregistry/src/lib.rs +++ b/crates/chainio/clients/avsregistry/src/lib.rs @@ -1,6 +1,6 @@ //! AvsRegistry methods for reading, writing and subscribing purposes. -use alloy_primitives::types::H256; +use alloy_primitives::B256; #[allow(dead_code)] /// Reader module @@ -16,14 +16,14 @@ pub mod writer; /// Avs registry error message pub mod error; -/// cast sig-event "NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))" -pub const NEW_BLS_APK_REGISTRATION_EVENT_SIGNATURE: H256 = H256([ - 0xe3, 0xfb, 0x66, 0x13, 0xaf, 0x2e, 0x89, 0x30, 0xcf, 0x85, 0xd4, 0x7f, 0xcf, 0x6d, 0xb1, 0x01, - 0x92, 0x22, 0x4a, 0x64, 0xc6, 0xcb, 0xe8, 0x02, 0x3e, 0x0e, 0xee, 0x1b, 0xa3, 0x82, 0x80, 0x41, -]); +// /// cast sig-event "NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))" +// pub const NEW_BLS_APK_REGISTRATION_EVENT_SIGNATURE: H256 = H256([ +// 0xe3, 0xfb, 0x66, 0x13, 0xaf, 0x2e, 0x89, 0x30, 0xcf, 0x85, 0xd4, 0x7f, 0xcf, 0x6d, 0xb1, 0x01, +// 0x92, 0x22, 0x4a, 0x64, 0xc6, 0xcb, 0xe8, 0x02, 0x3e, 0x0e, 0xee, 0x1b, 0xa3, 0x82, 0x80, 0x41, +// ]); -/// cast sig-event "OperatorSocketUpdate(bytes32,string)" -pub const OPERATOR_SOCKET_UPDATE_EVENT_SIGNATURE: H256 = H256([ - 0xec, 0x29, 0x63, 0xab, 0x21, 0xc1, 0xe5, 0x0e, 0x1e, 0x58, 0x2a, 0xa5, 0x42, 0xaf, 0x2e, 0x4b, - 0xf7, 0xbf, 0x38, 0xe6, 0xe1, 0x40, 0x3c, 0x27, 0xb4, 0x2e, 0x1c, 0x5d, 0x6e, 0x62, 0x1e, 0xaa, -]); +// /// cast sig-event "OperatorSocketUpdate(bytes32,string)" +// pub const OPERATOR_SOCKET_UPDATE_EVENT_SIGNATURE: H256 = H256([ +// 0xec, 0x29, 0x63, 0xab, 0x21, 0xc1, 0xe5, 0x0e, 0x1e, 0x58, 0x2a, 0xa5, 0x42, 0xaf, 0x2e, 0x4b, +// 0xf7, 0xbf, 0x38, 0xe6, 0xe1, 0x40, 0x3c, 0x27, 0xb4, 0x2e, 0x1c, 0x5d, 0x6e, 0x62, 0x1e, 0xaa, +// ]); diff --git a/crates/chainio/clients/avsregistry/src/reader.rs b/crates/chainio/clients/avsregistry/src/reader.rs index c0606ee60..40118e9c5 100644 --- a/crates/chainio/clients/avsregistry/src/reader.rs +++ b/crates/chainio/clients/avsregistry/src/reader.rs @@ -507,14 +507,14 @@ impl AvsRegistryChainReader { to_block = stop_block; } - let filter = Filter::new() + let mut filter = Filter::new() .select(start_block..to_block) .event("OperatorSocketUpdate(bytes32,string)") .address(self.registry_coordinator_addr); if stop_block == 0 { let current_block_number = provider.get_block_number().await?; - filter.clone().select(start_block..current_block_number); + filter = filter.clone().select(start_block..current_block_number); }; let logs = provider.get_logs(&filter).await?; diff --git a/crates/chainio/clients/avsregistry/src/subscriber.rs b/crates/chainio/clients/avsregistry/src/subscriber.rs index c0e9ce730..bfcf14cf2 100644 --- a/crates/chainio/clients/avsregistry/src/subscriber.rs +++ b/crates/chainio/clients/avsregistry/src/subscriber.rs @@ -15,7 +15,7 @@ use alloy_provider::{ use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_types::Filter; use alloy_transport::BoxTransport; -use BLSApkRegistry::{BLSApkRegistryEvents, BLSApkRegistryInstance,NewPubkeyRegistration}; +use BLSApkRegistry::{BLSApkRegistryEvents, BLSApkRegistryInstance, NewPubkeyRegistration}; /// AvsRegistry Chain Subscriber struct #[derive(Debug)] @@ -60,7 +60,9 @@ impl AvsRegistryChainSubscriber { return Ok(bls_apk_reg); } - pub async fn get_new_pub_key_registration_filter<'a>(&self) -> Result> { + pub async fn get_new_pub_key_registration_filter<'a>( + &self, + ) -> Result> { let provider = ProviderBuilder::new() .with_recommended_fillers() .on_builtin(&self.provider) @@ -68,9 +70,7 @@ impl AvsRegistryChainSubscriber { let current_block_number = provider.get_block_number().await.unwrap(); let filter = Filter::new() - .event( - "NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))" - ) + .event("NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))") .from_block(current_block_number); Ok(filter) } diff --git a/crates/chainio/clients/avsregistry/src/writer.rs b/crates/chainio/clients/avsregistry/src/writer.rs index 623e61f07..04091dea7 100644 --- a/crates/chainio/clients/avsregistry/src/writer.rs +++ b/crates/chainio/clients/avsregistry/src/writer.rs @@ -1,4 +1,3 @@ -use crate::error::AvsRegistryError; use alloy_network::EthereumSigner; use alloy_signer::SignerSync; use alloy_signer_wallet::LocalWallet; @@ -9,12 +8,14 @@ use eigensdk_chainio_utils::{ }; use eigensdk_client_elcontracts::reader::ELChainReader; use reqwest::Url; -sol!( - #[allow(missing_docs)] - #[sol(rpc)] - RegistryCoordinator, - "../../../../crates/contracts/bindings/utils/json/RegistryCoordinator.json" -); + +use eigensdk_chainio_utils::{ + BLSApkRegistry::{G1Point, PubkeyRegistrationParams}, + RegistryCoordinator::{ + self, G1Point as RegistryG1Point, G2Point as RegistryG2Point, + PubkeyRegistrationParams as RegistryPubkeyRegistrationParams, + }, +}; sol!( #[allow(missing_docs)] #[sol(rpc)] @@ -29,21 +30,13 @@ sol!( "StakeRegistry.json" ); -sol!( - #[allow(missing_docs)] - #[derive(Debug)] - #[sol(rpc)] - BLSApkRegistry, - "../../../../crates/contracts/bindings/utils/json/BLSApkRegistry.json" -); - use alloy_primitives::{Address, Bytes, FixedBytes, TxHash, U256}; use alloy_provider::{Provider, ProviderBuilder}; use eigensdk_crypto_bls::attestation::KeyPair; -use std::sync::Arc; use tracing::info; -use BLSApkRegistry::PubkeyRegistrationParams; use RegistryCoordinator::SignatureWithSaltAndExpiry; + +#[derive(Debug)] pub struct AvsRegistryChainWriter { service_manager_addr: Address, registry_coordinator_addr: Address, @@ -164,7 +157,11 @@ impl AvsRegistryChainWriter { let signed_msg = convert_to_bn254_g1_point( bls_key_pair .sign_hashes_to_curve_message(G1Projective::from( - convert_bn254_to_ark(g1_hashes_msg_to_sign).point, + convert_bn254_to_ark(G1Point { + X: g1_hashes_msg_to_sign.X, + Y: g1_hashes_msg_to_sign.Y, + }) + .point, )) .sig(), ); @@ -206,7 +203,20 @@ impl AvsRegistryChainWriter { let contract_call = contract_registry_coordinator.registerOperator( quorum_numbers.clone(), socket, - pub_key_reg_params, + RegistryPubkeyRegistrationParams { + pubkeyRegistrationSignature: RegistryG1Point { + X: pub_key_reg_params.pubkeyRegistrationSignature.X, + Y: pub_key_reg_params.pubkeyRegistrationSignature.Y, + }, + pubkeyG1: RegistryG1Point { + X: pub_key_reg_params.pubkeyG1.X, + Y: pub_key_reg_params.pubkeyG1.Y, + }, + pubkeyG2: RegistryG2Point { + X: pub_key_reg_params.pubkeyG2.X, + Y: pub_key_reg_params.pubkeyG2.Y, + }, + }, operator_signature_with_salt_and_expiry, ); @@ -282,6 +292,6 @@ impl AvsRegistryChainWriter { let tx = contract_call.send().await?; info!(tx_hash = ?tx,"succesfully deregistered operator with the AVS's registry coordinator" ); - return Ok(tx.tx_hash()); + return Ok(*tx.tx_hash()); } } diff --git a/crates/chainio/clients/elcontracts/src/reader.rs b/crates/chainio/clients/elcontracts/src/reader.rs index 38ce175d2..bc2711c21 100644 --- a/crates/chainio/clients/elcontracts/src/reader.rs +++ b/crates/chainio/clients/elcontracts/src/reader.rs @@ -41,6 +41,7 @@ use std::sync::Arc; use crate::error::ElContractsError; +#[derive(Debug)] pub struct ELChainReader { slasher: Address, delegation_manager: Address, diff --git a/crates/chainio/utils/Cargo.toml b/crates/chainio/utils/Cargo.toml index e1d2869af..09f2e1cd9 100644 --- a/crates/chainio/utils/Cargo.toml +++ b/crates/chainio/utils/Cargo.toml @@ -9,7 +9,6 @@ repository.workspace = true license-file.workspace = true [dependencies] -ethers.workspace = true ark-bn254 = "0.4.0" ark-ff.workspace = true eigensdk-contract-bindings.workspace = true diff --git a/crates/chainio/utils/src/lib.rs b/crates/chainio/utils/src/lib.rs index 859f974cd..a59b936d5 100644 --- a/crates/chainio/utils/src/lib.rs +++ b/crates/chainio/utils/src/lib.rs @@ -8,33 +8,40 @@ sol!( RegistryCoordinator, "../../../crates/contracts/bindings/utils/json/RegistryCoordinator.json" ); +sol!( + #[allow(missing_docs)] + #[derive(Debug)] + #[sol(rpc)] + BLSApkRegistry, + "../../../crates/contracts/bindings/utils/json/BLSApkRegistry.json" +); -use eigensdk_crypto_bls::attestation::G1Point; +use eigensdk_crypto_bls::attestation::G1Point as AttestationG1Point; use eigensdk_crypto_bn254::utils::biginteger256_to_u256; use eigensdk_crypto_bn254::utils::u256_to_bigint256; -use RegistryCoordinator::{G1Point as RegistryG1Point, G2Point as RegistryG2Point}; +pub use BLSApkRegistry::{G1Point, G2Point}; -pub fn convert_bn254_to_ark(g1_point: RegistryCoordinator::G1Point) -> G1Point { - G1Point::new(u256_to_bigint256(g1_point.X), u256_to_bigint256(g1_point.Y)) +pub fn convert_bn254_to_ark(g1_point: G1Point) -> AttestationG1Point { + AttestationG1Point::new(u256_to_bigint256(g1_point.X), u256_to_bigint256(g1_point.Y)) } -pub fn convert_to_bn254_g1_point(g1: G1Projective) -> RegistryG1Point { +pub fn convert_to_bn254_g1_point(g1: G1Projective) -> G1Point { let x: BigInteger256 = g1.x.into(); let y: BigInteger256 = g1.y.into(); - RegistryG1Point { + G1Point { X: biginteger256_to_u256(x), Y: biginteger256_to_u256(y), } } -pub fn convert_to_bn254_g2_point(g2: G2Projective) -> RegistryG2Point { +pub fn convert_to_bn254_g2_point(g2: G2Projective) -> G2Point { let x_0: BigInteger256 = g2.x.c0.into(); let x_1: BigInteger256 = g2.x.c1.into(); let y_0: BigInteger256 = g2.y.c0.into(); let y_1: BigInteger256 = g2.y.c1.into(); - RegistryG2Point { + G2Point { X: [biginteger256_to_u256(x_0), biginteger256_to_u256(x_1)], Y: [biginteger256_to_u256(y_0), biginteger256_to_u256(y_1)], } diff --git a/crates/contracts/bindings/src/lib.rs b/crates/contracts/bindings/src/lib.rs index cb32025b3..219a7c06a 100644 --- a/crates/contracts/bindings/src/lib.rs +++ b/crates/contracts/bindings/src/lib.rs @@ -1,6 +1,3 @@ //! This module is a helper module to generate ethers bindings, if required -//! +//! //! If you are using alloy, you don't need to take any action. - - - diff --git a/crates/crypto/bls/Cargo.toml b/crates/crypto/bls/Cargo.toml index 66399f958..9418c0b4e 100644 --- a/crates/crypto/bls/Cargo.toml +++ b/crates/crypto/bls/Cargo.toml @@ -13,6 +13,5 @@ ark-bn254 = "0.4.0" ark-ff.workspace = true eigensdk-crypto-bn254.workspace = true thiserror.workspace = true -ethers-core.workspace = true ark-ec = "0.4.2" alloy-primitives.workspace = true \ No newline at end of file diff --git a/crates/crypto/bls/src/attestation.rs b/crates/crypto/bls/src/attestation.rs index d6b77ba6b..1d5361b0d 100644 --- a/crates/crypto/bls/src/attestation.rs +++ b/crates/crypto/bls/src/attestation.rs @@ -1,4 +1,5 @@ use crate::error::BlsError; +use alloy_primitives::U256; use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; use ark_ec::{ pairing::{prepare_g1, prepare_g2, Pairing}, @@ -8,7 +9,6 @@ use ark_ff::{BigInteger256, Field, One}; use eigensdk_crypto_bn254::utils::{ get_g2_generator, mul_by_generator_g1, mul_by_generator_g2, u256_to_bigint256, }; -use alloy_primitives::U256; use std::ops::Neg; use std::ops::{Add, Mul}; pub fn new_fp_element(x: BigInteger256) -> Fq { diff --git a/crates/crypto/bn254/src/utils.rs b/crates/crypto/bn254/src/utils.rs index e32ea1bba..0e400cc10 100644 --- a/crates/crypto/bn254/src/utils.rs +++ b/crates/crypto/bn254/src/utils.rs @@ -1,7 +1,7 @@ use crate::error::Bn254Err; +use alloy_primitives::U256; use ark_bn254::{Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; use ark_ff::{BigInteger, BigInteger256}; -use alloy_primitives::U256; use std::ops::Mul; use std::str::FromStr; /// Converts [U256] to [BigInteger256] diff --git a/crates/metrics/Cargo.toml b/crates/metrics/Cargo.toml index da406c278..2192b716d 100644 --- a/crates/metrics/Cargo.toml +++ b/crates/metrics/Cargo.toml @@ -6,7 +6,6 @@ rust-version.workspace = true repository.workspace = true [dependencies] -ethers = "2.0.14" ark-bn254 = "0.4.0" ark-ff.workspace = true eigensdk-crypto-bls.workspace = true diff --git a/crates/metrics/collectors/economic/Cargo.toml b/crates/metrics/collectors/economic/Cargo.toml index 5f5c75879..13881ddd6 100644 --- a/crates/metrics/collectors/economic/Cargo.toml +++ b/crates/metrics/collectors/economic/Cargo.toml @@ -7,8 +7,6 @@ repository.workspace = true [dependencies] # reth.workspace = true -ethers-core.workspace = true ethers.workspace = true -ethers-signers.workspace = true eigensdk-client-elcontracts.workspace = true eigensdk-client-avsregistry.workspace = true diff --git a/crates/metrics/collectors/rpc_calls/Cargo.toml b/crates/metrics/collectors/rpc_calls/Cargo.toml index 8aafa83bd..7a6627187 100644 --- a/crates/metrics/collectors/rpc_calls/Cargo.toml +++ b/crates/metrics/collectors/rpc_calls/Cargo.toml @@ -6,6 +6,4 @@ rust-version.workspace = true repository.workspace = true [dependencies] -ethers-core.workspace = true -ethers.workspace = true -ethers-signers.workspace = true \ No newline at end of file +ethers.workspace = true \ No newline at end of file diff --git a/crates/services/avsregistry/Cargo.toml b/crates/services/avsregistry/Cargo.toml index 950c27a07..efb213675 100644 --- a/crates/services/avsregistry/Cargo.toml +++ b/crates/services/avsregistry/Cargo.toml @@ -9,9 +9,7 @@ repository.workspace = true license-file.workspace = true [dependencies] -ethers-core.workspace = true ethers.workspace = true -ethers-signers.workspace = true eth-keystore = "0.5.0" thiserror.workspace = true eigensdk-client-avsregistry.workspace = true diff --git a/crates/services/bls_aggregation/Cargo.toml b/crates/services/bls_aggregation/Cargo.toml index c2b919589..2f7760743 100644 --- a/crates/services/bls_aggregation/Cargo.toml +++ b/crates/services/bls_aggregation/Cargo.toml @@ -9,9 +9,7 @@ repository.workspace = true license-file.workspace = true [dependencies] -ethers-core.workspace = true ethers.workspace = true -ethers-signers.workspace = true eth-keystore = "0.5.0" thiserror.workspace = true eigensdk-types.workspace = true diff --git a/crates/services/operatorsinfo/Cargo.toml b/crates/services/operatorsinfo/Cargo.toml index 1ab7068fc..7789f1605 100644 --- a/crates/services/operatorsinfo/Cargo.toml +++ b/crates/services/operatorsinfo/Cargo.toml @@ -9,13 +9,10 @@ repository.workspace = true license-file.workspace = true [dependencies] -ethers-core.workspace = true ethers.workspace = true -ethers-signers.workspace = true eth-keystore = "0.5.0" thiserror.workspace = true eigensdk-client-avsregistry.workspace = true -ethers-providers.workspace = true eigensdk-types.workspace = true eigensdk-contract-bindings.workspace = true eigensdk-crypto-bls.workspace = true diff --git a/crates/signer/Cargo.toml b/crates/signer/Cargo.toml deleted file mode 100644 index 6a5992fd7..000000000 --- a/crates/signer/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "signer" -version.workspace = true -edition.workspace = true -rust-version.workspace = true -repository.workspace = true - -[dependencies] -# reth.workspace = true - diff --git a/crates/signer/src/lib.rs b/crates/signer/src/lib.rs deleted file mode 100644 index 8b1378917..000000000 --- a/crates/signer/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/signerv2/Cargo.toml b/crates/signerv2/Cargo.toml deleted file mode 100644 index 44a43c380..000000000 --- a/crates/signerv2/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "eigensdk-signerv2" -description = "Eigen Layer SDK signer utilities" - -version.workspace = true -edition.workspace = true -rust-version.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -ethers-core.workspace = true -ethers.workspace = true -ethers-signers.workspace = true -eth-keystore = "0.5.0" -thiserror.workspace = true \ No newline at end of file diff --git a/crates/signerv2/src/error.rs b/crates/signerv2/src/error.rs deleted file mode 100644 index 7ecb06397..000000000 --- a/crates/signerv2/src/error.rs +++ /dev/null @@ -1,20 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum SignerV2Error { - /// Build ethhers wallet from private key - #[error("Failed to build wallet from private key")] - BuildWallet, - - /// Failed to sign transaction - #[error("Failed to sign transaction")] - SignTransaction, - - /// Failed to decrypt key - #[error("Failed to decrypt key in keystore ")] - Decryptkey, - - /// Failed to get any config in signerv2 - #[error("Did not found any signer type in the config")] - ConfigNotFound, -} diff --git a/crates/signerv2/src/lib.rs b/crates/signerv2/src/lib.rs deleted file mode 100644 index a53f944bd..000000000 --- a/crates/signerv2/src/lib.rs +++ /dev/null @@ -1,146 +0,0 @@ -//! Signer utilities for Eigen SDK -//! TODO: Alloy migration when alloy features are complete. - -use crate::error::SignerV2Error; -use eth_keystore::decrypt_key; -use ethers_core::types::{transaction::eip2718::TypedTransaction, Signature}; -use ethers_signers::{Signer, Wallet}; - -pub mod error; - -pub trait SignerV2 { - async fn sign_transaction(&self, tx: &TypedTransaction) -> Result; -} - -#[derive(Clone, Debug)] -pub struct KeyStoreSigner { - path: String, - password: String, -} - -#[derive(Debug, Clone)] -pub struct PrivateKeySigner { - private_key: Vec, -} - -impl PrivateKeySigner { - async fn set_private_key(&mut self, pvt_key: Vec) { - self.private_key = pvt_key; - } -} - -impl SignerV2 for PrivateKeySigner { - async fn sign_transaction(&self, tx: &TypedTransaction) -> Result { - let wallet_result = Wallet::from_bytes(&self.private_key); - - match wallet_result { - Ok(wallet) => { - let signer_tx_result = wallet.sign_transaction(tx).await; - - match signer_tx_result { - Ok(signer_tx) => { - return Ok(signer_tx); - } - Err(_) => return Err(SignerV2Error::SignTransaction), - } - } - Err(_) => return Err(SignerV2Error::BuildWallet), - } - } -} - -impl SignerV2 for KeyStoreSigner { - async fn sign_transaction(&self, tx: &TypedTransaction) -> Result { - let private_key = decrypt_key(&self.path, &self.password).unwrap(); - - let wallet_result = Wallet::from_bytes(&private_key); - - match wallet_result { - Ok(wallet) => { - let signer_tx_result = wallet.sign_transaction(tx).await; - - match signer_tx_result { - Ok(signer_tx) => { - return Ok(signer_tx); - } - Err(_) => return Err(SignerV2Error::SignTransaction), - } - } - Err(_) => return Err(SignerV2Error::BuildWallet), - } - } -} - -pub struct Config { - private_key: Vec, - keystore_path: String, - password: String, -} - -impl Config { - fn is_private_key_signer(&self) -> bool { - !self.private_key.is_empty() - } - - fn is_local_key_store_signer(&self) -> bool { - !self.keystore_path.is_empty() - } -} - -pub struct SignerFromCOonfig { - c: Config, -} - -impl SignerV2 for SignerFromCOonfig { - async fn sign_transaction(&self, tx: &TypedTransaction) -> Result { - if self.c.is_local_key_store_signer() { - let private_key_result = decrypt_key(&self.c.keystore_path, &self.c.password); - - match private_key_result { - Ok(private_key) => { - let wallet_result = Wallet::from_bytes(&private_key); - - match wallet_result { - Ok(wallet) => { - let signer_tx_result = wallet.sign_transaction(tx).await; - - match signer_tx_result { - Ok(signer_tx) => { - return Ok(signer_tx); - } - Err(_) => return Err(SignerV2Error::SignTransaction), - } - } - Err(_) => return Err(SignerV2Error::BuildWallet), - } - } - Err(_) => return Err(SignerV2Error::Decryptkey), - } - } else if self.c.is_private_key_signer() { - let private_key_result = decrypt_key(&self.c.keystore_path, &self.c.password); - - match private_key_result { - Ok(private_key) => { - let wallet_result = Wallet::from_bytes(&private_key); - - match wallet_result { - Ok(wallet) => { - let signer_tx_result = wallet.sign_transaction(tx).await; - - match signer_tx_result { - Ok(signer_tx) => { - return Ok(signer_tx); - } - Err(_) => return Err(SignerV2Error::SignTransaction), - } - } - Err(_) => return Err(SignerV2Error::BuildWallet), - } - } - Err(_) => return Err(SignerV2Error::BuildWallet), - } - } else { - return Err(SignerV2Error::ConfigNotFound); - } - } -}