TBD54566975 / web5-kt

Apache License 2.0
10 stars 10 forks source link

[Bug] web did resolution does not support http ports #324

Closed aparkersquare closed 3 months ago

aparkersquare commented 3 months ago

Describe the bug Resolving a web did with a port results in an incorrect url for the did.json

To Reproduce:

Using the following code

import web5.sdk.dids.DidResolvers

fun main(args: Array<String>) {

  val did = "did:web:127.0.0.1:8802"
  try {
    val resolution = DidResolvers.resolve(did)
    println(resolution)
  } catch (t: Throwable) {
    println("Error resolving DID: $did")
    println("  ${t.stackTraceToString()}".replace("\n", "\n  "))
  }
}

This returns {"didDocumentMetadata":{},"didResolutionMetadata":{"error":"internalError"}}

Debugging through web5-kt I see the docUrl is using the port as part of the path, and also leaving off the .well-known.

docUrl=https://127.0.0.1/8802/did.json

This seems to be an issue somewhere in DidWeb.kt.

aparkersquare commented 3 months ago

Update - there is already a way to encode the port, and it's even in the unit test!

Example : did:web:example.com%3A3000:user:alice

There is still an issue for local testing that DidWeb assumes https.

It would be good if it switched to http for local addresses, similar to dap-dart. See did_web.dart#L94-L100 (thanks to @mistermoe for the pointer).