pub fn compute_adaptive_blinding_factor<C: Signing>(
    secp: &Secp256k1<C>,
    value: u64,
    generator_blinding_factor: Tweak,
    set_a: &[CommitmentSecrets],
    set_b: &[CommitmentSecrets],
) -> Tweak {
    let value_blinding_factor_placeholder = ZERO_TWEAK; // this placeholder will be filled with the generated blinding factor

    let (mut values, mut secrets) = set_a
        .iter()
        .chain(set_b.iter())
        .map(|c| {
            (
                c.value,
                (c.value_blinding_factor, c.generator_blinding_factor),
            )
        })
        .unzip::<_, _, Vec<_>, Vec<_>>();
    values.push(value);
    secrets.push((value_blinding_factor_placeholder, generator_blinding_factor));

    let (vbf, gbf) = secrets
        .iter_mut()
        .map(|(s_v, s_g)| (s_v.as_mut_ptr(), s_g.as_ptr()))
        .unzip::<_, _, Vec<_>, Vec<_>>();

    let ret = unsafe {
        ffi::secp256k1_pedersen_blind_generator_blind_sum(
            *secp.ctx(),
            values.as_ptr(),
            gbf.as_ptr(),
            vbf.as_ptr(),
            set_a.len() + set_b.len() + 1,
            set_a.len(),
        )
    };
    assert_eq!(1, ret, "failed to compute blinding factor");

    let last = vbf.last().expect("this vector is never empty");
    let slice = unsafe { slice::from_raw_parts(*last, 32) };
    Tweak::from_slice(slice).expect("data is always 32 bytes")
}
/// Compute a blinding factor such that the sum of all blinding factors in both sets is equal.
Compute a blinding factor such that the sum of all blinding factors in both sets is equal.
Compute a blinding factor such that the sum of all blinding factors in both sets is equal .
pub fn compute_adaptive_blinding_factor<C: Signing>(
    secp: &Secp256k1<C>,
    value: u64,
    generator_blinding_factor: Tweak,
    set_a: &[CommitmentSecrets],
    set_b: &[CommitmentSecrets],
) -> Tweak {
    let value_blinding_factor_placeholder = ZERO_TWEAK; // this placeholder will be filled with the generated blinding factor
    let (mut values, mut secrets) = set_a
        .iter()
        .chain(set_b.iter())
        .map(|c| {
            (
                c.value,
                (c.value_blinding_factor, c.generator_blinding_factor),
            )
        })
        .unzip::<_, _, Vec<_>, Vec<_>>();
    values.push(value);
    secrets.push((value_blinding_factor_placeholder, generator_blinding_factor));
    let (vbf, gbf) = secrets
        .iter_mut()
        .map(|(s_v, s_g)| (s_v.as_mut_ptr(), s_g.as_ptr()))
        .unzip::<_, _, Vec<_>, Vec<_>>();
    let ret = unsafe {
        ffi::secp256k1_pedersen_blind_generator_blind_sum(
            *secp.ctx(),
            values.as_ptr(),
            gbf.as_ptr(),
            vbf.as_ptr(),
            set_a.len() + set_b.len() + 1,
            set_a.len(),
        )
    };
    assert_eq!(1, ret, "failed to compute blinding factor");
    let last = vbf.last().expect("this vector is never empty");
    let slice = unsafe { slice::from_raw_parts(*last, 32) };
    Tweak::from_slice(slice).expect("data is always 32 bytes")
}
pub fn compute_adaptive_blinding_factor < C : Signing > ( secp : & Secp256k1 < C > , value : u64 , generator_blinding_factor : Tweak , set_a : & [ CommitmentSecrets ] , set_b : & [ CommitmentSecrets ] , ) -> Tweak { let value_blinding_factor_placeholder = ZERO_TWEAK ; // this placeholder will be filled with the generated blinding factor let ( mut values , mut secrets ) = set_a . iter ( ) . chain ( set_b . iter ( ) ) . map ( | c | { ( c . value , ( c . value_blinding_factor , c . generator_blinding_factor ) , ) } ) . unzip :: < _ , _ , Vec < _ > , Vec < _ > > ( ) ; values . push ( value ) ; secrets . push ( ( value_blinding_factor_placeholder , generator_blinding_factor ) ) ; let ( vbf , gbf ) = secrets . iter_mut ( ) . map ( | ( s_v , s_g ) | ( s_v . as_mut_ptr ( ) , s_g . as_ptr ( ) ) ) . unzip :: < _ , _ , Vec < _ > , Vec < _ > > ( ) ; let ret = unsafe { ffi :: secp256k1_pedersen_blind_generator_blind_sum ( * secp . ctx ( ) , values . as_ptr ( ) , gbf . as_ptr ( ) , vbf . as_ptr ( ) , set_a . len ( ) + set_b . len ( ) + 1 , set_a . len ( ) , ) } ; assert_eq ! ( 1 ret " " ) ; let last = vbf . last ( ) . expect ( " " ) ; let slice = unsafe { slice :: from_raw_parts ( * last , 32 ) } ; Tweak :: from_slice ( slice ) . expect ( " " ) }
Compute a blinding factor such that the sum of all blinding factors in both sets is equal.
Compute a blinding factor such that the sum of all blinding factors in both sets is equal .
secp
&Secp256k1<C>
value
u64
generator_blinding_factor
Tweak
set_a
&[CommitmentSecrets]
set_b
&[CommitmentSecrets]
secp
&Secp256k1<C>
value
u64
generator_blinding_factor
Tweak
set_a
&[CommitmentSecrets]
set_b
&[CommitmentSecrets]