![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
hypercore-protocol-substream
Advanced tools
Create independent virtual streams on a hypercore-protocol stream
Independent virtual streams through a hypercore-protocol stream
// Substreams can be created on any
const substream = require('hypercore-protocol-substream')
const protocol = require('hypercore-protocol')
const hypercore = require('hyprecore')
const core = hypercore(storage, key)
// Register the substream proto-extension
const stream = core.replicate({ extensions: [substream.EXTENSION] })
// Initialize new virtual stream as namespace 'beef'
const virt1 = substream(stream, Buffer.from('beef'))
// Connected event is fired when a virtual stream with the same
// namespace have been initialized on the remote end.
virt1.on('connected', (virt1) => {
virt1.write('Hello remote!')
})
// A virtual stream is a regular full-duplex stream
virt1.on('data', console.log)
virt1.on('error', console.error)
virt1.on('end', console.log('Stream has ended'))
// Ending the stream in one end, also signals end to the remote.
virt1.end('bye bye')
// Alternative initializer
substream(stream, Buffer.from('second'), (err, virtual2) => { // on connect
if (err) throw err
const replStream = core.replicate({ live: true })
replStream.pipe(virtual2).pipe(replStream) // replicate as usual.
})
// Once you've initiated a hypercore-protocol stream with substream's extension
// You can listen for incoming streams without any knowledge of the namespace.
const connectionHandler = (handshake) => {
if (handshake.payload === 'Please Respond') {
const virtual3 = substream(stream, handshake.id)
virtual3.end('Hey!')
}
}
stream.on('substream-connected', connectionHandler)
stream.once('end', () => stream.off('substream-connected', connectionHandler)
/*
* Alternatively create a manual hyperprotocol-stream
*/
const key = Buffer.alloc(32)
key.write('encryption secret')
const stream2 = protocol({extensions: [substream.EXTENSION]})
const vFeed = protocol.feed(key) // a main feed needs to be initialized manually
const vitual4 = substream(stream2, Buffer.from('dc'))
substream(stream, namespace, opts, callback')
stream
a hypercore-protocol stream
namespace
a buffer, keep it short if possible, as it produces overhead on
your data.
opts
Object
{
timeout: 5000 // Time to spend in init for remote to answer the call.
// causes 'HandshakeTimeoutError' error to be emitted
}
callback
optional function (error, virtualStream)
that will be called when stream becomes either
active or fails to initialize.
VirtualStream
event connected
Emitted when a connection has been established on both peer's ends.
Note: the sub stream is initialized in corked and paused state.
It is resumed and uncorked after the connected
event has been fired.
MainStream
event substream-disconnected
Once your main stream has been initialized with the extension
substream.EXTENSION
- the substream-connected
event will be fired
whenever an active virtual stream is disconnected either on your or the remote's
end.
MainStream
event substream-connected
Once your main stream has been initialized with the extension
substream.EXTENSION
- the substream-connected
event will be fired
whenever a virtual stream on the remote peer sends a handshake
MIT
FAQs
Create independent virtual streams on a hypercore-protocol stream
We found that hypercore-protocol-substream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.