New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-hypercore-protocol

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-hypercore-protocol - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

6

index.js

@@ -13,3 +13,3 @@ const Handshake = require('./lib/handshake')

constructor (initiator, handlers) {
const payload = { nonce: XOR.nonce(), userData: handlers.userData }
const payload = { nonce: XOR.nonce() }

@@ -22,5 +22,2 @@ this.handlers = handlers || {}

this.remoteUserData = null
this.userData = handlers.userData || null
this._initiator = initiator

@@ -163,3 +160,2 @@ this._payload = payload

this.remotePayload = remotePayload
this.remoteUserData = remotePayload.userData

@@ -166,0 +162,0 @@ if (this.handlers.onhandshake) this.handlers.onhandshake()

const SH = require('simple-handshake')
const varint = require('varint')
const assert = require('nanoassert')
module.exports = class ProtocolHandshake {
constructor (initiator, payload, opts, done) {
assert(payload.length <= 32768, 'Total handshake payload must be <= 32KB')
this.options = opts

@@ -10,0 +7,0 @@ this.ondone = done

@@ -111,89 +111,4 @@ // This file is auto generated by the protocol-buffers compiler

function defineNoisePayload () {
var UserData = NoisePayload.UserData = {
buffer: true,
encodingLength: null,
encode: null,
decode: null
}
defineUserData()
function defineUserData () {
var enc = [
encodings.string,
encodings.bytes
]
UserData.encodingLength = encodingLength
UserData.encode = encode
UserData.decode = decode
function encodingLength (obj) {
var length = 0
if (!defined(obj.type)) throw new Error("type is required")
var len = enc[0].encodingLength(obj.type)
length += 1 + len
if (defined(obj.value)) {
var len = enc[1].encodingLength(obj.value)
length += 1 + len
}
return length
}
function encode (obj, buf, offset) {
if (!offset) offset = 0
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
var oldOffset = offset
if (!defined(obj.type)) throw new Error("type is required")
buf[offset++] = 10
enc[0].encode(obj.type, buf, offset)
offset += enc[0].encode.bytes
if (defined(obj.value)) {
buf[offset++] = 18
enc[1].encode(obj.value, buf, offset)
offset += enc[1].encode.bytes
}
encode.bytes = offset - oldOffset
return buf
}
function decode (buf, offset, end) {
if (!offset) offset = 0
if (!end) end = buf.length
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
var oldOffset = offset
var obj = {
type: "",
value: null
}
var found0 = false
while (true) {
if (end <= offset) {
if (!found0) throw new Error("Decoded message is not valid")
decode.bytes = offset - oldOffset
return obj
}
var prefix = varint.decode(buf, offset)
offset += varint.decode.bytes
var tag = prefix >> 3
switch (tag) {
case 1:
obj.type = enc[0].decode(buf, offset)
offset += enc[0].decode.bytes
found0 = true
break
case 2:
obj.value = enc[1].decode(buf, offset)
offset += enc[1].decode.bytes
break
default:
offset = skip(prefix & 7, buf, offset)
}
}
}
}
var enc = [
encodings.bytes,
UserData
encodings.bytes
]

@@ -210,7 +125,2 @@

length += 1 + len
if (defined(obj.userData)) {
var len = enc[1].encodingLength(obj.userData)
length += varint.encodingLength(len)
length += 1 + len
}
return length

@@ -227,9 +137,2 @@ }

offset += enc[0].encode.bytes
if (defined(obj.userData)) {
buf[offset++] = 18
varint.encode(enc[1].encodingLength(obj.userData), buf, offset)
offset += varint.encode.bytes
enc[1].encode(obj.userData, buf, offset)
offset += enc[1].encode.bytes
}
encode.bytes = offset - oldOffset

@@ -245,4 +148,3 @@ return buf

var obj = {
nonce: null,
userData: null
nonce: null
}

@@ -265,8 +167,2 @@ var found0 = false

break
case 2:
var len = varint.decode(buf, offset)
offset += varint.decode.bytes
obj.userData = enc[1].decode(buf, offset, offset + len)
offset += enc[1].decode.bytes
break
default:

@@ -273,0 +169,0 @@ offset = skip(prefix & 7, buf, offset)

3

package.json
{
"name": "simple-hypercore-protocol",
"version": "1.3.0",
"version": "1.3.1",
"description": "Hypercore protocol state machine",
"main": "index.js",
"dependencies": {
"nanoassert": "^2.0.0",
"protocol-buffers-encodings": "^1.1.0",

@@ -9,0 +8,0 @@ "simple-handshake": "^1.3.1",

@@ -195,14 +195,2 @@ const tape = require('tape')

tape('check handshake payload size', function (t) {
t.plan(1)
t.throws(function () {
return new SHP(true, {
userData: {
type: 'biggie',
value: Buffer.alloc(32 * 1024)
}
})
})
})
tape('set key pair later', function (t) {

@@ -209,0 +197,0 @@ let later = null

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc