
Security News
vlt Launches Real-Time Dependency Analysis Powered by Socket
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.
dht-universal
Advanced tools
Universal wrapper for @hyperswarm/dht and @hyperswarm/dht-relay working in Node.js and the Browser
Universal wrapper for @hyperswarm/dht
and @hyperswarm/dht-relay
working in Node.js and the Browser
npm install dht-universal
In browser, it will use the @hyperswarm/dht-relay
with a WebSocket
transport, so you need to pass a relay URL to the constructor, and wait for it to be ready to confirm the websocket is open.
import { DHT } from 'dht-universal';
const node = new DHT({ relay: 'wss://dht-relay.example.com/' });
await node.ready();
You can also use the static async function create
to try multiple relays until one works.
import { DHT } from 'dht-universal';
const node = await DHT.create({
relays: ['wss://dht-relay.example.com/'],
...opts,
});
// No need to call `await node.ready()`
If you want to use the relay in Node, you can import it explicitly:
import { DHT } from 'dht-universal/relay.js';
const node = await DHT.create({
relays: ['wss://dht-relay.example.com/'],
...opts,
});
Should be the same as @hyperswarm/dht.
The goal of this module is to ensure the usability of the DHT in the browser within the common use cases namely Hyperswarm and replicating Hypercores through Corestore:
import Corestore from 'corestore';
import Hyperswarm from 'hyperswarm';
import ram from 'random-access-memory';
import DHT from 'dht-universal';
(async () => {
const dht = new DHT({ relay: 'wss://dht-relay.example.com/' });
const swarm = new Hyperswarm({ dht });
const store = new Corestore(ram);
await store.ready();
swarm.on('connection', (socket) => {
store.replicate(socket);
});
const core = store.get({ key: <0x012...def>});
await core.ready();
swarm.join(core.discoveryKey, { server: true, client: true });
await swarm.flush();
await core.update();
const block = await core.get(core.length - 1);
})();
Other unit tests are available but might be removed later.
This module exposes a helper function to easily run a relay server.
import { setupRelay } from 'dht-universal/setup-relay.js';
const { port, closeRelay } = await setupRelay({ dhtOpts, wsServerOptions });
FAQs
Universal wrapper for @hyperswarm/dht and @hyperswarm/dht-relay working in Node.js and the Browser
The npm package dht-universal receives a total of 5 weekly downloads. As such, dht-universal popularity was classified as not popular.
We found that dht-universal 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
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.