Skip to content

Commit

Permalink
fix: status list credential issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Nov 5, 2023
1 parent e567ba4 commit 4fb6bba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ class W3CCredentialBuilderWithCredentialStatus<C : VerifiableCredential, B : Abs

override fun build(): C = builder.apply {
getStatusProperty(
issuer = proofConfig.issuerDid,
type = proofConfig.statusType!!,
purpose = proofConfig.statusPurpose,
credentialUrl = proofConfig.credentialsEndpoint ?: signatoryConfig?.proofConfig?.credentialsEndpoint ?: ""
)?.let { this.setProperty("credentialStatus", it) }
}.build()

private fun getStatusProperty(type: CredentialStatus.Types, purpose: String, credentialUrl: String) = when (type) {
private fun getStatusProperty(issuer: String, type: CredentialStatus.Types, purpose: String, credentialUrl: String) = when (type) {
CredentialStatus.Types.SimpleCredentialStatus2022 -> simpleStatusFactory.create(SimpleStatusFactoryParameter(
id = URLBuilder().takeFrom(credentialUrl).appendPathSegments("token", createBaseToken()).buildString(),
)).asMap()
CredentialStatus.Types.StatusList2021Entry -> statusListEntryFactory.create(StatusListEntryFactoryParameter(
purpose = purpose,
credentialUrl = URLBuilder().takeFrom(credentialUrl).appendPathSegments("status", purpose).buildString(),
issuer = issuer,
)).asMap()
}.takeIf {
it.isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class StatusListEntryFactory(
// verify status-credential exists and create one
storageService.fetch(statusParameter.credentialUrl) ?: run {
storageService.store(
parameter.issuer,
statusParameter.credentialUrl,
statusParameter.purpose,
String(createEncodedBitString(BitSet(16 * 1024 * 8)))
Expand All @@ -54,5 +55,6 @@ data class SimpleStatusFactoryParameter(
) : CredentialStatusFactoryParameter
data class StatusListEntryFactoryParameter(
val credentialUrl: String,
val purpose: String
val purpose: String,
val issuer: String,
) : CredentialStatusFactoryParameter
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ open class StatusListCredentialStorageService : WaltIdService() {
override val implementation get() = serviceImplementation<StatusListCredentialStorageService>()

open fun fetch(id: String): VerifiableCredential? = implementation.fetch(id)
open fun store(id: String, purpose: String, bitString: String): Unit = implementation.store(id, purpose, bitString)
open fun store(issuer: String, id: String, purpose: String, bitString: String): Unit =
implementation.store(issuer, id, purpose, bitString)

companion object : ServiceProvider {
override fun getService() = object : StatusListCredentialStorageService() {}
Expand All @@ -35,7 +36,6 @@ class WaltIdStatusListCredentialStorageService : StatusListCredentialStorageServ
private val templatePath = "StatusList2021Credential"
private val signatoryService = Signatory.getService()
private val templateService = VcTemplateService.getService()
private val issuerDid = DidService.create(DidMethod.key)// TODO: fix it

override fun fetch(id: String): VerifiableCredential? = let {
val path = getCredentialPath(id.substringAfterLast("/"))
Expand All @@ -44,7 +44,7 @@ class WaltIdStatusListCredentialStorageService : StatusListCredentialStorageServ
}
}

override fun store(id: String, purpose: String, bitString: String): Unit = let {
override fun store(issuer: String, id: String, purpose: String, bitString: String): Unit = let {
fetch(id)?.let { vc ->
// update vc
W3CCredentialSubject(
Expand Down Expand Up @@ -73,8 +73,8 @@ class WaltIdStatusListCredentialStorageService : StatusListCredentialStorageServ
val credential = signatoryService.issue(
credentialBuilder = this, config = ProofConfig(
credentialId = id,
issuerDid = issuerDid,
subjectDid = issuerDid,
issuerDid = issuer,
subjectDid = issuer,
proofType = ProofType.LD_PROOF,
)
).toVerifiableCredential()
Expand Down

0 comments on commit 4fb6bba

Please sign in to comment.