> ## Documentation Index
> Fetch the complete documentation index at: https://docs.train.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# HKDF

> Describes HMAC-based Key Derivation Function(HKDF) usage in TRAIN

Train uses HKDF (HMAC-based Key Derivation Function) to generate deterministic and secure secrets for atomic swaps.
HKDF is a standardized key-derivation algorithm, which lets us turn one signature into any number of unique, swap-specific secrets.
If you are not familiar with HKDF you can consider it as just hashing.

**1. User Sign**

The users signs the message `I am using Train`.

**2. Initial Key**

`initial_key = HKDF-Extract(signature)`
This key is cached locally by the dApp, as long as the cache persists, more signatures are not needed.

**3. Derive secret**

`secret = HKDF-Expand(initial_key, salt = (source_chain, destination_chain, timelock))`
For each swap, dapp derives a new secret using initial\_key, and the salt.

### Advanatges of HKDF derived secrets.

* **Deterministic**: The dApp can always recompute the secret as salt is not random, but is based on public data from the blockchain.
* **Unique**: Even if two swaps involve the same user, they will have different secrets because the salts differ.
* **No user Friction**: The user signs only once, and the dapp produces unlimited secrets from that one signature.
* **Recoverable**: If the cached initial\_key is lost, the user can simply sign the same message again and regenerate the identical initial key.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.