Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ tag is placed.
| pratt | [genesis](libraries/pratt/openspec/changes/archive/2026-10-08-genesis) | pratt: a generic Pratt parser engine for C++20, with a decimal calculator | own | implemented | 0.1.0 | 2026-10-08 | [code](https://github.com/webcpporg/pratt/tree/d78451b) |
| trystero | [genesis](libraries/trystero/openspec/changes/archive/2026-10-09-genesis) | trystero: serverless WebRTC rooms, wire compatible with Trystero | port of Trystero 0.26.0 | implemented | 0.1.0 | 2026-10-09 | [code](https://github.com/webcpporg/trystero/tree/160f431) |
| trystero | [bounded-json-parse](libraries/trystero/openspec/changes/bounded-json-parse) | trystero: bound the text and the objects a room parses | port of Trystero 0.26.0 | draft | | | |
| trystero | [trystero-0-27](libraries/trystero/openspec/changes/trystero-0-27) | trystero: port to Trystero 0.27.0 | port of Trystero 0.27.0 | draft | | | |
| trystero | [shared-connection](libraries/trystero/openspec/changes/archive/2026-11-14-shared-connection) | trystero: one connection shared by the rooms of an app | port of Trystero 0.26.0 | implemented | 0.1.0 | 2026-10-11 | [code](https://github.com/webcpporg/trystero/tree/e9326e94c06cfa9ffdbd0a8d3c8d72b80b3b9b59) |
| wasi | [genesis](libraries/wasi/openspec/changes/archive/2026-10-08-genesis) | wasi: the HTTP handler a WebAssembly component exports, for C++ on wasip2 and wasip3 | own | implemented | 0.1.0 | 2026-10-08 | [code](https://github.com/webcpporg/wasi/tree/6e3c529) |
| wasi | [redesign](libraries/wasi/openspec/changes/redesign) | wasi: one namespace per WASI version, one entry point, target features and run scripts | own | accepted | | 2026-10-09 | |
Expand Down
11 changes: 11 additions & 0 deletions libraries/trystero/openspec/changes/trystero-0-27/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema: spec-driven
created: 2026-11-20
webcpp:
library: trystero
title: "trystero: port to Trystero 0.27.0"
kind: port
port_of: "Trystero 0.27.0"
status: draft
release: null
implementation: null
decided: null
287 changes: 287 additions & 0 deletions libraries/trystero/openspec/changes/trystero-0-27/design.md

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions libraries/trystero/openspec/changes/trystero-0-27/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Why

Trystero 0.27.0 (2026-11-11) is a major release with a new wire protocol that is not compatible
with 0.26.x peers: topics, ids, relay order, Nostr kinds, sealing and the action wire all changed,
and every room now runs a dual-signature handshake over ECDSA P-256 that binds unforgeable user
and endpoint identities to the WebRTC connection. webcpp::trystero ports 0.26.0, so a C++ peer no
longer meets a current Trystero JS peer. The owner asked on 2026-11-20 for the port to 0.27.0, and
for it to rest on webcpp::crypto and webcpp::hash; that supersedes his decision of 2026-11-17
(webcpp::crypto's genesis, design D23) that trystero would not move onto webcpp::crypto.

## What Changes

- **BREAKING (wire):** every value a peer exchanges follows 0.27.0: topics are the base64url
SHA-256 of a JSON path (`["Trystero",app,room]`), ids are unbiased base62 (peer ids 20 and user
ids 22 characters), relays are 0.27.0's 30 defaults in a new seeded order, Nostr kinds are
FNV-1a, a REQ asks `since` a minute ago, announcements carry a nonce, signals are sealed with
AES-256-GCM under a 12-byte IV with the signal's AAD and packed as base64url(iv || ct || tag),
a password derives the room's keys by PBKDF2-SHA-256 (600,000 iterations) then HKDF, the action
wire is version 3.
- **BREAKING (wire, Phase 2):** identity and the handshake: an endpoint key and a user key
(ECDSA P-256) per peer, `peerId` and `userId` derived from them, a dual-signature handshake
binding both SDP fingerprints; import and export of a user identity.
- **BREAKING (API):** listeners are `on_*` calls returning a `subscription` (several per event,
`once`, `replay`); `on_user_join`/`on_user_leave` beside `on_peer_join`/`on_peer_leave`;
`on_error` reports 0.27.0's room error codes (`room-full`, `banned`, `relay-failed`,
`identity-failed`, `plugin-failed`, `decrypt-failed`, `peer-connect-failed`,
`handshake-failed`, `peer-error`) with their context; `self()`, `users()`, `peers()`;
sends target a user or a peer and fail on an absent target; `set_relay_connectivity`;
`handshake_timeout` and a custom self id removed.
- **Dependencies:** trystero's sealer, randomness and Nostr signer move onto webcpp::crypto
(`aes256_gcm`, `random_device`, `curves::secp256k1`) and its hashing onto webcpp::hash
(SHA-256, HMAC, HKDF, PBKDF2; WebCrypto's PBKDF2 on Emscripten); the backend's `sealer` and
the EM_ASM WebCrypto and OpenSSL code of trystero's own are removed; Phase 2 needs
webcpp::crypto's P-256 (its foundation increment 3).
- **Plugins (Phase 3):** signed shared and per-user state, roles and moderation, then `scale()`.
- **Scope:** the Nostr strategy only, as today; media stays unported.
- **One merge:** the port lives on the branch `port/trystero-0.27` and reaches `main` once, when
interop with Trystero 0.27.0 JS peers is green.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `trystero`: ADDED requirements for 0.27.0's crypto layer, topics, ids, relays, Nostr details,
action wire v3, listeners, room errors, users and peers, relay connectivity, the key
derivation seam, the dependencies, the vectors, the branch and the Phase 2 and 3 features;
REMOVED requirements for 0.26.0's ids, topics, shuffle, sealing, sealer backends, signer,
self id and oracle pin.

## Impact

- **Kind:** port, of Trystero 0.27.0 (`port_of`), from 0.26.0.
- **Implementation:** Phase 1 built on the branches; `reference/plan.md` is the plan (Phases 1
and 2 in full, Phase 3 outlined), `reference/vectors/` the recorder and the vectors it recorded
from 0.27.0's code (`trystero-0.27.0.json`).
Library branch `port/trystero-0.27`, superproject branch `trystero/port-0.27`.
- **Dependencies:** webcpp::hash and webcpp::crypto (new); libsecp256k1 through webcpp::crypto
instead of directly; Phase 2 waits on webcpp::crypto's P-256 (foundation increment 3, Tasks
3.1 to 3.3 of its plan).
- **Status:** draft; release none.
- **Other proposals:** supersedes the part of webcpp::crypto's genesis D23 that kept trystero off
webcpp::crypto; `bounded-json-parse` (draft) applies to the same parser and is rebased on this
branch if it is accepted first; the archived `shared-connection`'s app-level sharing is retired
by design D9, which Phase 2's reading of 0.27.0 confirmed.
172 changes: 172 additions & 0 deletions libraries/trystero/openspec/changes/trystero-0-27/reference/STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# webcpp::trystero, port to Trystero 0.27.0: as built after Phase 1

Written 2026-11-22. Phase 1 (plan Tasks 1 to 13) is built on its branches, not interoperable
before Phase 2, and merged nowhere (design D1). Phase 2 waits for webcpp::crypto's P-256
(foundation increment 3, its plan's Tasks 3.1 to 3.3). `plan.md` is the plan, `vectors/record.mjs`
the recorder and `vectors/trystero-0.27.0.json` what it recorded (named `phase1.json` until
Phase 2 was written in full, 2026-11-22, with Phase 2's vectors added).

## Where it stands

| What | Where |
| --- | --- |
| The library | `webcpporg/trystero`, branch `port/trystero-0.27`, from `main` `0f7e6f4` |
| The superproject | `webcpporg/webcpp`, branch `trystero/port-0.27`, from `main` `4c5cfcc`: chapter 15's trystero section and the library's pointer |
| The vectors | `vectors/trystero-0.27.0.json` (was `phase1.json`), recorded 2026-11-20 with node v26.13.0 from Trystero 0.27.0 at `8d3f57e`, with the action frames since Task 8 (`49ecd70` here); the library's copy is `test/fixtures/expected/trystero-0.27.0.json`, written only by `test/oracle/record_0_27.mjs` |
| The lanes | the oracle and interop lanes are `explicit` on the branch (their Trystero is 0.26.0); every other test and example passes natively and on emscripten |
| Blocking Phase 2 | webcpp::crypto's `curves::p256` |

## Phase 1, task by task (library commits)

| Task | Commits | What |
| --- | --- | --- |
| 1 | `0f7e6f4..5b3087d` | the build moves onto webcpp::hash and webcpp::crypto; the fixture and its `section()` |
| 2 | `5b3087d..07c19ee` | topics, `hash32`, `str_to_num`, strict base64url, domain tags; one JSON string writer |
| 3 | `07c19ee..93fc181` | base62 ids, `gen_id`, UUIDs, derived ids; relays by `str_to_num` |
| 4 | `93fc181..1a8d3a6` | room keys, PBKDF2 master, HKDF, room auth tokens |
| 5 | `1a8d3a6..6578725` | sealing as 0.27.0 seals, with the signal's AAD; the whole error list (R2) |
| 6 | `6578725..38d82e4` | no sealer: the key derivation seam, PBKDF2 off the room's thread, the keys cache |
| 7 | `38d82e4..fbc66a1` | 0.27.0's Nostr: a signer per room over webcpp::crypto, kinds by FNV-1a, subscriptions since a minute ago, relay health |
| 8 | `fbc66a1..38d087f` | the action wire, version 3, its limits and the wide flag (received only) |
| 9 | `38d087f..487c99e` | listeners and subscriptions, receive gates, progress, request actions |
| 10 | `487c99e..ea6f2d1` | 0.27.0's room errors, `room_error`, `decrypt_failed` paced per peer and stage |
| 11 | `ea6f2d1..b4b87e9` | users and peers, `self()`, sends to users, `not_connected` |
| 12 | `b4b87e9..5c7f578` | relay connectivity per app; `self_id` and `handshake_timeout` gone |
| 12b | `5c7f578..9741f9b` | trystero's own `detail::wipe` (R19) |
| 13 | `9741f9b..1994bf2` | the pages, the README and AGENTS.md say what Phase 1 changed; `diff_peer_join` retired |

## Rulings that changed the plan

- **R2.** Task 5 appended Task 10's whole error list (`room_full` to `request_timed_out`, with
0.27.0's messages), so that numbering never changes; `action_redefined` (R15) is 29.
- **R11, amended.** `signer::generate` draws 32 bytes from `webcpp::crypto::random_device` and
makes the key with `keypair::make`, at most 4 draws, completing with `entropy_unavailable`
otherwise, as webcpp::crypto's coming secp256k1 `keypair::generate` does. **Phase 2's merge-main
step switches `signer::generate` to crypto's `keypair::generate` (one line).**
- **R14.** Frames of an action the room has not made follow 0.27.0: inline frames are dropped and
offers rejected at once as "unregistered action"; the 32-per-action-and-peer buffer for 10 s is
only for actions made that do not listen yet.
- **R15.** A name made both a message and a request action fails with `error::action_redefined`,
where 0.27.0 throws. A lone surrogate is refused in a peer's JSON metadata and payload, and read
as U+FFFD in a refusal's reason that 0.27.0's 512-unit cut left ending in one.
- **R16.** The `peer_connect_failed` hint names the port's option, "configure TURN via
app_config::ice_servers"; `turn_configured` counts only the TURN servers the app kept.
- **R17.** The test user mapping is a detail seam (no public `factory::user_of`); `users()` and
`peers()` return a `std::pmr::map` with `std::less<>`, a transparent comparator.
- **R18.** `visibilitychange` is not followed in Phase 1 (design D13 names `online` and `offline`
only); a `relay_connectivity` value outside the enum is taken as `online`, where 0.27.0 throws.
- **R19** (supersedes R10). trystero calls no `webcpp::crypto::detail`: its own `detail::wipe`
(`detail/wipe.hpp`) wipes every variable-size secret buffer.
- **R20.** The doc reference's failure is a merge blocker owned by the hash stream; trystero
gives its reference BearSSL now, and the draft PRs' docs check is expected red until hash's fix.

Each is a row of the differences page where it differs from 0.27.0.

## What Phase 2 inherits

Dependencies outside trystero:

- webcpp::crypto's `curves::p256` (its increment 3), for 2.2 to 2.4.
- webcpp::crypto's secp256k1 `keypair::generate` (max_draws 4, `entropy_unavailable`), for the
R11 switch.
- A public wipe in webcpp::crypto (or hash) for variable-size buffers, which trystero then calls
in place of its own `detail::wipe` (R19).
- A guard in webcpp::crypto's `random_device` on Emscripten against a missing or throwing
`crypto.getRandomValues` (design Open Question 1): trystero 0.1.0's own guard went with
`entropy.hpp`.
- **Merge blocker, owned by the hash stream (R20):** the reference of trystero's page
(`b2 libs/trystero/doc`) does not build, so the CI's docs check of both draft PRs is red and
the spec's "One branch, merged once" cannot be met until it does. The reference is read for
Emscripten's target (`/webcpp//emscripten-reference`) with the native platform's dependencies;
under `__MRDOCS__` webcpp::hash's `config.hpp` defines `WEBCPP_HASH_HAS_OPENSSL` (and BLAKE3,
XKCP, sodium) unconditionally, so its own Emscripten `#error` fires and `<blake3.h>` is
missing. The fix is the hash stream's: keep each `WEBCPP_HASH_HAS_<NAME>` under `__MRDOCS__`
only when the build defines it, as webcpp::crypto does (or skip OpenSSL's on
`WEBCPP_TARGET_EMSCRIPTEN`). trystero's half is done: its reference gets BearSSL, Emscripten's
GCM default, rather than the native `gcm-default`'s OpenSSL, which webcpp::crypto refuses there
(`<webcpp-trystero-reference>on` in `doc/Jamfile`, `rooms-gcm` in `build.jam`); with it the
crypto errors are gone, trystero's doc comments pass `doc_comments.py`, and the only failure
left is webcpp::hash's. Once the hash fix lands, the doc target is run again before the merge.

- **Merge blocker, owned by the crypto stream (R21):** the lint's clang-tidy fails on
webcpp::crypto's `backends/secp256k1.hpp:66` (`bugprone-dynamic-static-initializers` on the
secp256k1 canary) in every trystero translation unit that includes it, natively on the Linux
lint and with Emscripten's flags on crypto's own `secp256k1_keys_test.cpp`. main's lint does not
meet it only because no other library includes that header in a unit the lint analyses so. The
fix is crypto's; trystero's own sources pass the whole lint.

Carries inside trystero:

- **2.1** confirms or amends design D9 before the shared connection, its presence frames, room
tokens, the 64-room bound (`too_many_rooms`) and the password handshake `__trystero_pw` are
removed; their rows move off the differences page.
- **2.4** gives `handshake_failed` its emitter and replaces the provisional private
`room_impl::handshake_proof` (0.26.0's `hashChallenge`) by the dual-signature handshake;
`wrong_password` and `handshake_timed_out` go with the shared handshake.
- **2.5** replaces the `user_resolver` seam (the memory backend's `assign_user`,
`test::group_users`) with the handshake's verified user ids, and adds `max_users`.
- Wide bulk sending, once the room envelope goes and frames may reach
`max_bulk_frame_bytes`: the wire receives wide transfers and offers every one narrow.
- Emitters for `peer_error`, `room_full`, `banned`, `identity_failed` and `plugin_failed`
(Phases 2 and 3); `relay_failed` has only its boot path (every relay's first connection failed),
not 0.27.0's "every initial announcement failed".
- The receive decision limits (128 across peers, 8 per peer) and 64 concurrent requests per peer,
once `on_receive` and `on_request` may answer asynchronously; a gate set after an offer arrived
should then be asked of it at its next drain, as 0.27.0 asks.
- `requestMany`, a send's and a request's progress and `signal`, and rejecting an unexpected
`@_response` offer "unexpected response" (the port drops it); no test sends one yet.
- 2.6 pins the oracle to 0.27.0, rewrites every twin (`diff_peers.mjs` reads `PeerInfo`), records
their outputs again, and retires `diff_relay_config` if 0.27.0's per-room configuration then
prints what the C++ program prints; `diff_rooms_per_app` goes with the shared connection.
- A test of a page whose `crypto.getRandomValues` is missing or throws (no JavaScript exception
enters WebAssembly) comes back with the guard in `random_device` above: the deleted
`platform_page_sealer` test covered it for 0.1.0's sealer, and nothing replaces it yet.
- Commit subjects of the review-fix commits (`5c7f578`, `ea6f2d1`, `b4b87e9`, `487c99e`) are
paragraphs; Phase 2's commits take a one-sentence subject and the list in the body (no history
rewrite).
- The clauses "not interoperable before Phase 2" in `room.hpp`'s doc comments, and the same
marking on the library's pages, come out in 2.6 once the interop lanes pass.
- 2.7 writes the docs whole (README, every page, chapter 15), the changelog's entry, and merges.

## How to resume

Phase 2 is written in full in `plan.md` (2026-11-22, Tasks 2.1a to 2.7, every carry above placed
there or marked for after the merge; Phase 2's vectors recorded with node v26.13.0). Before that:
Phase 2 was to be written in full, task by task, when webcpp::crypto's P-256 part merged; its first task
(2.1) confirms or amends design D9 before any code of the shared connection is removed. Each task
records its vectors in `vectors/record.mjs` first (P-256 signatures are random in WebCrypto:
vectors fix keys and check each side verifies the other's signatures).

## Phase 2, as built (2026-11-23)

Phase 2 (plan Tasks 2.1a to 2.7) is built on the branches, reviewed task by task and as a whole,
interoperable with Trystero 0.27.0 (the interop lane: 19 native and 17 browser scenarios against
0.27.0 JS, green), and merged nowhere: the owner holds the merge until webcpp::crypto's
sign-unified, uniform-types, formats, backend-concepts and DIT on Windows ARM64 changes are on
crypto's `main` (ruling P2-R33); the P-256 calls then migrate once, to the final crypto API.

| Task | Library commits | What |
| --- | --- | --- |
| 2.1a | `11ed315..32a5ca2` | one connection per room and remote peer (D9 confirmed); the shared connection, presence frames, room tokens gone |
| 2.1b | `32a5ca2..ef73e00` | 0.27.0's handshake frame and timer, no password challenge; the Nostr signer on secp256k1 `keypair::generate` (R11) |
| 2.1c | `ef73e00..bd69bee` | wide bulk chunks, the size read through webcpp::webrtc's new `max_message_size()` (webrtc `8983e3b`, branch `trystero/max-message-size`) |
| 2.2 | `bd69bee..a01ebfc` | endpoint and user keys, ids derived from P-256 keys, user identity create, import, export |
| 2.3 | `a01ebfc..b77e7e7` | key records and the verification caches; tests on the virtual clock throughout |
| 2.4a | `b77e7e7..3f6c5b0` | the dual-signature handshake's messages and each side's run, against recorded JS sides |
| 2.4b | `3f6c5b0..c819ca3` | the handshake in the room; users are the ids it verified |
| 2.5a | `c819ca3..8ea1c8e` | `max_users` and `room_full` |
| 2.5b | `8ea1c8e..44da7af` | `peer_error`, `banned`, `relay_failed`'s announcement path, `@_ping` as a request |
| 2.6a | `44da7af..3fdda0b` | the oracle on 0.27.0, the recorder over the published packages, the twins; signals refused as `parseSignalEnvelope` refuses |
| 2.6b | `3fdda0b..09f45aa` | interop with 0.27.0 in Chrome and in a process, every lane on |
| 2.7 | `09f45aa..0d1387e` | the pages whole, the changelog lines, the final review's fixes, webcpp's lint and MSVC clean |

Lanes at `0d1387e` (superproject `4040794`): native clang, gcc-15 and Emscripten, the oracle and
interop lanes, the Linux and macOS lint, MSVC 14.3 and 14.5 (one flaky webcpp::webrtc case on
14.3, `native.run`'s `a_full_exchange`, predating the branch). The reference (`b2 libs/trystero/doc`)
still stops on webcpp::crypto's `config.hpp:202` under MrDocs (crypto's fix); trystero's own doc
comments pass.

What remains: the migration of `protocol/ecdsa.hpp`, `identity.hpp` and the signer to the final
crypto API (the call sites are listed in the ledger, ruling P2-R33), the interop rerun, the docs
target, the PRs out of draft and the merge. Phase 3 inherits the items in the final reports
(`p2-task-2.7-report.md`, "What Phase 3 inherits").
Loading
Loading