From 78bab8ee9118ee584badefc23a440ccd11110a22 Mon Sep 17 00:00:00 2001 From: mikeplotean <101570226+mikeplotean@users.noreply.github.com> Date: Mon, 8 May 2023 14:24:31 +0300 Subject: [PATCH] chore: updated storage location for status-list-credential (#305) --- .../StatusListCredentialStorageService.kt | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/id/walt/signatory/revocation/statuslist2021/StatusListCredentialStorageService.kt b/src/main/kotlin/id/walt/signatory/revocation/statuslist2021/StatusListCredentialStorageService.kt index 88714bb5..07d71bb5 100644 --- a/src/main/kotlin/id/walt/signatory/revocation/statuslist2021/StatusListCredentialStorageService.kt +++ b/src/main/kotlin/id/walt/signatory/revocation/statuslist2021/StatusListCredentialStorageService.kt @@ -1,5 +1,6 @@ package id.walt.signatory.revocation.statuslist2021 +import id.walt.common.resolveContent import id.walt.credentials.w3c.VerifiableCredential import id.walt.credentials.w3c.W3CCredentialSubject import id.walt.credentials.w3c.builder.W3CCredentialBuilder @@ -8,11 +9,14 @@ import id.walt.credentials.w3c.toVerifiableCredential import id.walt.model.DidMethod import id.walt.servicematrix.ServiceProvider import id.walt.services.WaltIdService -import id.walt.services.context.ContextManager +import id.walt.services.WaltIdServices import id.walt.services.did.DidService import id.walt.signatory.ProofConfig import id.walt.signatory.ProofType import id.walt.signatory.Signatory +import java.io.File +import kotlin.io.path.Path +import kotlin.io.path.pathString open class StatusListCredentialStorageService : WaltIdService() { override val implementation get() = serviceImplementation() @@ -29,14 +33,17 @@ open class StatusListCredentialStorageService : WaltIdService() { class WaltIdStatusListCredentialStorageService : StatusListCredentialStorageService() { private val templatePath = "StatusList2021Credential" - private val credentialsGroup = "status-credentials" private val signatoryService = Signatory.getService() - private val vcStoreService = ContextManager.vcStore private val templateService = VcTemplateService.getService() private val issuerDid = DidService.create(DidMethod.key)// TODO: fix it - override fun fetch(id: String): VerifiableCredential? = - vcStoreService.getCredential(id.substringAfterLast("/"), credentialsGroup) + override fun fetch(id: String): VerifiableCredential? = let { + val path = getCredentialPath(id.substringAfterLast("/")) + resolveContent(path).takeIf { it != path }?.let { + VerifiableCredential.fromJson(it) + } + } + override fun store(id: String, purpose: String, bitString: String): Unit = let { fetch(id)?.let { vc -> // update vc @@ -71,6 +78,10 @@ class WaltIdStatusListCredentialStorageService : StatusListCredentialStorageServ proofType = ProofType.LD_PROOF, ) ).toVerifiableCredential() - vcStoreService.storeCredential(credential.id!!.substringAfterLast("/"), credential, credentialsGroup) + getCredentialPath(credential.id!!.substringAfterLast("/")).let { + File(it).writeText(credential.encode()) + } } + + private fun getCredentialPath(name: String) = Path(WaltIdServices.revocationDir, "$name.cred").pathString }