Skip to content

Commit

Permalink
Address Web Discovery feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DJAndries committed Jan 10, 2025
1 parent b24c502 commit 3181583
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) struct ECPProof {
pub struct CredentialBIG(pub(crate) BIG);

/// A result of starting the "join" process to acquire credentials.
pub struct StartJoinResult {
pub struct JoinInitialization {
/// Private key which should be persisted for finishing the "join"
/// process and future signing requests.
pub gsk: CredentialBIG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use brave_miracl::{
};

use super::data::{
ecp2_to_compat_bytes, CredentialBIG, ECPProof, GroupPublicKey, JoinRequest, JoinResponse,
StartJoinResult, UserCredentials, BIG_SIZE, ECP2_COMPAT_SIZE, ECP_SIZE,
ecp2_to_compat_bytes, CredentialBIG, ECPProof, GroupPublicKey, JoinInitialization, JoinRequest,
JoinResponse, UserCredentials, BIG_SIZE, ECP2_COMPAT_SIZE, ECP_SIZE,
};
use super::util::{
ecp_challenge_equals, hash256, pair_normalized_triple_ate, random_mod_curve_order,
Expand Down Expand Up @@ -104,15 +104,15 @@ fn verify_aux_fast(a: &ECP, b: &ECP, c: &ECP, d: &ECP, x: &ECP2, y: &ECP2, rng:
w.equals(&fp12_one)
}

pub fn start_join(rng: &mut RAND, challenge: &[u8]) -> StartJoinResult {
pub fn start_join(rng: &mut RAND, challenge: &[u8]) -> JoinInitialization {
let gsk = random_mod_curve_order(rng);
let q = g1mul(&G1_ECP, &gsk);

let challenge_hash = hash256(challenge);

let proof = make_ecp_proof(rng, &q, &gsk, &challenge_hash);

StartJoinResult { gsk: CredentialBIG(gsk), join_msg: JoinRequest { q, proof } }
JoinInitialization { gsk: CredentialBIG(gsk), join_msg: JoinRequest { q, proof } }
}

pub fn finish_join(
Expand Down
11 changes: 7 additions & 4 deletions components/web_discovery/browser/anonymous_credentials/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub type Result<T> = std::result::Result<T, CredentialError>;

#[cxx::bridge(namespace = "web_discovery")]
mod ffi {
struct StartJoinResult {
struct JoinInitialization {
gsk: Vec<u8>,
join_request: Vec<u8>,
}
Expand Down Expand Up @@ -99,7 +99,10 @@ mod ffi {

fn new_anonymous_credentials_manager() -> Box<AnonymousCredentialsManager>;
fn new_anonymous_credentials_with_fixed_seed() -> Box<AnonymousCredentialsManager>;
fn start_join(self: &mut AnonymousCredentialsManager, challenge: &[u8]) -> StartJoinResult;
fn start_join(
self: &mut AnonymousCredentialsManager,
challenge: &[u8],
) -> JoinInitialization;
fn finish_join(
self: &mut AnonymousCredentialsManager,
public_key: &GroupPublicKey,
Expand Down Expand Up @@ -219,9 +222,9 @@ fn new_anonymous_credentials_with_fixed_seed() -> Box<AnonymousCredentialsManage
}

impl AnonymousCredentialsManager {
fn start_join(&mut self, challenge: &[u8]) -> StartJoinResult {
fn start_join(&mut self, challenge: &[u8]) -> JoinInitialization {
let result = self.0.start_join(challenge);
StartJoinResult {
JoinInitialization {
gsk: result.gsk.to_bytes().to_vec(),
join_request: result.join_msg.to_bytes().to_vec(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl CredentialManager {

/// Creates a "join" requests to be sent to the credential issuer,
/// for a given challenge.
pub fn start_join(&mut self, challenge: &[u8]) -> StartJoinResult {
pub fn start_join(&mut self, challenge: &[u8]) -> JoinInitialization {
start_join(&mut self.rng, challenge)
}

Expand Down

0 comments on commit 3181583

Please sign in to comment.