Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

fix: add buffer #118

Merged
merged 1 commit into from
Mar 23, 2020
Merged
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
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@
"dependencies": {
"bl": "^4.0.0",
"debug": "^4.1.1",
"it-buffer": "^0.1.1",
"it-length-prefixed": "^3.0.0",
"it-length-prefixed": "^3.0.1",
"it-pair": "^1.0.0",
"it-pb-rpc": "^0.1.4",
"it-pipe": "^1.1.0",
"libp2p-crypto": "^0.17.1",
"libp2p-crypto": "^0.17.3",
"libp2p-interfaces": "^0.2.1",
"multiaddr": "^7.2.1",
"multihashing-async": "^0.8.0",
"peer-id": "^0.13.6",
"protons": "^1.1.0"
"protons": "^1.0.2"
},
"devDependencies": {
"aegir": "^21.0.2",
"aegir": "^21.4.2",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/etm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { InvalidCryptoTransmissionError } = require('libp2p-interfaces/src/crypto
exports.createBoxStream = (cipher, mac) => {
return async function * (source) {
for await (const chunk of source) {
const data = await cipher.encrypt(chunk)
const data = await cipher.encrypt(BufferList.isBufferList(chunk) ? chunk.slice() : chunk)
const digest = await mac.digest(data)
yield new BufferList([data, digest])
}
Expand Down
1 change: 1 addition & 0 deletions src/handshake/crypto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const { Buffer } = require('buffer')
const PeerId = require('peer-id')
const crypto = require('libp2p-crypto')
const debug = require('debug')
Expand Down
3 changes: 0 additions & 3 deletions src/handshake/finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const pipe = require('it-pipe')
const lp = require('it-length-prefixed')
const Wrap = require('it-pb-rpc')
const { int32BEEncode, int32BEDecode } = lp
const ensureBuffer = require('it-buffer')

const etm = require('../etm')
const crypto = require('./crypto')
Expand All @@ -26,12 +25,10 @@ module.exports = async function finish (state, wrapped) {

pipe(
secure, // this is FROM the user
ensureBuffer,
etm.createBoxStream(proto.local.cipher, proto.local.mac),
lp.encode({ lengthEncoder: int32BEEncode }),
network, // and gets piped INTO and FROM the network
lp.decode({ lengthDecoder: int32BEDecode }),
ensureBuffer,
etm.createUnboxStream(proto.remote.cipher, proto.remote.mac),
secure // and gets piped TO the user
)
Expand Down
1 change: 1 addition & 0 deletions src/support.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const { Buffer } = require('buffer')
const mh = require('multihashing-async')
const crypto = require('libp2p-crypto')

Expand Down