Developer guide
Add Sign in with Rhea Key
A person approves on their device. Your server checks the result and starts its own session. Rhea never receives a recovery phrase or private key.
The official button shows the Rhea mark and the word Key in red (white on the red theme). See a live sign-in at rheakey.com/demo.
1Register your site
Unlock Rhea Key on rheakey.com/apps and add the exact address your site uses. The button only works on a registered site, and registration is signed by your key. There is no email signup.
For local work, register a loopback address. It needs no domain proof:
http://localhost:3000/api/auth/callback/rheakeyThe button is allowed on that address's origin (here http://localhost:3000). A public https site also proves it controls the host, with a short token at /.well-known/rheakey or a DNS TXT record on _rheakey. Addresses are matched exactly. No wildcards.
2Add the button and try it
Paste this into a page on http://localhost:3000. The two test attributes let you approve a sign-in before you write any server code:
<!-- Test only. Works on http://localhost after step 1. -->
<script src="https://rheakey.com/sdk/rhea.js" async></script>
<rhea-button app-name="My App" challenge="client" verify-url="none"></rhea-button>
<script>
document.addEventListener("rhea-success", (e) => console.log("Approved by", e.detail.address));
document.addEventListener("rhea-error", (e) => console.warn("Rhea Key:", e.detail.code));
</script>challenge="client" only works on localhost; the button refuses it anywhere else. Never ship verify-url="none".
3Verify on your server
Add two routes on the same origin, then remove the two test attributes. The button calls them for you:
POST /rhea-challengereturns{ nonce, issuedAt, expirationTime }and sets an HttpOnly cookie that points at that one challenge.POST /rhea-verifyreceives{ message, signature, address }, checks it against that challenge, starts a new session and answers 2xx. Any other answer shows “This site could not confirm sign-in”.
<script src="https://rheakey.com/sdk/rhea.js" async></script>
<rhea-button app-name="My App"></rhea-button>
<script>
// Fires only after your /rhea-verify route answered 2xx.
document.addEventListener("rhea-success", () => location.reload());
document.addEventListener("rhea-error", (e) => console.warn("Rhea Key:", e.detail.code));
</script>// server.mjs (Node 20+): npm i express cookie-parser ethers
import express from "express";
import cookieParser from "cookie-parser";
import { randomBytes } from "node:crypto";
import { verifyMessage } from "ethers";
const DOMAIN = "localhost:3000"; // your host, exactly as the browser shows it
const ORIGIN = "http://localhost:3000"; // your origin
const TTL_MS = 120_000; // two minutes at most
const challenges = new Map(); // production: Redis GETDEL or SQL DELETE ... RETURNING
const app = express();
app.use(express.json({ limit: "8kb" }));
app.use(cookieParser());
app.post("/rhea-challenge", (req, res) => {
const id = randomBytes(32).toString("hex");
const now = Date.now();
const challenge = {
nonce: randomBytes(16).toString("hex"),
issuedAt: new Date(now).toISOString(),
expirationTime: new Date(now + TTL_MS).toISOString(),
};
challenges.set(id, challenge);
res.cookie("rhea_rk1", id, {
httpOnly: true, sameSite: "lax", path: "/", maxAge: TTL_MS,
secure: ORIGIN.startsWith("https:"),
});
res.json(challenge);
});
app.post("/rhea-verify", (req, res) => {
const id = req.cookies.rhea_rk1;
const challenge = challenges.get(id);
challenges.delete(id); // single use, even when the check fails
res.clearCookie("rhea_rk1", { path: "/" });
const { message, signature, address } = req.body ?? {};
try {
if (!challenge || typeof message !== "string" || typeof address !== "string") throw 0;
const lines = message.split("\n");
const field = (name) => {
const hits = lines.filter((l) => l.startsWith(name + ": "));
if (hits.length !== 1) throw 0;
return hits[0].slice(name.length + 2);
};
if (lines[0] !== `${DOMAIN} wants you to sign in with your Rhea Key account:`) throw 0;
if (lines[1].toLowerCase() !== address.toLowerCase()) throw 0;
if (new URL(field("URI")).origin !== ORIGIN) throw 0;
if (field("Nonce") !== challenge.nonce) throw 0;
if (field("Issued At") !== challenge.issuedAt) throw 0;
if (field("Expiration Time") !== challenge.expirationTime) throw 0;
if (Date.now() > Date.parse(challenge.expirationTime)) throw 0;
if (verifyMessage(message, signature).toLowerCase() !== address.toLowerCase()) throw 0;
} catch {
return res.status(401).json({ error: "sign_in_failed" });
}
// Signed in as `address`. Start a NEW session here; never reuse the old session id.
res.status(204).end();
});
app.listen(3000);The browser event is not enough. Always verify on your server before you create a session. Issue a new session id; never reuse the old one. Every check is listed on RK-1.
Already use an identity library?
Use OpenID Connect instead of the button: register a callback in step 1, then point Auth.js, Auth0, Keycloak or any OIDC client at the issuer https://rheakey.com.
// auth.ts (Auth.js v5). Works today; no Rhea package needed.
// Callback: http://localhost:3000/api/auth/callback/rheakey
import NextAuth from "next-auth";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [{
id: "rheakey",
name: "Rhea Key",
type: "oidc",
issuer: "https://rheakey.com",
clientId: process.env.RHEA_CLIENT_ID,
clientSecret: process.env.RHEA_CLIENT_SECRET,
checks: ["pkce", "state", "nonce"],
client: {
token_endpoint_auth_method: "client_secret_post",
id_token_signed_response_alg: "ES256",
},
}],
});Full settings are on OIDC. If something fails, the code is explained on Errors.

