hypercore 11.0.11 → 11.0.12
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 +4 -0
- package/lib/block-encryption.js +6 -0
- package/lib/core.js +11 -6
- package/lib/session-state.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -146,6 +146,10 @@ class Hypercore extends EventEmitter {
|
|
|
146
146
|
return crypto.discoveryKey(key)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
static blockEncryptionKey (key, encryptionKey) {
|
|
150
|
+
return BlockEncryption.blockEncryptionKey(key, encryptionKey)
|
|
151
|
+
}
|
|
152
|
+
|
|
149
153
|
static getProtocolMuxer (stream) {
|
|
150
154
|
return stream.noiseStream.userData
|
|
151
155
|
}
|
package/lib/block-encryption.js
CHANGED
|
@@ -23,6 +23,12 @@ module.exports = class BlockEncryption {
|
|
|
23
23
|
sodium.crypto_generichash(this.blindingKey, this.blockKey)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
static blockEncryptionKey (hypercoreKey, encryptionKey) {
|
|
27
|
+
const blockKey = b4a.alloc(sodium.crypto_stream_KEYBYTES)
|
|
28
|
+
sodium.crypto_generichash_batch(blockKey, [BLOCK_ENCRYPTION, hypercoreKey, encryptionKey])
|
|
29
|
+
return blockKey
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
encrypt (index, block, fork) {
|
|
27
33
|
const padding = block.subarray(0, this.padding)
|
|
28
34
|
block = block.subarray(this.padding)
|
package/lib/core.js
CHANGED
|
@@ -258,10 +258,13 @@ module.exports = class Core {
|
|
|
258
258
|
header.userData.push({ key, value: unslab(value) })
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
const len = bitfield.findFirst(false, header.hints.contiguousLength)
|
|
262
|
+
if (header.hints.contiguousLength !== len) {
|
|
263
|
+
header.hints.contiguousLength = len
|
|
264
|
+
const tx = storage.write()
|
|
265
|
+
tx.setHints({ contiguousLength: len })
|
|
266
|
+
await tx.flush()
|
|
267
|
+
}
|
|
265
268
|
|
|
266
269
|
// to unslab
|
|
267
270
|
if (header.manifest) header.manifest = Verifier.createManifest(header.manifest)
|
|
@@ -757,7 +760,7 @@ function parseHeader (info) {
|
|
|
757
760
|
tree: info.head || getDefaultTree(),
|
|
758
761
|
hints: {
|
|
759
762
|
reorgs: [],
|
|
760
|
-
contiguousLength: 0
|
|
763
|
+
contiguousLength: info.hints ? info.hints.contiguousLength : 0
|
|
761
764
|
}
|
|
762
765
|
}
|
|
763
766
|
}
|
|
@@ -769,11 +772,13 @@ async function getCoreInfo (storage) {
|
|
|
769
772
|
|
|
770
773
|
const auth = r.getAuth()
|
|
771
774
|
const head = r.getHead()
|
|
775
|
+
const hints = r.getHints()
|
|
772
776
|
|
|
773
777
|
r.tryFlush()
|
|
774
778
|
|
|
775
779
|
return {
|
|
776
780
|
...await auth,
|
|
777
|
-
head: await head
|
|
781
|
+
head: await head,
|
|
782
|
+
hints: await hints
|
|
778
783
|
}
|
|
779
784
|
}
|
package/lib/session-state.js
CHANGED
|
@@ -537,7 +537,7 @@ module.exports = class SessionState {
|
|
|
537
537
|
return
|
|
538
538
|
}
|
|
539
539
|
|
|
540
|
-
if (p.drop) {
|
|
540
|
+
if (p.drop || p.truncated !== -1) {
|
|
541
541
|
if (p.truncated !== b.start + b.length) throw INVALID_OPERATION('Atomic truncations must be contiguous')
|
|
542
542
|
p.truncated = b.start
|
|
543
543
|
return
|