Files
pezkuwi-subxt/subxt/src/utils/multi_signature.rs
T
James Wilson a2b8dde5e6 Add 'Static' type and improve type substitution codegen to accept it (#886)
* Add Static type which defers to Encode/Decode and impls EncodeAsType/DecodeAsType

* rename to static_type and impl Deref/Mut

* Improve type substitution in codegen so that concrete types can be swapped in

* A couple of comment tweaks and no need for a macro export

* Extend type substitution logic to work recursively on destination type

* cargo fmt

* Fix a couple of comments

* update ui test outpuot

* Add docs and missing_docs lint

* Add test for replacing multiple of Ident

* Update codegen/src/error.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* update copyright year and fix ui test

* simplify another error

---------

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
2023-03-31 16:56:19 +01:00

59 lines
2.2 KiB
Rust

// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
//! The "default" Substrate/Polkadot Signature type. This is used in codegen, as well as signing related bits.
//! This doesn't contain much functionality itself, but is easy to convert to/from an `sp_runtime::MultiSignature`
//! for instance, to gain functionality without forcing a dependency on Substrate crates here.
use codec::{Decode, Encode};
/// Signature container that can store known signature types. This is a simplified version of
/// `sp_runtime::MultiSignature`. To obtain more functionality, convert this into that type.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)]
pub enum MultiSignature {
/// An Ed25519 signature.
Ed25519([u8; 64]),
/// An Sr25519 signature.
Sr25519([u8; 64]),
/// An ECDSA/SECP256k1 signature (a 512-bit value, plus 8 bits for recovery ID).
Ecdsa([u8; 65]),
}
// Improve compat with the substrate version if we're using those crates:
#[cfg(feature = "substrate-compat")]
mod substrate_impls {
use super::*;
impl From<sp_runtime::MultiSignature> for MultiSignature {
fn from(value: sp_runtime::MultiSignature) -> Self {
match value {
sp_runtime::MultiSignature::Ed25519(s) => Self::Ed25519(s.0),
sp_runtime::MultiSignature::Sr25519(s) => Self::Sr25519(s.0),
sp_runtime::MultiSignature::Ecdsa(s) => Self::Ecdsa(s.0),
}
}
}
impl From<sp_core::ed25519::Signature> for MultiSignature {
fn from(value: sp_core::ed25519::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
impl From<sp_core::sr25519::Signature> for MultiSignature {
fn from(value: sp_core::sr25519::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
impl From<sp_core::ecdsa::Signature> for MultiSignature {
fn from(value: sp_core::ecdsa::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
}