-
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
feat(did-key): Add Support To Resolve JWK_JCS-PUB encoded did:key DIDs #600
feat(did-key): Add Support To Resolve JWK_JCS-PUB encoded did:key DIDs #600
Conversation
Enhance did:key functionality to resolve [EBSI-style did:keys](https://hub.ebsi.eu/vc-framework/did/natural-person). They use the JWK_JCS-PUB multicodec. Relevant issues that are related to this PR: [w3c-ccg/did-method-key#63](w3c-ccg/did-method-key#63) [#536](#536) Re-do of former PR #545
This reverts commit 43c9843.
Enhance did:key functionality to resolve [EBSI-style did:keys](https://hub.ebsi.eu/vc-framework/did/natural-person). They use the JWK_JCS-PUB multicodec. Relevant issues that are related to this PR: [w3c-ccg/did-method-key#63](w3c-ccg/did-method-key#63) [#536](#536) Re-do of former PR #545
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.
Hi, thanks for this PR! Is it just about adding the JWK_JCS_PUB
decoding format? It doesn't seem directly related to EBSI Natural Person, unless this codec is exclusively used by this specification? Can you clarify and reflect that in the PR title and description?
crates/jwk/src/lib.rs
Outdated
@@ -102,6 +102,10 @@ impl FromStr for JWK { | |||
} | |||
} | |||
|
|||
pub fn from_bytes(bytes: &[u8]) -> Result<JWK, serde_json::Error> { |
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.
Can you make this a constructor of JWK
? And also add a TryFrom<&[u8]>
implementation?
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.
@timothee-haudebourg - ok. I moved it down to line 313, within the JWK implementation. I hope that's what you mean by make it a constructor.
And I added the TryFrom implementation too.
crates/jwk/src/lib.rs
Outdated
exponent: Some(e1), | ||
.. | ||
}), | ||
modulus: Some(n1), |
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 think there is a formatting issue here. Did you run cargo fmt
?
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.
@timothee-haudebourg Yikes! I did. Should be good now.
Enhance did:key functionality to resolve [EBSI-style did:keys](https://hub.ebsi.eu/vc-framework/did/natural-person). They use the JWK_JCS-PUB multicodec. Relevant issues that are related to this PR: [w3c-ccg/did-method-key#63](w3c-ccg/did-method-key#63) [#536](#536) Re-do of former PR #545
code review fixes
code review fixes
@timothee-haudebourg - I have adjusted the summary and description to make it less EBSI specific. |
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.
Can you add an implementation of ssi_multicodec::Codec
for JWK
? Using JWK_JCS_PUB
as the codec for JWK
. This will also allow use to implement and test encoding. You can use serde_jcs
which I think is already a dependency of ssi
to convert a JWK into JSON with JCS. It's a bit old now so if you prefer something else like serde_json_canonicalizer
it's fine.
@@ -47,6 +47,9 @@ impl JWK { | |||
ssi_multicodec::BLS12_381_G2_PUB => { | |||
crate::bls12381g2_parse(k).map_err(FromMulticodecError::Bls12381G2Pub) | |||
} | |||
ssi_multicodec::JWK_JCS_PUB => { |
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.
Can you add a test checking that its able to decode a JWK encoded with the JWK_JCS_PUB multicodec?
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.
Done!
Added test for from_multicodec w/ JWK_JCS_PUB. Added an implementation of ssi_multicodec::Codec for JWK_JCS_PUB. Because of that, removed the existing from_bytes() method.
@timothee-haudebourg I have done this. Hopefully, I have done this correctly. This is my first foray into Rust, so thank you for your patience. |
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.
It looks great 😄
Just use MultiEncodedBuf::encode
to encode the key in the new test and we're good.
crates/jwk/src/multicodec.rs
Outdated
// it will see the P256 key and assign a multicodec of 0x1200. | ||
// For jwk_jcs_pub multicodecs, we can only decode them | ||
let jwk_buf = | ||
MultiEncodedBuf::encode_bytes(ssi_multicodec::JWK_JCS_PUB, jwk_str.as_bytes()); |
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.
Since you implemented JWK: Codec
you can use MultiEncodedBuf::encode(&jwk)
.
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.
@timothee-haudebourg Done!
Fixed test_multicodec_jwk_jcs_pub()
Fixed test_multicodec_jwk_jcs_pub()
@timothee-haudebourg - mind doing one final review + approving? |
Yes sorry for the delay. Just waiting for the CI to pass and we'll be good. |
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.
The CI workflow is failing because of some missing feature gates.
|
||
#[test] | ||
fn test_multicodec_jwk_jcs_pub() { | ||
let jwk = JWK::generate_p256(); |
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.
This won't work without the secp256r1
feature enabled. You can feature-gate the test.
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.
@timothee-haudebourg - sorry about that. This is my first foray into Rust, can you tell?
Hopefully this fixes everything.
feature gate test
@timothee-haudebourg - ok. I feature-gated the tests. Mind approving the workflow so the tests can re-run? |
That's because some features are enabled by default. The CI workflow is actually testing a range of feature combinations (that's why it takes so much time). |
All good! Thanks again! |
@timothee-haudebourg Thanks! |
Enhance did:key functionality to resolve EBSI-style did:keys.
EBSI uses the JWK_JCS-PUB multicodec as noted in the document linked above. JWK_JCS-PUB is not exclusive to EBSI though and may be used elsewhere.
Relevant issues that are related to this PR:
w3c-ccg/did-method-key#63
#536
Re-do of former PR #545