TBD54566975 / web5-kt

Apache License 2.0
7 stars 9 forks source link

`VerifiableCredential.create` make value for `type` optional #320

Closed EbonyLouis closed 1 week ago

EbonyLouis commented 2 weeks ago

Purpose

From this slack convo we've discovered that if we pass a value to type it will break LD processors who consume it. Since KCC is a JSON-LD construct. Right now we're able to do this in JS but not in KT.

Currently:

        val knownCustomerCredential = VerifiableCredential.create(
            type = "KnownCustomerCredential",
            issuer = issuerBearerDid.uri.toString(),
            subject = customerBearerDid.uri.toString(),
            expirationDate = expirationDate,
            data = KccCredential("US" , "Gold"),
            evidence = evidence,
            credentialSchema = CredentialSchema(
                id = "https://schema.org/PFI",
                type = "JsonSchema"
            ),
        )

Desired goal:

        val knownCustomerCredential = VerifiableCredential.create(
            issuer = issuerBearerDid.uri.toString(),
            subject = customerBearerDid.uri.toString(),
            expirationDate = expirationDate,
            data = KccCredential("US" , "Gold"),
            evidence = evidence,
            credentialSchema = CredentialSchema(
                id = "https://schema.org/PFI",
                type = "JsonSchema"
            ),
        )

thanks šŸ’–

nitro-neal commented 2 weeks ago

but the actual object that gets created Will have a type of VerifiableCredential right? (this is the spec)

nitro-neal commented 2 weeks ago

you should be able to add type VerifiableCredential as a workaround do

    val knownCustomerCredential = VerifiableCredential.create(
        type = "VerifiableCredential",
        issuer = issuerBearerDid.uri.toString(),
        subject = customerBearerDid.uri.toString(),
        expirationDate = expirationDate,
        data = KccCredential("US" , "Gold"),
        evidence = evidence,
        credentialSchema = CredentialSchema(
            id = "https://schema.org/PFI",
            type = "JsonSchema"
        ),
    )
EbonyLouis commented 2 weeks ago

@nitro-neal yes @decentralgabe said it's ok for it to have the type verifiableCredential I don't fully understand why that's ok but the other isn't lol so it makes me think that doing this workaround won't work.

@decentralgabe can you clarify some more please

nitro-neal commented 2 weeks ago

The VC bible says it so lol: https://www.w3.org/TR/vc-data-model/#types

image
EbonyLouis commented 2 weeks ago

ah ok perfect I'll use the work around- thanks @nitro-neal

So that we're uniformed across languages, we should still make it optional to provide a value for type

EbonyLouis commented 2 weeks ago

@nitro-neal , @decentralgabe would VerifiableCredential being duplicated cause a problem?

decentralgabe commented 2 weeks ago

it may not create a problem it would depend on the LD processor, but we should not have duplicate values if we can avoid it

EbonyLouis commented 2 weeks ago

ok cool so yea we need the SDK updated, cause this work around will create a duplicate

jiyoontbd commented 2 weeks ago

yep, @EbonyLouis confirming you're correct - using this

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

will create a vc with the vc.vcDataModel that looks like this

image

calling vc.type still gets you VerifiableCredential because the library we happen to be using just gives back the last item on the types list in vc.vcDataModel.types. but if you need the vc data model, then yea we'd see dupes.

pushing up a pr now :)

EbonyLouis commented 2 weeks ago

@jiyoontbd thank you! šŸ™ŒšŸ¾