From 0b726123f52eeb5890da075739b6805156c85d5a Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Mon, 29 Nov 2021 13:16:49 +0200 Subject: [PATCH] Rename `DocumentDiff` to `DiffMessage` (#511) * Rename DocumentDiff to DiffMessage * Refactor identity-iota layout * Replace macro_use with explicit imports * Fix clippy lints --- bindings/wasm/docs/api-reference.md | 218 +++++++++--------- bindings/wasm/src/chain/document_history.rs | 28 +-- bindings/wasm/src/did/mod.rs | 4 +- ..._document_diff.rs => wasm_diff_message.rs} | 18 +- bindings/wasm/src/did/wasm_document.rs | 14 +- bindings/wasm/src/tangle/client.rs | 6 +- examples/account/config.rs | 8 +- examples/low-level-api/diff_chain.rs | 4 +- examples/low-level-api/private_tangle.rs | 8 +- examples/low-level-api/resolve_history.rs | 8 +- identity-account/src/account/account.rs | 8 +- .../src/identity/identity_state.rs | 2 +- identity-account/src/updates/update.rs | 4 +- identity-did/src/did/did_url.rs | 6 +- identity-iota/src/chain/diff_chain.rs | 46 ++-- identity-iota/src/chain/document_chain.rs | 11 +- identity-iota/src/chain/document_history.rs | 20 +- identity-iota/src/chain/integration_chain.rs | 10 +- identity-iota/src/credential/validator.rs | 2 +- identity-iota/src/did/did/mod.rs | 9 - identity-iota/src/did/{did => }/iota_did.rs | 4 + identity-iota/src/did/mod.rs | 21 +- identity-iota/src/did/{did => }/segments.rs | 0 .../diff_message.rs} | 22 +- .../{did/doc => document}/iota_document.rs | 57 ++--- .../iota_verification_method.rs | 4 + .../src/{did/doc => document}/mod.rs | 12 +- .../src/{did/doc => document}/properties.rs | 4 + identity-iota/src/lib.rs | 14 +- identity-iota/src/resolver.rs | 2 +- identity-iota/src/tangle/client.rs | 18 +- identity-iota/src/tangle/client_map.rs | 6 +- identity-iota/src/tangle/explorer.rs | 6 +- .../src/tangle/message/compression_brotli.rs | 2 +- .../src/tangle/message/message_ext.rs | 14 +- identity-iota/src/tangle/network.rs | 6 +- identity-iota/src/tangle/publish.rs | 4 +- identity-iota/src/tangle/receipt.rs | 4 + identity-iota/src/tangle/traits.rs | 2 +- identity/benches/diff_chain.rs | 4 +- identity/src/lib.rs | 3 +- 41 files changed, 323 insertions(+), 320 deletions(-) rename bindings/wasm/src/did/{wasm_document_diff.rs => wasm_diff_message.rs} (87%) delete mode 100644 identity-iota/src/did/did/mod.rs rename identity-iota/src/did/{did => }/iota_did.rs (99%) rename identity-iota/src/did/{did => }/segments.rs (100%) rename identity-iota/src/{did/doc/document_diff.rs => document/diff_message.rs} (89%) rename identity-iota/src/{did/doc => document}/iota_document.rs (97%) rename identity-iota/src/{did/doc => document}/iota_verification_method.rs (99%) rename identity-iota/src/{did/doc => document}/mod.rs (86%) rename identity-iota/src/{did/doc => document}/properties.rs (94%) diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index fe45dcc47c..08be10fe4d 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -11,11 +11,11 @@
DiffChainHistory
-
Document
-
-
DocumentDiff
+
DiffMessage

Defines the difference between two DID Documents' JSON representations.

+
Document
+
DocumentHistory

A DID Document's history and current state.

@@ -109,14 +109,14 @@ Publishes an `IotaDocument` to the Tangle. ### client.publishDiff(message_id, diff) ⇒ [Promise.<Receipt>](#Receipt) -Publishes a `DocumentDiff` to the Tangle. +Publishes a `DiffMessage` to the Tangle. **Kind**: instance method of [Client](#Client) | Param | Type | | --- | --- | | message_id | string | -| diff | [DocumentDiff](#DocumentDiff) | +| diff | [DiffMessage](#DiffMessage) | @@ -629,7 +629,7 @@ Parses a `DIDUrl` from the input string. * [DiffChainHistory](#DiffChainHistory) * _instance_ - * [.chainData()](#DiffChainHistory+chainData) ⇒ [Array.<DocumentDiff>](#DocumentDiff) + * [.chainData()](#DiffChainHistory+chainData) ⇒ [Array.<DiffMessage>](#DiffMessage) * [.spam()](#DiffChainHistory+spam) ⇒ Array.<string> * [.toJSON()](#DiffChainHistory+toJSON) ⇒ any * _static_ @@ -637,8 +637,8 @@ Parses a `DIDUrl` from the input string. -### diffChainHistory.chainData() ⇒ [Array.<DocumentDiff>](#DocumentDiff) -Returns an `Array` of the diff chain `DocumentDiffs`. +### diffChainHistory.chainData() ⇒ [Array.<DiffMessage>](#DiffMessage) +Returns an `Array` of the diff chain `DiffMessages`. NOTE: this clones the field. @@ -668,6 +668,98 @@ Deserializes from a JSON object. | --- | --- | | json | any | + + +## DiffMessage +Defines the difference between two DID `Document`s' JSON representations. + +**Kind**: global class + +* [DiffMessage](#DiffMessage) + * [.did](#DiffMessage+did) ⇒ [DID](#DID) + * [.diff](#DiffMessage+diff) ⇒ string + * [.messageId](#DiffMessage+messageId) ⇒ string + * [.messageId](#DiffMessage+messageId) + * [.previousMessageId](#DiffMessage+previousMessageId) ⇒ string + * [.previousMessageId](#DiffMessage+previousMessageId) + * [.proof](#DiffMessage+proof) ⇒ any + * [.id()](#DiffMessage+id) ⇒ [DID](#DID) + * [.merge(document)](#DiffMessage+merge) ⇒ [Document](#Document) + + + +### diffMessage.did ⇒ [DID](#DID) +Returns the DID of the associated DID Document. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + + +### diffMessage.diff ⇒ string +Returns the raw contents of the DID Document diff. + +NOTE: clones the data. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + + +### diffMessage.messageId ⇒ string +Returns the message_id of the DID Document diff. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + + +### diffMessage.messageId +Sets the message_id of the DID Document diff. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + +| Param | Type | +| --- | --- | +| message_id | string | + + + +### diffMessage.previousMessageId ⇒ string +Returns the Tangle message id of the previous DID Document diff. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + + +### diffMessage.previousMessageId +Sets the Tangle message id of the previous DID Document diff. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + +| Param | Type | +| --- | --- | +| message_id | string | + + + +### diffMessage.proof ⇒ any +Returns the `proof` object. + +**Kind**: instance property of [DiffMessage](#DiffMessage) + + +### diffMessage.id() ⇒ [DID](#DID) +Returns the DID of the associated DID Document. + +NOTE: clones the data. + +**Kind**: instance method of [DiffMessage](#DiffMessage) + + +### diffMessage.merge(document) ⇒ [Document](#Document) +Returns a new DID Document which is the result of merging `self` +with the given Document. + +**Kind**: instance method of [DiffMessage](#DiffMessage) + +| Param | Type | +| --- | --- | +| document | [Document](#Document) | + ## Document @@ -700,7 +792,7 @@ Deserializes from a JSON object. * [.verifyDataWithScope(data, scope)](#Document+verifyDataWithScope) ⇒ boolean * [.resolveMethod(query)](#Document+resolveMethod) ⇒ [VerificationMethod](#VerificationMethod) * [.revokeMerkleKey(query, index)](#Document+revokeMerkleKey) ⇒ boolean - * [.diff(other, message, key, method)](#Document+diff) ⇒ [DocumentDiff](#DocumentDiff) + * [.diff(other, message, key, method)](#Document+diff) ⇒ [DiffMessage](#DiffMessage) * [.verifyDiff(diff)](#Document+verifyDiff) * [.merge(diff)](#Document+merge) * [.integrationIndex()](#Document+integrationIndex) ⇒ string @@ -971,8 +1063,8 @@ in this DID Document with the verification relationship specified by `scope`. -### document.diff(other, message, key, method) ⇒ [DocumentDiff](#DocumentDiff) -Generate a `DocumentDiff` between two DID Documents and sign it using the specified +### document.diff(other, message, key, method) ⇒ [DiffMessage](#DiffMessage) +Generate a `DiffMessage` between two DID Documents and sign it using the specified `key` and `method`. **Kind**: instance method of [Document](#Document) @@ -998,18 +1090,18 @@ Fails if an unsupported verification method is used or the verification operatio | Param | Type | | --- | --- | -| diff | [DocumentDiff](#DocumentDiff) | +| diff | [DiffMessage](#DiffMessage) | ### document.merge(diff) -Verifies a `DocumentDiff` signature and merges the changes into `self`. +Verifies a `DiffMessage` signature and merges the changes into `self`. **Kind**: instance method of [Document](#Document) | Param | Type | | --- | --- | -| diff | [DocumentDiff](#DocumentDiff) | +| diff | [DiffMessage](#DiffMessage) | @@ -1081,98 +1173,6 @@ Deserializes a `Document` object from a JSON object. | --- | --- | | json | any | - - -## DocumentDiff -Defines the difference between two DID `Document`s' JSON representations. - -**Kind**: global class - -* [DocumentDiff](#DocumentDiff) - * [.did](#DocumentDiff+did) ⇒ [DID](#DID) - * [.diff](#DocumentDiff+diff) ⇒ string - * [.messageId](#DocumentDiff+messageId) ⇒ string - * [.messageId](#DocumentDiff+messageId) - * [.previousMessageId](#DocumentDiff+previousMessageId) ⇒ string - * [.previousMessageId](#DocumentDiff+previousMessageId) - * [.proof](#DocumentDiff+proof) ⇒ any - * [.id()](#DocumentDiff+id) ⇒ [DID](#DID) - * [.merge(document)](#DocumentDiff+merge) ⇒ [Document](#Document) - - - -### documentDiff.did ⇒ [DID](#DID) -Returns the DID of the associated DID Document. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - - -### documentDiff.diff ⇒ string -Returns the raw contents of the DID Document diff. - -NOTE: clones the data. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - - -### documentDiff.messageId ⇒ string -Returns the message_id of the DID Document diff. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - - -### documentDiff.messageId -Sets the message_id of the DID Document diff. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - -| Param | Type | -| --- | --- | -| message_id | string | - - - -### documentDiff.previousMessageId ⇒ string -Returns the Tangle message id of the previous DID Document diff. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - - -### documentDiff.previousMessageId -Sets the Tangle message id of the previous DID Document diff. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - -| Param | Type | -| --- | --- | -| message_id | string | - - - -### documentDiff.proof ⇒ any -Returns the `proof` object. - -**Kind**: instance property of [DocumentDiff](#DocumentDiff) - - -### documentDiff.id() ⇒ [DID](#DID) -Returns the DID of the associated DID Document. - -NOTE: clones the data. - -**Kind**: instance method of [DocumentDiff](#DocumentDiff) - - -### documentDiff.merge(document) ⇒ [Document](#Document) -Returns a new DID Document which is the result of merging `self` -with the given Document. - -**Kind**: instance method of [DocumentDiff](#DocumentDiff) - -| Param | Type | -| --- | --- | -| document | [Document](#Document) | - ## DocumentHistory @@ -1184,7 +1184,7 @@ A DID Document's history and current state. * _instance_ * [.integrationChainData()](#DocumentHistory+integrationChainData) ⇒ [Array.<Document>](#Document) * [.integrationChainSpam()](#DocumentHistory+integrationChainSpam) ⇒ Array.<string> - * [.diffChainData()](#DocumentHistory+diffChainData) ⇒ [Array.<DocumentDiff>](#DocumentDiff) + * [.diffChainData()](#DocumentHistory+diffChainData) ⇒ [Array.<DiffMessage>](#DiffMessage) * [.diffChainSpam()](#DocumentHistory+diffChainSpam) ⇒ Array.<string> * [.toJSON()](#DocumentHistory+toJSON) ⇒ any * _static_ @@ -1209,8 +1209,8 @@ NOTE: clones the data. **Kind**: instance method of [DocumentHistory](#DocumentHistory) -### documentHistory.diffChainData() ⇒ [Array.<DocumentDiff>](#DocumentDiff) -Returns an `Array` of diff chain `DocumentDiffs`. +### documentHistory.diffChainData() ⇒ [Array.<DiffMessage>](#DiffMessage) +Returns an `Array` of diff chain `DiffMessages`. NOTE: clones the data. diff --git a/bindings/wasm/src/chain/document_history.rs b/bindings/wasm/src/chain/document_history.rs index 5ba8f02777..c18a93100a 100644 --- a/bindings/wasm/src/chain/document_history.rs +++ b/bindings/wasm/src/chain/document_history.rs @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 use identity::iota::ChainHistory; -use identity::iota::DocumentDiff; +use identity::iota::DiffMessage; use identity::iota::DocumentHistory; use identity::iota::IotaDocument; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; +use crate::did::WasmDiffMessage; use crate::did::WasmDocument; -use crate::did::WasmDocumentDiff; use crate::error::Result; use crate::error::WasmResult; @@ -36,8 +36,8 @@ extern "C" { #[wasm_bindgen(typescript_type = "Array")] pub type ArrayDocument; - #[wasm_bindgen(typescript_type = "Array")] - pub type ArrayDocumentDiff; + #[wasm_bindgen(typescript_type = "Array")] + pub type ArrayDiffMessage; } #[wasm_bindgen(js_class = DocumentHistory)] @@ -75,20 +75,20 @@ impl WasmDocumentHistory { .unchecked_into::() } - /// Returns an `Array` of diff chain `DocumentDiffs`. + /// Returns an `Array` of diff chain `DiffMessages`. /// /// NOTE: clones the data. #[wasm_bindgen(js_name = diffChainData)] - pub fn diff_chain_data(&self) -> ArrayDocumentDiff { + pub fn diff_chain_data(&self) -> ArrayDiffMessage { self .0 .diff_chain_data .iter() .cloned() - .map(WasmDocumentDiff::from) + .map(WasmDiffMessage::from) .map(JsValue::from) .collect::() - .unchecked_into::() + .unchecked_into::() } /// Returns an `Array` of message id strings for "spam" messages on the same index @@ -133,7 +133,7 @@ pub struct IntegrationChainHistory(ChainHistory); #[wasm_bindgen(inspectable)] #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct DiffChainHistory(ChainHistory); +pub struct DiffChainHistory(ChainHistory); #[wasm_bindgen] impl IntegrationChainHistory { @@ -156,20 +156,20 @@ impl IntegrationChainHistory { #[wasm_bindgen] impl DiffChainHistory { - /// Returns an `Array` of the diff chain `DocumentDiffs`. + /// Returns an `Array` of the diff chain `DiffMessages`. /// /// NOTE: this clones the field. #[wasm_bindgen(js_name = chainData)] - pub fn chain_data(&self) -> ArrayDocumentDiff { + pub fn chain_data(&self) -> ArrayDiffMessage { self .0 .chain_data .iter() .cloned() - .map(WasmDocumentDiff::from) + .map(WasmDiffMessage::from) .map(JsValue::from) .collect::() - .unchecked_into::() + .unchecked_into::() } } @@ -215,4 +215,4 @@ macro_rules! impl_wasm_chain_history { } impl_wasm_chain_history!(IntegrationChainHistory, IotaDocument, WasmDocument); -impl_wasm_chain_history!(DiffChainHistory, DocumentDiff, WasmDocumentDiff); +impl_wasm_chain_history!(DiffChainHistory, DiffMessage, WasmDiffMessage); diff --git a/bindings/wasm/src/did/mod.rs b/bindings/wasm/src/did/mod.rs index 3691801aa3..db45984bca 100644 --- a/bindings/wasm/src/did/mod.rs +++ b/bindings/wasm/src/did/mod.rs @@ -3,13 +3,13 @@ pub use self::wasm_did::WasmDID; pub use self::wasm_did_url::WasmDIDUrl; +pub use self::wasm_diff_message::WasmDiffMessage; pub use self::wasm_document::PromiseDocument; pub use self::wasm_document::WasmDocument; -pub use self::wasm_document_diff::WasmDocumentDiff; pub use self::wasm_verification_method::WasmVerificationMethod; mod wasm_did; mod wasm_did_url; +mod wasm_diff_message; mod wasm_document; -mod wasm_document_diff; mod wasm_verification_method; diff --git a/bindings/wasm/src/did/wasm_document_diff.rs b/bindings/wasm/src/did/wasm_diff_message.rs similarity index 87% rename from bindings/wasm/src/did/wasm_document_diff.rs rename to bindings/wasm/src/did/wasm_diff_message.rs index 28ed7665ba..37c2627579 100644 --- a/bindings/wasm/src/did/wasm_document_diff.rs +++ b/bindings/wasm/src/did/wasm_diff_message.rs @@ -4,7 +4,7 @@ use std::ops::Deref; use std::str::FromStr; -use identity::iota::DocumentDiff; +use identity::iota::DiffMessage; use identity::iota::MessageId; use identity::iota::TangleRef; use wasm_bindgen::prelude::*; @@ -15,12 +15,12 @@ use crate::error::Result; use crate::error::WasmResult; /// Defines the difference between two DID `Document`s' JSON representations. -#[wasm_bindgen(js_name = DocumentDiff, inspectable)] +#[wasm_bindgen(js_name = DiffMessage, inspectable)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub struct WasmDocumentDiff(pub(crate) DocumentDiff); +pub struct WasmDiffMessage(pub(crate) DiffMessage); -#[wasm_bindgen(js_class = DocumentDiff)] -impl WasmDocumentDiff { +#[wasm_bindgen(js_class = DiffMessage)] +impl WasmDiffMessage { /// Returns the DID of the associated DID Document. /// /// NOTE: clones the data. @@ -87,14 +87,14 @@ impl WasmDocumentDiff { } } -impl From for WasmDocumentDiff { - fn from(document_diff: DocumentDiff) -> Self { +impl From for WasmDiffMessage { + fn from(document_diff: DiffMessage) -> Self { Self(document_diff) } } -impl Deref for WasmDocumentDiff { - type Target = DocumentDiff; +impl Deref for WasmDiffMessage { + type Target = DiffMessage; fn deref(&self) -> &Self::Target { &self.0 diff --git a/bindings/wasm/src/did/wasm_document.rs b/bindings/wasm/src/did/wasm_document.rs index 93e7c953e8..bcd28ab8cf 100644 --- a/bindings/wasm/src/did/wasm_document.rs +++ b/bindings/wasm/src/did/wasm_document.rs @@ -26,7 +26,7 @@ use crate::credential::VerifiablePresentation; use crate::crypto::KeyPair; use crate::did::wasm_did_url::WasmDIDUrl; use crate::did::WasmDID; -use crate::did::WasmDocumentDiff; +use crate::did::WasmDiffMessage; use crate::did::WasmVerificationMethod; use crate::error::Result; use crate::error::WasmResult; @@ -345,10 +345,10 @@ impl WasmDocument { // Diffs // =========================================================================== - /// Generate a `DocumentDiff` between two DID Documents and sign it using the specified + /// Generate a `DiffMessage` between two DID Documents and sign it using the specified /// `key` and `method`. #[wasm_bindgen] - pub fn diff(&self, other: &WasmDocument, message: &str, key: &KeyPair, method: &str) -> Result { + pub fn diff(&self, other: &WasmDocument, message: &str, key: &KeyPair, method: &str) -> Result { self .0 .diff( @@ -357,7 +357,7 @@ impl WasmDocument { key.0.private(), method, ) - .map(WasmDocumentDiff::from) + .map(WasmDiffMessage::from) .wasm_result() } @@ -368,13 +368,13 @@ impl WasmDocument { /// /// Fails if an unsupported verification method is used or the verification operation fails. #[wasm_bindgen(js_name = verifyDiff)] - pub fn verify_diff(&self, diff: &WasmDocumentDiff) -> Result<()> { + pub fn verify_diff(&self, diff: &WasmDiffMessage) -> Result<()> { self.0.verify_diff(&diff.0).wasm_result() } - /// Verifies a `DocumentDiff` signature and merges the changes into `self`. + /// Verifies a `DiffMessage` signature and merges the changes into `self`. #[wasm_bindgen] - pub fn merge(&mut self, diff: &WasmDocumentDiff) -> Result<()> { + pub fn merge(&mut self, diff: &WasmDiffMessage) -> Result<()> { self.0.merge(&diff.0).wasm_result() } diff --git a/bindings/wasm/src/tangle/client.rs b/bindings/wasm/src/tangle/client.rs index 1a66d2a85d..3268d4e92f 100644 --- a/bindings/wasm/src/tangle/client.rs +++ b/bindings/wasm/src/tangle/client.rs @@ -25,8 +25,8 @@ use crate::chain::PromiseDiffChainHistory; use crate::chain::PromiseDocumentHistory; use crate::chain::WasmDocumentHistory; use crate::did::PromiseDocument; +use crate::did::WasmDiffMessage; use crate::did::WasmDocument; -use crate::did::WasmDocumentDiff; use crate::error::Result; use crate::error::WasmResult; use crate::tangle::Config; @@ -97,9 +97,9 @@ impl Client { Ok(promise.unchecked_into::()) } - /// Publishes a `DocumentDiff` to the Tangle. + /// Publishes a `DiffMessage` to the Tangle. #[wasm_bindgen(js_name = publishDiff)] - pub fn publish_diff(&self, message_id: &str, diff: WasmDocumentDiff) -> Result { + pub fn publish_diff(&self, message_id: &str, diff: WasmDiffMessage) -> Result { let message: MessageId = MessageId::from_str(message_id).wasm_result()?; let client: Rc = self.client.clone(); diff --git a/examples/account/config.rs b/examples/account/config.rs index 3d6b6a0a83..3f1c255740 100644 --- a/examples/account/config.rs +++ b/examples/account/config.rs @@ -27,10 +27,10 @@ async fn main() -> Result<()> { let network_name = "dev"; let network = Network::try_from_name(network_name)?; - // If you deployed an explorer locally this would usually be `http://127.0.0.1:8082/` - let explorer = ExplorerUrl::parse("https://explorer.iota.org/devnet/")?; + // If you deployed an explorer locally this would usually be `http://127.0.0.1:8082` + let explorer = ExplorerUrl::parse("https://explorer.iota.org/devnet")?; - // In a locally running one-click tangle, this would often be `http://127.0.0.1:14265/` + // In a locally running one-click tangle, this would often be `http://127.0.0.1:14265` let private_node_url = "https://api.lb-0.h.chrysalis-devnet.iota.cafe"; // Create a new Account with explicit configuration @@ -65,7 +65,7 @@ async fn main() -> Result<()> { let identity: Account = match builder.create_identity(identity_setup).await { Ok(identity) => identity, Err(err) => { - eprintln!("[Example] Error: {:?} {}", err, err.to_string()); + eprintln!("[Example] Error: {:?}", err); eprintln!("[Example] Is your Tangle node listening on {}?", private_node_url); return Ok(()); } diff --git a/examples/low-level-api/diff_chain.rs b/examples/low-level-api/diff_chain.rs index 239a79d292..88effdd8c7 100644 --- a/examples/low-level-api/diff_chain.rs +++ b/examples/low-level-api/diff_chain.rs @@ -11,7 +11,7 @@ use identity::core::FromJson; use identity::did::Service; use identity::did::DID; use identity::iota::ClientMap; -use identity::iota::DocumentDiff; +use identity::iota::DiffMessage; use identity::iota::ExplorerUrl; use identity::iota::Receipt; use identity::iota::TangleRef; @@ -42,7 +42,7 @@ async fn main() -> Result<()> { }; // Generate a signed diff object. - let diff: DocumentDiff = document.diff( + let diff: DiffMessage = document.diff( &updated_document, *receipt.message_id(), keypair.private(), diff --git a/examples/low-level-api/private_tangle.rs b/examples/low-level-api/private_tangle.rs index 32c78df770..00b61ad1bc 100644 --- a/examples/low-level-api/private_tangle.rs +++ b/examples/low-level-api/private_tangle.rs @@ -30,10 +30,10 @@ pub async fn main() -> Result<()> { let network_name = "dev"; let network = Network::try_from_name(network_name)?; - // If you deployed an explorer locally this would usually be `http://127.0.0.1:8082/` - let explorer = ExplorerUrl::parse("https://explorer.iota.org/devnet/")?; + // If you deployed an explorer locally this would usually be `http://127.0.0.1:8082` + let explorer = ExplorerUrl::parse("https://explorer.iota.org/devnet")?; - // In a locally running one-click tangle, this would often be `http://127.0.0.1:14265/` + // In a locally running one-click tangle, this would often be `http://127.0.0.1:14265` let private_node_url = "https://api.lb-0.h.chrysalis-devnet.iota.cafe"; // Use DIDMessageEncoding::Json instead to publish plaintext messages to the Tangle for debugging. @@ -59,7 +59,7 @@ pub async fn main() -> Result<()> { let receipt: Receipt = match client.publish_document(&document).await { Ok(receipt) => receipt, Err(err) => { - eprintln!("Error > {:?} {}", err, err.to_string()); + eprintln!("Error > {:?}", err); eprintln!("Is your private Tangle node listening on {}?", private_node_url); return Ok(()); } diff --git a/examples/low-level-api/resolve_history.rs b/examples/low-level-api/resolve_history.rs index 7e8aa43321..ee8da134bf 100644 --- a/examples/low-level-api/resolve_history.rs +++ b/examples/low-level-api/resolve_history.rs @@ -15,7 +15,7 @@ use identity::did::Service; use identity::did::DID; use identity::iota::ChainHistory; use identity::iota::Client; -use identity::iota::DocumentDiff; +use identity::iota::DiffMessage; use identity::iota::DocumentHistory; use identity::iota::IotaDocument; use identity::iota::IotaVerificationMethod; @@ -103,7 +103,7 @@ async fn main() -> Result<()> { // // This is the first diff therefore the `previous_message_id` property is // set to the last DID document published. - let diff_1: DocumentDiff = int_doc_1.diff(&diff_doc_1, *int_receipt_1.message_id(), keypair.private(), int_doc_1.default_signing_method()?.id())?; + let diff_1: DiffMessage = int_doc_1.diff(&diff_doc_1, *int_receipt_1.message_id(), keypair.private(), int_doc_1.default_signing_method()?.id())?; // Publish the diff to the Tangle, starting a diff chain. let diff_receipt_1: Receipt = client.publish_diff(int_receipt_1.message_id(), &diff_1).await?; @@ -132,7 +132,7 @@ async fn main() -> Result<()> { // This is the second diff therefore its `previous_message_id` property is // set to the first published diff to extend the diff chain. - let diff_2: DocumentDiff = diff_doc_1.diff(&diff_doc_2, *diff_receipt_1.message_id(), keypair.private(), diff_doc_1.default_signing_method()?.id())?; + let diff_2: DiffMessage = diff_doc_1.diff(&diff_doc_2, *diff_receipt_1.message_id(), keypair.private(), diff_doc_1.default_signing_method()?.id())?; // Publish the diff to the Tangle. // Note that we still use the `message_id` from the last integration chain message here to link // the current diff chain to that point on the integration chain. @@ -208,7 +208,7 @@ async fn main() -> Result<()> { // Fetch the diff chain history of the previous integration chain document. // Old diff chains can be retrieved but they no longer affect DID resolution. let previous_integration_document = &history_2.integration_chain_data[1]; - let previous_diff_history: ChainHistory = client + let previous_diff_history: ChainHistory = client .resolve_diff_history(previous_integration_document) .await?; diff --git a/identity-account/src/account/account.rs b/identity-account/src/account/account.rs index f5645b3eb3..af4b26d2e2 100644 --- a/identity-account/src/account/account.rs +++ b/identity-account/src/account/account.rs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use identity_core::crypto::SetSignature; -use identity_iota::did::DocumentDiff; use identity_iota::did::IotaDID; -use identity_iota::did::IotaDocument; -use identity_iota::did::IotaVerificationMethod; +use identity_iota::document::DiffMessage; +use identity_iota::document::IotaDocument; +use identity_iota::document::IotaVerificationMethod; use identity_iota::tangle::Client; use identity_iota::tangle::ClientMap; use identity_iota::tangle::MessageId; @@ -364,7 +364,7 @@ impl Account { } } - let mut diff: DocumentDiff = DocumentDiff::new(old_doc, new_doc, *previous_message_id)?; + let mut diff: DiffMessage = DiffMessage::new(old_doc, new_doc, *previous_message_id)?; let method: &IotaVerificationMethod = old_state.document().default_signing_method()?; diff --git a/identity-account/src/identity/identity_state.rs b/identity-account/src/identity/identity_state.rs index 95c001c153..a720366683 100644 --- a/identity-account/src/identity/identity_state.rs +++ b/identity-account/src/identity/identity_state.rs @@ -10,7 +10,7 @@ use identity_core::crypto::SetSignature; use identity_did::verification::MethodType; use identity_iota::did::IotaDID; use identity_iota::did::IotaDIDUrl; -use identity_iota::did::IotaDocument; +use identity_iota::document::IotaDocument; use identity_iota::tangle::TangleRef; use crate::crypto::RemoteEd25519; diff --git a/identity-account/src/updates/update.rs b/identity-account/src/updates/update.rs index 6a89100186..8e73e620c1 100644 --- a/identity-account/src/updates/update.rs +++ b/identity-account/src/updates/update.rs @@ -18,8 +18,8 @@ use identity_did::verification::MethodScope; use identity_did::verification::MethodType; use identity_iota::did::IotaDID; use identity_iota::did::IotaDIDUrl; -use identity_iota::did::IotaDocument; -use identity_iota::did::IotaVerificationMethod; +use identity_iota::document::IotaDocument; +use identity_iota::document::IotaVerificationMethod; use identity_iota::tangle::UPDATE_METHOD_TYPES; use crate::account::Account; diff --git a/identity-did/src/did/did_url.rs b/identity-did/src/did/did_url.rs index 4ebd8e9bb9..6fe2df0494 100644 --- a/identity-did/src/did/did_url.rs +++ b/identity-did/src/did/did_url.rs @@ -223,7 +223,7 @@ impl Display for RelativeDIDUrl { impl Debug for RelativeDIDUrl { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - f.write_fmt(format_args!("{}", self.to_string())) + f.write_fmt(format_args!("{}", self)) } } @@ -541,7 +541,7 @@ where T: DID, { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - f.write_fmt(format_args!("{}", self.to_string())) + f.write_fmt(format_args!("{}", self)) } } @@ -550,7 +550,7 @@ where T: DID, { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - f.write_fmt(format_args!("{}{}", self.did.as_str(), self.url.to_string())) + f.write_fmt(format_args!("{}{}", self.did.as_str(), self.url)) } } diff --git a/identity-iota/src/chain/diff_chain.rs b/identity-iota/src/chain/diff_chain.rs index 7fe2d35276..cffc796bc4 100644 --- a/identity-iota/src/chain/diff_chain.rs +++ b/identity-iota/src/chain/diff_chain.rs @@ -7,12 +7,16 @@ use core::fmt::Formatter; use core::fmt::Result as FmtResult; use core::slice::Iter; +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::convert::ToJson; use crate::chain::IntegrationChain; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Error; use crate::error::Result; use crate::tangle::Message; @@ -25,7 +29,7 @@ use crate::tangle::TangleRef; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(transparent)] pub struct DiffChain { - inner: Vec, + inner: Vec, } impl DiffChain { @@ -33,19 +37,19 @@ impl DiffChain { pub fn try_from_messages(integration_chain: &IntegrationChain, messages: &[Message]) -> Result { let did: &IotaDID = integration_chain.current().id(); - let index: MessageIndex = messages + let index: MessageIndex = messages .iter() .flat_map(|message| message.try_extract_diff(did)) .collect(); - debug!("[Diff] Valid Messages = {}/{}", messages.len(), index.len()); + log::debug!("[Diff] Valid Messages = {}/{}", messages.len(), index.len()); Self::try_from_index(integration_chain, index) } /// Constructs a new [`DiffChain`] for the given [`IntegrationChain`] from the given [`MessageIndex`]. - pub fn try_from_index(integration_chain: &IntegrationChain, index: MessageIndex) -> Result { - trace!("[Diff] Message Index = {:#?}", index); + pub fn try_from_index(integration_chain: &IntegrationChain, index: MessageIndex) -> Result { + log::trace!("[Diff] Message Index = {:#?}", index); Self::try_from_index_with_document(integration_chain.current(), index) } @@ -53,7 +57,7 @@ impl DiffChain { /// to validate. pub(in crate::chain) fn try_from_index_with_document( integration_document: &IotaDocument, - mut index: MessageIndex, + mut index: MessageIndex, ) -> Result { if index.is_empty() { return Ok(Self::new()); @@ -95,8 +99,8 @@ impl DiffChain { self.inner.clear(); } - /// Returns an iterator yielding references to [`DocumentDiffs`][DocumentDiff]. - pub fn iter(&self) -> Iter<'_, DocumentDiff> { + /// Returns an iterator yielding references to [`DiffMessages`][DiffMessage]. + pub fn iter(&self) -> Iter<'_, DiffMessage> { self.inner.iter() } @@ -111,7 +115,7 @@ impl DiffChain { /// /// Fails if the diff signature is invalid or the Tangle message /// references within the diff are invalid. - pub fn try_push(&mut self, diff: DocumentDiff, integration_chain: &IntegrationChain) -> Result<()> { + pub fn try_push(&mut self, diff: DiffMessage, integration_chain: &IntegrationChain) -> Result<()> { let document: &IotaDocument = integration_chain.current(); self.try_push_inner(diff, document) } @@ -122,7 +126,7 @@ impl DiffChain { /// /// Fails if the diff signature is invalid or the Tangle message /// references within the diff are invalid. - fn try_push_inner(&mut self, diff: DocumentDiff, document: &IotaDocument) -> Result<()> { + fn try_push_inner(&mut self, diff: DiffMessage, document: &IotaDocument) -> Result<()> { let expected_prev_message_id: &MessageId = self.current_message_id().unwrap_or_else(|| document.message_id()); Self::check_valid_addition(&diff, document, expected_prev_message_id)?; @@ -139,18 +143,18 @@ impl DiffChain { /// # Safety /// /// This function is unsafe because it does not check the validity of - /// the signature or Tangle references of the [`DocumentDiff`]. - pub unsafe fn push_unchecked(&mut self, diff: DocumentDiff) { + /// the signature or Tangle references of the [`DiffMessage`]. + pub unsafe fn push_unchecked(&mut self, diff: DiffMessage) { self.inner.push(diff); } - /// Checks if the [`DocumentDiff`] can be added to the [`DiffChain`]. + /// Checks if the [`DiffMessage`] can be added to the [`DiffChain`]. /// /// # Errors /// - /// Fails if the [`DocumentDiff`] is not a valid addition. + /// Fails if the [`DiffMessage`] is not a valid addition. pub fn check_valid_addition( - diff: &DocumentDiff, + diff: &DiffMessage, document: &IotaDocument, expected_prev_message_id: &MessageId, ) -> Result<()> { @@ -202,7 +206,7 @@ impl Display for DiffChain { } } -impl From for Vec { +impl From for Vec { fn from(diff_chain: DiffChain) -> Self { diff_chain.inner } @@ -221,8 +225,8 @@ mod test { use crate::chain::DocumentChain; use crate::chain::IntegrationChain; - use crate::did::DocumentDiff; - use crate::did::IotaDocument; + use crate::document::DiffMessage; + use crate::document::IotaDocument; use crate::tangle::MessageId; use crate::tangle::TangleRef; @@ -307,7 +311,7 @@ mod test { // Sign using the new key added in the previous integration chain update. let message_id = *chain.diff_message_id(); - let mut diff: DocumentDiff = chain + let mut diff: DiffMessage = chain .current() .diff(&new, message_id, keys[1].private(), "#key-2") .unwrap(); diff --git a/identity-iota/src/chain/document_chain.rs b/identity-iota/src/chain/document_chain.rs index aa34f45ef8..80080d3353 100644 --- a/identity-iota/src/chain/document_chain.rs +++ b/identity-iota/src/chain/document_chain.rs @@ -6,13 +6,16 @@ use core::fmt::Error as FmtError; use core::fmt::Formatter; use core::fmt::Result as FmtResult; +use serde::Deserialize; +use serde::Serialize; + use identity_core::convert::ToJson; use crate::chain::DiffChain; use crate::chain::IntegrationChain; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::MessageId; @@ -136,12 +139,12 @@ impl DocumentChain { Ok(()) } - /// Adds a new [`DocumentDiff`] to the chain. + /// Adds a new [`DiffMessage`] to the chain. /// /// # Errors /// /// Fails if the diff is invalid. - pub fn try_push_diff(&mut self, diff: DocumentDiff) -> Result<()> { + pub fn try_push_diff(&mut self, diff: DiffMessage) -> Result<()> { // Use the last integration chain document to validate the signature on the diff. let integration_document: &IotaDocument = self.chain_i.current(); let expected_prev_message_id: &MessageId = self.diff_message_id(); diff --git a/identity-iota/src/chain/document_history.rs b/identity-iota/src/chain/document_history.rs index 9b931dc61f..c435ba20b3 100644 --- a/identity-iota/src/chain/document_history.rs +++ b/identity-iota/src/chain/document_history.rs @@ -4,11 +4,15 @@ use std::collections::HashSet; use std::ops::Deref; +use serde; +use serde::Deserialize; +use serde::Serialize; + use crate::chain::DiffChain; use crate::chain::IntegrationChain; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::Client; use crate::tangle::Message; @@ -29,7 +33,7 @@ pub struct DocumentHistory { pub integration_chain_spam: Vec, /// List of diffs for the last integration chain document. #[serde(rename = "diffChainData")] - pub diff_chain_data: Vec, + pub diff_chain_data: Vec, /// List of "spam" messages on the diff chain index. #[serde(rename = "diffChainSpam")] pub diff_chain_spam: Vec, @@ -50,7 +54,7 @@ impl DocumentHistory { let integration_chain_history: ChainHistory = ChainHistory::from((integration_chain, integration_messages.deref())); - let diff_chain_history: ChainHistory = ChainHistory::from((diff_chain, diff_messages.deref())); + let diff_chain_history: ChainHistory = ChainHistory::from((diff_chain, diff_messages.deref())); Ok(Self { integration_chain_data: integration_chain_history.chain_data, integration_chain_spam: integration_chain_history.spam, @@ -90,15 +94,15 @@ where } } -impl ChainHistory { - /// Construct a [`ChainHistory`] of [`DocumentDiffs`](DocumentDiff) for an integration chain +impl ChainHistory { + /// Construct a [`ChainHistory`] of [`DiffMessages`](DiffMessage) for an integration chain /// [`IotaDocument`]. /// /// This is useful for constructing histories of old diff chains no longer at the end of an /// integration chain. pub fn try_from_raw_messages(document: &IotaDocument, messages: &[Message]) -> Result { let did: &IotaDID = document.did(); - let index: MessageIndex = messages + let index: MessageIndex = messages .iter() .flat_map(|message| message.try_extract_diff(did)) .collect(); @@ -120,7 +124,7 @@ impl From<(IntegrationChain, &[Message])> for ChainHistory { } /// Construct [`ChainHistory`] from a [`DiffChain`]. -impl From<(DiffChain, &[Message])> for ChainHistory { +impl From<(DiffChain, &[Message])> for ChainHistory { fn from((diff_chain, messages): (DiffChain, &[Message])) -> Self { let chain_data = Vec::from(diff_chain); let spam = ChainHistory::separate_spam(&chain_data, messages); diff --git a/identity-iota/src/chain/integration_chain.rs b/identity-iota/src/chain/integration_chain.rs index e7609db943..5c32217532 100644 --- a/identity-iota/src/chain/integration_chain.rs +++ b/identity-iota/src/chain/integration_chain.rs @@ -7,10 +7,14 @@ use core::fmt::Formatter; use core::fmt::Result as FmtResult; use core::mem; +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::convert::ToJson; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::IotaDocument; use crate::error::Error; use crate::error::Result; use crate::tangle::Message; @@ -39,14 +43,14 @@ impl IntegrationChain { .flat_map(|message| message.try_extract_document(did)) .collect(); - debug!("[Int] Valid Messages = {}/{}", messages.len(), index.len()); + log::debug!("[Int] Valid Messages = {}/{}", messages.len(), index.len()); Self::try_from_index(index) } /// Constructs a new [`IntegrationChain`] from the given [`MessageIndex`]. pub fn try_from_index(mut index: MessageIndex) -> Result { - trace!("[Int] Message Index = {:#?}", index); + log::trace!("[Int] Message Index = {:#?}", index); // Extract root document. let current: IotaDocument = index diff --git a/identity-iota/src/credential/validator.rs b/identity-iota/src/credential/validator.rs index 8d58303cde..413cf818b3 100644 --- a/identity-iota/src/credential/validator.rs +++ b/identity-iota/src/credential/validator.rs @@ -12,7 +12,7 @@ use identity_credential::credential::Credential; use identity_credential::presentation::Presentation; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::IotaDocument; use crate::error::Error; use crate::error::Result; use crate::tangle::Client; diff --git a/identity-iota/src/did/did/mod.rs b/identity-iota/src/did/did/mod.rs deleted file mode 100644 index 6b76d9c092..0000000000 --- a/identity-iota/src/did/did/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2020-2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -mod iota_did; -mod segments; - -pub use self::iota_did::IotaDID; -pub use self::iota_did::IotaDIDUrl; -pub use self::segments::Segments; diff --git a/identity-iota/src/did/did/iota_did.rs b/identity-iota/src/did/iota_did.rs similarity index 99% rename from identity-iota/src/did/did/iota_did.rs rename to identity-iota/src/did/iota_did.rs index a357e0a8d2..60b4a0b2b3 100644 --- a/identity-iota/src/did/did/iota_did.rs +++ b/identity-iota/src/did/iota_did.rs @@ -11,6 +11,9 @@ use std::convert::TryInto; use crypto::hashes::blake2b::Blake2b256; use crypto::hashes::Digest; +use serde; +use serde::Deserialize; +use serde::Serialize; use identity_core::utils::decode_b58; use identity_core::utils::encode_b58; @@ -25,6 +28,7 @@ use crate::error::Error; use crate::error::Result; use crate::tangle::Network; use crate::tangle::NetworkName; +use crate::try_construct_did; // The hash size of BLAKE2b-256 (32-bytes) const BLAKE2B_256_LEN: usize = 32; diff --git a/identity-iota/src/did/mod.rs b/identity-iota/src/did/mod.rs index 3938af8f4b..c206f49d4e 100644 --- a/identity-iota/src/did/mod.rs +++ b/identity-iota/src/did/mod.rs @@ -1,19 +1,10 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -#[macro_use] -mod macros; - -#[allow(clippy::module_inception)] -mod did; -mod doc; +pub use self::iota_did::IotaDID; +pub use self::iota_did::IotaDIDUrl; +pub use self::segments::Segments; -pub use self::did::IotaDID; -pub use self::did::IotaDIDUrl; -pub use self::did::Segments; -pub use self::doc::DocumentDiff; -pub use self::doc::IotaDocument; -pub use self::doc::IotaDocumentSigner; -pub use self::doc::IotaDocumentVerifier; -pub use self::doc::IotaVerificationMethod; -pub use self::doc::Properties; +mod iota_did; +mod macros; +mod segments; diff --git a/identity-iota/src/did/did/segments.rs b/identity-iota/src/did/segments.rs similarity index 100% rename from identity-iota/src/did/did/segments.rs rename to identity-iota/src/did/segments.rs diff --git a/identity-iota/src/did/doc/document_diff.rs b/identity-iota/src/document/diff_message.rs similarity index 89% rename from identity-iota/src/did/doc/document_diff.rs rename to identity-iota/src/document/diff_message.rs index d413918910..2c914dff8f 100644 --- a/identity-iota/src/did/doc/document_diff.rs +++ b/identity-iota/src/document/diff_message.rs @@ -1,6 +1,10 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::convert::FromJson; use identity_core::convert::SerdeInto; use identity_core::convert::ToJson; @@ -15,7 +19,7 @@ use identity_did::verification::MethodUriType; use identity_did::verification::TryMethod; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::MessageId; use crate::tangle::MessageIdExt; @@ -23,7 +27,7 @@ use crate::tangle::TangleRef; /// Defines the difference between two DID [`Document`]s' JSON representations. #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub struct DocumentDiff { +pub struct DiffMessage { pub(crate) did: IotaDID, pub(crate) diff: String, #[serde( @@ -38,8 +42,8 @@ pub struct DocumentDiff { pub(crate) message_id: MessageId, } -impl DocumentDiff { - /// Construct a new `DocumentDiff` by diffing the JSON representations of `current` and `updated`. +impl DiffMessage { + /// Construct a new `DiffMessage` by diffing the JSON representations of `current` and `updated`. /// /// The `previous_message_id` is included verbatim in the output, and the `proof` is `None`. To /// set a proof, use the `set_signature()` method. @@ -88,7 +92,7 @@ impl DocumentDiff { } } -impl TangleRef for DocumentDiff { +impl TangleRef for DiffMessage { fn did(&self) -> &IotaDID { self.id() } @@ -110,24 +114,24 @@ impl TangleRef for DocumentDiff { } } -impl TrySignature for DocumentDiff { +impl TrySignature for DiffMessage { fn signature(&self) -> Option<&Signature> { self.proof.as_ref() } } -impl TrySignatureMut for DocumentDiff { +impl TrySignatureMut for DiffMessage { fn signature_mut(&mut self) -> Option<&mut Signature> { self.proof.as_mut() } } -impl SetSignature for DocumentDiff { +impl SetSignature for DiffMessage { fn set_signature(&mut self, value: Signature) { self.proof = Some(value); } } -impl TryMethod for DocumentDiff { +impl TryMethod for DiffMessage { const TYPE: MethodUriType = MethodUriType::Relative; } diff --git a/identity-iota/src/did/doc/iota_document.rs b/identity-iota/src/document/iota_document.rs similarity index 97% rename from identity-iota/src/did/doc/iota_document.rs rename to identity-iota/src/document/iota_document.rs index 40f6510864..b1cc229780 100644 --- a/identity-iota/src/did/doc/iota_document.rs +++ b/identity-iota/src/document/iota_document.rs @@ -8,7 +8,8 @@ use core::fmt::Display; use core::fmt::Formatter; use core::fmt::Result as FmtResult; -use identity_did::verification::MethodRelationship; +use serde; +use serde::Deserialize; use serde::Serialize; use identity_core::common::Object; @@ -35,17 +36,18 @@ use identity_did::verifiable::DocumentVerifier; use identity_did::verifiable::Properties as VerifiableProperties; use identity_did::verification::MethodQuery; use identity_did::verification::MethodRef; +use identity_did::verification::MethodRelationship; use identity_did::verification::MethodScope; use identity_did::verification::MethodType; use identity_did::verification::MethodUriType; use identity_did::verification::TryMethod; use identity_did::verification::VerificationMethod; -use crate::did::DocumentDiff; use crate::did::IotaDID; use crate::did::IotaDIDUrl; -use crate::did::IotaVerificationMethod; -use crate::did::Properties as BaseProperties; +use crate::document::DiffMessage; +use crate::document::IotaVerificationMethod; +use crate::document::Properties as BaseProperties; use crate::error::Error; use crate::error::Result; use crate::tangle::MessageId; @@ -89,7 +91,7 @@ impl IotaDocument { /// /// ``` /// # use identity_core::crypto::KeyPair; - /// # use identity_iota::did::IotaDocument; + /// # use identity_iota::document::IotaDocument; /// # /// // Create a DID Document from a new Ed25519 keypair. /// let keypair = KeyPair::new_ed25519().unwrap(); @@ -114,7 +116,7 @@ impl IotaDocument { /// /// ``` /// # use identity_core::crypto::KeyPair; - /// # use identity_iota::did::IotaDocument; + /// # use identity_iota::document::IotaDocument; /// # use identity_iota::tangle::Network; /// # /// // Create a new DID Document for the devnet from a new Ed25519 keypair. @@ -201,7 +203,7 @@ impl IotaDocument { // Validate that the document controller (if any) conforms to the IotaDID specification. // This check is required to ensure the correctness of the `IotaDocument::controller()` method // which creates an `IotaDID::new_unchecked_ref()` from the underlying controller. - document.controller().map_or(Ok(()), |c| IotaDID::check_validity(c))?; + document.controller().map_or(Ok(()), IotaDID::check_validity)?; // Validate that the verification methods conform to the IotaDID specification. // This check is required to ensure the correctness of the @@ -376,8 +378,8 @@ impl IotaDocument { /// Returns an iterator over all [`IotaVerificationMethods`][IotaVerificationMethod] in the DID Document. pub fn methods(&self) -> impl Iterator { self.document.methods().map(|m| - // SAFETY: Validity of verification methods checked in `IotaVerificationMethod::check_validity`. - unsafe { IotaVerificationMethod::new_unchecked_ref(m) }) + // SAFETY: Validity of verification methods checked in `IotaVerificationMethod::check_validity`. + unsafe { IotaVerificationMethod::new_unchecked_ref(m) }) } /// Adds a new [`IotaVerificationMethod`] to the document in the given [`MethodScope`]. @@ -640,9 +642,9 @@ impl IotaDocument { // Diffs // =========================================================================== - /// Creates a `DocumentDiff` representing the changes between `self` and `other`. + /// Creates a `DiffMessage` representing the changes between `self` and `other`. /// - /// The returned `DocumentDiff` will have a digital signature created using the + /// The returned `DiffMessage` will have a digital signature created using the /// specified `private_key` and `method_query`. /// /// NOTE: the method must be a capability invocation method. @@ -656,11 +658,11 @@ impl IotaDocument { message_id: MessageId, private_key: &'query PrivateKey, method_query: Q, - ) -> Result + ) -> Result where Q: Into>, { - let mut diff: DocumentDiff = DocumentDiff::new(self, other, message_id)?; + let mut diff: DiffMessage = DiffMessage::new(self, other, message_id)?; // Ensure the signing method has a capability invocation verification relationship. let method_query = method_query.into(); @@ -679,11 +681,11 @@ impl IotaDocument { /// # Errors /// /// Fails if an unsupported verification method is used or the verification operation fails. - pub fn verify_diff(&self, diff: &DocumentDiff) -> Result<()> { + pub fn verify_diff(&self, diff: &DiffMessage) -> Result<()> { self.verify_data_with_scope(diff, MethodScope::capability_invocation()) } - /// Verifies a `DocumentDiff` signature and merges the changes into `self`. + /// Verifies a `DiffMessage` signature and merges the changes into `self`. /// /// If merging fails `self` remains unmodified, otherwise `self` represents /// the merged document state. @@ -693,7 +695,7 @@ impl IotaDocument { /// # Errors /// /// Fails if the merge operation or signature operation fails. - pub fn merge(&mut self, diff: &DocumentDiff) -> Result<()> { + pub fn merge(&mut self, diff: &DiffMessage) -> Result<()> { self.verify_diff(diff)?; *self = diff.merge(self)?; @@ -814,34 +816,17 @@ mod tests { use identity_core::common::Value; use identity_core::convert::FromJson; - use identity_core::convert::SerdeInto; use identity_core::crypto::merkle_key::Sha256; use identity_core::crypto::KeyCollection; - use identity_core::crypto::KeyPair; use identity_core::crypto::KeyType; - use identity_core::crypto::PrivateKey; - use identity_core::crypto::PublicKey; use identity_core::utils::encode_b58; use identity_did::did::CoreDID; - use identity_did::did::CoreDIDUrl; use identity_did::did::DID; - use identity_did::document::CoreDocument; - use identity_did::service::Service; use identity_did::verification::MethodData; - use identity_did::verification::MethodRef; - use identity_did::verification::MethodScope; - use identity_did::verification::MethodType; - use identity_did::verification::VerificationMethod; - - use crate::did::did::IotaDID; - use crate::did::doc::iota_document::Properties; - use crate::did::doc::IotaDocument; - use crate::did::doc::IotaVerificationMethod; - use crate::did::IotaDIDUrl; - use crate::tangle::MessageId; + use crate::tangle::Network; - use crate::tangle::TangleRef; - use crate::Error; + + use super::*; const DID_ID: &str = "did:iota:HGE4tecHWL2YiZv5qAGtH7gaeQcaz2Z1CR15GWmMjY1M"; const DID_METHOD_ID: &str = "did:iota:HGE4tecHWL2YiZv5qAGtH7gaeQcaz2Z1CR15GWmMjY1M#sign-0"; diff --git a/identity-iota/src/did/doc/iota_verification_method.rs b/identity-iota/src/document/iota_verification_method.rs similarity index 99% rename from identity-iota/src/did/doc/iota_verification_method.rs rename to identity-iota/src/document/iota_verification_method.rs index 7e455fa632..0e28c8b64e 100644 --- a/identity-iota/src/did/doc/iota_verification_method.rs +++ b/identity-iota/src/document/iota_verification_method.rs @@ -9,6 +9,10 @@ use core::fmt::Formatter; use core::fmt::Result as FmtResult; use core::ops::Deref; +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::common::BitSet; use identity_core::convert::ToJson; use identity_core::crypto::merkle_key::MerkleDigest; diff --git a/identity-iota/src/did/doc/mod.rs b/identity-iota/src/document/mod.rs similarity index 86% rename from identity-iota/src/did/doc/mod.rs rename to identity-iota/src/document/mod.rs index 86f2134d50..7a8ceae80c 100644 --- a/identity-iota/src/did/doc/mod.rs +++ b/identity-iota/src/document/mod.rs @@ -1,14 +1,14 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod document_diff; -mod iota_document; -mod iota_verification_method; -mod properties; - -pub use self::document_diff::DocumentDiff; +pub use self::diff_message::DiffMessage; pub use self::iota_document::IotaDocument; pub use self::iota_document::IotaDocumentSigner; pub use self::iota_document::IotaDocumentVerifier; pub use self::iota_verification_method::IotaVerificationMethod; pub use self::properties::Properties; + +mod diff_message; +mod iota_document; +mod iota_verification_method; +mod properties; diff --git a/identity-iota/src/did/doc/properties.rs b/identity-iota/src/document/properties.rs similarity index 94% rename from identity-iota/src/did/doc/properties.rs rename to identity-iota/src/document/properties.rs index b753f04423..5a1a34b6ac 100644 --- a/identity-iota/src/did/doc/properties.rs +++ b/identity-iota/src/document/properties.rs @@ -1,6 +1,10 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::common::Object; use identity_core::common::Timestamp; diff --git a/identity-iota/src/lib.rs b/identity-iota/src/lib.rs index 5d146a0308..bdd126aeec 100644 --- a/identity-iota/src/lib.rs +++ b/identity-iota/src/lib.rs @@ -17,22 +17,14 @@ // clippy::missing_errors_doc, )] -#[macro_use] -extern crate lazy_static; - -#[macro_use] -extern crate log; - -#[macro_use] -extern crate serde; +pub use self::error::Error; +pub use self::error::Result; mod resolver; pub mod chain; pub mod credential; pub mod did; +pub mod document; pub mod error; pub mod tangle; - -pub use self::error::Error; -pub use self::error::Result; diff --git a/identity-iota/src/resolver.rs b/identity-iota/src/resolver.rs index 3a5e725261..e0bdc96982 100644 --- a/identity-iota/src/resolver.rs +++ b/identity-iota/src/resolver.rs @@ -12,7 +12,7 @@ use identity_did::resolution::MetaDocument; use identity_did::resolution::ResolverMethod; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::IotaDocument; use crate::tangle::Client; use crate::tangle::ClientMap; use crate::tangle::TangleResolve; diff --git a/identity-iota/src/tangle/client.rs b/identity-iota/src/tangle/client.rs index 86302c5020..758d763ac2 100644 --- a/identity-iota/src/tangle/client.rs +++ b/identity-iota/src/tangle/client.rs @@ -14,9 +14,9 @@ use crate::chain::DiffChain; use crate::chain::DocumentChain; use crate::chain::DocumentHistory; use crate::chain::IntegrationChain; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Error; use crate::error::Result; use crate::tangle::ClientBuilder; @@ -87,11 +87,11 @@ impl Client { .await } - /// Publishes a [`DocumentDiff`] to the Tangle to form part of the diff chain for the integration. + /// Publishes a [`DiffMessage`] to the Tangle to form part of the diff chain for the integration. /// chain message specified by the given [`MessageId`]. /// This method calls `publish_json_with_retry` with its default `interval` and `max_attempts` values for increasing /// the probability that the message will be referenced by a milestone. - pub async fn publish_diff(&self, message_id: &MessageId, diff: &DocumentDiff) -> Result { + pub async fn publish_diff(&self, message_id: &MessageId, diff: &DiffMessage) -> Result { self .publish_json_with_retry(&IotaDocument::diff_index(message_id)?, diff, None, None) .await @@ -154,8 +154,8 @@ impl Client { /// Fetches a [`DocumentChain`] given an [`IotaDID`]. pub async fn read_document_chain(&self, did: &IotaDID) -> Result { - trace!("Read Document Chain: {}", did); - trace!("Integration Chain Address: {}", did.tag()); + log::trace!("Read Document Chain: {}", did); + log::trace!("Integration Chain Address: {}", did.tag()); // Fetch all messages for the integration chain. let messages: Vec = self.read_messages(did.tag()).await?; @@ -172,7 +172,7 @@ impl Client { // let index: String = IotaDocument::diff_index(integration_chain.current_message_id())?; // let messages: Vec = self.read_messages(&index).await?; // - // trace!("Diff Messages: {:#?}", messages); + // log::trace!("Diff Messages: {:#?}", messages); // // DiffChain::try_from_messages(&integration_chain, &messages)? // }; @@ -182,7 +182,7 @@ impl Client { let index: String = IotaDocument::diff_index(integration_chain.current_message_id())?; let messages: Vec = self.read_messages(&index).await?; - trace!("Diff Messages: {:#?}", messages); + log::trace!("Diff Messages: {:#?}", messages); DiffChain::try_from_messages(&integration_chain, &messages)? }; @@ -200,7 +200,7 @@ impl Client { /// /// NOTE: the document must have been published to the Tangle and have a valid message id and /// authentication method. - pub async fn resolve_diff_history(&self, document: &IotaDocument) -> Result> { + pub async fn resolve_diff_history(&self, document: &IotaDocument) -> Result> { let diff_index: String = IotaDocument::diff_index(document.message_id())?; let diff_messages: Vec = self.read_messages(&diff_index).await?; ChainHistory::try_from_raw_messages(document, &diff_messages) diff --git a/identity-iota/src/tangle/client_map.rs b/identity-iota/src/tangle/client_map.rs index 50037734d3..47ea490d63 100644 --- a/identity-iota/src/tangle/client_map.rs +++ b/identity-iota/src/tangle/client_map.rs @@ -6,9 +6,9 @@ use std::sync::Arc; use dashmap::DashMap; use crate::chain::DocumentChain; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::Client; use crate::tangle::ClientBuilder; @@ -61,7 +61,7 @@ impl ClientMap { client.publish_document(document).await } - pub async fn publish_diff(&self, message_id: &MessageId, diff: &DocumentDiff) -> Result { + pub async fn publish_diff(&self, message_id: &MessageId, diff: &DiffMessage) -> Result { let network: Network = diff.id().network()?; let client: Arc = self.client(network).await?; diff --git a/identity-iota/src/tangle/explorer.rs b/identity-iota/src/tangle/explorer.rs index 29deec8966..9f6640b7e5 100644 --- a/identity-iota/src/tangle/explorer.rs +++ b/identity-iota/src/tangle/explorer.rs @@ -6,6 +6,10 @@ use core::fmt::Display; use core::fmt::Formatter; use std::str::FromStr; +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::common::Url; use identity_did::did::DID; @@ -13,7 +17,7 @@ use crate::error::Error; use crate::error::Result; use crate::tangle::MessageId; -lazy_static! { +lazy_static::lazy_static! { static ref EXPLORER_MAIN: ExplorerUrl = ExplorerUrl::new(Url::parse("https://explorer.iota.org/mainnet").unwrap()).unwrap(); static ref EXPLORER_DEV: ExplorerUrl = diff --git a/identity-iota/src/tangle/message/compression_brotli.rs b/identity-iota/src/tangle/message/compression_brotli.rs index 019d5c8bca..20b413d4b0 100644 --- a/identity-iota/src/tangle/message/compression_brotli.rs +++ b/identity-iota/src/tangle/message/compression_brotli.rs @@ -31,7 +31,7 @@ mod test { use identity_core::convert::ToJson; use identity_core::crypto::KeyPair; - use crate::did::IotaDocument; + use crate::document::IotaDocument; use super::*; diff --git a/identity-iota/src/tangle/message/message_ext.rs b/identity-iota/src/tangle/message/message_ext.rs index 9a4528c51d..e5a2bfb54e 100644 --- a/identity-iota/src/tangle/message/message_ext.rs +++ b/identity-iota/src/tangle/message/message_ext.rs @@ -11,9 +11,9 @@ use identity_core::convert::FromJson; use identity_core::convert::ToJson; use identity_did::did::DID; -use crate::did::DocumentDiff; use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::DiffMessage; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::message::compression_brotli; use crate::tangle::DIDMessageEncoding; @@ -131,7 +131,7 @@ impl MessageIdExt for MessageId { pub trait MessageExt { fn try_extract_document(&self, did: &IotaDID) -> Option; - fn try_extract_diff(&self, did: &IotaDID) -> Option; + fn try_extract_diff(&self, did: &IotaDID) -> Option; } impl MessageExt for Message { @@ -139,8 +139,8 @@ impl MessageExt for Message { IotaDocument::try_from_message(self, did) } - fn try_extract_diff(&self, did: &IotaDID) -> Option { - DocumentDiff::try_from_message(self, did) + fn try_extract_diff(&self, did: &IotaDID) -> Option { + DiffMessage::try_from_message(self, did) } } @@ -154,7 +154,7 @@ impl TryFromMessage for IotaDocument { } } -impl TryFromMessage for DocumentDiff { +impl TryFromMessage for DiffMessage { fn try_from_message(message: &Message, did: &IotaDID) -> Option { parse_message(message, did) } @@ -164,7 +164,7 @@ impl TryFromMessage for DocumentDiff { mod test { use identity_core::crypto::KeyPair; - use crate::did::IotaDocument; + use crate::document::IotaDocument; use crate::tangle::message::message_encoding::DIDMessageEncoding; use crate::tangle::MessageId; diff --git a/identity-iota/src/tangle/network.rs b/identity-iota/src/tangle/network.rs index 2459d4cd20..112f04f056 100644 --- a/identity-iota/src/tangle/network.rs +++ b/identity-iota/src/tangle/network.rs @@ -7,6 +7,10 @@ use core::fmt::Formatter; use core::ops::Deref; use std::borrow::Cow; +use serde; +use serde::Deserialize; +use serde::Serialize; + use identity_core::common::Url; use crate::did::IotaDID; @@ -16,7 +20,7 @@ use crate::error::Result; const NETWORK_NAME_MAIN: &str = "main"; const NETWORK_NAME_DEV: &str = "dev"; -lazy_static! { +lazy_static::lazy_static! { static ref NODE_MAIN: Url = Url::parse("https://chrysalis-nodes.iota.org").unwrap(); static ref NODE_DEV: Url = Url::parse("https://api.lb-0.h.chrysalis-devnet.iota.cafe").unwrap(); } diff --git a/identity-iota/src/tangle/publish.rs b/identity-iota/src/tangle/publish.rs index 331524022e..670856b12d 100644 --- a/identity-iota/src/tangle/publish.rs +++ b/identity-iota/src/tangle/publish.rs @@ -5,7 +5,7 @@ use identity_did::verification::MethodRef; use identity_did::verification::MethodType; use identity_did::verification::VerificationMethod; -use crate::did::IotaDocument; +use crate::document::IotaDocument; // Method types allowed to sign a DID document update. pub const UPDATE_METHOD_TYPES: &[MethodType] = &[MethodType::Ed25519VerificationKey2018]; @@ -66,7 +66,7 @@ mod test { use identity_did::did::DID; use identity_did::verification::MethodScope; - use crate::did::IotaVerificationMethod; + use crate::document::IotaVerificationMethod; use crate::tangle::TangleRef; use crate::Result; diff --git a/identity-iota/src/tangle/receipt.rs b/identity-iota/src/tangle/receipt.rs index 8bb04c0ef4..1616a17b2f 100644 --- a/identity-iota/src/tangle/receipt.rs +++ b/identity-iota/src/tangle/receipt.rs @@ -1,6 +1,10 @@ // Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use serde; +use serde::Deserialize; +use serde::Serialize; + use crate::tangle::Message; use crate::tangle::MessageId; use crate::tangle::Network; diff --git a/identity-iota/src/tangle/traits.rs b/identity-iota/src/tangle/traits.rs index 92999aecb2..ea1954cfd4 100644 --- a/identity-iota/src/tangle/traits.rs +++ b/identity-iota/src/tangle/traits.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::did::IotaDID; -use crate::did::IotaDocument; +use crate::document::IotaDocument; use crate::error::Result; use crate::tangle::MessageId; diff --git a/identity/benches/diff_chain.rs b/identity/benches/diff_chain.rs index c519cbb520..19b1903cc4 100644 --- a/identity/benches/diff_chain.rs +++ b/identity/benches/diff_chain.rs @@ -9,8 +9,8 @@ use identity::did::MethodData; use identity::did::MethodRef; use identity::did::MethodType; use identity::did::DID; +use identity::iota::DiffMessage; use identity::iota::DocumentChain; -use identity::iota::DocumentDiff; use identity::iota::IntegrationChain; use identity::iota::IotaDocument; use identity::iota::MessageId; @@ -45,7 +45,7 @@ pub fn update_diff_chain(n: usize, chain: &mut DocumentChain, keypair: &KeyPair) }; let message_id = *chain.diff_message_id(); - let mut diff: DocumentDiff = chain + let mut diff: DiffMessage = chain .current() .diff( &new, diff --git a/identity/src/lib.rs b/identity/src/lib.rs index 767b5f4a03..7c240d2e9d 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -71,6 +71,7 @@ pub mod iota { pub use identity_iota::chain::*; pub use identity_iota::credential::*; pub use identity_iota::did::*; + pub use identity_iota::document::*; pub use identity_iota::error::*; pub use identity_iota::tangle::*; @@ -110,7 +111,7 @@ pub mod prelude { //! Prelude of commonly used types pub use identity_core::crypto::KeyPair; - pub use identity_iota::did::IotaDocument; + pub use identity_iota::document::IotaDocument; pub use identity_iota::tangle::Client; pub use identity_iota::Result; }