Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the Account: internal state, one identity #453

Merged
merged 15 commits into from
Nov 18, 2021

Conversation

PhilippGackstatter
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter commented Oct 25, 2021

Description of change

Refactors the Account to handle one instead of multiple identities and refactors the internal state to reduce complexity and make it easier to implement features like granting low-level, unchecked access to an internal IotaDocument as well as tangle synchronization.

This PR essentially contains two other PRs:

Links to any relevant issues

fixes #431
fixes #433

Type of change

Add an x to the boxes that are relevant to your changes.

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

How the change has been tested

Describe the tests that you ran to verify your changes.
Make sure to provide instructions for the maintainer as well as any relevant configurations.

Change checklist

Add an x to the boxes that are relevant to your changes.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

PhilippGackstatter and others added 3 commits October 25, 2021 09:56
* Partial impl to use did as storage identifier

* Move `CreateIdentity` into a separate type

Update Account API to return IdentityState from find_identity and create_identity (#414)

* Update Account::create_identity() to return IdentityState.

* Update Account::find_identity() to return IdentityState.

Update `IdentityUpdater` to only use account ref

Remove resolve, find and list

Replace `IdentityId` with `IotaDID` in account

Use `IotaDID` over `IdentityId` in stronghold

More replacement of id with did

Remove index from account

Fix stream impl

Fix stronghold impl, migrate `MemStore`

Re-add `resolve_identity` so tests can run

Fix Wasm network calls, pin reqwest to 0.11.4 (#439)

Rename `Command` -> `Update`

Rearrange `process_update`

* Fix clippy lints in memstore

* Let `RemoteKey` take a `dyn Storage`

* Implement `AccountConfig`

* Impl create_identity and load_identity in builder

* Rename JSON serialization field name to match spec. (#412)

* Rename JSON serialization field name to match spec.

* Rename notSupported -> representationNotSupported

* Reduce WASM build size (#427)

* reduce wasm build size

* Enable lto for Wasm release

Add `build-dev` task for Wasm for debugging.

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

* Chore/combine examples (#420)

* Merged Stronghold with basic examples in account

* Updated explorer to identity resolver

* Added explorer URL after basic example

* Renamed examples

* Completed manipulate did example

* Fixed suggestions, removed replaced examples.

* Improved example readme

* Consistently use Stronghold and Resolver URL

* Fix examples

* Merged config example with private tangle

* low-level-api private-network example runs

* cargo fmt

* cargo fmt with nightly

* Impl suggestions

* Refactor config once more

* Update examples to use single-id account

* Don't pass did into `load_snapshot`

* Fix clippy lints

* Partially update `update` tests

* Fix update tests

* Ensure did exists in storage in `load`

* Remote `State` in account

* Rename `load` -> `load_identity`

* Remove `Identity{Id,Index,Key,Name,Tag}`

* Let `update_identity` take `&mut self`

* Document new and existing types

* Update top-level README example

* Fix visibility on `CreateIdentity`

* Add try_from implementation for ed25519 keypair

* Combine account tests

* Rename updates > commands for better reviewability

* Also rename in mod.rs

* Impl `AccountBuilder` without pub async fns

* Update README example with latest builder change

* Change visibility of setup, config, constructors

* Revert to the old `create_did` example

* Save to disk when creating identity, fix doc fmt

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

* Use `authority` instead of `tag` in stronghold

* Rename `Config` -> `AccountConfig`

* Prevent two accounts from managing the same did

* Impl `IdentityBuilder`

* Only impl `IdentityCreate` under `#[cfg(test)]`

* Use `IdentityBuilder` in examples

* Remove unused `name` field

* Run workflow for `epic/*` branches

* Relase the lease in account tests

* Also run format, clippy and coverage workflows

* Revert "Use `IdentityBuilder` in examples"

This reverts commit 3d1b716.

* Revert "Only impl `IdentityCreate` under `#[cfg(test)]`"

This reverts commit 08ada09.

* Revert "Impl `IdentityBuilder`"

This reverts commit 1a5d645.

* Rename `IdentityCreate` -> `IdentitySetup`

* Add multi-identity example

* Simplify README example

* Rename `identity_setup` module

* Implement the `IdentityLease` newtype

* Rename `IdentityLease` -> `DIDLease`

* Update `resolve_identity` docstring

Co-authored-by: Matt Renaud <matt@m-renaud.com>
Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com>
Co-authored-by: Craig Bester <craig.bester@iota.org>
Co-authored-by: Jelle Femmo Millenaar <jelle.millenaar@iota.org>
PhilippGackstatter and others added 6 commits October 29, 2021 13:37
* 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>
@PhilippGackstatter PhilippGackstatter changed the title Refactor Account: One-Identity, Tangle Sync, Internal State Refactor theAccount: internal state, one identity Nov 17, 2021
@PhilippGackstatter PhilippGackstatter changed the title Refactor theAccount: internal state, one identity Refactor the Account: internal state, one identity Nov 17, 2021
@PhilippGackstatter PhilippGackstatter marked this pull request as ready for review November 17, 2021 09:03
Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good! The constituent PRs have been reviewed already so this was just a light review.

Minor comments. Only required changes are to fix the README files I think.

README.md Outdated Show resolved Hide resolved
examples/README.md Show resolved Hide resolved
identity-account/src/account/builder.rs Outdated Show resolved Hide resolved
identity-account/src/tests/lazy.rs Outdated Show resolved Hide resolved
identity-iota/src/did/doc/iota_document.rs Show resolved Hide resolved
identity-iota/src/did/doc/iota_document.rs Show resolved Hide resolved
identity-did/src/document/core_document.rs Outdated Show resolved Hide resolved
identity-iota/src/tangle/publish.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the changes.

@PhilippGackstatter PhilippGackstatter merged commit 9bf01bb into dev Nov 18, 2021
@PhilippGackstatter PhilippGackstatter deleted the epic/account-refactor branch November 18, 2021 13:20
@PhilippGackstatter PhilippGackstatter added Chore Tedious, typically non-functional change Added A new feature that requires a minor release. Part of "Added" section in changelog labels Nov 19, 2021
@PhilippGackstatter PhilippGackstatter added Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog and removed Added A new feature that requires a minor release. Part of "Added" section in changelog Chore Tedious, typically non-functional change labels Dec 3, 2021
@PhilippGackstatter PhilippGackstatter added Rust Related to the core Rust code. Becomes part of the Rust changelog. No changelog Excludes PR from becoming part of any changelog labels Dec 3, 2021
@JelleMillenaar JelleMillenaar removed the No changelog Excludes PR from becoming part of any changelog label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Refactor the Account state [Task] Convert Account to handle one Identity
3 participants