Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/try-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jobs:
"$RUNNER_TEMP/frame-draw/bin/python" -I bootstrap/og.py
- name: The frame verifies in a real module worker, refuses bad archives and works offline
run: node --test site/worker-browser.test.mjs
- name: Prism ids - the pinned stitch copy matches its lock, every session check refuses, and two apps share one id
- name: Prism accounts - every signature check refuses, and the passkey flow signs in
run: npm run test:identity
- name: Build the canonical frame every Prism app loads
run: node frame/publish.mjs "$RUNNER_TEMP/frame" "$GITHUB_SHA"
- name: Build the sign-in page for id.uor.foundation, pinned by hash
run: node identity/publish.mjs "$RUNNER_TEMP/identity" "$GITHUB_SHA"

deploy:
name: publish the try page and the canonical frame
Expand Down
34 changes: 18 additions & 16 deletions bootstrap/page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ const prismRegistry = new URL(`https://${DEFAULT_REGISTRY}/`);
// a frame change reaches this app without rebuilding it. app.json may name
// another frame host, for a test or a mirror.
const frameHost = new URL(meta.frame ?? "https://uor-foundation.github.io/template/frame/");
// Prism accounts: the sign-in page the frame's account panel shows. The
// page's policy frames that one origin and no other. app.json may name
// another, for a test.
const accounts = new URL(meta.accounts ?? "https://id.uor.foundation/");
const shareUrl = live.href;

