eu-digital-identity-wallet / eudi-lib-jvm-sdjwt-kt

A library for issuing and verifying SD-JWT
Apache License 2.0
14 stars 4 forks source link

Serializing to JWS JSON fails on issued SD-JWT #161

Closed babisRoutis closed 4 months ago

babisRoutis commented 4 months ago

Function SdJwt<NimbusSignedJWT>.asJwsJsonObject() can produce a JWS JSON representation of an SD-JWT when NimbusSignedJWT is being instantiated through parsing.

SdJwt.asJwsJsonObject()` though when is applied on an issued SD-JWT fails.

Offending code is

return asJwsJsonObject(option) { jwt ->
        val parts = jwt.parsedParts
        checkNotNull(parts) { "It seems that the jwt is not signed" }
        val (header, payload, signature) = jwt.parsedParts.map { part ->
            checkNotNull(part)
            part.toString()
        }
        Triple(header, payload, signature)
    }

To correct this we need something like :

return asJwsJsonObject(option) { jwt ->
        require(jwt.state == JWSObject.State.SIGNED || jwt.state == JWSObject.State.VERIFIED) {
            "It seems that the jwt is not signed"
        }
        Triple(
            jwt.header.toBase64URL().toString(),
            jwt.payload.toBase64URL().toString(),
            jwt.signature.toString(),
        )
    }