From 884f82dda0839b4dc3b7e9670183d182fc578a4b Mon Sep 17 00:00:00 2001 From: Bassam Sayed Date: Wed, 11 Dec 2024 11:54:19 -0500 Subject: [PATCH] Changed the data type of the bypass_age_verification to a string based ona request from POP team. --- qr-link/src/lib.rs | 3 +++ qr-link/src/user_data.rs | 11 +++++------ qr-link/tests/verification.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/qr-link/src/lib.rs b/qr-link/src/lib.rs index 165469ed..7d1b7754 100644 --- a/qr-link/src/lib.rs +++ b/qr-link/src/lib.rs @@ -24,6 +24,7 @@ //! //! // 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(), @@ -31,6 +32,7 @@ //! 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. @@ -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` diff --git a/qr-link/src/user_data.rs b/qr-link/src/user_data.rs index 5a169863..881176e1 100644 --- a/qr-link/src/user_data.rs +++ b/qr-link/src/user_data.rs @@ -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, - /// 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, } /// User's biometric data policy. Part of [`UserData`]. @@ -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()); @@ -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()); } } } diff --git a/qr-link/tests/verification.rs b/qr-link/tests/verification.rs index f333a51a..afd9bd42 100644 --- a/qr-link/tests/verification.rs +++ b/qr-link/tests/verification.rs @@ -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= @@ -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();