[][src]Trait frame_system::offchain::AppCrypto

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>;
    fn sign(payload: &[u8], public: Public) -> Option<Signature> { ... }
fn verify(payload: &[u8], public: Public, signature: Signature) -> bool { ... } }

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.

TODO [#5662] Potentially use IsWrappedBy types, or find some other way to make it easy to obtain unwrapped crypto (and wrap it back).

Example (pseudo-)implementation:

This example is not tested
// 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 = MulitSignature: From<sr25519::Signature>;

Associated Types

type RuntimeAppPublic: RuntimeAppPublic

A application-specific crypto.

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

A raw crypto public key wrapped by RuntimeAppPublic.

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

A matching raw crypto Signature type.

Loading content...

Provided methods

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

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

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

Verify signature against the provided public key.

Loading content...

Implementors

Loading content...