1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::errors::SignatureError;
use snarkvm_utilities::{
serialize::{CanonicalDeserialize, CanonicalSerialize},
FromBytes,
ToBytes,
};
use rand::Rng;
use std::{fmt::Debug, hash::Hash};
pub trait SignatureScheme: Sized + Clone + From<<Self as SignatureScheme>::Parameters> {
type Parameters: Clone + Debug + ToBytes + FromBytes + Eq + Send + Sync;
type PublicKey: Clone
+ Debug
+ Default
+ ToBytes
+ FromBytes
+ Hash
+ Eq
+ Send
+ Sync
+ CanonicalSerialize
+ CanonicalDeserialize;
type PrivateKey: Clone + Debug + Default + ToBytes + FromBytes + PartialEq + Eq;
type Signature: Clone + Debug + Default + ToBytes + FromBytes + Send + Sync + PartialEq + Eq;
fn setup<R: Rng>(rng: &mut R) -> Result<Self, SignatureError>;
fn parameters(&self) -> &Self::Parameters;
fn generate_private_key<R: Rng>(&self, rng: &mut R) -> Result<Self::PrivateKey, SignatureError>;
fn generate_public_key(&self, private_key: &Self::PrivateKey) -> Result<Self::PublicKey, SignatureError>;
fn sign<R: Rng>(
&self,
private_key: &Self::PrivateKey,
message: &[u8],
rng: &mut R,
) -> Result<Self::Signature, SignatureError>;
fn verify(
&self,
public_key: &Self::PublicKey,
message: &[u8],
signature: &Self::Signature,
) -> Result<bool, SignatureError>;
fn randomize_public_key(
&self,
public_key: &Self::PublicKey,
randomness: &[u8],
) -> Result<Self::PublicKey, SignatureError>;
fn randomize_signature(
&self,
signature: &Self::Signature,
randomness: &[u8],
) -> Result<Self::Signature, SignatureError>;
}