20
20
21
21
// core
22
22
use core:: { borrow:: Borrow , ops:: Neg } ;
23
-
24
- // substrate
25
- use sp_std:: prelude:: Vec ;
26
-
27
23
// crates.io
28
24
use ark_bls12_381:: {
29
25
g2:: Config as G2Config , Bls12_381 , G1Affine , G1Projective , G2Affine , G2Projective ,
@@ -40,25 +36,24 @@ use ark_ec::{
40
36
use ark_ff:: { field_hashers:: DefaultFieldHasher , Zero } ;
41
37
use ark_serialize:: * ;
42
38
use sha2:: Sha256 ;
39
+ // substrate
40
+ use sp_std:: prelude:: Vec ;
43
41
44
42
/// Domain Separation Tag for signatures on G2
45
43
pub const DST_G2 : & [ u8 ] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_" ;
46
44
47
45
#[ derive( Clone , Debug ) ]
48
46
pub struct Signature ( G2Projective ) ;
49
-
50
47
impl From < G2Projective > for Signature {
51
48
fn from ( sig : G2Projective ) -> Signature {
52
49
Signature ( sig)
53
50
}
54
51
}
55
-
56
52
impl AsRef < G2Projective > for Signature {
57
53
fn as_ref ( & self ) -> & G2Projective {
58
54
& self . 0
59
55
}
60
56
}
61
-
62
57
impl Signature {
63
58
pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Signature , SerializationError > {
64
59
let p = G2Affine :: deserialize_compressed ( bytes) ?;
@@ -73,13 +68,11 @@ impl Signature {
73
68
74
69
#[ derive( Clone , Debug , Eq , PartialEq , Hash , CanonicalSerialize , CanonicalDeserialize ) ]
75
70
pub struct PublicKey ( pub G1Projective ) ;
76
-
77
71
impl From < G1Projective > for PublicKey {
78
72
fn from ( pk : G1Projective ) -> PublicKey {
79
73
PublicKey ( pk)
80
74
}
81
75
}
82
-
83
76
impl PublicKey {
84
77
pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < PublicKey , SerializationError > {
85
78
let p = G1Affine :: deserialize_compressed ( bytes) ?;
@@ -110,14 +103,14 @@ pub fn hash_to_curve_g2(message: &[u8]) -> Result<G2Projective, HashToCurveError
110
103
111
104
#[ cfg( test) ]
112
105
mod tests {
113
- use ark_std :: test_rng ;
106
+ // crates.io
114
107
use rand:: Rng ;
115
-
116
- use super :: * ;
117
-
108
+ use ark_std:: test_rng;
118
109
use ark_bls12_381:: Fr ;
119
110
use ark_ec:: Group ;
120
111
use ark_ff:: UniformRand ;
112
+ // darwinia
113
+ use super :: * ;
121
114
122
115
#[ derive( Clone , Debug , CanonicalSerialize , CanonicalDeserialize ) ]
123
116
pub struct SecretKey ( Fr ) ;
0 commit comments