hypersign-protocol / hid-node

A permissionless blockchain network to manage digital identity and access rights
https://hypersign.id
Apache License 2.0
223 stars 23 forks source link

feat: verification methods with `blockchainAccountId` field populated cannot be added in a DID Document if they already exists in some registered DID Document #359

Closed arnabghose997 closed 1 year ago

arnabghose997 commented 1 year ago

In the current implementation, there isn't any restriction imposed on addition of a Verification Method to a DID Document, even if its present in some other registered DID Document. However, one of our Customers have raised concern related to this.

A Reputation Score is given to a DID Document based on the number of wallet addresses (Verification Methods with blockchainAccountId populated) it carries. The problem is that the user of a DID Document can take one of the Verification Methods can add it to multiple DIDs and can claim score on those DID Documents which is not desirable.

This PR intends to solve the issue by restricting the movement of those Verification Methods whose blockchainAccountId field is populated, by not letting them being added to a new DID Document if they already exists in some DID Document. Only if the Verification Method is removed from the existing DID Document or the DID Document is deactivated, the Verification Method is available to be added a new DID Document.

This also ensures that those Verification Methods which doesn't have blockchainAccountId field populated are free to be added anywhere, thereby not hampering those scenarios where this functionality is deseriable.

Following test cases are added:

  1. FAIL: Alice Creates a DID Doc. Bob attempts to create a DID Document by adding one of Alice's VM.

  2. FAIL: Charlie creates a DID Document. After that, Charlie attempts to update its DID Document by adding one of Alice's VM for which valid signature is passed.

  3. PASS: Alice deactivates her DID Document. Charlie attempts to update its DID Document by adding one of Alice's VM for which valid signature is passed.

  4. PASS: Charlie removes one of its Verification Methods. George creates a didDoc for himself. He then proceed to update his DID Document by adding the Verification method removed by Charlie