blueprint_eigenlayer_extra/
util.rs

1use alloy_primitives::{Address, keccak256};
2use blueprint_crypto_bn254::ArkBlsBn254Secret;
3use blueprint_evm_extra::util::get_provider_http;
4use eigensdk::crypto_bls::{BlsKeyPair, OperatorId, error::BlsError};
5
6/// Get the allocation manager address from the `DelegationManager` contract
7///
8/// # Returns
9/// - [`Address`] - The allocation manager address
10///
11/// # Errors
12/// - [`Error::Contract`] - If the call to the contract fails (i.e. the contract doesn't exist at the given address)
13pub async fn get_allocation_manager_address(
14    delegation_manager_addr: Address,
15    http_endpoint: &str,
16) -> Result<Address, alloy_contract::Error> {
17    let provider = get_provider_http(http_endpoint);
18    let delegation_manager =
19        eigensdk::utils::slashing::core::delegationmanager::DelegationManager::DelegationManagerInstance::new(
20            delegation_manager_addr,
21            provider,
22        );
23    delegation_manager
24        .allocationManager()
25        .call()
26        .await
27        .map(|a| a._0)
28}
29
30/// Generate the Operator ID from the BLS Keypair
31///
32/// # Returns
33/// - [`OperatorId`] - The operator ID
34#[must_use]
35pub fn operator_id_from_key(key: &BlsKeyPair) -> OperatorId {
36    let pub_key = key.public_key();
37    let pub_key_affine = pub_key.g1();
38
39    let x_int: num_bigint::BigUint = pub_key_affine.x.into();
40    let y_int: num_bigint::BigUint = pub_key_affine.y.into();
41
42    let x_bytes = x_int.to_bytes_be();
43    let y_bytes = y_int.to_bytes_be();
44
45    keccak256([x_bytes, y_bytes].concat())
46}
47
48/// Generate the Operator ID from the Ark BLS Keypair
49///
50/// # Returns
51/// - [`OperatorId`] - The operator ID
52///
53/// # Errors
54/// - [`BlsError`] - If the key is invalid
55pub fn operator_id_from_ark_bls_bn254(key: &ArkBlsBn254Secret) -> Result<OperatorId, BlsError> {
56    BlsKeyPair::new(key.0.to_string()).map(|key| operator_id_from_key(&key))
57}
OSZAR »