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
1 change: 1 addition & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ model does not sanction.
| `FR-02` | `build` | A returning browser whose worker kept an earlier deploy serves this deploy from the navigation that brings its page |
| `FR-03` | `build` | A first visit's bytes are counted once the page has started, the frame's and the app's each within its own budget |
| `FR-04` | `build` | An app's workspace key opens only on a device of the Prism ID that made it, follows the ID when it joins or is recovered, and stays locked on a removed device |
| `FR-05` | `build` | An app's pages on every device of one Prism ID meet on a relay topic only those devices derive, per app, with every message sealed to the ID, and a removed device is left behind |

## Cited authorities

Expand Down
22 changes: 22 additions & 0 deletions TEMPLATE-VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,28 @@ The template's ratchet held: the three popovers in `frame/panels.css` now share
one surface and title rule, and the panel's relay messages parse in one place,
so this change shrinks the counted lines.

## An app on every device of the ID (FR-05)

An app's pages on the visitor's devices find each other with
`frame.appChannel(listen)`: `send(value)` reaches them and `listen(value)`
hears them. They meet on a relay topic, `prism-app:` and an HMAC under the
ID's current private boundary key of the app's origin (`appTopic`), so only
devices of the ID derive it, and each app has its own. Every message is
sealed with `sealPrivate`; one that does not open is dropped. A removal
rotates the key, so the remaining devices move to a topic the removed device
cannot derive. Foundry uses it to bring two devices' sealed work together.

`frame_fr_05` runs `appTopic` and the sealing in Node with FR-04's linked
devices; `npm run test:identity` has two pages of one app hear each other.

| Gate | Planted defect | Result |
| --- | --- | --- |
| `npm run test:identity`, "an app's pages hear each other on the id's channel, sealed (FR-05)" | `send` publishes the value unsealed (`json(value)`) | rejected: `not ok 4`, `page.waitForFunction: Timeout 10000ms exceeded`; restored, 17 of 17 pass |

The ratchet: the bar's three panels share one placement (`placeUnder`), and
elements made with several properties are made with `Object.assign`, so the
counted lines shrink.

## The workspace page

The standard page became the workspace: a header row, the app's surface
Expand Down
21 changes: 19 additions & 2 deletions crates/conformance/tests/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ fn frame_fr_04() {
node("FR-04", &["--input-type=module", "-e", WORKSPACE]);
}

/// `FR-05`: An app's pages on every device of one Prism ID meet on a relay topic only those devices derive, per app, with every message sealed to the ID, and a removed device is left behind
///
/// The same Node run as FR-04, whose linked devices it uses; two pages of one app in Chromium in
/// `identity/test.mjs`.
#[test]
fn frame_fr_05() {
node("FR-05", &["--input-type=module", "-e", WORKSPACE]);
}

const WORKSPACE: &str = r#"
import assert from "node:assert/strict";
import * as Prism from "./identity/prism-id.mjs";
import { carryWorkspace, openWorkspace } from "./frame/panels.mjs";
import { appTopic, carryWorkspace, openWorkspace } from "./frame/panels.mjs";
const id = await Prism.createPrism();
const made = await openWorkspace(Prism, id, null);
assert.equal(made.key.length, 32);
Expand All @@ -69,7 +78,15 @@ const offer = Prism.parseLinkUri(uri);
const device = await Prism.createDevice();
const accepted = await Prism.acceptLinkRequest(id, pending, await Prism.requestLink(device, offer), { now: Date.now(), confirmCode: await Prism.linkCode(offer.secret, device.record) });
const second = await Prism.completeLink(device, offer, accepted.response);
const rotated = await openWorkspace(Prism, await Prism.revokeDevice(accepted.session, second.device.id), made.record);
const app = "https://app.example", topic = await appTopic(Prism, accepted.session, app);
assert.match(topic, /^prism-app:[0-9a-f]{64}$/);
assert.equal(await appTopic(Prism, second, app), topic, "FR-05: the id's two devices meet");
assert.notEqual(await appTopic(Prism, accepted.session, "https://other.example"), topic, "FR-05: one topic per app");
assert.notEqual(await appTopic(Prism, other, app), topic, "FR-05: another id meets elsewhere");
assert.deepEqual(await Prism.openPrivate(second, (await Prism.sealPrivate(accepted.session, { offer: 1 })).sealed), { offer: 1 });
const kept = await Prism.revokeDevice(accepted.session, second.device.id);
assert.notEqual(await appTopic(Prism, kept, app), await appTopic(Prism, second, app), "FR-05: a removed device is left behind");
const rotated = await openWorkspace(Prism, kept, made.record);
assert.deepEqual(rotated.key, made.key);
await assert.rejects(openWorkspace(Prism, second, rotated.record));
"#;
10 changes: 10 additions & 0 deletions features/suites/frame.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ Feature: frame
And another ID is refused as removed, and asking for a new key replaces the one it cannot open
And joining or recovering an ID reseals the key for that ID in the same write that keeps the device
And after a rotation a member device reseals the key under the new boundary key, which the removed device cannot open

@FR-05 @build
Scenario: An app's pages on every device of one Prism ID meet on a relay topic only those devices derive, per app, with every message sealed to the ID, and a removed device is left behind
Given a Prism ID with two linked devices, another ID, and the frame's appTopic and appChannel
When each derives the topic for an app, for another app, and after one device was removed
Then the ID's two devices derive one topic for the app, another app and another ID derive others
And a message one device seals under the ID's private boundary key opens on the other
And once a removal rotates the key, the remaining device moves to a topic the removed one cannot derive
And an app's two pages hear each other through appChannel, and a message that is not sealed is never heard

10 changes: 5 additions & 5 deletions frame.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@
},
{
"path": "frame/frame.mjs",
"sha256": "e9c02c8355cf3fb6dea3801e7ea5fa84adab0a117198ed39418ce3ea83930156"
"sha256": "742ac476182099bcc4d93b142fdbd89ba2ce28085a24ab199d23a8f9698b2018"
},
{
"path": "frame/panels.css",
"sha256": "c6faa6a4ddf50444ca887a60e18530390ed52adf38a9d69fb257d3ed7254eb7d"
},
{
"path": "frame/panels.mjs",
"sha256": "4eb0dea50cd91a1dce08a459b80b96a5c34d89eec85fedfdf168c5644f7b92a9"
"sha256": "d818b1d511508ff46ad57224779aae00323309dc6aba766a61ecbfbe8f6dfdef"
},
{
"path": "frame/publish.mjs",
Expand All @@ -147,7 +147,7 @@
},
{
"path": "identity/PROTOCOL.md",
"sha256": "a66215423f8bf70ffbb52e2d9a96f04cb8baa922d2c5adf999be14a491dc382b"
"sha256": "b3a7e40635ea891aca2c3f228e01dfc816acc2531c0c1db7e4fdc445e942c9bd"
},
{
"path": "identity/README.md",
Expand All @@ -171,15 +171,15 @@
},
{
"path": "identity/test.mjs",
"sha256": "fd771e403d0391846fe8e666c2026d01026d47c78de709ac21171b82737f1cf1"
"sha256": "025f65e9749339cf8c9eb0d137dcf8014b0ba246e2c23eeb8b49b83b186c37b9"
},
{
"path": "lighthouserc.json",
"sha256": "85aa0f6219cb8396b34f5b461c1d4d7b149e4cc1674cbd2f0100c5b5e16636d9"
},
{
"path": "site/app.mjs",
"sha256": "65a3d1e3fcc6ed9ddfcbf85477c99a41a94a98502e62de90e7dcce3f860b0ace"
"sha256": "f3ede2982b85be162918bd4e40c67af9bd0a3fa9c4bfc8b50df3b8008d114765"
},
{
"path": "site/guest-worker.mjs",
Expand Down
88 changes: 37 additions & 51 deletions frame/frame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,15 @@ function speculate(href) {
speculation.box.prepend(held);
return;
}
const link = document.createElement("a");
link.href = url.href;
link.tabIndex = -1;
const link = Object.assign(document.createElement("a"), { href: url.href, tabIndex: -1 });
link.dataset.prismAhead = "";
speculation.box.prepend(link);
while (speculation.box.children.length > 3) speculation.box.lastElementChild.remove();
return;
}
if (url.origin !== location.origin || speculation.prefetched.has(url.href)) return;
speculation.prefetched.add(url.href);
const link = document.createElement("link");
link.rel = "prefetch";
link.href = url.href;
const link = Object.assign(document.createElement("link"), { rel: "prefetch", href: url.href });
document.head.append(link);
}

