hypercore 10.23.0 → 10.24.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
@@ -8,6 +8,7 @@ const Xache = require('xache')
8
8
  const NoiseSecretStream = require('@hyperswarm/secret-stream')
9
9
  const Protomux = require('protomux')
10
10
  const z32 = require('z32')
11
+ const id = require('hypercore-id-encoding')
11
12
 
12
13
  const Replicator = require('./lib/replicator')
13
14
  const Core = require('./lib/core')
@@ -42,16 +43,9 @@ module.exports = class Hypercore extends EventEmitter {
42
43
  key = opts.key || null
43
44
  }
44
45
 
45
- if (key && typeof key === 'string') {
46
- key = b4a.from(key, 'hex')
47
- }
48
-
46
+ if (key && typeof key === 'string') key = id.decode(key)
49
47
  if (!opts) opts = {}
50
48
 
51
- if (!opts.crypto && key && key.byteLength !== 32) {
52
- throw BAD_ARGUMENT('Hypercore key should be 32 bytes')
53
- }
54
-
55
49
  if (!storage) storage = opts.storage
56
50
 
57
51
  this[promises] = true
@@ -85,7 +79,6 @@ module.exports = class Hypercore extends EventEmitter {
85
79
  this.closing = null
86
80
  this.opening = null
87
81
 
88
- this._manifest = opts.manifest || null
89
82
  this._clone = opts.clone || null
90
83
  this._readonly = opts.writable === false
91
84
  this._preappend = preappend.bind(this)
@@ -546,7 +539,7 @@ module.exports = class Hypercore extends EventEmitter {
546
539
  }
547
540
 
548
541
  get manifest () {
549
- return this._manifest || (this.core === null ? null : this.core.header.manifest)
542
+ return this.core === null ? null : this.core.header.manifest
550
543
  }
551
544
 
552
545
  get length () {
@@ -642,8 +635,7 @@ module.exports = class Hypercore extends EventEmitter {
642
635
 
643
636
  if (status & 0b10000) {
644
637
  for (let i = 0; i < this.sessions.length; i++) {
645
- const s = this.sessions[i]
646
- if (!s._manifest) s.emit('manifest')
638
+ this.sessions[i].emit('manifest')
647
639
  }
648
640
  }
649
641
 
package/lib/core.js CHANGED
@@ -494,7 +494,7 @@ module.exports = class Core {
494
494
 
495
495
  const verifier = this.verifier || createVerifier(manifest, { compat: isCompat(this.header.key, manifest), crypto: this.crypto, legacy: this._legacy })
496
496
 
497
- if (!batch.signature || !verifier.verify(batch, batch.signature)) {
497
+ if (!verifier.verify(batch, batch.signature)) {
498
498
  throw INVALID_SIGNATURE('Proof contains an invalid signature')
499
499
  }
500
500
 
package/lib/manifest.js CHANGED
@@ -44,6 +44,7 @@ class CompatVerifier {
44
44
  }
45
45
 
46
46
  verify (batch, signature) {
47
+ if (!signature) return false
47
48
  return this.crypto.verify(batch.signableCompat(this.legacy), signature, this.publicKey)
48
49
  }
49
50
  }
@@ -63,6 +64,7 @@ class SingleVerifier {
63
64
  }
64
65
 
65
66
  verify (batch, signature) {
67
+ if (!signature) return false
66
68
  return this.crypto.verify(batch.signable(this.namespace), signature, this.publicKey)
67
69
  }
68
70
  }
@@ -82,6 +84,8 @@ class MultiVerifier {
82
84
  }
83
85
 
84
86
  verify (batch, signature) {
87
+ if (!signature) return false
88
+
85
89
  const inputs = multisig.inflate(signature)
86
90
 
87
91
  if (inputs.length < this.quorum) return false
@@ -188,7 +192,7 @@ function parseSigner (signer) {
188
192
 
189
193
  function validateSigner (signer) {
190
194
  if (!signer || !signer.publicKey) throw BAD_ARGUMENT('Signer missing public key')
191
- if (signer.signature !== 'ed25519') throw BAD_ARGUMENT('Only Ed25519 signatures are supported')
195
+ if (signer.signature && signer.signature !== 'ed25519') throw BAD_ARGUMENT('Only Ed25519 signatures are supported')
192
196
  }
193
197
 
194
198
  function defaultSignerManifest (publicKey) {
package/lib/multisig.js CHANGED
@@ -24,9 +24,9 @@ function inflate (data) {
24
24
  return inputs
25
25
  }
26
26
 
27
- async function partialSignature (core, signer, from, to = core.core.tree.length, signature = core.core.tree.signature) {
28
- if (from > core.core.tree.length) return null
29
- const patch = to <= from ? null : await upgrade(core, from, to)
27
+ async function partialSignature (tree, signer, from, to = tree.length, signature = tree.signature) {
28
+ if (from > tree.length) return null
29
+ const patch = to <= from ? null : await upgrade(tree, from, to)
30
30
 
31
31
  return {
32
32
  signer,
@@ -35,8 +35,8 @@ async function partialSignature (core, signer, from, to = core.core.tree.length,
35
35
  }
36
36
  }
37
37
 
38
- async function upgrade (core, from, to) {
39
- const p = await core.core.tree.proof({ upgrade: { start: from, length: to - from } })
38
+ async function upgrade (tree, from, to) {
39
+ const p = await tree.proof({ upgrade: { start: from, length: to - from } })
40
40
  p.upgrade.additionalNodes = []
41
41
  p.upgrade.signature = null
42
42
  return p.upgrade
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.23.0",
3
+ "version": "10.24.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "flat-tree": "^1.9.0",
46
46
  "hypercore-crypto": "^3.2.1",
47
47
  "hypercore-errors": "^1.1.0",
48
+ "hypercore-id-encoding": "^1.2.0",
48
49
  "is-options": "^1.0.1",
49
50
  "protomux": "^3.5.0",
50
51
  "quickbit-universal": "^2.1.1",