This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Simplify AppCrypto offchain type conversion #5662
Copy link
Copy link
Open
Labels
I7-refactorCode needs refactoring.Code needs refactoring.
Description
As a follow up to the refactoring of #5182, AppCrypto trait type conversions need some simplification. The scription attached explains what needs to be done.
substrate/frame/system/src/offchain.rs
Lines 397 to 438 in 4a6d268
| /// App-specific crypto trait that provides sign/verify abilities to offchain workers. | |
| /// | |
| /// 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` and | |
| /// the wrapped crypto types. | |
| /// | |
| /// TODO [#???] Potentially use `IsWrappedBy` types, or find some other way to make it easy to | |
| /// obtain unwrapped crypto (and wrap it back). | |
| /// | |
| /// 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 = MulitSignature: From<sr25519::Signature>; | |
| /// ``` | |
| pub trait AppCrypto<Public, Signature> { | |
| /// A application-specific crypto. | |
| type RuntimeAppPublic: RuntimeAppPublic; | |
| /// A raw crypto public key wrapped by `RuntimeAppPublic`. | |
| type GenericPublic: | |
| From<Self::RuntimeAppPublic> | |
| + Into<Self::RuntimeAppPublic> | |
| + TryFrom<Public> | |
| + Into<Public>; | |
| /// A matching raw crypto `Signature` type. | |
| type GenericSignature: | |
| From<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> | |
| + Into<<Self::RuntimeAppPublic as RuntimeAppPublic>::Signature> | |
| + TryFrom<Signature> | |
| + Into<Signature>; |
Metadata
Metadata
Assignees
Labels
I7-refactorCode needs refactoring.Code needs refactoring.