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

Create and resolve did:key #25

Merged
merged 2 commits into from
Dec 6, 2023
Merged

Create and resolve did:key #25

merged 2 commits into from
Dec 6, 2023

Conversation

amika-sq
Copy link
Contributor

@amika-sq amika-sq commented Dec 1, 2023

Resolve did:key DIDs using Spruce's did-method-key crate. Uses our DidResolutionResult implementation so that the resolved DIDDocument & all respective metadata is in the expected format according to the community draft resolution spec here.

Resolves #22

@amika-sq
Copy link
Contributor Author

amika-sq commented Dec 5, 2023

Created a task in our backlog to implement this ourselves: #43

let key_manager = Arc::new(LocalKeyManager::new_in_memory());

DidKey::create(key_manager, DidKeyCreateOptions { key_type })
.expect("DidKey Ed25519 creation failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Error message is hardcoded to Ed25519 as the key type rather than using the key_type parameter

Copy link
Contributor

@KendallWeihe KendallWeihe Dec 5, 2023

Choose a reason for hiding this comment

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

This actually begs the question... should we define default key types? (apologies if this convo has already been had)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it as I rebased to main!

Rust doesn't have the concept of "default parameter values" like a lot of other languages have. We could define a default value for ANY KeyType if it's not present, but that didn't seem right to me. What may be a good default for one did method may not be a good default for another.

The other approach we could take is the builder pattern, which would allow us to define default values if the builder doesn't have a value set for a required field.

Copy link
Contributor Author

@amika-sq amika-sq Dec 5, 2023

Choose a reason for hiding this comment

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

Another options is we could implement the Default trait (documentation) for DidKeyCreateOptions (and the others like DidJwkCreateOptions).

Then we could define whatever default options we think are good for creating did:key with.

The only downside, the user still needs to provide a value when calling this function. It would just change to the following:
DidKey::create(key_manager, DidKeyCreateOptions::default())

Copy link
Contributor

Choose a reason for hiding this comment

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

Just briefly perusing web5-js and web5-kt, we're offering at least some amount of default-value DX. I think this warrants an issue on the backlog, if only for the sake of discussion to rule it out. I don't love simplicity insofar as it robs the developer of valuable knowledge, but intuitively, I think it would be wise to offer a simple create() DX where the developer can easily get-off-zero. Which further begs the question of if the key manager should also have a default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

A compelling counter argument, against supporting default values, is that Rust is not a junior dev friendly language. Which is to say, not a lot of newbie developers are using Rust. In which case, default values only serve to add unnecessary overhead and confusion.

Idk just trying to steel man the counter case, I still think intuitively, default values are a good DX.

Copy link
Contributor

Choose a reason for hiding this comment

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

Late in the day for me so I'm rambling, but anyways this isn't a priority whatsoever IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

#45

Base automatically changed from clippy-main to main December 5, 2023 21:04
Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

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

Small suggestion about public facing docs, so when documentation is automatically generated then readers have clarity.

impl DidMethod<DidKey, DidKeyCreateOptions> for DidKey {
const NAME: &'static str = "key";

fn create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to add documentation to public facing functions?

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 isn't public. DidMethod is public, and it is documented here: https://github.com/TBD54566975/web5-rs/blob/main/crates/dids/src/method/mod.rs#L21-L42

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 public.

The implementation of DidMethod::create is being done via DidKey::create. Since the former is public, I thought that meant this method is public as well....

Anyways, I don't think it's important. My main concern is that there is no place in documentation that describes to consumers of the crate how to use DidKeyCreateOptions when creating a did of type key. While this is obvious for DidKey, it will become not so obvious for DidDht in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can address this when we implement DidDht

@amika-sq amika-sq merged commit 3dfa311 into main Dec 6, 2023
9 checks passed
@amika-sq amika-sq deleted the did-key branch December 6, 2023 16:24
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.

Implement did:key creation and resolution
4 participants