Skip to main content

Issuing a Credential

Prerequisites

To issue a credential, follow these steps:

  1. Create a new credential.
  2. Fill in the credential claims and configure necessary settings.
  3. Issue the created credential.

Create Credential

The first step is to create a new empty credential in the wallet. Use the following code to do so:

CREDENTIAL=$(curl --request POST \
--url "https://api.truvity.com/api/wallet/v1/credential?entityDid=${ENTITY_DID}&walletDid=${WALLET_DID}" \
--header 'Content-Type: application/json' \
--header "X-API-KEY: ${TRUVITY_API_KEY}" | jq -r '.Credential')

CREDENTIAL_DID=$(echo $CREDENTIAL | jq -r '.CredentialDid')
CREDENTIAL_REVISION=$(echo $CREDENTIAL | jq -r '.Revision')

Update Credential

Since the created credential is empty and can't be issued, we need to update its content.

tip

We'll use a simplified version of one of the examples from the W3C VC specification as content for our credential.

credential.json
{
"@context": ["https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1"],
"id": null,
"type": ["VerifiableCredential", "AlumniCredential"],
"issuer": "https://example.edu/issuers/565049",
"issuanceDate": "2010-01-01T19:23:24Z",
"credentialSubject": {
"alumniOf": {
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
"name": "Example University"
}
}
}

Use the following code to update the credential:

# replacing id with actual credential id, set `credentialSubject.type` and encode it to base64
BASE64_ENCODED_CREDENTIAL=$(cat credential.json | jq ".id = \"${CREDENTIAL_DID}\"" | base64 -w 0)

# updates CREDENTIAL_REVISION with latest revision number
CREDENTIAL_REVISION=$(curl --request PATCH \
--url "https://api.truvity.com/api/wallet/v1/credential/${CREDENTIAL_DID}?revision=${CREDENTIAL_REVISION}&entityDid=${ENTITY_DID}&walletDid=${WALLET_DID}" \
--header 'Content-Type: application/json' \
--header "X-API-KEY: ${TRUVITY_API_KEY}" \
--data "{\"JsonLd\": \"${BASE64_ENCODED_CREDENTIAL}\"}" | jq -r '.CredentialUpdateParameters.Revision')

Issue Credential

Once the credential is updated, issue the created credential to make it a verifiable credential. Use the following code to do so:

# updates CREDENTIAL_REVISION with latest revision number
CREDENTIAL_REVISION=$(curl --request POST \
--url "https://api.truvity.com/api/wallet/v1/credential/${CREDENTIAL_DID}?revision=${CREDENTIAL_REVISION}&entityDid=${ENTITY_DID}&walletDid=${WALLET_DID}" \
--header 'Content-Type: application/json' \
--header "X-API-KEY: ${TRUVITY_API_KEY}" | jq -r '.Revision')

Further reading