Skip to content
7 changes: 3 additions & 4 deletions src/client/lid_pn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,9 @@ impl Client {
}

/// Resolve any user JID to its bare LID form, or `None` when no LID is
/// available. Mirrors WA Web's `WAWebLidMigrationUtils.toUserLid`
/// (`docs/captured-js/WAWeb/Lid/MigrationUtils.js:17-20`): LID passes
/// through, PN goes through the cache-aside mapping, anything else and
/// any lookup failure returns `None`.
/// available. Mirrors WA Web's `WAWebLidMigrationUtils.toUserLid`: LID
/// passes through, PN goes through the cache-aside mapping, anything
/// else and any lookup failure returns `None`.
///
/// Used by `send_status_message` to replicate WA Web's
/// `compactMap(list, toUserLid)` skip-on-unresolvable semantics.
Expand Down
2 changes: 1 addition & 1 deletion src/features/media_reupload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! sends a `<receipt type="server-error">` stanza and waits for a
//! `<notification type="mediaretry">` response with a new `directPath`.
//!
//! Reference: WAWebRequestMediaReuploadManager (docs/captured-js/).
//! Reference: WAWebRequestMediaReuploadManager.

use crate::client::{Client, ClientError, NodeFilter};
use anyhow::Result;
Expand Down
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::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::companion_reg::{CompanionWebClientType, NATIVE_CAMERA_DEEP_LINK_PREFIX};
pub use wacore::pair::{DeviceState, PairCryptoError, PairUtils};

pub fn make_qr_data(store: &crate::store::Device, ref_str: String) -> String {
/// Auto-derives client type from `device_props`; see
/// [`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)
}

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
12 changes: 4 additions & 8 deletions src/pair_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use wacore_binary::Jid;
use wacore_binary::{NodeContent, NodeContentRef, NodeRef};

// Re-export types for user convenience
pub use wacore::companion_reg::CompanionWebClientType;
pub use wacore::pair_code::PairCodeOptions;

impl Client {
Expand Down Expand Up @@ -160,22 +161,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