Credential Issuance
Install Dependency
Package: affinidi-tdk/affinidi-tdk-php
composer require affinidi-tdk/affinidi-tdk-phpCheck 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
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
RequiredExample
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
RequiredExample
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
RequiredExample
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
RequiredprojectId
string
RequiredExample
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
RequiredExample
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
RequiredExample
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
RequiredExample
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
RequiredExample
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
RequiredconfigurationId
string
RequiredrangeStartTime
string
OptionalrangeEndTime
string
OptionalexclusiveStartKey
string
Optionallimit
integer
OptionalExample
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
RequiredconfigurationId
string
RequiredExample
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
RequiredconfigurationId
string
Requiredlimit
integer
OptionalexclusiveStartKey
string
OptionalExample
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
RequiredissuanceId
string
RequiredExample
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
RequiredExample
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;
}Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.