bc_components/
private_key_data_provider.rs

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