Wallets

Manage Digital Wallet with Wallets 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

Wallet API

Used to manage digital wallets for issuing credentials.

createWallet

Creates a wallet by type.

Parameters

createWalletInput CreateWalletInput Required
Wallet name, description, and DID method.

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 Required
ID of the wallet to delete.

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 {
    $apiInstance->deleteWallet('<WALLET_ID>');
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

getWallet

Retrieves the details of a wallet.

Parameters

walletId string Required
ID of the wallet to retrieve.

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->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 Required
ID of the wallet used for signing.
signCredentialInputDto SignCredentialInputDto Required
Credential data, revocability flag, and credential 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(
        '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 Required
ID of the wallet used for signing.
signJwtToken SignJwtToken Required
JWT header and payload to sign.

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(
        '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 Required
ID of the wallet to update.
updateWalletInput UpdateWalletInput Required
Updated wallet name and description.

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' => '<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:web wallets.

Parameters

walletId string Required
ID of the wallet to add a key to.
createWalletKeyInput CreateWalletKeyInput Required
Key type and verification relationships.

Example

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:web wallets.

Parameters

walletId string Required
ID of the wallet.

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->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:web wallets.

Parameters

walletId string Required
ID of the wallet.
keyId string Required
Wallet-scoped key identifier.

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 {
    $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:web wallets.

Parameters

walletId string Required
ID of the wallet.
keyId string Required
Wallet-scoped key identifier to update.
updateWalletKeyInput UpdateWalletKeyInput Required
Updated verification relationships.

Example

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 Required
ID of the wallet.
serviceEndpointInput ServiceEndpointInput Required
Service endpoint name, URL, and type.

Example

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 Required
ID of the wallet.

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->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 Required
ID of the wallet.
serviceId string Required
ID of the service endpoint to remove.

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 {
    $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 Required
ID of the wallet.
serviceId string Required
ID of the service endpoint to update.
updateServiceEndpointInput UpdateServiceEndpointInput Required
Updated service endpoint details.

Example

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;
}