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 3.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,6 +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 +10,16 @@ module.exports = KP

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,23 +29,24 @@ }

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) {
var self = this
if (!opts) opts = {}
if (typeof value === 'string') value = Buffer(value)
var svalue = bencode.encode({
seq: this.seq,
v: value
}).slice(1, -1)
var seq = defined(opts.seq, this.seq)
if (opts.seq === undefined) this.seq ++
return {
k: this.k,
seq: this.seq++,
k: this.publicKey,
seq: seq,
salt: opts.salt,
v: value,
sig: this.sign(value)
sign: function (buf) {
return ed.sign(buf, self.publicKey, self.secretKey)
}
}
}
KP.verify = ed.verify
function tobuf (s) {

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

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

@@ -11,8 +11,9 @@ "main": "index.js",

"dependencies": {
"bencode": "~0.6.0",
"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 +20,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