Fixed unused imports and variables
This commit is contained in:
parent
b0b6359be1
commit
b82d457873
@ -134,13 +134,13 @@ For questions, contributions, or more details, see the architecture docs or open
|
||||
|
||||
### Native
|
||||
```sh
|
||||
cargo check --workspace --features kvstore/native
|
||||
cargo check --workspace
|
||||
cargo test --workspace
|
||||
```
|
||||
|
||||
### WASM (kvstore only)
|
||||
### WASM
|
||||
```sh
|
||||
cd kvstore
|
||||
wasm-pack test --headless --firefox --features web
|
||||
make test-browser-all
|
||||
```
|
||||
|
||||
# Rhai Scripting System
|
||||
|
@ -68,7 +68,7 @@ impl EvmClient {
|
||||
mut tx: provider::Transaction,
|
||||
signer: &dyn crate::signer::Signer,
|
||||
) -> Result<ethers_core::types::H256, EvmError> {
|
||||
use ethers_core::types::{U256, H256, Bytes, Address};
|
||||
use ethers_core::types::{U256, H256};
|
||||
use std::str::FromStr;
|
||||
use serde_json::json;
|
||||
use crate::provider::{send_rpc, parse_signature_rs_v};
|
||||
@ -131,7 +131,7 @@ impl EvmClient {
|
||||
|
||||
// 3. Sign the RLP-encoded unsigned transaction
|
||||
let sig = signer.sign(&rlp_unsigned).await?;
|
||||
let (r, s, v) = parse_signature_rs_v(&sig, tx.chain_id.unwrap()).ok_or_else(|| EvmError::Signing("Invalid signature format".to_string()))?;
|
||||
let (r, s, _v) = parse_signature_rs_v(&sig, tx.chain_id.unwrap()).ok_or_else(|| EvmError::Signing("Invalid signature format".to_string()))?;
|
||||
|
||||
// 4. RLP encode signed transaction (EIP-155)
|
||||
use rlp::RlpStream;
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Rhai bindings for EVM Client module
|
||||
//! Provides a single source of truth for scripting integration for EVM actions.
|
||||
|
||||
use rhai::{Engine, Map};
|
||||
use rhai::Engine;
|
||||
pub use crate::EvmClient; // Ensure EvmClient is public and defined in lib.rs
|
||||
|
||||
/// Register EVM Client APIs with the Rhai scripting engine.
|
||||
@ -25,7 +25,7 @@ pub fn register_rhai_api(engine: &mut Engine, evm_client: std::sync::Arc<EvmClie
|
||||
engine.register_type::<RhaiEvmClient>();
|
||||
engine.register_fn("get_balance", RhaiEvmClient::get_balance);
|
||||
// Register instance for scripts
|
||||
let rhai_ec = RhaiEvmClient { inner: evm_client.clone() };
|
||||
let _rhai_ec = RhaiEvmClient { inner: evm_client.clone() };
|
||||
// Rhai does not support register_global_constant; pass the client as a parameter or use module scope.
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
//! These use block_on for native, and should be adapted for WASM as needed.
|
||||
|
||||
use crate::EvmClient;
|
||||
use rhai::Map;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use tokio::runtime::Handle;
|
||||
|
@ -37,7 +37,6 @@
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[tokio::test]
|
||||
async fn test_get_balance_real_address() {
|
||||
use ethers_core::types::{Address, U256};
|
||||
use evm_client::provider::get_balance;
|
||||
|
||||
// Vitalik's address
|
||||
|
1
hero_vault_extension/.gitignore
vendored
Normal file
1
hero_vault_extension/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist
|
@ -130,6 +130,7 @@ store.put(&js_value, Some(&JsValue::from_str(key)))?.await
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub struct WasmStore;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[async_trait]
|
||||
impl KVStore for WasmStore {
|
||||
@ -139,10 +140,16 @@ impl KVStore for WasmStore {
|
||||
async fn set(&self, _key: &str, _value: &[u8]) -> Result<()> {
|
||||
Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string()))
|
||||
}
|
||||
async fn delete(&self, _key: &str) -> Result<()> {
|
||||
async fn remove(&self, _key: &str) -> Result<()> {
|
||||
Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string()))
|
||||
}
|
||||
async fn exists(&self, _key: &str) -> Result<bool> {
|
||||
async fn contains_key(&self, _key: &str) -> Result<bool> {
|
||||
Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string()))
|
||||
}
|
||||
async fn keys(&self) -> Result<Vec<String>> {
|
||||
Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string()))
|
||||
}
|
||||
async fn clear(&self) -> Result<()> {
|
||||
Err(KVError::Other("WasmStore is only available on wasm32 targets".to_string()))
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use crate::session::SessionManager;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn register_rhai_api<S: kvstore::traits::KVStore + Send + Sync + Clone + 'static>(
|
||||
engine: &mut Engine,
|
||||
session_manager: std::sync::Arc<std::sync::Mutex<SessionManager<S>>>,
|
||||
_session_manager: std::sync::Arc<std::sync::Mutex<SessionManager<S>>>,
|
||||
) {
|
||||
engine.register_type::<RhaiSessionManager<S>>();
|
||||
engine.register_fn("select_keypair", RhaiSessionManager::<S>::select_keypair);
|
||||
@ -37,7 +37,7 @@ impl<S: kvstore::traits::KVStore + Send + Sync + Clone + 'static> RhaiSessionMan
|
||||
// Use Mutex for interior mutability, &self is sufficient
|
||||
self.inner.lock().unwrap().select_keypair(&key_id).map_err(|e| format!("select_keypair error: {e}"))
|
||||
}
|
||||
|
||||
|
||||
pub fn select_default_keypair(&self) -> Result<(), String> {
|
||||
self.inner.lock().unwrap().select_default_keypair()
|
||||
.map_err(|e| format!("select_default_keypair error: {e}"))
|
||||
|
@ -3,7 +3,6 @@
|
||||
//! All state is local to the SessionManager instance. No global state.
|
||||
|
||||
use crate::{KVStore, KeyEntry, KeyspaceData, Vault, VaultError};
|
||||
use std::collections::HashMap;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
/// SessionManager: Ergonomic, stateful wrapper over the Vault stateless API.
|
||||
@ -130,17 +129,17 @@ impl<S: KVStore + Send + Sync> SessionManager<S> {
|
||||
self.current_keyspace()
|
||||
.and_then(|ks| ks.keypairs.first())
|
||||
}
|
||||
|
||||
|
||||
/// Selects the default keypair (first keypair) as the current keypair.
|
||||
pub fn select_default_keypair(&mut self) -> Result<(), VaultError> {
|
||||
let default_id = self
|
||||
.default_keypair()
|
||||
.map(|k| k.id.clone())
|
||||
.ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?;
|
||||
|
||||
|
||||
self.select_keypair(&default_id)
|
||||
}
|
||||
|
||||
|
||||
/// Returns true if the current keypair is the default keypair (first keypair).
|
||||
pub fn is_default_keypair_selected(&self) -> bool {
|
||||
match (self.current_keypair(), self.default_keypair()) {
|
||||
@ -312,17 +311,17 @@ impl<S: KVStore> SessionManager<S> {
|
||||
self.current_keyspace()
|
||||
.and_then(|ks| ks.keypairs.first())
|
||||
}
|
||||
|
||||
|
||||
/// Selects the default keypair (first keypair) as the current keypair.
|
||||
pub fn select_default_keypair(&mut self) -> Result<(), VaultError> {
|
||||
let default_id = self
|
||||
.default_keypair()
|
||||
.map(|k| k.id.clone())
|
||||
.ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?;
|
||||
|
||||
|
||||
self.select_keypair(&default_id)
|
||||
}
|
||||
|
||||
|
||||
/// Returns true if the current keypair is the default keypair (first keypair).
|
||||
pub fn is_default_keypair_selected(&self) -> bool {
|
||||
match (self.current_keypair(), self.default_keypair()) {
|
||||
|
@ -26,6 +26,8 @@ async fn test_keypair_management_and_crypto() {
|
||||
vault.create_keyspace(keyspace, password, None).await.unwrap();
|
||||
|
||||
debug!("after create_keyspace: keyspace={} password={}", keyspace, hex::encode(password));
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 1); // should be 1 because we added a default keypair on create_keyspace
|
||||
debug!("before add Ed25519 keypair");
|
||||
let key_id = vault.add_keypair(keyspace, password, Some(KeyType::Ed25519), Some(KeyMetadata { name: Some("edkey".into()), created_at: None, tags: None })).await;
|
||||
match &key_id {
|
||||
@ -38,7 +40,7 @@ async fn test_keypair_management_and_crypto() {
|
||||
|
||||
debug!("before list_keypairs");
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 2);
|
||||
assert_eq!(keys.len(), 3);
|
||||
|
||||
debug!("before export Ed25519 keypair");
|
||||
let (priv_bytes, pub_bytes) = vault.export_keypair(keyspace, password, &key_id).await.unwrap();
|
||||
@ -65,5 +67,5 @@ async fn test_keypair_management_and_crypto() {
|
||||
// Remove a keypair
|
||||
vault.remove_keypair(keyspace, password, &key_id).await.unwrap();
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 1);
|
||||
assert_eq!(keys.len(), 2);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ async fn session_manager_end_to_end() {
|
||||
use tempfile::TempDir;
|
||||
let tmp_dir = TempDir::new().expect("create temp dir");
|
||||
let store = NativeStore::open(tmp_dir.path().to_str().unwrap()).expect("open NativeStore");
|
||||
let mut vault = Vault::new(store);
|
||||
let vault = Vault::new(store);
|
||||
let keyspace = "personal";
|
||||
let password = b"testpass";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user