# Pay Money Project Documentation
## Overview
**Pay Money** is a peer-to-peer cryptocurrency-to-fiat exchange platform. It allows users to create offers for selling specific tokens at a certain price. These offers are registered on the backend, and when another user decides to accept an offer, the backend generates the transfer parameters. The buyer has one hour to complete a fiat payment via Revolut and notarize the transfer to confirm it. Once the transfer is notarized and verified, the backend reveals the cryptocurrency for the buyer who made the fiat payment.
The core technology used in this project is **TLS Notary**, which ensures the security and authenticity of the transfer and verification process.
## Features
- **Offer Creation**: Users can create offers to sell tokens at specified prices, including network and token parameters.
- **Offer Registration**: Offers are registered on the backend, making them available for other users to fill.
- **Transfer Generation**: When a user wants to fill an offer, the backend generates the transfer parameters for the fiat-to-crypto exchange.
- **Notarization Process**: The buyer has 1 hour to send the fiat payment through Revolut and notarize the transfer.
- **Cryptocurrency Release**: After notarizing the transfer, the backend verifies it and releases the cryptocurrency to the user who made the fiat payment.
- **Security with TLS Notary**: The system ensures the integrity and security of the fiat payment process using TLS Notary.
## Core Technology
### TLS Notary
TLS Notary provides a framework for notarizing the transaction of a fiat payment made through Revolut. It allows the user to prove that the payment took place without revealing sensitive information about the transfer.
- Official Documentation: [TLS Notary Documentation](https://docs.tlsnotary.org)
### Revolut
Revolut is used as the fiat payment method. Users must send the transfer via Revolut with the correct parameters to ensure that the transaction is verified properly.
## Workflow
1. **Create an Offer:**
- The user specifies the network, token, and price they want to sell their tokens for.
- The offer is registered on the backend, and other users can see it.
2. **Accept an Offer:**
- A buyer selects the offer they want to fill.
- The backend generates the transfer parameters for the user, which includes information such as the payment amount and recipient details.
3. **Complete the Fiat Payment:**
- The buyer sends the payment via Revolut, ensuring that the transaction follows the generated transfer parameters.
4. **Notarize the Transfer:**
- The buyer has 1 hour to notarize the transfer by submitting the transaction proof via the Pay Money app.
- TLS Notary ensures that the transfer data is securely captured, including the payment details, without revealing sensitive information.
5. **Verify and Release Cryptocurrency:**
- After the transfer is notarized, the backend verifies the transaction and confirms that the payment has been successfully made.
- Once verified, the backend releases the cryptocurrency to the buyer.
## Security
- **TLS Notary**: Ensures secure and verifiable transfer of payment details without revealing sensitive information.
- **Payment Confirmation**: The system uses a notarization mechanism to confirm the fiat payment, ensuring that only successful payments result in cryptocurrency release.
## Future Work
- **Token Support Expansion**: Support for additional tokens and networks to make the platform more flexible.
- **Improved Notarization Flow**: Enhance the process of notarizing transfers with added support for more payment methods.
- **Mobile Application**: Develop a mobile version of the Pay Money app for easier use and transfer verification on the go.
## Conclusion
Pay Money is a secure and efficient platform for peer-to-peer cryptocurrency-to-fiat exchanges, leveraging the power of TLS Notary to provide secure payment verification without compromising user privacy. By utilizing Revolut for fiat transfers and implementing a robust notarization process, Pay Money ensures that both parties in a transaction are protected and that the cryptocurrency is only released after successful fiat payment confirmation.
---
# API Endpoints Documentation
## Authentication
All endpoints require authentication unless specified otherwise.
## Endpoints
### 1. Get Welcome Message
**GET /**
Returns a welcome message for the authenticated user.
**Response:**
```json
{
"message": "Hello, World private! - {userId}"
}
```
### 2. Create Offer
**POST /offers**
Creates a new offer to sell tokens.
**Request Body:**
```json
{
"amount": 100,
"fee": 2,
"cryptoType": "ETH",
"currency": "USD",
"pricePerUnit": 2000,
"value": 2000,
"offerType": "buy",
"revTag": "rev123"
}
```
**Response:**
- Status: 200 OK
### 3. Create Transaction
**POST /transactions**
Creates a new transaction based on an existing offer.
**Request Body:**
```json
{
"offerId": "12345",
"amount": 100,
"cryptoType": "ETH",
"pricePerUnit": 2000,
"currency": "USD",
"takerFee": 1.5,
"makerFee": 2,
"value": 2000
}
```
**Response:**
```json
{
"transactionId": "abcd1234",
"status": "pending"
}
```
### 4. Confirm Deposit
**POST /deposit**
Confirms a deposit by checking a Revolut transfer and updating the balance.
**Request Body:**
```json
{
"tx_hash": "0xabc12345"
}
```
**Response:**
- Status: 200 OK
### 5. Withdraw Funds
**POST /withdraw**
Handles user withdrawal requests by updating the balance and sending the transaction.
**Request Body:**
```json
{
"address": "0xaddress123",
"amount": 50
}
```
**Response:**
- Status: 200 OK
### 6. Get Fee Information
**POST /fee**
Retrieves the aggregated fee for a specific offer.
**Request Body:**
```json
{
"offer_id": "12345"
}
```
**Response:**
```json
{
"fee": 5
}
```
### 7. Get User Balance
**GET /balance**
Gets the current balance of the authenticated user.
**Response:**
```json
{
"balance": 1000
}
```
### 8. Get User Offers
**GET /user/offers**
Gets the current open offers for the authenticated user.
**Response:**
```json
[
{
"offerId": "12345",
"amount": 100,
"cryptoType": "ETH",
"currency": "USD",
"pricePerUnit": 2000,
"status": "open"
}
]
```
### 9. Delete Offer
**DELETE /user/offers/{id}**
Deletes an offer by its ID.
**Response:**
- Status: 204 No Content
### 10. Get User Transactions
**GET /user/transactions**
Retrieves all transactions for the authenticated user.
**Response:**
```json
[
{
"transactionId": "abcd1234",
"value": 2000,
"currency": "USD",
"status": "pending"
}
]
```
### 11. Get Token Information
**GET /token-info**
Retrieves token information like symbol and decimals for the supported token.
**Response:**
```json
{
"token_address": "0xabcdef12345",
"token_symbol": "ETH",
"token_decimals": 18
}
```
## Error Handling
All endpoints may return error responses in the following format:
```json
{
"error": "Error description"
}
```
**Common Error Codes:**
- Insufficient balance
- Transaction not found
- Offer not found
- Invalid private key
- Failed transaction confirmation