From e9421f2e040e22b99ba81f5556ffe6a514face5b Mon Sep 17 00:00:00 2001 From: Sosthene Date: Wed, 30 Oct 2024 16:06:52 +0100 Subject: [PATCH] Fix connect.rs documentation --- tests/connect.rs | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/connect.rs b/tests/connect.rs index 5a85de8..83df1ef 100644 --- a/tests/connect.rs +++ b/tests/connect.rs @@ -24,29 +24,44 @@ use utils::*; wasm_bindgen_test_configure!(run_in_browser); #[wasm_bindgen_test] -/// Tests the connection process between two devices, Alice and Bob, by executing a series of secure -/// transactions to establish a shared secret for encrypted communication. +/// Tests the connection process between two devices, Alice and Bob, by executing a secure +/// transaction to establish a shared secret for encrypted communication. +/// +/// The basics are that one device will initiate the process by sending a transaction that pays another device. +/// The recipient of the transaction as soon as it finds it, can extract a shared secret and send an encrypted +/// message back. Upon receiving this message, the initiator answers with a similar message similarly encrypted. +/// Upon receiving this message, the recipient can be assured that the communication is safe, and start using +/// the secret to communicate. +/// +/// The security of the shared secret rest on the soundness of the silent payment protocol for Bitcoin. +/// In its encrypted response, the initiator adds a signature that is proof that it indeed controls the +/// private key for the silent payment address it announced, so recipient knows there's no mitm or impostor. /// -/// # Process Summary +/// # Detailed Process /// -/// ## Alice's Initialization: +/// ## Alice sends a transaction that pays Bob: /// - Alice initializes her device from an `sp_wallet` object and sets it as the local device. /// - She retrieves her own address and obtains Bob’s address. -/// - Alice creates a new member using Bob’s address to identify him within the transaction. -/// - She generates a connection transaction (`connect_tx`) targeting Bob's device, initiating the process for secure message sharing. +/// - Alice creates a new member using Bob’s device address (this is mainly for testing purpose, +/// because `create_connection_transaction` would take members as argument). +/// - She generates a connection transaction (`connect_tx`) targeting Bob's device. /// - Alice processes her own transaction and stores the derived shared secrets in `alice_secrets_store`, -/// associating each shared secret with Bob's addresses. +/// associating the shared secret with Bob's addresses. /// -/// ## Bob's Initialization: +/// ## Bob parses the transaction: /// - Bob initializes his device from his own `sp_wallet`. -/// - He parses Alice’s connection transaction to retrieve the shared secret Alice created for him, -/// then responds by sending an encrypted message back to Alice in a follow-up transaction. -/// - Bob saves these derived shared secrets in `bob_secrets_store`. +/// - He parses Alice’s connection transaction to retrieve the shared secret Alice created for him. +/// - Bob saves these derived shared secrets in `bob_secrets_store` but can't index it with Alice's address yet. /// -/// ## Message Exchange: -/// - **Alice’s Response**: Alice receives and decrypts the message from Bob’s response transaction. -/// - She replies to Bob by encrypting a confirmation message, updating her secrets in `alice_secrets_store`. -/// - **Bob’s Confirmation**: Bob receives Alice’s confirmation message, decrypts it, and updates his secrets in `bob_secrets_store`. +/// ## Prd Connect exchange +/// - Bob then responds by sending a prd connect back to Alice encrypted with the shared secret. +/// This prd is very simple and basically contains the following: +/// * All Bob's devices addresses +/// * a commitment to the shared secret +/// * a proof signed with Bob's device spend key +/// - Alice receives and decrypts the message from Bob. +/// - She replies to Bob by encrypting another prd connect which is basically the same, but keeping Bob's proof and adding her own. +/// - **Bob’s Confirmation**: Bob receives Alice’s confirmation message, decrypts it, and updates his secret in `bob_secrets_store`. /// /// ## Verification: /// - Finally, the function asserts that Alice and Bob now share the same secrets, confirming successful