pub struct Seed { /* private fields */ }Expand description
A cryptographic seed for deterministic key generation.
A Seed is a source of entropy used to generate cryptographic keys in a
deterministic manner. Unlike randomly generated keys, seed-derived keys can
be recreated if you have the original seed, making them useful for backup
and recovery scenarios.
This implementation of Seed includes the random seed data as well as
optional metadata:
- A name (for identifying the seed)
- A note (for storing additional information)
- A creation date
The minimum seed length is 16 bytes to ensure sufficient security and entropy.
§CBOR Serialization
Seed implements the CBORTaggedCodable trait, which means it can be
serialized to and deserialized from CBOR with specific tags. The tags used
are TAG_SEED and the older TAG_SEED_V1 for backward compatibility.
When serialized to CBOR, a Seed is represented as a map with the following
keys:
- 1: The seed data (required)
- 2: The creation date (optional)
- 3: The name (optional, omitted if empty)
- 4: The note (optional, omitted if empty)
§UR Serialization
When serialized as a Uniform Resource (UR), a Seed is represented with the
type “seed”.
§Key Derivation
A Seed implements the PrivateKeyDataProvider trait, which means it can
be used as a source of entropy for deriving private keys in various
cryptographic schemes.
§Examples
Creating a new random seed:
use bc_components::Seed;
// Create a new random seed with default length (16 bytes)
let seed = Seed::new();Creating a seed with a specific length:
use bc_components::Seed;
// Create a seed with 32 bytes of entropy
let seed = Seed::new_with_len(32).unwrap();Creating a seed with metadata:
use bc_components::Seed;
use dcbor::prelude::*;
// Create seed data
let data = vec![0u8; 16];
// Create a seed with name, note, and creation date
let mut seed = Seed::new_opt(
data,
Some("Wallet Backup".to_string()),
Some("Cold storage backup for main wallet".to_string()),
Some(Date::now()),
)
.unwrap();
// Modify metadata
seed.set_name("Updated Wallet Backup");Implementations§
Source§impl Seed
impl Seed
pub const MIN_SEED_LENGTH: usize = 16usize
Sourcepub fn new_with_len(count: usize) -> Result<Self>
pub fn new_with_len(count: usize) -> Result<Self>
Create a new random seed with a specified length.
If the number of bytes is less than 16, this will return None.
Sourcepub fn new_with_len_using(
count: usize,
rng: &mut impl RandomNumberGenerator,
) -> Result<Self>
pub fn new_with_len_using( count: usize, rng: &mut impl RandomNumberGenerator, ) -> Result<Self>
Create a new random seed with a specified length.
If the number of bytes is less than 16, this will return None.
Sourcepub fn new_opt(
data: impl AsRef<[u8]>,
name: Option<String>,
note: Option<String>,
creation_date: Option<Date>,
) -> Result<Self>
pub fn new_opt( data: impl AsRef<[u8]>, name: Option<String>, note: Option<String>, creation_date: Option<Date>, ) -> Result<Self>
Create a new seed from the data and options.
If the data is less than 16 bytes, this will return None.
Sourcepub fn creation_date(&self) -> &Option<Date>
pub fn creation_date(&self) -> &Option<Date>
Return the creation date of the seed.
Sourcepub fn set_creation_date(&mut self, creation_date: Option<Date>)
pub fn set_creation_date(&mut self, creation_date: Option<Date>)
Set the creation date of the seed.
Trait Implementations§
Source§impl AsRef<Seed> for Seed
Provides a self-reference, enabling API consistency with other types.
impl AsRef<Seed> for Seed
Provides a self-reference, enabling API consistency with other types.
Source§impl CBORTagged for Seed
Identifies the CBOR tags used for Seed serialization, including the legacy
tag.
impl CBORTagged for Seed
Identifies the CBOR tags used for Seed serialization, including the legacy tag.
Source§impl CBORTaggedDecodable for Seed
Defines how a Seed is decoded from CBOR.
impl CBORTaggedDecodable for Seed
Defines how a Seed is decoded from CBOR.
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for Seed
Defines how a Seed is encoded as CBOR (as a map with data and metadata).
impl CBORTaggedEncodable for Seed
Defines how a Seed is encoded as CBOR (as a map with data and metadata).
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Default for Seed
Provides a default implementation that creates a new random seed with the
minimum length.
impl Default for Seed
Provides a default implementation that creates a new random seed with the minimum length.
Source§impl PrivateKeyDataProvider for Seed
Implements PrivateKeyDataProvider to use seed data for key derivation.
impl PrivateKeyDataProvider for Seed
Implements PrivateKeyDataProvider to use seed data for key derivation.
impl Eq for Seed
impl StructuralPartialEq for Seed
Auto Trait Implementations§
impl Freeze for Seed
impl RefUnwindSafe for Seed
impl Send for Seed
impl Sync for Seed
impl Unpin for Seed
impl UnwindSafe for Seed
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)