Skip to content
21 changes: 18 additions & 3 deletions src/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@ use prost::Message;

use std::sync::Arc;
use std::sync::atomic::Ordering;
use wacore::companion_reg::{CompanionWebClientType, companion_web_client_type_for_props};
use wacore::libsignal::protocol::KeyPair;
use wacore_binary::NodeRef;
use wacore_binary::{Jid, SERVER_JID};
use waproto::whatsapp as wa;

pub use wacore::pair::{DeviceState, PairCryptoError, PairUtils};

pub fn make_qr_data(store: &crate::store::Device, ref_str: String) -> String {
/// Derives `CompanionWebClientType` from `device_props.platform_type`. Use
/// [`make_qr_data_with_client_type`] to override.
pub fn make_qr_data(store: &crate::store::Device, ref_str: &str) -> String {
let client_type = companion_web_client_type_for_props(&store.device_props);
make_qr_data_with_client_type(store, ref_str, client_type)
}

/// Same as [`make_qr_data`] but with an explicit `CompanionWebClientType`.
pub fn make_qr_data_with_client_type(
store: &crate::store::Device,
ref_str: &str,
client_type: CompanionWebClientType,
Comment on lines +25 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-export companion enum for QR override API

make_qr_data_with_client_type is public but its parameter type (CompanionWebClientType) is not exposed by whatsapp-rust, so downstream crates that depend only on whatsapp-rust cannot call this new override path without adding a direct wacore dependency. That makes the advertised override seam effectively unusable for current consumers of the high-level crate.

Useful? React with 👍 / 👎.

) -> String {
let device_state = DeviceState {
identity_key: store.identity_key.clone(),
noise_key: store.noise_key.clone(),
adv_secret_key: store.adv_secret_key,
};
PairUtils::make_qr_data(&device_state, ref_str)
PairUtils::make_qr_data(&device_state, ref_str, client_type)
}

pub async fn handle_iq(client: &Arc<Client>, node: &NodeRef<'_>) -> bool {
Expand Down Expand Up @@ -49,12 +62,14 @@ pub async fn handle_iq(client: &Arc<Client>, node: &NodeRef<'_>) -> bool {
noise_key: device_snapshot.noise_key.clone(),
adv_secret_key: device_snapshot.adv_secret_key,
};
let client_type =
companion_web_client_type_for_props(&device_snapshot.device_props);

for grandchild in child.get_children_by_tag("ref") {
if let Some(bytes) = grandchild.content_bytes()
&& let Ok(r) = std::str::from_utf8(bytes)
{
codes.push(PairUtils::make_qr_data(&device_state, r.to_string()));
codes.push(PairUtils::make_qr_data(&device_state, r, client_type));
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/pair_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,17 @@ impl Client {
})
.await;

// Resolve companion_platform_{id,display} from options + device_props.
// This is the single point where the pairing code flow picks what
// identity to announce; bare `PairCodeOptions::default()` derives from
// `Device.device_props` (os + platform_type) rather than the legacy
// "Chrome (Linux)" hardcode.
let (platform_id_str, platform_display_str) =
let (platform_id, platform_display) =
resolve_companion_platform(&options, &device_snapshot.device_props);
let platform_id_str = platform_id.to_string();

// Build the stage 1 IQ node
let req_id = self.generate_request_id();
let iq_content = PairCodeUtils::build_companion_hello_iq(
&phone_number,
&noise_static_pub,
&wrapped_ephemeral,
&platform_id_str,
&platform_display_str,
&platform_display,
options.show_push_notification,
req_id.clone(),
);
Expand Down
Loading
Loading