pub trait KeyProvider: Send + Sync {
// Required methods
fn get_next_keypair(
&self,
keypair_index: KeypairIndex,
) -> Result<Keypair, Error>;
fn get_keypair_for_path(&self, path: &[u32]) -> Result<Keypair, Error>;
fn get_keypair_for_pk(&self, pk: &XOnlyPublicKey) -> Result<Keypair, Error>;
fn get_cached_pks(&self) -> Result<Vec<XOnlyPublicKey>, Error>;
}Expand description
Provides keypairs for signing operations
This trait allows different key management strategies:
- Static keypair (single key)
- BIP32 HD wallet (hierarchical deterministic)
- Hardware wallets (future)
- Custom key derivation schemes
Required Methods§
Sourcefn get_next_keypair(
&self,
keypair_index: KeypairIndex,
) -> Result<Keypair, Error>
fn get_next_keypair( &self, keypair_index: KeypairIndex, ) -> Result<Keypair, Error>
Get a keypair for receiving funds
For static key providers, this always returns the same keypair regardless of the index.
For HD wallets, behavior depends on the keypair_index parameter.
§Arguments
keypair_index- Controls which keypair to return:KeypairIndex::New: Increments the internal index and returns a new keypairKeypairIndex::LastUnused: Returns the last unused keypair without incrementing
§Returns
A keypair to use for receiving funds
Sourcefn get_keypair_for_pk(&self, pk: &XOnlyPublicKey) -> Result<Keypair, Error>
fn get_keypair_for_pk(&self, pk: &XOnlyPublicKey) -> Result<Keypair, Error>
Get a keypair for a specific public key
This is essential for HD wallets where you need to find the correct keypair for signing with a previously generated public key.
§Arguments
pk- The X-only public key to find the keypair for
§Returns
The keypair corresponding to the public key, or an error if not found
Sourcefn get_cached_pks(&self) -> Result<Vec<XOnlyPublicKey>, Error>
fn get_cached_pks(&self) -> Result<Vec<XOnlyPublicKey>, Error>
Get all public keys that this provider currently knows about
For static key providers, this returns the single keypair’s public key.
For HD wallets, this returns all public keys that have been derived and cached
(i.e., keys generated via get_next_keypair).
This is useful for determining which keys are available for signing operations without having to search or derive new keys.
§Returns
A vector of X-only public keys known to this provider
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".