@totemsdk/omnia-hyperswarm
v0.2.2
Published
Hyperswarm P2P transport adapter for @totemsdk/omnia payment channels — Bare/Pear compatible
Downloads
1,085
Maintainers
Readme
@totemsdk/omnia-hyperswarm
P2P transport for Omnia channels — no central relay server needed.
Wires Omnia payment channel messaging over the Hyperswarm DHT (the same P2P network used by Holepunch/Pear). Two channel peers discover each other and exchange state updates directly, with no intermediary.
Install
npm install @totemsdk/omnia-hyperswarmCompatible with Bare/Pear runtimes as well as Node.js.
What's inside
| Export | What it does |
|--------|-------------|
| createOmniaSwarm() | Spawn a Hyperswarm instance configured for Omnia |
| createOmniaIntegration(swarm, store, config) | Fully-wired: auto-accepts inbound proposals, binds per-peer handlers |
| bindPeerIntegration(peer, store, config) | Manual per-peer binding for custom flows |
| channelTopic(channelId) | Deterministic DHT topic derived from a channel ID |
| peerTopic(publicKey) | Deterministic DHT topic for direct peer discovery |
| broadcastTopic(tokenId) | DHT topic for swap rate announcements |
| OmniaFrameParser | Streaming binary message parser |
| encodeOmniaMessage(msg) | Encode a typed message to binary frame |
| createMockStreamPair() | In-process testing harness (no real network) |
Usage
Start the swarm and accept channels
import { createOmniaSwarm, createOmniaIntegration } from '@totemsdk/omnia-hyperswarm';
const swarm = createOmniaSwarm();
const integration = await createOmniaIntegration(swarm, channelStore, {
signer,
leaseProvider,
onChannelProposed: async (proposal) => {
// Auto-accept, prompt user, or reject
return true;
},
onPaymentReceived: (channelId, amount) => {
console.log(`Received ${amount} MIN on channel ${channelId}`);
},
});
// Announce yourself on the DHT
await swarm.listen();
console.log('Swarm public key:', swarm.keyPair.publicKey.toString('hex'));Open a channel to a remote peer
import { peerTopic } from '@totemsdk/omnia-hyperswarm';
const topic = peerTopic(remotePeerPublicKey);
const connection = await swarm.connect(topic);
await integration.proposeChannel(connection, {
amount: '100',
tokenid: '0x00',
});Test with in-process mock streams
import { createMockStreamPair } from '@totemsdk/omnia-hyperswarm';
const [aliceStream, bobStream] = createMockStreamPair();
// Wire each stream into integration.bindPeerIntegration() for unit testsSee also
@totemsdk/omnia— channel state machine transported by this package@totemsdk/omnia-router— uses swarm for route propagation and swap announcements@totemsdk/lookup-protocol— companion binary framing conventions@totemsdk/pear— Pear runtime adapters for running swarm apps
