From 99783c1fa4ec952a02afb4d32cfe697f8fa16b68 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Fri, 27 Mar 2026 09:11:17 +0400 Subject: [PATCH] Self-test: add X3DH shared secret comparison for debugging Shows alice_shared vs bob_shared to verify X3DH produces same secret. Co-Authored-By: Claude Opus 4.6 (1M context) --- warzone/crates/warzone-wasm/src/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/warzone/crates/warzone-wasm/src/lib.rs b/warzone/crates/warzone-wasm/src/lib.rs index 8c11482..3db5cbc 100644 --- a/warzone/crates/warzone-wasm/src/lib.rs +++ b/warzone/crates/warzone-wasm/src/lib.rs @@ -257,10 +257,23 @@ pub fn self_test() -> Result { let text = result.get("text").and_then(|v| v.as_str()).unwrap_or("MISSING"); + // More detailed info + let alice_shared_hex = hex::encode(x3dh_result.shared_secret); + + // Bob's side: compute shared secret for comparison + let bob_shared = x3dh::respond( + &bob_id, &bob_spk_secret, None, + &alice_pub.encryption, &x3dh_result.ephemeral_public, + ).map_err(|e| JsValue::from_str(&format!("X3DH respond direct: {}", e)))?; + let bob_shared_hex = hex::encode(bob_shared); + + let shared_match = alice_shared_hex == bob_shared_hex; + Ok(format!( - "WASM self-test: alice_fp={}, bob_fp={}, wire_bytes={}, decrypted='{}', PASS={}", - alice_pub.fingerprint, bob_pub.fingerprint, wire_bytes.len(), text, - text == "hello from WASM self-test" + "alice_fp={}, bob_fp={}, wire_bytes={}, alice_shared={}..., bob_shared={}..., shared_match={}, decrypted='{}', PASS={}", + alice_pub.fingerprint, bob_pub.fingerprint, wire_bytes.len(), + &alice_shared_hex[..16], &bob_shared_hex[..16], shared_match, + text, text == "hello from WASM self-test" )) }