@@ -8,15 +8,16 @@ use ark_serialize::CanonicalSerialize;
88use ark_std:: { UniformRand , rand:: RngCore } ;
99use sha2:: { Digest , Sha256 } ;
1010
11- use crate :: bbs_bn254:: structs:: { BlindedCommitment , CommitmentProof , Parameters } ;
11+ use crate :: bbs_bn254:: { Signature , structs:: { BlindedCommitment , CommitmentProof , Parameters } } ;
1212
1313/// Create a blinded commitment for a list of messages.
1414/// Returns `Err` if message length exceeds available parameters.
15- /// data with index at and behind `blind_index` will be blinded, should be between 1 and messages.len() - 1
15+ /// for example, if blind_index is 3, and the length of messages is 5
16+ /// the m0, m1, m2 are visual, while m3, m4 are blinded, the commitment will be C = r*H_0 + m3*H_4 + m4*H_5
1617pub fn blind (
1718 params : & Parameters ,
1819 messages : & [ Scalar ] ,
19- blind_index : usize ,
20+ blind_index : & usize ,
2021) -> Result < BlindedCommitment , & ' static str > {
2122 let mut rng = ark_std:: test_rng ( ) ;
2223 blind_with_rng ( params, messages, blind_index, & mut rng)
@@ -26,7 +27,7 @@ pub fn blind(
2627pub fn blind_with_rng < R : RngCore > (
2728 params : & Parameters ,
2829 messages : & [ Scalar ] ,
29- blind_index : usize ,
30+ blind_index : & usize ,
3031 rng : & mut R ,
3132) -> Result < BlindedCommitment , & ' static str > {
3233 if messages. len ( ) > params. L {
@@ -35,7 +36,7 @@ pub fn blind_with_rng<R: RngCore>(
3536 if params. H . len ( ) < messages. len ( ) + 1 {
3637 return Err ( "parameters do not include enough message base points" ) ;
3738 }
38- if blind_index == 0 || blind_index >= messages. len ( ) {
39+ if * blind_index > messages. len ( ) {
3940 return Err ( "invalid blind index" ) ;
4041 }
4142
@@ -44,7 +45,7 @@ pub fn blind_with_rng<R: RngCore>(
4445 let mut commitment = params. H [ 0 ] * blinding_factor;
4546
4647 // calc m_j*H_{j+1}
47- for j in ( blind_index - 1 ) ..messages. len ( ) {
48+ for j in * blind_index..messages. len ( ) {
4849 commitment += params. H [ j + 1 ] * messages[ j] ;
4950 }
5051
@@ -54,6 +55,24 @@ pub fn blind_with_rng<R: RngCore>(
5455 } )
5556}
5657
58+ pub fn unblind (
59+ params : & Parameters ,
60+ signature : & Signature ,
61+ commitment : & BlindedCommitment ,
62+ ) -> Result < Signature , & ' static str > {
63+ if params. H . len ( ) < 2 {
64+ return Err ( "parameters do not include enough message base points" ) ;
65+ }
66+
67+ let unblinded_s = signature. s + commitment. blinding_factor ;
68+ return Ok ( Signature {
69+ A : signature. A ,
70+ e : signature. e ,
71+ s : unblinded_s,
72+ } ) ;
73+ }
74+
75+
5776/// Generate a proof of knowledge for the blinded commitment.
5877pub fn commitment_pok_prove (
5978 params : & Parameters ,
@@ -156,7 +175,7 @@ mod tests {
156175 let messages = vec ! [ Scalar :: from( 1u64 ) , Scalar :: from( 2u64 ) , Scalar :: from( 3u64 ) ] ;
157176
158177 let mut rng = ark_std:: test_rng ( ) ;
159- let commitment = blind_with_rng ( & params, & messages, 1 , & mut rng) . unwrap ( ) ;
178+ let commitment = blind_with_rng ( & params, & messages, & 1 , & mut rng) . unwrap ( ) ;
160179 let proof =
161180 commitment_pok_prove_with_rng ( & params, & commitment, & messages, & mut rng) . unwrap ( ) ;
162181
0 commit comments