hypercore 10.27.1 → 10.28.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/index.js CHANGED
@@ -56,7 +56,7 @@ module.exports = class Hypercore extends EventEmitter {
56
56
  this.replicator = null
57
57
  this.encryption = null
58
58
  this.extensions = new Map()
59
- this.cache = opts.cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (opts.cache || null)
59
+ this.cache = createCache(opts.cache)
60
60
 
61
61
  this.valueEncoding = null
62
62
  this.encodeBatch = null
@@ -296,6 +296,7 @@ module.exports = class Hypercore extends EventEmitter {
296
296
 
297
297
  if (!isFirst) await opts._opening
298
298
  if (opts.preload) opts = { ...opts, ...(await this._retryPreload(opts.preload)) }
299
+ if (this.cache === null && opts.cache) this.cache = createCache(opts.cache)
299
300
 
300
301
  if (isFirst) {
301
302
  await this._openCapabilities(key, storage, opts)
@@ -356,7 +357,6 @@ module.exports = class Hypercore extends EventEmitter {
356
357
 
357
358
  this.core = await Core.open(this.storage, {
358
359
  compat: opts.compat,
359
- encrypted: !!opts.encryptionKey || !!opts.encrypted,
360
360
  force: opts.force,
361
361
  createIfMissing: opts.createIfMissing,
362
362
  readonly: unlocked,
@@ -479,7 +479,7 @@ module.exports = class Hypercore extends EventEmitter {
479
479
  throw BAD_ARGUMENT('Cannot clone a fork')
480
480
  }
481
481
 
482
- const manifest = opts.manifest || defaultSignerManifest(keyPair.publicKey, !!opts.encryptionKey)
482
+ const manifest = opts.manifest || defaultSignerManifest(keyPair.publicKey)
483
483
  const key = opts.key || (opts.compat !== false ? manifest.signer.publicKey : manifestHash(manifest))
484
484
 
485
485
  if (b4a.equals(key, this.key)) {
@@ -1117,3 +1117,7 @@ function ensureEncryption (core, opts) {
1117
1117
  if (core.encryption && b4a.equals(core.encryption.key, opts.encryptionKey)) return
1118
1118
  core.encryption = new BlockEncryption(opts.encryptionKey, core.key, { compat: core.core.compat, isBlockKey: opts.isBlockKey })
1119
1119
  }
1120
+
1121
+ function createCache (cache) {
1122
+ return cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (cache || null)
1123
+ }
package/lib/core.js CHANGED
@@ -92,7 +92,7 @@ module.exports = class Core {
92
92
 
93
93
  const keyPair = opts.keyPair || (opts.key ? null : crypto.keyPair())
94
94
  const defaultManifest = !opts.manifest && (!!opts.compat || !opts.key || !!(keyPair && b4a.equals(opts.key, keyPair.publicKey)))
95
- const manifest = defaultManifest ? defaultSignerManifest(opts.key || keyPair.publicKey, !!opts.encrypted) : createManifest(opts.manifest)
95
+ const manifest = defaultManifest ? defaultSignerManifest(opts.key || keyPair.publicKey) : createManifest(opts.manifest)
96
96
 
97
97
  header = {
98
98
  external: null,
@@ -188,7 +188,7 @@ module.exports = class Core {
188
188
  }
189
189
 
190
190
  setManifest (manifest, keyPair) {
191
- if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = defaultSignerManifest(this.header.key, false)
191
+ if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = defaultSignerManifest(this.header.key)
192
192
  if (!manifest) return
193
193
 
194
194
  const compat = isCompat(this.header.key, manifest)
@@ -558,7 +558,7 @@ module.exports = class Core {
558
558
 
559
559
  _verifyBatchUpgrade (batch, manifest) {
560
560
  if (!this.header.manifest) {
561
- if (!manifest && this.compat) manifest = defaultSignerManifest(this.header.key, false)
561
+ if (!manifest && this.compat) manifest = defaultSignerManifest(this.header.key)
562
562
 
563
563
  if (!manifest || !(isValidManifest(this.header.key, manifest) || (this.compat && isCompat(this.header.key, manifest)))) {
564
564
  throw INVALID_SIGNATURE('Proof contains an invalid manifest') // TODO: proper error type
package/lib/manifest.js CHANGED
@@ -144,7 +144,6 @@ function createManifest (inp) {
144
144
  if (!inp) return null
145
145
 
146
146
  const manifest = {
147
- encrypted: !!inp.encrypted,
148
147
  hash: 'blake2b',
149
148
  static: null,
150
149
  signer: null,
@@ -196,9 +195,8 @@ function validateSigner (signer) {
196
195
  if (signer.signature && signer.signature !== 'ed25519') throw BAD_ARGUMENT('Only Ed25519 signatures are supported')
197
196
  }
198
197
 
199
- function defaultSignerManifest (publicKey, encrypted) {
198
+ function defaultSignerManifest (publicKey) {
200
199
  return {
201
- encrypted,
202
200
  hash: 'blake2b',
203
201
  static: null,
204
202
  signer: {
package/lib/messages.js CHANGED
@@ -89,7 +89,6 @@ const multipleSigners = {
89
89
  const manifest = exports.manifest = {
90
90
  preencode (state, m) {
91
91
  c.uint.preencode(state, 0) // version
92
- c.uint.preencode(state, 0) // flags
93
92
  hashes.preencode(state, m.hash)
94
93
  c.uint.preencode(state, 2) // type
95
94
 
@@ -107,7 +106,6 @@ const manifest = exports.manifest = {
107
106
  },
108
107
  encode (state, m) {
109
108
  c.uint.encode(state, 0) // version
110
- c.uint.encode(state, m.encrypted ? 1 : 0)
111
109
  hashes.encode(state, m.hash)
112
110
  c.uint.encode(state, m.signer ? 1 : m.multipleSigners ? 2 : 0)
113
111
 
@@ -127,14 +125,12 @@ const manifest = exports.manifest = {
127
125
  const version = c.uint.decode(state)
128
126
  if (version !== 0) throw new Error('Invalid version: ' + version)
129
127
 
130
- const flags = c.uint.decode(state)
131
128
  const hash = hashes.decode(state)
132
129
  const type = c.uint.decode(state)
133
130
 
134
131
  if (type > 2) throw new Error('Unknown type: ' + type)
135
132
 
136
133
  return {
137
- encrypted: (flags & 1) !== 0,
138
134
  hash,
139
135
  static: type === 0 ? c.fixed32.decode(state) : null,
140
136
  signer: type === 1 ? signer.decode(state) : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.27.1",
3
+ "version": "10.28.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {