Package Exports
- crypto-puzzle
- crypto-puzzle/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (crypto-puzzle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Crypto Puzzle
Basically a proof-of-work generator, this library makes cryptographic puzzles that are arbitrarily expensive to solve.
Install
npm install --save crypto-puzzleHow It Works
Puzzles are generated this way:
- A random salt is generated.
- A random integer is picked between
0anddifficulty, that's going to be the solution of the puzzle. - The salt and integer are joined together to form the key.
- The key is hashed.
- The solver receives the
difficulty, the salt and the hash and it's asked to find the solution.
Puzzles are solved this way:
- For all integers between
0anddifficultythe following actions are performed. - The current integer, which is the potential solution, is joined with the salt to form the key.
- The key is hashed.
- If the key doesn't match the correct one the next integer is tried.
- If the key matches the correct one the integer is the solution and the puzzle is solved.
Details:
- The time necessary to generate puzzles is constant, it doesn't matter what the
difficultyis. - The average time necessary to solve puzzles grows linearly with the
difficulty. - There are no shortcuts, unlike captchas and other stuff the user here must do the work to solve each puzzle.
Usage
import Puzzle from 'crypto-puzzle';
const difficulty = 100000;
const puzzle = await Puzzle.generate ( difficulty );
const solution = await Puzzle.solve ( puzzle.question );
console.assert ( puzzle.solution === solution );License
MIT © Fabio Spampinato