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

Commit 914eb4f

Browse files
authored
fix: add buffer (#118)
Adds buffer where needed and removes dependency on it-buffer related to ipfs/js-ipfs#2924
1 parent ef5f09d commit 914eb4f

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@
3131
"dependencies": {
3232
"bl": "^4.0.0",
3333
"debug": "^4.1.1",
34-
"it-buffer": "^0.1.1",
35-
"it-length-prefixed": "^3.0.0",
34+
"it-length-prefixed": "^3.0.1",
3635
"it-pair": "^1.0.0",
3736
"it-pb-rpc": "^0.1.4",
3837
"it-pipe": "^1.1.0",
39-
"libp2p-crypto": "^0.17.1",
38+
"libp2p-crypto": "^0.17.3",
4039
"libp2p-interfaces": "^0.2.1",
4140
"multiaddr": "^7.2.1",
4241
"multihashing-async": "^0.8.0",
4342
"peer-id": "^0.13.6",
44-
"protons": "^1.1.0"
43+
"protons": "^1.0.2"
4544
},
4645
"devDependencies": {
47-
"aegir": "^21.0.2",
46+
"aegir": "^21.4.2",
4847
"benchmark": "^2.1.4",
4948
"chai": "^4.2.0",
5049
"dirty-chai": "^2.0.1",

src/etm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { InvalidCryptoTransmissionError } = require('libp2p-interfaces/src/crypto
66
exports.createBoxStream = (cipher, mac) => {
77
return async function * (source) {
88
for await (const chunk of source) {
9-
const data = await cipher.encrypt(chunk)
9+
const data = await cipher.encrypt(BufferList.isBufferList(chunk) ? chunk.slice() : chunk)
1010
const digest = await mac.digest(data)
1111
yield new BufferList([data, digest])
1212
}

src/handshake/crypto.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const PeerId = require('peer-id')
45
const crypto = require('libp2p-crypto')
56
const debug = require('debug')

src/handshake/finish.js

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const pipe = require('it-pipe')
99
const lp = require('it-length-prefixed')
1010
const Wrap = require('it-pb-rpc')
1111
const { int32BEEncode, int32BEDecode } = lp
12-
const ensureBuffer = require('it-buffer')
1312

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

2726
pipe(
2827
secure, // this is FROM the user
29-
ensureBuffer,
3028
etm.createBoxStream(proto.local.cipher, proto.local.mac),
3129
lp.encode({ lengthEncoder: int32BEEncode }),
3230
network, // and gets piped INTO and FROM the network
3331
lp.decode({ lengthDecoder: int32BEDecode }),
34-
ensureBuffer,
3532
etm.createUnboxStream(proto.remote.cipher, proto.remote.mac),
3633
secure // and gets piped TO the user
3734
)

src/support.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const mh = require('multihashing-async')
45
const crypto = require('libp2p-crypto')
56

0 commit comments

Comments
 (0)