# VGS Tokenization Configuration

This section outlines how to configure `VGSTextField` to create aliases (tokenize data) using the VGS Vault API.

## Inbound Route setup

To begin using the Vault API with the VGS Collect SDK, you must first establish an [Inbound connection](https://docs.verygoodsecurity.com/vault/http-proxy/inbound-connection).\
Navigate to the [Dashboard](https://dashboard.verygoodsecurity.com) and create a new **Inbound Route**. Configure the **Upstream Host** to forward requests to your preferred Vault API ([v1](https://docs.verygoodsecurity.com/vault/developer-tools/apis/vault-api-v1) or [v2)](https://docs.verygoodsecurity.com/vault/developer-tools/apis/vault-api).

## Tokenization Configurations

To tokenize data from `VGSTextField`, use one of the available tokenization configuration types:

| Field Type        | Tokenization Configuration Type            |
| ----------------- | ------------------------------------------ |
| `.cardNumber`     | VGSCardNumberTokenizationConfiguration     |
| `.cvc`            | VGSCVCTokenizationConfiguration            |
| `.expDate`        | VGSExpDateTokenizationConfiguration        |
| `.cardHolderName` | VGSCardHolderNameTokenizationConfiguration |
| `.ssn`            | VGSSSNTokenizationConfiguration            |
| `.date`           | VGSDateTokenizationConfiguration           |
| `.none`           | VGSTokenizationConfiguration               |

These configurations extend [VGSConfiguration](https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/ios-sdk/configuration) and introduce additional `tokenizationParameters` required for interacting with the Vault API.

```swift
/// `VGSTokenizationConfiguration` - Generic configuration for fields with arbitrary data. Required for Vault API usage.
public class VGSTokenizationConfiguration: VGSConfiguration {
  
  /// `VGSTokenizationParameters` - Tokenization parameters configuration.
  public var tokenizationParameters = VGSTokenizationParameters()
}
```

> Some advanced features such as fieldName policies are not supported by the Vault API.

### Tokenization Parameters

`VGSTokenizationParametersProtocol` defines the parameters required to describe how field input should be tokenized:

```swift
/// Describes tokenization behavior for text field input.
public protocol VGSTokenizationParametersProtocol {
  ///  The format of the tokenized alias.
  var format: String { get }
  /// The storage type (PERSISTENT or VOLATILE).
  var storage: String  { get }
}
```

### Tokenization format

The tokenization format defines how the alias will appear in the response.\
Each field has a default format set by the SDK, which can be overridden if necessary.

| Field Type        | Default Format          |
| ----------------- | ----------------------- |
| `.cardNumber`     | `FPE_SIX_T_FOUR`        |
| `.cvc`            | `NUM_LENGTH_PRESERVING` |
| `.expDate`        | `UUID`                  |
| `.cardHolderName` | `UUID`                  |
| `.ssn`            | `UUID`                  |
| `.date`           | `UUID`                  |
| `.none`           | `UUID`                  |

### Tokenization storage

VGS supports two storage types: `PERSISTENT` and `VOLATILE`.\
Available values are defined in the `VGSVaultStorageType` enum.

| Field Type        | Default Storage |
| ----------------- | --------------- |
| `.cardNumber`     | PERSISTENT      |
| `.cvc`            | VOLATILE        |
| `.expDate`        | PERSISTENT      |
| `.cardHolderName` | PERSISTENT      |
| `.ssn`            | PERSISTENT      |
| `.date`           | PERSISTENT      |
| `.none`           | PERSISTENT      |

> While most fields allow you to customize storage type, this setting cannot be changed for `.cvc` and `.cardNumber`.

### Code example

```swift
/// Use VGSCVCTokenizationConfiguration with predefined tokenization parameters
let cvcConfiguration = VGSCVCTokenizationConfiguration(collector: vgsCollect, fieldName: "card_cvc")
cvcCardNum.configuration = cvcConfiguration

/// Use VGSCardNumberTokenizationConfiguration and override tokenization format
let cardConfiguration = VGSCardNumberTokenizationConfiguration(collector: vgsCollect, fieldName: "card_number")
cardConfiguration.tokenizationParameters.format = VGSVaultAliasFormat.UUID.rawValue
cardNumber.configuration = cardConfiguration
```

See also:

* [Tokenize Data](https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/ios-sdk/submit-data)
* [UI Components](https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/ios-sdk/ui-components)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/vgs-collect/ios-sdk/tokenization-configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
