October 25, 2026
5 pull requests merged across 1 repo
Offline-Protocol/offline-protocol-sdk
Stacked on #635, which is stacked on #634. This branch contains both of their commits. Review only the last commit, 8d25e8e0. Merge #634, then #635, then merge main into this branch. Reaching an iPhone also needs #636, which makes the iOS peripheral serve Hello.
What this does
In Chromium a page can be a GATT central and nothing else: it cannot advertise and it serves no GATT. BluetoothCarrier links the page's node to a phone or a board running the SDK as a peripheral. Its person picks the device in the browser's chooser, inside a click, or the page reconnects one the origin was granted before. The link runs on the same BleTransport and fragment codec as every binding.
- The engine decides who is on the link. The page reads Device id and Identity and hands both over.
bleVerifyruns the one verifier and compares the derived address with the Device id exactly.bleLinkUpannounces only an address that verification produced. - The handshake follows the contract's order. Choose the instance by App tag when there are several, read and verify, subscribe to Message, write Hello with response, then link up. Nothing reaches Message before the peripheral can attribute it.
- The write payload falls back to the floor. The carrier uses
maxWriteWithoutResponseSizewhere the browser reports it and the 185-byte floor otherwise. The MTU is set before the peer is announced. - Writes go one at a time per link, and a failed write closes the link. A peer also linked over a peer stream is lost only when its last link goes.
WebEngine.withNostr becomes withOptions, which takes the Bluetooth switch beside the Nostr ones; the worker is its only caller. bleAppTag is the browser's copy of the App tag, pinned to the iOS and Android vectors. Documented as W14 and R31.
Testing
cargo test -p offline-protocol-web --lib: 65 pass. Five new host tests link two engines over their Bluetooth slots, with the codec on both sides:- A session forms and a multi-fragment message crosses.
- A Device id that the identity does not prove is refused, as are a forged identity and this device's own identity.
- Only a verified address can be linked, and only a linked one delivers.
- A disconnect reports the peer lost once.
the_app_tag_matches_the_native_vectorsandthe_bluetooth_carrier_names_the_contracts_uuidspin the tag and the UUID literals.bash bindings/web/scripts/test-browser.sh: 24 of 24 pass, eight pages in Chromium, Firefox and WebKit.bluetooth.htmldrives the carrier through a stand-in fornavigator.bluetoothwhose device is a second node playing the peripheral, so the engine runs on both sides.- Negative control. With the hello moved after the link-up, the page fails: the peripheral drops the writes it cannot attribute, and no session forms.
- Clippy is clean on the host and for wasm32, and docs build under
-D warnings.
What this fixes
An iPhone could not name a central it cannot dial back. The iOS peripheral served Message, Device id, Identity and App tag but not Hello. Every fragment a central wrote was queued behind ensureDeviceId, which dials the central's address to read its identity.
- Android phone with a rotated address: the dial-back costs seconds to tens of seconds.
- Browser over Web Bluetooth: it serves no GATT, so the dial-back never completes. This PR is the prerequisite for the browser's Bluetooth carrier reaching an iPhone.
Android and the Python service already serve Hello. The iOS central already writes it.
What changes
- Hello in the service. The characteristic is write-only and dynamic.
BlePeripheralHelloPolicy. It sits beside the central'sBleHelloPolicyand refuses a write before anything is verified when it is long, offset, or outside 96 to 512 bytes. CoreBluetooth hands a long write over as several requests in one call, so more than one Hello request in a call counts as long.handleInboundHello. It is the iOS copy of Android'shandleInboundHelloOnBleThread, in this order:
1. Verify with the one verifier.
2. Bind the central to the derived address only, and never rebind a link bound to another peer.
3. Flush the per-peer MTU before announcing the peer, once.
4. Deliver the fragments the central wrote before its hello.
Testing
swift test --package-path bindings/react-native/ios: 497 pass, three of them new for the peripheral policy.- The CI iOS bridge typecheck command is clean against the iPhone SDK. Negative control: a bad member access in the new handler is reported as an error.
react_native_ios_peripheral_serves_hellois new. It pins the service list, the verdict routing, and the verify-then-bind and MTU-then-announce orders. It fails when Hello is dropped from the service.
Not done
- No device run. An Android central writing Hello to an iPhone, and a browser over Web Bluetooth writing to an iPhone, are both untested. The second waits on the Bluetooth carrier PR.
Stacked on #634. This branch contains #634's three commits. Review only the last commit, 59ae4095. Merge #634 first, then merge main into this branch.
What this does
A page cannot scan for Bluetooth, browse DNS-SD or join Wi-Fi Direct, so two browsers on one network had no way to notice each other. NearbyRoom meets the browsers behind one public address in a Nostr room derived from that address and the application id. It lists them by the label each application chose and links over WebRTC to the one a person picks. The relays carry only the setup, and the link runs on the local network.
- The room key is public by construction. Anyone can derive it from an address. It seals only presences, which hold a key used for this room and the application's label.
- Every connection code is sealed to one presence key. It uses NIP-44, under the room key as a second layer, with the role bound in. A holder of the room key reads no code and no local address.
- The application admits.
admit({ peer, label })is required and decides every offer. A refused session is ignored while its offer stays fresh, so republished offers do not ask again. - The relays and STUN servers are the application's. A room without them refuses to open. The network address comes from the first server-reflexive candidate the application's STUN server produces.
- IPv6 rooms are per /64, because each IPv6 device has its own public address.
Documented as W13 in docs/bridges/web.md, residual risk R30, and ADR 0034. ADR 0034 records that same-network discovery for browsers needs the internet and is shared with everyone behind the address.
Supporting changes
- The transport crate gains
seal_to_keyandopen_from_keyover its existing NIP-44 code, with a round-trip and wrong-key test. RoomChannelinnostr-signal.jsnow takes its subscription and opener as a source. The nearby room reuses the signaller's relay handling, with redial, probe and keep-alive unchanged.test/stun-server.mjsis a STUN Binding responder in Node's standard library. It reports a fixed documentation address, so a page on one machine gets a server-reflexive candidate.test-browser.shstarts it. Firefox runs withmedia.peerconnection.ice.loopbackon so it gathers toward loopback, the same kind of test-host setting as the existing obfuscation pref.- The lobby example gains a nearby section. It has empty relay and STUN fields, and an inline Allow or Deny for every request.
Testing
cargo test -p offline-protocol-web -p offline-protocol-transport --lib: 58 and 315 pass. Seven new nearby tests check:- Devices behind one address share a room.
- A different address or application id gives a different room.
- IPv6 rooms follow the /64.
- An offer opens only for its key: an eavesdropper holding the room key reads nothing.
- Events outside their freshness window are refused.
- Labels are bounded.
- Signalling rooms and nearby rooms do not read each other.
bash bindings/web/scripts/test-browser.sh: 21 of 21 pass, seven pages in Chromium, Firefox and WebKit. Onnearby.html:- The STUN step learns the fixed address.
- Three nodes see each other's labels.
- An admitted device links and a message crosses.
- A device the host refuses gets no answer, after the host was asked.
- A room behind another address sees nobody.
- The lobby's nearby flow, driven headlessly in two Chromium contexts against the local relay and STUN server: list, Connect, Allow, then "1 device connected" on both pages.
- Clippy is clean on the host and for wasm32, and docs build under
-D warnings.
Not done
- No run on two physical devices. It is step 8 of
docs/bridges/web-devices.md, which also covers the phone-on-cellular case where the two must stop listing each other. - Devices that leave by different routes land in different rooms. A VPN, or one device reporting IPv4 and the other IPv6, has that effect. Nothing detects it, and ADR 0034 states it as a consequence.
- Nearby is browser to browser only. Native bindings have no WebRTC carrier.
What this does
A browser node could reach only the tabs and devices it held a link to. With this, OfflineNode.start({ nostr: { relays } }) adds the Nostr transport every binding shares, so a browser reaches any device on the same relays by its address and can use the username directory.
- The relays are the application's.
startrefusesnostrwithout a non-empty list ofws://orwss://URLs. No shipped file names a relay any more: the docs, two doc comments and the Nostr example listed public ones, andno_shipped_file_names_a_relaynow refuses any. - The worker holds the sockets; Rust decides what they mean. No binding opens a relay socket in Rust, so
nostr-relays.jsis the browser's copy of the Swift and Kotlin drivers. The engine decodes, unseals and attributes every event along the FFI's receive path (nostr_host.rs). - Cold contact works between two browsers.
sendMessageandestablishSecureSessionto a session-less device ask the relays for its published key packages. The engine never asks on its own, which is a core gap on native too, filed as #633. - New page calls.
resolveUsername,establishSecureSession(answers created, existing or pending),createInviteandparseInvite.usernameDiscovery, off by default, gates publishing and resolving together, as the spec requires.
Documented as W12 in docs/bridges/web.md.
Driver rules
| Rule | Value |
|---|---|
| A relay is live | from the EOSE confirming this device's subscription |
| Keep-alive probe | every 60 s; dropped after 10 s silent |
| Redial backoff | 1 s doubling to 30 s; at once on online |
| Event confirmed | first relay that accepts it |
| Event failed | every relay refused or dropped |
| Query complete | every relay answered EOSE, or after 10 s |
The 10 s is the sixth hand-mirrored constant (C5). The existing guard now pins it in nostr-relays.js beside the two mobile trackers.
Testing
cargo test -p offline-protocol-web: 51 pass. Seven new host tests run two nodes against an in-test relay that stores, replaces addressable events and filters on any tag. They cover a message to a bare address, username resolution, an unclaimed name, a pending session becoming established, invites, and no publishing before a relay is live.- Negative control. With the key-package request removed, the bare-address test fails: the sender sees only
identity_readyandtransport_switched. bash bindings/web/scripts/test-browser.sh: all six pages pass in Chromium, Firefox and WebKit, 18 of 18. That includes the newnostr-transport.htmland the existingnostr-signal.htmlagainst the relay that now stores events.no_shipped_file_names_a_relayfails when a relay URL is put back indocs/configuration.md.- Clippy is clean on the host and for wasm32, and docs build under
-D warnings.
Not done
- Browser to phone has not been run. It is the same transport and wire format, but a phone would also hit #633 when it initiates.
- The signalling channel was not refactored onto the new driver.
RoomChannelinnostr-signal.jskeeps its own slots. Its timers are pinned bynostr-signal.html, and its liveness rule differs. - CI runs the Linux Test leg more often now. The
rust_testsfilter now coversdocs/,examples/,bindings/**and root*.md, because the new guard reads them. - The internet relay is still not wired. Its handshake sets an
X-Device-IDheader, which a browser cannot set on a WebSocket. It is listed under "What is not built yet" in the web bridge doc.
What
A group frame that is further behind the receiver's ratchet than the out-of-order window fails as too_distant_in_the_past. The group decrypt path classified that as Retriable: it buffered the frame and withheld the ACK. That failure is permanent:
- The window only moves forward, and a sender never re-seals a group frame. Every resend is the same ciphertext and fails the same way.
- The sender kept resending it for the outbox lifetime of 7 days. A restart or relink reset its retry budget along the way.
- Each such frame holds one of the
PEER_SEND_WINDOW(16) slots for that peer.
Found with the Obsidian shared-folders plugin, between a Mac and an Android phone (Samsung SM-M366B, Android 16) after a day of app kills and restarts. Android had 16 of these frames in flight to the Mac and 146 frames held behind them. The oldest had waited 3.5 hours, and the held frames included the plugin's join request. Live edits still synced only because they are ephemeral.
Fix
A new GroupDecryptOutcome::Spent covers too_distant_in_the_past.
- Mesh arrival: a Spent frame from a member of the group is
Consumed, so the receive loop ACKs it and the sender stops. From anyone else it is buffered and not answered, exactly as before. An ACK would tell whoever replayed an old ciphertext that the device is up (invariant I4). - Drain: the same split. A member's buffered Spent frame gets its deferred ACK. Anyone else's stays buffered.
- Relay path: unchanged. It waits for no ACK, so the frame is buffered as before.
secret_reuse deliberately stays Retriable. A copy refused under SEC-M1 spends exactly the generation of the genuine copy behind it. Acknowledging that genuine copy would report as delivered a message nobody received. test_mesh_copy_sender_mismatch_rejected_releases_dedup_entry and the two relay mismatch tests pin this. My first version also treated secret_reuse as Spent, and those three tests caught it.
Tests
- New:
test_group_mls_member_frame_behind_the_window_is_acked_not_deferred. Without the fix it fails withgot Some(Deferred). - New:
test_group_mls_non_member_frame_behind_the_window_is_not_acked. The same old ciphertext replayed under a non-member wire identity staysDeferred, and so does its replay. This guards I4, so it passes with or without the fix. cargo fmt --all -- --check,cargo clippy --workspace --locked -- -D warnings,cargo clippy --package offline-protocol --no-default-features --locked -- -D warnings: clean.cargo test --package offline-protocol --locked: 2137 lib tests and the integration tests pass.- On the devices: on a local build, the Mac recorded every failed group decrypt. All 172 failures were
too_distant_in_the_past, mostly Android's frames, so this is the failure in the field. With an earlier version of this fix on the Mac, a direct message from Android to the Mac was delivered at once. The stuck frames can't be recreated, so the final version (member check,secret_reuseexcluded) has not run on the devices. The unit tests above cover it. The debug build was never committed.
Type of change
-
fix: bug fix
Breaking changes
None.
Notes for reviewers
- The ACK for a Spent frame means "stop", not "delivered". The frame was either delivered long ago and its ACK was lost, or it is lost for good. In the field case most of them were delivered: live sync between the pair kept working. A sender may therefore see
message_deliveredfor a frame that never arrived. Before this change, that frame retried for up to 7 days and then failed. The app's own catch-up, Yjs state vectors in the plugin, is what recovers the content either way. - Membership comes from
group_roster, which reads the cache first and MLS after a restart. If the roster can't be read, the frame is not answered. - Separate, not fixed here: the flush path (
try_flush_send_via) registers a fresh ACK at retry 0 even when the outbox entry already has attempts. The retry-queue path carries the count over, as the comment inprocess_retry_queuedescribes. That reset is part of why these frames never gave up. Fixing it alone would only have turned the wedge into a slowermessage_failed.