@santaklouse/p2p-netcat-core
v0.1.1
Published
Browser-safe protocol, addressing and dial planning primitives for p2p-netcat
Maintainers
Readme
@santaklouse/p2p-netcat-core
English | Русский
The interaction between the library, CLI, and browser Worker is documented in
docs/ARCHITECTURE.md.
The browser-safe shared core of p2p-netcat. The package does not use Node.js
APIs and can be imported by the CLI, a Web Worker, and other JavaScript clients.
The package owns:
- logical ports and protocol IDs;
- PeerId and multiaddr normalization;
- relay address validation;
- Circuit Relay dial-plan construction;
- browser-compatible address detection;
- a shared transport preference order.
Creating a libp2p node, querying the DHT, Web Worker RPC, and stdin/stdout remain in platform-specific packages.
Exported API
| Function | Purpose |
|---|---|
| validateService(value) | Validates a logical port in the 1..65535 range |
| protocolForService(service) | Builds /p2p-netcat/1.0.0/{service} |
| normalizePeerId(value) | Validates and canonicalizes a PeerId |
| normalizeMultiaddr(value) | Validates and canonicalizes a multiaddr |
| normalizeRelayAddress(value, options) | Applies relay, WS/WSS, and secure-context checks |
| relayedTargetAddress(relay, peerId, options) | Returns the target Circuit Relay multiaddr |
| createRelayDialPlan(input) | Returns an immutable dial plan |
| browserDialableAddress(address, options) | Checks whether a browser can dial an address |
| addressRank(address) | Returns a numeric transport rank |
| preferDialAddresses(a, b) | Comparator for sorting multiaddrs |
| trysteroRoomId(peerId, service) | Builds the deterministic WebRTC room |
| trysteroAuthPayload(...) | Builds a domain-separated signed challenge |
| encodeTrysteroAuthResponse(...) | Encodes the public key and signature |
| decodeTrysteroAuthResponse(...) | Validates and decodes the response |
| TrysteroStream | Adapts an action channel to backpressure and EOF semantics |
The order is WebRTC Direct, QUIC v1, WebTransport, WSS, WS, TCP, other addresses, and Circuit Relay. A transport appearing in the common ranking does not imply that every runtime implements it.
The CLI and Web Worker use the library as a local npm dependency. The CLI path
is file:packages/core; the web project uses file:../packages/core.
Example of constructing a shared dial plan:
import { createRelayDialPlan } from '@santaklouse/p2p-netcat-core'
const plan = createRelayDialPlan({
peerId: '12D3KooWQ3uxpHgjDKE6vGmvzKS8RPbxUDLwJ7XCLaD6YXdUfbR9',
service: 31337,
relay: '/dns4/relay.example/tcp/443/wss/p2p/12D3KooWEqeQRAJ61HSv9yMPk8yzjke7NxmTFcvFt4GzwXxzVjXW',
requireWebSocket: true,
secureContext: true
})
console.log(plan.destination)
console.log(plan.protocol)