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

did:dht resolution #15

Merged
merged 5 commits into from
Feb 16, 2024
Merged

did:dht resolution #15

merged 5 commits into from
Feb 16, 2024

Conversation

amika-sq
Copy link
Contributor

(Adding reviewers that I know are semi familiar with did:dht resolution. Feel free to add anyone else if I might have missed anyone!)

This PR adds did:dht resolution.

How-To

did:dht resolution can be done either by interacting directly with the DIDDHT.Resolver struct, or by resolving using the generic DIDResolver, which can resolve any supported DID Method

Resolving directly with DIDDHT.Resolver

Resolution can be accomplished via the DIDDHT.Resolver struct:

  1. With the default options:
let resolver = DIDDHT.Resolver()
await resolver.resolve(didURI: "did:dht:1234")
  1. With a custom gateway:
let resolver = DIDDHT.Resolver(
    options: .init(gatewayURI: "https://my-custom-gateway.org")
)
await resolver.resolve(didURI: "did:dht:1234")

Resolving with DIDResolver

Resolution can also be accomplished with the DIDResolver simply by calling it with a DID URI:

await DIDResolver.resolve(didURI: "did:dht:1234")

By default, DIDResolver uses the default options to resolve the DID. If you want to customize the resolution process, create a new DIDDHT.Resolver, define your desired custom options, and register it.

Note

This will cause all did:dht resolutions to use the custom resolution options

let resolver = DIDDHT.Resolver(
    options: .init(gatewayURI: "https://my-custom-gateway.org")
)
DIDResolver.register(resolver: resolver)
await DIDResolver.resolve(didURI: "did:dht:1234")

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

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

awesome work. after the test vectors pass this should be good to go


func test_resolve_publishedDID_withSingleVerificationMethod() async throws {
Mock(
url: URL(string: "https://diddht.tbddev.org/pjiiw7ibn6t9k1mkknkowjketa8chksgwzkt5uk8798epux1386o")!,
Copy link
Member

Choose a reason for hiding this comment

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

if these tests rely on DIDs being present on this node it will work for some time...then break when we move to our prod node.

separately I believe it's crucial to implement tests for the two vectors the spec currently has https://did-dht.com/#test-vectors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied these tests from the web5-js repo here.

In terms of the test-vectors defined in the spec, I'm a little confused as to what exactly they are representing. It looks like they are not resolution vectors, but instead are importing keys, and verifying a particular DIDDocument is constructed from them. Creation/Importing will be coming in a later PR, and should be able to handle those. Do let me know if I'm misunderstanding those though!

Copy link
Member

Choose a reason for hiding this comment

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

they are not exactly resolution vectors, you are correct. they make sure you can construct a consistent document and packet given a set of inputs.

I mention it now because you have implemented fromDNSPacket which could exercise the listed vectors DNS packets and compare them to the resulting DID document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these vectors in the following commit: 93351ac

These vectors are kind of a deviation from the existing resolve vectors in the web5-spec here, so I decided to just implement them directly in Swift for the time being. Eventually, I think these should work their way into the web5-spec repo though, so that we ensure they pass across all SDKs. Just a matter of aligning on input/output formats!

Copy link
Member

Choose a reason for hiding this comment

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

thank you @amika-sq I noted a comment here and will make sure to get these updated.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

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

awesome work

@amika-sq amika-sq enabled auto-merge (squash) February 16, 2024 17:58
@amika-sq amika-sq merged commit 5a939c4 into main Feb 16, 2024
1 check passed
@amika-sq amika-sq deleted the did-dht branch February 16, 2024 18:04
@amika-sq amika-sq mentioned this pull request Feb 23, 2024
2 tasks
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.

2 participants