Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(qr-link): Age verification token field in UserData struct #317

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions qr-link/src/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +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. If the token exists we skip the age verification.
pub bypass_age_verification_token: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a String?
if it should be bool, what about a rename to bypass_age_verification

Copy link
Member

@karelispanagiotis karelispanagiotis Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got my answer from

...request from POP team

}

/// User's biometric data policy. Part of [`UserData`].
Expand Down Expand Up @@ -67,6 +69,7 @@ impl UserData {
pcp_version,
user_centric_signup,
orb_relay_app_id,
bypass_age_verification_token,
} = self;
hasher.update(identity_commitment.as_bytes());
hasher.update(self_custody_public_key.as_bytes());
Expand All @@ -80,6 +83,9 @@ impl UserData {
if let Some(app_id) = orb_relay_app_id {
hasher.update(app_id.as_bytes());
}
if let Some(age_verification_token) = bypass_age_verification_token {
hasher.update(age_verification_token.as_bytes());
}
}
}

Expand Down
26 changes: 25 additions & 1 deletion 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,6 +15,30 @@ MCowBQYDK2VuAyEA2boNBmJX4lGkA9kjthS5crXOBxu2BPycKRMakpzgLG4=
pcp_version: 3,
user_centric_signup: true,
orb_relay_app_id: Some("123123".to_string()),
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