Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoW Faucet #16

Merged
merged 67 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b067746
Update Dockerfile
harryttd Jun 1, 2023
f761149
Use vite + update pkgs
harryttd Jun 1, 2023
4421f23
Fix Vite issues with nodejs modules
harryttd Jun 2, 2023
4e08f09
WIP VDF
harryttd Jun 12, 2023
2bcb5a0
Merge branch 'main' into vdf
harryttd Jun 12, 2023
e771ce7
WIP POW
harryttd Jun 23, 2023
0715cd1
Make pow cancel button work
harryttd Jun 23, 2023
e3f68f9
Working cancel button on Alert component
harryttd Jun 26, 2023
fbae0bb
Use type
harryttd Jun 26, 2023
e84e709
Disable address input form while loading
harryttd Jun 29, 2023
2237c43
Working multi challenges
harryttd Jun 29, 2023
28974a8
Some cleanup
harryttd Jun 29, 2023
9314086
Add types + cleanup
harryttd Jun 29, 2023
b435de7
Properly validate address + cleanup
harryttd Jun 30, 2023
37289a0
Add feedback to address form
harryttd Jun 30, 2023
2943766
Cleanup
harryttd Jun 30, 2023
1e98967
Update pow worker code
harryttd Jun 30, 2023
a42b81a
Cleanup vite config and package.json
harryttd Jun 30, 2023
87fe362
Display challenge counter + cleanup
harryttd Jul 1, 2023
bb3d398
npm audit fix
harryttd Jul 5, 2023
c2824d3
Add spinner for solving pow message
harryttd Jul 11, 2023
919249d
Working programmatic faucet script
harryttd Jul 13, 2023
5637903
Fix prod build issues
harryttd Jul 13, 2023
b948bd2
Make getTez script executable via import in file and also via CLI
harryttd Jul 17, 2023
22658e9
Only check 0's in solution
harryttd Jul 18, 2023
fb9d9e9
Rename value
harryttd Jul 18, 2023
8b9e9be
Add 5s timeout to axios reqs
harryttd Jul 18, 2023
e939713
Don't require captcha on verify endpoint
harryttd Jul 18, 2023
8a2f73e
Don't bundle package.json
harryttd Jul 25, 2023
afeb946
Misc cleanup
harryttd Jul 25, 2023
d70bcd9
Log error message in POW worker
harryttd Jul 25, 2023
7932967
Make build more efficient
harryttd Jul 25, 2023
fad3cf1
Use --noEmit flag for tsc
harryttd Jul 25, 2023
d3f4a6e
Cleanup packages
harryttd Jul 25, 2023
73401c6
Check if txHash exists before trying to write
harryttd Aug 1, 2023
8fc2dd1
Add error event listener on worker
harryttd Aug 2, 2023
b37594c
Move 'USER node' to top of Dockerfile'
harryttd Aug 4, 2023
f7d18ea
Update pkgs
harryttd Aug 4, 2023
7094f38
Add logic to log to terminal in dev
harryttd Aug 4, 2023
2625c99
npm i -D ts-node
harryttd Aug 8, 2023
aa55038
Don't rebuild application on every restart
harryttd Aug 9, 2023
d8263d5
Cleanup
harryttd Aug 9, 2023
0973578
npx npm-check-updates -u && npm i
harryttd Aug 9, 2023
f03ebc8
Some readme cleanup
harryttd Aug 9, 2023
a6a6dba
Cleanup + update .dockerignore
harryttd Aug 18, 2023
b798d6e
Keep button disabled if address isn't valid
harryttd Aug 18, 2023
028bf93
Map over profiles
harryttd Aug 18, 2023
687d6ff
Remove unnecessary profile field
harryttd Aug 18, 2023
70470c1
sort profiles by amount
harryttd Aug 18, 2023
70ca539
getTez.js: Add verbose flag + in place text update
harryttd Aug 18, 2023
4f5e847
Update package.json fields
harryttd Aug 21, 2023
21494a5
Add OxheadAlpha logo and links to header and footer
harryttd Aug 21, 2023
d8bb555
Better footer responsiveness
harryttd Aug 22, 2023
394a762
Add info about pow + captcha z-index + footer fixes
harryttd Aug 22, 2023
07f9469
Fix footer and move captcha to left side
harryttd Aug 22, 2023
98bebcb
Default show info + use secondary button variant
harryttd Aug 22, 2023
fb32bf0
Fix path to svg for built application
harryttd Aug 22, 2023
bfffad1
Handle if challenges are disabled
harryttd Aug 22, 2023
b8ddc3e
Make footer container fluid
harryttd Aug 23, 2023
3c560d4
Don't start loading until prompted captcha is solved
harryttd Aug 23, 2023
023659e
Keep header fixed and don't overlap it on scroll
harryttd Aug 23, 2023
8bc3dd9
update index.html
harryttd Aug 24, 2023
a64187a
Handle in getTez.js if challenges are disabled
harryttd Aug 24, 2023
be7bc78
WIP to update README
harryttd Aug 25, 2023
306cf59
npx npm-check-updates -i && npm i
harryttd Aug 25, 2023
84f7733
getTez.js: Add log 'by Oxhead Alpha...'
harryttd Aug 25, 2023
9128096
Merge branch 'main' into pow
harryttd Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
.dockerignore
.DS_Store
.env*
.git
.github
build
craco.config.ts
.gitignore
.vscode
dist
Dockerfile
LICENSE.md
node_modules
npm-debug.log
README.md
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM node:16-alpine as build
FROM node:20-alpine

