hypercore-signing-request 4.0.0 → 4.0.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/index.js +9 -11
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -90,7 +90,6 @@ async function generate (core, { length = core.length, fork = core.fork, manifes
90
90
  if (core.blobs) return generateDrive(core, { length, fork, manifest })
91
91
 
92
92
  if (core.core.compat && !manifest) throw new Error('Cannot generate signing requests for compat cores')
93
- if (core.fork !== fork) throw new Error('Core should have the same fork')
94
93
  if (!manifest) manifest = core.manifest
95
94
 
96
95
  return c.encode(Request, {
@@ -109,10 +108,7 @@ async function generateDrive (drive, { length = drive.core.length, fork = drive.
109
108
  if (!manifest) manifest = drive.core.manifest
110
109
  if (manifest < 1) throw new Error('Only v1 manifests are supported')
111
110
 
112
- const last = await drive.db.getBySeq(length - 1)
113
- const { blockOffset, blockLength } = last.value.blob
114
-
115
- const contentLength = blockOffset + blockLength
111
+ const contentLength = await drive.getBlobsLength(length)
116
112
  const content = {
117
113
  length: contentLength,
118
114
  treeHash: await drive.blobs.core.treeHash(contentLength)
@@ -141,19 +137,21 @@ function decode (buffer) {
141
137
  function signable (pub, req) {
142
138
  const v = req.manifest.version
143
139
 
144
- for (const s of req.manifest.signers) {
140
+ for (let signer = 0; signer < req.manifest.signers.length; signer++) {
141
+ const s = req.manifest.signers[signer]
145
142
  if (!s.publicKey.equals(pub)) continue
146
143
 
147
- if (req.isHyperdrive) return driveSignable(pub, req)
144
+ if (req.isHyperdrive) return driveSignable(pub, req, signer)
148
145
 
149
146
  const signable = caps.treeSignable(v === 0 ? s.namespace : req.key, req.treeHash, req.length, req.fork)
150
- return [signable]
147
+
148
+ return [{ signer, signable }]
151
149
  }
152
150
 
153
151
  throw new Error('Public key is not a declared signer for this request')
154
152
  }
155
153
 
156
- function driveSignable (pub, req) {
154
+ function driveSignable (pub, req, signer) {
157
155
  const contentKey = Hyperdrive.getContentKey(req.manifest)
158
156
  if (!contentKey) {
159
157
  throw new Error('Drive is not compatible, needs v1 manifest')
@@ -163,7 +161,7 @@ function driveSignable (pub, req) {
163
161
  const content = caps.treeSignable(contentKey, req.content.treeHash, req.content.length, req.fork)
164
162
 
165
163
  return [
166
- signable,
167
- content
164
+ { signer, signable },
165
+ { signer, signable: content }
168
166
  ]
169
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-signing-request",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Generate shareable signing requests for Hypercore",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,8 +12,8 @@
12
12
  "dependencies": {
13
13
  "compact-encoding": "^2.13.0",
14
14
  "hypercore": "^10.32.8",
15
- "hyperdrive": "^11.7.0",
16
- "hypercore-id-encoding": "^1.2.0"
15
+ "hypercore-id-encoding": "^1.2.0",
16
+ "hyperdrive": "^11.8.1"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",