// The one speculation rule: the frame marks the pages a visitor is about to
Expand All @@ -117,26 +121,23 @@ const speculationRules = JSON.stringify({
// with the page's, so the frame does not wait for a TLS handshake.
const frameConnect = frameHost.origin !== live.origin ? `<link rel="preconnect" href="${escape(frameHost.origin)}" crossorigin />` : "";

// The origins this page's connect-src must name for the frame: its Unsplash
// worker, for the theme panel's search, and stitch's relay (with its
// WebSocket origin), where a visitor's Prism id devices meet. Both are read
// from the live frame at build, after its SHA-256 is checked as the browser
// checks it. The frame itself is not written into the page: the page's own
// stand-in (prism-page.css) shows, drawn as the bar, until the module
// arrives, which keeps the first load inside the Lighthouse budget.
async function frameAllowed() {
// The frame's Unsplash worker, which this page's connect-src must name for
// the theme panel's search: read from the live frame at build, after its
// SHA-256 is checked as the browser checks it. The frame itself is not
// written into the page: the page's own stand-in (prism-page.css) shows,
// drawn as the bar, until the module arrives, which keeps the first load
// inside the Lighthouse budget.
async function frameUnsplash() {
try {
const pointer = await (await fetch(new URL("current.json", frameHost), { cache: "no-store" })).json();
if (!/^[0-9a-f]{64}$/.test(pointer.sha256 ?? "")) throw new Error("the frame pointer names no sha256");
const bytes = Buffer.from(await (await fetch(new URL(pointer.module, frameHost))).arrayBuffer());
if (hex(bytes) !== pointer.sha256) throw new Error(`the frame is ${hex(bytes)}, its pointer says ${pointer.sha256}`);
const frame = await import(`data:text/javascript;base64,${bytes.toString("base64")}`);
const origin = (value) => (/^https:\/\/[a-z0-9.-]+$/.test(value ?? "") ? value : "");
const relay = origin(/^https:\/\/[a-z0-9.-]+/.exec(frame.PRISM_RELAY ?? "")?.[0]);
return { unsplash: origin(frame.UNSPLASH_ORIGIN), relay: relay ? `${relay} ${relay.replace(/^https:/, "wss:")}` : "" };
return /^https:\/\/[a-z0-9.-]+$/.test(frame.UNSPLASH_ORIGIN ?? "") ? frame.UNSPLASH_ORIGIN : "";
} catch (error) {
console.warn(`page: the frame could not be read at build (${error.message}); no Unsplash or relay origin in connect-src`);
return { unsplash: "", relay: "" };
console.warn(`page: the frame could not be read at build (${error.message}); no Unsplash origin in connect-src`);
return "";
}
}
// The repository's GitHub stars at build, so the bar shows them from its
Expand Down Expand Up @@ -165,7 +166,7 @@ async function githubStars() {
}
}
const stars = await githubStars();
const frameOrigins = await frameAllowed();
const unsplashOrigin = await frameUnsplash();

// ---------------------------------------------------------------------------
// The workspace and the spec, rendered here so the page says everything
Expand Down Expand Up @@ -431,8 +432,9 @@ const fill = {
HOLO_SEARCH_ORIGIN: holoSearch.origin,
REGISTRY_ORIGIN: prismRegistry.origin,
FRAME_ORIGIN: frameHost.origin,
UNSPLASH_ORIGIN: frameOrigins.unsplash,
PRISM_RELAY_ORIGINS: frameOrigins.relay,
ACCOUNTS: escape(accounts.href),
ACCOUNTS_ORIGIN: accounts.origin,
UNSPLASH_ORIGIN: unsplashOrigin,
OG_IMAGE: escape(new URL("og.png", live).href),
OG_ALT: escape(`${meta.name}: ${meta.purpose}`),
NAME: escape(meta.name),
Expand Down
4 changes: 2 additions & 2 deletions frame.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"path": "bootstrap/page.mjs",
"sha256": "8eee238bce9206ca58fc9be5471c28c0bdab82e2350ed78f1972da2a1da6581f"
"sha256": "2df4ef057d37e778b04f67e4f63d862c7da6a77c301d0862b2bb8681fc8ec9d4"
},
{
"path": "bootstrap/precache.mjs",
Expand Down Expand Up @@ -51,7 +51,7 @@
},
{
"path": "site/page.template.html",
"sha256": "b48b9d18e23e959c9e96b4bec58e2e7d80b7b977e981d8a7b0fd369293819b08"
"sha256": "d7df0bc4d5190ca38ee768bdbd54cbc665ede811608de846068c8a92bd02c14d"
},
{
"path": "site/prism-page.css",
Expand Down
4 changes: 2 additions & 2 deletions frame/frame.css
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ svg.gh, svg.fill { fill: currentColor; stroke: none; }
#github[hidden] + .sep { display: none; }
/* Full screen: the corners point out to enter, in to leave. */
:host([fullscreen]) #fullscreen .expand, :host(:not([fullscreen])) #fullscreen .shrink { display: none; }
/* The account: a line drawing signed out; while the Prism id window is open
* it breathes; signed in, the same figure filled, in the full text
/* The account: a line drawing signed out; while the device is asked for its
* passkey it breathes; signed in, the same figure filled, in the full text
* colour, so who is signed in reads at a glance and nothing else changes. */
#account.signed-in { color: var(--foreground); }
#account.signed-in svg.person { fill: currentColor; }
Expand Down
50 changes: 25 additions & 25 deletions frame/frame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// The contract (prism/frame/1):
// <prism-frame name address live repo home purpose card identity
// verdict verdict-label fingerprint proof proof-url examples>
// verdict verdict-label fingerprint proof proof-url examples accounts>
// <span slot="status">…</span> optional: shown in the bar, e.g. "Update available"
// </prism-frame>
// name the app's name ("Luhn check")
Expand All @@ -25,10 +25,11 @@
// proof-url optional: the proof's attestation
// examples optional: "passed/total" once the page has replayed the holo's
// examples, "running" while it does, "error" when it could not
// The element's account is the visitor's Prism id (null when signed out);
// sign(bytes) signs with this browser's session key and returns the
// signature with the id's delegation; "accountchange" fires on sign-in and
// sign-out. identity/PROTOCOL.md is the account contract.
// accounts optional: the Prism accounts origin (https://id.uor.foundation)
// The element's account is the visitor's Prism account (null when signed
// out); sign(bytes) signs with this browser's session key and returns the
// signature with the passkey's delegation; "accountchange" fires on sign-in
// and sign-out. identity/PROTOCOL.md is the account contract.
// The shield sums the three: green only when the bytes are authentic and
// every example gives its proved answer; its panel shows each check, as a
// browser shows a page's security.
Expand Down Expand Up @@ -345,14 +346,12 @@ function holoIndex() {
const githubMark = '<svg class="gh" viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" focusable="false"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z" /></svg>';
const starMark = '<svg class="star" viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" focusable="false"><path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z" /></svg>';

// Prism ids (prism/identity/4, identity/PROTOCOL.md): stitch's Prism id,
// named by the κ of its genesis and held by devices whose keys never leave
// them, with a recovery kit its owner keeps, so losing a device never loses
// the id. The frame keeps this app's session and signs with it; the panels
// module holds this origin's device and runs the sign-in, in the visitor's
// browser. Devices of one id meet on stitch's relay, which the page build
// reads from here into the page's connect-src (with its WebSocket origin).
export const PRISM_RELAY = "https://ntfy.sh";
// Prism accounts (prism/identity/1, identity/PROTOCOL.md). An account is a
// passkey: its private key stays in the device's secure hardware, and the
// account's name is the hash of its public key. The frame keeps the session
// and signs with it; the panels module runs the sign-in and checks every
// signature the sign-in page hands back, in the visitor's browser.
const ACCOUNTS = "https://id.uor.foundation";
const SESSION_DAYS = 7;
const b64u = (bytes) => btoa(String.fromCharCode(...new Uint8Array(bytes))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
// The session, in this app's IndexedDB: the browser key cannot be read out
Expand All @@ -374,11 +373,11 @@ function store(mode, work) {
const accountChannel = { session: null, loaded: null };
function loadSession() {
return (accountChannel.loaded ??= store("readonly", (s) => s.get("current"))
.then((saved) => (accountChannel.session = saved?.delegation?.envelope && saved.expires > Date.now() ? saved : null))
.then((saved) => (accountChannel.session = saved && saved.delegation.expires > Date.now() ? saved : null))
.catch(() => null));
}
// What the account panel, in the panels module, borrows from the frame.
const ACCOUNT_CORE = { SESSION_DAYS, b64u, store, accountChannel, loadSession, PRISM_RELAY };
const ACCOUNT_CORE = { SESSION_DAYS, b64u, store, accountChannel, loadSession };

// Everything the markup needs, from the attributes (get), the page's title
// and its address: one function, for the element and for the shell.
Expand All @@ -401,6 +400,7 @@ function modelOf(get, title, base) {
...starsOf(Number(get("stars"))),
card: get("card") ?? new URL("og.png", url).href,
identity: get("identity") ?? "#identity-title",
accounts: get("accounts") ?? ACCOUNTS,
host: (url.host + url.pathname).replace(/\/$/, ""),
x: `https://x.com/intent/post?${query({ text, url: url.href })}`,
linkedin: `https://www.linkedin.com/sharing/share-offsite/?${query({ url: url.href })}`,
Expand Down Expand Up @@ -448,7 +448,7 @@ export function shell(attributes, base) {
// there is none, to write the shell.
const Element = globalThis.HTMLElement ?? class {};
class PrismFrame extends Element {
static observedAttributes = ["name", "address", "live", "repo", "home", "purpose", "card", "identity", "verdict", "verdict-label", "fingerprint", "proof", "proof-url", "examples", "stars"];
static observedAttributes = ["name", "address", "live", "repo", "home", "purpose", "card", "identity", "verdict", "verdict-label", "fingerprint", "proof", "proof-url", "examples", "stars", "accounts"];

constructor() {
super();
Expand Down Expand Up @@ -831,32 +831,32 @@ class PrismFrame extends Element {
// The visitor's Prism account, for the app: null when signed out.
get account() {
const saved = accountChannel.session;
return saved ? { id: saved.account, key: saved.key, expires: saved.expires } : null;
return saved ? { id: saved.account, key: saved.key, expires: saved.delegation.expires } : null;
}

// Signs bytes with this browser's session key. The delegation proves the
// Prism id let that key act for it here; verifySession checks it.
// account's passkey let that key act for it here; verifySession checks it.
async sign(data) {
const saved = accountChannel.session;
if (!saved || saved.expires <= Date.now()) throw Object.assign(new Error("No one is signed in"), { name: "IdentityError", code: "signed-out" });
if (!saved || saved.delegation.expires <= Date.now()) throw Object.assign(new Error("No one is signed in"), { name: "IdentityError", code: "signed-out" });
const signature = await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, saved.privateKey, data);
return { signature: b64u(signature), delegation: saved.delegation };
}

// The account icon, after full screen: a line drawing signed out, filled
// once signed in. Its panel and the
// The account icon, after full screen: a line drawing signed out, a soft
// pulse while a passkey is asked, filled once signed in. Its panel and the
// sign-in itself come with the panels module (accounts() there), fetched
// when the visitor reaches for the icon, so an app's first load carries
// none of it. Where a Prism id cannot work (no secure context, no
// WebCrypto, no IndexedDB, no popover) the icon is not shown, so it never
// offers what would fail.
// none of it. Where passkeys cannot work (no secure context, no WebAuthn,
// no IndexedDB, no popover) the icon is not shown, so it never offers
// what would fail.
accountPanel() {
const button = this.$("account");
const panel = this.$("account-panel");
this.accountWatch?.abort();
this.accountReady = null;
let wired = false;
if (typeof panel.showPopover !== "function" || !window.isSecureContext || !globalThis.crypto?.subtle || !globalThis.indexedDB) {
if (typeof panel.showPopover !== "function" || !window.isSecureContext || !window.PublicKeyCredential || !globalThis.indexedDB) {
button.hidden = true;
return;
}
Expand Down
24 changes: 10 additions & 14 deletions frame/panels.css
Original file line number Diff line number Diff line change
Expand Up @@ -466,21 +466,17 @@
.account-panel .row { justify-content: flex-start; width: 100%; min-height: 2.618rem; padding: 0 1rem; border: 0; border-radius: var(--radius-control); background: none; color: var(--foreground); font-size: 1rem; text-align: start; cursor: pointer; }
.account-panel .row:hover { background: var(--accent); }
.account-panel .row:focus-visible, .account-panel .text:focus-visible, .account-close:focus-visible { outline: var(--ring-width) solid var(--ring); outline-offset: var(--ring-offset); }
.account-panel .primary { width: 100%; min-height: 2.618rem; font-size: 1rem; }
.account-panel .account-in > p { margin-bottom: 0.618rem; color: var(--muted-foreground); }
.account-panel .account-in > p b { color: var(--foreground); font-weight: 600; }
.account-panel input:not([type="file"]) { width: 100%; min-height: 2.618rem; padding: 0 1rem; border: var(--border-width) solid var(--border); border-radius: var(--radius-control); background: var(--background); color: var(--foreground); font: inherit; font-size: 1rem; }
.account-panel #account-code { margin-top: 0.382rem; font-family: var(--font-mono); letter-spacing: 0.2em; }
.account-panel label { display: grid; color: var(--muted-foreground); }
.account-panel input:focus-visible { outline: var(--ring-width) solid var(--ring); outline-offset: var(--ring-offset); }
.account-code { margin-top: 0.618rem !important; color: var(--foreground); font-size: 1rem; }
.account-devices { display: grid; gap: 0.382rem; margin: 0; padding: 0; list-style: none; }
.account-devices li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 2.618rem; padding: 0 1rem; border: var(--border-width) solid var(--border); border-radius: var(--radius-control); }
.account-devices code { font-family: var(--font-mono); color: var(--muted-foreground); }
.account-error { margin-top: 1rem !important; color: var(--destructive, #c2410c); }
.account-panel.busy > :not(.account-close) { opacity: 0.618; pointer-events: none; }
.account-ceremony:empty { display: none; }
/* The iframe's colour scheme matches the page inside it; a mismatch would
* make the browser paint it an opaque ground over the dialog. */
.account-ceremony iframe { display: block; width: 100%; height: 2.618rem; border: 0; color-scheme: light; }
:host([dark]) .account-ceremony iframe { color-scheme: dark; }
/* Shown only once the sign-in page has answered, so a page that fails to
* load never shows the browser's error page in the dialog. */
.account-ceremony iframe:not(.ready) { visibility: hidden; height: 0 !important; }
#account-window { width: 100%; min-height: 2.618rem; font-size: 1rem; }
@media (pointer: coarse) {
.account-panel .row, .account-panel .primary, .account-panel input:not([type="file"]) { min-height: var(--touch); }
.account-panel .row, #account-window { min-height: var(--touch); }
.account-close { top: 0.618rem; right: 0.618rem; width: var(--touch); height: var(--touch); min-height: var(--touch); }
}
@media (prefers-reduced-transparency: reduce) { .account-panel::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgb(0 0 0 / 0.618); } }
Loading
Loading