NanoShutter is a simplified implementation of the Shutter Network protocol designed specifically for hackathons and educational purposes. It provides a lightweight framework for developers to integrate time-locked encryption into their decentralized applications (DApps) or other projects without the complexity of the full Shutter protocol. It's fully centralized and unsafe to use in any kind of production environment.
NanoShutter allows you to encrypt messages or transactions that can only be decrypted after a certain time (epoch), enabling use cases like front-running protection, sealed-bid auctions, or fair multiplayer games.
- Introduction
- Features
- API Endpoints
- Getting Started
- Configuration
- Usage
- Development
- Contributing
- License
NanoShutter offers a simplified version of Shutter Network for developers to quickly prototype and learn. It is a Go-based API server providing encryption and decryption capabilities through four RESTful endpoints. These endpoints use time-based or custom epochs to manage cryptographic operations securely.
- Time-Based Encryption/Decryption: Encrypt messages that can only be decrypted after a certain time.
- Custom Epoch Encryption/Decryption: Users can specify custom epochs for cryptographic operations.
- REST API Interface: Four straightforward API endpoints to interact with.
- Lightweight and Hackathon-Friendly: Simplified setup, perfect for experimentation and learning.
The NanoShutter API provides four main endpoints:
-
Time-Based Encryption:
/encrypt/with_time
- Encrypts a message for a future decryption, based on a timestamp in the future.
-
Time-Based Decryption:
/decrypt/with_time
- Decrypts a message after the specified time has elapsed.
-
Custom Epoch Encryption:
/encrypt/custom
- Encrypts a message using a custom epoch ID provided by the user.
-
Custom Epoch Decryption:
/decrypt/custom
- Decrypts a message based on a custom epoch ID.
We provide the following testing URLs that you can use to interact with the NanoShutter API without needing to deploy your own:
-
Time-Based Encryption/Decryption
https://nanoshutter.staging.shutter.network/encrypt/with_time
https://nanoshutter.staging.shutter.network/decrypt/with_time
-
Custom Epoch Encryption/Decryption
https://nanoshutter.staging.shutter.network/encrypt/custom
https://nanoshutter.staging.shutter.network/decrypt/custom
NanoShutter is an ideal tool for experimenting with time-locked encryption in various hackathon scenarios. Below are some ideas to inspire you at your next hackathon:
- Build games like Rock Paper Scissors, where players commit their moves and decrypt them simultaneously using NanoShutter, ensuring fairness.
- Create a decentralized auction where bids are encrypted and revealed only after a specific time, using the NanoShutter API for transparent and fair bidding.
- Integrate NanoShutter into a decentralized exchange (DEX) to enable front-running protection by encrypting trades before they are submitted for execution.
- Develop a privacy-focused negotiation tool that allows individuals to submit encrypted salary offers that are revealed after both parties have committed, ensuring transparency and fairness.
- Build a simple voting application where votes are encrypted until the voting period ends, enabling privacy-preserving decision-making in decentralized environments.
- Use NanoShutter to create a platform for releasing premium content (e.g., music, art) only after a certain time or when conditions are met, enabling timed exclusive access.
- Create a platform for charitable donations where donation amounts are encrypted and revealed only after the campaign ends, preventing strategic donations and promoting fairness.
- Design a trivia game where questions and answers are encrypted, and participants reveal their answers simultaneously after the question is closed, maintaining fairness and fun.
These hackathon ideas are just starting points. Feel free to modify, combine, or expand on them to create unique and impactful projects using NanoShutter!
If you want to start quickly without setting up your own API server, you can use the provided endpoints:
- Use any REST client (e.g., Postman, Insomnia, or cURL) to interact with the NanoShutter endpoints.
- Send POST requests to the provided URLs with the required JSON body (see examples in Usage).
- Decrypt the messages when the required time or epoch conditions are met.
This is the fastest way to get started and understand how NanoShutter works without dealing with infrastructure setup.
If you want to operate your own instance of the NanoShutter API, follow these steps:
- Go (version 1.16 or higher)
- Docker (optional, for containerized deployment)
-
Clone the Repository:
git clone https://github.com/your-username/nanoshutter.git cd nanoshutter/api
-
Install Dependencies:
Use
go mod
to install required Go modules:go mod tidy
-
Environment Configuration:
Copy
.env.example
to.env
and modify environment variables as needed:cp .env.example .env
-
Run the Server:
go run main.go
By default, the server runs on
http://localhost:8080
.
-
Build Docker Image:
docker build -t nanoshutter .
-
Run the Docker Container:
docker-compose up -d
This will start the NanoShutter service on the specified port defined in the
docker-compose.yml
.
Use the .env
file to configure the application settings, such as:
- PORT: The port on which the service runs.
PORT=8080
Send a POST request to /encrypt/with_time
with the message and timestamp to encrypt (e.g. 60 seconds in the future).
Request Body Example:
{
"cypher_text": "This is a secret message",
"timestamp": 1696787387
}
Response Example:
{
"message": "encrypted_hex_string"
}
Send a POST request to /decrypt/with_time
with the encrypted message and the same timestamp used previously.
Request Body Example:
{
"encrypted_msg": "encrypted_hex_string",
"timestamp": 1696787387
}
Response Example:
{
"message": "This is a secret message"
}
Send a POST request to /encrypt/custom
with the message and a custom epoch ID.
Request Body Example:
{
"cypher_text": "Custom epoch secret message",
"epoch_id": "12345"
}
Response Example:
{
"message": "encrypted_hex_string"
}
Send a POST request to /decrypt/custom
with the encrypted message and epoch ID.
Request Body Example:
{
"encrypted_msg": "encrypted_hex_string",
"epoch_id": "12345"
}
Response Example:
{
"message": "Custom epoch secret message"
}
main.go
: The main entry point of the service.service/service.go
: Implements core business logic for the encryption/decryption API.router/router.go
: Defines the HTTP routes and handlers.dkg/dkg.go
: Handles Distributed Key Generation (DKG) functionality.internal/error/error.go
: Centralized error handling.internal/middleware/error.go
: Middleware for handling request errors.- Docker and
.env
Files: To assist with containerized deployments.
To deploy the service using Docker:
-
Build and Run Using Docker Compose:
docker-compose up --build
This will build the image and run the container.
Contributions are welcome! Please follow these steps:
-
Fork the Project
-
Create a Branch
git checkout -b feature/your-feature-name
-
Commit Your Changes
git commit -m "Add your feature"
-
Push to Branch
git push origin feature/your-feature-name
-
Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.