# Credential

Credentials will be issued based on a template and will be stored in the user's wallet. Each credential has a specific issuer and belongs to a specific user. Therefore you need to specify the wallet when issuing it.

{% hint style="info" %}
**Credentials expired**: Credentials can be expired. You can pass *`credentialExpiration`* to time expired for credentials.
{% endhint %}

## Issue Credential

<mark style="color:green;">`POST`</mark> `https://api.dentity.com/core/api/v1/programmatic/credential`

Issues a credential from a previously defined template.  Credential templates can be created in [Dentity business](https://business.dentity.com/) site or by using [Dentity AP](https://docs.dentity.com/reference/wallets-and-credentials/api-endpoints/template)[I](https://docs.dentity.com/reference/wallets-and-credentials/api-endpoints/template).

#### Request Body

| Name                                                   | Type                       | Description                                                                                                                                   |
| ------------------------------------------------------ | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| walletId<mark style="color:red;">\*</mark>             | String                     | User’s wallet address                                                                                                                         |
| ...rest                                                | String                     | Fields based on “customFields” Credential Template                                                                                            |
| credentialExpiration<mark style="color:red;">\*</mark> | Number (Unix time) or null | <p>Credential expiration. <br><strong>NOTE</strong>: It must be greater than the current date and less or equal than template expiration.</p> |
| credentialTemplateId<mark style="color:red;">\*</mark> | String                     | Template ID                                                                                                                                   |

{% tabs %}
{% tab title="200: OK Issue credential successfully" %}

```javascript
{
    "data": {
        "credentialId": "654cb11409081b002b4f782f",
        "templateId": "654856f46e1395002b6d9526"
    }
}
```

{% endtab %}

{% tab title="400: Bad Request Occurs when a phone number or email already exists in the Dentity system or when the wrong data type is entered." %}

```javascript
{
    "code": "bad_request",
    "message": "This credential already exists in wallet",
    "errors": {
        "message": "This credential already exists in wallet",
        "code": "bad_request",
        "status": 400
    }
}
```

{% endtab %}
{% endtabs %}

## Get Credential Detail&#x20;

<mark style="color:blue;">`GET`</mark> `https://api.dentity.com/core/api/v1/programmatic/credential/:id`

Fetches credential details

#### Path Parameters

| Name                                 | Type   | Description   |
| ------------------------------------ | ------ | ------------- |
| id<mark style="color:red;">\*</mark> | String | Credential ID |

{% tabs %}
{% tab title="200: OK Get credential detail successfully" %}

```json
{
    "data": {
        "status": "active",
        "isSeparated": false,
        "_id": "65374cb71530d2002b5e133d",
        "detail": {
            "@context": [
                "https://www.w3.org/2018/credentials/v1",
                "https://w3id.org/bbs/v1",
                {
                    "@vocab": "https://trinsic.cloud/dentity-dev/"
                }
            ],
            "type": [
                "VerifiableCredential",
                "IssueTemplateOriginator61dbb8930dfa450011f7d9aa1698122828731"
            ],
            "credentialSchema": [
                {
                    "id": "https://schema.trinsic.cloud/dentity-dev/issue-template-originator-61dbb8930dfa450011f7d9aa-1698122828731",
                    "type": "JsonSchemaValidator2018"
                }
            ],
            "credentialSubject": {
                "credentialIssuer": "Issue Template Originator",
                "credentialType": "Issue Template Originator",
                "holderFullName": "Leslie Knope",
                "id": "urn:vc:subject:0"
            },
            "id": "urn:vc",
            "issuanceDate": "2023-10-24T04:48:55Z",
            "credentialStatus": {
                "id": "https://dentity-dev.connect.trinsic.cloud/credential-status/W9U5cYArzKKuFZE6yY7wQH#0",
                "type": "RevocationList2020Status",
                "revocationListIndex": "0",
                "revocationListCredential": "https://dentity-dev.connect.trinsic.cloud/credential-status/W9U5cYArzKKuFZE6yY7wQH"
            },
            "issuer": "did:web:dentity-dev.connect.trinsic.cloud:z8wCvUe4sM5eTnYYHFaxxjs",
            "proof": {
                "type": "BbsBlsSignature2020",
                "created": "2023-10-24T04:48:55Z",
                "proofPurpose": "assertionMethod",
                "proofValue": "lIhBZ7yg99DPjYYyp98f1q+YayTt3vrW0VTz3Jmja6n+J5zFBA1SfDo/F5Nl4ffBFyuoonXH+p3MRILXXzMQ/y9q/R5d68jR4r9M753HBuVdhq2pq7r4VJGFMq/NebGEbu1OBrVuVjhtYsxHR2U/5g==",
                "verificationMethod": "did:web:dentity-dev.connect.trinsic.cloud:z8wCvUe4sM5eTnYYHFaxxjs#z9KMl1J5wRrDBZ2J4m5P3EUqo4F86pHgCmLeT5Bviqo"
            }
        },
        "templateId": "urn:template:dentity-dev:issue-template-originator-61dbb8930dfa450011f7d9aa-1698122828731",
        "templateName": "Issue Template Originator",
        "credentialId": "65374cb71530d2002b5e133d",
        "template": "65374c4d1530d2002b5e1339",
        "partner": "61dbb8930dfa450011f7d9aa",
        "credentialSubjectsData": {
            "credentialIssuer": "Issue Template Originator",
            "credentialType": "Issue Template Originator",
            "holderFullName": "Leslie Knope"
        },
        "offerCredential": "65374cb71530d2002b5e133e",
        "dateCreated": "2023-10-24T04:48:55.685Z",
        "dateUpdated": "2023-10-24T04:48:55.685Z",
        "__v": 0
    }
}
```

{% endtab %}
{% endtabs %}

## Delete Credential in Wallet

<mark style="color:red;">`DELETE`</mark> `https://api.dentity.com/core/api/v1/programmatic/credential/:id`

Deletes a credential by ID.

#### Path Parameters

| Name                                 | Type   | Description   |
| ------------------------------------ | ------ | ------------- |
| id<mark style="color:red;">\*</mark> | String | Credential ID |

{% tabs %}
{% tab title="200: OK Delete credential successfully" %}

```json
{
    "data": {
        "isSuccess": true
    }
}
```

{% endtab %}
{% endtabs %}

## Verify Credential Proof

<mark style="color:green;">`POST`</mark> `https://api.dentity.com/core/api/v1/credential/proofs/verify`

Verify proof that you received when Holder finished [OIDC for Verifiable Presentation](https://docs.dentity.com/reference/wallets-and-credentials/openid-for-verifiable-credentials/openid-connect-for-verifiable-presentations).&#x20;

#### Request Body

| Name   | Type         | Description |
| ------ | ------------ | ----------- |
| proofs | Array object |             |

{% tabs %}
{% tab title="200: OK Verify proof successfully" %}

```json
{
  "data": [
    {
      "isValid": true,
      "validationResults": {
        "CredentialStatus": {
          "isValid": true,
          "messages": []
        },
        "IssuerIsSigner": {
          "isValid": true,
          "messages": []
        },
        "SchemaConformance": {
          "isValid": true,
          "messages": []
        },
        "SignatureVerification": {
          "isValid": true,
          "messages": []
        },
        "TrustRegistryMembership": {
          "isValid": true,
          "messages": []
        }
      }
    }
  
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Validation results**: The verification process performs a number of validations, each of which may fail independently of the others.
{% endhint %}

For example, a credential may be expired or revoked, but otherwise perfectly valid.\
`validation_results` contains an entry for each of the following verification steps:

| Name                      | Description                                                                                                                                                                                                                                |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `SignatureVerification`   | The cryptographic proof over the entire Verifiable Credential, specifically using BBS+ Proof of Signature                                                                                                                                  |
| `CredentialStatus`        | *(if supported by credential)* Checks if credential has been revoked                                                                                                                                                                       |
| `SchemaConformance`       | Ensures credential conforms with its schema. It is possible to issue a credential omitting a required field (as captured in the credential template). If your use case allows this kind of omission, you can ignore this validation entry. |
| `TrustRegistryMembership` | *(if relevant)* Verifies that credential issuer is an authorized member of the credential's governing Trust Registry                                                                                                                       |
| `IssuerIsSigner`          | Document `issuer` is same DID as document signer. *If false, it is not safe to assume that the claimed `issuer` actually issued the credential.*                                                                                           |
