Wallets
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
Wallet API
Used to manage digital wallets for issuing credentials.
createWallet
Creates a wallet by type.
Parameters
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'name' => 'Wallet Name',
'description' => 'Description',
'didMethod' => 'key',
);
$result = $apiInstance->createWallet($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}deleteWallet
Deletes a wallet by ID.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$apiInstance->deleteWallet('<WALLET_ID>');
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}getWallet
Retrieves the details of a wallet.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->getWallet('<WALLET_ID>');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listWallets
Returns the list of wallets in the project.
No parameters required.
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listWallets();
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}signCredential
Signs a credential using the wallet’s DID document.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'unsignedCredential' => array(),
'revocable' => true,
'unsignedCredentialParams' => array(
'jsonLdContextUrl' => '',
'jsonSchemaUrl' => '',
'typeName' => '',
'credentialSubject' => '',
'holderDid' => '',
'expiresAt' => '',
),
);
$result = $apiInstance->signCredential('<WALLET_ID>', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}signJwtToken
Signs a JSON Web Token using the wallet’s DID document.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'header' => array(),
'payload' => array(),
);
$result = $apiInstance->signJwtToken('<WALLET_ID>', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updateWallet
Updates an existing wallet by ID.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'name' => '<NEW_NAME>',
'description' => '<NEW_DESCRIPTION>',
);
$result = $apiInstance->updateWallet('<WALLET_ID>', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}createWalletKey
Adds a cryptographic key to an existing wallet.
Note: Multiple keys are only supported for
did:webwallets.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
use AffinidiTdk\Clients\WalletsClient\Model\CreateWalletKeyInput;
use AffinidiTdk\Clients\WalletsClient\Model\VerificationRelationship;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$input = new CreateWalletKeyInput([
'key_type' => CreateWalletKeyInput::KEY_TYPE_ED25519,
'relationships' => [
VerificationRelationship::AUTHENTICATION,
VerificationRelationship::ASSERTION_METHOD,
],
]);
$result = $apiInstance->createWalletKey('<WALLET_ID>', $input);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listWalletKeys
Retrieves all keys associated with a wallet.
Note: Multiple keys are only supported for
did:webwallets.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listWalletKeys('<WALLET_ID>');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}removeWalletKey
Removes a key from a wallet.
Note: Multiple keys are only supported for
did:webwallets.
Parameters
walletId
string
RequiredkeyId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$apiInstance->removeWalletKey('<WALLET_ID>', '<KEY_ID>');
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updateWalletKey
Updates the verification relationships of an existing wallet key.
Note: Multiple keys are only supported for
did:webwallets.
Parameters
walletId
string
RequiredkeyId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
use AffinidiTdk\Clients\WalletsClient\Model\UpdateWalletKeyInput;
use AffinidiTdk\Clients\WalletsClient\Model\VerificationRelationship;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$input = new UpdateWalletKeyInput([
'relationships' => [
VerificationRelationship::AUTHENTICATION,
VerificationRelationship::KEY_AGREEMENT,
],
]);
$result = $apiInstance->updateWalletKey('<WALLET_ID>', '<KEY_ID>', $input);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}createServiceEndpoint
Adds a DID service endpoint to a wallet’s DID document.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
use AffinidiTdk\Clients\WalletsClient\Model\ServiceEndpointInput;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$input = new ServiceEndpointInput([
'name' => 'My Service',
'url' => 'https://example.com/service',
'service_type' => 'LinkedDomains',
]);
$result = $apiInstance->createServiceEndpoint('<WALLET_ID>', $input);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listServiceEndpoints
Retrieves all service endpoints associated with a wallet.
Parameters
walletId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listServiceEndpoints('<WALLET_ID>');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}removeServiceEndpoint
Removes a service endpoint from a wallet’s DID document.
Parameters
walletId
string
RequiredserviceId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$apiInstance->removeServiceEndpoint('<WALLET_ID>', '<SERVICE_ID>');
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updateServiceEndpoint
Updates an existing service endpoint on a wallet.
Parameters
walletId
string
RequiredserviceId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\WalletsClient;
use AffinidiTdk\Clients\WalletsClient\Model\UpdateServiceEndpointInput;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = WalletsClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new WalletsClient\Api\WalletApi(new GuzzleHttp\Client(), $config);
try {
$input = new UpdateServiceEndpointInput([
'url' => 'https://new-endpoint.example.com',
]);
$result = $apiInstance->updateServiceEndpoint('<WALLET_ID>', '<SERVICE_ID>', $input);
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.