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

support web did resolution over http for local host #325

Conversation

aparkersquare
Copy link
Contributor

Overview

Uses http for web did resolution for local hosts. This allows for local development.

See #324

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.60%. Comparing base (489ca78) to head (7ae58e7).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #325   +/-   ##
=======================================
  Coverage   73.60%   73.60%           
=======================================
  Files          45       45           
  Lines        2163     2163           
  Branches      402      403    +1     
=======================================
  Hits         1592     1592           
  Misses        376      376           
  Partials      195      195           
Components Coverage Δ
credentials 81.31% <ø> (ø)
crypto 49.16% <ø> (ø)
dids 80.50% <100.00%> (ø)
common 65.21% <ø> (ø)

@@ -192,15 +192,15 @@ public sealed class DidWebApi(
private fun decodeId(parsedDid: Did): String {
Copy link
Member

Choose a reason for hiding this comment

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

@aparkersquare thoughts on using a parsed url to build targetUrl? something like

  public fun decodeId(parsedDid: Did): String {
    val domainNameWithPath = parsedDid.id.replace(":", "/")
    val decodedDomain = URLDecoder.decode(domainNameWithPath, UTF_8)
    val url = URL("https://$decodedDomain")

    val decodedId = StringBuilder()
    if (url.host == "localhost" || url.host == "127.0.0.1") {
      decodedId.append("http://")
    } else {
      decodedId.append("https://")
    }

    decodedId.append(decodedDomain)

    if (url.path.isEmpty()) {
      decodedId.append(WELL_KNOWN_URL_PATH)
    }
    decodedId.append(DID_DOC_FILE_NAME)

    return decodedDomain.toString()
  }

potential benefits of doing it this way are:

  • url is parsed (therefore "validated" prior to doing anything else
  • we can check url.host explicitly

there's probably kotlin idioms that can be used in the above suggestion to make the code more kotlin-esque which you'd know better about than me!

when i gave chad (aka chatGPT) the above suggestion and asked him for something more idiomatic, he suggested:

public fun decodeId(parsedDid: Did): String {
    val domainNameWithPath = parsedDid.id.replace(":", "/")
    val decodedDomain = URLDecoder.decode(domainNameWithPath, UTF_8.name())
    val url = URL("https://$decodedDomain")

    return buildString {
        append(if (url.host == "localhost" || url.host == "127.0.0.1") "http://" else "https://")
        append(decodedDomain)
        if (url.path.isEmpty()) {
            append(WELL_KNOWN_URL_PATH)
        }
        append(DID_DOC_FILE_NAME)
    }
}

let me know what you think! i personally prefer the former but maybe that's because i don't write much kotlin. Either way, 👍🏽

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh, I didn't know about url.host!
Agree, that looks like it could be a nicer approach. Thanks.

I'll have a closer look soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works.
Updated the PR to use this approach, and deleted the LocalHostDomainMatcher

Copy link
Member

Choose a reason for hiding this comment

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

Naisuu!

Copy link
Member

@mistermoe mistermoe left a comment

Choose a reason for hiding this comment

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

thanks @aparkersquare ! left a comment and approved regardless so you're not stuck waiting for approval

@aparkersquare aparkersquare force-pushed the aparker/20240626-support-web-did-resolution-over-http-for-local-host branch from b256de5 to 7ae58e7 Compare June 28, 2024 03:00
@mistermoe mistermoe merged commit e287b8a into TBD54566975:main Jun 28, 2024
10 checks passed
@angiejones
Copy link
Member

thanks so much @aparkersquare 🙏🏾

@taniashiba
Copy link

thank you so much!

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.

5 participants