Skip to content

Commit

Permalink
fix: 328-setting-the-expirydate-when-issuing-credential-via-rest-v1cr…
Browse files Browse the repository at this point in the history
…edentialsissue (#347)
  • Loading branch information
mikeplotean committed Sep 17, 2023
1 parent 35d0dd8 commit 7aa0054
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/id/walt/common/SerializationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import id.walt.model.VerificationMethod
import id.walt.sdjwt.SDMap
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import java.time.Instant

@Target(AnnotationTarget.FIELD)
annotation class VCList
Expand Down Expand Up @@ -42,6 +43,9 @@ annotation class DidVerificationRelationships
@Target(AnnotationTarget.FIELD)
annotation class SDMapProperty

@Target(AnnotationTarget.FIELD)
annotation class InstantValue

class VcConverter(private val singleVC: Boolean, private val singleIfOne: Boolean, private val toVcObject: Boolean) :
Converter {
override fun canConvert(cls: Class<*>) = singleVC && cls == VerifiableCredential::class.java || cls == List::class.java
Expand Down Expand Up @@ -162,6 +166,20 @@ val sdMapConverter = object : Converter {

}

val klaxonInstantValueConverter = object : Converter {
override fun canConvert(cls: Class<*>) = cls == InstantValue::class.java

override fun fromJson(jv: JsonValue): Any? = jv.longValue ?: jv.int?.toLong()?.let {
Instant.ofEpochSecond(it)
}

override fun toJson(value: Any): String {
return (value as Instant).epochSecond.toString()
}


}

fun KlaxonWithConverters() = Klaxon()
.fieldConverter(VCList::class, VcConverter(singleVC = false, singleIfOne = false, toVcObject = false))
.fieldConverter(VCObjectList::class, VcConverter(singleVC = false, singleIfOne = false, toVcObject = true))
Expand All @@ -174,6 +192,7 @@ fun KlaxonWithConverters() = Klaxon()
.fieldConverter(DidVerificationRelationships::class, didVerificationRelationshipsConverter)
.fieldConverter(SDMapProperty::class, sdMapConverter)
.fieldConverter(KotlinxJsonObjectField::class, kotlinxJsonObjectFieldConverter)
.fieldConverter(InstantValue::class, klaxonInstantValueConverter)

@Deprecated("Use KlaxonWithConverters()")
val KlaxonWithConverters = KlaxonWithConverters()
8 changes: 4 additions & 4 deletions src/main/kotlin/id/walt/signatory/Signatory.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package id.walt.signatory

import com.beust.klaxon.Json
import id.walt.common.InstantValue
import id.walt.common.SDMapProperty
import id.walt.credentials.w3c.VerifiableCredential
import id.walt.credentials.w3c.W3CIssuer
Expand Down Expand Up @@ -39,9 +40,9 @@ data class ProofConfig(
@Json(serializeNull = false) val nonce: String? = null,
@Json(serializeNull = false) val proofPurpose: String? = null,
@Json(serializeNull = false) val credentialId: String? = null,
@Json(serializeNull = false) val issueDate: Instant? = null, // issue date from json-input or current system time if null
@Json(serializeNull = false) val validDate: Instant? = null, // valid date from json-input or current system time if null
@Json(serializeNull = false) val expirationDate: Instant? = null,
@Json(serializeNull = false) @InstantValue val issueDate: Instant? = null, // issue date from json-input or current system time if null
@Json(serializeNull = false) @InstantValue val validDate: Instant? = null, // valid date from json-input or current system time if null
@Json(serializeNull = false) @InstantValue val expirationDate: Instant? = null,
@Json(serializeNull = false) val dataProviderIdentifier: String? = null, // may be used for mapping data-sets from a custom data-provider
@Json(serializeNull = false) val ldSignatureType: LdSignatureType? = null,
@Json(serializeNull = false) val creator: String? = issuerDid,
Expand Down Expand Up @@ -90,4 +91,3 @@ abstract class Signatory : WaltIdService() {
open fun removeTemplate(templateId: String): Unit = implementation.removeTemplate(templateId)
open fun hasTemplateId(templateId: String): Boolean = implementation.hasTemplateId(templateId)
}

0 comments on commit 7aa0054

Please sign in to comment.