GithubHelp home page GithubHelp logo

fabiospampinato / crypto-puzzle Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 1.0 24 KB

A time-lock puzzle generator.

License: MIT License

TypeScript 88.08% JavaScript 11.92%
crypto puzzle pow proof-of-work captcha time-lock

crypto-puzzle's Introduction

Crypto Puzzle

A time-lock puzzle generator.

Description

Time-lock puzzles are kind of a way to craft a message that can only be read after some point in the future, which you can pick.

A time-lock puzzle is a computational puzzle that requires a deterministic number of operations to solve. By calculating how many operations per second an attacker, or the receiver of your message, could perform you can configure the amount of operations needed to decrypt the message such that at least the amount of time that you require must have passed for the message to have been decrypted.

This works because the operations that need to be performed to solve a puzzle are not parallelizable, you can't solve time-lock puzzles meaningfully faster with a GPU or a million computers, and generating the puzzle is always cheap, because you know which prime numbers it's secured by, basically.

Time-lock puzzles are basically little proof-of-works, they have lots of interesting applications, for example a solution like this can be used to fight spam, by requiring that each request that your server receives comes with its own solution to a unique time-lock puzzle, which would be cheap for you to generate, cheap for you to check, cheap for legitimate users to solve, but prohibitively expensive for abusers/spammers to solve many of. It can be used as a sort of transparent captcha that can't be bypassed.

Install

npm install --save crypto-puzzle

Usage

import Puzzle from 'crypto-puzzle';

// Generate a puzzle that can only be read in about 10 seconds from now

const puzzle = await Puzzle.generate ({
  /* OPTIONAL OPTIONS */
  primeBits: 100, // Number of bits of entropy that the two internally generated primes will have
  primeRounds: 6, // Number of Miller-Rabin primality checks that the prime numbers will have to pass
  opsPerSecond: 3_300_000, // Rough number of operations per second that the attacker/receiver can perform, 3.3M is around what a MBP M1 Max can do
  /* REQUIRED OPTIONS */
  duration: 10_000, // Rough minimum number of milliseconds that this puzzle will be unsolvable for
  message: 'Hey there!' // Message to encrypt inside the puzzle
});

// Now let's solve the puzzle

const solution = await Puzzle.solve ( puzzle );

// About 10 seconds later...

console.log ( solution ); // => 'Hey there!'

License

MIT © Fabio Spampinato

crypto-puzzle's People

Contributors

fabiospampinato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

echowxsy

crypto-puzzle's Issues

Duplicate types

NODE: 16
TypeScript: 4.8.4

import Puzzle from "crypto-puzzle"
let puzzle = await Puzzle.generate(difficulty)

'Puzzle' cannot be used as a value because it was imported using 'import type'.

19     let puzzle = await Puzzle.generate(difficulty)
                          ~~~~~~

  node_modules/crypto-puzzle/dist/index.d.ts:1:35
    1 import type { Question, Solution, Puzzle } from './types';
                                        ~~~~~~
    'Puzzle' was imported here.

Import Error on nodejs

When i import by require
const crypto_puzzle_1 = require("crypto-puzzle");

i get error

Error [ERR_REQUIRE_ESM]: require() of ES Module

i found way

let Puzzle = require("fix-esm").require("crypto-puzzle").default;

but is not clean, please add support regular require

One generation, multiple puzzles

Is it possible for current (time-lock puzzle) algorithm to have multiple maybe infinite count of solutions per one puzzle?

That would be very handy, for example server generates puzzle for each client session ones and when client send request for something, request has to be along with puzzle solution, then server keeps all previous solutions and checks if the new one is truely new and only then fullfil request response.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.