-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from kafeikui/add-multiple-network-support
(node)Add multiple network support
- Loading branch information
Showing
73 changed files
with
18,194 additions
and
10,821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,68 @@ | ||
use anyhow::Result; | ||
use std::marker::PhantomData; | ||
use threshold_bls::{ | ||
group::PairingCurve, | ||
group::Curve, | ||
poly::Eval, | ||
sig::{G2Scheme, Scheme, Share, SignatureScheme, ThresholdScheme}, | ||
sig::{Share, SignatureScheme, ThresholdScheme}, | ||
}; | ||
|
||
pub(crate) struct SimpleBLSCore<C: PairingCurve> { | ||
pub(crate) struct SimpleBLSCore< | ||
C: Curve, | ||
S: SignatureScheme + ThresholdScheme<Public = C::Point, Private = C::Scalar>, | ||
> { | ||
c: PhantomData<C>, | ||
s: PhantomData<S>, | ||
} | ||
|
||
pub(crate) trait BLSCore<C: PairingCurve> { | ||
pub(crate) trait BLSCore<C: Curve> { | ||
/// Partially signs a message with a share of the private key | ||
fn partial_sign( | ||
private: &Share<<G2Scheme<C> as Scheme>::Private>, | ||
msg: &[u8], | ||
) -> Result<Vec<u8>>; | ||
fn partial_sign(private: &Share<C::Scalar>, msg: &[u8]) -> Result<Vec<u8>>; | ||
|
||
/// Verifies a partial signature on a message against the public polynomial | ||
fn partial_verify( | ||
partial_public_key: &<G2Scheme<C> as Scheme>::Public, | ||
msg: &[u8], | ||
partial: &[u8], | ||
) -> Result<()>; | ||
fn partial_verify(partial_public_key: &C::Point, msg: &[u8], partial: &[u8]) -> Result<()>; | ||
|
||
/// Aggregates all partials signature together. Note that this method does | ||
/// not verify if the partial signatures are correct or not; it only | ||
/// aggregates them. | ||
fn aggregate(threshold: usize, partials: &[Vec<u8>]) -> Result<Vec<u8>>; | ||
|
||
/// Verifies that the signature on the provided message was produced by the public key | ||
fn verify(public: &<G2Scheme<C> as Scheme>::Public, msg: &[u8], sig: &[u8]) -> Result<()>; | ||
fn verify(public: &C::Point, msg: &[u8], sig: &[u8]) -> Result<()>; | ||
|
||
fn verify_partial_sigs( | ||
publics: &[<G2Scheme<C> as Scheme>::Public], | ||
msg: &[u8], | ||
partial_sigs: &[&[u8]], | ||
) -> Result<()>; | ||
fn verify_partial_sigs(publics: &[C::Point], msg: &[u8], partial_sigs: &[&[u8]]) -> Result<()>; | ||
} | ||
|
||
impl<C: PairingCurve + 'static> BLSCore<C> for SimpleBLSCore<C> { | ||
fn partial_sign( | ||
private: &Share<<G2Scheme<C> as Scheme>::Private>, | ||
msg: &[u8], | ||
) -> Result<Vec<u8>> { | ||
let partial_signature = G2Scheme::<C>::partial_sign(private, msg)?; | ||
impl< | ||
C: Curve + 'static, | ||
S: SignatureScheme + ThresholdScheme<Public = C::Point, Private = C::Scalar> + 'static, | ||
> BLSCore<C> for SimpleBLSCore<C, S> | ||
where | ||
<S as ThresholdScheme>::Error: Sync + Send, | ||
<S as SignatureScheme>::Error: Sync + Send, | ||
{ | ||
fn partial_sign(private: &Share<C::Scalar>, msg: &[u8]) -> Result<Vec<u8>> { | ||
let partial_signature = S::partial_sign(private, msg)?; | ||
Ok(partial_signature) | ||
} | ||
|
||
fn partial_verify( | ||
partial_public_key: &<G2Scheme<C> as Scheme>::Public, | ||
msg: &[u8], | ||
partial: &[u8], | ||
) -> Result<()> { | ||
fn partial_verify(partial_public_key: &C::Point, msg: &[u8], partial: &[u8]) -> Result<()> { | ||
let partial: Eval<Vec<u8>> = bincode::deserialize(partial)?; | ||
G2Scheme::<C>::verify(partial_public_key, msg, &partial.value)?; | ||
S::verify(partial_public_key, msg, &partial.value)?; | ||
Ok(()) | ||
} | ||
|
||
fn aggregate(threshold: usize, partials: &[Vec<u8>]) -> Result<Vec<u8>> { | ||
let signature = G2Scheme::<C>::aggregate(threshold, partials)?; | ||
let signature = S::aggregate(threshold, partials)?; | ||
Ok(signature) | ||
} | ||
|
||
fn verify(public: &<G2Scheme<C> as Scheme>::Public, msg: &[u8], sig: &[u8]) -> Result<()> { | ||
G2Scheme::<C>::verify(public, msg, sig)?; | ||
fn verify(public: &C::Point, msg: &[u8], sig: &[u8]) -> Result<()> { | ||
S::verify(public, msg, sig)?; | ||
Ok(()) | ||
} | ||
|
||
fn verify_partial_sigs( | ||
publics: &[<G2Scheme<C> as Scheme>::Public], | ||
msg: &[u8], | ||
partial_sigs: &[&[u8]], | ||
) -> Result<()> { | ||
G2Scheme::<C>::aggregation_verify_on_the_same_msg(publics, msg, partial_sigs)?; | ||
fn verify_partial_sigs(publics: &[C::Point], msg: &[u8], partial_sigs: &[&[u8]]) -> Result<()> { | ||
S::aggregation_verify_on_the_same_msg(publics, msg, partial_sigs)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.