Trait sp_keystore::Keystore

source ·
pub trait Keystore: Send + Sync {
Show 16 methods // Required methods fn sr25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>; fn sr25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>; fn sr25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>; fn sr25519_vrf_sign( &self, key_type: KeyTypeId, public: &Public, data: &VrfSignData, ) -> Result<Option<VrfSignature>, Error>; fn sr25519_vrf_pre_output( &self, key_type: KeyTypeId, public: &Public, input: &VrfInput, ) -> Result<Option<VrfPreOutput>, Error>; fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>; fn ed25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>; fn ed25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>; fn ecdsa_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>; fn ecdsa_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>; fn ecdsa_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>; fn ecdsa_sign_prehashed( &self, key_type: KeyTypeId, public: &Public, msg: &[u8; 32], ) -> Result<Option<Signature>, Error>; fn insert( &self, key_type: KeyTypeId, suri: &str, public: &[u8], ) -> Result<(), ()>; fn keys(&self, key_type: KeyTypeId) -> Result<Vec<Vec<u8>>, Error>; fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool; // Provided method fn sign_with( &self, id: KeyTypeId, crypto_id: CryptoTypeId, public: &[u8], msg: &[u8], ) -> Result<Option<Vec<u8>>, Error> { ... }
}
Expand description

Something that generates, stores and provides access to secret keys.

Required Methods§

source

fn sr25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

Returns all the sr25519 public keys for the given key type.

source

fn sr25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

Generate a new sr25519 key pair for the given key type and an optional seed.

Returns an sr25519::Public key of the generated key pair or an Err if something failed during key generation.

source

fn sr25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

Generate an sr25519 signature for a given message.

Receives KeyTypeId and an sr25519::Public key to be able to map them to a private key that exists in the keystore.

Returns an sr25519::Signature or None in case the given key_type and public combination doesn’t exist in the keystore. An Err will be returned if generating the signature itself failed.

source

fn sr25519_vrf_sign( &self, key_type: KeyTypeId, public: &Public, data: &VrfSignData, ) -> Result<Option<VrfSignature>, Error>

Generate an sr25519 VRF signature for the given data.

Receives KeyTypeId and an sr25519::Public key to be able to map them to a private key that exists in the keystore.

Returns None if the given key_type and public combination doesn’t exist in the keystore or an Err when something failed.

source

fn sr25519_vrf_pre_output( &self, key_type: KeyTypeId, public: &Public, input: &VrfInput, ) -> Result<Option<VrfPreOutput>, Error>

Generate an sr25519 VRF pre-output for a given input data.

Receives KeyTypeId and an sr25519::Public key to be able to map them to a private key that exists in the keystore.

Returns None if the given key_type and public combination doesn’t exist in the keystore or an Err when something failed.

source

fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

Returns all ed25519 public keys for the given key type.

source

fn ed25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

Generate a new ed25519 key pair for the given key type and an optional seed.

Returns an ed25519::Public key of the generated key pair or an Err if something failed during key generation.

source

fn ed25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

Generate an ed25519 signature for a given message.

Receives KeyTypeId and an ed25519::Public key to be able to map them to a private key that exists in the keystore.

Returns an ed25519::Signature or None in case the given key_type and public combination doesn’t exist in the keystore. An Err will be returned if generating the signature itself failed.

source

fn ecdsa_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

Returns all ecdsa public keys for the given key type.

source

fn ecdsa_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

Generate a new ecdsa key pair for the given key type and an optional seed.

Returns an ecdsa::Public key of the generated key pair or an Err if something failed during key generation.

source

fn ecdsa_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

Generate an ecdsa signature for a given message.

Receives KeyTypeId and an ecdsa::Public key to be able to map them to a private key that exists in the keystore.

Returns an ecdsa::Signature or None in case the given key_type and public combination doesn’t exist in the keystore. An Err will be returned if generating the signature itself failed.

source

fn ecdsa_sign_prehashed( &self, key_type: KeyTypeId, public: &Public, msg: &[u8; 32], ) -> Result<Option<Signature>, Error>

Generate an ecdsa signature for a given pre-hashed message.

Receives KeyTypeId and an ecdsa::Public key to be able to map them to a private key that exists in the keystore.

Returns an ecdsa::Signature or None in case the given key_type and public combination doesn’t exist in the keystore. An Err will be returned if generating the signature itself failed.

source

fn insert( &self, key_type: KeyTypeId, suri: &str, public: &[u8], ) -> Result<(), ()>

Insert a new secret key.

source

fn keys(&self, key_type: KeyTypeId) -> Result<Vec<Vec<u8>>, Error>

List all supported keys of a given type.

Returns a set of public keys the signer supports in raw format.

source

fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool

Checks if the private keys for the given public key and key type combinations exist.

Returns true iff all private keys could be found.

Provided Methods§

source

fn sign_with( &self, id: KeyTypeId, crypto_id: CryptoTypeId, public: &[u8], msg: &[u8], ) -> Result<Option<Vec<u8>>, Error>

Convenience method to sign a message using the given key type and a raw public key for secret lookup.

The message is signed using the cryptographic primitive specified by crypto_id.

Schemes supported by the default trait implementation:

  • sr25519
  • ed25519
  • ecdsa
  • bandersnatch
  • bls381
  • (ecdsa,bls381) paired keys

To support more schemes you can overwrite this method.

Returns the SCALE encoded signature if key is found and supported, None if the key doesn’t exist or an error when something failed.

Implementations on Foreign Types§

source§

impl<T: Keystore + ?Sized> Keystore for Arc<T>

source§

fn sr25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

source§

fn sr25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

source§

fn sr25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

source§

fn sr25519_vrf_sign( &self, key_type: KeyTypeId, public: &Public, data: &VrfSignData, ) -> Result<Option<VrfSignature>, Error>

source§

fn sr25519_vrf_pre_output( &self, key_type: KeyTypeId, public: &Public, input: &VrfInput, ) -> Result<Option<VrfPreOutput>, Error>

source§

fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

source§

fn ed25519_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

source§

fn ed25519_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

source§

fn ecdsa_public_keys(&self, key_type: KeyTypeId) -> Vec<Public>

source§

fn ecdsa_generate_new( &self, key_type: KeyTypeId, seed: Option<&str>, ) -> Result<Public, Error>

source§

fn ecdsa_sign( &self, key_type: KeyTypeId, public: &Public, msg: &[u8], ) -> Result<Option<Signature>, Error>

source§

fn ecdsa_sign_prehashed( &self, key_type: KeyTypeId, public: &Public, msg: &[u8; 32], ) -> Result<Option<Signature>, Error>

source§

fn insert( &self, key_type: KeyTypeId, suri: &str, public: &[u8], ) -> Result<(), ()>

source§

fn keys(&self, key_type: KeyTypeId) -> Result<Vec<Vec<u8>>, Error>

source§

fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool

Implementors§