Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion core/src/signer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use alloy::{
dyn_abi::TypedData,
hex::FromHex,
primitives::{Address, Bytes, ChainId},
primitives::{Address, Bytes, ChainId, U256, FixedBytes},
rpc::types::Authorization,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_with::{DisplayFromStr, PickFirst, serde_as};
use thirdweb_core::iaw::IAWClient;
use vault_sdk::VaultClient;
Expand Down Expand Up @@ -176,6 +178,16 @@ pub trait AccountSigner {
typed_data: &TypedData,
credentials: SigningCredential,
) -> impl std::future::Future<Output = Result<String, EngineError>> + Send;

/// Sign EIP-7702 authorization
fn sign_authorization(
&self,
options: Self::SigningOptions,
chain_id: u64,
address: Address,
nonce: alloy::primitives::U256,
credentials: SigningCredential,
) -> impl std::future::Future<Output = Result<alloy::rpc::types::Authorization, EngineError>> + Send;
}

/// EOA signer implementation
Expand Down Expand Up @@ -287,6 +299,55 @@ impl AccountSigner for EoaSigner {
}
}
}

async fn sign_authorization(
&self,
options: EoaSigningOptions,
chain_id: u64,
address: Address,
nonce: U256,
credentials: SigningCredential,
) -> Result<Authorization, EngineError> {
match credentials {
SigningCredential::Vault(auth_method) => {
let vault_result = self
.vault_client
.sign_authorization(
auth_method,
options.from,
ChainId::from(chain_id),
address,
nonce,
)
.await
.map_err(|e| {
tracing::error!("Error signing authorization with EOA (Vault): {:?}", e);
e
})?;

Ok(vault_result)
}
SigningCredential::Iaw { auth_token, thirdweb_auth } => {
let iaw_result = self
.iaw_client
.sign_authorization(
auth_token,
thirdweb_auth,
options.from,
ChainId::from(chain_id),
address,
nonce,
)
.await
.map_err(|e| {
tracing::error!("Error signing authorization with EOA (IAW): {:?}", e);
EngineError::from(e)
})?;

Ok(iaw_result)
}
}
}
}

/// Parameters for signing a message (used in routes)
Expand Down
Loading