Skip to content

Commit

Permalink
Changed the data type of the bypass_age_verification to a string base…
Browse files Browse the repository at this point in the history
…d ona request from POP team.
  • Loading branch information
bsayed committed Dec 12, 2024
1 parent ea348ac commit 068750c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions qr-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
//!
//! // Generate a new session id and user data.
//! let session_id = Uuid::new_v4();
//! let sample_jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
//! let user_data = UserData {
//! identity_commitment: String::new(),
//! self_custody_public_key: String::new(),
//! data_policy: DataPolicy::OptOut,
//! pcp_version: 2,
//! user_centric_signup: true,
//! orb_relay_app_id: Some("123123".to_string()),
//! bypass_age_verification_token: Some(sample_jwt_token.to_string()),
//! };
//!
//! // Upload `user_data` to the backend by the `session_id` key.
Expand Down Expand Up @@ -66,6 +68,7 @@
//! pcp_version: 2,
//! user_centric_signup: true,
//! orb_relay_app_id: Some("123123".to_string()),
//! bypass_age_verification_token: None,
//! };
//!
//! // Verify that the `user_data_hash` from the QR-code matches `user_data`
Expand Down
11 changes: 5 additions & 6 deletions qr-link/src/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ pub struct UserData {
pub user_centric_signup: bool,
/// A unique UUID that the Orb will use to send messages to the app through Orb Relay.
pub orb_relay_app_id: Option<String>,
/// Whether the Orb should perform the age verification.
#[serde(default = "default_false")]
pub bypass_age_verification: bool,
/// Whether the Orb should perform the age verification. If the token exists we skip the age verification.
pub bypass_age_verification_token: Option<String>,
}

/// User's biometric data policy. Part of [`UserData`].
Expand Down Expand Up @@ -70,7 +69,7 @@ impl UserData {
pcp_version,
user_centric_signup,
orb_relay_app_id,
bypass_age_verification,
bypass_age_verification_token,
} = self;
hasher.update(identity_commitment.as_bytes());
hasher.update(self_custody_public_key.as_bytes());
Expand All @@ -84,8 +83,8 @@ impl UserData {
if let Some(app_id) = orb_relay_app_id {
hasher.update(app_id.as_bytes());
}
if *bypass_age_verification {
hasher.update(&[true as u8]);
if let Some(age_verification_token) = bypass_age_verification_token {
hasher.update(age_verification_token.as_bytes());
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions qr-link/tests/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use orb_qr_link::{decode_qr, encode_qr, DataPolicy, UserData};
use uuid::Uuid;

#[test]
fn test_encode_decode_verify() {
fn test_encode_decode_verify_without_age_verification_token() {
let session_id = Uuid::new_v4();
let self_custody_public_key = r#"-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEA2boNBmJX4lGkA9kjthS5crXOBxu2BPycKRMakpzgLG4=
Expand All @@ -15,7 +15,30 @@ MCowBQYDK2VuAyEA2boNBmJX4lGkA9kjthS5crXOBxu2BPycKRMakpzgLG4=
pcp_version: 3,
user_centric_signup: true,
orb_relay_app_id: Some("123123".to_string()),
bypass_age_verification: false,
bypass_age_verification_token: None,
};
let qr = encode_qr(&session_id, user_data.hash(16));
let (parsed_session_id, parsed_user_data_hash) = decode_qr(&qr).unwrap();
assert_eq!(parsed_session_id, session_id);
assert!(user_data.verify(parsed_user_data_hash));
}

#[test]
fn test_encode_decode_verify_with_age_verification_token() {
let session_id = Uuid::new_v4();
let self_custody_public_key = r#"-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEA2boNBmJX4lGkA9kjthS5crXOBxu2BPycKRMakpzgLG4=
-----END PUBLIC KEY-----"#;
let sample_jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
let identity_commitment = "0xabcd";
let user_data = UserData {
identity_commitment: identity_commitment.to_string(),
self_custody_public_key: self_custody_public_key.to_string(),
data_policy: DataPolicy::OptOut,
pcp_version: 3,
user_centric_signup: true,
orb_relay_app_id: Some("123123".to_string()),
bypass_age_verification_token: Some(sample_jwt_token.to_string()),
};
let qr = encode_qr(&session_id, user_data.hash(16));
let (parsed_session_id, parsed_user_data_hash) = decode_qr(&qr).unwrap();
Expand Down

0 comments on commit 068750c

Please sign in to comment.