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: 328-setting-the-expirydate-when-issuing-credential-via-rest-v1credentialsissue #347

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
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)
}