hypercore 10.32.1 → 10.32.3

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/lib/messages.js CHANGED
@@ -87,6 +87,11 @@ const manifestv0 = {
87
87
  hashes.preencode(state, m.hash)
88
88
  state.end++ // type
89
89
 
90
+ if (m.prologue && m.signers.length === 0) {
91
+ c.fixed32.preencode(state, m.prologue.hash)
92
+ return
93
+ }
94
+
90
95
  if (m.quorum === 1 && m.signers.length === 1 && !m.allowPatch) {
91
96
  signer.preencode(state, m.signers[0])
92
97
  } else {
@@ -98,6 +103,12 @@ const manifestv0 = {
98
103
  encode (state, m) {
99
104
  hashes.encode(state, m.hash)
100
105
 
106
+ if (m.prologue && m.signers.length === 0) {
107
+ c.uint.encode(state, 0)
108
+ c.fixed32.encode(state, m.prologue.hash)
109
+ return
110
+ }
111
+
101
112
  if (m.quorum === 1 && m.signers.length === 1 && !m.allowPatch) {
102
113
  c.uint.encode(state, 1)
103
114
  signer.encode(state, m.signers[0])
@@ -112,9 +123,22 @@ const manifestv0 = {
112
123
  const hash = hashes.decode(state)
113
124
  const type = c.uint.decode(state)
114
125
 
115
- if (type === 0) throw new Error('Type 0 is deprecated')
116
126
  if (type > 2) throw new Error('Unknown type: ' + type)
117
127
 
128
+ if (type === 0) {
129
+ return {
130
+ version: 0,
131
+ hash,
132
+ allowPatch: false,
133
+ quorum: 0,
134
+ signers: [],
135
+ prologue: {
136
+ hash: c.fixed32.decode(state),
137
+ length: 0
138
+ }
139
+ }
140
+ }
141
+
118
142
  if (type === 1) {
119
143
  return {
120
144
  version: 0,
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,12 @@ function toMap (nodes) {
206
207
  return m
207
208
  }
208
209
 
210
+ function defaultQuorum (man) {
211
+ if (typeof man.quorum === 'number') return man.quorum
212
+ if (!man.signers || !man.signers.length) return 0
213
+ return (man.signers.length >> 1) + 1
214
+ }
215
+
209
216
  function generateUpgrade (patch, start, length) {
210
217
  const upgrade = { start, length, nodes: null, additionalNodes: [] }
211
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.32.1",
3
+ "version": "10.32.3",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {