Skip to content

Commit

Permalink
making vc type nullable during VerifiableCredential.Create() (#321)
Browse files Browse the repository at this point in the history
* making vc type nullable during VerifiableCredential.Create()
* checking vcdatamodel type list size

Co-authored-by: Ebony Louis <[email protected]>
  • Loading branch information
jiyoontbd and EbonyLouis authored Jun 24, 2024
1 parent 365242a commit 489ca78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class VerifiableCredential internal constructor(public val vcDataModel: V
*/
@JvmOverloads
public fun <T> create(
type: String,
type: String? = null,
issuer: String,
subject: String,
data: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertNotNull
import kotlin.test.assertNull

data class StreetCredibility(val localRespect: String, val legit: Boolean)
class VerifiableCredentialTest {
Expand Down Expand Up @@ -328,6 +329,26 @@ fun `kyc credential verify does not throw an exception if vc is legit`() {
assertEquals(vc.issuer, parsedVc.issuer)
assertEquals(vc.subject, parsedVc.subject)
}

@Test
fun `create can create a VC with default VerifiableCredential type with null type passed in`() {
val keyManager = InMemoryKeyManager()
val issuerDid = DidKey.create(keyManager)
val holderDid = DidKey.create(keyManager)

val vc = VerifiableCredential.create(
issuer = issuerDid.uri,
subject = holderDid.uri,
data = StreetCredibility(localRespect = "high", legit = true)
)

val vcDataModelType = vc.vcDataModel.jsonObject["type"] as List<*>
assertEquals(vcDataModelType.size, 1)

assertEquals(vc.type, "VerifiableCredential")
assertEquals(vc.issuer, issuerDid.uri)
assertEquals(vc.subject, holderDid.uri)
}
}

class Web5TestVectorsCredentials {
Expand Down

0 comments on commit 489ca78

Please sign in to comment.