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

feat(did-key): Add Support To Resolve JWK_JCS-PUB encoded did:key DIDs #600

Merged
merged 14 commits into from
Sep 18, 2024

Conversation

ianhamilton87
Copy link
Contributor

@ianhamilton87 ianhamilton87 commented Aug 15, 2024

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

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
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
Copy link
Contributor

@timothee-haudebourg timothee-haudebourg left a 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?

@@ -102,6 +102,10 @@ impl FromStr for JWK {
}
}

pub fn from_bytes(bytes: &[u8]) -> Result<JWK, serde_json::Error> {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

exponent: Some(e1),
..
}),
modulus: Some(n1),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@timothee-haudebourg timothee-haudebourg self-assigned this Aug 23, 2024
@ianhamilton87 ianhamilton87 changed the title feat(did-key): Add EBSI Natural Person Format feat(did-key): Add Support To Resolve JWK_JCS-PUB encoded did:key DIDs Aug 28, 2024
@ianhamilton87
Copy link
Contributor Author

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?

@timothee-haudebourg - I have adjusted the summary and description to make it less EBSI specific.
EBSI proposes using did:key with the JWK_JCS-PUB format, but it has no exclusive use of that multicodec. That multicodec existed before EBSI decided to use it as far as I can see.
There's a link to an EBSI website that explains all this.
I figured mentioning EBSI would get more folks to want this change.
Why they can't juse did:jwk, who knows 🤷 .

Copy link
Contributor

@timothee-haudebourg timothee-haudebourg left a 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 => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@ianhamilton87
Copy link
Contributor Author

ianhamilton87 commented Sep 4, 2024

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.

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

Copy link
Contributor

@timothee-haudebourg timothee-haudebourg left a 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.

// 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());
Copy link
Contributor

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

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 test_multicodec_jwk_jcs_pub()
Fixed test_multicodec_jwk_jcs_pub()
@ianhamilton87
Copy link
Contributor Author

@timothee-haudebourg - mind doing one final review + approving?

@timothee-haudebourg
Copy link
Contributor

Yes sorry for the delay. Just waiting for the CI to pass and we'll be good.

Copy link
Contributor

@timothee-haudebourg timothee-haudebourg left a 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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ianhamilton87
Copy link
Contributor Author

@timothee-haudebourg - ok. I feature-gated the tests. Mind approving the workflow so the tests can re-run?
(Note: locally the test always ran successfully, so there must be something in my setup that prevents me from recreating this locally)

@timothee-haudebourg
Copy link
Contributor

locally the test always ran successfully

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

@timothee-haudebourg timothee-haudebourg merged commit a585e0c into spruceid:main Sep 18, 2024
4 checks passed
@timothee-haudebourg
Copy link
Contributor

All good! Thanks again!

@ianhamilton87
Copy link
Contributor Author

@timothee-haudebourg Thanks!

@ianhamilton87 ianhamilton87 deleted the did-key-ebsi branch September 20, 2024 17:11
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.

2 participants