Expand description
Pairing protocol for cross-device identity linking.
This module implements a secure pairing protocol that allows users to link multiple devices to the same identity. The protocol uses X25519 ECDH key exchange with Ed25519 signature binding to ensure secure device authentication and forward secrecy.
§Protocol Flow
-
Initiating device generates a
PairingTokenwith:- Controller DID (identity of the initiator)
- X25519 ephemeral public key
- Alphanumeric short code (6-char, no ambiguous chars)
- Capabilities to grant
- 5-minute expiry
-
Initiating device displays the token as:
- QR code (preferred)
- Alphanumeric short code (fallback)
-
Responding device scans/enters the token and creates a
PairingResponse:- Generates its own X25519 ephemeral key
- Performs ECDH with initiator’s key → shared secret
- Signs binding message (short_code || initiator_x25519 || device_x25519)
- Includes its Ed25519 public key and DID
-
Initiating device verifies the response and completes ECDH:
- Verifies Ed25519 signature binding
- Performs ECDH with responder’s X25519 key → same shared secret
- Creates device attestation
§Example
use auths_core::pairing::{PairingToken, PairingResponse, format_pairing_qr};
use chrono::{DateTime, Utc};
// `now` is injected by the caller (e.g., clock.now() at presentation boundary)
fn initiate_pairing(now: DateTime<Utc>) {
let mut session = PairingToken::generate(
now,
"did:keri:controller123".to_string(),
"http://localhost:3000".to_string(),
vec!["sign_commit".to_string()],
).unwrap();
let display = format_pairing_qr(&session.token).unwrap();
print!("{}", display);
// Get the URI for QR code
let uri = session.token.to_uri();
}Re-exports§
pub use types::*;
Modules§
- types
- Shared API types for pairing sessions.
Structs§
- Pairing
Response - A response to a pairing request from the responding device.
- Pairing
Session - Ephemeral keypair for a pairing session.
- Pairing
Token - A pairing token for initiating cross-device identity linking.
- QrOptions
- QR code rendering options.
Enums§
- Pairing
Error - Errors that can occur during the pairing protocol.
Functions§
- format_
pairing_ qr - Format a pairing QR code with header text for terminal display.
- normalize_
short_ code - Normalize a short code: uppercase, strip spaces/dashes.
- render_
qr - Render a pairing token as a QR code string for terminal display.
- render_
qr_ from_ data - Render arbitrary data as a QR code string for terminal display.