Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Wallet Association By Using Installation Keys #1314

Merged
merged 16 commits into from
Nov 22, 2024
3 changes: 2 additions & 1 deletion bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ impl FfiXmtpClient {
) -> Result<Arc<FfiSignatureRequest>, 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)),
Expand Down
1 change: 1 addition & 0 deletions bindings_node/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions bindings_wasm/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 31 additions & 5 deletions xmtp_mls/src/identity_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -276,7 +277,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,
Expand All @@ -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::<InstallationKeyContext>(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
Expand Down Expand Up @@ -603,6 +625,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;
Expand Down Expand Up @@ -657,6 +680,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;
Expand Down Expand Up @@ -738,6 +762,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;
Expand Down Expand Up @@ -818,6 +843,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;
Expand Down
Loading