Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ Puts a value into the DHT.
- `v`: <String> value to store
- `s`: <Number> sequence number
- `opts`
- `keys`: <Object> contains `ed25519-supercop` private and public key
- `publicKey`: <Buffer> public key
- `secretKey`: <Buffer> private key
- `keys`: <Object> contains `ed25519` private and public key
- `pk`: <Buffer> public key
- `sk`: <Buffer> private key
- `callback` <function>

Provides sugar for storing mutable, signed data in the DHT.
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const LRU = require('lru')
const request = require('request')
const CbQ = require('cbq')
const bencode = require('bencode')
const ed = require('bittorrent-dht-sodium')

class Link {
constructor (conf) {
Expand Down Expand Up @@ -222,10 +223,10 @@ class Link {
if (!data || !opts || !cb) throw new Error('ERR_MISSING_ARGS')
if (!data.seq) return cb(new Error('ERR_MISSING_SEQ'))

const { publicKey, secretKey } = opts.keys
if (!publicKey || !secretKey) return cb(new Error('ERR_MISSING_KEY'))
const { pk, sk } = opts.keys
if (!pk || !sk) return cb(new Error('ERR_MISSING_KEY'))

data.k = publicKey.toString('hex')
data.k = pk.toString('hex')

const toEncode = { seq: data.seq, v: data.v }

Expand All @@ -237,7 +238,7 @@ class Link {
.toString()

data.sig = ed
.sign(encoded, publicKey, secretKey)
.sign(Buffer.from(encoded), sk)
.toString('hex')

this.put(data, cb)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"async": "^2.6.1",
"bencode": "^2.0.0",
"bittorrent-dht-sodium": "^1.1.0",
"cbq": "0.0.1",
"lodash": "^4.17.11",
"lru": "^3.1.0",
Expand Down
8 changes: 4 additions & 4 deletions test/put-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict'

const assert = require('assert')
const ed = require('ed25519-supercop')
const ed = require('bittorrent-dht-sodium')

const Link = require('../')

Expand Down Expand Up @@ -51,7 +51,7 @@ describe('announce and lookups', () => {

const data = { v: 'hello world', seq: 1 }
const opts = {
keys: ed.createKeyPair(ed.createSeed())
keys: ed.keygen()
}

link.putMutable(data, opts, (err, hash) => {
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('announce and lookups', () => {

const data = { v: 'hello world', seq: 1, salt: 'foobar' }
const opts = {
keys: ed.createKeyPair(ed.createSeed())
keys: ed.keygen()
}

link.putMutable(data, opts, (err, hash) => {
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('announce and lookups', () => {

const data = { v: 'hello world', seq: 1, salt: 'foobar' }
const opts = {
keys: ed.createKeyPair(ed.createSeed())
keys: ed.keygen()
}

link.putMutable(data, opts, (err, hash) => {
Expand Down