|
10 | 10 | //! backend for performance, and transfer a hash of the data via a QR-code for
|
11 | 11 | //! security.
|
12 | 12 | //!
|
| 13 | +//! //! The library is shared between Worldcoin App and Orb Core. |
13 | 14 | //! # Usage
|
14 |
| -//! |
15 |
| -//! The library is shared between Worldcoin App and Orb Core. |
16 |
| -//! |
17 | 15 | //! ## Encode (App)
|
18 | 16 | //!
|
19 |
| -//! Worldcoin App uploads user data and generates a QR-code. |
| 17 | +//! Worldcoin App generates a QR-code using the orb relay ID and includes a hash of the app authenticated data that will be sent in the orb relay message. |
20 | 18 | //!
|
21 | 19 | //! ```rust
|
22 |
| -//! use orb_qr_link::{encode_qr, DataPolicy, UserData}; |
| 20 | +//! use orb_qr_link::{encode_static_qr, AppAuthenticatedDataExt}; |
| 21 | +//! use orb_relay_messages::common::v1::AppAuthenticatedData; |
23 | 22 | //! use uuid::Uuid;
|
24 | 23 | //!
|
25 | 24 | //! // Generate a new session id and user data.
|
26 |
| -//! let session_id = Uuid::new_v4(); |
27 |
| -//! let sample_jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"; |
28 |
| -//! let user_data = UserData { |
29 |
| -//! identity_commitment: String::new(), |
30 |
| -//! self_custody_public_key: String::new(), |
31 |
| -//! data_policy: DataPolicy::OptOut, |
32 |
| -//! pcp_version: 2, |
33 |
| -//! user_centric_signup: true, |
34 |
| -//! orb_relay_app_id: Some("123123".to_string()), |
35 |
| -//! bypass_age_verification_token: Some(sample_jwt_token.to_string()), |
| 25 | +//! let orb_relay_id = Uuid::new_v4(); |
| 26 | +//! let app_data = AppAuthenticatedData { |
| 27 | +//! identity_commitment: identity_commitment.to_string(), |
| 28 | +//! self_custody_public_key: self_custody_public_key.to_string(), |
| 29 | +//! pcp_version: 3, |
| 30 | +//! os: "Android".to_string(), |
| 31 | +//! os_version: "1.2.3".to_string(), |
36 | 32 | //! };
|
37 | 33 | //!
|
38 |
| -//! // Upload `user_data` to the backend by the `session_id` key. |
39 |
| -//! // ... |
40 |
| -//! |
41 |
| -//! // Calculate a variable-length hash of `user_data`. |
42 |
| -//! let user_data_hash = user_data.hash(16); |
| 34 | +//! // Calculate a variable-length hash of `app_data`. |
| 35 | +//! let app_data_hash = app_data.hash(16); |
43 | 36 | //! // Encode a new QR-code.
|
44 |
| -//! let qr = encode_qr(&session_id, user_data_hash); |
| 37 | +//! let qr = encode_static_qr(&orb_relay_id, app_data_hash); |
45 | 38 | //!
|
46 | 39 | //! // Allow the Orb to scan the generated QR-code.
|
47 | 40 | //! // ...
|
48 | 41 | //! ```
|
49 | 42 | //!
|
50 | 43 | //! ## Decode (Orb)
|
51 | 44 | //!
|
52 |
| -//! The Orb scans a QR-code and downloads the user data. |
| 45 | +//! The Orb scans a QR-code |
53 | 46 | //!
|
54 | 47 | //! ```rust
|
55 |
| -//! use orb_qr_link::{decode_qr, DataPolicy, UserData}; |
| 48 | +//! use orb_qr_link::{decode_qr_with_version}; |
56 | 49 | //!
|
57 | 50 | //! // Scan QR-code generated by the App.
|
58 | 51 | //! let qr = "3WVd+tbAtSgyH0Ce9uiKT9i063t/xG2HxTIhuNa+gNnM";
|
59 | 52 | //!
|
60 | 53 | //! // Decode the QR-code string.
|
61 |
| -//! let (session_id, user_data_hash) = decode_qr(qr).unwrap(); |
62 |
| -//! |
63 |
| -//! // Download `user_data` from the backend by the `session_id` key. |
64 |
| -//! let user_data = UserData { |
65 |
| -//! identity_commitment: String::new(), |
66 |
| -//! self_custody_public_key: String::new(), |
67 |
| -//! data_policy: DataPolicy::OptOut, |
68 |
| -//! pcp_version: 2, |
69 |
| -//! user_centric_signup: true, |
70 |
| -//! orb_relay_app_id: Some("123123".to_string()), |
71 |
| -//! bypass_age_verification_token: None, |
72 |
| -//! }; |
| 54 | +//! let (version, orb_relay_id, app_data_hash) = decode_qr_with_version(qr).unwrap(); |
| 55 | +//! |
| 56 | +//! // connects to the app via orb relay using the orb_relay_id |
| 57 | +//! // if version is V4 then orb can do the logic for static sessions |
| 58 | +//! |
| 59 | +//! // Retrieves the app data from the AnnounceAppId Orb Relay Message |
| 60 | +//! let app_data = orb_relay_announce_id_message.app_authenticated_data; |
73 | 61 | //!
|
74 |
| -//! // Verify that the `user_data_hash` from the QR-code matches `user_data` |
| 62 | +//! // Verify that the `app_data_hash` from the QR-code matches `app_data` |
75 | 63 | //! // from the backend.
|
76 |
| -//! let success = user_data.verify(user_data_hash); |
| 64 | +//! let success = app_data.verify(app_data_hash); |
77 | 65 | //! ```
|
78 | 66 |
|
79 | 67 | #![forbid(unsafe_code)]
|
80 | 68 | #![warn(missing_docs)]
|
81 | 69 |
|
| 70 | +mod app_authenticated_data; |
82 | 71 | #[cfg(feature = "decode")]
|
83 | 72 | mod decode;
|
84 | 73 | #[cfg(feature = "encode")]
|
85 | 74 | mod encode;
|
86 | 75 | mod user_data;
|
87 | 76 |
|
| 77 | +pub use app_authenticated_data::AppAuthenticatedDataExt; |
88 | 78 | #[cfg(feature = "decode")]
|
89 |
| -pub use decode::{decode_qr, DecodeError}; |
| 79 | +pub use decode::{decode_qr_with_version, DecodeError}; |
90 | 80 | #[cfg(feature = "encode")]
|
91 |
| -pub use encode::encode_qr; |
| 81 | +pub use encode::encode_static_qr; |
92 | 82 | pub use user_data::{DataPolicy, UserData};
|
0 commit comments