Skip to content

Commit

Permalink
Merge branch 'main' into valentyn/add-analysis-ml-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah authored Dec 12, 2024
2 parents 6806622 + c11dd05 commit df07fd4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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>,
}

/// 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

0 comments on commit df07fd4

Please sign in to comment.