-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f9159a
commit f0b87ae
Showing
1 changed file
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
![Elm package](https://img.shields.io/elm-package/v/cachix/elm-hashcash) | ||
|
||
Implements [HashCash](https://en.wikipedia.org/wiki/Hashcash) in Elm to | ||
prevent spammers abusing a resource. | ||
|
||
[Install devenv](https://devenv.sh/getting-started/) and `devenv shell`. | ||
HashCash hashes your data with a `sha256` and appends a nonce. | ||
|
||
It then verifies that the hash has N number of leading zeros, which is the difficulty level. | ||
|
||
If it doesn't match, it increases the nonce by 1 and retries. | ||
|
||
The more leading zeros you want, the longer it takes to find the hash. | ||
|
||
Here's an example how to calculate the nonce and send it over with the data: | ||
|
||
```elm | ||
let | ||
data = "example data" | ||
difficulty = 3 | ||
nonce = findNonce difficulty data | ||
in { nonce = nonce | ||
, data = data | ||
} | ||
``` | ||
|
||
### Development | ||
|
||
[Install devenv](https://devenv.sh/getting-started/) and `devenv shell elm-test`. |