stakwork / sphinx-rs

Rust crates for Sphinx Chat
0 stars 0 forks source link

Better types #26

Closed irriden closed 11 months ago

irriden commented 11 months ago

Attempts to close #25

My biggest question is regarding the changes in lss-connector/src/broker.rs in 309be0bd73dc3b0205bcae6c18ba2d111fbfc499. Whenever we set the muts to Vec::new I set server_hmac to None.

Next will test the flow with these changes.

Evanfeenstra commented 11 months ago

@irriden That is not correct, you need to include the server_hmac even if the muts are empty.

The signer actually remembers the muts that were sent to the broker, and compares the HMAC with the locally saved muts https://github.com/stakwork/sphinx-rs/blob/master/lss-connector/src/signer.rs#L164. That is why in most cases, the broker actually sends empty muts back (no need to send back the exact same muts that were received, as that is just a waste of networking and deserializing on the signer side). However the muts are still needed in the BrokerMutations object because that is how the initial state sync in transferred

So the server_hmac is always required EXCEPT in cases where lss-connector/broker put_muts is called but the muts are actually empty. So put_muts should actually return an Option<[u8; 32]>, (None in the case of empty muts) which can directly be added to the BrokerMutations

Evanfeenstra commented 11 months ago

looks good to me, feel free to merge whenever