# Wallets

> Manage Digital Wallet with Wallets Service.

## Install Dependency

Package: affinidi_tdk_wallets_client

```bash
pip install affinidi_tdk_wallets_client
```

Check the latest version on the [PyPI repository](https://pypi.org/project/affinidi_tdk_wallets_client/) or view the source on [GitHub](https://github.com/affinidi/affinidi-tdk/tree/main/clients/python/wallets_client).

## Classes and Methods

### Wallet API

Used to manage digital wallets for issuing credentials.

#### create_wallet

Creates a wallet by type.

Parameters

    create_wallet_input
    [CreateWalletInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/CreateWalletInput.md)
    Optional
  Details for the wallet to create, including optional name, description, and DID method.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    new_wallet_json = {
        'name': 'Wallet Name',
        'description': 'Description',
        'didMethod': 'key',
    }

    create_wallet_input = affinidi_tdk_wallets_client.CreateWalletInput.from_dict(new_wallet_json)
    api_response = api_instance.create_wallet(create_wallet_input=create_wallet_input)
```

#### delete_wallet

Deletes a wallet by ID.

Parameters

    walletId
    str
    Required
  ID of the wallet to delete.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_instance.delete_wallet('')
```

#### get_wallet

Retrieves the details of a wallet.

Parameters

    walletId
    str
    Required
  ID of the wallet to retrieve.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_response = api_instance.get_wallet('')
```

#### list_wallets

Returns the list of wallets in the project.

No parameters required.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_response = api_instance.list_wallets()
```

#### sign_credential

Signs a credential with the wallet’s DID document.

Parameters

    walletId
    str
    Required
  ID of the wallet used for signing.

    sign_credential_input_dto
    [SignCredentialInputDto](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/SignCredentialInputDto.md)
    Required
  Credential data to sign, including unsigned credential and revocation flag.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    sign_credential_json = {
        'unsigned_credential': {},
        'revocable': True,
        'unsigned_credential_params': {
            'json_ld_context_url': '',
            'json_schema_url': '',
            'type_name': '',
            'credential_subject': '',
            'holder_did': '',
            'expires_at': '',
        },
    }

    sign_credential_input_dto = affinidi_tdk_wallets_client.SignCredentialInputDto.from_dict(sign_credential_json)
    api_response = api_instance.sign_credential('', sign_credential_input_dto)
```

#### sign_jwt_token

Signs a JSON Web Token with the wallet’s DID document.

Parameters

    walletId
    str
    Required
  ID of the wallet used for signing.

    sign_jwt_token
    [SignJwtToken](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/SignJwtToken.md)
    Required
  JWT header and payload to sign.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    sign_jwt_token_json = {
        'header': {},
        'payload': {},
    }

    sign_jwt_token = affinidi_tdk_wallets_client.SignJwtToken.from_dict(sign_jwt_token_json)
    api_response = api_instance.sign_jwt_token('', sign_jwt_token)
```

#### update_wallet

Updates an existing wallet by ID.

Parameters

    walletId
    str
    Required
  ID of the wallet to update.

    update_wallet_input
    [UpdateWalletInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/UpdateWalletInput.md)
    Required
  Updated name and description for the wallet.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    update_wallet_json = {
        'name': '',
        'description': '',
    }

    update_wallet_input = affinidi_tdk_wallets_client.UpdateWalletInput.from_dict(update_wallet_json)
    api_response = api_instance.update_wallet('', update_wallet_input)
```

#### create_wallet_key

Adds a cryptographic key to an existing wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

    walletId
    str
    Required
  ID of the wallet to add a key to.

    create_wallet_key_input
    [CreateWalletKeyInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/CreateWalletKeyInput.md)
    Required
  Key type and verification relationships.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    create_key_json = {
        'keyType': 'ed25519',
        'relationships': ['authentication', 'assertionMethod'],
    }

    create_wallet_key_input = affinidi_tdk_wallets_client.CreateWalletKeyInput.from_dict(create_key_json)
    api_response = api_instance.create_wallet_key('', create_wallet_key_input=create_wallet_key_input)
```

#### list_wallet_keys

Retrieves all keys associated with a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

    walletId
    str
    Required
  ID of the wallet.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_response = api_instance.list_wallet_keys('')
```

#### remove_wallet_key

Removes a key from a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

    walletId
    str
    Required
  ID of the wallet.

    keyId
    str
    Required
  Wallet-scoped key identifier (for example, key-1).

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_instance.remove_wallet_key('', 'key-1')
```

#### update_wallet_key

Updates the verification relationships of an existing wallet key.

Note: Multiple keys are only supported for did:web wallets.

Parameters

    walletId
    str
    Required
  ID of the wallet.

    keyId
    str
    Required
  Wallet-scoped key identifier (for example, key-1).

    update_wallet_key_input
    [UpdateWalletKeyInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/UpdateWalletKeyInput.md)
    Required
  Updated verification relationships for the key.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    update_key_json = {
        'relationships': ['authentication', 'keyAgreement'],
    }

    update_wallet_key_input = affinidi_tdk_wallets_client.UpdateWalletKeyInput.from_dict(update_key_json)
    api_response = api_instance.update_wallet_key('', 'key-1', update_wallet_key_input=update_wallet_key_input)
```

#### create_service_endpoint

Adds a DID service endpoint to a wallet’s DID document.

Parameters

    walletId
    str
    Required
  ID of the wallet.

    service_endpoint_input
    [ServiceEndpointInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/ServiceEndpointInput.md)
    Required
  Service endpoint URL, name, and type.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    service_endpoint_json = {
        'url': 'https://example.com/messaging',
        'name': 'My Messaging Service',
        'serviceType': 'DIDCommMessaging',
    }

    service_endpoint_input = affinidi_tdk_wallets_client.ServiceEndpointInput.from_dict(service_endpoint_json)
    api_response = api_instance.create_service_endpoint('', service_endpoint_input=service_endpoint_input)
```

#### list_service_endpoints

Retrieves all service endpoints associated with a wallet.

Parameters

    walletId
    str
    Required
  ID of the wallet.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_response = api_instance.list_service_endpoints('')
```

#### remove_service_endpoint

Removes a service endpoint from a wallet’s DID document.

Parameters

    walletId
    str
    Required
  ID of the wallet.

    serviceId
    str
    Required
  ID of the service endpoint to remove.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)
    api_instance.remove_service_endpoint('', '')
```

#### update_service_endpoint

Updates an existing service endpoint on a wallet.

Parameters

    walletId
    str
    Required
  ID of the wallet.

    serviceId
    str
    Required
  ID of the service endpoint to update.

    update_service_endpoint_input
    [UpdateServiceEndpointInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/python/wallets_client/docs/UpdateServiceEndpointInput.md)
    Required
  Updated service endpoint name and URL.

Example

```python
import affinidi_tdk_wallets_client

configuration = affinidi_tdk_wallets_client.Configuration()
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_wallets_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_wallets_client.WalletApi(api_client)

    update_service_json = {
        'name': 'Updated Service Name',
        'url': 'https://new-endpoint.example.com',
    }

    update_service_endpoint_input = affinidi_tdk_wallets_client.UpdateServiceEndpointInput.from_dict(update_service_json)
    api_response = api_instance.update_service_endpoint('', '', update_service_endpoint_input=update_service_endpoint_input)
```
