# Wallets

> Manage Digital Wallet with Wallets Service.

## Install Dependency

Package: affinidi-tdk/affinidi-tdk-php

```bash
composer require affinidi-tdk/affinidi-tdk-php
```

Check the latest version on the [Packagist repository](https://packagist.org/packages/affinidi-tdk/affinidi-tdk-php) or view the source on [GitHub](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient).

## Classes and Methods

### Wallet API

Used to manage digital wallets for issuing credentials.

#### createWallet

Creates a wallet by type.

Parameters

    createWalletInput
    [CreateWalletInput](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/CreateWalletInput.md)
    Required
  Wallet name, description, and DID method.

Example

```php
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

```php
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('');
} 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

```php
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('');
    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

```php
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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/SignCredentialInputDto.md)
    Required
  Credential data, revocability flag, and credential parameters.

Example

```php
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('', $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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/SignJwtToken.md)
    Required
  JWT header and payload to sign.

Example

```php
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('', $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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/UpdateWalletInput.md)
    Required
  Updated wallet name and description.

Example

```php
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' => '',
        'description' => '',
    );
    $result = $apiInstance->updateWallet('', $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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/CreateWalletKeyInput.md)
    Required
  Key type and verification relationships.

Example

```php
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('', $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

```php
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('');
    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

```php
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('', '');
} 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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/UpdateWalletKeyInput.md)
    Required
  Updated verification relationships.

Example

```php
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('', '', $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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/ServiceEndpointInput.md)
    Required
  Service endpoint name, URL, and type.

Example

```php
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('', $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

```php
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('');
    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

```php
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('', '');
} 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](https://github.com/affinidi/affinidi-tdk-php/tree/main/src/Clients/WalletsClient/docs/Model/UpdateServiceEndpointInput.md)
    Required
  Updated service endpoint details.

Example

```php
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('', '', $input);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}
```
