From 7d44ceb087919382aefc778bce57d1b05eff497f Mon Sep 17 00:00:00 2001 From: Yasir Date: Wed, 27 Nov 2024 08:36:44 +0300 Subject: [PATCH] docs: add missing documentation comments and improve code readability --- examples/0_basic/5_create_vc.rs | 3 +-- examples/0_basic/6_create_vp.rs | 6 ++---- examples/0_basic/7_revoke_vc.rs | 3 +-- examples/1_advanced/4_identity_history.rs | 4 ++-- examples/1_advanced/7_sd_jwt.rs | 6 ++---- examples/1_advanced/8_status_list_2021.rs | 3 +-- identity_iota/src/lib.rs | 4 ++-- identity_iota_core/Cargo.toml | 5 +++-- identity_iota_core/src/document/iota_document.rs | 15 +++++++-------- identity_iota_core/src/lib.rs | 1 + .../src/rebased/assets/public_available_vc.rs | 8 ++++++++ .../src/rebased/client/full_client.rs | 9 +++++++++ .../src/rebased/client/read_only.rs | 5 +++++ .../src/rebased/migration/identity.rs | 9 +++++---- .../src/rebased/migration/registry.rs | 12 +++++++----- identity_iota_core/src/rebased/mod.rs | 6 ++++++ .../src/rebased/proposals/borrow.rs | 1 + .../src/rebased/proposals/config_change.rs | 1 + .../src/rebased/proposals/deactivate_did.rs | 1 + identity_iota_core/src/rebased/proposals/mod.rs | 10 ++++++++++ .../src/rebased/proposals/update_did_doc.rs | 1 + .../sui/move_calls/identity/borrow_asset.rs | 2 +- .../src/rebased/sui/move_calls/identity/create.rs | 10 ++++++++-- .../rebased/sui/move_calls/identity/proposal.rs | 2 +- .../src/rebased/sui/move_calls/identity/update.rs | 4 ++-- .../src/rebased/sui/move_calls/utils.rs | 8 ++++++-- identity_iota_core/src/rebased/utils.rs | 6 ++++++ identity_iota_core/tests/e2e/common.rs | 14 ++++++++------ identity_iota_core/tests/e2e/identity.rs | 1 - identity_resolver/src/resolution/resolver.rs | 6 ++++-- 30 files changed, 112 insertions(+), 54 deletions(-) diff --git a/examples/0_basic/5_create_vc.rs b/examples/0_basic/5_create_vc.rs index 3f15effd7..e6ed4610a 100644 --- a/examples/0_basic/5_create_vc.rs +++ b/examples/0_basic/5_create_vc.rs @@ -36,8 +36,7 @@ async fn main() -> anyhow::Result<()> { // create new issuer account with did document let issuer_storage = get_memstorage()?; let issuer_identity_client = get_client_and_create_account(&issuer_storage).await?; - let (issuer_document, issuer_vm_fragment) = - create_did_document(&issuer_identity_client, &issuer_storage).await?; + let (issuer_document, issuer_vm_fragment) = create_did_document(&issuer_identity_client, &issuer_storage).await?; // create new holder account with did document let holder_storage = get_memstorage()?; diff --git a/examples/0_basic/6_create_vp.rs b/examples/0_basic/6_create_vp.rs index db4d73be3..916d63e99 100644 --- a/examples/0_basic/6_create_vp.rs +++ b/examples/0_basic/6_create_vp.rs @@ -54,14 +54,12 @@ async fn main() -> anyhow::Result<()> { // create new issuer account with did document let issuer_storage = get_memstorage()?; let issuer_identity_client = get_client_and_create_account(&issuer_storage).await?; - let (issuer_document, issuer_vm_fragment) = - create_did_document(&issuer_identity_client, &issuer_storage).await?; + let (issuer_document, issuer_vm_fragment) = create_did_document(&issuer_identity_client, &issuer_storage).await?; // create new holder account with did document let holder_storage = get_memstorage()?; let holder_identity_client = get_client_and_create_account(&holder_storage).await?; - let (holder_document, holder_vm_fragment) = - create_did_document(&holder_identity_client, &holder_storage).await?; + let (holder_document, holder_vm_fragment) = create_did_document(&holder_identity_client, &holder_storage).await?; // create new client for verifier // new client actually not necessary, but shows, that client is independent from issuer and holder diff --git a/examples/0_basic/7_revoke_vc.rs b/examples/0_basic/7_revoke_vc.rs index c9d8c3132..c713f70ca 100644 --- a/examples/0_basic/7_revoke_vc.rs +++ b/examples/0_basic/7_revoke_vc.rs @@ -52,8 +52,7 @@ async fn main() -> anyhow::Result<()> { // create new issuer account with did document let issuer_storage = get_memstorage()?; let issuer_identity_client = get_client_and_create_account(&issuer_storage).await?; - let (mut issuer_document, issuer_vm_fragment) = - create_did_document(&issuer_identity_client, &issuer_storage).await?; + let (mut issuer_document, issuer_vm_fragment) = create_did_document(&issuer_identity_client, &issuer_storage).await?; // create new holder account with did document let holder_storage = get_memstorage()?; diff --git a/examples/1_advanced/4_identity_history.rs b/examples/1_advanced/4_identity_history.rs index f94649838..19f8ae3fd 100644 --- a/examples/1_advanced/4_identity_history.rs +++ b/examples/1_advanced/4_identity_history.rs @@ -73,8 +73,8 @@ async fn main() -> anyhow::Result<()> { .into_iter() .map(|data| IotaDocument::unpack_from_iota_object_data(&did, &data, true)) .collect::>()?; - println!("Current version: {}", documents[0].to_string()); - println!("Previous version: {}", documents[1].to_string()); + println!("Current version: {}", documents[0]); + println!("Previous version: {}", documents[1]); // Depending on your use case, you can also page through the results // Alternative Step 2 - Page by looping until no result is returned (here with page size 1) diff --git a/examples/1_advanced/7_sd_jwt.rs b/examples/1_advanced/7_sd_jwt.rs index 0e8bbe446..6ced57c84 100644 --- a/examples/1_advanced/7_sd_jwt.rs +++ b/examples/1_advanced/7_sd_jwt.rs @@ -43,14 +43,12 @@ async fn main() -> anyhow::Result<()> { // Create an identity for the issuer with one verification method `key-1`. let issuer_storage = get_memstorage()?; let issuer_identity_client = get_client_and_create_account(&issuer_storage).await?; - let (issuer_document, issuer_vm_fragment) = - create_did_document(&issuer_identity_client, &issuer_storage).await?; + let (issuer_document, issuer_vm_fragment) = create_did_document(&issuer_identity_client, &issuer_storage).await?; // Create an identity for the holder, in this case also the subject. let holder_storage = get_memstorage()?; let holder_identity_client = get_client_and_create_account(&holder_storage).await?; - let (holder_document, holder_vm_fragment) = - create_did_document(&holder_identity_client, &holder_storage).await?; + let (holder_document, holder_vm_fragment) = create_did_document(&holder_identity_client, &holder_storage).await?; // =========================================================================== // Step 2: Issuer creates and signs a selectively disclosable JWT verifiable credential. diff --git a/examples/1_advanced/8_status_list_2021.rs b/examples/1_advanced/8_status_list_2021.rs index b0137ea48..3a87cb24d 100644 --- a/examples/1_advanced/8_status_list_2021.rs +++ b/examples/1_advanced/8_status_list_2021.rs @@ -41,8 +41,7 @@ async fn main() -> anyhow::Result<()> { // create new issuer account with did document let issuer_storage = get_memstorage()?; let issuer_identity_client = get_client_and_create_account(&issuer_storage).await?; - let (issuer_document, issuer_vm_fragment) = - create_did_document(&issuer_identity_client, &issuer_storage).await?; + let (issuer_document, issuer_vm_fragment) = create_did_document(&issuer_identity_client, &issuer_storage).await?; // create new holder account with did document let holder_storage = get_memstorage()?; diff --git a/identity_iota/src/lib.rs b/identity_iota/src/lib.rs index 2550b981d..12a5d9dc4 100644 --- a/identity_iota/src/lib.rs +++ b/identity_iota/src/lib.rs @@ -75,8 +75,8 @@ pub mod prelude { pub use identity_iota_core::IotaDID; pub use identity_iota_core::IotaDocument; - #[cfg(feature = "client")] - #[cfg_attr(docsrs, doc(cfg(feature = "client")))] + #[cfg(feature = "resolver")] + #[cfg_attr(docsrs, doc(cfg(feature = "resolver")))] pub use identity_iota_core::DidResolutionHandler; #[cfg(feature = "resolver")] diff --git a/identity_iota_core/Cargo.toml b/identity_iota_core/Cargo.toml index abc09cf2a..2023c6ad5 100644 --- a/identity_iota_core/Cargo.toml +++ b/identity_iota_core/Cargo.toml @@ -41,7 +41,7 @@ iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk itertools = { version = "0.13.0", optional = true } move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", rev = "39c83ddcf07894cdee2abd146381d8704205e6e9", optional = true } rand = { version = "0.8.5", optional = true } -secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", branch = "main", optional = true } +secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", tag = "v0.1.0", optional = true } serde-aux = { version = "4.5.0", optional = true } shared-crypto = { git = "https://github.com/iotaledger/iota.git", package = "shared-crypto", rev = "39c83ddcf07894cdee2abd146381d8704205e6e9", optional = true } tokio = { version = "1.29.0", default-features = false, optional = true, features = ["macros", "sync", "rt", "process"] } @@ -51,9 +51,10 @@ iota-crypto = { version = "0.23", default-features = false, features = ["bip39", proptest = { version = "1.0.0", default-features = false, features = ["std"] } # for feature iota-client tests -identity_iota_core= { path = ".", features = ["iota-client"] } # enable for e2e tests +identity_iota_core = { path = ".", features = ["iota-client"] } # enable for e2e tests identity_storage = { path = "../identity_storage", features = ["send-sync-storage", "storage-signer"] } jsonpath-rust = "0.5.1" +lazy_static = "1.5.0" serial_test = "3.1.1" [package.metadata.docs.rs] diff --git a/identity_iota_core/src/document/iota_document.rs b/identity_iota_core/src/document/iota_document.rs index a4cba80ff..f5b682780 100644 --- a/identity_iota_core/src/document/iota_document.rs +++ b/identity_iota_core/src/document/iota_document.rs @@ -395,7 +395,7 @@ impl IotaDocument { } #[cfg(feature = "iota-client")] -pub mod client_document { +mod client_document { use identity_core::common::Timestamp; use iota_sdk::rpc_types::IotaObjectData; @@ -421,7 +421,7 @@ pub mod client_document { data: &IotaObjectData, allow_empty: bool, ) -> Result { - let unpacked = unpack_identity_data(&did, data).map_err(|_| { + let unpacked = unpack_identity_data(did, data).map_err(|_| { Error::InvalidDoc(identity_document::Error::InvalidDocument( "could not unpack identity data from IotaObjectData", None, @@ -437,7 +437,7 @@ pub mod client_document { } }; let did_doc = - Self::from_iota_document_data(multi_controller.controlled_value(), allow_empty, &did, created, updated)?; + Self::from_iota_document_data(multi_controller.controlled_value(), allow_empty, did, created, updated)?; Ok(did_doc) } @@ -451,7 +451,7 @@ pub mod client_document { /// * document related parsing Errors from `StateMetadataDocument::unpack` /// * possible parsing errors when trying to parse `created` and `updated` to a `Timestamp` pub fn from_iota_document_data( - data: &Vec, + data: &[u8], allow_empty: bool, did: &IotaDID, created: Timestamp, @@ -465,8 +465,7 @@ pub mod client_document { empty_document } else { // we have a value, therefore unpack it - StateMetadataDocument::unpack(data) - .and_then(|state_metadata_doc| state_metadata_doc.into_iota_document(&did))? + StateMetadataDocument::unpack(data).and_then(|state_metadata_doc| state_metadata_doc.into_iota_document(did))? }; // Overwrite `created` and `updated` with given timestamps @@ -732,7 +731,7 @@ mod tests { .parse() .unwrap(); let document = IotaDocument::from_iota_document_data( - &vec![], + &[], true, &did, Timestamp::from_unix(12).unwrap(), @@ -750,7 +749,7 @@ mod tests { // INVALID: reject empty document. assert!(IotaDocument::from_iota_document_data( - &vec![], + &[], false, &did, Timestamp::from_unix(12).unwrap(), diff --git a/identity_iota_core/src/lib.rs b/identity_iota_core/src/lib.rs index 484b44d5a..e076bbb7e 100644 --- a/identity_iota_core/src/lib.rs +++ b/identity_iota_core/src/lib.rs @@ -31,5 +31,6 @@ mod document; mod error; mod network; #[cfg(feature = "iota-client")] +/// Contains the rebased Identity and the interaction with the IOTA Client. pub mod rebased; mod state_metadata; diff --git a/identity_iota_core/src/rebased/assets/public_available_vc.rs b/identity_iota_core/src/rebased/assets/public_available_vc.rs index a3812962a..f2cb5c8c4 100644 --- a/identity_iota_core/src/rebased/assets/public_available_vc.rs +++ b/identity_iota_core/src/rebased/assets/public_available_vc.rs @@ -60,6 +60,7 @@ impl MoveType for IotaVerifiableCredential { } } +/// A publicly available verifiable credential. #[derive(Debug, Clone)] pub struct PublicAvailableVC { asset: AuthenticatedAsset, @@ -74,16 +75,22 @@ impl Deref for PublicAvailableVC { } impl PublicAvailableVC { + /// Get the ID of the asset. pub fn object_id(&self) -> ObjectID { self.asset.id() } + /// Get the JWT of the credential. pub fn jwt(&self) -> Jwt { String::from_utf8(self.asset.content().data.clone()) .map(Jwt::new) .expect("JWT is valid UTF8") } + /// Create a new publicly available VC. + /// + /// # Returns + /// A new `PublicAvailableVC`. pub async fn new(jwt: Jwt, gas_budget: Option, client: &IdentityClient) -> Result where S: Signer + Sync, @@ -102,6 +109,7 @@ impl PublicAvailableVC { Ok(Self { credential, asset }) } + /// Get a publicly available VC by its ID. pub async fn get_by_id(id: ObjectID, client: &IdentityClientReadOnly) -> Result { let asset = client .get_object_by_id::>(id) diff --git a/identity_iota_core/src/rebased/client/full_client.rs b/identity_iota_core/src/rebased/client/full_client.rs index 066bac68c..b5014f7c8 100644 --- a/identity_iota_core/src/rebased/client/full_client.rs +++ b/identity_iota_core/src/rebased/client/full_client.rs @@ -47,8 +47,11 @@ use crate::rebased::Error; use super::get_object_id_from_did; use super::IdentityClientReadOnly; +/// A signature which is used to sign transactions. pub struct IotaKeySignature { + /// The public key of the signature. pub public_key: Vec, + /// The signature of the transaction. pub signature: Vec, } @@ -85,11 +88,16 @@ impl From for String { } } +/// A client for interacting with the IOTA network. #[derive(Clone)] pub struct IdentityClient { + /// [`IdentityClientReadOnly`] instance, used for read-only operations. read_client: IdentityClientReadOnly, + /// The address of the client. address: IotaAddress, + /// The public key of the client. public_key: Vec, + /// The signer of the client. signer: S, } @@ -104,6 +112,7 @@ impl IdentityClient where S: Signer + Sync, { + /// Create a new [`IdentityClient`]. pub async fn new(client: IdentityClientReadOnly, signer: S) -> Result { let public_key = signer .public_key() diff --git a/identity_iota_core/src/rebased/client/read_only.rs b/identity_iota_core/src/rebased/client/read_only.rs index 96cb6e800..c9ec75340 100644 --- a/identity_iota_core/src/rebased/client/read_only.rs +++ b/identity_iota_core/src/rebased/client/read_only.rs @@ -300,6 +300,11 @@ async fn resolve_unmigrated(client: &IdentityClientReadOnly, object_id: ObjectID Ok(unmigrated_alias.map(Identity::Legacy)) } +/// Extracts the object ID from the given `IotaDID`. +/// +/// # Arguments +/// +/// * `did` - A reference to the `IotaDID` to be converted. pub fn get_object_id_from_did(did: &IotaDID) -> Result { ObjectID::from_str(did.tag_str()) .map_err(|err| Error::DIDResolutionError(format!("could not parse object id from did {did}; {err}"))) diff --git a/identity_iota_core/src/rebased/migration/identity.rs b/identity_iota_core/src/rebased/migration/identity.rs index b1a09d03a..f617cf160 100644 --- a/identity_iota_core/src/rebased/migration/identity.rs +++ b/identity_iota_core/src/rebased/migration/identity.rs @@ -57,6 +57,9 @@ const MODULE: &str = "identity"; const NAME: &str = "Identity"; const HISTORY_DEFAULT_PAGE_SIZE: usize = 10; +/// The data stored in an on-chain identity. +pub type IdentityData = (UID, Multicontroller>, Timestamp, Timestamp); + /// An on-chain object holding a DID Document. pub enum Identity { /// A legacy IOTA Stardust's Identity. @@ -230,6 +233,7 @@ impl OnChainIdentity { } } +/// Returns the previous version of the given `history_item`. pub fn has_previous_version(history_item: &IotaObjectData) -> Result { if let Some(Owner::Shared { initial_shared_version }) = history_item.owner { Ok(history_item.version != initial_shared_version) @@ -373,10 +377,7 @@ fn is_identity(value: &IotaParsedMoveObject) -> bool { /// # Errors: /// * in case given data for DID is not an object /// * parsing identity data from object fails -pub(crate) fn unpack_identity_data( - did: &IotaDID, - data: &IotaObjectData, -) -> Result>, Timestamp, Timestamp)>, Error> { +pub(crate) fn unpack_identity_data(did: &IotaDID, data: &IotaObjectData) -> Result, Error> { let content = data .clone() .content diff --git a/identity_iota_core/src/rebased/migration/registry.rs b/identity_iota_core/src/rebased/migration/registry.rs index 41b94a543..28cc9a1d7 100644 --- a/identity_iota_core/src/rebased/migration/registry.rs +++ b/identity_iota_core/src/rebased/migration/registry.rs @@ -10,12 +10,16 @@ use crate::rebased::client::IdentityClientReadOnly; use super::get_identity; use super::OnChainIdentity; +/// Errors that can occur during migration registry operations. #[derive(thiserror::Error, Debug)] pub enum Error { + /// An error occurred while interacting with the IOTA Client. #[error(transparent)] - ClientError(anyhow::Error), + Client(anyhow::Error), + /// The MigrationRegistry object was not found. #[error("could not locate MigrationRegistry object: {0}")] NotFound(String), + /// The MigrationRegistry object is malformed. #[error("malformed MigrationRegistry's entry: {0}")] Malformed(String), } @@ -36,7 +40,7 @@ pub async fn lookup( .read_api() .get_dynamic_field_object(iota_client.migration_registry_id(), dynamic_field_name) .await - .map_err(|e| Error::ClientError(e.into()))? + .map_err(|e| Error::Client(e.into()))? .data .map(|data| { data @@ -51,9 +55,7 @@ pub async fn lookup( .transpose()?; if let Some(id) = identity_id { - get_identity(iota_client, id) - .await - .map_err(|e| Error::ClientError(e.into())) + get_identity(iota_client, id).await.map_err(|e| Error::Client(e.into())) } else { Ok(None) } diff --git a/identity_iota_core/src/rebased/mod.rs b/identity_iota_core/src/rebased/mod.rs index 334d16e39..7eb41c2a8 100644 --- a/identity_iota_core/src/rebased/mod.rs +++ b/identity_iota_core/src/rebased/mod.rs @@ -1,13 +1,19 @@ // Copyright 2020-2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +/// Module for handling assets. pub mod assets; +/// Module for handling client operations. pub mod client; mod error; +/// Module for handling migration operations. pub mod migration; +/// Contains the operations of proposals. pub mod proposals; mod sui; +/// Module for handling transactions. pub mod transaction; +/// Contains utility functions. pub mod utils; pub use assets::*; diff --git a/identity_iota_core/src/rebased/proposals/borrow.rs b/identity_iota_core/src/rebased/proposals/borrow.rs index d14292e2b..341fa0dcc 100644 --- a/identity_iota_core/src/rebased/proposals/borrow.rs +++ b/identity_iota_core/src/rebased/proposals/borrow.rs @@ -147,6 +147,7 @@ impl ProposalT for Proposal { } } +/// A transaction to execute a borrow proposal. pub struct ExecuteBorrowTx<'i, B> { identity: &'i mut OnChainIdentity, borrow_action: B, diff --git a/identity_iota_core/src/rebased/proposals/config_change.rs b/identity_iota_core/src/rebased/proposals/config_change.rs index 891eef86f..cec2bc10c 100644 --- a/identity_iota_core/src/rebased/proposals/config_change.rs +++ b/identity_iota_core/src/rebased/proposals/config_change.rs @@ -91,6 +91,7 @@ impl<'i> ProposalBuilder<'i, ConfigChange> { } impl ConfigChange { + /// Creates a new [`ConfigChange`] proposal action. pub fn new() -> Self { Self::default() } diff --git a/identity_iota_core/src/rebased/proposals/deactivate_did.rs b/identity_iota_core/src/rebased/proposals/deactivate_did.rs index cfca0b901..71b879f1d 100644 --- a/identity_iota_core/src/rebased/proposals/deactivate_did.rs +++ b/identity_iota_core/src/rebased/proposals/deactivate_did.rs @@ -28,6 +28,7 @@ use super::ProposalT; pub struct DeactivateDid; impl DeactivateDid { + /// Creates a new [`DeactivateDid`] action. pub const fn new() -> Self { Self } diff --git a/identity_iota_core/src/rebased/proposals/mod.rs b/identity_iota_core/src/rebased/proposals/mod.rs index 766d575b8..ac8c8489f 100644 --- a/identity_iota_core/src/rebased/proposals/mod.rs +++ b/identity_iota_core/src/rebased/proposals/mod.rs @@ -48,8 +48,10 @@ use crate::rebased::Error; pub trait ProposalT { /// The [`Proposal`] action's type. type Action; + /// The output of the [`Proposal`] type Output; + /// Creates a new [`Proposal`] with the provided action and expiration. async fn create<'i, S>( action: Self::Action, expiration: Option, @@ -59,6 +61,7 @@ pub trait ProposalT { where S: Signer + Sync; + /// Converts the [`Proposal`] into a transaction that can be executed. async fn into_tx<'i, S>( self, identity: &'i mut OnChainIdentity, @@ -67,10 +70,12 @@ pub trait ProposalT { where S: Signer + Sync; + /// Parses the transaction's effects and returns the output of the [`Proposal`]. fn parse_tx_effects(tx_response: &IotaTransactionBlockResponse) -> Result; } impl Proposal { + /// Creates a new [`ApproveProposalTx`] for the provided [`Proposal`] pub fn approve<'i>(&mut self, identity: &'i OnChainIdentity) -> ApproveProposalTx<'_, 'i, A> { ApproveProposalTx { proposal: self, @@ -79,6 +84,7 @@ impl Proposal { } } +/// A builder for creating a [`Proposal`]. #[derive(Debug)] pub struct ProposalBuilder<'i, A> { identity: &'i mut OnChainIdentity, @@ -108,6 +114,7 @@ impl<'i, A> ProposalBuilder<'i, A> { } } + /// Sets the expiration epoch for the [`Proposal`]. pub fn expiration_epoch(mut self, exp: u64) -> Self { self.expiration = Some(exp); self @@ -140,6 +147,7 @@ pub enum ProposalResult { Executed(P::Output), } +/// A transaction to create a [`Proposal`]. #[derive(Debug)] pub struct CreateProposalTx<'i, A> { identity: &'i mut OnChainIdentity, @@ -213,6 +221,7 @@ where } } +/// A transaction to execute a [`Proposal`]. #[derive(Debug)] pub struct ExecuteProposalTx<'i, A> { tx: ProgrammableTransaction, @@ -257,6 +266,7 @@ where } } +/// A transaction to approve a [`Proposal`]. #[derive(Debug)] pub struct ApproveProposalTx<'p, 'i, A> { proposal: &'p mut Proposal, diff --git a/identity_iota_core/src/rebased/proposals/update_did_doc.rs b/identity_iota_core/src/rebased/proposals/update_did_doc.rs index 8d1af3be6..27ffef54a 100644 --- a/identity_iota_core/src/rebased/proposals/update_did_doc.rs +++ b/identity_iota_core/src/rebased/proposals/update_did_doc.rs @@ -38,6 +38,7 @@ impl MoveType for UpdateDidDocument { } impl UpdateDidDocument { + /// Creates a new [`UpdateDidDocument`] action. pub fn new(document: IotaDocument) -> Self { Self(document.pack().expect("a valid IotaDocument is packable")) } diff --git a/identity_iota_core/src/rebased/sui/move_calls/identity/borrow_asset.rs b/identity_iota_core/src/rebased/sui/move_calls/identity/borrow_asset.rs index 95837f3ec..62e1f995a 100644 --- a/identity_iota_core/src/rebased/sui/move_calls/identity/borrow_asset.rs +++ b/identity_iota_core/src/rebased/sui/move_calls/identity/borrow_asset.rs @@ -59,7 +59,7 @@ where let mut ptb = ProgrammableTransactionBuilder::new(); let identity = utils::owned_ref_to_shared_object_arg(identity, &mut ptb, true)?; let controller_cap = ptb.obj(ObjectArg::ImmOrOwnedObject(capability))?; - let (delegation_token, borrow)= utils::get_controller_delegation(&mut ptb, controller_cap, package); + let (delegation_token, borrow) = utils::get_controller_delegation(&mut ptb, controller_cap, package); let proposal_id = ptb.pure(proposal_id)?; // Get the proposal's action as argument. diff --git a/identity_iota_core/src/rebased/sui/move_calls/identity/create.rs b/identity_iota_core/src/rebased/sui/move_calls/identity/create.rs index f36ce0b83..036be6e0b 100644 --- a/identity_iota_core/src/rebased/sui/move_calls/identity/create.rs +++ b/identity_iota_core/src/rebased/sui/move_calls/identity/create.rs @@ -67,7 +67,7 @@ where vec![ids, vps], ) }; - + let controllers_that_can_delegate = ptb.programmable_move_call( IOTA_FRAMEWORK_PACKAGE_ID, ident_str!("vec_map").into(), @@ -85,7 +85,13 @@ where module: ident_str!("identity").into(), function: ident_str!("new_with_controllers").into(), type_arguments: vec![], - arguments: vec![doc_arg, controllers, controllers_that_can_delegate, threshold_arg, clock], + arguments: vec![ + doc_arg, + controllers, + controllers_that_can_delegate, + threshold_arg, + clock, + ], }))); // Share the resulting identity. diff --git a/identity_iota_core/src/rebased/sui/move_calls/identity/proposal.rs b/identity_iota_core/src/rebased/sui/move_calls/identity/proposal.rs index bb04d73a1..7a56dbde0 100644 --- a/identity_iota_core/src/rebased/sui/move_calls/identity/proposal.rs +++ b/identity_iota_core/src/rebased/sui/move_calls/identity/proposal.rs @@ -24,7 +24,7 @@ pub(crate) fn approve( let controller_cap = ptb .obj(ObjectArg::ImmOrOwnedObject(controller_cap)) .map_err(|e| Error::InvalidArgument(e.to_string()))?; - let (delegation_token, borrow) = utils::get_controller_delegation(&mut ptb, controller_cap, package); + let (delegation_token, borrow) = utils::get_controller_delegation(&mut ptb, controller_cap, package); let proposal_id = ptb .pure(proposal_id) .map_err(|e| Error::InvalidArgument(e.to_string()))?; diff --git a/identity_iota_core/src/rebased/sui/move_calls/identity/update.rs b/identity_iota_core/src/rebased/sui/move_calls/identity/update.rs index 9ec751425..34603d54b 100644 --- a/identity_iota_core/src/rebased/sui/move_calls/identity/update.rs +++ b/identity_iota_core/src/rebased/sui/move_calls/identity/update.rs @@ -20,7 +20,7 @@ pub(crate) fn propose_update( ) -> Result { let mut ptb = ProgrammableTransactionBuilder::new(); let cap_arg = ptb.obj(ObjectArg::ImmOrOwnedObject(capability))?; - let (delegation_token , borrow) = utils::get_controller_delegation(&mut ptb, cap_arg, package_id); + let (delegation_token, borrow) = utils::get_controller_delegation(&mut ptb, cap_arg, package_id); let identity_arg = utils::owned_ref_to_shared_object_arg(identity, &mut ptb, true)?; let exp_arg = utils::option_to_move(expiration, &mut ptb, package_id)?; let doc_arg = ptb.pure(did_doc.as_ref())?; @@ -47,7 +47,7 @@ pub(crate) fn execute_update( ) -> Result { let mut ptb = ProgrammableTransactionBuilder::new(); let cap_arg = ptb.obj(ObjectArg::ImmOrOwnedObject(capability))?; - let (delegation_token, borrow)= utils::get_controller_delegation(&mut ptb, cap_arg, package_id); + let (delegation_token, borrow) = utils::get_controller_delegation(&mut ptb, cap_arg, package_id); let proposal_id = ptb.pure(proposal_id)?; let identity_arg = utils::owned_ref_to_shared_object_arg(identity, &mut ptb, true)?; let clock = utils::get_clock_ref(&mut ptb); diff --git a/identity_iota_core/src/rebased/sui/move_calls/utils.rs b/identity_iota_core/src/rebased/sui/move_calls/utils.rs index bb8b66525..0a1d380dc 100644 --- a/identity_iota_core/src/rebased/sui/move_calls/utils.rs +++ b/identity_iota_core/src/rebased/sui/move_calls/utils.rs @@ -27,7 +27,11 @@ pub(crate) fn get_clock_ref(ptb: &mut Ptb) -> Argument { .expect("network has a singleton clock instantiated") } -pub(crate) fn get_controller_delegation(ptb: &mut Ptb, controller_cap: Argument, package: ObjectID) -> (Argument, Argument) { +pub(crate) fn get_controller_delegation( + ptb: &mut Ptb, + controller_cap: Argument, + package: ObjectID, +) -> (Argument, Argument) { let Argument::Result(idx) = ptb.programmable_move_call( package, ident_str!("controller").into(), @@ -53,7 +57,7 @@ pub(crate) fn put_back_delegation_token( ident_str!("controller").into(), ident_str!("put_back").into(), vec![], - vec![controller_cap, delegation_token, borrow] + vec![controller_cap, delegation_token, borrow], ); } diff --git a/identity_iota_core/src/rebased/utils.rs b/identity_iota_core/src/rebased/utils.rs index 57c1dce43..32cf1902b 100644 --- a/identity_iota_core/src/rebased/utils.rs +++ b/identity_iota_core/src/rebased/utils.rs @@ -15,8 +15,10 @@ use iota_sdk::IotaClientBuilder; use crate::rebased::Error; +/// The local `IOTA` network. pub const LOCAL_NETWORK: &str = "http://127.0.0.1:9000"; +/// Builds an `IOTA` client for the given network. pub async fn get_client(network: &str) -> Result { let client = IotaClientBuilder::default() .build(network) @@ -26,6 +28,7 @@ pub async fn get_client(network: &str) -> Result { Ok(client) } +/// Requests funds from the local `IOTA` faucet. pub async fn request_funds(address: &IotaAddress) -> anyhow::Result<()> { let output = Command::new("iota") .arg("client") @@ -49,9 +52,12 @@ pub async fn request_funds(address: &IotaAddress) -> anyhow::Result<()> { Ok(()) } +/// Trait for types that can be converted to a Move type. pub trait MoveType: Serialize { + /// Returns the Move type for this type. fn move_type(package: ObjectID) -> TypeTag; + /// Tries to convert this type to a Move argument. fn try_to_argument( &self, ptb: &mut ProgrammableTransactionBuilder, diff --git a/identity_iota_core/tests/e2e/common.rs b/identity_iota_core/tests/e2e/common.rs index de724abac..1a4fad984 100644 --- a/identity_iota_core/tests/e2e/common.rs +++ b/identity_iota_core/tests/e2e/common.rs @@ -2,11 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 #![allow(dead_code)] -use std::io::Write; -use std::ops::Deref; -use std::sync::Arc; -use std::sync::LazyLock; - use anyhow::anyhow; use anyhow::Context; use identity_iota_core::rebased::client::IdentityClient; @@ -36,10 +31,14 @@ use iota_sdk::types::IOTA_FRAMEWORK_PACKAGE_ID; use iota_sdk::IotaClient; use iota_sdk::IotaClientBuilder; use jsonpath_rust::JsonPathQuery; +use lazy_static::lazy_static; use move_core_types::ident_str; use move_core_types::language_storage::StructTag; use secret_storage::Signer; use serde_json::Value; +use std::io::Write; +use std::ops::Deref; +use std::sync::Arc; use tokio::process::Command; use tokio::sync::OnceCell; @@ -69,7 +68,10 @@ pub const TEST_DOC: &[u8] = &[ 50, 50, 84, 49, 50, 58, 49, 52, 58, 51, 50, 90, 34, 44, 34, 117, 112, 100, 97, 116, 101, 100, 34, 58, 34, 50, 48, 50, 52, 45, 48, 53, 45, 50, 50, 84, 49, 50, 58, 49, 52, 58, 51, 50, 90, 34, 125, 125, ]; -pub static TEST_COIN_TYPE: LazyLock = LazyLock::new(|| "0x2::coin::Coin".parse().unwrap()); + +lazy_static! { + pub static ref TEST_COIN_TYPE: StructTag = "0x2::coin::Coin".parse().unwrap(); +} pub async fn get_client() -> anyhow::Result { let client = IotaClientBuilder::default().build_localnet().await?; diff --git a/identity_iota_core/tests/e2e/identity.rs b/identity_iota_core/tests/e2e/identity.rs index 7dde485e1..6317f0651 100644 --- a/identity_iota_core/tests/e2e/identity.rs +++ b/identity_iota_core/tests/e2e/identity.rs @@ -204,7 +204,6 @@ async fn can_get_historical_identity_data() -> anyhow::Result<()> { }; let history = updated_identity.get_history(&identity_client, None, None).await?; - let versions: Vec = history.iter().map(|elem| elem.version).collect(); // test check for previous version let has_previous_version_responses: Vec = history diff --git a/identity_resolver/src/resolution/resolver.rs b/identity_resolver/src/resolution/resolver.rs index cd19343e4..50ca40b2e 100644 --- a/identity_resolver/src/resolution/resolver.rs +++ b/identity_resolver/src/resolution/resolver.rs @@ -20,7 +20,7 @@ use super::commands::Command; use super::commands::SendSyncCommand; use super::commands::SingleThreadedCommand; -/// Convenience type for resolving DID documents from different DID methods. +/// Convenience type for resolving DID documents from different DID methods. /// /// # Configuration /// @@ -394,7 +394,9 @@ mod tests { if self.0.id().as_str() == did.as_str() { Ok(self.0.clone()) } else { - Err(identity_iota_core::Error::DIDResolutionError("DID not found".to_string())) + Err(identity_iota_core::Error::DIDResolutionError( + "DID not found".to_string(), + )) } } }