package io.flamenet.e2e import kotlin.test.Test import kotlin.test.assertEquals /** * The salt for an account on a relay that keeps its own accounts. * * 🔴 **Pinned against the JavaScript engine, which is normative** — the value * below was produced by `engine/src/fnid.js`'s `localAccountSalt`, not by this * implementation. A Kotlin test that asserts what Kotlin computes proves only * that Kotlin is self-consistent; the failure this guards against is the three * engines disagreeing, which surfaces as one person having two addresses * depending on which phone they signed in from. * * ⚠️ Changing the expected value here is never the fix. It is a wire constant: * a different salt is a different account key, and a different account key is * a different person to everyone who pinned the old one. */ class LocalAccountSaltTest { @Test fun `matches the javascript engine`() { assertEquals( "331bfb32ce724a978dda86f671ac324a", AccountKdf.localAccountSalt("fnreviewalpha").toHex(), ) } /** Normalisation is part of the contract, not a convenience. */ @Test fun `case and surrounding space do not change the salt`() { val plain = AccountKdf.localAccountSalt("fnreviewalpha").toHex() assertEquals(plain, AccountKdf.localAccountSalt("FNReviewAlpha").toHex()) assertEquals(plain, AccountKdf.localAccountSalt(" fnreviewalpha ").toHex()) } @Test fun `it is the length the KDF params ask for`() { assertEquals( AccountKdf.Params.PBKDF2_V1.saltBytes, AccountKdf.localAccountSalt("someone").size, ) } private fun ByteArray.toHex() = joinToString("") { "%02x".format(it) } }