# Wallets

> Manage Digital Wallet with Wallets Service.

## Install Dependency

Package: @affinidi-tdk/wallets-client

```bash
npm install @affinidi-tdk/wallets-client --save
```

Check the latest version on the [npm registry](https://www.npmjs.com/package/@affinidi-tdk/wallets-client) or view the source on [GitHub](https://github.com/affinidi/affinidi-tdk/tree/main/clients/typescript/wallets-client).

## Classes and Methods

### Wallet API

Manages digital wallets for issuing and signing credentials.

#### createWallet

Creates a wallet by type.

Parameters

    request
    [CreateWalletInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/CreateWalletInput.md)
    Required
  Details of the wallet to create, including name, description, and didMethod ("key" or "web"). When didMethod is "web", didWebUrl is required.

Example

```typescript
import { WalletApi, Configuration, CreateWalletInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

// Create a did:key wallet
const request: CreateWalletInput = {
  name: 'Wallet Name',
  description: 'Description',
  didMethod: 'key',
}
const { data } = await api.createWallet(request)

// Create a did:web wallet — didWebUrl is required
const { data: webWallet } = await api.createWallet({ didMethod: 'web', didWebUrl: 'https://' })
```

#### deleteWallet

Deletes a wallet by ID.

Parameters

    walletId
    string
    Required
  ID of the wallet to delete.

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

await api.deleteWallet('')
```

#### getWallet

Retrieves the details of a wallet.

Parameters

    walletId
    string
    Required
  ID of the wallet to retrieve.

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const { data } = await api.getWallet('')
```

#### listWallets

Returns the list of wallets in the project.

No parameters required.

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const { data } = await api.listWallets()
```

#### signCredential

Signs a credential using the wallet’s DID document.

Parameters

    walletId
    string
    Required
  ID of the wallet used to sign the credential.

    request
    [SignCredentialInputDto](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/SignCredentialInputDto.md)
    Required
  Credential data to sign.

Example

```typescript
import { WalletApi, Configuration, SignCredentialInputDto } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const request: SignCredentialInputDto = {
  unsignedCredential: {},
  revocable: true,
  unsignedCredentialParams: {
    jsonLdContextUrl: '',
    jsonSchemaUrl: '',
    typeName: '',
    credentialSubject: '',
    holderDid: '',
    expiresAt: '',
  },
}

const { data } = await api.signCredential('', request)
```

#### signJwtToken

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

Parameters

    walletId
    string
    Required
  ID of the wallet used to sign the JWT.

    request
    [SignJwtToken](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/SignJwtToken.md)
    Required
  JWT header and payload data to sign.

Example

```typescript
import { WalletApi, Configuration, SignJwtToken } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const request: SignJwtToken = {
  header: {},
  payload: {},
}

const { data } = await api.signJwtToken('', request)
```

#### updateWallet

Updates an existing wallet by ID.

Parameters

    walletId
    string
    Required
  ID of the wallet to update.

    request
    [UpdateWalletInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/UpdateWalletInput.md)
    Required
  Updated wallet details.

Example

```typescript
import { WalletApi, Configuration, UpdateWalletInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const request: UpdateWalletInput = {
  name: '',
  description: '',
}

const { data } = await api.updateWallet('', request)
```

#### 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 the key to.

    request
    [CreateWalletKeyInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/CreateWalletKeyInput.md)
    Required
  Key type and verification relationships to assign.

Example

```typescript
import { WalletApi, Configuration, CreateWalletKeyInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const request: CreateWalletKeyInput = {
  keyType: 'ed25519',
  relationships: ['authentication', 'assertionMethod'],
}

const { data } = await api.createWalletKey('', request)
```

#### listWalletKeys

Retrieves all cryptographic keys associated with a wallet.

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

Parameters

    walletId
    string
    Required
  ID of the wallet.

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const { data } = await api.listWalletKeys('')
```

#### 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 (e.g. "key-1").

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

await api.removeWalletKey('', 'key-1')
```

#### 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 (e.g. "key-1").

    request
    [UpdateWalletKeyInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/UpdateWalletKeyInput.md)
    Required
  Updated verification relationships for the key.

Example

```typescript
import { WalletApi, Configuration, UpdateWalletKeyInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const request: UpdateWalletKeyInput = {
  relationships: ['authentication', 'keyAgreement'],
}

const { data } = await api.updateWalletKey('', 'key-1', request)
```

#### createServiceEndpoint

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

Parameters

    walletId
    string
    Required
  ID of the wallet.

    request
    [ServiceEndpointInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/ServiceEndpointInput.md)
    Required
  Service endpoint details including URL, name, and service type.

Example

```typescript
import { WalletApi, Configuration, ServiceEndpointInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

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

const { data } = await api.createServiceEndpoint('', request)
```

#### listServiceEndpoints

Retrieves all service endpoints associated with a wallet.

Parameters

    walletId
    string
    Required
  ID of the wallet.

Example

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

const { data } = await api.listServiceEndpoints('')
```

#### 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

```typescript
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

await api.removeServiceEndpoint('', '')
```

#### 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.

    request
    [UpdateServiceEndpointInput](https://github.com/affinidi/affinidi-tdk/blob/main/clients/typescript/wallets-client/docs/UpdateServiceEndpointInput.md)
    Required
  Updated service endpoint details.

Example

```typescript
import { WalletApi, Configuration, UpdateServiceEndpointInput } from '@affinidi-tdk/wallets-client'

const api = new WalletApi(
  new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)

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

const { data } = await api.updateServiceEndpoint('', '', request)
```
