bdk_wallet::keys

Trait GeneratableKey

Source
pub trait GeneratableKey<Ctx: ScriptContext>: Sized {
    type Entropy: AsMut<[u8]> + Default;
    type Options;
    type Error: Debug;

    // Required method
    fn generate_with_entropy(
        options: Self::Options,
        entropy: Self::Entropy,
    ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>;

    // Provided methods
    fn generate(
        options: Self::Options,
    ) -> Result<GeneratedKey<Self, Ctx>, Self::Error> { ... }
    fn generate_with_aux_rand(
        options: Self::Options,
        rng: &mut (impl CryptoRng + RngCore),
    ) -> Result<GeneratedKey<Self, Ctx>, Self::Error> { ... }
}
Expand description

Trait for keys that can be generated

The same rules about ScriptContext and ValidNetworks from IntoDescriptorKey apply.

This trait is particularly useful when combined with DerivableKey: if Self implements it, the returned GeneratedKey will also implement it. The same is true for IntoDescriptorKey: the generated keys can be directly used in descriptors if Self is also IntoDescriptorKey.

Required Associated Types§

Source

type Entropy: AsMut<[u8]> + Default

Type specifying the amount of entropy required e.g. [u8;32]

Source

type Options

Extra options required by the generate_with_entropy

Source

type Error: Debug

Returned error in case of failure

Required Methods§

Source

fn generate_with_entropy( options: Self::Options, entropy: Self::Entropy, ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>

Generate a key given the extra options and the entropy

Provided Methods§

Source

fn generate( options: Self::Options, ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>

Generate a key given the options with random entropy.

Uses the thread-local random number generator.

Source

fn generate_with_aux_rand( options: Self::Options, rng: &mut (impl CryptoRng + RngCore), ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>

Generate a key given the options with random entropy.

Uses a provided random number generator (rng).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<Ctx: ScriptContext> GeneratableKey<Ctx> for PrivateKey

Source§

type Entropy = [u8; 32]

Source§

type Options = PrivateKeyGenerateOptions

Source§

type Error = Error

Source§

fn generate_with_entropy( options: Self::Options, entropy: Self::Entropy, ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>

Source§

impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Xpriv

Source§

type Entropy = [u8; 32]

Source§

type Options = ()

Source§

type Error = Error

Source§

fn generate_with_entropy( _: Self::Options, entropy: Self::Entropy, ) -> Result<GeneratedKey<Self, Ctx>, Self::Error>

Implementors§