Expand Down Expand Up @@ -449,6 +445,19 @@ export function shell(attributes, base) {

// The element runs in a browser; the module also loads at build time, where
// there is none, to write the shell.
// A bar panel opens under its button, `rem` wide at most, `gap` below the bar,
// and never closer than 16 px to either side of the window: on the left, a
// little before the button's centre; on the right, edge to edge with it.
function placeUnder(frame, button, panel, name, rem, gap, side) {
const bar = frame.shadowRoot.querySelector(".bar").getBoundingClientRect();
const edge = button.getBoundingClientRect();
const view = document.documentElement.clientWidth;
const width = Math.min(rem * parseFloat(getComputedStyle(document.documentElement).fontSize), view - 32);
const at = side === "left" ? edge.left + edge.width / 2 - 24 : view - edge.right;
panel.style.setProperty(`--${name}-top`, `${Math.round(bar.bottom + gap)}px`);
panel.style.setProperty(`--${name}-${side}`, `${Math.round(Math.max(16, Math.min(at, view - width - 16)))}px`);
}

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"];
Expand Down Expand Up @@ -610,13 +619,7 @@ class PrismFrame extends Element {
}
panel.addEventListener("beforetoggle", (event) => {
if (event.newState !== "open") return;
const bar = frame.shadowRoot.querySelector(".bar").getBoundingClientRect();
const edge = button.getBoundingClientRect();
const view = document.documentElement.clientWidth;
const width = Math.min(22 * parseFloat(getComputedStyle(document.documentElement).fontSize), view - 32);
const left = Math.max(16, Math.min(edge.left + edge.width / 2 - 24, view - width - 16));
panel.style.setProperty("--trust-top", `${Math.round(bar.bottom + 6)}px`);
panel.style.setProperty("--trust-left", `${Math.round(left)}px`);
placeUnder(frame, button, panel, "trust", 22, 6, "left");
});
frame.$("trust-copy").addEventListener("click", async () => {
const copy = frame.$("trust-copy");
Expand Down Expand Up @@ -791,13 +794,7 @@ class PrismFrame extends Element {
}, () => {});
return;
}
const bar = frame.shadowRoot.querySelector(".bar").getBoundingClientRect();
const edge = button.getBoundingClientRect();
const view = document.documentElement.clientWidth;
const width = Math.min(20 * parseFloat(getComputedStyle(document.documentElement).fontSize), view - 32);
const right = Math.max(16, Math.min(view - edge.right, view - width - 16));
panel.style.setProperty("--theme-top", `${Math.round(bar.bottom + 6)}px`);
panel.style.setProperty("--theme-right", `${Math.round(right)}px`);
placeUnder(frame, button, panel, "theme", 20, 6, "right");
ui.open();
});
}
Expand Down Expand Up @@ -848,11 +845,20 @@ class PrismFrame extends Element {
return { signature: b64u(signature), delegation: saved.delegation };
}

