The Atyha protocol, version 1

Atyha lets a program (the joiner) reach another (the host) by a short room code that a person reads aloud or pastes, and set up a WebRTC connection between them, with no server of its own. The host's address, ICE servers and SDP travel through public Nostr relays; an optional password protects the room with a PAKE (CPace), so the relays and anyone watching them learn nothing that lets them join a password room or tamper with the connection.

Atyha is signalling only. What it carries is one SDP offer and one SDP answer, both complete (no trickle ICE). What runs on the WebRTC connection afterwards (DataChannels, media, the application's protocol) is the application's business; section 9 gives a recommended DataChannel profile.

The key words MUST, SHOULD and MAY are used as in RFC 2119.

1. Notation

  • || is concatenation of byte strings.
  • lv_cat(a, b, ...) is the length-value concatenation of draft-irtf-cfrg-cpace-21 (A.1): each argument is preceded by its length in unsigned LEB128. lv_cat("1234", "5", "", "678") = 04 31323334 01 35 00 03 363738.
  • Strings are UTF-8 bytes, with no normalization.
  • b64u(x) is base64url (RFC 4648 section 5) without padding. Decoders MUST refuse padding and characters outside the alphabet.
  • hex(x) is lowercase hexadecimal.
  • random(n) is n bytes from a cryptographically secure generator.

2. Parameters

namevalue
protocol label Patyha/1
code alphabet AABCDEFHJKMNPRTUVWXYZ34579 (25 symbols)
code length8 symbols
Nostr event kind KIND21490 (ephemeral range)
hello retry interval2 s
join deadline (code to answer)25 s
host hello budget20 per 60 s per room (section 7.4)

An application id app (a non-empty UTF-8 string, at most 64 bytes, such as ngspades; implementations refuse any other) separates applications: a code in one application never reaches a host of another.

3. Room codes

A code is 8 symbols from A. The alphabet leaves out every symbol people confuse (I L O Q 0 1, and G S 2 6 8, which read as 6 5 Z G B): 25^8 ≈ 1.5 × 10^11 codes.

Generation. Draw bytes with random; a byte b < 250 gives the symbol A[b mod 25], any other byte is discarded (no modulo bias). A host draws a new code for every room.

Display. XXXX-XXXX, for instance HK4M-7TRW.

Parsing (what a person typed or pasted):

  1. Remove leading and trailing white space (any Unicode White_Space character).
  2. If the text starts with a URI scheme followed by :// ([A-Za-z][A-Za-z0-9+.-]*://), drop it.
  3. Drop every -, space and tab.
  4. Upper-case ASCII letters.
  5. The result MUST be exactly 8 symbols, all in A; otherwise the text is not a code.

hk4m 7trw, HK4M-7TRW and myapp://HK4M7TRW are the same code, HK4M7TRW (its canonical form, the one every computation below uses).

4. Topic

The Nostr tag every message of a room carries:

topic = hex(SHA-256(lv_cat("atyha/1 topic", app, code)))

64 hex characters. Anyone who knows app can compute the topic of every code, so the topic tells an observer which codes are in use: rooms without a password are open to whoever learns their code, by design. A password room is protected by section 5, not by the topic.

5. Authentication: CPace

CPace with ristretto255 and SHA-512 (CPACE-RISTR255-SHA512) exactly as in draft-irtf-cfrg-cpace-21, in the initiator-responder setting (transcript_ir). The joiner is the initiator A, the host the responder B.

CPace inputvalue
PRSlv_cat(code, password); password is the UTF-8 bytes as typed, "" for a room with none
CIlv_cat("atyha/1", app)
sidrandom(16), drawn by the joiner for each join attempt, sent in hello
ADa, ADb""

Every room runs CPace, with or without a password: the code alone then authenticates, which stops a relay from replacing the SDP (and so the DTLS fingerprint) of a room it does not know the code of, and costs one scalar multiplication per side.

Both sides compute ISK (64 bytes). Each side MUST abort the attempt if the peer's share does not decode or K is the identity (CPace's scalar_mult_vfy).

