@@ -14,6 +14,9 @@ use tree_hash::TreeHash;
1414/// The byte-length of a BLS signature when serialized in compressed form.
1515pub const SIGNATURE_BYTES_LEN : usize = 96 ;
1616
17+ /// The byte-length of a BLS signature when serialized in uncompressed form.
18+ pub const SIGNATURE_UNCOMPRESSED_BYTES_LEN : usize = 192 ;
19+
1720/// Represents the signature at infinity.
1821pub const INFINITY_SIGNATURE : [ u8 ; SIGNATURE_BYTES_LEN ] = [
1922 0xc0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -22,6 +25,16 @@ pub const INFINITY_SIGNATURE: [u8; SIGNATURE_BYTES_LEN] = [
2225 0 ,
2326] ;
2427
28+ pub const INFINITY_SIGNATURE_UNCOMPRESSED : [ u8 ; SIGNATURE_UNCOMPRESSED_BYTES_LEN ] = [
29+ 0x40 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
30+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
31+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
32+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
33+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
34+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
35+ 0 ,
36+ ] ;
37+
2538/// The compressed bytes used to represent `GenericSignature::empty()`.
2639pub const NONE_SIGNATURE : [ u8 ; SIGNATURE_BYTES_LEN ] = [ 0 ; SIGNATURE_BYTES_LEN ] ;
2740
@@ -31,9 +44,15 @@ pub trait TSignature<GenericPublicKey>: Sized + Clone {
3144 /// Serialize `self` as compressed bytes.
3245 fn serialize ( & self ) -> [ u8 ; SIGNATURE_BYTES_LEN ] ;
3346
47+ /// Serialize `self` as uncompressed bytes.
48+ fn serialize_uncompressed ( & self ) -> [ u8 ; SIGNATURE_UNCOMPRESSED_BYTES_LEN ] ;
49+
3450 /// Deserialize `self` from compressed bytes.
3551 fn deserialize ( bytes : & [ u8 ] ) -> Result < Self , Error > ;
3652
53+ /// Serialize `self` from uncompressed bytes.
54+ fn deserialize_uncompressed ( bytes : & [ u8 ] ) -> Result < Self , Error > ;
55+
3756 /// Returns `true` if `self` is a signature across `msg` by `pubkey`.
3857 fn verify ( & self , pubkey : & GenericPublicKey , msg : Hash256 ) -> bool ;
3958}
@@ -93,12 +112,12 @@ where
93112 }
94113
95114 /// Returns a reference to the underlying BLS point.
96- pub ( crate ) fn point ( & self ) -> Option < & Sig > {
115+ pub fn point ( & self ) -> Option < & Sig > {
97116 self . point . as_ref ( )
98117 }
99118
100119 /// Instantiates `Self` from a `point`.
101- pub ( crate ) fn from_point ( point : Sig , is_infinity : bool ) -> Self {
120+ pub fn from_point ( point : Sig , is_infinity : bool ) -> Self {
102121 Self {
103122 point : Some ( point) ,
104123 is_infinity,
@@ -115,6 +134,13 @@ where
115134 }
116135 }
117136
137+ /// Serialize `self` as compressed bytes.
138+ pub fn serialize_uncompressed ( & self ) -> Option < [ u8 ; SIGNATURE_UNCOMPRESSED_BYTES_LEN ] > {
139+ self . point
140+ . as_ref ( )
141+ . map ( |point| point. serialize_uncompressed ( ) )
142+ }
143+
118144 /// Deserialize `self` from compressed bytes.
119145 pub fn deserialize ( bytes : & [ u8 ] ) -> Result < Self , Error > {
120146 let point = if bytes == & NONE_SIGNATURE [ ..] {
@@ -129,6 +155,17 @@ where
129155 _phantom : PhantomData ,
130156 } )
131157 }
158+
159+ /// Deserialize `self` from uncompressed bytes.
160+ pub fn deserialize_uncompressed ( bytes : & [ u8 ] ) -> Result < Self , Error > {
161+ // The "none signature" is a beacon chain concept. As we never directly deal with
162+ // uncompressed signatures on the beacon chain, it does not apply here.
163+ Ok ( Self {
164+ point : Some ( Sig :: deserialize_uncompressed ( bytes) ?) ,
165+ is_infinity : bytes == & INFINITY_SIGNATURE_UNCOMPRESSED [ ..] ,
166+ _phantom : PhantomData ,
167+ } )
168+ }
132169}
133170
134171impl < Pub , Sig > GenericSignature < Pub , Sig >
0 commit comments