1.0.2 • Published 8 years ago

dapid-payment-captcha v1.0.2

Weekly downloads
7
License
ISC
Repository
github
Last release
8 years ago

Captcha payment protocol

The Captcha-payment-protocol for DAPID.

Usage in DapiD

var Dapid = require('dapid');
var captchaProtocol = require('dapid-payment-captcha');
var storageEngine = require('memdown'); //any level-down module

var dapid = new Dapid(storageEngine, 'any_db_prefix');
var roleClient = dapid.beClient(identity); //any dapid.Identity
var roleProvider = dapid.beProvider(identity); //any dapid.Identity


var instance = captchaProtocol.get('any_db_prefix', storageEngine, {
  captchaSolutionTime_avg: 1000 * 5, //how long does it take to solve a captcha
  waitingWasteMultiplier: 20, //because it anoys the user to type in captchas, the lifePrice is multiplied with this factor
}),

//add this if you want to be client
instance.setClientData({
  /**
   * RoleClient, created from the DAPID-module
   * @type {RoleClient}
   */
    role: roleClient,
    solveHandler: function(captcha, cb) {
      //callback the solution of the captcha here
    }
});


instance.setProviderData({
  /**
   * RoleProvider, created from the DAPID-module
   * @type {RoleProvider}
   */
  role: providerRole,
  captchaCreator: function(cb) {
      //replace this with your own captcha creator
      var captcha = {
          id: 'foobar',
          base64: 'base64-representation of the catpcha'
      };
      cb(captcha);
  },
  solutionValidator: function(captcha, solution, cb) {
    cb(true); //replace this with a validator and check if solution is valid
  }
});

dapid.addPaymentProtocol(instance);

paymentOptionData

A captcha has 1.000.000 coins. The price defines how much coins will have to be send. For example if price==1000, than a single captcha can be used for 1000 requests.

  {
    "price": 1000,
  }

##TODOs

//TODO remember if a providers captchas are wrong so that the lifePrice will adjust accordingly.

1.0.2

8 years ago

1.0.1

8 years ago