...
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run

This commit is contained in:
2025-05-12 12:16:03 +03:00
parent e47e163285
commit a8ed0900fd
13 changed files with 320 additions and 227 deletions

View File

@@ -12,7 +12,7 @@ mod postgresclient;
mod process;
mod redisclient;
mod rfs;
mod hero_vault; // This module now uses hero_vault internally
mod vault;
mod text;
mod zinit;
@@ -111,7 +111,7 @@ pub use crate::text::{
pub use text::*;
// Re-export crypto module
pub use hero_vault::register_crypto_module;
pub use vault::register_crypto_module;
// Rename copy functions to avoid conflicts
pub use os::copy as os_copy;
@@ -162,7 +162,7 @@ pub fn register(engine: &mut Engine) -> Result<(), Box<rhai::EvalAltResult>> {
rfs::register(engine)?;
// Register Crypto module functions
hero_vault::register_crypto_module(engine)?;
vault::register_crypto_module(engine)?;
// Register Redis client module functions

View File

@@ -11,9 +11,10 @@ use tokio::runtime::Runtime;
use ethers::types::{Address, U256};
use std::str::FromStr;
use crate::vault::{keypair, symmetric, ethereum};
use crate::vault::ethereum::{prepare_function_arguments, convert_token_to_rhai};
use crate::vault::{keypair, ethereum};
use crate::vault::ethereum::contract_utils::{prepare_function_arguments, convert_token_to_rhai};
use symmetric_impl::implementation as symmetric_impl;
// Global Tokio runtime for blocking async operations
static RUNTIME: Lazy<Mutex<Runtime>> = Lazy::new(|| {
Mutex::new(Runtime::new().expect("Failed to create Tokio runtime"))
@@ -55,7 +56,7 @@ fn load_key_space(name: &str, password: &str) -> bool {
};
// Deserialize the encrypted space
let encrypted_space = match symmetric::deserialize_encrypted_space(&serialized) {
let encrypted_space = match symmetric_impl::deserialize_encrypted_space(&serialized) {
Ok(space) => space,
Err(e) => {
log::error!("Error deserializing key space: {}", e);
@@ -64,7 +65,7 @@ fn load_key_space(name: &str, password: &str) -> bool {
};
// Decrypt the space
let space = match symmetric::decrypt_key_space(&encrypted_space, password) {
let space = match symmetric_impl::decrypt_key_space(&encrypted_space, password) {
Ok(space) => space,
Err(e) => {
log::error!("Error decrypting key space: {}", e);
@@ -83,13 +84,13 @@ fn load_key_space(name: &str, password: &str) -> bool {
}
fn create_key_space(name: &str, password: &str) -> bool {
match keypair::create_space(name) {
match keypair::session_manager::create_space(name) {
Ok(_) => {
// Get the current space
match keypair::get_current_space() {
Ok(space) => {
// Encrypt the key space
let encrypted_space = match symmetric::encrypt_key_space(&space, password) {
let encrypted_space = match symmetric_impl::encrypt_key_space(&space, password) {
Ok(encrypted) => encrypted,
Err(e) => {
log::error!("Error encrypting key space: {}", e);
@@ -98,7 +99,7 @@ fn create_key_space(name: &str, password: &str) -> bool {
};
// Serialize the encrypted space
let serialized = match symmetric::serialize_encrypted_space(&encrypted_space) {
let serialized = match symmetric_impl::serialize_encrypted_space(&encrypted_space) {
Ok(json) => json,
Err(e) => {
log::error!("Error serializing encrypted space: {}", e);
@@ -152,7 +153,7 @@ fn auto_save_key_space(password: &str) -> bool {
match keypair::get_current_space() {
Ok(space) => {
// Encrypt the key space
let encrypted_space = match symmetric::encrypt_key_space(&space, password) {
let encrypted_space = match symmetric_impl::encrypt_key_space(&space, password) {
Ok(encrypted) => encrypted,
Err(e) => {
log::error!("Error encrypting key space: {}", e);
@@ -161,7 +162,7 @@ fn auto_save_key_space(password: &str) -> bool {
};
// Serialize the encrypted space
let serialized = match symmetric::serialize_encrypted_space(&encrypted_space) {
let serialized = match symmetric_impl::serialize_encrypted_space(&encrypted_space) {
Ok(json) => json,
Err(e) => {
log::error!("Error serializing encrypted space: {}", e);
@@ -207,7 +208,7 @@ fn auto_save_key_space(password: &str) -> bool {
fn encrypt_key_space(password: &str) -> String {
match keypair::get_current_space() {
Ok(space) => {
match symmetric::encrypt_key_space(&space, password) {
match symmetric_impl::encrypt_key_space(&space, password) {
Ok(encrypted_space) => {
match serde_json::to_string(&encrypted_space) {
Ok(json) => json,
@@ -233,7 +234,7 @@ fn encrypt_key_space(password: &str) -> String {
fn decrypt_key_space(encrypted: &str, password: &str) -> bool {
match serde_json::from_str(encrypted) {
Ok(encrypted_space) => {
match symmetric::decrypt_key_space(&encrypted_space, password) {
match symmetric_impl::decrypt_key_space(&encrypted_space, password) {
Ok(space) => {
match keypair::set_current_space(space) {
Ok(_) => true,
@@ -323,7 +324,7 @@ fn verify(message: &str, signature: &str) -> bool {
// Symmetric encryption
fn generate_key() -> String {
let key = symmetric::generate_symmetric_key();
let key = symmetric_impl::generate_symmetric_key();
BASE64.encode(key)
}
@@ -331,7 +332,7 @@ fn encrypt(key: &str, message: &str) -> String {
match BASE64.decode(key) {
Ok(key_bytes) => {
let message_bytes = message.as_bytes();
match symmetric::encrypt_symmetric(&key_bytes, message_bytes) {
match symmetric_impl::encrypt_symmetric(&key_bytes, message_bytes) {
Ok(ciphertext) => BASE64.encode(ciphertext),
Err(e) => {
log::error!("Error encrypting message: {}", e);
@@ -351,7 +352,7 @@ fn decrypt(key: &str, ciphertext: &str) -> String {
Ok(key_bytes) => {
match BASE64.decode(ciphertext) {
Ok(ciphertext_bytes) => {
match symmetric::decrypt_symmetric(&key_bytes, &ciphertext_bytes) {
match symmetric_impl::decrypt_symmetric(&key_bytes, &ciphertext_bytes) {
Ok(plaintext) => {
match String::from_utf8(plaintext) {
Ok(text) => text,