bc_components/private_key_data_provider.rs
1/// A trait for types that can provide unique data for cryptographic key derivation.
2///
3/// Types implementing `PrivateKeyDataProvider` can be used as seed material for
4/// cryptographic key derivation. The provided data should be sufficiently random
5/// and unpredictable to ensure the security of the derived keys.
6///
7/// This trait is particularly useful for:
8/// - Deterministic key generation systems
9/// - Key recovery mechanisms
10/// - Key derivation hierarchies
11/// - Hierarchical deterministic wallet implementations
12///
13/// # Security Considerations
14///
15/// Implementers of this trait should ensure that:
16/// - The data they provide has sufficient entropy
17/// - The data is properly protected in memory
18/// - Any serialization or storage is done securely
19/// - Appropriate zeroization occurs when data is no longer needed
20pub trait PrivateKeyDataProvider {
21 /// Returns unique data from which cryptographic keys can be derived.
22 ///
23 /// The returned data should be sufficiently random and have enough entropy
24 /// to serve as the basis for secure cryptographic key derivation.
25 ///
26 /// # Returns
27 ///
28 /// A vector of bytes containing the private key data.
29 fn private_key_data(&self) -> Vec<u8>;
30}
31
32/// Implementation of `PrivateKeyDataProvider` for any type that can be referenced as a byte slice.
33///
34/// This allows any type that implements `AsRef<[u8]>` to be used as a source of
35/// private key data.
36impl PrivateKeyDataProvider for dyn AsRef<[u8]> {
37 fn private_key_data(&self) -> Vec<u8> {
38 self.as_ref().to_vec()
39 }
40}