...
This commit is contained in:
parent
393c4270d4
commit
a4438d63e0
@ -16,7 +16,7 @@ static ETH_WALLETS: Lazy<Mutex<HashMap<String, Vec<EthereumWallet>>>> = Lazy::ne
|
||||
/// Creates an Ethereum wallet from the currently selected keypair for a specific network.
|
||||
pub fn create_ethereum_wallet_for_network(network: NetworkConfig) -> Result<EthereumWallet, CryptoError> {
|
||||
// Get the currently selected keypair
|
||||
let keypair = crate::vault::keypair::get_selected_keypair()?;
|
||||
let keypair = crate::vault::keyspace::get_selected_keypair()?;
|
||||
|
||||
// Create an Ethereum wallet from the keypair
|
||||
let wallet = EthereumWallet::from_keypair(&keypair, network)?;
|
||||
@ -77,7 +77,7 @@ pub fn clear_ethereum_wallets_for_network(network_name: &str) {
|
||||
/// Creates an Ethereum wallet from a name and the currently selected keypair for a specific network.
|
||||
pub fn create_ethereum_wallet_from_name_for_network(name: &str, network: NetworkConfig) -> Result<EthereumWallet, CryptoError> {
|
||||
// Get the currently selected keypair
|
||||
let keypair = crate::vault::keypair::get_selected_keypair()?;
|
||||
let keypair = crate::vault::keyspace::get_selected_keypair()?;
|
||||
|
||||
// Create an Ethereum wallet from the name and keypair
|
||||
let wallet = EthereumWallet::from_name_and_keypair(name, &keypair, network)?;
|
||||
|
@ -1,7 +0,0 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
mod implementation_tests;
|
||||
mod keypair_types_tests;
|
||||
mod session_manager_tests;
|
@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::vault::error::CryptoError;
|
||||
use crate::vault::keypair::keypair_types::{KeyPair, KeySpace}; // Assuming KeyPair and KeySpace will be in keypair_types.rs
|
||||
use crate::vault::keyspace::keypair_types::{KeyPair, KeySpace}; // Assuming KeyPair and KeySpace will be in keypair_types.rs
|
||||
|
||||
/// Session state for the current key space and selected keypair.
|
||||
pub struct Session {
|
36
src/vault/keyspace/spec.md
Normal file
36
src/vault/keyspace/spec.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Keyspace Module Specification
|
||||
|
||||
This document explains the purpose and functionality of the `keyspace` module within the Hero Vault.
|
||||
|
||||
## Purpose of the Module
|
||||
|
||||
The `keyspace` module provides a secure and organized way to manage cryptographic keypairs. It allows for the creation, storage, loading, and utilization of keypairs within designated containers called keyspaces. This module is essential for handling sensitive cryptographic material securely.
|
||||
|
||||
## What is a Keyspace?
|
||||
|
||||
A keyspace is a logical container designed to hold multiple cryptographic keypairs. It is represented by the `KeySpace` struct in the code. Keyspaces can be encrypted and persisted to disk, providing a secure method for storing collections of keypairs. Each keyspace is identified by a unique name.
|
||||
|
||||
## What is a Keypair?
|
||||
|
||||
A keypair, represented by the `KeyPair` struct, is a fundamental cryptographic element consisting of a mathematically linked pair of keys: a public key and a private key. In this module, ECDSA (Elliptic Curve Digital Signature Algorithm) keypairs are used.
|
||||
|
||||
* **Private Key:** This key is kept secret and is used for operations like signing data or decrypting messages intended for the keypair's owner.
|
||||
* **Public Key:** This key can be shared openly and is used to verify signatures created by the corresponding private key or to encrypt messages that can only be decrypted by the private key.
|
||||
|
||||
## How Many Keypairs Per Space?
|
||||
|
||||
A keyspace can hold multiple keypairs. The `KeySpace` struct uses a `HashMap` to store keypairs, where each keypair is associated with a unique string name. There is no inherent, fixed limit on the number of keypairs a keyspace can contain, beyond the practical limitations of system memory.
|
||||
|
||||
## How Do We Load Them?
|
||||
|
||||
Keyspaces are loaded from persistent storage (disk) using the `KeySpace::load` function, which requires the keyspace name and a password for decryption. Once a `KeySpace` object is loaded into memory, it can be set as the currently active keyspace for the session using the `session_manager::set_current_space` function. Individual keypairs within the loaded keyspace are then accessed by their names using functions like `session_manager::select_keypair` and `session_manager::get_selected_keypair`.
|
||||
|
||||
## What Do They Do?
|
||||
|
||||
Keypairs within a keyspace are used to perform various cryptographic operations. The `KeyPair` struct provides methods for:
|
||||
|
||||
* **Digital Signatures:** Signing messages with the private key (`KeyPair::sign`) and verifying those signatures with the public key (`KeyPair::verify`).
|
||||
* **Ethereum Address Derivation:** Generating an Ethereum address from the public key (`KeyPair::to_ethereum_address`).
|
||||
* **Asymmetric Encryption/Decryption:** Encrypting data using a recipient's public key (`KeyPair::encrypt_asymmetric`) and decrypting data encrypted with the keypair's public key using the private key (`KeyPair::decrypt_asymmetric`).
|
||||
|
||||
The `session_manager` module provides functions that utilize the currently selected keypair to perform these operations within the context of the active session.
|
@ -1,5 +1,5 @@
|
||||
|
||||
use crate::vault::keypair::keypair_types::{KeyPair, KeySpace};
|
||||
use crate::vault::keyspace::keypair_types::{KeyPair, KeySpace};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
3
src/vault/keyspace/tests/mod.rs
Normal file
3
src/vault/keyspace/tests/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
mod keypair_types_tests;
|
||||
mod session_manager_tests;
|
@ -1,8 +1,8 @@
|
||||
use crate::vault::keypair::session_manager::{
|
||||
use crate::vault::keyspace::session_manager::{
|
||||
clear_session, create_keypair, create_space, get_current_space, get_selected_keypair,
|
||||
list_keypairs, select_keypair, set_current_space, SESSION,
|
||||
};
|
||||
use crate::vault::keypair::keypair_types::KeySpace;
|
||||
use crate::vault::keyspace::keypair_types::KeySpace;
|
||||
|
||||
// Helper function to clear the session before each test
|
||||
fn setup_test() {
|
@ -9,7 +9,7 @@
|
||||
//! - Key-value store with encryption
|
||||
|
||||
pub mod error;
|
||||
pub mod keypair;
|
||||
pub mod keyspace;
|
||||
pub mod symmetric;
|
||||
pub mod ethereum;
|
||||
pub mod kvs;
|
||||
@ -17,4 +17,4 @@ pub mod kvs;
|
||||
// Re-export modules
|
||||
// Re-export common types for convenience
|
||||
pub use error::CryptoError;
|
||||
pub use keypair::{KeyPair, KeySpace};
|
||||
pub use keyspace::{KeyPair, KeySpace};
|
||||
|
@ -7,7 +7,7 @@ use serde::{Serialize, Deserialize};
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
use crate::vault::error::CryptoError;
|
||||
use crate::vault::keypair::KeySpace;
|
||||
use crate::vault::keyspace::KeySpace;
|
||||
|
||||
/// The size of the nonce in bytes.
|
||||
const NONCE_SIZE: usize = 12;
|
||||
|
Loading…
Reference in New Issue
Block a user