9afd3558b9e8
rewrite stale Rust host comment references in noise-js, noise-js.test, sync-types
- time
- 2026-05-07 14:40 UTC · 5 months ago
- machine
- koh2
- parent
- 923817147387
↓ peach-browser-9afd3558.tar.gzatlas at this save
files changed3 files
src/shared/noise-js.test.ts+8 −14src/shared/noise-js.ts+5 −8src/shared/sync-types.ts+4 −4src/shared/noise-js.test.ts+8 −14
@@ -1,16 +1,10 @@11 /**2- * Noise NK auth proof cross-check.2+ * Noise NK auth proof regression test.33 *4- * The JS implementation in `noise-js.ts` MUST produce byte-identical proofs to5- * the native Rust host (see `native/peach-sync-host/src/auth.rs`). The fixed6- * test vector below was captured by running:7- *8- * cargo test --manifest-path native/peach-sync-host/Cargo.toml \9- * print_known_proof_for_js_cross_check -- --nocapture10- *11- * If either side ever changes the auth proof format, ONE of the two pinned12- * hex strings (here and in auth.rs) will fail and CI catches the divergence13- * before any device pair gets wedged.4+ * Pins a known input → output for the HMAC-SHA256 proof so any change to the5+ * proof format is caught immediately. The pinned vector was captured against6+ * the originally-shipped implementation; if the format ever needs to change,7+ * regenerate both this vector and any peer that pairs against this build.148 */159 1610 import { describe, expect, it } from "vitest";@@ -25,7 +19,7 @@2519 performResponderAuth,2620 } from "./noise-js";2721 28-// Inputs match the Rust test in auth.rs::tests::print_known_proof_for_js_cross_check22+// Pinned cross-check vector for HMAC-SHA256 auth proof.2923 const INITIATOR_PRIVATE = new Uint8Array(32).fill(0x01);3024 const RESPONDER_PRIVATE = new Uint8Array(32).fill(0x02);3125 const NONCE = new Uint8Array(32).fill(0x03);@@ -47,11 +41,11 @@4741 }4842 4943 describe("noise-js cross-check", () => {50- it("computes the same proof bytes as the Rust auth.rs HMAC-SHA256 scheme", () => {44+ it("computes the pinned HMAC-SHA256 proof for the known input vector", () => {5145 // Use the pinned public-key constants — they correspond to the X255195246 // public derived from the all-0x01 / all-0x02 private keys. Rederiving5347 // them here would require a "derivePublic from raw scalar" helper that54- // @stablelib does not expose, so we trust the Rust pinned values.48+ // @stablelib does not expose, so we trust the pinned values.5549 void derivePublic;5650 5751 const initiatorPublic = hexToBytes(EXPECTED_INITIATOR_PUBLIC);src/shared/noise-js.ts+5 −8
@@ -134,8 +134,7 @@134134 }135135 136136 /**137- * Compute the auth proof byte-for-byte identically to the native host.138- * See `native/peach-sync-host/src/auth.rs::proof_for`.137+ * Compute the post-handshake auth proof.139138 *140139 * proof = HMAC-SHA256(141140 * key = X25519(local_priv, remote_pub), // 32-byte DH shared@@ -145,9 +144,8 @@145144 * || nonce_32146145 * )147146 *148- * The initiator and responder both pass the same DH peer key (their PEER's149- * public key) and the same initiator_public/responder_public ordering so the150- * MAC matches. `mac_for` in auth.rs implements both directions; this helper147+ * Both sides pass the same DH peer key (their PEER's public key) and the same148+ * initiator_public/responder_public ordering so the MAC matches. This helper151149 * targets the initiator-side: `local_priv` is the initiator's private key,152150 * `remote_pub` is the responder's public key.153151 */@@ -305,9 +303,8 @@305303 * generate a random 32-byte nonce, send `Challenge`, receive `Proof`, and306304 * verify. Returns the initiator's authenticated public key on success.307305 *308- * Mirrors `auth.rs::verify_proof`: the MAC key is X25519(our_priv,309- * initiator_pub) and the data is the same domain-separated transcript both310- * sides feed into HMAC-SHA256.306+ * The MAC key is X25519(our_priv, initiator_pub) and the data is the same307+ * domain-separated transcript both sides feed into HMAC-SHA256.311308 */312309 export async function performResponderAuth(313310 session: NoiseNKSession,src/shared/sync-types.ts+4 −4
@@ -98,10 +98,10 @@9898 receivedAt: number;9999 expiresAt: number;100100 /**101- * Native-host connection id of the still-open pairing-only connection. The102- * background's RESPOND_INCOMING_PAIRING handler sends PAIR_ACCEPT or103- * PAIR_REJECT over this connection then disconnects. May be absent for104- * synthetic test injections that do not have a real connection behind them.101+ * Connection id of the still-open pairing-only socket. The background's102+ * RESPOND_INCOMING_PAIRING handler sends PAIR_ACCEPT or PAIR_REJECT over103+ * this connection then disconnects. May be absent for synthetic test104+ * injections that do not have a real connection behind them.105105 */106106 connectionId?: string;107107 }