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) <noreply@anthropic.com>
This commit is contained in:
@@ -257,10 +257,23 @@ pub fn self_test() -> Result<String, JsValue> {
|
|||||||
|
|
||||||
let text = result.get("text").and_then(|v| v.as_str()).unwrap_or("MISSING");
|
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!(
|
Ok(format!(
|
||||||
"WASM self-test: alice_fp={}, bob_fp={}, wire_bytes={}, decrypted='{}', PASS={}",
|
"alice_fp={}, bob_fp={}, wire_bytes={}, alice_shared={}..., bob_shared={}..., shared_match={}, decrypted='{}', PASS={}",
|
||||||
alice_pub.fingerprint, bob_pub.fingerprint, wire_bytes.len(), text,
|
alice_pub.fingerprint, bob_pub.fingerprint, wire_bytes.len(),
|
||||||
text == "hello from WASM self-test"
|
&alice_shared_hex[..16], &bob_shared_hex[..16], shared_match,
|
||||||
|
text, text == "hello from WASM self-test"
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user