Skip to content

Commit

Permalink
chore: updated storage location for status-list-credential (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean authored May 8, 2023
1 parent d7d4f90 commit 78bab8e
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<StatusListCredentialStorageService>()
Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 78bab8e

Please sign in to comment.