Skip to main content

witnet_bls_signatures/
lib.rs

1//! This crate provides:
2//!
3//! - `MultiSignature` trait for specifying curves with multi signature support.
4//! - `bn256` module implementing the aforementioned trait for the BLS curve bn256.
5
6pub mod bn256;
7
8/// The `MultiSignature` trait specifies an interface common for curves with multi signature support.
9///
10/// This trait requires to define the types for `PublicKey`, `SecretKey` and `Signature`.
11pub trait MultiSignature<PublicKey, SecretKey, Signature> {
12    type Error;
13
14    /// Function to derive public key given a secret key.
15    ///
16    /// # Arguments
17    ///
18    /// * `secret_key` - The secret key to derive the public key
19    ///
20    /// # Returns
21    ///
22    /// * If successful, a vector of bytes with the public key
23    fn derive_public_key(&mut self, secret_key: SecretKey) -> Result<Vec<u8>, Self::Error>;
24
25    /// Function to sign a message given a private key.
26    ///
27    /// # Arguments
28    ///
29    /// * `message`     - The message to be signed
30    /// * `secret_key`  - The secret key for signing
31    ///
32    /// # Returns
33    ///
34    /// * If successful, a vector of bytes with the signature
35    fn sign(&mut self, secret_key: SecretKey, message: &[u8]) -> Result<Vec<u8>, Self::Error>;
36
37    /// Function to verify a signature given a public key.
38    ///
39    /// # Arguments
40    ///
41    /// * `signature`   - The signature
42    /// * `message`     - The message to be signed
43    /// * `public_key`  - The public key to verify
44    ///
45    /// # Returns
46    ///
47    /// * If successful, `Ok(())`; otherwise `Error`
48    fn verify(
49        &mut self,
50        signature: Signature,
51        message: &[u8],
52        public_key: PublicKey,
53    ) -> Result<(), Self::Error>;
54
55    /// Function to aggregate public keys in their corresponding group.
56    ///
57    /// # Arguments
58    ///
59    /// * `public_key`  - An array of public keys to be aggregated
60    ///
61    /// # Returns
62    ///
63    /// * If successful, a vector of bytes with the aggregated public key
64    fn aggregate_public_keys(&mut self, public_keys: &[PublicKey]) -> Result<Vec<u8>, Self::Error>;
65
66    /// Function to aggregate signatures in their corresponding group.
67    ///
68    /// # Arguments
69    ///
70    /// * `signatures`   - An array of signatures to be aggregated
71    ///
72    /// # Returns
73    ///
74    /// * If successful, a vector of bytes with the aggregated signature
75    fn aggregate_signatures(&mut self, signatures: &[Signature]) -> Result<Vec<u8>, Self::Error>;
76}