bittorrent-dht-store-keypair
Advanced tools
Comparing version 1.1.0 to 2.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) | ||
}) | ||
})) | ||
}) |
41
index.js
@@ -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
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
10553
11
208
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)
- Removedelliptic@^3.1.0
- 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)