hypercore 11.5.0 → 11.6.0

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.
Files changed (3) hide show
  1. package/index.js +7 -15
  2. package/lib/core.js +0 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -253,7 +253,6 @@ class Hypercore extends EventEmitter {
253
253
  }
254
254
 
255
255
  this.encryption = encryption
256
- if (!this.core.encryption) this.core.encryption = this.encryption
257
256
  }
258
257
 
259
258
  setKeyPair (keyPair) {
@@ -329,19 +328,10 @@ class Hypercore extends EventEmitter {
329
328
 
330
329
  if (this.keyPair === null) this.keyPair = opts.keyPair || this.core.header.keyPair
331
330
 
332
- const e = getEncryptionOption(opts)
333
- if (!this.core.encryption && e) {
334
- if (isEncryptionProvider(e)) {
335
- this.core.encryption = e
336
- } else {
337
- this.core.encryption = this._getEncryptionProvider(e.key, e.block)
338
- }
339
- }
340
-
341
331
  const parent = opts.parent || null
332
+ if (parent && parent.encryption) this.encryption = parent.encryption
342
333
 
343
- if (this.core.encryption) this.encryption = this.core.encryption
344
- else if (parent && parent.encryption) this.encryption = this.core.encryption = parent.encryption
334
+ if (!this.encryption) this.encryption = this._getEncryptionProvider(opts)
345
335
 
346
336
  this.writable = this._isWritable()
347
337
 
@@ -1064,9 +1054,11 @@ class Hypercore extends EventEmitter {
1064
1054
  return block
1065
1055
  }
1066
1056
 
1067
- _getEncryptionProvider (encryptionKey, block) {
1068
- if (!encryptionKey) return null
1069
- return new DefaultEncryption(encryptionKey, this.key, { block, compat: this.core.compat })
1057
+ _getEncryptionProvider (opts) {
1058
+ const e = getEncryptionOption(opts)
1059
+ if (isEncryptionProvider(e)) return e
1060
+ if (!e || !e.key) return null
1061
+ return new DefaultEncryption(e.key, this.key, { block: e.block, compat: this.core.compat })
1070
1062
  }
1071
1063
  }
1072
1064
 
package/lib/core.js CHANGED
@@ -42,7 +42,6 @@ module.exports = class Core {
42
42
  this.skipBitfield = null
43
43
  this.globalCache = opts.globalCache || null
44
44
  this.autoClose = opts.autoClose !== false
45
- this.encryption = null
46
45
  this.onidle = noop
47
46
 
48
47
  this.state = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.5.0",
3
+ "version": "11.6.0",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {