iotaledger / identity.rs

Implementation of the Decentralized Identity standards such as DID and Verifiable Credentials by W3C for the IOTA Tangle.
https://www.iota.org
Apache License 2.0
301 stars 87 forks source link

[Task] Enforce intra-document fragment uniqueness #1061

Open eike-hass opened 2 years ago

eike-hass commented 2 years ago

Description

We should enforce uniqueness of fragments in DID documents, since multiple identical fragments in one document could lead to errors or at least unexpected or undefined behavior, during credential validation and other operations.

Motivation

Prevent user errors and keep documents in a consistent state.

Sub-tasks

olivereanderson commented 2 years ago

As of now verification methods under the same scope (authentication, assertionMethod, capabilityInvocation, capabilityDelegation) in a document must necessarily have different fragments/ids as it is enforced by the library. The same goes for services.

It is however possible to have the same fragment/identifier under different scopes, although certain methods prevent this, it is not a guarantee.

olivereanderson commented 2 years ago

I have updated the issue with a few sub-tasks. Note that we cannot reliably ensure that the custom properties users can pass in our CoreDocument don't break fragment/identifier uniqueness because we don't have enough context.

We can however consider embracing JSON-LD support in the future and provide an additional method to check that the document can be serialized to valid JSON-LD. That method cannot be called by serde though as it will likely need to be asynchronous.