From a99b4d0ab60cb8fab4fc64b9bcfac5d72875dd35 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Thu, 21 Nov 2024 16:07:56 -0500 Subject: [PATCH 01/14] wip --- bindings_ffi/src/mls.rs | 3 ++- bindings_node/src/signatures.rs | 1 + bindings_wasm/src/signatures.rs | 1 + xmtp_mls/src/identity_updates.rs | 6 +++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 7ab18fe12..f87aa91ce 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -480,7 +480,8 @@ impl FfiXmtpClient { ) -> Result, GenericError> { let signature_request = self .inner_client - .associate_wallet(existing_wallet_address.into(), new_wallet_address.into())?; + .associate_wallet(existing_wallet_address.into(), new_wallet_address.into()) + .await?; let scw_verifier = self.inner_client.scw_verifier().clone(); let request = Arc::new(FfiSignatureRequest { inner: Arc::new(tokio::sync::Mutex::new(signature_request)), diff --git a/bindings_node/src/signatures.rs b/bindings_node/src/signatures.rs index cfc67a81f..51187ac77 100644 --- a/bindings_node/src/signatures.rs +++ b/bindings_node/src/signatures.rs @@ -46,6 +46,7 @@ impl Client { existing_wallet_address.to_lowercase(), new_wallet_address.to_lowercase(), ) + .await .map_err(ErrorWrapper::from)?; let signature_text = signature_request.signature_text(); let mut signature_requests = self.signature_requests().lock().await; diff --git a/bindings_wasm/src/signatures.rs b/bindings_wasm/src/signatures.rs index 7c9f27ac7..58242b879 100644 --- a/bindings_wasm/src/signatures.rs +++ b/bindings_wasm/src/signatures.rs @@ -45,6 +45,7 @@ impl Client { existing_wallet_address.to_lowercase(), new_wallet_address.to_lowercase(), ) + .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; let signature_text = signature_request.signature_text(); let mut signature_requests = self.signature_requests().lock().await; diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index 83c0b9c5f..778e55433 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -276,7 +276,7 @@ where } /// Generate a `AssociateWallet` signature request using an existing wallet and a new wallet address - pub fn associate_wallet( + pub async fn associate_wallet( &self, existing_wallet_address: String, new_wallet_address: String, @@ -603,6 +603,7 @@ pub(crate) mod tests { let mut add_association_request = client .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .await .unwrap(); add_wallet_signature(&mut add_association_request, &wallet).await; @@ -657,6 +658,7 @@ pub(crate) mod tests { let mut add_association_request = client .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .await .unwrap(); add_wallet_signature(&mut add_association_request, &wallet).await; @@ -738,6 +740,7 @@ pub(crate) mod tests { let new_wallet = generate_local_wallet(); let mut add_association_request = client .associate_wallet(wallet.get_address(), new_wallet.get_address()) + .await .unwrap(); add_wallet_signature(&mut add_association_request, &wallet).await; @@ -818,6 +821,7 @@ pub(crate) mod tests { let mut add_wallet_signature_request = client .associate_wallet(recovery_wallet.get_address(), second_wallet.get_address()) + .await .unwrap(); add_wallet_signature(&mut add_wallet_signature_request, &recovery_wallet).await; From 3e52b2c8ba372a37967b0d2c3d46e2b37af7467f Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Thu, 21 Nov 2024 17:24:01 -0500 Subject: [PATCH 02/14] wip --- xmtp_mls/src/identity_updates.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index 778e55433..3e023c3a3 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -7,6 +7,7 @@ use crate::{ }; use futures::future::try_join_all; use thiserror::Error; +use xmtp_cryptography::CredentialSign; use xmtp_id::{ associations::{ apply_update, @@ -15,8 +16,8 @@ use xmtp_id::{ unverified::{ UnverifiedIdentityUpdate, UnverifiedInstallationKeySignature, UnverifiedSignature, }, - AssociationError, AssociationState, AssociationStateDiff, IdentityUpdate, MemberIdentifier, - SignatureError, + AssociationError, AssociationState, AssociationStateDiff, IdentityUpdate, + InstallationKeyContext, MemberIdentifier, SignatureError, }, scw_verifier::SmartContractSignatureVerifier, InboxIdRef, @@ -285,9 +286,30 @@ where let inbox_id = self.inbox_id(); let builder = SignatureRequestBuilder::new(inbox_id); - Ok(builder + let installation_public_key = self.identity().installation_keys.verifying_key(); + let mut signature_request = builder + .add_association( + installation_public_key.as_bytes().to_vec().into(), + existing_wallet_address.clone().into(), + ) .add_association(new_wallet_address.into(), existing_wallet_address.into()) - .build()) + .build(); + + let signature = self + .identity() + .installation_keys + .credential_sign::(signature_request.signature_text())?; + signature_request + .add_signature( + UnverifiedSignature::new_installation_key( + signature, + self.identity().installation_keys.verifying_key(), + ), + &self.scw_verifier, + ) + .await?; + + Ok(signature_request) } /// Revoke the given wallets from the association state for the client's inbox From 03682230a6c183e2fb6c30071e3ec3fb9955aa4c Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 10:34:00 -0500 Subject: [PATCH 03/14] sign with installation --- bindings_ffi/src/mls.rs | 29 +++++++++++++---------------- bindings_node/src/signatures.rs | 11 ++--------- bindings_wasm/src/signatures.rs | 6 +----- xmtp_id/src/associations/builder.rs | 29 +++++++++-------------------- xmtp_id/src/associations/member.rs | 7 +++++++ xmtp_mls/src/identity_updates.rs | 22 +++++++--------------- 6 files changed, 39 insertions(+), 65 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index f87aa91ce..a83cc6732 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -475,12 +475,11 @@ impl FfiXmtpClient { /// Adds an identity - really a wallet address - to the existing client pub async fn add_wallet( &self, - existing_wallet_address: &str, new_wallet_address: &str, ) -> Result, GenericError> { let signature_request = self .inner_client - .associate_wallet(existing_wallet_address.into(), new_wallet_address.into()) + .associate_wallet(new_wallet_address.into()) .await?; let scw_verifier = self.inner_client.scw_verifier().clone(); let request = Arc::new(FfiSignatureRequest { @@ -2175,10 +2174,9 @@ mod tests { use super::FfiSignatureRequest; async fn sign_with_wallet( - wallet: &xmtp_cryptography::utils::LocalWallet, signature_request: &FfiSignatureRequest, + wallet: &xmtp_cryptography::utils::LocalWallet, ) { - let scw_verifier = signature_request.scw_verifier.clone(); let signature_text = signature_request.inner.lock().await.signature_text(); let wallet_signature: Vec = wallet.sign(&signature_text.clone()).unwrap().into(); @@ -2190,7 +2188,7 @@ mod tests { UnverifiedSignature::RecoverableEcdsa(UnverifiedRecoverableEcdsaSignature::new( wallet_signature, )), - scw_verifier, + &signature_request.scw_verifier, ) .await .unwrap(); @@ -2225,7 +2223,7 @@ mod tests { let signature_request = client.signature_request().unwrap().clone(); register_client(&ffi_inbox_owner, &client).await; - sign_with_wallet(&ffi_inbox_owner.wallet, &signature_request).await; + sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; let conn = client.inner_client.store().conn().unwrap(); let state = client @@ -2237,18 +2235,17 @@ mod tests { assert_eq!(state.members().len(), 2); // Now, add the second wallet to the client - let wallet_to_add = generate_local_wallet(); let new_account_address = wallet_to_add.get_address(); println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) + .add_wallet(&new_account_address) .await .expect("could not add wallet"); - sign_with_wallet(&ffi_inbox_owner.wallet, &signature_request).await; - sign_with_wallet(&wallet_to_add, &signature_request).await; + sign_with_wallet(&signature_request, &wallet_to_add).await; + // sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; client .apply_signature_request(signature_request) @@ -2291,7 +2288,7 @@ mod tests { let signature_request = client.signature_request().unwrap().clone(); register_client(&ffi_inbox_owner, &client).await; - sign_with_wallet(&ffi_inbox_owner.wallet, &signature_request).await; + sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; let conn = client.inner_client.store().conn().unwrap(); let state = client @@ -2309,12 +2306,12 @@ mod tests { println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) + .add_wallet(&new_account_address) .await .expect("could not add wallet"); - sign_with_wallet(&ffi_inbox_owner.wallet, &signature_request).await; - sign_with_wallet(&wallet_to_add, &signature_request).await; + sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; + sign_with_wallet(&signature_request, &wallet_to_add).await; client .apply_signature_request(signature_request.clone()) @@ -2335,7 +2332,7 @@ mod tests { .await .expect("could not revoke wallet"); - sign_with_wallet(&ffi_inbox_owner.wallet, &signature_request).await; + sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; client .apply_signature_request(signature_request) @@ -3836,7 +3833,7 @@ mod tests { assert_eq!(client_2_state.installations.len(), 2); let signature_request = client_1.revoke_all_other_installations().await.unwrap(); - sign_with_wallet(&wallet, &signature_request).await; + sign_with_wallet(&signature_request, &wallet).await; client_1 .apply_signature_request(signature_request) .await diff --git a/bindings_node/src/signatures.rs b/bindings_node/src/signatures.rs index 51187ac77..709c374ec 100644 --- a/bindings_node/src/signatures.rs +++ b/bindings_node/src/signatures.rs @@ -35,17 +35,10 @@ impl Client { } #[napi] - pub async fn add_wallet_signature_text( - &self, - existing_wallet_address: String, - new_wallet_address: String, - ) -> Result { + pub async fn add_wallet_signature_text(&self, new_wallet_address: String) -> Result { let signature_request = self .inner_client() - .associate_wallet( - existing_wallet_address.to_lowercase(), - new_wallet_address.to_lowercase(), - ) + .associate_wallet(new_wallet_address.to_lowercase()) .await .map_err(ErrorWrapper::from)?; let signature_text = signature_request.signature_text(); diff --git a/bindings_wasm/src/signatures.rs b/bindings_wasm/src/signatures.rs index 58242b879..9fde22378 100644 --- a/bindings_wasm/src/signatures.rs +++ b/bindings_wasm/src/signatures.rs @@ -36,15 +36,11 @@ impl Client { #[wasm_bindgen(js_name = addWalletSignatureText)] pub async fn add_wallet_signature_text( &self, - existing_wallet_address: String, new_wallet_address: String, ) -> Result { let signature_request = self .inner_client() - .associate_wallet( - existing_wallet_address.to_lowercase(), - new_wallet_address.to_lowercase(), - ) + .associate_wallet(new_wallet_address.to_lowercase()) .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; let signature_text = signature_request.signature_text(); diff --git a/xmtp_id/src/associations/builder.rs b/xmtp_id/src/associations/builder.rs index cc1af30d9..360025493 100644 --- a/xmtp_id/src/associations/builder.rs +++ b/xmtp_id/src/associations/builder.rs @@ -2,7 +2,7 @@ //! resolved into an [`IdentityUpdate`]. An [`IdentityUpdate`] may be used for updating the state //! of an XMTP ID according to [XIP-46](https://github.com/xmtp/XIPs/pull/53) -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use crate::{scw_verifier::SmartContractSignatureVerifier, utils::now_ns}; use thiserror::Error; @@ -194,29 +194,18 @@ impl SignatureRequest { } } - pub fn missing_signatures(&self) -> Vec { - let signers: HashSet = self - .pending_actions + pub fn missing_signatures(&self) -> Vec<&MemberIdentifier> { + self.pending_actions .iter() - .flat_map(|pending_action| { - pending_action - .pending_signatures - .values() - .cloned() - .collect::>() - }) - .collect(); - - let signatures: HashSet = self.signatures.keys().cloned().collect(); - - signers.difference(&signatures).cloned().collect() + .flat_map(|pending_action| pending_action.pending_signatures.values()) + .filter(|pa| !self.signatures.contains_key(pa)) + .collect() } - pub fn missing_address_signatures(&self) -> Vec { + pub fn missing_address_signatures(&self) -> Vec<&MemberIdentifier> { self.missing_signatures() - .iter() + .into_iter() .filter(|member| member.kind() == MemberKind::Address) - .cloned() .collect() } @@ -275,7 +264,7 @@ impl SignatureRequest { tracing::info!("Missing Signatures: {:?}", missing_signatures); // Make sure the signer is someone actually in the request - if !missing_signatures.contains(signer_identity) { + if !missing_signatures.contains(&signer_identity) { return Err(SignatureRequestError::UnknownSigner); } diff --git a/xmtp_id/src/associations/member.rs b/xmtp_id/src/associations/member.rs index de7008a62..ef35f4b66 100644 --- a/xmtp_id/src/associations/member.rs +++ b/xmtp_id/src/associations/member.rs @@ -1,3 +1,4 @@ +use ed25519_dalek::VerifyingKey; use xmtp_cryptography::XmtpInstallationCredential; #[derive(Clone, Debug, PartialEq)] @@ -94,6 +95,12 @@ impl From> for MemberIdentifier { } } +impl From for MemberIdentifier { + fn from(installation: VerifyingKey) -> Self { + installation.as_bytes().to_vec().into() + } +} + impl<'a> From<&'a XmtpInstallationCredential> for MemberIdentifier { fn from(cred: &'a XmtpInstallationCredential) -> MemberIdentifier { MemberIdentifier::Installation(cred.public_slice().to_vec()) diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index 3e023c3a3..e1a0fc6e7 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -279,20 +279,15 @@ where /// Generate a `AssociateWallet` signature request using an existing wallet and a new wallet address pub async fn associate_wallet( &self, - existing_wallet_address: String, new_wallet_address: String, ) -> Result { tracing::info!("Associating new wallet with inbox_id {}", self.inbox_id()); let inbox_id = self.inbox_id(); let builder = SignatureRequestBuilder::new(inbox_id); - let installation_public_key = self.identity().installation_keys.verifying_key(); + let mut signature_request = builder - .add_association( - installation_public_key.as_bytes().to_vec().into(), - existing_wallet_address.clone().into(), - ) - .add_association(new_wallet_address.into(), existing_wallet_address.into()) + .add_association(new_wallet_address.into(), installation_public_key.into()) .build(); let signature = self @@ -301,10 +296,7 @@ where .credential_sign::(signature_request.signature_text())?; signature_request .add_signature( - UnverifiedSignature::new_installation_key( - signature, - self.identity().installation_keys.verifying_key(), - ), + UnverifiedSignature::new_installation_key(signature, installation_public_key), &self.scw_verifier, ) .await?; @@ -624,7 +616,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&wallet).await; let mut add_association_request = client - .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .associate_wallet(wallet_2_address.clone()) .await .unwrap(); @@ -679,7 +671,7 @@ pub(crate) mod tests { assert_logged!("Wrote association", 1); let mut add_association_request = client - .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .associate_wallet(wallet_2_address.clone()) .await .unwrap(); @@ -761,7 +753,7 @@ pub(crate) mod tests { .unwrap(); let new_wallet = generate_local_wallet(); let mut add_association_request = client - .associate_wallet(wallet.get_address(), new_wallet.get_address()) + .associate_wallet(new_wallet.get_address()) .await .unwrap(); @@ -842,7 +834,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&recovery_wallet).await; let mut add_wallet_signature_request = client - .associate_wallet(recovery_wallet.get_address(), second_wallet.get_address()) + .associate_wallet(second_wallet.get_address()) .await .unwrap(); From aabbb5888219f6f12341f4d5879fdb48d79a62e7 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 10:45:25 -0500 Subject: [PATCH 04/14] cleanup --- bindings_ffi/src/mls.rs | 60 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index a83cc6732..f2997940a 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -2172,26 +2172,28 @@ mod tests { assert!(result_errored, "did not error on wrong encryption key") } + trait SignWithWallet { + async fn sign_with_wallet(&self, wallet: &xmtp_cryptography::utils::LocalWallet); + } + use super::FfiSignatureRequest; - async fn sign_with_wallet( - signature_request: &FfiSignatureRequest, - wallet: &xmtp_cryptography::utils::LocalWallet, - ) { - let signature_text = signature_request.inner.lock().await.signature_text(); - let wallet_signature: Vec = wallet.sign(&signature_text.clone()).unwrap().into(); + impl SignWithWallet for FfiSignatureRequest { + async fn sign_with_wallet(&self, wallet: &xmtp_cryptography::utils::LocalWallet) { + let signature_text = self.inner.lock().await.signature_text(); + let wallet_signature: Vec = wallet.sign(&signature_text.clone()).unwrap().into(); - signature_request - .inner - .lock() - .await - .add_signature( - UnverifiedSignature::RecoverableEcdsa(UnverifiedRecoverableEcdsaSignature::new( - wallet_signature, - )), - &signature_request.scw_verifier, - ) - .await - .unwrap(); + self.inner + .lock() + .await + .add_signature( + UnverifiedSignature::RecoverableEcdsa( + UnverifiedRecoverableEcdsaSignature::new(wallet_signature), + ), + &self.scw_verifier, + ) + .await + .unwrap(); + } } use xmtp_cryptography::utils::generate_local_wallet; @@ -2223,7 +2225,9 @@ mod tests { let signature_request = client.signature_request().unwrap().clone(); register_client(&ffi_inbox_owner, &client).await; - sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; + signature_request + .sign_with_wallet(&ffi_inbox_owner.wallet) + .await; let conn = client.inner_client.store().conn().unwrap(); let state = client @@ -2244,7 +2248,7 @@ mod tests { .await .expect("could not add wallet"); - sign_with_wallet(&signature_request, &wallet_to_add).await; + signature_request.sign_with_wallet(&wallet_to_add).await; // sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; client @@ -2288,7 +2292,9 @@ mod tests { let signature_request = client.signature_request().unwrap().clone(); register_client(&ffi_inbox_owner, &client).await; - sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; + signature_request + .sign_with_wallet(&ffi_inbox_owner.wallet) + .await; let conn = client.inner_client.store().conn().unwrap(); let state = client @@ -2310,8 +2316,10 @@ mod tests { .await .expect("could not add wallet"); - sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; - sign_with_wallet(&signature_request, &wallet_to_add).await; + signature_request + .sign_with_wallet(&ffi_inbox_owner.wallet) + .await; + signature_request.sign_with_wallet(&wallet_to_add).await; client .apply_signature_request(signature_request.clone()) @@ -2332,7 +2340,9 @@ mod tests { .await .expect("could not revoke wallet"); - sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; + signature_request + .sign_with_wallet(&ffi_inbox_owner.wallet) + .await; client .apply_signature_request(signature_request) @@ -3833,7 +3843,7 @@ mod tests { assert_eq!(client_2_state.installations.len(), 2); let signature_request = client_1.revoke_all_other_installations().await.unwrap(); - sign_with_wallet(&signature_request, &wallet).await; + signature_request.sign_with_wallet(&wallet).await; client_1 .apply_signature_request(signature_request) .await From 3cd40d78b549f95298e605141d0c5cc475ee1bdc Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 10:46:05 -0500 Subject: [PATCH 05/14] naming --- bindings_ffi/src/mls.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index f2997940a..25c9bc46b 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -2173,12 +2173,12 @@ mod tests { } trait SignWithWallet { - async fn sign_with_wallet(&self, wallet: &xmtp_cryptography::utils::LocalWallet); + async fn add_wallet_signature(&self, wallet: &xmtp_cryptography::utils::LocalWallet); } use super::FfiSignatureRequest; impl SignWithWallet for FfiSignatureRequest { - async fn sign_with_wallet(&self, wallet: &xmtp_cryptography::utils::LocalWallet) { + async fn add_wallet_signature(&self, wallet: &xmtp_cryptography::utils::LocalWallet) { let signature_text = self.inner.lock().await.signature_text(); let wallet_signature: Vec = wallet.sign(&signature_text.clone()).unwrap().into(); @@ -2226,7 +2226,7 @@ mod tests { register_client(&ffi_inbox_owner, &client).await; signature_request - .sign_with_wallet(&ffi_inbox_owner.wallet) + .add_wallet_signature(&ffi_inbox_owner.wallet) .await; let conn = client.inner_client.store().conn().unwrap(); @@ -2248,7 +2248,7 @@ mod tests { .await .expect("could not add wallet"); - signature_request.sign_with_wallet(&wallet_to_add).await; + signature_request.add_wallet_signature(&wallet_to_add).await; // sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; client @@ -2293,7 +2293,7 @@ mod tests { register_client(&ffi_inbox_owner, &client).await; signature_request - .sign_with_wallet(&ffi_inbox_owner.wallet) + .add_wallet_signature(&ffi_inbox_owner.wallet) .await; let conn = client.inner_client.store().conn().unwrap(); @@ -2317,9 +2317,9 @@ mod tests { .expect("could not add wallet"); signature_request - .sign_with_wallet(&ffi_inbox_owner.wallet) + .add_wallet_signature(&ffi_inbox_owner.wallet) .await; - signature_request.sign_with_wallet(&wallet_to_add).await; + signature_request.add_wallet_signature(&wallet_to_add).await; client .apply_signature_request(signature_request.clone()) @@ -2341,7 +2341,7 @@ mod tests { .expect("could not revoke wallet"); signature_request - .sign_with_wallet(&ffi_inbox_owner.wallet) + .add_wallet_signature(&ffi_inbox_owner.wallet) .await; client @@ -3843,7 +3843,7 @@ mod tests { assert_eq!(client_2_state.installations.len(), 2); let signature_request = client_1.revoke_all_other_installations().await.unwrap(); - signature_request.sign_with_wallet(&wallet).await; + signature_request.add_wallet_signature(&wallet).await; client_1 .apply_signature_request(signature_request) .await From dfa181767cfc6f59fb2a3b98c5c50991a5280563 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 11:01:14 -0500 Subject: [PATCH 06/14] more cleanup --- bindings_ffi/src/mls.rs | 12 ++++++++---- bindings_node/src/signatures.rs | 8 ++++++-- bindings_wasm/src/signatures.rs | 3 ++- xmtp_mls/src/identity_updates.rs | 16 +++++++++++----- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 25c9bc46b..292f20b1c 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -472,14 +472,18 @@ impl FfiXmtpClient { Ok(()) } - /// Adds an identity - really a wallet address - to the existing client + /// Adds a wallet address to the existing client pub async fn add_wallet( &self, + existing_wallet_address: &str, new_wallet_address: &str, ) -> Result, GenericError> { let signature_request = self .inner_client - .associate_wallet(new_wallet_address.into()) + .associate_wallet( + existing_wallet_address.to_string(), + new_wallet_address.into(), + ) .await?; let scw_verifier = self.inner_client.scw_verifier().clone(); let request = Arc::new(FfiSignatureRequest { @@ -2244,7 +2248,7 @@ mod tests { println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&new_account_address) + .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) .await .expect("could not add wallet"); @@ -2312,7 +2316,7 @@ mod tests { println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&new_account_address) + .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) .await .expect("could not add wallet"); diff --git a/bindings_node/src/signatures.rs b/bindings_node/src/signatures.rs index 709c374ec..2dfed2feb 100644 --- a/bindings_node/src/signatures.rs +++ b/bindings_node/src/signatures.rs @@ -35,10 +35,14 @@ impl Client { } #[napi] - pub async fn add_wallet_signature_text(&self, new_wallet_address: String) -> Result { + pub async fn add_wallet_signature_text( + &self, + existing_wallet_address: String, + new_wallet_address: String, + ) -> Result { let signature_request = self .inner_client() - .associate_wallet(new_wallet_address.to_lowercase()) + .associate_wallet(existing_wallet_address, new_wallet_address.to_lowercase()) .await .map_err(ErrorWrapper::from)?; let signature_text = signature_request.signature_text(); diff --git a/bindings_wasm/src/signatures.rs b/bindings_wasm/src/signatures.rs index 9fde22378..ca441a3ec 100644 --- a/bindings_wasm/src/signatures.rs +++ b/bindings_wasm/src/signatures.rs @@ -36,11 +36,12 @@ impl Client { #[wasm_bindgen(js_name = addWalletSignatureText)] pub async fn add_wallet_signature_text( &self, + existing_wallet_address: String, new_wallet_address: String, ) -> Result { let signature_request = self .inner_client() - .associate_wallet(new_wallet_address.to_lowercase()) + .associate_wallet(existing_wallet_address, new_wallet_address.to_lowercase()) .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; let signature_text = signature_request.signature_text(); diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index e1a0fc6e7..5f3f13fd8 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -279,15 +279,21 @@ where /// Generate a `AssociateWallet` signature request using an existing wallet and a new wallet address pub async fn associate_wallet( &self, + existing_wallet_address: String, new_wallet_address: String, ) -> Result { tracing::info!("Associating new wallet with inbox_id {}", self.inbox_id()); let inbox_id = self.inbox_id(); let builder = SignatureRequestBuilder::new(inbox_id); let installation_public_key = self.identity().installation_keys.verifying_key(); + let new_member_identifier: MemberIdentifier = new_wallet_address.into(); let mut signature_request = builder - .add_association(new_wallet_address.into(), installation_public_key.into()) + .add_association( + new_member_identifier.clone(), + existing_wallet_address.into(), + ) + .add_association(new_member_identifier, installation_public_key.into()) .build(); let signature = self @@ -616,7 +622,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&wallet).await; let mut add_association_request = client - .associate_wallet(wallet_2_address.clone()) + .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) .await .unwrap(); @@ -671,7 +677,7 @@ pub(crate) mod tests { assert_logged!("Wrote association", 1); let mut add_association_request = client - .associate_wallet(wallet_2_address.clone()) + .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) .await .unwrap(); @@ -753,7 +759,7 @@ pub(crate) mod tests { .unwrap(); let new_wallet = generate_local_wallet(); let mut add_association_request = client - .associate_wallet(new_wallet.get_address()) + .associate_wallet(wallet.get_address(), new_wallet.get_address()) .await .unwrap(); @@ -834,7 +840,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&recovery_wallet).await; let mut add_wallet_signature_request = client - .associate_wallet(second_wallet.get_address()) + .associate_wallet(recovery_wallet.get_address(), second_wallet.get_address()) .await .unwrap(); From fcf8d571099c544e2fc0bf1e1602ba85482b6887 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 11:11:08 -0500 Subject: [PATCH 07/14] cleanup --- bindings_node/src/signatures.rs | 5 ++++- bindings_wasm/src/signatures.rs | 5 ++++- xmtp_id/src/associations/builder.rs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bindings_node/src/signatures.rs b/bindings_node/src/signatures.rs index 2dfed2feb..51187ac77 100644 --- a/bindings_node/src/signatures.rs +++ b/bindings_node/src/signatures.rs @@ -42,7 +42,10 @@ impl Client { ) -> Result { let signature_request = self .inner_client() - .associate_wallet(existing_wallet_address, new_wallet_address.to_lowercase()) + .associate_wallet( + existing_wallet_address.to_lowercase(), + new_wallet_address.to_lowercase(), + ) .await .map_err(ErrorWrapper::from)?; let signature_text = signature_request.signature_text(); diff --git a/bindings_wasm/src/signatures.rs b/bindings_wasm/src/signatures.rs index ca441a3ec..58242b879 100644 --- a/bindings_wasm/src/signatures.rs +++ b/bindings_wasm/src/signatures.rs @@ -41,7 +41,10 @@ impl Client { ) -> Result { let signature_request = self .inner_client() - .associate_wallet(existing_wallet_address, new_wallet_address.to_lowercase()) + .associate_wallet( + existing_wallet_address.to_lowercase(), + new_wallet_address.to_lowercase(), + ) .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; let signature_text = signature_request.signature_text(); diff --git a/xmtp_id/src/associations/builder.rs b/xmtp_id/src/associations/builder.rs index 7fe526372..43c0d166a 100644 --- a/xmtp_id/src/associations/builder.rs +++ b/xmtp_id/src/associations/builder.rs @@ -198,7 +198,7 @@ impl SignatureRequest { self.pending_actions .iter() .flat_map(|pending_action| pending_action.pending_signatures.values()) - .filter(|pa| !self.signatures.contains_key(pa)) + .filter(|ident| !self.signatures.contains_key(ident)) .collect() } From 67de882a7c6e65262e3cba5b9be3db5fc7c3165b Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 11:28:59 -0500 Subject: [PATCH 08/14] cleanup --- bindings_ffi/src/mls.rs | 5 +---- xmtp_mls/src/identity_updates.rs | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 292f20b1c..9a5b86182 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -480,10 +480,7 @@ impl FfiXmtpClient { ) -> Result, GenericError> { let signature_request = self .inner_client - .associate_wallet( - existing_wallet_address.to_string(), - new_wallet_address.into(), - ) + .associate_wallet(existing_wallet_address.into(), new_wallet_address.into()) .await?; let scw_verifier = self.inner_client.scw_verifier().clone(); let request = Arc::new(FfiSignatureRequest { diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index 5f3f13fd8..ed4629066 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -289,11 +289,14 @@ where let new_member_identifier: MemberIdentifier = new_wallet_address.into(); let mut signature_request = builder + // .add_association( + // new_member_identifier.clone(), + // existing_wallet_address.into(), + // ) .add_association( new_member_identifier.clone(), - existing_wallet_address.into(), + installation_public_key.into(), ) - .add_association(new_member_identifier, installation_public_key.into()) .build(); let signature = self From 482f7510c8f2d89a8ecf9870da9a1eba51c1bbed Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 11:51:03 -0500 Subject: [PATCH 09/14] getting closer --- bindings_ffi/src/mls.rs | 3 --- xmtp_mls/src/identity_updates.rs | 4 ---- 2 files changed, 7 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 9a5b86182..a3e69b4af 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -2317,9 +2317,6 @@ mod tests { .await .expect("could not add wallet"); - signature_request - .add_wallet_signature(&ffi_inbox_owner.wallet) - .await; signature_request.add_wallet_signature(&wallet_to_add).await; client diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index ed4629066..c446cd0e7 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -629,7 +629,6 @@ pub(crate) mod tests { .await .unwrap(); - add_wallet_signature(&mut add_association_request, &wallet).await; add_wallet_signature(&mut add_association_request, &wallet_2).await; client @@ -684,7 +683,6 @@ pub(crate) mod tests { .await .unwrap(); - add_wallet_signature(&mut add_association_request, &wallet).await; add_wallet_signature(&mut add_association_request, &wallet_2).await; client @@ -766,7 +764,6 @@ pub(crate) mod tests { .await .unwrap(); - add_wallet_signature(&mut add_association_request, &wallet).await; add_wallet_signature(&mut add_association_request, &new_wallet).await; client @@ -847,7 +844,6 @@ pub(crate) mod tests { .await .unwrap(); - add_wallet_signature(&mut add_wallet_signature_request, &recovery_wallet).await; add_wallet_signature(&mut add_wallet_signature_request, &second_wallet).await; client From f0bb14159980457a368083b7c18adcdcd5af77e2 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 12:02:54 -0500 Subject: [PATCH 10/14] test fix --- bindings_node/test/Client.test.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bindings_node/test/Client.test.ts b/bindings_node/test/Client.test.ts index 063b0f603..5bfec443b 100644 --- a/bindings_node/test/Client.test.ts +++ b/bindings_node/test/Client.test.ts @@ -70,17 +70,17 @@ describe('Client', () => { expect(signatureText).toBeDefined() // sign message - const signature = await user.wallet.signMessage({ - message: signatureText, - }) + // const signature = await user.wallet.signMessage({ + // message: signatureText, + // }) const signature2 = await user2.wallet.signMessage({ message: signatureText, }) - await client.addSignature( - SignatureRequestType.AddWallet, - toBytes(signature) - ) + // await client.addSignature( + // SignatureRequestType.AddWallet, + // toBytes(signature) + // ) await client.addSignature( SignatureRequestType.AddWallet, toBytes(signature2) @@ -114,10 +114,10 @@ describe('Client', () => { message: signatureText, }) - await client.addSignature( - SignatureRequestType.AddWallet, - toBytes(signature) - ) + // await client.addSignature( + // SignatureRequestType.AddWallet, + // toBytes(signature) + // ) await client.addSignature( SignatureRequestType.AddWallet, toBytes(signature2) From ca89653457fe5d1bc72c348e52dcb158f9024d47 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 12:16:51 -0500 Subject: [PATCH 11/14] remove a param --- bindings_ffi/src/mls.rs | 7 +++---- bindings_node/src/signatures.rs | 11 ++--------- bindings_node/test/Client.test.ts | 11 ----------- bindings_wasm/src/signatures.rs | 6 +----- xmtp_mls/src/identity_updates.rs | 13 ++++--------- 5 files changed, 10 insertions(+), 38 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index a3e69b4af..a67da58f1 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -475,12 +475,11 @@ impl FfiXmtpClient { /// Adds a wallet address to the existing client pub async fn add_wallet( &self, - existing_wallet_address: &str, new_wallet_address: &str, ) -> Result, GenericError> { let signature_request = self .inner_client - .associate_wallet(existing_wallet_address.into(), new_wallet_address.into()) + .associate_wallet(new_wallet_address.into()) .await?; let scw_verifier = self.inner_client.scw_verifier().clone(); let request = Arc::new(FfiSignatureRequest { @@ -2245,7 +2244,7 @@ mod tests { println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) + .add_wallet(&new_account_address) .await .expect("could not add wallet"); @@ -2313,7 +2312,7 @@ mod tests { println!("second address: {}", new_account_address); let signature_request = client - .add_wallet(&ffi_inbox_owner.get_address(), &new_account_address) + .add_wallet(&new_account_address) .await .expect("could not add wallet"); diff --git a/bindings_node/src/signatures.rs b/bindings_node/src/signatures.rs index 51187ac77..709c374ec 100644 --- a/bindings_node/src/signatures.rs +++ b/bindings_node/src/signatures.rs @@ -35,17 +35,10 @@ impl Client { } #[napi] - pub async fn add_wallet_signature_text( - &self, - existing_wallet_address: String, - new_wallet_address: String, - ) -> Result { + pub async fn add_wallet_signature_text(&self, new_wallet_address: String) -> Result { let signature_request = self .inner_client() - .associate_wallet( - existing_wallet_address.to_lowercase(), - new_wallet_address.to_lowercase(), - ) + .associate_wallet(new_wallet_address.to_lowercase()) .await .map_err(ErrorWrapper::from)?; let signature_text = signature_request.signature_text(); diff --git a/bindings_node/test/Client.test.ts b/bindings_node/test/Client.test.ts index 5bfec443b..cf7fed29e 100644 --- a/bindings_node/test/Client.test.ts +++ b/bindings_node/test/Client.test.ts @@ -69,10 +69,6 @@ describe('Client', () => { ) expect(signatureText).toBeDefined() - // sign message - // const signature = await user.wallet.signMessage({ - // message: signatureText, - // }) const signature2 = await user2.wallet.signMessage({ message: signatureText, }) @@ -107,17 +103,10 @@ describe('Client', () => { expect(signatureText).toBeDefined() // sign message - const signature = await user.wallet.signMessage({ - message: signatureText, - }) const signature2 = await user2.wallet.signMessage({ message: signatureText, }) - // await client.addSignature( - // SignatureRequestType.AddWallet, - // toBytes(signature) - // ) await client.addSignature( SignatureRequestType.AddWallet, toBytes(signature2) diff --git a/bindings_wasm/src/signatures.rs b/bindings_wasm/src/signatures.rs index 58242b879..9fde22378 100644 --- a/bindings_wasm/src/signatures.rs +++ b/bindings_wasm/src/signatures.rs @@ -36,15 +36,11 @@ impl Client { #[wasm_bindgen(js_name = addWalletSignatureText)] pub async fn add_wallet_signature_text( &self, - existing_wallet_address: String, new_wallet_address: String, ) -> Result { let signature_request = self .inner_client() - .associate_wallet( - existing_wallet_address.to_lowercase(), - new_wallet_address.to_lowercase(), - ) + .associate_wallet(new_wallet_address.to_lowercase()) .await .map_err(|e| JsError::new(format!("{}", e).as_str()))?; let signature_text = signature_request.signature_text(); diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index c446cd0e7..aa955290a 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -279,7 +279,6 @@ where /// Generate a `AssociateWallet` signature request using an existing wallet and a new wallet address pub async fn associate_wallet( &self, - existing_wallet_address: String, new_wallet_address: String, ) -> Result { tracing::info!("Associating new wallet with inbox_id {}", self.inbox_id()); @@ -289,10 +288,6 @@ where let new_member_identifier: MemberIdentifier = new_wallet_address.into(); let mut signature_request = builder - // .add_association( - // new_member_identifier.clone(), - // existing_wallet_address.into(), - // ) .add_association( new_member_identifier.clone(), installation_public_key.into(), @@ -625,7 +620,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&wallet).await; let mut add_association_request = client - .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .associate_wallet(wallet_2_address.clone()) .await .unwrap(); @@ -679,7 +674,7 @@ pub(crate) mod tests { assert_logged!("Wrote association", 1); let mut add_association_request = client - .associate_wallet(wallet_address.clone(), wallet_2_address.clone()) + .associate_wallet(wallet_2_address.clone()) .await .unwrap(); @@ -760,7 +755,7 @@ pub(crate) mod tests { .unwrap(); let new_wallet = generate_local_wallet(); let mut add_association_request = client - .associate_wallet(wallet.get_address(), new_wallet.get_address()) + .associate_wallet(new_wallet.get_address()) .await .unwrap(); @@ -840,7 +835,7 @@ pub(crate) mod tests { let client = ClientBuilder::new_test_client(&recovery_wallet).await; let mut add_wallet_signature_request = client - .associate_wallet(recovery_wallet.get_address(), second_wallet.get_address()) + .associate_wallet(second_wallet.get_address()) .await .unwrap(); From e58b9620654facd92997c1ad6935d94e4fabd7e4 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 12:21:29 -0500 Subject: [PATCH 12/14] cleanup --- bindings_ffi/src/mls.rs | 1 - bindings_node/test/Client.test.ts | 4 ---- 2 files changed, 5 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index a67da58f1..f8c9ab19a 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -2249,7 +2249,6 @@ mod tests { .expect("could not add wallet"); signature_request.add_wallet_signature(&wallet_to_add).await; - // sign_with_wallet(&signature_request, &ffi_inbox_owner.wallet).await; client .apply_signature_request(signature_request) diff --git a/bindings_node/test/Client.test.ts b/bindings_node/test/Client.test.ts index cf7fed29e..000d93a0b 100644 --- a/bindings_node/test/Client.test.ts +++ b/bindings_node/test/Client.test.ts @@ -73,10 +73,6 @@ describe('Client', () => { message: signatureText, }) - // await client.addSignature( - // SignatureRequestType.AddWallet, - // toBytes(signature) - // ) await client.addSignature( SignatureRequestType.AddWallet, toBytes(signature2) From cf583e80241593af51b1ed343cfa36cb42355f16 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 12:34:51 -0500 Subject: [PATCH 13/14] fix js tests --- bindings_node/test/Client.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings_node/test/Client.test.ts b/bindings_node/test/Client.test.ts index 000d93a0b..8942e7b25 100644 --- a/bindings_node/test/Client.test.ts +++ b/bindings_node/test/Client.test.ts @@ -64,7 +64,6 @@ describe('Client', () => { const user2 = createUser() const client = await createRegisteredClient(user) const signatureText = await client.addWalletSignatureText( - user.account.address, user2.account.address ) expect(signatureText).toBeDefined() @@ -93,7 +92,6 @@ describe('Client', () => { const user2 = createUser() const client = await createRegisteredClient(user) const signatureText = await client.addWalletSignatureText( - user.account.address, user2.account.address ) expect(signatureText).toBeDefined() From e2598b22cd46dc90140aa5d931f9fc067627ee65 Mon Sep 17 00:00:00 2001 From: Dakota Brink Date: Fri, 22 Nov 2024 12:47:05 -0500 Subject: [PATCH 14/14] unnecessary clone --- xmtp_mls/src/identity_updates.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xmtp_mls/src/identity_updates.rs b/xmtp_mls/src/identity_updates.rs index aa955290a..23d08e69a 100644 --- a/xmtp_mls/src/identity_updates.rs +++ b/xmtp_mls/src/identity_updates.rs @@ -288,10 +288,7 @@ where let new_member_identifier: MemberIdentifier = new_wallet_address.into(); let mut signature_request = builder - .add_association( - new_member_identifier.clone(), - installation_public_key.into(), - ) + .add_association(new_member_identifier, installation_public_key.into()) .build(); let signature = self