hypercore 10.35.4 → 10.36.1
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/README.md +9 -1
- package/index.js +6 -1
- package/lib/bitfield.js +1 -1
- package/lib/core.js +19 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hypercore
|
|
2
2
|
|
|
3
|
-
### [See the full API docs at docs.
|
|
3
|
+
### [See the full API docs at docs.pears.com](https://docs.pears.com/building-blocks/hypercore)
|
|
4
4
|
|
|
5
5
|
Hypercore is a secure, distributed append-only log.
|
|
6
6
|
|
|
@@ -478,3 +478,11 @@ Emitted when a new connection has been established with a peer.
|
|
|
478
478
|
#### `core.on('peer-remove')`
|
|
479
479
|
|
|
480
480
|
Emitted when a peer's connection has been closed.
|
|
481
|
+
|
|
482
|
+
#### `core.on('upload', index, byteLength, peer)`
|
|
483
|
+
|
|
484
|
+
Emitted when a block is uploaded to a peer.
|
|
485
|
+
|
|
486
|
+
#### `core.on('download', index, byteLength, peer)`
|
|
487
|
+
|
|
488
|
+
Emitted when a block is downloaded from a peer.
|
package/index.js
CHANGED
|
@@ -142,7 +142,8 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
142
142
|
|
|
143
143
|
static MAX_SUGGESTED_BLOCK_SIZE = MAX_SUGGESTED_BLOCK_SIZE
|
|
144
144
|
|
|
145
|
-
static key (manifest, { compat } = {}) {
|
|
145
|
+
static key (manifest, { compat, version, namespace } = {}) {
|
|
146
|
+
if (b4a.isBuffer(manifest)) manifest = { version, signers: [{ publicKey: manifest, namespace }] }
|
|
146
147
|
return compat ? manifest.signers[0].publicKey : manifestHash(createManifest(manifest))
|
|
147
148
|
}
|
|
148
149
|
|
|
@@ -334,6 +335,10 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
334
335
|
ensureEncryption(this, opts)
|
|
335
336
|
}
|
|
336
337
|
|
|
338
|
+
if (opts.manifest && !this.core.header.manifest) {
|
|
339
|
+
await this.core.setManifest(opts.manifest)
|
|
340
|
+
}
|
|
341
|
+
|
|
337
342
|
this.writable = this._isWritable()
|
|
338
343
|
|
|
339
344
|
if (opts.valueEncoding) {
|
package/lib/bitfield.js
CHANGED
package/lib/core.js
CHANGED
|
@@ -194,7 +194,21 @@ module.exports = class Core {
|
|
|
194
194
|
return new this(header, compat, crypto, oplog, bigHeader, tree, blocks, bitfield, verifier, legacy, opts.onupdate || noop, opts.onconflict || noop)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
setManifest (manifest
|
|
197
|
+
async setManifest (manifest) {
|
|
198
|
+
await this._mutex.lock()
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
if (manifest && this.header.manifest === null) {
|
|
202
|
+
if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
|
|
203
|
+
this._setManifest(Verifier.createManifest(manifest), null)
|
|
204
|
+
await this._flushOplog()
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
207
|
+
this._mutex.unlock()
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
_setManifest (manifest, keyPair) {
|
|
198
212
|
if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = Verifier.defaultSignerManifest(this.header.key)
|
|
199
213
|
if (!manifest) return
|
|
200
214
|
|
|
@@ -430,7 +444,7 @@ module.exports = class Core {
|
|
|
430
444
|
await this._mutex.lock()
|
|
431
445
|
|
|
432
446
|
// upsert compat manifest
|
|
433
|
-
if (this.verifier === null && keyPair) this.
|
|
447
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
434
448
|
|
|
435
449
|
try {
|
|
436
450
|
const batch = await this.tree.truncate(length, fork)
|
|
@@ -549,7 +563,7 @@ module.exports = class Core {
|
|
|
549
563
|
|
|
550
564
|
try {
|
|
551
565
|
// upsert compat manifest
|
|
552
|
-
if (this.verifier === null && keyPair) this.
|
|
566
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
553
567
|
|
|
554
568
|
if (this.tree.fork !== batch.fork) return null
|
|
555
569
|
|
|
@@ -623,7 +637,7 @@ module.exports = class Core {
|
|
|
623
637
|
|
|
624
638
|
try {
|
|
625
639
|
// upsert compat manifest
|
|
626
|
-
if (this.verifier === null && keyPair) this.
|
|
640
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
627
641
|
|
|
628
642
|
if (preappend) await preappend(values)
|
|
629
643
|
|
|
@@ -790,7 +804,7 @@ module.exports = class Core {
|
|
|
790
804
|
// if we got a manifest AND its strictly a non compat one, lets store it
|
|
791
805
|
if (manifest && this.header.manifest === null) {
|
|
792
806
|
if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
|
|
793
|
-
this.
|
|
807
|
+
this._setManifest(manifest, null)
|
|
794
808
|
}
|
|
795
809
|
|
|
796
810
|
batch.commit()
|