hypercore 10.32.1 → 10.32.2

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.
Files changed (2) hide show
  1. package/lib/verifier.js +14 -8
  2. package/package.json +1 -1
package/lib/verifier.js CHANGED
@@ -47,13 +47,14 @@ class CompatSigner extends Signer {
47
47
  module.exports = class Verifier {
48
48
  constructor (manifest, { compat = false, crypto = defaultCrypto, legacy = false } = {}) {
49
49
  this.compat = compat || manifest === null
50
- this.manifest = manifest
51
- this.version = this.compat ? 0 : typeof this.manifest.version === 'number' ? this.manifest.version : 1
50
+ this.version = this.compat ? 0 : typeof manifest.version === 'number' ? manifest.version : 1
52
51
  this.hash = manifest.hash || 'blake2b'
53
- this.allowPatch = !this.compat && !!this.manifest.allowPatch
54
- this.quorum = this.compat ? 1 : (this.manifest.quorum || 0)
55
- this.signers = this.manifest.signers.map((s, index) => this.compat ? new CompatSigner(crypto, index, s, legacy) : new Signer(crypto, index, s))
56
- this.prologue = this.compat ? null : (this.manifest.prologue || null)
52
+ this.allowPatch = !this.compat && !!manifest.allowPatch
53
+ this.quorum = this.compat ? 1 : defaultQuorum(manifest)
54
+ this.signers = manifest.signers
55
+ ? manifest.signers.map((s, index) => this.compat ? new CompatSigner(crypto, index, s, legacy) : new Signer(crypto, index, s))
56
+ : []
57
+ this.prologue = this.compat ? null : (manifest.prologue || null)
57
58
  }
58
59
 
59
60
  _verifyCompat (batch, signature) {
@@ -169,8 +170,8 @@ module.exports = class Verifier {
169
170
  version: typeof inp.version === 'number' ? inp.version : 1,
170
171
  hash: 'blake2b',
171
172
  allowPatch: !!inp.allowPatch,
172
- quorum: inp.quorum || 0,
173
- signers: inp.signers.map(parseSigner),
173
+ quorum: defaultQuorum(inp),
174
+ signers: inp.signers ? inp.signers.map(parseSigner) : [],
174
175
  prologue: null
175
176
  }
176
177
 
@@ -206,6 +207,11 @@ function toMap (nodes) {
206
207
  return m
207
208
  }
208
209
 
210
+ function defaultQuorum (man) {
211
+ if (!man.signers) return 0
212
+ return typeof man.quorum === 'number' ? man.quorum : (man.signers.length >> 1) + 1
213
+ }
214
+
209
215
  function generateUpgrade (patch, start, length) {
210
216
  const upgrade = { start, length, nodes: null, additionalNodes: [] }
211
217
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.32.1",
3
+ "version": "10.32.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {