-
Notifications
You must be signed in to change notification settings - Fork 85
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
Expose iteration over verification relationship fields #1024
Conversation
There was a problem hiding this 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())
}
}
There was a problem hiding this 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>
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.