pub fn new<C: Signing, R: Rng>(
            secp: &Secp256k1<C>,
            rng: &mut R,
            codomain_tag: Tag,
            codomain_blinding_factor: Tweak,
            domain: &[(Generator, Tag, Tweak)],
        ) -> Result<SurjectionProof, Error> {
            let mut proof = ffi::SurjectionProof::new();

            let mut seed = [0u8; 32];
            rng.fill_bytes(&mut seed);

            let mut domain_index = 0;
            let max_iteration = 100;

            let mut domain_blinded_tags = Vec::with_capacity(domain.len());
            let mut domain_tags = Vec::with_capacity(domain.len());
            let mut domain_blinding_factors = Vec::with_capacity(domain.len());

            for (blinded_tag, tag, bf) in domain {
                domain_blinded_tags.push(*blinded_tag.as_inner());
                domain_tags.push(tag.into_inner());
                domain_blinding_factors.push(*bf);
            }

            let ret = unsafe {
                ffi::secp256k1_surjectionproof_initialize(
                    *secp.ctx(),
                    &mut proof,
                    &mut domain_index,
                    domain_tags.as_ptr(),
                    domain.len(),
                    domain.len().min(3),
                    codomain_tag.as_inner(),
                    max_iteration,
                    seed.as_ptr(),
                )
            };

            if ret == 0 {
                return Err(Error::CannotProveSurjection);
            }

            let codomain_blinded_tag =
                Generator::new_blinded(secp, codomain_tag, codomain_blinding_factor);

            let ret = unsafe {
                ffi::secp256k1_surjectionproof_generate(
                    *secp.ctx(),
                    &mut proof,
                    domain_blinded_tags.as_ptr(),
                    domain.len(),
                    codomain_blinded_tag.as_inner(),
                    domain_index,
                    domain
                        .get(domain_index)
                        .ok_or(Error::CannotProveSurjection)?
                        .2
                        .as_ptr(), // TODO: Return dedicated error here?
                    codomain_blinding_factor.as_ptr(),
                )
            };

            if ret == 0 {
                return Err(Error::CannotProveSurjection);
            }

            Ok(SurjectionProof { inner: proof })
        }
/// Prove that a given tag - when blinded - is contained within another set of blinded tags.
///
/// Mathematically, we are proving that there exists a surjective mapping between the domain and codomain of tags.
/// Blinding a tag produces a [`Generator`]. As such, to create this proof we need to provide the `[Generator]`s and the respective blinding factors that were used to create them.
Prove that a given tag - when blinded - is contained within another set of blinded tags.
Mathematically, we are proving that there exists a surjective mapping between the domain and codomain of tags.
Blinding a tag produces a [`Generator`]. As such, to create this proof we need to provide the `[Generator]`s and the respective blinding factors that were used to create them.
Prove that a given tag - when blinded - is contained within another set of blinded tags . Mathematically we are proving that there exists a surjective mapping between the domain and codomain of tags . Blinding a tag produces a [ ` Generator ` ] . As such to create this proof we need to provide the ` [ Generator ] ` s and the respective blinding factors that were used to create them .
pub fn new<C: Signing, R: Rng>(
            secp: &Secp256k1<C>,
            rng: &mut R,
            codomain_tag: Tag,
            codomain_blinding_factor: Tweak,
            domain: &[(Generator, Tag, Tweak)],
        ) -> Result<SurjectionProof, Error> {
            let mut proof = ffi::SurjectionProof::new();
            let mut seed = [0u8; 32];
            rng.fill_bytes(&mut seed);
            let mut domain_index = 0;
            let max_iteration = 100;
            let mut domain_blinded_tags = Vec::with_capacity(domain.len());
            let mut domain_tags = Vec::with_capacity(domain.len());
            let mut domain_blinding_factors = Vec::with_capacity(domain.len());
            for (blinded_tag, tag, bf) in domain {
                domain_blinded_tags.push(*blinded_tag.as_inner());
                domain_tags.push(tag.into_inner());
                domain_blinding_factors.push(*bf);
            }
            let ret = unsafe {
                ffi::secp256k1_surjectionproof_initialize(
                    *secp.ctx(),
                    &mut proof,
                    &mut domain_index,
                    domain_tags.as_ptr(),
                    domain.len(),
                    domain.len().min(3),
                    codomain_tag.as_inner(),
                    max_iteration,
                    seed.as_ptr(),
                )
            };
            if ret == 0 {
                return Err(Error::CannotProveSurjection);
            }
            let codomain_blinded_tag =
                Generator::new_blinded(secp, codomain_tag, codomain_blinding_factor);
            let ret = unsafe {
                ffi::secp256k1_surjectionproof_generate(
                    *secp.ctx(),
                    &mut proof,
                    domain_blinded_tags.as_ptr(),
                    domain.len(),
                    codomain_blinded_tag.as_inner(),
                    domain_index,
                    domain
                        .get(domain_index)
                        .ok_or(Error::CannotProveSurjection)?
                        .2
                        .as_ptr(), // TODO: Return dedicated error here?
                    codomain_blinding_factor.as_ptr(),
                )
            };
            if ret == 0 {
                return Err(Error::CannotProveSurjection);
            }
            Ok(SurjectionProof { inner: proof })
        }
