hypercore 10.28.6 → 10.28.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -242,7 +242,7 @@ module.exports = class Hypercore extends EventEmitter {
242
242
  s.cache = opts.cache === true || !opts.cache ? this.cache : opts.cache
243
243
  }
244
244
 
245
- ensureEncryption(s, opts)
245
+ if (this.opened) ensureEncryption(s, opts)
246
246
 
247
247
  this.sessions.push(s)
248
248
 
@@ -289,6 +289,11 @@ module.exports = class Hypercore extends EventEmitter {
289
289
  this.replicator.findingPeers += this._findingPeers
290
290
 
291
291
  ensureEncryption(this, opts)
292
+
293
+ // we need to manually fwd the encryption cap as the above removes it potentially
294
+ if (this.encryption && !from.encryption) {
295
+ for (const s of sessions) s.encryption = this.encryption
296
+ }
292
297
  }
293
298
 
294
299
  async _openSession (key, storage, opts) {
@@ -317,6 +322,8 @@ module.exports = class Hypercore extends EventEmitter {
317
322
  this._clone = null
318
323
  }
319
324
  }
325
+ } else {
326
+ ensureEncryption(this, opts)
320
327
  }
321
328
 
322
329
  this.writable = this._isWritable()
@@ -659,11 +666,14 @@ module.exports = class Hypercore extends EventEmitter {
659
666
  for (let i = 0; i < this.sessions.length; i++) {
660
667
  const s = this.sessions[i]
661
668
 
662
- s.emit('manifest')
663
669
  if (s.encryption && s.encryption.compat !== this.core.compat) {
664
- s.encryption = new BlockEncryption(s.encryptionKey, this.key, { compat: this.core.compat, isBlockKey: s.isBlockKey })
670
+ s.encryption = new BlockEncryption(s.encryption.key, this.key, { compat: this.core.compat, isBlockKey: s.encryption.isBlockKey })
665
671
  }
666
672
  }
673
+
674
+ for (let i = 0; i < this.sessions.length; i++) {
675
+ this.sessions[i].emit('manifest')
676
+ }
667
677
  }
668
678
 
669
679
  for (let i = 0; i < this.sessions.length; i++) {
@@ -1118,8 +1128,8 @@ function ensureEncryption (core, opts) {
1118
1128
  if (!opts.encryptionKey) return
1119
1129
  // Only override the block encryption if it's either not already set or if
1120
1130
  // the caller provided a different key.
1121
- if (core.encryption && b4a.equals(core.encryption.key, opts.encryptionKey)) return
1122
- core.encryption = new BlockEncryption(opts.encryptionKey, core.key, { compat: core.core.compat, isBlockKey: opts.isBlockKey })
1131
+ if (core.encryption && b4a.equals(core.encryption.key, opts.encryptionKey) && core.encryption.compat === core.core.compat) return
1132
+ core.encryption = new BlockEncryption(opts.encryptionKey, core.key, { compat: core.core ? core.core.compat : true, isBlockKey: opts.isBlockKey })
1123
1133
  }
1124
1134
 
1125
1135
  function createCache (cache) {
@@ -6,7 +6,7 @@ const { BLOCK_ENCRYPTION } = require('./caps')
6
6
  const nonce = b4a.alloc(sodium.crypto_stream_NONCEBYTES)
7
7
 
8
8
  module.exports = class BlockEncryption {
9
- constructor (encryptionKey, hypercoreKey, { isBlockKey = false, compat = false } = {}) {
9
+ constructor (encryptionKey, hypercoreKey, { isBlockKey = false, compat = true } = {}) {
10
10
  const subKeys = b4a.alloc(2 * sodium.crypto_stream_KEYBYTES)
11
11
 
12
12
  this.key = encryptionKey
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.28.6",
3
+ "version": "10.28.7",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {