Skip to content

Commit

Permalink
Request Amount of Tez Within a Range + getTez Programmatic Faucet (#17)
Browse files Browse the repository at this point in the history
* Allow range of tez amount request. Remove profiles.

* getTez.js: Allow range of tez + option for timing challenges

* WIP getTez package

* Better typescript support for getTez

* getTez updates

* Validate amount + add comments

* getTez: Add license and readme + update package.json

* Implement progress bar + cleanup

* Cleanup UserInfo

* Use handleError function

* Cleanup

* Cleanup + fixes

* Use the same worker for all challenges

* Make the webworker inline

* Set worker event listeners before posting msg

* Validate worker args

* getTez: Log progress percentage

* Update readme

* getTez: Add timeouts to fetch requests
  • Loading branch information
harryttd authored Sep 29, 2023
1 parent 966fb16 commit cc4bdf1
Show file tree
Hide file tree
Showing 25 changed files with 1,060 additions and 602 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
build
dist

# misc
.DS_Store
Expand All @@ -21,3 +22,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.aider*
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 oxheadalpha
Copyright (c) 2023 Oxhead Alpha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ A one-click faucet for Tezos, now enhanced with a PoW (Proof of Work) challenge

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.

### Application Flow

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.
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 amount of Tez requested.
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.

## Programmatic Faucet Usage

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.
For programmatic usage of the faucet, we provide an npm package `@oxheadalpha/get-tez`. The code can be found [here](https://github.com/oxheadalpha/tezos-faucet/tree/main/getTez). Please refer to it for more details on how to use it. This script can be run from a JavaScript program or directly from a shell. It interacts with the backend to request Tez, solve the required challenges, and verify the solutions.

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.
Please note that the programmatic faucet code does not use CAPTCHA and so more challenges can be given when using it.

## Setup

Expand Down Expand Up @@ -80,13 +78,9 @@ See https://github.com/oxheadalpha/tezos-faucet-backend

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

- `profiles`: backend profiles, must match backend configuration.

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

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

- - - `amount`: amount given for the profile, for display only.
- `minTez`: The minimum amount of Tez that can be requested.
-
- `maxTez`: The maximum amount of Tez that can be requested.

**Network configuration:**

Expand Down
21 changes: 21 additions & 0 deletions getTez/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Oxhead Alpha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions getTez/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# get-tez

This zero dependency package provides a programmatic interface to interact with the [Tezos faucet](https://github.com/oxheadalpha/tezos-faucet-backend). It is a script that can be run from a JavaScript/Typescript program or directly from a shell.

## Installation

You can install the package from npm:

```bash
npm install @oxheadalpha/get-tez
```

## Usage

### JS / TS
After installing the package, you can import it in your Node.js JavaScript or TypeScript project:

```javascript
const getTez = require("@oxheadalpha/get-tez")

// OR

import getTez from "@oxheadalpha/get-tez"
```

You can then use the `getTez` function to interact with the Tezos faucet. The function takes an object as an argument, with the following properties:

- `address`: The address to send Tez to.
- `amount`: The amount of Tez to request.
- `network`: The faucet's network name. Must match a network name with a faucet listed at https://teztnets.xyz. Ignored if `faucetUrl` is set.
- `faucetUrl`: The custom faucet URL. Ignores `network`.

Here is an example of how to use the `getTez` function:

```javascript
const txHash = await getTez({
address: "tz1...",
amount: 10,
network: "ghostnet",
})
```

Example using the `faucetUrl` parameter:
```js
const txHash = await getTez({
address: "tz1...",
amount: 10,
faucetUrl: "https://my-custom-faucet-url.com",
})
```

### CLI

You can also run the script directly from the command line with Node.js. When you install the package via npm, the JavaScript file will be located at `node_modules/@oxheadalpha/get-tez/dist/getTez.js`. You can run it with the following command:

```bash
node node_modules/@oxheadalpha/get-tez/dist/getTez.js tz1... --amount 10 --network ghostnet
```

Run the script with the `--help` flag for more information.
Loading

0 comments on commit cc4bdf1

Please sign in to comment.