← Back to Pull requests

Browser members: Noise beside TLS, CORS on the mesh surface, the JS SDK in a page #516

Closed
unknown closed this pull request without merging on Sep 26, 2026 15:45 UTC
View on GitHub
unknown unknown commented on Sep 26, 2026 14:24 UTC
Author

A member of the mesh can now be a browser page. Seven commits, each standing on its own:

1. router, node: accept Noise after TLS. libp2p.Security(noise.ID, noise.New) after TLS on sam-router and sam-node. TLS first: Go peers and the Node/Python SDKs land on it. Noise is what a browser can speak; both bind the connection to the peer ID. TestNoiseOnlyPeer joins a Noise-only host through the router and reaches a node's service over the relay; removing Noise from the node makes the relayed dial fail. No new go.mod entry (flynn/noise was already indirect). Docs (networking concept, SDK design, host comments) no longer say TLS only.
2. controlplane: answer the mesh protocol's endpoints for any origin. /info, /keys, /enroll, /enroll/status, /register, /refresh, /policies answer a preflight and set Access-Control-Allow-Origin: . They authenticate by what the request carries (token in the body, biscuit as a bearer), never by a cookie, so a page on another origin can send nothing a program could not already. /admin/, /user/ (cookie-authenticated) and /routers/lease get no such header; TestMeshSurfaceCORS pins both sides.
3. sdk/js: identity and encodings without node:crypto and Buffer. Ed25519 from @noble/curves (what libp2p uses in a browser), RFC 8032 verification as Go and node:crypto apply it; hex/base64/base64url from uint8arrays, named by alphabet and padding to match each Go decoder. Both were already installed through libp2p and are now declared. Cross-checked against node:crypto in both directions.
4. sdk/js: speak /libp2p-http on the stream itself. A small HTTP/1.1 codec (http1.ts: Content-Length, chunked, until-close, heads capped at 64 KiB) replaces Node's http over a Duplex for session.fetch()/fetchOverStream and for the handler/url ingress; a streaming Response body goes out chunk by chunk, so SSE works. The Node listener (Express) path keeps Node's parser in libp2p-http-node.ts and shares admission (admitIngress), so authorization is written once. Codec unit tests feed it byte by byte; the ingress tests add a fetch handler with a streaming body and Node's own client reading the chunked response.
5. sdk/js: one SDK for Node and the browser. Four platform pairs under src/platform with .browser.ts twins mapped by package.json's browser field: transports (TCP+WS with TLS then Noise / WS with Noise via @chainsafe/libp2p-noise), state (owner-only files / IndexedDB), the biscuit WASM loader, the ingress. scripts/bundle-browser.mjs (esbuild, devDependency) bundles for a page and fails if the browser graph reaches a node: module.
6. sdk: a browser page as a member of a sam-one mesh, tested. sdk/js/examples/browser is the Echo agent in a page (A2A SDK's JsonRpcTransportHandler behind a fetch handler, the verified peer as the A2A user, IndexedDB state so a reload resumes the same peer without a token). tests/ui/browser-sdk.spec.js drives it in Chromium against bin/sam-one directly and behind a TLS-terminating edge reached by name (the sam-one --tunnel topology, router advertised as wss): the page enrolls cross-origin, joins over ws/wss + Noise (verified: enc: "/noise", wss://localhost:<edge>), a Node member calls the page's agent through the relay, the page calls a Node agent. run.sh builds the SDK, examples and the page; make ui-test runs it. Three fixes the page surfaced: the Node and Python SDKs must also accept Noise beside TLS (else a relayed connection from a browser member has no security protocol in common); a browser's fetch must not be stored as a method; js-libp2p in a browser denies loopback and plain ws:// addresses by default, which is what sam-one on the same machine advertises, so the host's gater judges peers, not address shapes.
7. docs: the JS SDK in a browser. "In a browser" section in the Native SDKs guide; the browser non-goal is gone from sdk/README.md and the guide; the npm page points at the guide.

Decisions: CORS on the mesh surface only; a hand-written codec rather than a dependency; Node keeps node:http for listener/url; TLS first and Noise accepted everywhere; FIPS parked until a concrete customer need.

Validation: make build, go vet ./..., hack/lint.sh (0 issues), go test ./... (incl. TestNoiseOnlyPeer, TestMeshSurfaceCORS, TestNativeSDKsMesh, TestNativeSDKA2A, TestNativeSDKExamples, TestSDKCanaryScript, TestStandaloneSDKAgents*), npm test (77), npm run build/examples, npm ci from the lockfile, pytest (82), hack/verify-sdk-generated.sh, hack/verify-secrets.sh, make ui-test (20 passed, both browser topologies included).

Diff: 589 lines (+441 / -148) across 7 files Reviewer: aojea Review duration: 81m
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.73) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.73 · 589 lines diff across 7 files
0.73
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
57%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.382
Shallow Review Depth shallow_review_depth
0.289
Sensitive Paths sensitive_paths
0.073
Real PR Conversation Timeline
1 comments
"Review active on #516"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 58.0% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 73.1% (HIGH) · Higher = larger blast radius
73.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 58.0% · Lower = rushed or shallow review
58.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 30.7% · Safe to merge
30.7%