Skip to content

Commit

Permalink
Signature verification requests routing (#1094)
Browse files Browse the repository at this point in the history
* url parser

* imlement SmartContractVerification for lots of chainids

* explain unwraps

* naming

* imlement SmartContractVerification for lots of chainids (#1086)

* imlement SmartContractVerification for lots of chainids

* remove comment

* move file parser (#1087)

* move file parser

* load in verifier

* cleanup

* cleanup

* log malformatted url

* chainurls.json

* closure, dont expect

* go gentle into that good night

* default

* lint

* cleanup

* Add block number (#1089)

* block number optional

* rename multi contract verifier

* update permissions that changed for some reason

* remove fake.com

* scw verifier in bindings

* MLS Validation Service for SCW (#1098)

* wip

* wip

* patchwork

* a few fixes

* update to use scw verifier for inbox_ids

* Fix build errors

* fix signature

* lint

* remove debug

* lint

* revert gen protos script

* restore tests too

* feedback

* cleanup, feedback

* cleanup

* cleanup

* hash

* Actually do the work, and take the hash from the proto

* cleanup

* more cleanup

* not using error msg

* use latest proto

* wip

* cleanup

* nicer error

* revert

* unnecessary change

* remove env logger

* cleanup

* false in place of none

* lint

* error message in the result

---------

Co-authored-by: Dakota Brink <[email protected]>
Co-authored-by: Andrew Plaza <[email protected]>
Co-authored-by: Andrew Plaza <[email protected]>
Co-authored-by: Dakota Brink <[email protected]>
  • Loading branch information
5 people authored Oct 3, 2024
1 parent de864d4 commit 2acfde8
Show file tree
Hide file tree
Showing 35 changed files with 6,598 additions and 2,651 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ ecies_bindings_wasm/
**/test_output.jsonl
**/tracing.folded
**/tracing-flamegraph.svg

chain_urls.json
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions bindings_ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use xmtp_id::associations::unverified::UnverifiedSignature;
use xmtp_id::associations::AccountId;
use xmtp_id::associations::AssociationState;
use xmtp_id::associations::MemberIdentifier;
use xmtp_id::scw_verifier::RpcSmartContractWalletVerifier;
use xmtp_id::scw_verifier::SmartContractSignatureVerifier;
use xmtp_id::{
associations::{builder::SignatureRequest, generate_inbox_id as xmtp_id_generate_inbox_id},
Expand Down Expand Up @@ -183,11 +182,7 @@ pub fn generate_inbox_id(account_address: String, nonce: u64) -> String {
#[derive(uniffi::Object)]
pub struct FfiSignatureRequest {
inner: Arc<Mutex<SignatureRequest>>,
}

// TODO:nm store the verifier on the request from the client
fn signature_verifier() -> impl SmartContractSignatureVerifier {
RpcSmartContractWalletVerifier::new("http://www.fake.com".to_string())
scw_verifier: Box<dyn SmartContractSignatureVerifier>,
}

#[uniffi::export(async_runtime = "tokio")]
Expand All @@ -198,7 +193,7 @@ impl FfiSignatureRequest {
inner
.add_signature(
UnverifiedSignature::new_recoverable_ecdsa(signature_bytes),
&signature_verifier(),
self.scw_verifier.clone().as_ref(),
)
.await?;

Expand All @@ -222,7 +217,7 @@ impl FfiSignatureRequest {
block_number,
);
inner
.add_signature(signature, &signature_verifier())
.add_signature(signature, self.scw_verifier.clone().as_ref())
.await?;
Ok(())
}
Expand Down Expand Up @@ -358,12 +353,14 @@ impl FfiXmtpClient {
#[uniffi::export(async_runtime = "tokio")]
impl FfiXmtpClient {
pub fn signature_request(&self) -> Option<Arc<FfiSignatureRequest>> {
let scw_verifier = self.inner_client.context().scw_verifier.clone();
self.inner_client
.identity()
.signature_request()
.map(|request| {
Arc::new(FfiSignatureRequest {
inner: Arc::new(Mutex::new(request)),
scw_verifier,
})
})
}
Expand Down Expand Up @@ -400,6 +397,7 @@ impl FfiXmtpClient {

let request = Arc::new(FfiSignatureRequest {
inner: Arc::new(tokio::sync::Mutex::new(signature_request)),
scw_verifier: self.inner_client.context().scw_verifier.clone(),
});

Ok(request)
Expand Down Expand Up @@ -429,6 +427,7 @@ impl FfiXmtpClient {

let request = Arc::new(FfiSignatureRequest {
inner: Arc::new(tokio::sync::Mutex::new(signature_request)),
scw_verifier: self.inner_client.context().scw_verifier.clone(),
});

Ok(request)
Expand All @@ -455,6 +454,7 @@ impl FfiXmtpClient {

Ok(Arc::new(FfiSignatureRequest {
inner: Arc::new(tokio::sync::Mutex::new(signature_request)),
scw_verifier: self.inner_client.context().scw_verifier.clone(),
}))
}
}
Expand Down Expand Up @@ -1724,7 +1724,7 @@ impl FfiGroupPermissions {

#[cfg(test)]
mod tests {
use super::{create_client, signature_verifier, FfiMessage, FfiMessageCallback, FfiXmtpClient};
use super::{create_client, FfiMessage, FfiMessageCallback, FfiXmtpClient};
use crate::{
get_inbox_id_for_address, inbox_owner::SigningError, logger::FfiLogger, FfiConsent,
FfiConsentEntityType, FfiConsentState, FfiConversationCallback, FfiCreateGroupOptions,
Expand Down Expand Up @@ -2057,6 +2057,7 @@ mod tests {
wallet: &xmtp_cryptography::utils::LocalWallet,
signature_request: &FfiSignatureRequest,
) {
let scw_verifier = signature_request.scw_verifier.clone();
let signature_text = signature_request.inner.lock().await.signature_text();
let wallet_signature: Vec<u8> = wallet.sign(&signature_text.clone()).unwrap().into();

Expand All @@ -2068,7 +2069,7 @@ mod tests {
UnverifiedSignature::RecoverableEcdsa(UnverifiedRecoverableEcdsaSignature::new(
wallet_signature,
)),
&signature_verifier(),
scw_verifier.clone().as_ref(),
)
.await
.unwrap();
Expand Down
9 changes: 9 additions & 0 deletions bindings_node/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub struct NapiGroupMember {
pub consent_state: NapiConsentState,
}

#[derive(Debug)]
#[napi]
pub struct NapiGroup {
inner_client: Arc<RustXmtpClient>,
Expand Down
2 changes: 0 additions & 2 deletions bindings_wasm/src/mls_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ impl WasmClient {
signature_bytes: Uint8Array,
chain_id: u64,
account_address: String,
// TODO:nm Remove this
_chain_rpc_url: String,
block_number: u64,
) -> Result<(), JsError> {
if self.is_registered() {
Expand Down
11 changes: 5 additions & 6 deletions mls_validation_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ path = "src/main.rs"
[dependencies]
clap = { version = "4.4.6", features = ["derive"] }
ed25519-dalek = { workspace = true, features = ["digest"] }
ethers = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
openmls = { workspace = true }
Expand All @@ -20,15 +21,13 @@ serde = { workspace = true }
thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
tonic = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing.workspace = true
warp = "0.3.6"
xmtp_cryptography = { path = "../xmtp_cryptography" }
xmtp_id.workspace = true
xmtp_mls.workspace = true
xmtp_proto = { path = "../xmtp_proto", features = [
"proto_full",
"convert",
] }
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
xmtp_proto = { path = "../xmtp_proto", features = ["proto_full", "convert"] }

[dev-dependencies]
anyhow.workspace = true
Expand Down
Loading

0 comments on commit 2acfde8

Please sign in to comment.