From 9c314c44e3e567f4327b63f012b4b8b27f8a8dfe Mon Sep 17 00:00:00 2001 From: umr1352 Date: Mon, 2 Dec 2024 10:43:13 +0100 Subject: [PATCH] fix identity creation lint --- .../iota_identity/sources/identity.move | 70 ++++++++++--------- .../iota_identity/sources/migration.move | 9 ++- .../iota/move_calls/identity/create.rs | 51 ++++---------- 3 files changed, 56 insertions(+), 74 deletions(-) diff --git a/identity_iota_core/packages/iota_identity/sources/identity.move b/identity_iota_core/packages/iota_identity/sources/identity.move index e7da1123c..08e977f34 100644 --- a/identity_iota_core/packages/iota_identity/sources/identity.move +++ b/identity_iota_core/packages/iota_identity/sources/identity.move @@ -63,12 +63,12 @@ module iota_identity::identity { version: u64, } - /// Creates a new DID Document with a single controller. + /// Creates a [`Identity`] with a single controller. public fun new( doc: vector, clock: &Clock, ctx: &mut TxContext - ): Identity { + ): ID { new_with_controller(doc, ctx.sender(), false, clock, ctx) } @@ -79,12 +79,20 @@ module iota_identity::identity { creation_timestamp: u64, clock: &Clock, ctx: &mut TxContext - ): Identity { - let mut identity = new_with_controller(doc, ctx.sender(), false, clock, ctx); - assert!(identity.updated >= creation_timestamp, EInvalidTimestamp); - identity.created = creation_timestamp; + ): ID { + let now = clock.timestamp_ms(); + assert!(now >= creation_timestamp, EInvalidTimestamp); + let identity = Identity { + id: object::new(ctx), + did_doc: multicontroller::new_with_controller(doc, ctx.sender(), false, ctx), + created: creation_timestamp, + updated: now, + version: PACKAGE_VERSION, + }; + let id = object::id(&identity); + transfer::share_object(identity); - identity + id } /// Creates a new `Identity` wrapping DID DOC `doc` and controller by @@ -95,15 +103,19 @@ module iota_identity::identity { can_delegate: bool, clock: &Clock, ctx: &mut TxContext, - ): Identity { + ): ID { let now = clock.timestamp_ms(); - Identity { + let identity = Identity { id: object::new(ctx), did_doc: multicontroller::new_with_controller(doc, controller, can_delegate, ctx), created: now, updated: now, version: PACKAGE_VERSION, - } + }; + let id = object::id(&identity); + transfer::share_object(identity); + + id } /// Creates a new DID Document controlled by multiple controllers. @@ -116,19 +128,23 @@ module iota_identity::identity { threshold: u64, clock: &Clock, ctx: &mut TxContext, - ): Identity { + ): ID { assert!(is_did_output(&doc), ENotADidDocument); assert!(threshold >= 1, EInvalidThreshold); assert!(controllers.size() > 0, EInvalidControllersList); let now = clock.timestamp_ms(); - Identity { + let identity = Identity { id: object::new(ctx), did_doc: multicontroller::new_with_controllers(doc, controllers, controllers_that_can_delegate, threshold, ctx), created: now, updated: now, version: PACKAGE_VERSION, - } + }; + let id = object::id(&identity); + + transfer::share_object(identity); + id } /// Returns a reference to the `UID` of an `Identity`. @@ -564,8 +580,7 @@ module iota_identity::identity_tests { // Create a DID document with no funds and 1 controller with a weight of 1 and a threshold of 1. // Share the document and send the controller capability to `controller1`. - let identity = new(b"DID", &clock, scenario.ctx()); - transfer::public_share_object(identity); + let _identity_id = new(b"DID", &clock, scenario.ctx()); scenario.next_tx(controller1); @@ -607,7 +622,7 @@ module iota_identity::identity_tests { controllers.insert(controller3, 1); // Create an identity shared by `controller1`, `controller2`, `controller3`. - let identity = new_with_controllers( + let _identity_id = new_with_controllers( b"DID", controllers, vec_map::empty(), @@ -615,7 +630,6 @@ module iota_identity::identity_tests { &clock, scenario.ctx(), ); - transfer::public_share_object(identity); scenario.next_tx(controller1); @@ -682,7 +696,7 @@ module iota_identity::identity_tests { // === First transaction === // Controller A can execute config changes { - let identity = new_with_controllers( + let _ = new_with_controllers( b"DID", controllers, vec_map::empty(), @@ -690,7 +704,6 @@ module iota_identity::identity_tests { &clock, scenario.ctx(), ); - transfer::public_share_object(identity); scenario.next_tx(controller_a); // Controller A alone should be able to do anything. @@ -718,7 +731,7 @@ module iota_identity::identity_tests { // Controller B alone should not be able to make changes. { - let identity = new_with_controllers( + let _ = new_with_controllers( b"DID", controllers, vec_map::empty(), @@ -726,7 +739,6 @@ module iota_identity::identity_tests { &clock, scenario.ctx(), ); - transfer::public_share_object(identity); scenario.next_tx(controller_a); let mut identity = scenario.take_shared(); @@ -770,7 +782,7 @@ module iota_identity::identity_tests { // === First transaction === // Controller B & C can execute config changes - let identity = new_with_controllers( + let _ = new_with_controllers( b"DID", controllers, vec_map::empty(), @@ -778,7 +790,6 @@ module iota_identity::identity_tests { &clock, scenario.ctx(), ); - transfer::public_share_object(identity); scenario.next_tx(controller_b); let mut identity = scenario.take_shared(); @@ -820,8 +831,7 @@ module iota_identity::identity_tests { let mut scenario = test_scenario::begin(controller_a); let clock = clock::create_for_testing(scenario.ctx()); - let first_identity = new(b"DID", &clock, scenario.ctx()); - transfer::public_share_object(first_identity); + let _ = new(b"DID", &clock, scenario.ctx()); scenario.next_tx(controller_a); let first_identity = scenario.take_shared(); @@ -830,7 +840,7 @@ module iota_identity::identity_tests { controllers.insert(first_identity.to_address(), 10); // Create a second identity. - let second_identity = new_with_controllers( + let _ = new_with_controllers( b"DID", controllers, vec_map::empty(), @@ -839,8 +849,6 @@ module iota_identity::identity_tests { scenario.ctx(), ); - transfer::public_share_object(second_identity); - scenario.next_tx(first_identity.to_address()); let mut first_identity_cap = scenario.take_from_address(first_identity.to_address()); let (token, borrow) = first_identity_cap.borrow(); @@ -874,8 +882,7 @@ module iota_identity::identity_tests { let mut scenario = test_scenario::begin(controller); let clock = clock::create_for_testing(scenario.ctx()); - let identity = new(b"DID", &clock, scenario.ctx()); - transfer::public_share_object(identity); + let _ = new(b"DID", &clock, scenario.ctx()); scenario.next_tx(controller); @@ -907,8 +914,7 @@ module iota_identity::identity_tests { controllers.insert(controller_a, 1); controllers.insert(controller_b, 1); - let identity = new_with_controllers(b"DID", controllers, vec_map::empty(), 2, &clock, scenario.ctx()); - transfer::public_share_object(identity); + let _ = new_with_controllers(b"DID", controllers, vec_map::empty(), 2, &clock, scenario.ctx()); scenario.next_tx(controller_a); diff --git a/identity_iota_core/packages/iota_identity/sources/migration.move b/identity_iota_core/packages/iota_identity/sources/migration.move index 01b839ed7..b103940ba 100644 --- a/identity_iota_core/packages/iota_identity/sources/migration.move +++ b/identity_iota_core/packages/iota_identity/sources/migration.move @@ -8,6 +8,7 @@ module iota_identity::migration { const ENotADidOutput: u64 = 1; + #[allow(lint(share_owned))] public fun migrate_alias( alias: Alias, migration_registry: &mut MigrationRegistry, @@ -24,19 +25,17 @@ module iota_identity::migration { // Check if `state_metadata` contains a DID document. assert!(state_metadata.is_some() && identity::is_did_output(state_metadata.borrow()), ENotADidOutput); - let identity = identity::new_with_creation_timestamp( + let identity_id = identity::new_with_creation_timestamp( state_metadata.extract(), creation_timestamp, clock, ctx ); - let identity_addr = identity.id().to_address(); // Add a migration record. - migration_registry.add(alias_id, identity.id().to_inner()); - transfer::public_share_object(identity); + migration_registry.add(alias_id, identity_id); - identity_addr + identity_id.to_address() } /// Creates a new `Identity` from an Iota 1.0 legacy `AliasOutput` containing a DID Document. diff --git a/identity_iota_core/src/rebased/iota/move_calls/identity/create.rs b/identity_iota_core/src/rebased/iota/move_calls/identity/create.rs index 87b247d4f..e14f0875e 100644 --- a/identity_iota_core/src/rebased/iota/move_calls/identity/create.rs +++ b/identity_iota_core/src/rebased/iota/move_calls/identity/create.rs @@ -4,17 +4,12 @@ use iota_sdk::types::base_types::IotaAddress; use iota_sdk::types::base_types::ObjectID; use iota_sdk::types::programmable_transaction_builder::ProgrammableTransactionBuilder; -use iota_sdk::types::transaction::Command; -use iota_sdk::types::transaction::ProgrammableMoveCall; use iota_sdk::types::transaction::ProgrammableTransaction; use iota_sdk::types::TypeTag; use iota_sdk::types::IOTA_FRAMEWORK_PACKAGE_ID; use move_core_types::ident_str; use crate::rebased::iota::move_calls::utils; -use crate::rebased::migration::OnChainIdentity; - -use crate::rebased::utils::MoveType; use crate::rebased::Error; /// Build a transaction that creates a new on-chain Identity containing `did_doc`. @@ -24,22 +19,13 @@ pub(crate) fn new(did_doc: &[u8], package_id: ObjectID) -> Result