pub fn new < C : Signing , R : Rng > ( secp : & Secp256k1 < C > , rng : & mut R , codomain_tag : Tag , codomain_blinding_factor : Tweak , domain : & [ ( Generator , Tag , Tweak ) ] , ) -> Result < SurjectionProof , Error > { let mut proof = ffi :: SurjectionProof :: new ( ) ; let mut seed = [ 0u8 ; 32 ] ; rng . fill_bytes ( & mut seed ) ; let mut domain_index = 0 ; let max_iteration = 100 ; let mut domain_blinded_tags = Vec :: with_capacity ( domain . len ( ) ) ; let mut domain_tags = Vec :: with_capacity ( domain . len ( ) ) ; let mut domain_blinding_factors = Vec :: with_capacity ( domain . len ( ) ) ; for ( blinded_tag , tag , bf ) in domain { domain_blinded_tags . push ( * blinded_tag . as_inner ( ) ) ; domain_tags . push ( tag . into_inner ( ) ) ; domain_blinding_factors . push ( * bf ) ; } let ret = unsafe { ffi :: secp256k1_surjectionproof_initialize ( * secp . ctx ( ) , & mut proof , & mut domain_index , domain_tags . as_ptr ( ) , domain . len ( ) , domain . len ( ) . min ( 3 ) , codomain_tag . as_inner ( ) , max_iteration , seed . as_ptr ( ) , ) } ; if ret == 0 { return Err ( Error :: CannotProveSurjection ) ; } let codomain_blinded_tag = Generator :: new_blinded ( secp , codomain_tag , codomain_blinding_factor ) ; let ret = unsafe { ffi :: secp256k1_surjectionproof_generate ( * secp . ctx ( ) , & mut proof , domain_blinded_tags . as_ptr ( ) , domain . len ( ) , codomain_blinded_tag . as_inner ( ) , domain_index , domain . get ( domain_index ) . ok_or ( Error :: CannotProveSurjection ) ? . 2 . as_ptr ( ) , // TODO: Return dedicated error here? codomain_blinding_factor . as_ptr ( ) , ) } ; if ret == 0 { return Err ( Error :: CannotProveSurjection ) ; } Ok ( SurjectionProof { inner : proof } ) }
Prove that a given tag - when blinded - is contained within another set of blinded tags.
Prove that a given tag - when blinded - is contained within another set of blinded tags .
secp
&Secp256k1<C>
rng
&mut R
codomain_tag
Tag
codomain_blinding_factor
Tweak
domain
&[(Generator, Tag, Tweak)]
secp
&Secp256k1<C>
rng
&mut R
codomain_tag
Tag
codomain_blinding_factor
Tweak
domain
&[(Generator, Tag, Tweak)]