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

fix: JWTJsonPayload fields are optional except #80

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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