Skip to main content

Derive

Trait Derive 

Source
pub trait Derive {
    type Account: AsRef<DerivedAccount>;
    type Error: Debug + Display + From<DeriveError>;

    // Required methods
    fn derive(&self, index: u32) -> Result<Self::Account, Self::Error>;
    fn derive_path(&self, path: &str) -> Result<Self::Account, Self::Error>;
}
Expand description

Unified derivation trait implemented by every chain deriver.

Each chain implements this trait on its Deriver type and declares the account newtype it returns via the associated Account type. The AsRef<DerivedAccount> bound keeps the unified read view available to generic callers, without erasing chain-specific metadata (BTC WIF, Solana keypair, Nostr nsec, …).

Batch derivation is provided by the blanket DeriveExt trait.

§Example

use kobe_primitives::{Derive, DerivedAccount};

fn first_address<D: Derive>(d: &D) -> String {
    // `as_ref` yields the unified view regardless of the chain newtype.
    let account = d.derive(0).unwrap();
    let view: &DerivedAccount = account.as_ref();
    view.address().to_owned()
}

Required Associated Types§

Source

type Account: AsRef<DerivedAccount>

The (possibly newtype) account returned by this deriver.

Chains without chain-specific metadata set Account = DerivedAccount directly; chains with extra fields (BTC, SVM, Nostr) return their own <Chain>Account wrapper.

Source

type Error: Debug + Display + From<DeriveError>

The error type returned by derivation operations.

Required Methods§

Source

fn derive(&self, index: u32) -> Result<Self::Account, Self::Error>

Derive an account at the given index using the chain’s default path.

§Errors

Returns an error if key derivation or address encoding fails.

Source

fn derive_path(&self, path: &str) -> Result<Self::Account, Self::Error>

Derive an account at a custom path string.

§Errors

Returns an error if the path is invalid or derivation fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§