bittorrent-dht-store-keypair
Advanced tools
Comparing version 1.1.0 to 3.0.0
@@ -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) | ||
}) | ||
})) | ||
}) |
50
index.js
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10504
3
11
207
126
1
1
1
+ Addeded25519-supercop@^1.0.0
+ Addeded25519-supercop@1.2.0(transitive)
+ Addednan@2.22.0(transitive)
+ Addednode-gyp-build@3.9.0(transitive)
- Removedbencode@~0.6.0
- Removedelliptic@^3.1.0
- Removedbencode@0.6.0(transitive)
- Removedbn.js@2.2.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@3.1.0(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedminimalistic-assert@1.0.1(transitive)