host_extensions/protocol/peer.rs
1/// Prefix applied to peer IDs derived from statement store public keys.
2pub const PEER_ID_PREFIX: &str = "peer-";
3
4/// Number of hex characters used from the public key.
5pub const PEER_ID_HEX_LEN: usize = 16;
6
7/// Format a peer ID from a hex-encoded public key.
8///
9/// The actual key derivation is platform-specific; this function
10/// only defines the canonical format: `"peer-{first 16 hex chars}"`.
11pub fn format_peer_id(pubkey_hex: &str) -> String {
12 let len = PEER_ID_HEX_LEN.min(pubkey_hex.len());
13 format!("{PEER_ID_PREFIX}{}", &pubkey_hex[..len])
14}
15
16/// Determine which peer is the offerer (creates the SDP offer).
17///
18/// Lower peer ID (lexicographic comparison) = offerer.
19/// Both peers must use the same function to agree on roles.
20pub fn is_offerer(local_peer_id: &str, remote_peer_id: &str) -> bool {
21 local_peer_id < remote_peer_id
22}