feat: pubsub#1151
Draft
nugaon wants to merge 12 commits intoethersphere:masterfrom
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Pubsub Module
Introduces a new
pubsubmodule that wraps Bee's (G)SOC-based PubSub WebSocket API, along with supporting types, tests and documentation.What's added
pubsubConnect(mode, handler, brokerPeer, ...params)— opens a WebSocket toGET /pubsub/:topicAddressand returns a subscription withsend(payload)andcancel().listPubsubTopics()—GET /pubsub/returning active topics with role (broker/subscriber/publisher) and connection info.GsocEphemeralMode— SOC-based pubsub mode implementing theIPubsubModeinterface (topicAddress,getPublisherHeaders,encodeMessage,decodeMessage). Frame layout:[sig:65B][span:4B][payload].createPubsubMode(mode, ...)— generic factory with constructor-parameter inference keyed by thePubsubModeenum.Three signer variants (discriminated union on
GsocEphemeralParams){ topic: string | Uint8Array }. Astringiskeccak256-hashed to derive the 32-byte private key; aUint8Array/ hex string is used as the private key directly. Can publish.{ address, signFn }. Can publish; signs off-chunk via user-providedsignFn. Address is carried in theswarm-pubsub-gsoc-eth-addressheader (hex, no0xprefix).{ topicAddress }. Read-only, no signer;getPublisherHeaders()returnsnullandencodeMessage()throws.All variants support an optional
socId(string →keccak256, or 32-byteUint8Array; defaults toNULL_IDENTIFIER). For publisher variants,topicAddressis computed internally asmakeSOCAddress(socIdentifier, signerAddress).Other changes
prepareWebsocketDatamade synchronous for consistency with websocket data types.socId, external signer, subscriber-only mode,Uint8Arraytopic, and the mode factory.pubsubConnect,listPubsubTopics, andgsocSubscribe.