feat: implement browser extension UI with WebAssembly integration

This commit is contained in:
Sameh Abouel-saad
2025-05-22 11:53:32 +03:00
parent 13945a8725
commit ed76ba3d8d
74 changed files with 7054 additions and 577 deletions

View File

@@ -1,80 +1,8 @@
// Signing should be done using ethers-core utilities directly. This file is now empty.
use super::error::EvmError;
// Native: Only compile for non-WASM
#[cfg(not(target_arch = "wasm32"))]
#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
pub trait Signer: Send + Sync {
async fn sign(&self, message: &[u8]) -> Result<Vec<u8>, EvmError>;
fn address(&self) -> String;
}
// WASM: Only compile for WASM
#[cfg(target_arch = "wasm32")]
#[async_trait(?Send)]
pub trait Signer {
async fn sign(&self, message: &[u8]) -> Result<Vec<u8>, EvmError>;
fn address(&self) -> String;
}
// --- Implementation for vault::SessionManager ---
#[cfg(target_arch = "wasm32")]
#[async_trait::async_trait(?Send)]
impl<S: vault::KVStore> Signer for vault::SessionManager<S> {
async fn sign(&self, message: &[u8]) -> Result<Vec<u8>, EvmError> {
log::debug!("SessionManager::sign called");
self.sign(message)
.await
.map_err(|e| {
log::error!("Vault signing error: {}", e);
EvmError::Vault(e.to_string())
})
}
fn address(&self) -> String {
log::debug!("SessionManager::address called");
self.current_keypair()
.map(|k| {
if k.key_type == vault::KeyType::Secp256k1 {
let pubkey = &k.public_key;
use alloy_primitives::keccak256;
let hash = keccak256(&pubkey[1..]);
format!("0x{}", hex::encode(&hash[12..]))
} else {
format!("0x{}", hex::encode(&k.public_key))
}
})
.unwrap_or_default()
}
}
#[cfg(not(target_arch = "wasm32"))]
#[async_trait::async_trait]
impl<S: vault::KVStore + Send + Sync> Signer for vault::SessionManager<S> {
async fn sign(&self, message: &[u8]) -> Result<Vec<u8>, EvmError> {
log::debug!("SessionManager::sign called");
self.sign(message)
.await
.map_err(|e| {
log::error!("Vault signing error: {}", e);
EvmError::Vault(e.to_string())
})
}
fn address(&self) -> String {
log::debug!("SessionManager::address called");
self.current_keypair()
.map(|k| {
if k.key_type == vault::KeyType::Secp256k1 {
let pubkey = &k.public_key;
use alloy_primitives::keccak256;
let hash = keccak256(&pubkey[1..]);
format!("0x{}", hex::encode(&hash[12..]))
} else {
format!("0x{}", hex::encode(&k.public_key))
}
})
.unwrap_or_default()
}
}