generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implementing BearerDid / PortableDid, exposing our own JWS, JWT, JWK types #262
Merged
Merged
Changes from 42 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9eca633
create bearerdid and portable did, keyexporter and keyimporter
jiyoonie9 12cb845
changing Did to ChangemeDid to make it easier to spot and replace w B…
jiyoonie9 28e683a
removing didmethod interface
jiyoonie9 0106920
trying on BearerDID for did jwk
jiyoonie9 9c5fbbf
removing create options
jiyoonie9 f348127
getting did:dht and did:key to return BearerDID. next step: figure ou…
jiyoonie9 cb309ee
moved bearerdid import() to companion object so i can call bearerdid.…
jiyoonie9 1f32e5a
updated codeowners doc
jiyoonie9 a3ac9b5
changing type names to be true CamelCase. implemented Jws methods and…
jiyoonie9 90fa517
wrote jwt class. modify jws class to include builder for jwsheader
jiyoonie9 584a36b
sub out JwtUtils.sign() for Jwt.sign()
jiyoonie9 a9e1494
implemented jwt. removed jwtutil class
jiyoonie9 d387f2c
using hand rolled JwsHeader and JwtClaimsSet instead of nimbusds
jiyoonie9 b681b7c
adding jwk impl, in progress
jiyoonie9 33852b9
adding jose package. fixing some todos
jiyoonie9 9a77e89
goodbye, changemedid
jiyoonie9 9945824
updating tests to test import instead of load
jiyoonie9 f522197
wrote kt docs, fixed didresolvers, removed resolvedidoptions because …
jiyoonie9 e92dbd1
removing unnecessary tests
jiyoonie9 275d6f8
fixing tests
jiyoonie9 e2a3cb7
requiring keytype and curve when building Jwk
jiyoonie9 f0fbc80
adding default keyUse of sig to Jwk when computing public key.
jiyoonie9 46e3d5e
fixing some tests
jiyoonie9 f4c418c
adding '$.misc.vc....' path to all test vector jsons
jiyoonie9 a3e7688
fixing test vectors for credentials package tests
jiyoonie9 81c470d
reverting back adding $.misc.vc... for valid paths, instead using jwt…
jiyoonie9 fca2488
removing todos, removing extraneous Convert() call in Jwt.decode()
jiyoonie9 f56860c
removing jwk serializer/deserializer
jiyoonie9 129483b
tests pass. writing tests for jwt in process. jwk still needs tests w…
jiyoonie9 68d9c6b
Merge branch 'main' of github.com:TBD54566975/web5-kt into 234-did-impl
jiyoonie9 0b7dc33
fixing tests
jiyoonie9 149ed9a
new web5-spec sha
jiyoonie9 711f9d7
adding more jwttest
jiyoonie9 2f3c98d
added jwktest
jiyoonie9 c5d3b91
fixing detekt error
jiyoonie9 c1ea33d
adding bearerdid tests
jiyoonie9 eb52fd3
removing portabledidtest class because there is no method inside port…
jiyoonie9 5cdfec3
fixing detekt error
jiyoonie9 3937376
moving nimbusds lib to implementation instead of api
jiyoonie9 cda57a0
adding wording around not supporting did web creation
jiyoonie9 58db293
adding uri as a property to BearerDid as it was missed. addressing co…
jiyoonie9 55e652c
Merge branch 'main' of github.com:TBD54566975/web5-kt into 234-did-impl
jiyoonie9 5ab978d
changing how portabledid is constructed in vc test vector test
jiyoonie9 030678d
addressing review comments
jiyoonie9 6004707
Update dids/src/test/kotlin/web5/sdk/dids/methods/jwk/DidJwkTest.kt
b472990
making error in testvectorinput to default to false, added portabledi…
jiyoonie9 aa90cd4
Merge branch '234-did-impl' of github.com:TBD54566975/web5-kt into 23…
jiyoonie9 c5bba53
adding comment about supporting keys that use ECC
jiyoonie9 1d7e0a5
reverting back to include portabledid concept in vc create test vecto…
jiyoonie9 870cc12
bumping web5-spec commit
jiyoonie9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,10 @@ package web5.sdk.credentials | |
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.nimbusds.jwt.JWTClaimsSet | ||
import com.nimbusds.jwt.JWTParser | ||
import com.nimbusds.jwt.SignedJWT | ||
import web5.sdk.credentials.util.JwtUtil | ||
import web5.sdk.dids.Did | ||
import web5.sdk.common.Json | ||
import web5.sdk.dids.did.BearerDid | ||
import web5.sdk.jose.jwt.Jwt | ||
import web5.sdk.jose.jwt.JwtClaimsSet | ||
import java.net.URI | ||
import java.security.SignatureException | ||
import java.util.Date | ||
|
@@ -37,17 +36,17 @@ public class VerifiablePresentation internal constructor(public val vpDataModel: | |
public val verifiableCredential: List<String> | ||
get() = vpDataModel.toMap()["verifiableCredential"] as List<String> | ||
|
||
public val holder: String | ||
public val holder: String | ||
get() = vpDataModel.holder.toString() | ||
|
||
/** | ||
* Sign a verifiable presentation using a specified decentralized identifier ([did]) with the private key that pairs | ||
* Sign a verifiable presentation using a specified decentralized identifier ([bearerDid]) with the private key that pairs | ||
* with the public key identified by [assertionMethodId]. | ||
* | ||
* If the [assertionMethodId] is null, the function will attempt to use the first available verification method from | ||
* the [did]. The result is a String in a JWT format. | ||
* the [bearerDid]. The result is a String in a JWT format. | ||
* | ||
* @param did The [Did] used to sign the credential. | ||
* @param bearerDid The [BearerDid] used to sign the credential. | ||
* @param assertionMethodId An optional identifier for the assertion method that will be used for verification of the | ||
* produced signature. | ||
* @return The JWT representing the signed verifiable credential. | ||
|
@@ -58,14 +57,14 @@ public class VerifiablePresentation internal constructor(public val vpDataModel: | |
* ``` | ||
*/ | ||
@JvmOverloads | ||
public fun sign(did: Did, assertionMethodId: String? = null): String { | ||
val payload = JWTClaimsSet.Builder() | ||
.issuer(did.uri) | ||
.issueTime(Date()) | ||
.claim("vp", vpDataModel.toMap()) | ||
public fun sign(bearerDid: BearerDid, assertionMethodId: String? = null): String { | ||
val payload = JwtClaimsSet.Builder() | ||
.issuer(bearerDid.uri) | ||
.issueTime(Date().time) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is iat may need to change to seconds, currently this is milliseconds I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, and updated the ktdoc |
||
.misc("vp", vpDataModel.toMap()) | ||
.build() | ||
|
||
return JwtUtil.sign(did, assertionMethodId, payload) | ||
return Jwt.sign(bearerDid, payload) | ||
} | ||
|
||
/** | ||
|
@@ -153,7 +152,8 @@ public class VerifiablePresentation internal constructor(public val vpDataModel: | |
* ``` | ||
*/ | ||
public fun verify(vpJwt: String) { | ||
JwtUtil.verify(vpJwt) | ||
val decodedJwt = Jwt.decode(vpJwt) | ||
decodedJwt.verify() | ||
|
||
val vp = this.parseJwt(vpJwt) | ||
vp.verifiableCredential.forEach { | ||
|
@@ -177,15 +177,12 @@ public class VerifiablePresentation internal constructor(public val vpDataModel: | |
* ``` | ||
*/ | ||
public fun parseJwt(vpJwt: String): VerifiablePresentation { | ||
val jwt = JWTParser.parse(vpJwt) as SignedJWT | ||
val jwtPayload = jwt.payload.toJSONObject() | ||
val vpDataModelValue = jwtPayload.getOrElse("vp") { | ||
throw IllegalArgumentException("jwt payload missing vp property") | ||
} | ||
val jwt = Jwt.decode(vpJwt) | ||
val jwtPayload = jwt.claims | ||
val vpDataModelValue = jwtPayload.misc["vp"] | ||
?: throw IllegalArgumentException("jwt payload missing vp property") | ||
|
||
@Suppress("UNCHECKED_CAST") // only partially unchecked. can only safely cast to Map<*, *> | ||
val vpDataModelMap = vpDataModelValue as? Map<String, Any> | ||
?: throw IllegalArgumentException("expected vp property in JWT payload to be an object") | ||
val vpDataModelMap = Json.parse<Map<String, Any>>(Json.stringify(vpDataModelValue)) | ||
|
||
val vpDataModel = VpDataModel.fromMap(vpDataModelMap) | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is
misc
the more official name thanclaim
?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.
misc
is the top level field where we shove everything that's not a reserved keyword in JWT. i've followed the implementation in web5-darthttps://github.com/TBD54566975/web5-dart/blob/main/packages/web5/lib/src/jwt/jwt_claims.dart#L59
@mistermoe is there a spec i can reference for neal / do we need to write one?
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 standard to use is public / private claim names, depending on whether the claims are registered in an IANA registry
https://datatracker.ietf.org/doc/html/rfc7519#section-4.2
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
claims
is more apt thanmisc
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.
leaving it as
misc
for now, but this needs a discussion and a decision - TBD54566975/web5-spec#143There 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.
agreed @decentralgabe .
misc
is just something i came up with to avoid having to use the termsprivate
andpublic
in code because those are reserved. i think @nitro-neal 'sclaim()
suggestion is a great idea. can address in a subsequent PR