dhuseby / did

Rust create for working with DID documents.
Apache License 2.0
1 stars 2 forks source link

[RFC] DidUri improvements #3

Open dhuseby opened 5 years ago

dhuseby commented 5 years ago

@mikelodder7 I like what you've done with DidUri so far. The validation is solid. However, I think we should create a trait called Did that has functions for accessing the parts of a DID string. Maybe even have traits for DidQuery and DidFragment and DidParams?

Here's why I want to make a Did trait. We can then have specific implementations for the different Did methods. I could impl Did for DidGit for instance and then I could also add functions that return libgit2 types along with the functions in the Did trait. The DidGit implementations for the DidQuery, DidFragment and DidParams also mean specialized things in the DidGit method context. The impl DidParams for DidGitParams will support the interface but also be able to return libgit2 references to specific commits in a repo and other things.

The current DidUri is a good first step, but I think making it a trait with specialized implementations for each DID method is in order.

Thoughts?

dhuseby commented 5 years ago

Hrm...if we make the trait called DidUri instead of Did, then we can have a module level method that does the parsing and tries to create instances of the method-specific types that impl the DidUri trait. That way we could just do this:

// this will create an instance of DidGitUri
let git = Did::from_str("did:git:akjsdhgaksdjhgasdkgh").unwrap();

// this will create an instance of DidSovUri
let sov = Did::from_str("did:sov:akjsdhgaksdjhgasdkgh").unwrap();

That's what I'm thinking.

mikelodder7 commented 5 years ago

My only concern is that all DIDs have a common format which is the goal of this function. After generic parsing, then you can downcast to the most specific ones, so I’m not sure what the trait buys.

mikelodder7 commented 5 years ago

I’m not opposed to having a generic parse that returns the specific instance

dhuseby commented 5 years ago

My only concern is that all DIDs have a common format which is the goal of this function. After generic parsing, then you can downcast to the most specific ones, so I’m not sure what the trait buys.

I guess that does make more sense. I'm mostly concerned with turning the method specific parts of the DID into instances of objects for that method. for instance, turning the commit hash in a did:git string into a commit object from libgit2.