Giter Site home page Giter Site logo

bittorrent-dht-store-keypair's Introduction

bittorrent-dht-store-keypair

Setting up elliptic curve keys and signing properly for BEP44 can be tricky, especially since bittorrent uses the more obscure supercop/ref10 instead of sodium/nacl ed25519 key formatting.

example

quick example

var KP = require('bittorrent-dht-store-keypair')
var DHT = require('bittorrent-dht')

var dht = new DHT({ verify: KP.verify })
var kp = KP()

var value = 'beep boop'
dht.once('ready', function () {
  dht.put(kp.store(value), function (errors, hash) {
    if (errors.length) errors.forEach(console.log)
    else console.log(kp.id)
  })
})

save and load a key from a file

var KP = require('bittorrent-dht-store-keypair')
var kp = KP()
console.log(JSON.stringify({
  publicKey: kp.publicKey.toString('hex'),
  secretKey: kp.secretKey.toString('hex')
}))
$ node generate.js > keypair.json
var KP = require('bittorrent-dht-store-keypair')
var DHT = require('bittorrent-dht')
var path = require('path')
var concat = require('concat-stream')

var dht = new DHT({ verify: KP.verify })
var kp = KP(require(path.resolve(process.argv[2])))

dht.once('ready', function () {
  process.stdin.pipe(concat(function (value) {
    dht.put(kp.store(value), function (errors, hash) {
      if (errors.length) errors.forEach(console.log)
      else console.log(kp.id)
    })
  }))
})
$ echo wow cool | node put.js keypair.json

api

var KP = require('bittorrent-dht-store-keypair')

var kp = KP(opts)

  • opts.publicKey - create kp with a buffer or hex string public key
  • opts.secretKey - create kp with a buffer or hex string private key
  • opts.seq - sequence to start at in kp.store()

var signature = kp.sign(value)

Sign a buffer or string value with the private key.

var putOpts = kp.store(value, opts)

Create the putOpts for a value to pass into bittorrent-dht's put() function.

kp.seq is incremented here unless opts.seq is provided.

kp.publicKey

public key (32 bytes)

kp.secretKey

private key (64 bytes)

kp.id

sha1 hash of the kp.publicKey

kp.seq

sequence number

KP.verify

The underlying ed25519-supercop verify function. This is handy to pass into the bittorrent-dht constructor as the verify parameter:

var DHT = require('bittorrent-dht')
var KP = require('bittorrent-dht-store-keypair')
var dht = new DHT({ verify: KP.verify })

install

npm install bittorrent-dht-store-keypair

license

MIT

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.