-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Borrow an
Identity
's ControllerCap
in order to perform operations…
… on sub-Identities (#1454) * rebase commit * borrow controller cap proposal * e2e test for controller execution * fix merge issues * fix merge
- Loading branch information
Showing
13 changed files
with
546 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
identity_iota_core/packages/iota_identity/sources/proposals/controller.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module iota_identity::controller_proposal { | ||
use iota::transfer::Receiving; | ||
use iota_identity::controller::{Self, ControllerCap}; | ||
use iota_identity::multicontroller::Action; | ||
|
||
/// The received `ControllerCap` does not match the one | ||
/// specified in the `ControllerExecution` action. | ||
const EControllerCapMismatch: u64 = 0; | ||
/// The provided `UID` is not the `UID` of the `Identity` | ||
/// specified in the action. | ||
const EInvalidIdentityUID: u64 = 1; | ||
|
||
/// Borrow a given `ControllerCap` from an `Identity` for | ||
/// a single transaction. | ||
public struct ControllerExecution has store { | ||
/// ID of the `ControllerCap` to borrow. | ||
controller_cap: ID, | ||
/// The address of the `Identity` that owns | ||
/// the `ControllerCap` we are borrowing. | ||
identity: address, | ||
} | ||
|
||
/// Returns a new `ControllerExecution` that - in a Proposal - allows whoever | ||
/// executes it to receive `identity`'s `ControllerCap` (the one that has ID `controller_cap`) | ||
/// for the duration of a single transaction. | ||
public fun new(controller_cap: ID, identity: address): ControllerExecution { | ||
ControllerExecution { | ||
controller_cap, | ||
identity, | ||
} | ||
} | ||
|
||
/// Returns the `ControllerCap` specified in this action. | ||
public fun receive( | ||
self: &mut Action<ControllerExecution>, | ||
identity: &mut UID, | ||
cap: Receiving<ControllerCap> | ||
): ControllerCap { | ||
assert!(identity.to_address() == self.borrow().identity, EInvalidIdentityUID); | ||
assert!(cap.receiving_object_id() == self.borrow().controller_cap, EControllerCapMismatch); | ||
|
||
controller::receive(identity, cap) | ||
} | ||
|
||
/// Consumes a `ControllerExecution` action by returning the borrowed `ControllerCap` | ||
/// to the corresponding `Identity`. | ||
public fun put_back( | ||
action: Action<ControllerExecution>, | ||
cap: ControllerCap, | ||
) { | ||
let ControllerExecution { identity, controller_cap } = action.unwrap(); | ||
assert!(object::id(&cap) == controller_cap, EControllerCapMismatch); | ||
|
||
cap.transfer(identity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.