Skip to content

Commit

Permalink
feat: add memory db key manager util function (#6444)
Browse files Browse the repository at this point in the history
This helps with creating a few keys from seed words
  • Loading branch information
stringhandler authored Aug 3, 2024
1 parent af1f451 commit 900a107
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ pub fn create_memory_db_key_manager_with_range_proof_size(
)
}

pub fn create_memory_db_key_manager_from_seed(
seed: CipherSeed,
rangeproof_size: usize,
) -> Result<MemoryDbKeyManager, KeyManagerServiceError> {
let connection = DbConnection::connect_url(&DbConnectionUrl::MemoryShared(random_string(8)))?;
let cipher = seed;

let mut key = [0u8; size_of::<Key>()];
OsRng.fill_bytes(&mut key);
let key_ga = Key::from_slice(&key);
let db_cipher = XChaCha20Poly1305::new(key_ga);
let factory = CryptoFactories::new(rangeproof_size);

TransactionKeyManagerWrapper::<KeyManagerSqliteDatabase<DbConnection>>::new(
cipher,
KeyManagerDatabase::new(KeyManagerSqliteDatabase::init(connection, db_cipher)),
factory,
WalletType::default(),
)
}

pub fn create_memory_db_key_manager() -> Result<MemoryDbKeyManager, KeyManagerServiceError> {
create_memory_db_key_manager_with_range_proof_size(64)
}
1 change: 1 addition & 0 deletions base_layer/core/src/transactions/key_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod memory_db_key_manager;
pub use inner::TransactionKeyManagerInner;
pub use memory_db_key_manager::{
create_memory_db_key_manager,
create_memory_db_key_manager_from_seed,
create_memory_db_key_manager_with_range_proof_size,
MemoryDbKeyManager,
};
Expand Down

0 comments on commit 900a107

Please sign in to comment.