hypercore 11.0.12 → 11.0.13

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
@@ -230,6 +230,7 @@ class Hypercore extends EventEmitter {
230
230
 
231
231
  async setEncryptionKey (encryptionKey, opts) {
232
232
  if (!this.opened) await this.opening
233
+ if (this.core.unencrypted) return
233
234
  this.encryption = encryptionKey ? new BlockEncryption(encryptionKey, this.key, { compat: this.core.compat, ...opts }) : null
234
235
  if (!this.core.encryption) this.core.encryption = this.encryption
235
236
  }
@@ -317,7 +318,7 @@ class Hypercore extends EventEmitter {
317
318
 
318
319
  if (this.keyPair === null) this.keyPair = opts.keyPair || this.core.header.keyPair
319
320
 
320
- if (!this.core.encryption) {
321
+ if (!this.core.encryption && !this.core.unencrypted) {
321
322
  const e = getEncryptionOption(opts)
322
323
  if (e) this.core.encryption = new BlockEncryption(e.key, this.key, { compat: this.core.compat, ...e })
323
324
  }
@@ -759,7 +760,8 @@ class Hypercore extends EventEmitter {
759
760
  block = b4a.from(block)
760
761
 
761
762
  if (this.encryption.compat !== this.core.compat) this._updateEncryption()
762
- this.encryption.decrypt(index, block)
763
+ if (this.core.unencrypted) this.encryption = null
764
+ else this.encryption.decrypt(index, block)
763
765
  }
764
766
 
765
767
  return this._decode(encoding, block)
@@ -903,13 +905,13 @@ class Hypercore extends EventEmitter {
903
905
  const defaultKeyPair = this.state.name === null ? this.keyPair : null
904
906
 
905
907
  const { keyPair = defaultKeyPair, signature = null } = opts
906
- const writable = !isDefault || !!signature || !!(keyPair && keyPair.secretKey)
908
+ const writable = !isDefault || !!signature || !!(keyPair && keyPair.secretKey) || opts.writable === true
907
909
 
908
910
  if (this._readonly || writable === false) throw SESSION_NOT_WRITABLE()
909
911
 
910
912
  blocks = Array.isArray(blocks) ? blocks : [blocks]
911
913
 
912
- const preappend = this.encryption && this._preappend
914
+ const preappend = this.core.unencrypted ? null : (this.encryption && this._preappend)
913
915
 
914
916
  const buffers = this.encodeBatch !== null ? this.encodeBatch(blocks) : new Array(blocks.length)
915
917
 
package/lib/core.js CHANGED
@@ -41,6 +41,7 @@ module.exports = class Core {
41
41
  this.verifier = null
42
42
  this.truncating = 0
43
43
  this.updating = false
44
+ this.unencrypted = false
44
45
  this.skipBitfield = null
45
46
  this.globalCache = opts.globalCache || null
46
47
  this.autoClose = opts.autoClose !== false
@@ -267,7 +268,10 @@ module.exports = class Core {
267
268
  }
268
269
 
269
270
  // to unslab
270
- if (header.manifest) header.manifest = Verifier.createManifest(header.manifest)
271
+ if (header.manifest) {
272
+ header.manifest = Verifier.createManifest(header.manifest)
273
+ this.unencrypted = header.manifest.unencrypted
274
+ }
271
275
 
272
276
  const verifier = header.manifest ? new Verifier(header.key, header.manifest, { crypto, legacy }) : null
273
277
 
@@ -332,6 +336,7 @@ module.exports = class Core {
332
336
  if (verifier.prologue) this.state.prologue = Object.assign({}, verifier.prologue)
333
337
 
334
338
  this.manifest = this.header.manifest = manifest
339
+ this.unencrypted = this.manifest.unencrypted
335
340
 
336
341
  tx.setAuth({
337
342
  key: this.header.key,
package/lib/messages.js CHANGED
@@ -136,7 +136,8 @@ const manifestv0 = {
136
136
  prologue: {
137
137
  hash: c.fixed32.decode(state),
138
138
  length: 0
139
- }
139
+ },
140
+ unencrypted: false
140
141
  }
141
142
  }
142
143
 
@@ -147,7 +148,8 @@ const manifestv0 = {
147
148
  allowPatch: false,
148
149
  quorum: 1,
149
150
  signers: [signer.decode(state)],
150
- prologue: null
151
+ prologue: null,
152
+ unencrypted: false
151
153
  }
152
154
  }
153
155
 
@@ -159,7 +161,8 @@ const manifestv0 = {
159
161
  allowPatch: (flags & 1) !== 0,
160
162
  quorum: c.uint.decode(state),
161
163
  signers: signerArray.decode(state),
162
- prologue: null
164
+ prologue: null,
165
+ unencrypted: false
163
166
  }
164
167
  }
165
168
  }
@@ -180,7 +183,7 @@ const manifest = exports.manifest = {
180
183
  c.uint.encode(state, m.version)
181
184
  if (m.version === 0) return manifestv0.encode(state, m)
182
185
 
183
- c.uint.encode(state, (m.allowPatch ? 1 : 0) | (m.prologue ? 2 : 0))
186
+ c.uint.encode(state, (m.allowPatch ? 1 : 0) | (m.prologue ? 2 : 0) | (m.unencrypted ? 4 : 0))
184
187
  hashes.encode(state, m.hash)
185
188
 
186
189
  c.uint.encode(state, m.quorum)
@@ -196,6 +199,7 @@ const manifest = exports.manifest = {
196
199
  const hash = hashes.decode(state)
197
200
  const quorum = c.uint.decode(state)
198
201
  const signers = signerArray.decode(state)
202
+ const unencrypted = (flags & 4) !== 0
199
203
 
200
204
  return {
201
205
  version: 1,
@@ -203,7 +207,8 @@ const manifest = exports.manifest = {
203
207
  allowPatch: (flags & 1) !== 0,
204
208
  quorum,
205
209
  signers,
206
- prologue: (flags & 2) === 0 ? null : prologue.decode(state)
210
+ prologue: (flags & 2) === 0 ? null : prologue.decode(state),
211
+ unencrypted
207
212
  }
208
213
  }
209
214
  }
package/lib/verifier.js CHANGED
@@ -200,7 +200,8 @@ module.exports = class Verifier {
200
200
  allowPatch: !!inp.allowPatch,
201
201
  quorum: defaultQuorum(inp),
202
202
  signers: inp.signers ? inp.signers.map(parseSigner) : [],
203
- prologue: null
203
+ prologue: null,
204
+ unencrypted: !!inp.unencrypted
204
205
  }
205
206
 
206
207
  if (inp.hash && inp.hash !== 'blake2b') throw BAD_ARGUMENT('Only Blake2b hashes are supported')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.0.12",
3
+ "version": "11.0.13",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {