bridge: add broker long-poll v2 pull signing#123
Merged
Conversation
Greptile SummaryThis PR adds broker long-poll v2 support with cryptographic request signing using stable JSON canonicalization. The implementation introduces Key changes:
The implementation is well-structured with proper separation of concerns, thorough testing, and clear documentation. Input validation through clamping prevents signature mismatches between client and broker. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Bridge as broker-bridge.mjs
participant Crypto as crypto.mjs
participant Broker as Broker API
Note over Bridge: Poll Loop Start
Bridge->>Bridge: Check BROKER_WAIT_SECONDS
alt Long-poll mode (wait_seconds > 0)
Bridge->>Crypto: canonicalizeOutboundV2(workspace, "inbox.pull.v2", timestamp, payload)
Crypto->>Crypto: stableStringify({workspace_id, action, timestamp, payload})
Crypto-->>Bridge: Uint8Array (canonical bytes)
Bridge->>Bridge: crypto_sign_detached(canonical, privateKey)
else Legacy short-poll (wait_seconds = 0)
Bridge->>Crypto: canonicalizeOutbound(workspace, "inbox.pull", timestamp, max_messages)
Crypto->>Crypto: utf8Bytes("workspace|action|timestamp|max_messages")
Crypto-->>Bridge: Uint8Array (canonical bytes)
Bridge->>Bridge: crypto_sign_detached(canonical, privateKey)
end
Bridge->>Broker: POST /api/inbox/pull<br/>{workspace_id, max_messages, wait_seconds?, timestamp, signature}
Broker-->>Bridge: {ok: true, messages: [...]}
Bridge->>Bridge: Process messages
alt Long-poll mode
Bridge->>Bridge: Skip sleep, immediately re-poll
else Short-poll mode
Bridge->>Bridge: Sleep POLL_INTERVAL_MS
end
Note over Bridge: Repeat Poll Loop
Last reviewed commit: 7665c30 |
7b3e8f2 to
f19b29a
Compare
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.
Summary
slack-bridge/broker-bridge.mjsusingwait_seconds(default 20s, clamped to 25s max)inbox.pull.v2stable JSON canonicalization; keep legacyinbox.pullsigning whenSLACK_BROKER_WAIT_SECONDS=0SLACK_BROKER_MAX_MESSAGESto1..100,SLACK_BROKER_WAIT_SECONDSto0..25) so signatures match broker-side clamped verificationcanonicalizeOutboundV2helper and unit coverage inslack-bridge/crypto.test.mjstest/broker-bridge.integration.test.mjsfor:max_messagesclamping before signature generationSLACK_BROKER_WAIT_SECONDSinCONFIGURATION.md,README.md, andAGENTS.mdTesting
node --test slack-bridge/crypto.test.mjsnode --check slack-bridge/broker-bridge.mjsnode --check test/broker-bridge.integration.test.mjs