-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add did-jwk
support
#466
Add did-jwk
support
#466
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great 👍 Could be worth it to include more tests, although looks like you have covered all the spec-provided test cases (at least one should-fail case could be handy as this did method is just a function)
did-jwk/src/lib.rs
Outdated
// TODO: pass through these errors somehow | ||
return ( | ||
ResolutionMetadata { | ||
error: Some(ERROR_INVALID_DID.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with how we use ResolutionMetadata
usually, but could you just format the error as a string in the error field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's not a specified set https://w3c-ccg.github.io/did-resolution/#errors (but why wouldn't we use an enum if it were)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha yes:
The error code from the resolution process. This property is REQUIRED when there is an error in the resolution process. The value of this property MUST be a single keyword ASCII string. The possible property values of this field SHOULD be registered in the DID Specification Registries [DID-SPEC-REGISTRIES].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I think the TODO
can just be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #468
did-jwk/src/lib.rs
Outdated
_ => return None, | ||
}; | ||
let jwk = jwk.to_public(); | ||
let jwk = serde_jcs::to_string(&jwk).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if this never fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From docs.rs:
Serialization can fail if T's implementation of Serialize fails.
If JWK
is safe to serialize then it shouldn't be a problem, otherwise I can add error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should change the .unwrap()
to .ok()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed something in the spec that might need addressing:
Only JWKs containing public key material may be used, a JWK for a private key must never be used and must be rejected by all implementations when encountered.
From that I would expect that the resolve
method should check that the encoded JWK does not contain the private key (and if so return an error instead of resolving?).
Also if we are being very precise about the spec then I would expect generate
to return None
instead of converting it to a public key.
I might be misunderstanding the strength of the language used in the spec though :)
Could you rebase please? |
@sbihel rebased. @cobward I wasn't sure myself, maybe @awoie can help us here. I chose to go with Hadn't thought of the |
b4b7f54
to
5b9fc5e
Compare
i believe the only requirement is that we shouldn't allow private key material in the |
5b9fc5e
to
f17d4c0
Compare
I have kept the |
Could you still address the leftover TODO and unwrap? |
Signed-off-by: Tiago Nascimento <[email protected]>
Signed-off-by: Tiago Nascimento <[email protected]>
Signed-off-by: Tiago Nascimento <[email protected]>
f17d4c0
to
4b96075
Compare
@sbihel done and rebased. |
Adds
did-jwk
support as described in https://github.com/quartzjer/did-jwk/blob/main/spec.mdAlthough the spec mentions canonicalization is optional, it has been implemented here with
serde_jcs
. So generally, we can expect the samejwk
, with an arbitrary field ordering on input, to generate the samedid-jwk
identifier when usingSSI
.