hypercore-signing-request 5.1.0 → 5.1.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 +25 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -57,7 +57,7 @@ const Request = {
57
57
  throw new Error('Unknown signing request version: ' + version)
58
58
  }
59
59
 
60
- const type = version < COMPAT_VERSION ? REQUEST : c.uint8.decode(state)
60
+ const type = version <= COMPAT_VERSION ? REQUEST : c.uint8.decode(state)
61
61
  if (type !== REQUEST) {
62
62
  throw new Error('Expected an encoded request')
63
63
  }
@@ -126,7 +126,7 @@ const Response = {
126
126
  throw new Error('Response version is not supported, please upgrade')
127
127
  }
128
128
 
129
- const type = version > COMPAT_VERSION ? c.uint8.decode(state) : RESPONSE
129
+ const type = version <= COMPAT_VERSION ? RESPONSE : c.uint8.decode(state)
130
130
  if (type !== RESPONSE) {
131
131
  throw new Error('Expected an encoded response')
132
132
  }
@@ -147,7 +147,9 @@ module.exports = {
147
147
  decode,
148
148
  encodeResponse,
149
149
  decodeResponse,
150
- signable
150
+ signable,
151
+ isRequest,
152
+ isResponse
151
153
  }
152
154
 
153
155
  async function generate (core, { length = core.length, fork = core.fork, manifest = null } = {}) {
@@ -190,6 +192,26 @@ async function generateDrive (drive, { length = drive.core.length, fork = drive.
190
192
  })
191
193
  }
192
194
 
195
+ function isRequest (buffer) {
196
+ const state = { start: 0, end: buffer.byteLength, buffer }
197
+
198
+ const version = c.uint.decode(state)
199
+ if (version <= COMPAT_VERSION) return true
200
+
201
+ const type = c.uint8.decode(state)
202
+ return type === REQUEST
203
+ }
204
+
205
+ function isResponse (buffer) {
206
+ const state = { start: 0, end: buffer.byteLength, buffer }
207
+
208
+ const version = c.uint.decode(state)
209
+ if (version <= COMPAT_VERSION) return true
210
+
211
+ const type = c.uint8.decode(state)
212
+ return type === RESPONSE
213
+ }
214
+
193
215
  function decode (buffer) {
194
216
  const state = { start: 0, end: buffer.byteLength, buffer }
195
217
  const req = Request.decode(state)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-signing-request",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Generate shareable signing requests for Hypercore",
5
5
  "main": "index.js",
6
6
  "scripts": {