hypercore 10.28.6 → 10.28.8
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 +15 -5
- package/lib/block-encryption.js +1 -1
- package/lib/core.js +8 -0
- package/package.json +1 -1
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.
|
|
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) {
|
package/lib/block-encryption.js
CHANGED
|
@@ -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 =
|
|
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/lib/core.js
CHANGED
|
@@ -222,6 +222,13 @@ module.exports = class Core {
|
|
|
222
222
|
async copyFrom (src, signature, { length = src.tree.length } = {}) {
|
|
223
223
|
await this._mutex.lock()
|
|
224
224
|
|
|
225
|
+
try {
|
|
226
|
+
await src._mutex.lock()
|
|
227
|
+
} catch (err) {
|
|
228
|
+
this._mutex.unlock()
|
|
229
|
+
throw err
|
|
230
|
+
}
|
|
231
|
+
|
|
225
232
|
try {
|
|
226
233
|
let pos = 0
|
|
227
234
|
|
|
@@ -290,6 +297,7 @@ module.exports = class Core {
|
|
|
290
297
|
|
|
291
298
|
await this._flushOplog()
|
|
292
299
|
} finally {
|
|
300
|
+
src._mutex.unlock()
|
|
293
301
|
this._mutex.unlock()
|
|
294
302
|
}
|
|
295
303
|
}
|