Credential Issuance

Issue a Verifiable Credentials using Credential Issuance Service.

Install Dependency

Package: affinidi-tdk/affinidi-tdk-php

composer require affinidi-tdk/affinidi-tdk-php

Check the latest version on the Packagist repository or view the source on GitHub.

Classes and Methods

Configuration API

Manage the issuance configuration for the project. Project only one issuance configuration.

createIssuanceConfig

Creates an issuance configuration for the project.

Parameters

createIssuanceConfigInput CreateIssuanceConfigInput Required
Configuration details including supported credentials, wallet ID, offer duration, and format.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\ConfigurationApi(new GuzzleHttp\Client(), $config);

try {
    $request = array(
        'credentialSupported' => array(
            array(
                'credentialTypeId' => 'SchemaOne',
                'jsonSchemaUrl' => 'https://schema.affinidi.io/SchemaOneV1R1.json',
                'jsonLdContextUrl' => 'https://schema.affinidi.io/SchemaOneV1R1.jsonld',
            )
        ),
        'issuerWalletId' => '<WALLET_ID>',
        'credentialOfferDuration' => 3600,
        'format' => 'ldp_vc',
    );
    $result = $apiInstance->createIssuanceConfigRequest($request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

deleteIssuanceConfigById

Deletes the issuance configuration by ID.

Parameters

configurationId string Required
ID of the issuance configuration to delete.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\ConfigurationApi(new GuzzleHttp\Client(), $config);

try {
    $apiInstance->deleteIssuanceConfigById('<CONFIG_ID>');
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

getIssuanceConfigById

Retrieves the issuance configuration details by ID.

Parameters

configurationId string Required
ID of the issuance configuration to retrieve.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\ConfigurationApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->getIssuanceConfigById('<CONFIG_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

getIssuanceConfigList

Returns the list of issuance configurations for the current project.

No parameters required.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\ConfigurationApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->getIssuanceConfigList();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

updateIssuanceConfigById

Updates an existing issuance configuration by ID.

Parameters

configurationId string Required
ID of the issuance configuration to update.
updateIssuanceConfigInput UpdateIssuanceConfigInput Required
Updated configuration details.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\ConfigurationApi(new GuzzleHttp\Client(), $config);

try {
    $request = array(
        'credentialSupported' => array(
            array(
                'credentialTypeId' => 'SchemaOne',
                'jsonSchemaUrl' => 'https://schema.affinidi.io/SchemaOneV1R1.json',
                'jsonLdContextUrl' => 'https://schema.affinidi.io/SchemaOneV1R1.jsonld',
            )
        ),
        'issuerWalletId' => '<WALLET_ID>',
        'credentialOfferDuration' => 4600,
        'format' => 'ldp_vc',
    );
    $result = $apiInstance->updateIssuanceConfigById('<CONFIG_ID>', $request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

Issuance API

Use to initiate issuance of the credential and check the status.

issuanceState

Retrieves the status of an issuance.

Parameters

issuanceId string Required
ID of the initiated issuance.
projectId string Required
Project ID from where the issuance was initiated.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\IssuanceApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->issuanceState('<ISSUANCE_ID>', '<PROJECT_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

listIssuance

Returns the list of issuances initiated in the project.

Parameters

projectId string Required
Project ID from which to list issuances.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\IssuanceApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->listIssuance('<PROJECT_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

startIssuance

Initiates the issuance of a credential.

Parameters

projectId string Required
Project ID from which to initiate the issuance.
startIssuanceInput StartIssuanceInput Required
Credential data, holder DID, and claim mode.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\IssuanceApi(new GuzzleHttp\Client(), $config);

try {
    $request = array(
        'data' => array(
            array(
                'credentialTypeId' => 'SchemaOne',
                'credentialData' => array(
                    'Firstname' => 'FirstName',
                    'Lastname' => 'LastName',
                    'dob' => '1970-01-01',
                ),
            )
        ),
        'holderDid' => 'did:key:holder-did-value',
        'claimMode' => 'FIXED_HOLDER',
    );
    $result = $apiInstance->startIssuance('<PROJECT_ID>', $request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

Credentials API

Issue a Verifiable Credentials to the users.

batchCredential

Allows digital wallets to claim multiple credentials at once.

Parameters

projectId string Required
Project ID from which to issue the credentials.
batchCredentialInput BatchCredentialInput Required
List of credential requests, each with a credential identifier and proof.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\CredentialsApi(new GuzzleHttp\Client(), $config);

try {
    $batchRequest = [
        'credential_requests' => [
            [
                'credential_identifier' => 'credentialIdentifier',
                'proof' => [
                    'proof_type' => 'jwt',
                    'jwt' => '<PROOF_JWT>',
                ],
            ]
        ]
    ];
    $result = $apiInstance->batchCredential('<PROJECT_ID>', $batchRequest);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

generateCredentials

Generates and issues a credential offer to the user.

Parameters

projectId string Required
Project ID from which to issue the credential.
createCredentialInput CreateCredentialInput Required
Credential identifier and proof JWT.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\CredentialsApi(new GuzzleHttp\Client(), $config);

try {
    $request = array(
        'credential_identifier' => 'SchemaOne',
        'proof' => array(
            'proof_type' => 'jwt',
            'jwt' => '<PROOF_JWT>',
        ),
    );
    $result = $apiInstance->generateCredentials('<PROJECT_ID>', $request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

getClaimedCredentials

Returns claimed credentials in the specified time range.

Parameters

projectId string Required
Project ID.
configurationId string Required
Issuance configuration ID.
rangeStartTime string Optional
Start of the time range.
rangeEndTime string Optional
End of the time range.
exclusiveStartKey string Optional
Base64url-encoded pagination key.
limit integer Optional
Maximum number of records to return.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\CredentialsApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->getClaimedCredentials(
        '<PROJECT_ID>',
        '<CONFIG_ID>',
        '<START_DATE>',
        '<END_DATE>',
        null,
        20
    );
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

Default API

Revoke a revocable Verifiable Credentials issued to the users.

changeCredentialStatus

Updates the status of a credential (for example, REVOKED).

Parameters

projectId string Required
Project ID from which the credential was issued.
configurationId string Required
Configuration ID from which the credential was issued.
changeCredentialStatusInput ChangeCredentialStatusInput Required
Change reason and issuance record ID.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\DefaultApi(new GuzzleHttp\Client(), $config);

try {
    $request = array(
        'changeReason' => 'INVALID_CREDENTIAL',
        'issuanceRecordId' => '<RECORD_ID>',
    );
    $result = $apiInstance->changeCredentialStatus('<PROJECT_ID>', '<CONFIG_ID>', $request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

listIssuanceDataRecords

Retrieves the list of records for revocable credentials, including record IDs that can be used to revoke credentials.

Parameters

projectId string Required
Project ID from which the credentials were issued.
configurationId string Required
Configuration ID from which the credentials were issued.
limit integer Optional
Maximum number of records to return.
exclusiveStartKey string Optional
Base64url-encoded pagination key.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\DefaultApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->listIssuanceDataRecords('<PROJECT_ID>', '<CONFIG_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

Offer API

Used to get the credential offer initiated by the Issuance API.

getCredentialOffer

Retrieves the credential offer details.

Parameters

projectId string Required
Project ID.
issuanceId string Required
ID of the initiated issuance.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\OfferApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->getCredentialOffer('<PROJECT_ID>', '<ISSUANCE_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

WellKnown API

Used to get the WellKnown OpenID Credential Issuer information.

getWellKnownOpenIdCredentialIssuer

Retrieves the credential issuer well-known configurations.

Parameters

projectId string Required
Project ID.

Example

require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\CredentialIssuanceClient;

$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = CredentialIssuanceClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new CredentialIssuanceClient\Api\WellKnownApi(new GuzzleHttp\Client(), $config);

try {
    $result = $apiInstance->getWellKnownOpenIdCredentialIssuer('<PROJECT_ID>');
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}