// This app's workspace key: 32 bytes only a device of the visitor's Prism
// id opens (panels.mjs, openWorkspace). { replace: true } starts a new one.
workspaceKey(options) {
// What the account in the panels module (panels.mjs) gives this app: its
// workspace key, 32 bytes only a device of the visitor's Prism ID opens
// (openWorkspace; { replace: true } starts a new one), and this app on the
// visitor's other devices, where send(value) reaches them and listen(value)
// hears them, sealed to the Prism ID (appTopic).
viaAccount(work) {
if (!this.accountsReady) return Promise.reject(Object.assign(new Error("A Prism ID cannot work here"), { name: "IdentityError", code: "unsupported" }));
return this.accountsReady().then((accounts) => accounts.workspace(options));
return this.accountsReady().then(work);
}
workspaceKey(options) {
return this.viaAccount((accounts) => accounts.workspace(options));
}
appChannel(listen) {
return this.viaAccount((accounts) => accounts.channel(listen));
}

// The Prism id icon, after full screen: a line drawing until the id is
Expand Down Expand Up @@ -1013,19 +1019,10 @@ class PrismFrame extends Element {
// and never closer than 16 px to either side of the window.
panel.addEventListener("beforetoggle", (event) => {
if (event.newState !== "open") return;
const bar = frame.shadowRoot.querySelector(".bar").getBoundingClientRect();
const edge = button.getBoundingClientRect();
const view = document.documentElement.clientWidth;
const width = Math.min(23 * parseFloat(getComputedStyle(document.documentElement).fontSize), view - 32);
const right = Math.max(16, Math.min(view - edge.right, view - width - 16));
panel.style.setProperty("--share-top", `${Math.round(bar.bottom + 8)}px`);
panel.style.setProperty("--share-right", `${Math.round(right)}px`);
placeUnder(frame, button, panel, "share", 23, 8, "right");
// The card is fetched the first time the panel opens, never with the page.
if (!frame.$("share-image").firstChild) {
const image = new Image(1200, 630);
image.src = card;
image.alt = "";
image.decoding = "async";
const image = Object.assign(new Image(1200, 630), { src: card, alt: "", decoding: "async" });
frame.$("share-image").append(image);
}
});
Expand Down Expand Up @@ -1211,9 +1208,7 @@ class PrismFrame extends Element {
// A tile: the name's first letter on a hue taken from the fingerprint, so
// an app keeps its colour wherever it is listed.
const tile = (row) => {
const span = document.createElement("span");
span.className = "opt-tile";
span.textContent = (row.title.match(/[\p{L}\p{N}]/u)?.[0] ?? "?").toUpperCase();
const span = Object.assign(document.createElement("span"), { className: "opt-tile", textContent: (row.title.match(/[\p{L}\p{N}]/u)?.[0] ?? "?").toUpperCase() });
const seed = /^[0-9a-f]{4}/i.test(row.print) ? parseInt(row.print.slice(0, 4), 16) : [...row.title].reduce((sum, c) => sum * 31 + c.codePointAt(0), 7);
span.style.setProperty("--tile-hue", String(Math.abs(seed) % 360));
return span;
Expand All @@ -1229,9 +1224,7 @@ class PrismFrame extends Element {
box.append(tile(row));
return box;
}
const image = new Image(24, 24);
image.alt = "";
image.decoding = "async";
const image = Object.assign(new Image(24, 24), { alt: "", decoding: "async" });
image.addEventListener("error", () => image.replaceWith(tile(row)), { once: true });
image.src = row.icon;
box.append(image);
Expand All @@ -1258,24 +1251,17 @@ class PrismFrame extends Element {
rows = suggest(input.value);
active = Math.min(active, Math.max(rows.length - 1, 0));
const items = rows.map((row, i) => {
const li = document.createElement("li");
li.id = `omnibox-${i}`;
li.className = `opt opt-${row.kind}`;
const li = Object.assign(document.createElement("li"), { id: `omnibox-${i}`, className: `opt opt-${row.kind}` });
li.setAttribute("role", "option");
li.setAttribute("aria-selected", String(i === active));
const sub = document.createElement("span");
sub.className = "opt-sub";
sub.textContent = row.sub;
const sub = Object.assign(document.createElement("span"), { className: "opt-sub", textContent: row.sub });
const fill = document.createElement("span");
fill.className = "opt-fill";
li.append(iconFor(row), title(row.title, row.match), sub, fill);
// Who keeps it on GitHub, and its stars, 0 included, so the column lines up.
const owner = row.repo ? row.repo.split("/")[0] : "";
if (owner) {
const by = document.createElement("span");
by.className = "opt-owner";
by.textContent = owner;
by.title = `github.com/${row.repo}`;
const by = Object.assign(document.createElement("span"), { className: "opt-owner", textContent: owner, title: `github.com/${row.repo}` });
li.append(by);
const stars = document.createElement("span");
stars.className = "opt-stars";
Expand Down
Loading
Loading