referrerpolicy=no-referrer-when-downgrade
frame_system::offchain

Trait AppCrypto

Source
pub trait AppCrypto<Public, Signature> {
    type RuntimeAppPublic: RuntimeAppPublic;
    type GenericPublic: From<Self::RuntimeAppPublic> + Into<Self::RuntimeAppPublic> + TryFrom<Public> + Into<Public>;
    type GenericSignature: From<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> + Into<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> + TryFrom<Signature> + Into<Signature>;

    // Provided methods
    fn sign(payload: &[u8], public: Public) -> Option<Signature> { ... }
    fn verify(payload: &[u8], public: Public, signature: Signature) -> bool { ... }
}
Expand description

A type binding runtime-level Public/Signature pair with crypto wrapped by RuntimeAppPublic.

Implementations of this trait should specify the app-specific public/signature types. This is merely a wrapper around an existing RuntimeAppPublic type, but with extra non-application-specific crypto type that is being wrapped (e.g. sr25519, ed25519). This is needed to later on convert into runtime-specific Public key, which might support multiple different crypto. The point of this trait is to be able to easily convert between RuntimeAppPublic, the wrapped (generic = non application-specific) crypto types and the Public type required by the runtime.

Example (pseudo-)implementation:

// im-online specific crypto
type RuntimeAppPublic = ImOnline(sr25519::Public);

// wrapped "raw" crypto
type GenericPublic = sr25519::Public;
type GenericSignature = sr25519::Signature;

// runtime-specific public key
type Public = MultiSigner: From<sr25519::Public>;
type Signature = MultiSignature: From<sr25519::Signature>;

Required Associated Types§

Source

type RuntimeAppPublic: RuntimeAppPublic

A application-specific crypto.

Source

type GenericPublic: From<Self::RuntimeAppPublic> + Into<Self::RuntimeAppPublic> + TryFrom<Public> + Into<Public>

A raw crypto public key wrapped by RuntimeAppPublic.

Source

type GenericSignature: From<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> + Into<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> + TryFrom<Signature> + Into<Signature>

A matching raw crypto Signature type.

Provided Methods§

Source

fn sign(payload: &[u8], public: Public) -> Option<Signature>

Sign payload with the private key to maps to the provided public key.

Source

fn verify(payload: &[u8], public: Public, signature: Signature) -> bool

Verify signature against the provided public key.

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.

Implementors§

impl AppCrypto<<CryptoBytes<sp_core::::sr25519::Signature::{constant#0}, (SignatureTag, Sr25519Tag)> as Verify>::Signer, CryptoBytes<sp_core::::sr25519::Signature::{constant#0}, (SignatureTag, Sr25519Tag)>> for TestAuthId

impl AppCrypto<MultiSigner, MultiSignature> for TestAuthId