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

Expose iteration over verification relationship fields #1024

Merged
merged 7 commits into from Sep 20, 2022

Conversation

abdulmth
Copy link
Contributor

@abdulmth abdulmth commented Sep 16, 2022

Description of change

Add an optional scope parameter to the method getter on DID Document implementations to allow iterating over particular verification relationship fields.

Links to any relevant issues

fixes issue #989

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

@abdulmth abdulmth self-assigned this Sep 16, 2022
@abdulmth abdulmth added Wasm Related to Wasm bindings. Becomes part of the Wasm changelog Chore Tedious, typically non-functional change Rust Related to the core Rust code. Becomes part of the Rust changelog. labels Sep 16, 2022
@abdulmth abdulmth added this to the v0.7 Features milestone Sep 16, 2022
@abdulmth abdulmth linked an issue Sep 16, 2022 that may be closed by this pull request
7 tasks
@abdulmth abdulmth added Enhancement New feature or improvement to an existing feature Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog and removed Enhancement New feature or improvement to an existing feature labels Sep 16, 2022
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter 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!

I tried a different approach with Box<dyn Iterator> but it produces a 6 KiB larger Wasm binary, so the Vec approach seems preferable despite more allocations and going through the entire iterator upfront.

For reference:

pub fn methods<'this>(
    &'this self,
    scope: Option<MethodScope>,
  ) -> Box<dyn Iterator<Item = &VerificationMethod<D, U>> + 'this>
  where
    D: DID,
  {
    if let Some(scope) = scope {
      match scope {
        MethodScope::VerificationMethod => Box::new(self.verification_method().iter()),
        MethodScope::VerificationRelationship(MethodRelationship::AssertionMethod) => Box::new(
          self
            .assertion_method()
            .iter()
            .filter_map(|mr| self.resolve_method_ref(mr)),
        ),
        MethodScope::VerificationRelationship(MethodRelationship::Authentication) => Box::new(
          self
            .authentication()
            .iter()
            .filter_map(|mr| self.resolve_method_ref(mr)),
        ),
        MethodScope::VerificationRelationship(MethodRelationship::CapabilityDelegation) => Box::new(
          self
            .capability_delegation()
            .iter()
            .filter_map(|mr| self.resolve_method_ref(mr)),
        ),
        MethodScope::VerificationRelationship(MethodRelationship::CapabilityInvocation) => Box::new(
          self
            .capability_invocation()
            .iter()
            .filter_map(|mr| self.resolve_method_ref(mr)),
        ),
        MethodScope::VerificationRelationship(MethodRelationship::KeyAgreement) => {
          Box::new(self.key_agreement().iter().filter_map(|mr| self.resolve_method_ref(mr)))
        }
      }
    } else {
      Box::new(self.all_methods())
    }
  }

identity_did/src/document/core_document.rs Show resolved Hide resolved
identity_did/src/document/core_document.rs Outdated Show resolved Hide resolved
identity_did/src/document/core_document.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.

Co-authored-by: cycraig <craig.bester@iota.org>
@abdulmth abdulmth merged commit f0b69a3 into dev Sep 20, 2022
@eike-hass eike-hass deleted the chore/iteration-over-verification-relationships branch September 30, 2022 11:43
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 Chore Tedious, typically non-functional change Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
Development

Successfully merging this pull request may close these issues.

[Task] Expose iteration over verification relationship fields
3 participants