The Swap Server provides a single JSON-RPC API with the method `swap`. This API is used by clients to initiate the mixing process for their outputs, obscuring their coin history in a transaction with other users.
## SWAP
### Request
The `swap` method accepts a single JSON object containing the following fields:
-`onion`: an `Onion` data structure, which is the encrypted onion packet containing the key information necessary to transform the user's output.
-`comsig`: a Commitment Signature that proves the client knows the secret key and value of the output's commitment.
#### `Onion` data structure
The `Onion` data structure consists of the following fields:
-`pubkey`: an ephemeral pubkey to as the onion originator's portion of the shared secret, represented as an `x25519_dalek::PublicKey`.
-`commit`: the Pedersen commitment before adjusting the excess and subtracting the fee, represented as a 33-byte `secp256k1` Pedersen commitment.
-`data`: a vector of encrypted payloads, each representing a layer of the onion. When completely decrypted, these are serialized `Payload` objects.
Each entry in the `enc_payloads` vector corresponds to a server in the system, in order, with the first entry containing the payload for the swap server, and the last entry containing the payload for the final mix server.
#### `Payload` data structure
A `Payload` represents a single, decrypted/peeled layer of an Onion. It consists of the following fields:
-`next_ephemeral_pk`: an `xPublicKey` representing the public key for the next layer.
-`excess`: a `SecretKey` representing the excess value.
-`fee`: a `FeeFields` value representing the transaction fee.
-`rangeproof`: an optional `RangeProof` value.
### Response
A successful call to the 'swap' API will result in an empty JSON-RPC response with no error.
In case of errors, the API will return a `SwapError` type with one of the following variants:
-`InvalidPayloadLength`: The provided number of payloads is invalid.
-`InvalidComSignature`: The Commitment Signature is invalid.
-`InvalidRangeproof`: The provided rangeproof is invalid.
-`MissingRangeproof`: A rangeproof is required but was not supplied.
-`CoinNotFound`: The output does not exist, or it is already spent.
-`AlreadySwapped`: The output is already in the swap list.
-`PeelOnionFailure`: Failed to peel onion layer due to an `OnionError`.
-`FeeTooLow`: The provided fee is too low.
-`StoreError`: An error occurred when saving swap to the data store.
-`ClientError`: An error occurred during client communication.