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

cli did create web #263

Merged
merged 7 commits into from
Jul 16, 2024
Merged

cli did create web #263

merged 7 commits into from
Jul 16, 2024

Conversation

diehuxx
Copy link
Contributor

@diehuxx diehuxx commented Jul 8, 2024

Add basic CLI to create and print a did web document

no_indent,
json_escape,
} => {
let private_jwk = Ed25519Generator::generate();
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that with did web especially, we should allow people to pass in the own private key / portable did. We can add this as a feature in the future though

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed, on the private key input (portable DID slightly different use case I haven't thought through -- creating a new DID with an existing DID), but yeah not a priority at this moment

Copy link
Contributor

@nitro-neal nitro-neal left a comment

Choose a reason for hiding this comment

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

Awesome!

@nitro-neal
Copy link
Contributor

if you have the output handy can you put here?

This is amazing!


let verification_method = VerificationMethod {
id: format!("{}#key-0", did),
r#type: "JsonWebKey2020".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

@nitro-neal didn't we standardize this to just JsonWebKey?

@@ -18,6 +21,29 @@ pub struct DidWeb {
}

impl DidWeb {
pub fn new(domain: &str, public_jwk: Jwk) -> Result<Self> {
let did = format!("did:web:{}", domain);
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite right because the domain has to be encoded according to the spec. See here and here. Also web5-go as inspiration.

Probably we should use a strongly typed Url here to ensure the passed domain: &str is a valid domain.

I believe also did:web has a requirement of enforcing https over http, but with the caveat that, if the domain is localhost then http is allowed. We're currently setup to handle this in resolution, but here too, we should use a strongly typed Url to ensure the domain is localhost and not something like localhost-neal-example.com. Feel free to improve the resolution code as well in this PR if you think it's appropriate.

@@ -17,7 +17,12 @@ pub enum Commands {
json_escape: bool,
},
Web {
#[arg(long)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[arg(long)]

The domain is a required parameter, so not an arg (you can just delete the line).

Also, thoughts on calling it URL because it could include the HTTP path such as in Example 5 here. I'm thinking, name it url, and then handle the following use cases:

  1. If they pass in http://some-domain.com then the http would throw an error, b/c needs to be https
  2. With the caveat, http is allowed if the domain name is localhost (or 127.0.0.1)
  3. If they pass in https://some-domain.com then that's fine, but we have to splice off the https://
  4. If they pass in the did.json file name (as the trailing path part), that's fine but it must be spliced off before creating the DID URI
  5. If they pass in the .well-known use case in the url then it's also spliced off

Basically my thinking is, enable the developer to copy/paste exactly the endpoint they're expecting to host the DID Document at but then ensure the DID URI is spec conformant.

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 a commit to cover these cases

let mut public_jwk = private_jwk.clone();
public_jwk.d = None;

let valid_url = if domain.starts_with("http://") || domain.starts_with("https://") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is really amazing code @diehuxx 👏

so good, in fact, I'm going to move it inside the DidWeb::new() function, so that we enable this DX not just for the CLI experience but also for application-level use cases. I feel confident exposing this code such that we can expose to developers, "send in any endpoint and we'll create a did:web instance out of it"

also I spy a slight bug in the case wherein both a .well-known and did.json are passed in, like in Example 4 here

@KendallWeihe KendallWeihe merged commit b1ca55c into main Jul 16, 2024
10 checks passed
@KendallWeihe KendallWeihe deleted the create-did-web branch July 16, 2024 13:56
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.

4 participants