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

Updates did:dht implementation to the latest spec #183

Merged
merged 7 commits into from
Jan 11, 2024
Merged

Conversation

andresuribe87
Copy link
Contributor

Overview

Fixes #182 by implementing the updates in the spec.

Description

This includes:

  • Using ; as a property separator. , as an array separator.
  • Supporting also known as, and did.controller.
  • Supporting verificationMethod.controller.

Changes to the public API add the possible new fields, in a way that was consistent with the existing methods.

How Has This Been Tested?

Added fields to the tests.

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Merging #183 (3ef3fa1) into main (06a879c) will increase coverage by 0.72%.
Report is 1 commits behind head on main.
The diff coverage is 82.40%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   78.96%   79.69%   +0.72%     
==========================================
  Files          33       34       +1     
  Lines        1930     2088     +158     
  Branches      265      317      +52     
==========================================
+ Hits         1524     1664     +140     
- Misses        274      280       +6     
- Partials      132      144      +12     
Components Coverage Δ
credentials 82.34% <ø> (+1.66%) ⬆️
crypto 38.07% <ø> (ø)
dids 89.53% <82.40%> (-0.07%) ⬇️
common 80.44% <ø> (ø)

@@ -146,11 +154,17 @@ public sealed class DidDhtApi(configuration: DidDhtConfiguration) : DidMethod<Di
}

// map to the DID object model's verification methods
val verificationMethods = (opts.verificationMethods?.map { (key, purposes) ->
val verificationMethods = (opts.verificationMethods?.map { (key, purposes, controller) ->
VerificationMethod.builder()
.id(URI.create("$id#${key.keyID}"))
.type("JsonWebKey2020")
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be JsonWebKey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assumed we were waiting as stated in decentralized-identity/web5-spec#73

If we want to include it, I'd rather do so in #181.


val keyType = when (publicKeyJwk.algorithm) {
JWSAlgorithm.EdDSA -> 0
JWSAlgorithm.ES256K -> 1
Copy link
Member

Choose a reason for hiding this comment

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

could we add ES256 here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

add("id=${verificationMethod.id.rawFragment}")
add("t=$keyType")
add("k=$base64UrlEncodedKey")
if (verificationMethod.jsonObject.containsKey("controller")) {
Copy link
Member

Choose a reason for hiding this comment

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

probably fine to add this but not in the spec yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, figured it would be added really soon :)

Name("_aka._did."),
DClass.IN,
ttl,
didDocument.alsoKnownAses.joinToString(PROPERTY_SEPARATOR)
Copy link
Member

Choose a reason for hiding this comment

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

if this is a single value what happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didDocument.alsoKnownAses always returns a list.

Join returns the the value of the single element when the list is of size 1.

Name("_cnt._did."),
DClass.IN,
ttl,
didDocument.controllers.joinToString(PROPERTY_SEPARATOR)
Copy link
Member

Choose a reason for hiding this comment

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

same question here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto

@@ -492,22 +585,28 @@ public sealed class DidDhtApi(configuration: DidDhtConfiguration) : DidMethod<Di
else -> throw IllegalArgumentException("Unknown key type: ${data["t"]}")
}

verificationMethods += VerificationMethod.builder()
val builder = VerificationMethod.builder()
.id(URI.create("$did#$verificationMethodId"))
.type("JsonWebKey2020")
Copy link
Member

Choose a reason for hiding this comment

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

also JsonWebKey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above

public val services: Iterable<Service>? = null,
public val publish: Boolean = true,
public val controllers: Iterable<String>? = null,
public val alsoKnownAses: Iterable<String>? = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this spelling right?

Copy link
Contributor Author

@andresuribe87 andresuribe87 Jan 10, 2024

Choose a reason for hiding this comment

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

I don't know :S
I considered it good enough so it conveys that it has possibly multiple items. Any suggestions you have in mind?

@andresuribe87 andresuribe87 merged commit 04119f2 into main Jan 11, 2024
6 of 8 checks passed
@andresuribe87 andresuribe87 deleted the issue_182 branch January 11, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update did:dht implementation based on spec changes
3 participants