From b9c50c08534aec2093bb675d892f8faf83379e83 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 03:58:25 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m1/mesh-key-codec.md Quest-Claim: fa04d98c4aac551d From 6e0b9a8b270b4dcc3b99f194660e09ac1c9fd55b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 04:07:26 -0800 Subject: [PATCH 2/4] refactor(auth)!: share signing public keys and canonical key codecs Co-Authored-By: GPT-6.1 Sol --- .github/workflows/release-gate.yml | 1 + Cargo.lock | 4 +- Cargo.toml | 1 + drafts/moq-sign-00.json | 25 +++++ drafts/moq-sign-00.ts | 50 +++------- quest/m1/mesh-key-codec.md | 21 +++- rs/moq-auth/Cargo.toml | 2 +- rs/moq-auth/MIGRATE.md | 12 +++ rs/moq-auth/src/mesh/coordinator.rs | 31 +++--- rs/moq-auth/src/mesh/mod.rs | 148 +++++----------------------- rs/moq-sign/Cargo.toml | 1 + rs/moq-sign/src/key.rs | 23 ++++- rs/moq-sign/src/tests.rs | 12 +++ rs/workspace-hack/Cargo.toml | 2 - sh/drafts/check.sh | 2 +- 15 files changed, 149 insertions(+), 186 deletions(-) diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.yml index 8501656548f..25464ff84a3 100644 --- a/.github/workflows/release-gate.yml +++ b/.github/workflows/release-gate.yml @@ -259,6 +259,7 @@ jobs: - "rs/moq-rtmp/**" - "rs/moq-rtsp/**" - "rs/moq-shaper/**" + - "rs/moq-sign/**" - "rs/moq-sock/**" - "rs/moq-srt/**" - "rs/moq-stats/**" diff --git a/Cargo.lock b/Cargo.lock index 302d669a3a3..03bb4eea074 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4479,12 +4479,12 @@ dependencies = [ "axum", "base64 0.23.1", "bench-harness", - "data-encoding", "jsonwebtoken", "kio", "moq-auth 0.2.1", "moq-auth 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "moq-pattern 0.1.2", + "moq-sign", "moq-token", "pkcs1", "pkcs8 0.11.0", @@ -5202,6 +5202,7 @@ dependencies = [ "hex", "kio", "moq-net", + "serde", "serde_json", "tempfile", "thiserror 2.0.21", @@ -11235,7 +11236,6 @@ dependencies = [ "futures-io", "futures-lite", "futures-sink", - "futures-task", "futures-util", "getrandom 0.2.17", "getrandom 0.4.3", diff --git a/Cargo.toml b/Cargo.toml index 284ae42569e..c8a87f32637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,6 +148,7 @@ moq-relay = { version = "0.17.2", path = "rs/moq-relay", default-features = fals moq-rtc = { version = "0.3.12", path = "rs/moq-rtc" } moq-rtmp = { version = "0.3.11", path = "rs/moq-rtmp" } moq-rtsp = { version = "0.1.0", path = "rs/moq-rtsp" } +moq-sign = { version = "0.0.1", path = "rs/moq-sign" } moq-sock = { version = "0.2.0", path = "rs/moq-sock" } moq-srt = { version = "0.3.11", path = "rs/moq-srt" } moq-stats = { version = "0.2.12", path = "rs/moq-stats" } diff --git a/drafts/moq-sign-00.json b/drafts/moq-sign-00.json index 1399107c087..9cd524c6fe0 100644 --- a/drafts/moq-sign-00.json +++ b/drafts/moq-sign-00.json @@ -28,6 +28,11 @@ "id": "ones", "public": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "endpoint": "999999999999999999999999999999999999999999999999999o" + }, + { + "id": "zeros", + "public": "0000000000000000000000000000000000000000000000000000000000000000", + "endpoint": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" } ], "frames": [ @@ -405,6 +410,26 @@ { "id": "empty", "text": "" + }, + { + "id": "ones-trailing-bits", + "text": "9999999999999999999999999999999999999999999999999999" + }, + { + "id": "padding", + "text": "eyamftwcf3sck8rs5m1meugf8odwqg78473t7p3st9wxob9csz8y====" + }, + { + "id": "leading-whitespace", + "text": " eyamftwcf3sck8rs5m1meugf8odwqg78473t7p3st9wxob9csz8y" + }, + { + "id": "trailing-newline", + "text": "eyamftwcf3sck8rs5m1meugf8odwqg78473t7p3st9wxob9csz8y\n" + }, + { + "id": "base64url", + "text": "QDCyxowubMUcltrktEzFPAdHG6fXcx63No_o-Afstc4" } ] } diff --git a/drafts/moq-sign-00.ts b/drafts/moq-sign-00.ts index 2dd55a04f56..8e9db116423 100644 --- a/drafts/moq-sign-00.ts +++ b/drafts/moq-sign-00.ts @@ -12,6 +12,7 @@ import { readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; +import * as ZBase32 from "../js/sign/src/zbase32.ts"; export const PROFILE = "moq-sign-00"; export const LABEL = utf8(PROFILE); @@ -41,9 +42,6 @@ export type Identity = { timestamp: bigint; }; -// z-base-32: most significant bit first, no padding, trailing bits must be zero. -const ZBASE32 = "ybndrfg8ejkmcpqxot1uwisza345h769"; - function utf8(text: string): Uint8Array { return new TextEncoder().encode(text); } @@ -56,23 +54,6 @@ function toHex(bytes: Uint8Array): string { return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(""); } -function zbase32(bytes: Uint8Array): string { - let out = ""; - let buffer = 0; - let bits = 0; - for (const byte of bytes) { - buffer = (buffer << 8) | byte; - bits += 8; - while (bits >= 5) { - bits -= 5; - out += ZBASE32[(buffer >> bits) & 31]; - } - buffer &= (1 << bits) - 1; - } - if (bits > 0) out += ZBASE32[(buffer << (5 - bits)) & 31]; - return out; -} - function concat(...parts: Uint8Array[]): Uint8Array { const out = new Uint8Array(parts.reduce((sum, part) => sum + part.byteLength, 0)); let offset = 0; @@ -111,29 +92,14 @@ export function message(identity: Identity, payload: Uint8Array): Uint8Array { - if (text.length !== 52) throw new ProfileError("key"); - const out = new Uint8Array(KEY_LEN); - let buffer = 0; - let bits = 0; - let offset = 0; - for (const char of text) { - const value = ZBASE32.indexOf(char); - if (value < 0) throw new ProfileError("key"); - buffer = (buffer << 5) | value; - bits += 5; - if (bits >= 8) { - bits -= 8; - out[offset++] = (buffer >> bits) & 0xff; - } - buffer &= (1 << bits) - 1; - } - if (buffer !== 0) throw new ProfileError("key"); - return out; + const key = ZBase32.decode(text, KEY_LEN); + if (!key) throw new ProfileError("key"); + return key; } async function privateKey(seed: Uint8Array): Promise { @@ -267,6 +233,7 @@ async function generate() { { id: "other", seed: OTHER_SEED, public: toHex(await publicKey(hex(OTHER_SEED))), endpoint: otherKey }, // Every bit set: the last character carries one key bit and four zero bits. { id: "ones", public: "ff".repeat(KEY_LEN), endpoint: endpointId(new Uint8Array(KEY_LEN).fill(0xff)) }, + { id: "zeros", public: "00".repeat(KEY_LEN), endpoint: endpointId(new Uint8Array(KEY_LEN)) }, ], frames: [ await frameVector("base", SEED, base, payload), @@ -315,6 +282,11 @@ async function generate() { { id: "trailing-bits", text: `${key.slice(0, 51)}b` }, { id: "hex", text: toHex(keyBytes) }, { id: "empty", text: "" }, + { id: "ones-trailing-bits", text: "9".repeat(52) }, + { id: "padding", text: `${key}====` }, + { id: "leading-whitespace", text: ` ${key}` }, + { id: "trailing-newline", text: `${key}\n` }, + { id: "base64url", text: Buffer.from(keyBytes).toString("base64url") }, ], }; } diff --git a/quest/m1/mesh-key-codec.md b/quest/m1/mesh-key-codec.md index f533e46b06e..5ccd2b84a38 100644 --- a/quest/m1/mesh-key-codec.md +++ b/quest/m1/mesh-key-codec.md @@ -29,9 +29,10 @@ is related. moq-sign for it, or the type moves to a small shared crate if the dependency direction is wrong; say which in the PR). Keep the shared vectors in `drafts/moq-sign-00.json` as the single source of test vectors. -- Both copies are still on `main` at be39188000: - `rs/moq-auth/src/mesh/mod.rs:52` (the specification) and `:65` - (`EndpointId`), beside `rs/moq-sign/src/key.rs:18`. +- The implementation in [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733) + uses `moq_sign::PublicKey` directly in auth, moves byte access and string serde + onto it, and removes auth's codec. Auth still verifies proofs on rind. Rust + auth/signing and JS signing consume `drafts/moq-sign-00.json`. - [moq-crypto replaces moq-sign](/quest/m1/moq-crypto.md) renames `moq-sign`/`@moq/sign` to `moq-crypto`/`@moq/crypto`. If it lands first, merge `EndpointId` into its public key type and use its JS codec instead. @@ -42,6 +43,20 @@ is related. Public API: breaking for moq-auth (`mesh::EndpointId` becomes `moq_sign::PublicKey` or a re-export). Wire: none. +## Waiting + +- Maintainer: settle the extra methods on the removed `EndpointId` before + completing [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733). + It exposed `publish()` and raw `verify(message, signature)`, while signing's + `PublicKey::verify` is private and takes a fixed-size signature. Option 1 + (recommended, implemented in the draft): keep mesh policy and rind proof + verification in auth, use `Pattern::subtree(&format!("mesh/{endpoint}"))` for + paths, and use `Proof::verify` or a verifier over `PublicKey::as_bytes()` for + signatures. This adds no new public helper or verification API. Option 2: + preserve those conveniences with a public mesh path helper and public raw + `PublicKey` verification, settling their names and verification contract. + A maintainer comment on the PR choosing the migration clears this wait. + ## Related - [Mesh](/quest/m2/mesh/README.md) - the epic both types serve diff --git a/rs/moq-auth/Cargo.toml b/rs/moq-auth/Cargo.toml index afd7ff63b80..4c6366631bf 100644 --- a/rs/moq-auth/Cargo.toml +++ b/rs/moq-auth/Cargo.toml @@ -19,11 +19,11 @@ serve = ["dep:axum", "dep:tokio", "dep:tracing", "tokio/net"] [dependencies] axum = { workspace = true, optional = true } base64 = { workspace = true } -data-encoding = { workspace = true } jsonwebtoken = { workspace = true } # `async` for `Shared::wait`, until moq-auth grows an `async` feature of its own. kio = { workspace = true, features = ["async", "serde"] } moq-pattern = { workspace = true, features = ["serde"] } +moq-sign = { workspace = true } pkcs1 = { workspace = true, features = ["std"] } pkcs8 = { workspace = true } rand = { workspace = true, optional = true } diff --git a/rs/moq-auth/MIGRATE.md b/rs/moq-auth/MIGRATE.md index a8589d838c0..0400c84d7dd 100644 --- a/rs/moq-auth/MIGRATE.md +++ b/rs/moq-auth/MIGRATE.md @@ -4,6 +4,18 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Mesh endpoints use the signing public key + +Replace `moq_auth::mesh::EndpointId` with `moq_sign::PublicKey` and +`mesh::InvalidEndpoint` with `moq_sign::InvalidKey`. +`Proof`, `Member`, `Device`, `Signer::endpoint`, and `Coordinator::revoke_device` +use that type directly; byte access and canonical z-base-32 text are unchanged. +Build the publish pattern with `Pattern::subtree(&format!("mesh/{endpoint}"))` +instead of `endpoint.publish()`. +For raw proof verification, use `Proof::verify`; callers verifying other messages +can pass `endpoint.as_bytes()` to their Ed25519 verifier. +Enrollment JSON, stored device IDs, tokens, and signed content keep their formats. + ### Crypto runs on rind (#7570) Signing, verifying, key generation, and the HTTP clients' TLS run on [rind](https://github.com/moq-dev/rind), a pure-Rust library, instead of aws-lc-rs, `p256`, and `p384`. diff --git a/rs/moq-auth/src/mesh/coordinator.rs b/rs/moq-auth/src/mesh/coordinator.rs index 69eb7d2c4b9..bac0dd3c4d9 100644 --- a/rs/moq-auth/src/mesh/coordinator.rs +++ b/rs/moq-auth/src/mesh/coordinator.rs @@ -21,10 +21,11 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::routing::{delete, get, post}; use axum::{Json, Router}; +use moq_sign::PublicKey; use serde::{Deserialize, Serialize}; use serde_with::serde_as; -use super::{CHALLENGE_LEN, Challenge, EndpointId, EnrollRequest, Enrollment, ErrorCode, ErrorReply, Member, Proof}; +use super::{CHALLENGE_LEN, Challenge, EnrollRequest, Enrollment, ErrorCode, ErrorReply, Member, Proof}; use crate::{Claims, Key, Pattern}; /// How long a challenge stays valid. @@ -103,7 +104,7 @@ struct StoredKey { #[non_exhaustive] pub struct Device { /// Its endpoint ID. - pub endpoint: EndpointId, + pub endpoint: PublicKey, /// Its unique, DNS-safe name. pub name: String, /// The tags of the enrollment key it joined with. @@ -176,7 +177,7 @@ struct Inner { store: Store, /// The sequence of the last challenge each endpoint was granted with. Only an /// enrolled device gets an entry, so it grows with the devices and nothing else. - used: HashMap, + used: HashMap, } /// The mesh coordinator: issues challenges, enrolls devices, and refreshes their tokens. @@ -208,7 +209,7 @@ impl Coordinator { // than after an enrollment key is spent. config .key - .sign(&claims(EndpointId::from_bytes([0; 32]), kio::clock::wall(), None))?; + .sign(&claims(PublicKey::from_bytes([0; 32]), kio::clock::wall(), None))?; Ok(Self { config: Arc::new(config), secret: Arc::new(rind::hmac::Key::new(&rind::hmac::HMAC_SHA256, &random(32))), @@ -360,7 +361,7 @@ impl Coordinator { /// Revoke a device: its next refresh fails, and it cannot enroll again. /// Returns whether the device exists. - pub fn revoke_device(&self, endpoint: EndpointId) -> crate::Result { + pub fn revoke_device(&self, endpoint: PublicKey) -> crate::Result { let mut inner = self.inner.lock().unwrap(); let found = self.commit(&mut inner, |store| { let device = store.devices.iter_mut().find(|device| device.endpoint == endpoint); @@ -446,7 +447,7 @@ impl Coordinator { } /// Record `endpoint` as enrolled, or update its name and tags if it already is. - fn admit(&self, store: &mut Store, endpoint: EndpointId, name: Option<&str>, tags: Vec) -> Reply<()> { + fn admit(&self, store: &mut Store, endpoint: PublicKey, name: Option<&str>, tags: Vec) -> Reply<()> { refuse_revoked(store, endpoint)?; let devices = &mut store.devices; let current = devices.iter().position(|device| device.endpoint == endpoint); @@ -471,7 +472,7 @@ impl Coordinator { } /// Sign a token for an enrolled `endpoint` and list the mesh. - fn issue(&self, store: &Store, endpoint: EndpointId) -> Reply { + fn issue(&self, store: &Store, endpoint: PublicKey) -> Reply { let internal = |err: crate::Error| ErrorReply::new(ErrorCode::ServerError, err.to_string()); let now = kio::clock::wall(); // `exp` is whole seconds on the wire; truncate so the reply matches the token. @@ -524,7 +525,7 @@ impl Coordinator { } } -fn refuse_revoked(store: &Store, endpoint: EndpointId) -> Reply<()> { +fn refuse_revoked(store: &Store, endpoint: PublicKey) -> Reply<()> { if store .devices .iter() @@ -536,9 +537,9 @@ fn refuse_revoked(store: &Store, endpoint: EndpointId) -> Reply<()> { } /// The grant every mesh token carries: publish under its own ID, subscribe to the mesh. -fn claims(endpoint: EndpointId, issued: kio::clock::Wall, expires: Option) -> Claims { +fn claims(endpoint: PublicKey, issued: kio::clock::Wall, expires: Option) -> Claims { Claims::default() - .with_publish([endpoint.publish()]) + .with_publish([Pattern::subtree(&format!("mesh/{endpoint}")).expect("a z-base-32 segment is a valid path")]) .with_subscribe([Pattern::subtree("mesh").expect("a valid path")]) .with_issued(issued) .with_expires(expires) @@ -562,7 +563,7 @@ fn sanitize(name: &str) -> String { } /// `name`, or `name-2`, `name-3`, ... when another endpoint holds it. -fn unique_name(devices: &[Device], endpoint: EndpointId, name: &str) -> String { +fn unique_name(devices: &[Device], endpoint: PublicKey, name: &str) -> String { let taken = |candidate: &str| { devices .iter() @@ -699,21 +700,21 @@ mod tests { #[test] fn names_stay_unique() { let device = |byte, name: &str| Device { - endpoint: EndpointId::from_bytes([byte; 32]), + endpoint: PublicKey::from_bytes([byte; 32]), name: name.into(), tags: Vec::new(), enrolled: kio::clock::wall(), revoked: false, }; let devices = vec![device(1, "robot"), device(2, "robot-2")]; - assert_eq!(unique_name(&devices, EndpointId::from_bytes([1; 32]), "robot"), "robot"); + assert_eq!(unique_name(&devices, PublicKey::from_bytes([1; 32]), "robot"), "robot"); assert_eq!( - unique_name(&devices, EndpointId::from_bytes([3; 32]), "robot"), + unique_name(&devices, PublicKey::from_bytes([3; 32]), "robot"), "robot-3" ); let long = "a".repeat(MAX_NAME); let devices = vec![device(1, &long)]; - let name = unique_name(&devices, EndpointId::from_bytes([3; 32]), &long); + let name = unique_name(&devices, PublicKey::from_bytes([3; 32]), &long); assert_eq!(name.len(), MAX_NAME); assert!(name.ends_with("-2")); } diff --git a/rs/moq-auth/src/mesh/mod.rs b/rs/moq-auth/src/mesh/mod.rs index 93c05f36813..42ad5629822 100644 --- a/rs/moq-auth/src/mesh/mod.rs +++ b/rs/moq-auth/src/mesh/mod.rs @@ -20,8 +20,8 @@ //! Every refusal is a 4xx with an [`ErrorReply`]. use std::fmt; -use std::str::FromStr; +use moq_sign::PublicKey; use serde::{Deserialize, Serialize}; use serde_with::serde_as; @@ -44,96 +44,8 @@ pub const PROOF_CONTEXT: &[u8] = b"moq-mesh-enroll-00"; /// The length of a challenge in bytes. pub const CHALLENGE_LEN: usize = 32; -const KEY_LEN: usize = 32; const SIGNATURE_LEN: usize = 64; -/// z-base-32: most significant bit first, no padding, trailing bits must be zero. -static ZBASE32: std::sync::LazyLock = std::sync::LazyLock::new(|| { - let mut spec = data_encoding::Specification::new(); - spec.symbols.push_str("ybndrfg8ejkmcpqxot1uwisza345h769"); - spec.encoding().expect("a valid z-base-32 specification") -}); - -/// An endpoint's Ed25519 public key, which is also its endpoint ID. -/// -/// Its text form is the 52-character [z-base-32] of the key, the form pkarr and iroh's DNS -/// discovery use, which is also a valid DNS label. Parsing accepts only that form (lowercase, -/// zero trailing bits), so one key names exactly one `mesh/` path. -/// -/// [z-base-32]: https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt -#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct EndpointId([u8; KEY_LEN]); - -impl EndpointId { - /// The ID of the raw 32-byte Ed25519 public key. - pub fn from_bytes(bytes: [u8; KEY_LEN]) -> Self { - Self(bytes) - } - - /// The raw 32-byte Ed25519 public key. - pub fn as_bytes(&self) -> &[u8; KEY_LEN] { - &self.0 - } - - /// Whether `signature` is this key's Ed25519 signature over `message`. - pub fn verify(&self, message: &[u8], signature: &[u8]) -> bool { - use rind::signature::{PublicKey, verify}; - PublicKey::new(&verify::ED25519, &self.0).is_ok_and(|key| key.verify(message, signature).is_ok()) - } - - /// The broadcasts this endpoint may publish: `mesh//**`. - pub fn publish(&self) -> crate::Pattern { - crate::Pattern::subtree(&format!("mesh/{self}")).expect("a z-base-32 segment is a valid path") - } -} - -/// The text is not the 52-character z-base-32 of a 32-byte key. -#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] -#[error("invalid endpoint ID: expected 52 z-base-32 characters")] -#[non_exhaustive] -pub struct InvalidEndpoint; - -impl FromStr for EndpointId { - type Err = InvalidEndpoint; - - fn from_str(text: &str) -> Result { - // The alphabet is lowercase-only and nonzero trailing bits are refused, so a key has one text form. - let mut out = [0u8; KEY_LEN]; - match ZBASE32.decode_len(text.len()) { - Ok(KEY_LEN) => ZBASE32 - .decode_mut(text.as_bytes(), &mut out) - .map_err(|_| InvalidEndpoint)?, - _ => return Err(InvalidEndpoint), - }; - Ok(Self(out)) - } -} - -impl fmt::Display for EndpointId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&ZBASE32.encode(&self.0)) - } -} - -impl fmt::Debug for EndpointId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("EndpointId").field(&format_args!("{self}")).finish() - } -} - -impl Serialize for EndpointId { - fn serialize(&self, serializer: S) -> Result { - serializer.collect_str(self) - } -} - -impl<'de> Deserialize<'de> for EndpointId { - fn deserialize>(deserializer: D) -> Result { - let text = >::deserialize(deserializer)?; - text.parse().map_err(serde::de::Error::custom) - } -} - /// The message a [`Proof`] signs: [`PROOF_CONTEXT`], a zero byte, the coordinator's base /// URL as the device addressed it, a zero byte, then the raw challenge. /// @@ -173,7 +85,7 @@ pub struct Challenge { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Proof { /// The endpoint ID, which is the key that signed. - pub endpoint: EndpointId, + pub endpoint: PublicKey, /// The challenge, as issued. #[serde_as(as = "serde_with::base64::Base64")] pub challenge: Vec, @@ -196,10 +108,12 @@ impl Proof { /// Whether the signature verifies for the coordinator `base`. The challenge's /// freshness is the coordinator's to check. pub fn verify(&self, base: &url::Url) -> bool { + use rind::signature::{PublicKey, verify}; self.signature.len() == SIGNATURE_LEN - && self - .endpoint - .verify(&proof_message(base, &self.challenge), &self.signature) + && PublicKey::new(&verify::ED25519, self.endpoint.as_bytes()).is_ok_and(|key| { + key.verify(&proof_message(base, &self.challenge), &self.signature) + .is_ok() + }) } } @@ -209,14 +123,14 @@ impl Proof { /// its own key type. pub trait Signer: Send + Sync { /// The endpoint ID: this key's public half. - fn endpoint(&self) -> EndpointId; + fn endpoint(&self) -> PublicKey; /// The Ed25519 signature over `message`. fn sign(&self, message: &[u8]) -> [u8; SIGNATURE_LEN]; } impl Signer for rind::signature::Ed25519KeyPair { - fn endpoint(&self) -> EndpointId { - EndpointId( + fn endpoint(&self) -> PublicKey { + PublicKey::from_bytes( self.public_key() .as_ref() .try_into() @@ -267,7 +181,7 @@ pub struct Enrollment { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Member { /// Its endpoint ID. - pub endpoint: EndpointId, + pub endpoint: PublicKey, /// Its unique, DNS-safe name. pub name: String, /// The tags of the enrollment key it joined with. @@ -337,30 +251,22 @@ mod tests { } #[test] - fn endpoint_ids_have_one_text_form() { - let id = signer().endpoint(); - let text = id.to_string(); - assert_eq!(text.len(), 52); - assert_eq!(text.parse::().unwrap(), id); - assert!(text.to_uppercase().parse::().is_err()); - assert!(text[..51].parse::().is_err()); - assert!(format!("{text}y").parse::().is_err()); - assert!( - data_encoding::HEXLOWER - .encode(id.as_bytes()) - .parse::() - .is_err() - ); - assert_eq!(id.publish().as_str(), format!("mesh/{text}/**")); - } - - #[test] - fn endpoint_ids_are_z_base_32() { - assert_eq!(EndpointId::from_bytes([0; KEY_LEN]).to_string(), "y".repeat(52)); - let ones = EndpointId::from_bytes([0xff; KEY_LEN]); - assert_eq!(ones.to_string(), format!("{}o", "9".repeat(51))); - // The last character carries 4 padding bits, which must be zero. - assert!(format!("{}9", "9".repeat(51)).parse::().is_err()); + fn endpoint_vectors() { + let vectors: serde_json::Value = + serde_json::from_str(include_str!("../../../../drafts/moq-sign-00.json")).unwrap(); + for row in vectors["keys"].as_array().unwrap() { + let text = row["endpoint"].as_str().unwrap(); + let member: Member = serde_json::from_value(serde_json::json!({"endpoint": text, "name": "node"})).unwrap(); + assert_eq!(member.endpoint.to_string(), text, "{}", row["id"]); + assert_eq!(serde_json::to_value(&member).unwrap()["endpoint"], text); + } + for row in vectors["invalid_ids"].as_array().unwrap() { + assert!( + serde_json::from_value::(serde_json::json!({"endpoint": row["text"], "name": "node"})).is_err(), + "{}", + row["id"] + ); + } } #[test] diff --git a/rs/moq-sign/Cargo.toml b/rs/moq-sign/Cargo.toml index bcad6ad0373..83e5bf2a3ee 100644 --- a/rs/moq-sign/Cargo.toml +++ b/rs/moq-sign/Cargo.toml @@ -19,6 +19,7 @@ bytes = { workspace = true } data-encoding = { workspace = true } kio = { workspace = true } moq-net = { workspace = true } +serde = { workspace = true } thiserror = { workspace = true } zeroize = { workspace = true } diff --git a/rs/moq-sign/src/key.rs b/rs/moq-sign/src/key.rs index aa977c818bc..9ab1cdc3c2d 100644 --- a/rs/moq-sign/src/key.rs +++ b/rs/moq-sign/src/key.rs @@ -6,6 +6,7 @@ use std::str::FromStr; use std::sync::Arc; use aws_lc_rs::signature::{ED25519, Ed25519KeyPair, KeyPair, UnparsedPublicKey}; +use serde::{Deserialize, Serialize}; use zeroize::Zeroizing; use crate::scope::SIGNATURE_LEN; @@ -31,11 +32,16 @@ static ZBASE32: std::sync::LazyLock = std::sync::LazyLo pub struct PublicKey([u8; KEY_LEN]); impl PublicKey { - #[cfg(test)] - pub(crate) fn from_bytes(bytes: [u8; KEY_LEN]) -> Self { + /// The ID of the raw 32-byte Ed25519 public key. + pub fn from_bytes(bytes: [u8; KEY_LEN]) -> Self { Self(bytes) } + /// The raw 32-byte Ed25519 public key. + pub fn as_bytes(&self) -> &[u8; KEY_LEN] { + &self.0 + } + /// Whether `signature` is this key's Ed25519 signature over `message`. pub(crate) fn verify(&self, message: &[u8], signature: &[u8; SIGNATURE_LEN]) -> bool { UnparsedPublicKey::new(&ED25519, &self.0) @@ -70,6 +76,19 @@ impl fmt::Debug for PublicKey { } } +impl Serialize for PublicKey { + fn serialize(&self, serializer: S) -> Result { + serializer.collect_str(self) + } +} + +impl<'de> Deserialize<'de> for PublicKey { + fn deserialize>(deserializer: D) -> Result { + let text = >::deserialize(deserializer)?; + text.parse().map_err(serde::de::Error::custom) + } +} + /// Decode exactly 52 z-base-32 characters. The alphabet is lowercase-only and nonzero trailing /// bits are refused, so a key has one text form. fn decode(text: &str) -> Result<[u8; KEY_LEN], InvalidKey> { diff --git a/rs/moq-sign/src/tests.rs b/rs/moq-sign/src/tests.rs index 58ed38af99b..2e408090bd9 100644 --- a/rs/moq-sign/src/tests.rs +++ b/rs/moq-sign/src/tests.rs @@ -54,6 +54,13 @@ fn vector_keys() { "{id}" ); assert_eq!(endpoint.to_string(), row["endpoint"].as_str().unwrap(), "{id}"); + assert_eq!(endpoint.as_bytes().as_slice(), hex(&row["public"]), "{id}"); + assert_eq!(serde_json::to_value(endpoint).unwrap(), row["endpoint"], "{id}"); + assert_eq!( + serde_json::from_value::(row["endpoint"].clone()).unwrap(), + endpoint, + "{id}" + ); if !row["seed"].is_null() { assert_eq!(seed(&row["seed"]).public(), endpoint, "{id}"); } @@ -99,6 +106,11 @@ fn vector_invalid_ids() { "{}", row["id"] ); + assert!( + serde_json::from_value::(row["text"].clone()).is_err(), + "{}", + row["id"] + ); } } diff --git a/rs/workspace-hack/Cargo.toml b/rs/workspace-hack/Cargo.toml index 767776371e0..58c20b22fef 100644 --- a/rs/workspace-hack/Cargo.toml +++ b/rs/workspace-hack/Cargo.toml @@ -57,7 +57,6 @@ futures-core = { version = "0.3" } futures-executor = { version = "0.3" } futures-io = { version = "0.3" } futures-sink = { version = "0.3" } -futures-task = { version = "0.3", default-features = false, features = ["std"] } futures-util = { version = "0.3", features = ["channel", "io", "sink"] } getrandom-6f8ce4dd05d13bba = { package = "getrandom", version = "0.2", default-features = false, features = ["std"] } hashbrown = { version = "0.17", default-features = false, features = ["default-hasher", "inline-more"] } @@ -173,7 +172,6 @@ futures-core = { version = "0.3" } futures-executor = { version = "0.3" } futures-io = { version = "0.3" } futures-sink = { version = "0.3" } -futures-task = { version = "0.3", default-features = false, features = ["std"] } futures-util = { version = "0.3", features = ["channel", "io", "sink"] } getrandom-6f8ce4dd05d13bba = { package = "getrandom", version = "0.2", default-features = false, features = ["std"] } hashbrown = { version = "0.17", default-features = false, features = ["default-hasher", "inline-more"] } diff --git a/sh/drafts/check.sh b/sh/drafts/check.sh index e5b78393bec..e1f852cba4c 100755 --- a/sh/drafts/check.sh +++ b/sh/drafts/check.sh @@ -31,6 +31,6 @@ for f in draft-*.md; do done for f in moq-e2ee-*.ts moq-sign-*.ts; do - bun tsc --ignoreConfig --noEmit --skipLibCheck --target esnext --module esnext --moduleResolution bundler --types bun "$f" + bun tsc --ignoreConfig --noEmit --skipLibCheck --target esnext --module esnext --moduleResolution bundler --allowImportingTsExtensions --types bun "$f" bun "$f" done From e4ab6a58000ac968ed4ec6109ec9ac1740fe24de Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 04:11:56 -0800 Subject: [PATCH 3/4] docs(quest): record key dependency and API blockers Co-Authored-By: GPT-6.1 Sol --- quest/m1/mesh-key-codec.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/quest/m1/mesh-key-codec.md b/quest/m1/mesh-key-codec.md index 5ccd2b84a38..4f978357fa6 100644 --- a/quest/m1/mesh-key-codec.md +++ b/quest/m1/mesh-key-codec.md @@ -45,6 +45,20 @@ Public API: breaking for moq-auth (`mesh::EndpointId` becomes ## Waiting +- Maintainer: choose the dependency boundary after local review of + [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733). The direct + dependency proposed in that draft makes published `moq-auth` require + `moq-sign`, whose manifest sets `publish = false`. It also makes auth compile + net and aws-lc-rs just for the public key, while auth itself verifies on rind. + Option 1 (recommended): move the existing `PublicKey` and codec to a small + publishable leaf crate and re-export the same type from signing; settle the + crate name before implementation. Option 2: make the existing signing crate + publishable with a key-only dependency path, gating its net and aws-lc-rs + dependencies. Keep the rename in + [moq-dev/moq#7702](https://github.com/moq-dev/moq/pull/7702) independent and do + not settle its timestamp-export decision here. A maintainer comment choosing + the boundary and naming clears this wait; implement it, rerun checks, and + review the resulting head before completion. - Maintainer: settle the extra methods on the removed `EndpointId` before completing [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733). It exposed `publish()` and raw `verify(message, signature)`, while signing's From 8b7ef5ddb48c1c2d02b15b30ab069c697e59e34d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 15:55:22 -0800 Subject: [PATCH 4/4] docs(quest): finish mesh-key-codec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maintainer decision 2026-11-03: ✅ option 1, no EndpointId convenience helpers, as already implemented. Use `Pattern::subtree(&format!("mesh/{endpoint}"))` for mesh paths and `Proof::verify` or a verifier over `PublicKey::as_bytes()` for signatures. With the dependency boundary also settled, this PR completes the quest, so delete it and its link. Co-Authored-By: Claude Opus 5.5 --- quest/m1/README.md | 1 - quest/m1/mesh-key-codec.md | 71 -------------------------------------- 2 files changed, 72 deletions(-) delete mode 100644 quest/m1/mesh-key-codec.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 13b46b1670d..9b36966731a 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -175,7 +175,6 @@ per-frame CPU growth since #5926. - [Authored tracks default to a 30 s max-age](/quest/m1/max-age-defaults.md) - raw and media tracks advertise 30 s unless their author chooses otherwise, with explicit unlimited in every binding - [HLS export lists a same-codec reconfigure's first group under the new init](/quest/m1/hls-reinit-same-codec.md) - the hand-over pick, whichever of the catalog and the records arrives first, after the catalog `hls` removal is planned - [A cancelled MoqTrackDemand wait never loses the next change](/quest/m1/demand-cancel-race.md) - cancelling a `MoqTrackDemand::wanted_changed` call, from any binding, never consumes a demand change -- [One Ed25519 public key type with one z-base-32 codec](/quest/m1/mesh-key-codec.md) - `moq_auth::mesh::EndpointId` is merged into `moq_crypto::sign::PublicKey` - [Ordered reads can skip owed holes, and snapshot latest() does](/quest/m1/ordered-owed-holes.md) - moq-net's `Ordered` gains a read that skips past an owed hole to the newest buffered group, while keeping the reader's bounds - [A Rust relay never replays from group 0 to a lite-03/04 subscriber](/quest/m1/relay-inflight-replay.md) - A Rust relay or publisher serving a lite-03 or lite-04 SUBSCRIBE from a track copy that is still resolving starts at the newest group once the copy resolves - [Stats name the route instance's epoch with a type](/quest/m1/stats-epoch-type.md) - `GroupFrame::epoch` gets a dedicated type and tests stop mislabelling the instance diff --git a/quest/m1/mesh-key-codec.md b/quest/m1/mesh-key-codec.md deleted file mode 100644 index dba8ab0b205..00000000000 --- a/quest/m1/mesh-key-codec.md +++ /dev/null @@ -1,71 +0,0 @@ -# [S] One Ed25519 public key type with one z-base-32 codec - -## Goal - -`moq_auth::mesh::EndpointId` is merged into `moq_crypto::sign::PublicKey`: one Rust -type for a mesh endpoint's Ed25519 public key, with one z-base-32 text codec -(52 lowercase characters, zero trailing bits, no other text form) that -moq-auth and moq-crypto share. JS has one codec too, used by `@moq/crypto` and -by `@moq/auth` if it grows one. The text form, vectors, and refusals stay as -both PRs specified. - -## Plan - -Decided 2026-10-31 (user, /quest-plan of the follow-ups from the 2026-10-31 -/quest-complete run), from -[moq-dev/moq#7301](https://github.com/moq-dev/moq/pull/7301) and -[moq-dev/moq#7092](https://github.com/moq-dev/moq/pull/7092). - -Milestone: ✅ m1 (moved from m2). Not chosen: m2. There is no m1 mesh epic, -so this sits at the m1 top level; the [mesh epic](/quest/m2/mesh/README.md) -is related. - -- [moq-dev/moq#7301](https://github.com/moq-dev/moq/pull/7301) (merged) added `moq_auth::mesh::EndpointId` (an Ed25519 key with z-base-32 - text, via `data-encoding` with a custom `Specification`). [moq-dev/moq#7092](https://github.com/moq-dev/moq/pull/7092) (merged) added - `rs/moq-sign` with `SecretKey`/`PublicKey` using the same specification, - and a separate JS codec in `js/sign/src/zbase32.ts`. Both chose z-base-32 - so they would share one format; whichever landed second was to dedupe. -- Merge `EndpointId` into `moq_crypto::sign::PublicKey` (moq-auth depends on - moq-crypto for it, or the type moves to a small shared crate if the - dependency direction is wrong; say which in the PR). Keep the shared - vectors in `drafts/moq-sign-00.json` as the single source of test vectors. -- [moq-dev/moq#7702](https://github.com/moq-dev/moq/pull/7702) merged - `moq-sign`/`@moq/sign` into `moq-crypto`/`@moq/crypto`; the JS codec is - `js/crypto/src/sign/zbase32.ts`. -- Dependency boundary, decided 2026-11-03 (maintainer): ✅ publish moq-crypto - with a key-only dependency path that excludes moq-net and aws-lc-rs. Not - chosen: a separate publishable leaf crate. The `sign` and `e2ee` default - features gate those modules; with default features off, moq-crypto is only - `sign::PublicKey`/`InvalidKey` and the z-base-32 codec (`serde` optional), - which moq-auth depends on. -- [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733) implements this: - auth uses `moq_crypto::sign::PublicKey` directly, the key gains public byte - access and string serde, and auth's codec is removed. Auth still verifies - proofs on rind. Rust auth/crypto and JS crypto consume - `drafts/moq-sign-00.json`. -- Note, not in scope: persist a browser JS `SecretKey` (a nonextractable - `CryptoKey`) in IndexedDB only once a browser mesh node needs a stable - endpoint ID. - -Public API: breaking for moq-auth (`mesh::EndpointId` becomes -`moq_crypto::sign::PublicKey`). Wire: none. - -## Waiting - -- Maintainer: settle the extra methods on the removed `EndpointId` before - completing [moq-dev/moq#7733](https://github.com/moq-dev/moq/pull/7733). - It exposed `publish()` and raw `verify(message, signature)`, while the - crypto `PublicKey::verify` is private, needs the `sign` feature (aws-lc-rs), - and takes a fixed-size signature. Option 1 (recommended, implemented in the - draft): keep mesh policy and rind proof verification in auth, use - `Pattern::subtree(&format!("mesh/{endpoint}"))` for paths, and use - `Proof::verify` or a verifier over `PublicKey::as_bytes()` for signatures. - This adds no new public helper or verification API. Option 2: preserve - those conveniences with a public mesh path helper and public raw - `PublicKey` verification, settling their names, verification contract, and - backend. A maintainer comment on the PR choosing the migration clears this - wait. - -## Related - -- [Mesh](/quest/m2/mesh/README.md) - the epic both types serve