# BiDirectionalPaymentChannel

## Overview

The `BiDirectionalPaymentChannel` contract is designed to manage a two-way payment channel between two parties.&#x20;

This type of channel allows these parties to conduct numerous transactions with each other off-chain, with the final settlement occurring on the Ethereum blockchain.

The primary advantage of this approach is the significant reduction in transaction fees and improved efficiency, as only two transactions (channel opening and closing) are recorded on the blockchain, regardless of the number of off-chain transactions conducted.

## Methods

## <mark style="color:blue;">`verify`</mark>

Checks whether the provided signatures are valid for the given contract state (balances and nonce).

### Parameters

| Name          | Type                | Description                                       |
| ------------- | ------------------- | ------------------------------------------------- |
| `_signatures` | `bytes[2] memory`   | Array of cryptographic signatures from the users. |
| `_contract`   | `address`           | Address of this contract.                         |
| `_signers`    | `address[2] memory` | Array of addresses of the signers.                |
| `_balances`   | `uint[2] memory`    | Proposed balances of the users in the channel.    |
| `_nonce`      | `uint`              | Nonce associated with the current state.          |

### Returns

| Name | Type   | Description                                                                        |
| ---- | ------ | ---------------------------------------------------------------------------------- |
| -    | `bool` | Returns `true` if the signatures are valid for the given state, otherwise `false`. |

## <mark style="color:blue;">`challengeExit`</mark>

Allows a user to propose a new state (balances and nonce) for the channel, secured by their signatures.

### Parameters

| Name          | Type              | Description                                                         |
| ------------- | ----------------- | ------------------------------------------------------------------- |
| `_balances`   | `uint[2] memory`  | Proposed balances of the users in the challenge.                    |
| `_nonce`      | `uint`            | Nonce associated with the challenge state.                          |
| `_signatures` | `bytes[2] memory` | Array of cryptographic signatures from the users for the challenge. |

## <mark style="color:blue;">`withdraw`</mark>

Enables a user to withdraw their balance from the contract after the challenge period has expired.
