hypercore-signing-request 2.0.0 → 3.0.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.
Files changed (2) hide show
  1. package/index.js +15 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,31 +6,29 @@ const c = require('compact-encoding')
6
6
 
7
7
  const VERSION = 1
8
8
 
9
- const FramedManifest = c.frame(m.manifest)
10
-
11
9
  const Request = {
12
10
  preencode (state, req) {
13
11
  c.uint.preencode(state, req.version)
14
- FramedManifest.preencode(state, req.manifest)
15
- c.fixed32.preencode(state, req.treeHash)
16
12
  c.uint.preencode(state, req.length)
17
13
  c.uint.preencode(state, req.fork)
14
+ c.fixed32.preencode(state, req.treeHash)
15
+ m.manifest.preencode(state, req.manifest)
18
16
  },
19
17
  encode (state, req) {
20
18
  c.uint.encode(state, req.version)
21
- FramedManifest.encode(state, req.manifest)
22
- c.fixed32.encode(state, req.treeHash)
23
19
  c.uint.encode(state, req.length)
24
20
  c.uint.encode(state, req.fork)
21
+ c.fixed32.encode(state, req.treeHash)
22
+ m.manifest.encode(state, req.manifest)
25
23
  },
26
24
  decode (state) {
27
25
  const version = c.uint.decode(state)
28
26
  if (version !== VERSION) throw new Error('Unknown signing request version: ' + version)
29
27
 
30
- const manifest = FramedManifest.decode(state)
31
- const treeHash = c.fixed32.decode(state)
32
28
  const length = c.uint.decode(state)
33
29
  const fork = c.uint.decode(state)
30
+ const treeHash = c.fixed32.decode(state)
31
+ const manifest = m.manifest.decode(state)
34
32
 
35
33
  const key = Verifier.manifestHash(manifest)
36
34
  const id = HypercoreID.normalize(key)
@@ -39,24 +37,27 @@ const Request = {
39
37
  version,
40
38
  id,
41
39
  key,
42
- manifest,
43
- treeHash,
44
40
  length,
45
- fork
41
+ fork,
42
+ treeHash,
43
+ manifest
46
44
  }
47
45
  }
48
46
  }
49
47
 
50
48
  module.exports = {
51
49
  async generate (core, { length = core.length, fork = core.fork } = {}) {
50
+ if (!core.opened) await core.ready()
51
+
52
52
  if (core.core.compat) throw new Error('Cannot generate signing requests for compat cores')
53
+ if (cork.fork !== fork) throw new Error('Core should have the same fork')
53
54
 
54
55
  return c.encode(Request, {
55
56
  version: VERSION,
56
- manifest: core.manifest,
57
- treeHash: await core.treeHash(length),
58
57
  length,
59
- fork
58
+ fork,
59
+ treeHash: await core.treeHash(length),
60
+ manifest: core.manifest
60
61
  })
61
62
  },
62
63
  decode (buffer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-signing-request",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Generate shareable signing requests for Hypercore",
5
5
  "main": "index.js",
6
6
  "files": [