USER node

WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH

RUN chown node:node /app

USER node
COPY --chown=node:node package.json ./
COPY --chown=node:node package-lock.json ./

RUN npm install

COPY --chown=node:node . ./

RUN npm install
RUN npm run build

CMD ["sh", "-c", "/app/entrypoint.sh" ]
74 changes: 38 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
# Tezos faucet
# Tezos Faucet Frontend

## Presentation

One-click faucet for Tezos.
A one-click faucet for Tezos, now enhanced with a PoW (Proof of Work) challenge to ensure secure and fair Tez distribution.

### Made with

- React
- Craco
- Typescript
- Vite
- React
- Bootstrap
- Taquito
- Beacon Wallet
- ReactBootstrap

## Overview

This front-end faucet is build on top of a backend (https://github.com/oxheadalpha/tezos-faucet-backend).
The faucet's backend code can be located at [tezos-faucet-backend](https://github.com/oxheadalpha/tezos-faucet-backend). The backend handles the faucet's private key, CAPTCHA secret, PoW challenge creation and solution verification, and the amounts of Tez sent.

Sent amounts and challenge details are configured via `profiles`. This enforces security, avoiding a user trying to change amounts in frontend javascript code and drying out the faucet. Two profiles are created by default: **user**, to get 1 xtz and **baker** to get 6000 xtz.

### Proof of Work (PoW) Challenge

To mitigate potential abuse and ensure a fair distribution of Tez, users are now required to solve computational challenges before receiving their Tez. This PoW mechanism discourages bots and other malicious actors from exploiting the faucet.

Backend handles:
- faucet private key
- captcha secret
- amounts sent
### Application Flow

Sent amounts are configured in backend, using a conf named `profiles`.
1. **Initiating the Process**: Upon a Tez request, the frontend communicates with the `/challenge` endpoint of the backend, providing essential details such as the user's address and the profile type.
2. **Receiving and Solving the Challenge**: The backend then sends a challenge. The difficulty and amount of challenges to be solved depends on factors such as if a CAPTCHA token was submitted and how much Tez was requested. The browser will create a webworker which will begin the process of finding a solution.
3. **Submitting and Verifying the Solution**: After solving, the frontend sends the solution to the `/verify` endpoint. The backend then checks its validity. Assuming it is valid, if more challenges are pending, the user proceeds to solve them. Once all challenges are cleared, Tez is sent to the user's account.

2 profiles are created: **User**, to get 1 xtz and **Backer** to get 6000 xtz.
## Programmatic Faucet Usage

Faucet calls backend using the target address and the given profile name. Then backend send as many xtz as configured on its side for the given profile.
We provide a [`getTez.js`](./scripts/getTez.js) script for programmatic faucet usage. This script can be run from a JavaScript program or directly from a shell.

This enforces security, avoiding user to change amount in front javascript code and dry out the faucet.
Please note that the `getTez.js` script does not use CAPTCHA. Therefore, challenges can be configured to make them more difficult and require more of them to be solved when using the programmatic faucet.

## Setup

To setup the faucet for a new network:

1. Update Beacon Wallet lib to make sure it will handle the new network.
1. Update Beacon Wallet lib to make sure it will handle the new network
2. Deploy a new instance of backend
3. Configure faucet to use backend
4. Deploy faucet


### 1. Update Beacon Wallet configuration for new network

Currently supported networks:
Currently supported networks include:

- Mainnet
- Ghostnet
- Mondaynet
- Dailynet
- Ghostnet
- Ithacanet
- Jakartanet
- Kathmandunet
- Nairobinet

To add a new network, first check that `@airgap/beacon-sdk` handles it ([check their config](https://github.com/airgap-it/beacon-sdk/blob/312226a3588eddd804044b52dfcf1d0512f1a9df/packages/beacon-types/src/types/beacon/NetworkType.ts)), then update:
To add a new network, first check that `@airgap/beacon-sdk` handles it ([check their config on the latest release](https://github.com/airgap-it/beacon-sdk/blob/v4.0.6/packages/beacon-types/src/types/beacon/NetworkType.ts)), then update:

```
npm i @airgap/beacon-sdk
Expand All @@ -68,34 +70,33 @@ See https://github.com/oxheadalpha/tezos-faucet-backend

**Application configuration:**

`name`: application name, displayed in header
- `name`: application name, displayed in header

`googleCaptchaSiteKey`: Google ReCAPTCHA public site key
- `googleCaptchaSiteKey`: Google ReCAPTCHA public site key

`backendUrl`: Base URL of backend to connect to.
- `backendUrl`: Base URL of faucet backend to connect to.

`githubRepo`: URL of Github repository (displayed in header with Github icon).
- `githubRepo`: URL of Github repository (displayed in header with Github icon).

`profiles`: backend profiles, must match backend configuration.
- `disableChallenges`: If PoW challenges need to be solved before receiving Tez. The backend must also disable challenges. Defaults to `false`.

-- `user`: user profile, to get a single XTZ
- `profiles`: backend profiles, must match backend configuration.

-- `baker`: baker profile, to get 6000 XTZ
- - `user`: user profile, to get 1 XTZ

-- -- `profile`: backend profile ID

-- -- `amount`: amount given for the profile, for display only.
- - `baker`: baker profile, to get 6000 XTZ

- - - `amount`: amount given for the profile, for display only.

**Network configuration:**

`name`: network name. Must match one of [@airgap/beacon-sdk NetworkType]((https://github.com/airgap-it/beacon-sdk/blob/312226a3588eddd804044b52dfcf1d0512f1a9df/packages/beacon-types/src/types/beacon/NetworkType.ts)) value (case insensitive). Also used to be displayed.
- `name`: network name. Must match one of [@airgap/beacon-sdk NetworkType](https://github.com/airgap-it/beacon-sdk/blob/v4.0.6/packages/beacon-types/src/types/beacon/NetworkType.ts) value (case insensitive). Also used to be displayed.

`rpcUrl`: Tezos network RPC endpoint to be used by faucet
- `rpcUrl`: Tezos network RPC endpoint to be used by faucet

`faucetAddress`: public Tezos address of faucet
- `faucetAddress`: public Tezos address of faucet

```viewer```: URL of a viewer that displays operation detail like `http://viewer-url.com/{tx_hash}` (eg. https://jakarta.tzstats.com)
- `viewer`: URL of a block explorer that displays operation detail like `http://viewer-url.com/{tx_hash}` (eg. https://ghost.tzstats.com)

### 4. Deploy

Expand All @@ -108,6 +109,7 @@ docker build . -t tezos-faucet
```

Run Docker image:

```
docker run -p 8080:8080 tezos-faucet
```
61 changes: 0 additions & 61 deletions craco.config.ts

This file was deleted.

12 changes: 8 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh
set -e
# We need to buid because the configuration file may be modified at runtime.
npm run build
set -ex

serve -s build -p 8080
# Validate the application's config.json. This includes a ts compilation that
# validates the config's structure. It may have custom settings and was mounted
# to the container in /public. Once validated, move it to /build to be served.
npm run check-config
cp ./public/config.json ./build/config.json

serve build --single -p 8080 --no-port-switching
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="tezos, faucet, testnet, teztnet, ghostnet, mondaynet, dailynet, blockchain">
<meta name="description" content="Get Free Tez for Tezos Networks">
<link rel="shortcut icon" id="favicon" href="favicon.ico">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web">

<title>Tezos Faucet</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>

</html>
Loading
Loading