Keys. HKDF-SHA-256 (RFC 5869) with IKM = ISK, salt = sid, L = 32:

k_hj = HKDF(ISK, sid, "atyha/1 host to joiner")
k_jh = HKDF(ISK, sid, "atyha/1 joiner to host")

Sealing. ChaCha20-Poly1305 (RFC 8439). The nonce is 11 zero bytes followed by the message's number in its direction (one byte); the additional data is lv_cat("atyha/1", t, sid) where t is the message type. A key never seals two different plaintexts under one number: a message sent again is the same ciphertext.

directionnumbermessage
host to joiner0pake
host to joiner1answer or reject (one of them, never both)
joiner to host0offer

A sealed payload is a UTF-8 JSON object; c = b64u(ciphertext || tag).

6. Messages

Every message is a UTF-8 JSON object with:

field
v1
tthe type: hello, pake, offer, answer, reject
sidb64u(sid)
fromb64u(random(16)), the sender's peer id, drawn per room (host) or per attempt (joiner)
tothe receiver's peer id; absent in hello

and by type:

tfromextra fieldssealed payload
hellojoinerY: b64u(Ya)none
pakehostY: b64u(Yb), c{"ice": [...]?, "meta": {...}?}
offerjoinerc{"sdp": "<offer>", "meta": {...}?}
answerhostc{"sdp": "<answer>"}
rejecthostc{"reason": "<text>"}
  • ice is the host's ICE server list, as RTCIceServer objects (urls a string or an array of strings, optional username and credential), so the joiner can use the host's TURN. A joiner uses it in place of its own list when it is present and non-empty.
  • meta is the application's own object (a player name, a server name, a protocol version), at most 2 KB once encoded (a sender's duty; receivers need not check it). Atyha passes it through.
  • Unknown fields MUST be ignored. A message with another v, a field of the wrong type or a value that does not decode MUST be ignored.

7. The exchange

joiner                                          host
  hello {sid, from=J, Y=Ya}            ──►        (computes Yb, ISK)
                                        ◄──       pake {sid, from=H, to=J, Y=Yb, c=seal(k_hj, 0, {ice, meta})}
  (computes ISK, opens c: the password
   is right; makes its peer connection
   with ice, gathers every candidate)
  offer {sid, from=J, to=H, c=seal(k_jh, 0, {sdp, meta})}  ──►
                                        ◄──       answer {.., c=seal(k_hj, 1, {sdp})}   or   reject {..}
  (sets the answer; ICE and DTLS follow, peer to peer)

7.1 Joiner

  1. Parse the code (section 3; bad_code when it is not one); compute topic; draw sid, its peer id and ya; subscribe (section 8). No relay confirms the subscription within 10 s: report no_relay.
  2. Send hello once subscribed on at least one relay, and again every 2 s (a new Nostr event each time) until a pake for its sid arrives.
  3. On the first pake with its sid and to: compute K and ISK, open c with k_hj, number 0. If it does not open, the password is wrong (or someone else answered): keep waiting 4 s more for another pake, then report wrong_password (or at the 25 s deadline of step 6, whichever comes first). If it opens, keep this host's peer id and ignore every other host.
  4. Make the peer connection (with ice when present; entries without a usable urls are skipped), wait for ICE gathering to complete (at most 5 s), send offer, and again every 2 s until an answer or reject arrives. An offer not made within 25 s of the pake is reported as no_answer.
  5. answer: open it (number 1), set it as the remote description. reject: open it, report rejected with its reason.
  6. No pake within 25 s of the first hello: report no_room. No answer or reject within 25 s of the first offer: report no_answer. The application may give up at any time (cancelled).

The error names above (bad_code, no_relay, no_room, wrong_password, rejected, no_answer, cancelled) are what every implementation reports, so applications can translate them the same way.

