Skip to content

Commit

Permalink
modules_api: simplify public key definition (#918)
Browse files Browse the repository at this point in the history
* simplify publi key definition

* private key
  • Loading branch information
bkolad authored and dubbelosix committed Sep 29, 2023
1 parent 3b9b547 commit e6cd64a
Showing 1 changed file with 23 additions and 48 deletions.
71 changes: 23 additions & 48 deletions module-system/sov-modules-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ pub enum SigVerificationError {
}

/// Signature used in the Module System.
pub trait Signature {
pub trait Signature:
borsh::BorshDeserialize + borsh::BorshSerialize + Eq + Clone + Debug + Send + Sync
{
type PublicKey;

fn verify(&self, pub_key: &Self::PublicKey, msg: &[u8]) -> Result<(), SigVerificationError>;
Expand All @@ -150,13 +152,22 @@ pub trait Signature {
pub enum NonInstantiable {}

/// PublicKey used in the Module System.
pub trait PublicKey {
pub trait PublicKey:
borsh::BorshDeserialize + borsh::BorshSerialize + Eq + Hash + Clone + Debug + Send + Sync
{
fn to_address<A: RollupAddress>(&self) -> A;
}

/// A PrivateKey used in the Module System.
#[cfg(feature = "native")]
pub trait PrivateKey {
pub trait PrivateKey:
Debug
+ Send
+ Sync
+ for<'a> TryFrom<&'a [u8], Error = anyhow::Error>
+ Serialize
+ DeserializeOwned
{
type PublicKey: PublicKey;
type Signature: Signature<PublicKey = Self::PublicKey>;
fn generate() -> Self;
Expand Down Expand Up @@ -199,69 +210,33 @@ pub trait Spec {

/// The public key used for digital signatures
#[cfg(feature = "native")]
type PublicKey: borsh::BorshDeserialize
+ borsh::BorshSerialize
+ Eq
+ Hash
+ Clone
+ Debug
+ PublicKey
type PublicKey: PublicKey
+ Serialize
+ for<'a> Deserialize<'a>
+ ::schemars::JsonSchema
+ Send
+ Sync
+ FromStr<Err = anyhow::Error>;

#[cfg(not(feature = "native"))]
type PublicKey: PublicKey;

/// The public key used for digital signatures
#[cfg(feature = "native")]
type PrivateKey: Debug
+ Send
+ Sync
+ for<'a> TryFrom<&'a [u8], Error = anyhow::Error>
+ Serialize
+ DeserializeOwned
+ PrivateKey<PublicKey = Self::PublicKey, Signature = Self::Signature>;

#[cfg(not(feature = "native"))]
type PublicKey: borsh::BorshDeserialize
+ borsh::BorshSerialize
+ Eq
+ Hash
+ Clone
+ Debug
+ Send
+ Sync
+ PublicKey;
type PrivateKey: PrivateKey<PublicKey = Self::PublicKey, Signature = Self::Signature>;

/// The hasher preferred by the rollup, such as Sha256 or Poseidon.
type Hasher: Digest<OutputSize = U32>;

/// The digital signature scheme used by the rollup
#[cfg(feature = "native")]
type Signature: borsh::BorshDeserialize
+ borsh::BorshSerialize
type Signature: Signature<PublicKey = Self::PublicKey>
+ FromStr<Err = anyhow::Error>
+ Serialize
+ for<'a> Deserialize<'a>
+ schemars::JsonSchema
+ Eq
+ Clone
+ Debug
+ Send
+ Sync
+ FromStr<Err = anyhow::Error>
+ Signature<PublicKey = Self::PublicKey>;
+ schemars::JsonSchema;

/// The digital signature scheme used by the rollup
#[cfg(not(feature = "native"))]
type Signature: borsh::BorshDeserialize
+ borsh::BorshSerialize
+ Eq
+ Clone
+ Debug
+ Signature<PublicKey = Self::PublicKey>
+ Send
+ Sync;
type Signature: Signature<PublicKey = Self::PublicKey>;

/// A structure containing the non-deterministic inputs from the prover to the zk-circuit
type Witness: Witness;
Expand Down

0 comments on commit e6cd64a

Please sign in to comment.