npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bittorrent-dht-store-keypair

v3.0.2

Published

create and load signing keys for bittorrent-dht dht_store

Downloads

15

Readme

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