Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bittorrent-dht-store-keypair

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bittorrent-dht-store-keypair - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

example/generate.js

20

example/put.js

@@ -1,10 +0,16 @@

var kp = require('../')()
var KP = require('../')
var DHT = require('bittorrent-dht')
var dht = new DHT({ bootstrap: false })
console.log(kp.id)
var path = require('path')
var concat = require('concat-stream')
dht.listen(5001, function () {
dht.put(kp.store('whatever'), function (errors, hash) {
console.log(hash)
})
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)
})
}))
})

@@ -1,5 +0,4 @@

var EC = require('elliptic').ec
var ed = require('ed25519-supercop')
var sha = require('sha.js')
var defined = require('defined')
var bpad = require('./lib/bpad.js')
var bencode = require('bencode')

@@ -12,7 +11,16 @@

if (!opts) opts = {}
this.kp = opts.secretKey
? new EC('ed25519').keyFromPrivate(tobuf(opts.secretKey))
: new EC('ed25519').genKeyPair()
this.k = bpad(32, Buffer(this.kp.getPublic().x.toArray()))
this.id = sha('sha1').update(this.k).digest('hex')
this.secretKey = opts.secretKey
this.publicKey = opts.publicKey
if (typeof this.secretKey === 'string') {
this.secretKey = Buffer(this.secretKey, 'hex')
}
if (typeof this.publicKey === 'string') {
this.publicKey = Buffer(this.publicKey, 'hex')
}
if (!this.secretKey && !this.publicKey) {
var kp = ed.createKeyPair(this.seed || ed.createSeed())
this.secretKey = kp.secretKey
this.publicKey = kp.publicKey
}
this.id = sha('sha1').update(this.publicKey).digest('hex')
this.seq = defined(opts.seq, 0)

@@ -22,18 +30,17 @@ }

KP.prototype.sign = function (value) {
var sig = this.kp.sign(value)
return Buffer.concat([
bpad(32, Buffer(sig.r.toArray())),
bpad(32, Buffer(sig.s.toArray()))
])
return ed.sign(value, this.publicKey, this.secretKey)
}
KP.prototype.store = function (value) {
KP.prototype.store = function (value, opts) {
if (!opts) opts = {}
if (typeof value === 'string') value = Buffer(value)
var seq = defined(opts.seq, this.seq)
var svalue = bencode.encode({
seq: this.seq,
seq: seq,
v: value
}).slice(1, -1)
if (opts.seq === undefined) this.seq ++
return {
k: this.k,
seq: this.seq++,
k: this.publicKey,
seq: seq,
v: value,

@@ -44,2 +51,4 @@ sig: this.sign(value)

KP.verify = ed.verify
function tobuf (s) {

@@ -46,0 +55,0 @@ if (typeof s === 'string') return Buffer(s, 'hex')

{
"name": "bittorrent-dht-store-keypair",
"version": "1.1.0",
"version": "2.0.0",
"description": "create and load signing keys for bittorrent-dht dht_store",

@@ -13,6 +13,8 @@ "main": "index.js",

"defined": "^1.0.0",
"elliptic": "^3.1.0",
"ed25519-supercop": "^1.0.0",
"sha.js": "^2.4.2"
},
"devDependencies": {},
"devDependencies": {
"tape": "^4.2.0"
},
"scripts": {

@@ -19,0 +21,0 @@ "test": "tape test/*.js"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc