mirror of
https://github.com/fluencelabs/js-libp2p-secio
synced 2025-03-15 18:00:52 +00:00
chore: fix linting
This commit is contained in:
parent
87fb3462a4
commit
65b9675ffe
@ -7,7 +7,7 @@ const PeerId = require('peer-id')
|
|||||||
|
|
||||||
const secio = require('./src')
|
const secio = require('./src')
|
||||||
|
|
||||||
const peerNodeJSON = require('./test/peer-node.json')
|
const peerNodeJSON = require('./test/fixtures/peer-node.json')
|
||||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
||||||
let listener
|
let listener
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
> Secio implementation in JavaScript
|
> SECIO implementation in JavaScript
|
||||||
|
|
||||||
This repo contains the JavaScript implementation of secio, an encryption protocol used in libp2p. This is based on this [go implementation](https://github.com/libp2p/go-libp2p-secio).
|
This repo contains the JavaScript implementation of secio, an encryption protocol used in libp2p. This is based on this [go implementation](https://github.com/libp2p/go-libp2p-secio).
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ const secio = require('libp2p-secio')
|
|||||||
|
|
||||||
The current `secio` tag, usable in `multistream`.
|
The current `secio` tag, usable in `multistream`.
|
||||||
|
|
||||||
### `encrypt(id, key, insecure[, callback])`
|
### `i.encrypt(id, key, insecure[, callback])`
|
||||||
|
|
||||||
- `id: PeerId` - The id of the node.
|
- `id: PeerId` - The id of the node.
|
||||||
- `key: RSAPrivateKey` - The private key of the node.
|
- `key: RSAPrivateKey` - The private key of the node.
|
||||||
|
@ -8,10 +8,22 @@ const crypto = require('libp2p-crypto')
|
|||||||
|
|
||||||
const secio = require('../src')
|
const secio = require('../src')
|
||||||
|
|
||||||
|
function createSession (insecure, cb) {
|
||||||
|
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
||||||
|
if (err) { return cb(err) }
|
||||||
|
|
||||||
|
PeerId.createFromPrivKey(key.bytes, (err, id) => {
|
||||||
|
if (err) { return cb(err) }
|
||||||
|
|
||||||
|
cb(null, secio.encrypt(id, key, insecure))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const suite = new Benchmark.Suite('secio')
|
const suite = new Benchmark.Suite('secio')
|
||||||
const ids = []
|
const ids = []
|
||||||
|
|
||||||
suite.add('createKey', function (d) {
|
suite.add('createKey', (d) => {
|
||||||
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
PeerId.createFromPrivKey(key.bytes, (err, id) => {
|
PeerId.createFromPrivKey(key.bytes, (err, id) => {
|
||||||
@ -21,10 +33,9 @@ suite.add('createKey', function (d) {
|
|||||||
d.resolve()
|
d.resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, {
|
}, { defer: true })
|
||||||
defer: true
|
|
||||||
})
|
suite.add('send', (deferred) => {
|
||||||
.add('send', function (deferred) {
|
|
||||||
const p = pair()
|
const p = pair()
|
||||||
|
|
||||||
createSession(p[0], (err, local) => {
|
createSession(p[0], (err, local) => {
|
||||||
@ -48,31 +59,17 @@ suite.add('createKey', function (d) {
|
|||||||
remote,
|
remote,
|
||||||
pull.take(100),
|
pull.take(100),
|
||||||
pull.collect((err, chunks) => {
|
pull.collect((err, chunks) => {
|
||||||
if (err) throw err
|
if (err) { throw err }
|
||||||
if (chunks.length !== 100) throw new Error('Did not receive enough chunks')
|
if (chunks.length !== 100) { throw new Error('Did not receive enough chunks') }
|
||||||
deferred.resolve()
|
deferred.resolve()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, {
|
}, { defer: true })
|
||||||
defer: true
|
|
||||||
})
|
suite.on('cycle', (event) => {
|
||||||
.on('cycle', (event) => {
|
|
||||||
console.log(String(event.target))
|
console.log(String(event.target))
|
||||||
})
|
})
|
||||||
|
|
||||||
// run async
|
// run async
|
||||||
.run({
|
suite.run({ async: true })
|
||||||
async: true
|
|
||||||
})
|
|
||||||
|
|
||||||
function createSession (insecure, cb) {
|
|
||||||
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
|
||||||
if (err) { return cb(err) }
|
|
||||||
|
|
||||||
PeerId.createFromPrivKey(key.bytes, (err, id) => {
|
|
||||||
if (err) { return cb(err) }
|
|
||||||
|
|
||||||
cb(null, secio.encrypt(id, key, insecure))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"release-major": "aegir release --type major -t node browser",
|
"release-major": "aegir release --type major -t node browser",
|
||||||
"coverage": "aegir coverage",
|
"coverage": "aegir coverage",
|
||||||
"coverage-publish": "aegir coverage publish",
|
"coverage-publish": "aegir coverage publish",
|
||||||
"bench": "node benchmarks/send.js"
|
"benchmark": "node benchmarks/send.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"IPFS",
|
"IPFS",
|
||||||
|
@ -71,7 +71,7 @@ exports.createUnboxStream = (decipher, mac) => {
|
|||||||
function ensureBuffer () {
|
function ensureBuffer () {
|
||||||
return pull.map((c) => {
|
return pull.map((c) => {
|
||||||
if (typeof c === 'string') {
|
if (typeof c === 'string') {
|
||||||
return new Buffer(c, 'utf-8')
|
return Buffer.from(c, 'utf-8')
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
@ -12,10 +12,10 @@ const WS = require('libp2p-websockets')
|
|||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
|
|
||||||
const peerBrowserJSON = require('./peer-browser.json')
|
const peerBrowserJSON = require('./fixtures/peer-browser.json')
|
||||||
const secio = require('../src')
|
const secio = require('../src')
|
||||||
|
|
||||||
describe('secio browser <-> nodejs', () => {
|
describe('secio between browser <-> nodejs through websockets', () => {
|
||||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
||||||
let conn
|
let conn
|
||||||
let encryptedConn
|
let encryptedConn
|
||||||
|
@ -19,8 +19,20 @@ const Dialer = ms.Dialer
|
|||||||
|
|
||||||
const secio = require('../src')
|
const secio = require('../src')
|
||||||
|
|
||||||
describe('libp2p-secio', () => {
|
function createSession (insecure, callback) {
|
||||||
it('exports a tag', () => {
|
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
key.public.hash((err, digest) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
callback(null, secio.encrypt(new PeerId(digest, key), key, insecure))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('secio', () => {
|
||||||
|
it('exports a secio multicodec', () => {
|
||||||
expect(secio.tag).to.equal('/secio/1.0.0')
|
expect(secio.tag).to.equal('/secio/1.0.0')
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -51,7 +63,7 @@ describe('libp2p-secio', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works over multistream', function (done) {
|
it('works over multistream-select', function (done) {
|
||||||
this.timeout(20 * 1000)
|
this.timeout(20 * 1000)
|
||||||
|
|
||||||
const p = pair()
|
const p = pair()
|
||||||
@ -72,7 +84,7 @@ describe('libp2p-secio', () => {
|
|||||||
local,
|
local,
|
||||||
pull.collect((err, chunks) => {
|
pull.collect((err, chunks) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(chunks).to.be.eql([new Buffer('hello world')])
|
expect(chunks).to.eql([Buffer.from('hello world')])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -86,7 +98,7 @@ describe('libp2p-secio', () => {
|
|||||||
createSession(conn, (err, remote) => {
|
createSession(conn, (err, remote) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hello world')]),
|
pull.values([Buffer.from('hello world')]),
|
||||||
remote
|
remote
|
||||||
)
|
)
|
||||||
cb()
|
cb()
|
||||||
@ -95,15 +107,3 @@ describe('libp2p-secio', () => {
|
|||||||
], (err) => expect(err).to.not.exist())
|
], (err) => expect(err).to.not.exist())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function createSession (insecure, callback) {
|
|
||||||
crypto.keys.generateKeyPair('RSA', 2048, (err, key) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
|
|
||||||
key.public.hash((err, digest) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
|
|
||||||
callback(null, secio.encrypt(new PeerId(digest, key), key, insecure))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user