Skip to content

Commit

Permalink
fix: JWTJsonPayload fields are optional except (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK authored Jun 27, 2023
1 parent 96100f9 commit e095c49
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ import kotlin.jvm.JvmOverloads
*/
@Serializable
data class JWTCredentialPayload(
val iss: DID,
val iss: DID?,
val sub: String?,
@SerialName(VC)
val verifiableCredential: JWTVerifiableCredential,
val nbf: String,
val nbf: String?,
val exp: String?,
val jti: String
val jti: String?
) : VerifiableCredential {

/**
Expand All @@ -60,7 +60,7 @@ data class JWTCredentialPayload(
override val credentialType: CredentialType,
override val context: Array<String> = arrayOf(),
override val type: Array<String> = arrayOf(),
override val issuer: DID,
override val issuer: DID?,
override val credentialSchema: VerifiableCredentialTypeContainer? = null,
override val credentialSubject: String,
override val credentialStatus: VerifiableCredentialTypeContainer? = null,
Expand Down Expand Up @@ -125,7 +125,7 @@ data class JWTCredentialPayload(
}

override val id: String
get() = jti
get() = jti ?: ""
override val credentialType: CredentialType
get() = CredentialType.JWT
override val context: Array<String>
Expand All @@ -144,7 +144,7 @@ data class JWTCredentialPayload(
get() = verifiableCredential.evidence
override val termsOfUse: VerifiableCredentialTypeContainer?
get() = verifiableCredential.termsOfUse
override val issuer: DID
override val issuer: DID?
get() = verifiableCredential.issuer
override val issuanceDate: String
get() = verifiableCredential.issuanceDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sealed interface VerifiableCredential {
val refreshService: VerifiableCredentialTypeContainer?
val evidence: VerifiableCredentialTypeContainer?
val termsOfUse: VerifiableCredentialTypeContainer?
val issuer: DID
val issuer: DID?
val issuanceDate: String // TODO(Date)
val expirationDate: String? // TODO(Date)
val validFrom: VerifiableCredentialTypeContainer?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class W3CVerifiableCredential @JvmOverloads constructor(
override val credentialType: CredentialType = CredentialType.W3C,
override val context: Array<String>,
override val type: Array<String>,
override val issuer: DID,
override val issuer: DID?,
override val issuanceDate: String,
override val expirationDate: String? = null,
override val credentialSchema: VerifiableCredentialTypeContainer? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.serialization.json.JsonElement

@Serializable
data class JWTJsonPayload(
val iss: String,
val sub: String,
val nbf: Long,
val exp: Long,
val iss: String? = null,
val sub: String? = null,
val nbf: Long? = null,
val exp: Long? = null,
val vc: JsonElement
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class PolluxImpl(val castor: Castor) : Pollux {
val verifiableCredentialJson = Json.decodeFromString<JWTJsonPayload>(decodedBase64CredentialJson)

return JWTCredentialPayload(
iss = DID(verifiableCredentialJson.iss),
exp = verifiableCredentialJson.exp.toString(),
nbf = verifiableCredentialJson.nbf.toString(),
iss = if (verifiableCredentialJson.iss != null) DID(verifiableCredentialJson.iss) else null,
exp = if (verifiableCredentialJson.exp != null) verifiableCredentialJson.exp.toString() else null,
nbf = if (verifiableCredentialJson.nbf != null) verifiableCredentialJson.nbf.toString() else null,
jti = jwtString,
verifiableCredential = JWTCredentialPayload.JWTVerifiableCredential(
credentialType = CredentialType.JWT,
issuer = DID(verifiableCredentialJson.iss),
credentialSubject = verifiableCredentialJson.sub,
issuer = if (verifiableCredentialJson.iss != null) DID(verifiableCredentialJson.iss) else null,
credentialSubject = verifiableCredentialJson.sub ?: "",
id = jwtString,
issuanceDate = verifiableCredentialJson.nbf.toString(),
expirationDate = verifiableCredentialJson.exp.toString(),
Expand Down

0 comments on commit e095c49

Please sign in to comment.