7.2 Host

  1. Draw the code and its peer id; compute topic; subscribe. The room is open once at least one relay has confirmed the subscription (EOSE).
  2. hello with a sid not seen before (and within the budget, 7.4): draw yb, compute Yb, K, ISK; keep the attempt (sid, joiner id, keys) for 60 s; send pake. A hello with a known sid and the same from gets the same pake again.
  3. offer for a kept attempt, from its joiner: open it (number 0). If it does not open, ignore it (wrong password, or forged). If it opens, hand the SDP and meta to the application, which returns an answer SDP or a refusal; send answer or reject and keep it, so that the same offer again gets the same reply.
  4. Close the subscription when the room ends.

7.3 Timing

A relay delivers in well under a second, so a join takes about two relay round trips plus ICE gathering. Both sides accept messages whose Nostr created_at is within 60 s of their clock.

7.4 Guessing

Each hello lets its sender test one password against the host, and no observer can test any offline. A host answers at most 20 hello per 60 s per room (sliding window; MAY be configured) and ignores the rest: a person typing the right password never meets the limit, a script trying a list of passwords gets 20 guesses a minute. A room whose password is in the first thousand of a list therefore stands for about an hour against a determined attacker: a password is for keeping strangers out of a game, not for secrets.

8. Nostr transport

Messages travel as Nostr events (NIP-01) of kind KIND (ephemeral: relays forward them to subscribers and do not store them).

  • content: the message JSON text. tags: [["x", topic]]. created_at: the sender's clock in seconds.
  • pubkey, id, sig: NIP-01, signed with BIP-340 Schnorr by a secp256k1 key drawn for the room (host) or the attempt (joiner) and never reused. The relay checks the signature; receivers MAY skip checking it, since every message that matters is authenticated by section 5.
  • Subscribe with ["REQ", <sub id>, {"kinds": [KIND], "#x": [topic], "since": <now - 60>}], publish with ["EVENT", <event>], end with ["CLOSE", <sub id>].
  • Use several relays at once (default: all of the list below that connect; at least 3 SHOULD be tried); publish every event to every connected relay; drop an event whose id was seen. A message repeated in a new event (the 2 s resends) is NOT dropped by the transport: section 7 says what each side does with a repeat.
  • A relay connection that closes is opened again after 2 s, doubling up to 30 s.
  • A relay that answers ["OK", id, false, "rate-limited: ..."] or ["CLOSED", sub, "rate-limited: ..."] is closed and opened again after 60 s; one that answers blocked:, restricted:, auth-required: or pow: is closed and not opened again for the session.
  • Applications SHOULD let the relay list be configured.

Default relays (section 10 records when they were last checked):

wss://nos.lol
wss://relay.primal.net
wss://relay.nostr.net
wss://relay.snort.social
wss://nostr.mom
wss://nostr.overmind.lol
wss://bucket.coracle.social

Each of these took a kind 21490 event from a fresh key and delivered it to a subscriber in 230 to 600 ms (from Brazil) on the date of section 10. Some well-known relays do not: purplepag.es and relay.nos.social refuse the kind, nostr.wine takes only its members, offchain.pub refuses keys outside its web of trust (with no machine-readable prefix), and nostr.data.haus refuses the TLS key exchange libdatachannel offers (P-256 only). A refusal without one of the prefixes above leaves the relay connected (it may take a later event), but an implementation SHOULD stop publishing to a relay that refused every event it sent.

Not part of the exchange; what the Atyha libraries open by default, which suits a game:

labeloptionsmeaning
reliableordered, reliable (the defaults)channel 0
unreliableordered: false, maxRetransmits: 0channel 1

The joiner creates both before its offer. A text message is control, a binary one is the application's data. Some stacks cannot tell the two apart (com.unity.webrtc) or need the unreliable flag spelled out (libdatachannel: unreliable = true with maxRetransmits = 0); an application that has to run on them keeps its own framing.

10. Test vectors and status

vectors/atyha-v1.json holds the code, topic, CPace, key and sealing values for fixed inputs; every implementation MUST reproduce them. The relays of section 8 were checked on 2026-11-30.