From 07fc3668a1c405fcc11117a6e3fe1ea8dee3a711 Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Mon, 29 Nov 2021 17:36:32 +0200 Subject: [PATCH 1/4] Add mismatched network error during resolution --- identity-iota/src/chain/integration_chain.rs | 6 +++--- identity-iota/src/error.rs | 3 ++- identity-iota/src/tangle/client.rs | 12 ++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/identity-iota/src/chain/integration_chain.rs b/identity-iota/src/chain/integration_chain.rs index 43899287a5..17bd8d5f24 100644 --- a/identity-iota/src/chain/integration_chain.rs +++ b/identity-iota/src/chain/integration_chain.rs @@ -58,20 +58,20 @@ impl IntegrationChain { let root_document: IotaDocument = { let valid_root_documents: Vec = index .remove(&MessageId::null()) - .ok_or(Error::DIDNotFound("DID not found or pruned"))? + .ok_or_else(|| Error::DIDNotFound("DID not found or pruned".to_owned()))? .into_iter() .filter(|doc| IotaDocument::verify_root_document(doc).is_ok()) .collect(); if valid_root_documents.is_empty() { - return Err(Error::DIDNotFound("no valid root document found")); + return Err(Error::DIDNotFound("no valid root document found".to_owned())); } let sorted_root_documents: Vec = sort_by_milestone(valid_root_documents, client).await?; sorted_root_documents .into_iter() .next() - .ok_or(Error::DIDNotFound("no root document confirmed by a milestone found"))? + .ok_or_else(|| Error::DIDNotFound("no root document confirmed by a milestone found".to_owned()))? }; // Construct the rest of the integration chain. diff --git a/identity-iota/src/error.rs b/identity-iota/src/error.rs index 8ef39ec28e..8cb9bcc265 100644 --- a/identity-iota/src/error.rs +++ b/identity-iota/src/error.rs @@ -19,8 +19,9 @@ pub enum Error { ClientError(#[from] iota_client::error::Error), #[error("Invalid Message: {0}")] InvalidMessage(#[from] iota_client::bee_message::Error), + #[error("{0}")] - DIDNotFound(&'static str), + DIDNotFound(String), #[error("Invalid Document - Missing Message Id")] InvalidDocumentMessageId, #[error("Invalid Document - Signing Verification Method Type Not Supported")] diff --git a/identity-iota/src/tangle/client.rs b/identity-iota/src/tangle/client.rs index c1d41e3719..8209c5d398 100644 --- a/identity-iota/src/tangle/client.rs +++ b/identity-iota/src/tangle/client.rs @@ -18,6 +18,7 @@ use crate::did::IotaDID; use crate::document::DiffMessage; use crate::document::IotaDocument; use crate::error::Error; +use crate::error::Error::DIDNotFound; use crate::error::Result; use crate::tangle::ClientBuilder; use crate::tangle::DIDMessageEncoding; @@ -155,9 +156,16 @@ impl Client { /// Fetches a [`DocumentChain`] given an [`IotaDID`]. pub async fn read_document_chain(&self, did: &IotaDID) -> Result { log::trace!("Read Document Chain: {}", did); - log::trace!("Integration Chain Address: {}", did.tag()); + if self.network != did.network()? { + return Err(DIDNotFound(format!( + "DID network '{}' does not match client network '{}'", + did.network_str(), + self.network.name_str() + ))); + } // Fetch all messages for the integration chain. + log::trace!("Integration Chain Address: {}", did.tag()); let messages: Vec = self.read_messages(did.tag()).await?; let integration_chain: IntegrationChain = IntegrationChain::try_from_messages(did, &messages, self).await?; @@ -251,7 +259,7 @@ impl Client { } } -#[async_trait::async_trait(?Send)] +#[async_trait::async_trait(? Send)] impl TangleResolve for Client { async fn resolve(&self, did: &IotaDID) -> Result { self.read_document(did).await From 4a76e169a2762982a78a390d1211ecc09699e4b5 Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Mon, 29 Nov 2021 17:42:23 +0200 Subject: [PATCH 2/4] Remove unused identity-iota error variants --- identity-iota/src/error.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/identity-iota/src/error.rs b/identity-iota/src/error.rs index 8cb9bcc265..7b652e54bd 100644 --- a/identity-iota/src/error.rs +++ b/identity-iota/src/error.rs @@ -32,16 +32,6 @@ pub enum Error { InvalidRootDocument, #[error("Invalid Network Name")] InvalidNetworkName, - #[error("Invalid Tryte Conversion")] - InvalidTryteConversion, - #[error("Invalid Transaction Bundle")] - InvalidTransactionBundle, - #[error("Invalid Transaction Hashes")] - InvalidTransactionHashes, - #[error("Invalid Transaction Trytes")] - InvalidTransactionTrytes, - #[error("Invalid Bundle Tail")] - InvalidBundleTail, #[error("Invalid Presentation Holder")] InvalidPresentationHolder, #[error("Chain Error: {error}")] From 04adc6d2c7e174f3cd56882e4d314ab963635894 Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Mon, 29 Nov 2021 18:04:08 +0200 Subject: [PATCH 3/4] Improve NoClientNodesProvided error message slightly --- identity-iota/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-iota/src/error.rs b/identity-iota/src/error.rs index 7b652e54bd..e43eca3131 100644 --- a/identity-iota/src/error.rs +++ b/identity-iota/src/error.rs @@ -40,7 +40,7 @@ pub enum Error { MissingSigningKey, #[error("Cannot Revoke Verification Method")] CannotRevokeMethod, - #[error("No Client Nodes Provided")] + #[error("no client nodes provided for network")] NoClientNodesProvided, #[error("No Explorer URL Set")] NoExplorerURLSet, From 426b52bb0fc5b2d3dcc96e42e7ddb58393bf3ecf Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Mon, 29 Nov 2021 18:13:20 +0200 Subject: [PATCH 4/4] Fix formatting --- identity-iota/src/tangle/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-iota/src/tangle/client.rs b/identity-iota/src/tangle/client.rs index 8209c5d398..16b936a6f3 100644 --- a/identity-iota/src/tangle/client.rs +++ b/identity-iota/src/tangle/client.rs @@ -259,7 +259,7 @@ impl Client { } } -#[async_trait::async_trait(? Send)] +#[async_trait::async_trait(?Send)] impl TangleResolve for Client { async fn resolve(&self, did: &IotaDID) -> Result { self.read_document(did).await