Git Product home page Git Product logo

hashcash-for-node's Introduction

Hashcash for Node

Hashcash is a simple proof of work algorithm to prevent or slow down spam. It works by giving the requester a challenge in the form of a sha1 hash. After the hash is received the requesting client has four seconds to find a hash of the challenge + number that has three leading zeros. The client can find the challenge in the header: hashcash-challenge and add the answer to hashcash-answer.

Using the middleware on an end-point in express will prevent the client from accessing the resource until an answer is found. A new challenge is created every four seconds.

How to Install

npm install hashcash 

How to use

First, require hashcash:

var hashcash = require('hashcash');
var express = require('express');
var app = express.createServer();

app.get('/protected',hashcash.middleware(),function(req,res) {
	/* this will never get hit if the hashcash-answer is not present */
	res.send('Success!');
});

var port = 8080;
console.log('Listening on port: '+port);
app.listen(port);

hashcash-for-node's People

Contributors

base698 avatar

Watchers

James Cloos avatar

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.