
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
peersockets
Advanced tools
Directly connect to peers via hyperswarm (or an API-compatible alternative).
Warning: Extension messages are currently not MAC'd, so we can't detect tampering. This is still experimental!
Peersockets is a lightweight wrapper around corestore-swarm-networker that lets you exchange topic-tagged messages with peers over hypercore-protocol streams.
To use a Peersocket, you first join a topic -- under the hood, this will register a topic-specific extension on every current peer connection in your networker. By defining topics at the extension level, Peersockets does not need to do any extra encoding/decoding. Once you've created a topic, you can send messages to peers by their NOISE keys. If the remote peer has also joined the topic, they will receive the message.
In the future, it'd be cool to support a broadcast method as well! Supporting topic broadcasts in the v0 version would add complexity, though, and would be challenging to do without leaking topic names to the wrong peers.
npm i peersockets --save
This example assumes you already have Networker (corestore-swarm-networking) instance. You can use anything that emits handshake and stream-closed events, though!
const networker = (my swarm networker)
const sockets = new Peersockets(networker)
// Let's say you have a friend's NOISE key, and you're already swarming with them.
const friendKey = ...
const handle = sockets.join('my-topic', {
onmessage: (msg, peer) => {
console.log(`I got message ${msg} from ${peer.remotePublicKeytoString('hex')}`)
}
})
// If your friend is also subscribed to topic 'my-topic', they will receive this message.
handle.send(friendKey, 'hello!')
const socket = new Peersockets(networker)Creates a new Peersockets instance.
networker is an instance of @corestore/networker).const handler = socket.join(topicName, opts = { onmessage, onclose })Joins a new topic. If this is the first time the topic has been joined, a topic extension will be registered on every connected peer. Otherwise the previous topic/extension will be reused.
topicName can be any stringopts can contain the following callbacks:
onmessage(remoteKey, msg) - Called whenever a message with this topic is received from remoteKey.onclose() - Called if the topic is closed via leave.The topic handler's API is described below.
socket.leave([topicName])Close all topic handlers for topicName and unregister the topic's extension from all connected peers.
If a topicName is not specified, all topics will be left.
topicHandle.send(msg, peer)Send a message to peer.
msg is a string or a Buffer.
peer is a @corestore/networker Peer instance that can be obtained from networker.peers.
topicHandle.close()Close the handle when you're finished with it. This will not unregister the topic extension.
MIT
FAQs
Directly connect to peers via hyperswarm (or an API-compatible alternative).
We found that peersockets 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.