Skip to content

Commit

Permalink
Refactor the Account state (#462)
Browse files Browse the repository at this point in the history
* Get rid of `IdentitySnapshot`

* Start replacing parts of `IdentityState`

* Create identity document from core structures

* Impl int/diff update determination

* Remove `Deref` impls for IdentityState

* Implement `CreateMethod` update

* Impl attach/detach `MethodRelationship`

* Update to cap inv refactor

* Use `IotaDocument` directly to construct the doc

* Update tests for account updates

* Remove unused types & variables

* Return to unified publish method

* Implement & test attaching relationships

* Fix attach/detach tests post-merge

* Implement detach relationship test

* Implement insert and remove service

* Move `Publish` to low-level API

* Remove did field from account

* Refactor publishing & storing

* Rename int/diff generations

* Change fresh id detection & fix `store_state` call

* Factor out `ChainState` from `IdentityState`

* Remove `this_message_id` from chain state

* Test the chain state

* Fix some error TODOs

* Fix some TODOs

* Fix some storage todos/errors

* Make `IotaDocument::remove_method` fallible again

* Use name instead of identifier to call from_did

* Move state loading into the else clause

* Remove `persist` flag on `process_update`

* Remove unnecessary cloning

* Rename `as_document` -> `document`

* Improve `ChainState` docs

* Fix post-merge things & clippy lint

* Remove `Tiny*` and other unused state types

* `InvalidMethodTarget` -> `InvalidTargetMethod`

* `as_document_mut` -> `document_mut`

* Expand lazy test

* Rename impl_command_builder to update

* Remove event context

* Rename `events` module to `updates`

* Apply fmt

* Rename `commands` -> `updates`

* Remove `UnixTimestamp`

* Remove unused errors in account & update

* Change `fromDID` method in Wasm

* Return `Option<Publish>` from constructor

* Use strum, add todo!(), rename `PublishType`

Co-authored-by: Craig Bester <craig.bester@iota.org>

* Move attach/detach relationship to `CoreDocument`

* Return bool from `detach_method_relationship`

* Use `MethodQuery` in attach/detach

Co-authored-by: Craig Bester <craig.bester@iota.org>

* Revert "Change `fromDID` method in Wasm"

This reverts commit cb0cf35.

* Nest `MethodRelationship` in `MethodScope`

* Move some chain state logic to publish_diff_change

* Don't expect, bubble up

* Return early if there's nothing to publish

* Add todo about error handling

* Remove mut state methods

* Move account constructors to the top

* Use `try_resolve_method_with_scope` in tests

* Remove todos, inline code, explicitly ignore res.

* Remove todo comments, `unwrap`

* Rename chain state fields to `last_*`

* Improve `InvalidTargetMethod` Error name

* Increment actions when updating

* check for updated referenced method in publish

* Enable diff updates for merkle cap. inv. methods

* Only attach relationship on non-embedded methods

* Add proper type annotations in publish

* Improve chain state docs & variable naming

Co-authored-by: Craig Bester <craig.bester@iota.org>
  • Loading branch information
PhilippGackstatter and cycraig authored Nov 17, 2021
1 parent 3b21c93 commit 24de8d8
Show file tree
Hide file tree
Showing 43 changed files with 2,159 additions and 2,265 deletions.
2 changes: 1 addition & 1 deletion bindings/wasm/src/did/wasm_verification_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl WasmVerificationMethod {
/// Creates a new `VerificationMethod` object from the given `did` and `key`.
#[wasm_bindgen(js_name = fromDID)]
pub fn from_did(did: &WasmDID, key: &KeyPair, fragment: String) -> Result<WasmVerificationMethod, JsValue> {
IotaVerificationMethod::from_did(did.0.clone(), &key.0, &fragment)
IotaVerificationMethod::from_did(did.0.clone(), key.0.type_(), key.0.public(), &fragment)
.map_err(wasm_error)
.map(Self)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/account/create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
println!(
"[Example] Local Document from {} = {:#?}",
iota_did,
account.state().await?.to_document()
account.state().document()
);

// Prints the Identity Resolver Explorer URL.
Expand Down
6 changes: 3 additions & 3 deletions examples/account/manipulate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use identity::account::AccountStorage;
use identity::account::IdentitySetup;
use identity::account::Result;
use identity::core::Url;
use identity::did::MethodScope;
use identity::did::MethodRelationship;
use identity::iota::IotaDID;

#[tokio::main]
Expand Down Expand Up @@ -48,8 +48,8 @@ async fn main() -> Result<()> {
.update_identity()
.attach_method()
.fragment("my-next-key")
.scope(MethodScope::CapabilityDelegation)
.scope(MethodScope::CapabilityInvocation)
.relationship(MethodRelationship::CapabilityDelegation)
.relationship(MethodRelationship::CapabilityInvocation)
.apply()
.await?;

Expand Down
3 changes: 2 additions & 1 deletion examples/low-level-api/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ pub async fn add_new_key(

// Add #newKey to the document
let new_key: KeyPair = KeyPair::new_ed25519()?;
let method: IotaVerificationMethod = IotaVerificationMethod::from_did(updated_doc.did().clone(), &new_key, "newKey")?;
let method: IotaVerificationMethod =
IotaVerificationMethod::from_did(updated_doc.did().clone(), new_key.type_(), new_key.public(), "newKey")?;
assert!(updated_doc.insert_method(method, MethodScope::VerificationMethod));

// Prepare the update
Expand Down
3 changes: 2 additions & 1 deletion examples/low-level-api/manipulate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub async fn run() -> Result<(IotaDocument, KeyPair, KeyPair, Receipt, Receipt)>

// Add a new VerificationMethod with a new keypair
let new_key: KeyPair = KeyPair::new_ed25519()?;
let method: IotaVerificationMethod = IotaVerificationMethod::from_did(document.did().clone(), &new_key, "newKey")?;
let method: IotaVerificationMethod =
IotaVerificationMethod::from_did(document.did().clone(), new_key.type_(), new_key.public(), "newKey")?;
assert!(document.insert_method(method, MethodScope::VerificationMethod));

// Add a new Service
Expand Down
4 changes: 2 additions & 2 deletions examples/low-level-api/resolve_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn main() -> Result<()> {

// Add a new VerificationMethod with a new KeyPair, with the tag "keys-1"
let keys_1: KeyPair = KeyPair::new_ed25519()?;
let method_1: IotaVerificationMethod = IotaVerificationMethod::from_did(int_doc_1.id().clone(), &keys_1, "keys-1")?;
let method_1: IotaVerificationMethod = IotaVerificationMethod::from_did(int_doc_1.id().clone(), keys_1.type_(), keys_1.public(), "keys-1")?;
assert!(int_doc_1.insert_method(method_1, MethodScope::VerificationMethod));

// Add the `message_id` of the previous message in the chain.
Expand Down Expand Up @@ -176,7 +176,7 @@ async fn main() -> Result<()> {

// Add a VerificationMethod with a new KeyPair, called "keys-2"
let keys_2: KeyPair = KeyPair::new_ed25519()?;
let method_2: IotaVerificationMethod = IotaVerificationMethod::from_did(int_doc_2.id().clone(), &keys_2, "keys-2")?;
let method_2: IotaVerificationMethod = IotaVerificationMethod::from_did(int_doc_2.id().clone(), keys_2.type_(), keys_2.public(), "keys-2")?;
assert!(int_doc_2.insert_method(method_2, MethodScope::VerificationMethod));

// Note: the `previous_message_id` points to the `message_id` of the last integration chain
Expand Down
3 changes: 2 additions & 1 deletion examples/low-level-api/revoke_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ pub async fn add_new_key(

// Add #newKey to the document
let new_key: KeyPair = KeyPair::new_ed25519()?;
let method: IotaVerificationMethod = IotaVerificationMethod::from_did(updated_doc.did().clone(), &new_key, "newKey")?;
let method: IotaVerificationMethod =
IotaVerificationMethod::from_did(updated_doc.did().clone(), new_key.type_(), new_key.public(), "newKey")?;
assert!(updated_doc.insert_method(method, MethodScope::VerificationMethod));

// Prepare the update
Expand Down
Loading

0 comments on commit 24de8d8

Please sign in to comment.