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
24 changes: 20 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ call is well formed. (2) The page is the community's portal: every call names
that DID document's first usable `SignInPortal`, resolved and verified as the
trigger-link sign-in does (domain-linked contacts also need their DID
Configuration); host requests go to the same document's `TrustTaskHTTPS`. (3)
The member shared the room with that origin. (4) A write is confirmed.
The member shared the room with that origin. (4) A write is confirmed — the
one exception is a reaction under a live reaction grant (below).

**Rooms are shared by the member, one by one, because nothing else can say
which rooms a community hosts.** A room's DID names no host (deliberately: a
Expand Down Expand Up @@ -1118,7 +1119,19 @@ refuses with `recordMembersNotListed` where it does not list what the write
needs — a reply is never sent without `inReplyTo`, a reaction never as a
message. The confirm window shows the record answered or reacted to **as the
wallet read it** (`rooms/keys/read`, `glimpseOf`), never anything the page
said about it. Each reaction is confirmed like any write: no "remember".
said about it. Each reaction is confirmed like any write, with one bounded,
revocable exception: the reaction prompt offers an **unticked** box, "let this
portal add and remove your reactions in <room> for 30 minutes"
(`REACTION_GRANT_TTL_MS`). Ticking it sets `reactionsUntil` on the share itself
(`withReactionGrant`), so it is keyed exactly as the share is — origin,
community, VTA, room and member — and ends with it (`Stop sharing`, the page's
`forget`, a fresh `choose`, the share lapsing). While `reactionGrantLive`, a
`react`/`unreact` from that origin for that room runs with no window; gates 1–3,
the value checks and `recordMembersNotListed` still apply. It is never extended
by use, never set by anything but that box on an approval (`deliverConsentResult`
passes it only with `approved`, and `requestRoomConsent` only from a prompt that
offered it), and the console's Communities tab lists it with the minutes left
and a Stop. Messages, notes and files are always confirmed.

**A page learns a shared room moved over a port, never a broadcast.**
`rooms.watch` opens one `ROOM_WATCH_PAGE_PORT` per watch (the content script
Expand Down Expand Up @@ -1230,7 +1243,8 @@ signed in.

**Reads ride the share; every write is confirmed**, in a window naming the
room, the persona that will sign and what will be written (title and excerpt,
or file name and size), with no "remember". A file's bytes reach the page only
or file name and size), with no "remember" — except the bounded, revocable
reaction grant (≤30 min, one room, reactions only). A file's bytes reach the page only
after the whole file verified against its author's digest: the background holds
the offscreen document's provisional pieces and releases them on `got`, and
drops them on anything else.
Expand All @@ -1239,7 +1253,9 @@ drops them on anything else.
DID document, or comparing origins loosely; letting a page name a room's host
for a room it was not shared; passing a VTA or host reply to the page as is
(views are built member by member); a share prompt that the page can
pre-approve, or a write with a "remember" box; posting a provisional download
pre-approve, or a write with a "remember" box (the reaction grant is the one
exception, and widening it — beyond reactions, beyond one room, beyond 30
minutes, or renewing it without a fresh confirm's box — breaks it too); posting a provisional download
byte; offering a room as the community's own DID, or as any identity the
member does not use at that community; sending a room request for a page or a
console row without naming its member (the VTA refuses, and it must); keying a
Expand Down
20 changes: 16 additions & 4 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,21 +869,33 @@ void refreshPendingBadge();
/** Raise a room prompt (share, write or accept an offer) and wait. Closed or unopened is a denial. */
async function requestRoomConsent(
view: RoomShareConsentView | RoomWriteConsentView | RoomOfferConsentView,
): Promise<{ approved: boolean; selectedRooms?: string[] }> {
): Promise<{ approved: boolean; selectedRooms?: string[]; reactionGrant?: boolean }> {
const consentId = crypto.randomUUID();
await chrome.storage.session.set({ [`${ROOM_CONSENT_PREFIX}${consentId}`]: view });
// A reaction grant is honoured only from a prompt that offered one.
const offersGrant = view.kind === "write" && "reaction" in view.what && view.what.grant !== undefined;
const url = `${chrome.runtime.getURL("confirm.html")}?cid=${consentId}&kind=room`;
const bounds = await consentWindowBounds(view.kind === "share" ? 640 : 560);
return new Promise((resolve) => {
let settled = false;
const settle = (approved: boolean, selectedRooms?: string[]) => {
const settle = (approved: boolean, selectedRooms?: string[], reactionGrant?: boolean) => {
if (settled) return;
settled = true;
pendingConsents.delete(consentId);
void chrome.storage.session.remove(`${ROOM_CONSENT_PREFIX}${consentId}`);
resolve(approved ? { approved: true, ...(selectedRooms ? { selectedRooms } : {}) } : { approved: false });
resolve(
approved
? {
approved: true,
...(selectedRooms ? { selectedRooms } : {}),
...(offersGrant && reactionGrant === true ? { reactionGrant: true } : {}),
}
: { approved: false },
);
};
pendingConsents.set(consentId, (approved, _remember, _prf, _did, selectedRooms) => settle(approved, selectedRooms));
pendingConsents.set(consentId, (approved, _remember, _prf, _did, selectedRooms, _credential, _ballot, reactionGrant) =>
settle(approved, selectedRooms, reactionGrant),
);
openConsentWindow({ url, bounds, deny: () => settle(false), tag: "[pnm rooms]", what: "room window" });
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/extension/src/bridge-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ export interface RuntimeConsentResult {
* window (`voting/ballot/cast` `Ballot`). Checked again by the background
* against the election before anything is built. Ignored on a denial. */
ballot?: unknown;
/** Reaction prompt only: the member ticked "let this portal add and remove
* your reactions in this room for 30 minutes". Ignored on a denial, and on
* any prompt that did not offer it. */
reactionGrant?: boolean;
}

/** confirm popup → background: resolve + verify an RP DID. */
Expand Down
9 changes: 7 additions & 2 deletions packages/extension/src/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,13 @@ if (root) {
) : isRoomConsent ? (
<RoomConsent
consentId={consentId}
decide={(ok, rooms) =>
void sendConsentResult({ approved: ok, remember: false, ...(ok && rooms ? { selectedRooms: rooms } : {}) })
decide={(ok, rooms, reactionGrant) =>
void sendConsentResult({
approved: ok,
remember: false,
...(ok && rooms ? { selectedRooms: rooms } : {}),
...(ok && reactionGrant === true ? { reactionGrant: true } : {}),
})
}
/>
) : isStepUpApproverConsent ? (
Expand Down
14 changes: 13 additions & 1 deletion packages/extension/src/consent-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ConsentDecision = (
selectedRooms?: string[],
selectedCredential?: string,
ballot?: unknown,
reactionGrant?: boolean,
) => void;

/** The subset of `chrome.windows` this file drives — narrow so a test can
Expand Down Expand Up @@ -164,6 +165,7 @@ export function deliverConsentResult(
selectedRooms?: string[];
selectedCredential?: string;
ballot?: unknown;
reactionGrant?: boolean;
},
): boolean {
const decision = pending.get(result.consentId);
Expand All @@ -176,6 +178,16 @@ export function deliverConsentResult(
// against the election by the gate that asked for it.
const ballot =
result.ballot !== null && typeof result.ballot === "object" && !Array.isArray(result.ballot) ? result.ballot : undefined;
decision(result.approved, !!result.remember, result.prfOutputB64u, result.selectedDid, rooms, credential, ballot);
// Only an explicit `true` from the reaction prompt's own box grants anything.
decision(
result.approved,
!!result.remember,
result.prfOutputB64u,
result.selectedDid,
rooms,
credential,
ballot,
result.approved && result.reactionGrant === true,
);
return true;
}
47 changes: 37 additions & 10 deletions packages/extension/src/manager/panes/rooms-communities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
// share stops the portal reading the room at once and cannot recall what it was
// already shown.

import type { ReactNode } from "react";
import type { CSSProperties, ReactNode } from "react";
import type { RoomProfileView } from "@openvtc/pnm-core/rooms";
import { displayAgentName, type AgentName } from "../../agent-name.js";
import { didHost } from "../../did-display.js";
import { isActionable, type OfferView } from "../../room-offers-policy.js";
import { reactionGrantLive } from "../../room-page-policy.js";
import { Button, Did, Note, Pill } from "../../ui.js";
import { c, t } from "../../theme.js";
import { communityLanes, joinedOpen, rowStage, type Lane, type LaneRow } from "../community-lanes.js";
Expand Down Expand Up @@ -197,6 +198,22 @@ const WEBSITE_HINT =
"The community's member site can list and read this room while you are signed in there. " +
"Anything it asks to write is still confirmed in the wallet's own window.";

const linkButton: CSSProperties = {
font: "inherit",
fontSize: t.xs,
fontWeight: 600,
padding: 0,
border: "none",
background: "transparent",
color: c.danger,
cursor: "pointer",
};

/** Whole minutes left until `until`, at least 1 while it is live. */
export function minutesLeft(until: number, now: number): number {
return Math.max(1, Math.ceil((until - now) / 60_000));
}

function websiteStep(row: LaneRow, shares: RoomSharesState): Step {
if (row.shares.length === 0) {
return { label: "On its website", hint: WEBSITE_HINT, state: "todo", lines: ["not shared"] };
Expand All @@ -205,15 +222,25 @@ function websiteStep(row: LaneRow, shares: RoomSharesState): Step {
label: "On its website",
hint: WEBSITE_HINT,
state: "done",
lines: row.shares.flatMap((s: ShareRow) => [
`${host(s.grant.origin)} · until ${new Date(s.grant.expiresAt).toLocaleDateString()}`,
<button
onClick={() => void shares.revoke(s)}
style={{ font: "inherit", fontSize: t.xs, fontWeight: 600, padding: 0, border: "none", background: "transparent", color: c.danger, cursor: "pointer" }}
>
Stop sharing
</button>,
]),
lines: row.shares.flatMap((s: ShareRow) => {
const reactions = reactionGrantLive(s.grant, Date.now())
? [
<span>
Reacts without asking for {minutesLeft(s.grant.reactionsUntil!, Date.now())} more min ·{" "}
<button onClick={() => void shares.stopReactions(s)} style={linkButton}>
Stop
</button>
</span>,
]
: [];
return [
`${host(s.grant.origin)} · until ${new Date(s.grant.expiresAt).toLocaleDateString()}`,
...reactions,
<button onClick={() => void shares.revoke(s)} style={linkButton}>
Stop sharing
</button>,
];
}),
};
}

Expand Down
20 changes: 17 additions & 3 deletions packages/extension/src/manager/panes/rooms-shares.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
// asks (`window.vtaWallet.rooms.choose`), and lasts 30 days. This reads every
// live one and revokes any of them; `rooms-communities.tsx` draws each beside
// the room it shares. Revoking stops the page reading the room at once; it
// cannot recall what the page was already shown.
// cannot recall what the page was already shown. A share may carry a reaction
// grant (`reactionsUntil`, at most 30 minutes): listed with its time left and
// stopped on its own, and gone with the share.

import { useCallback, useEffect, useState } from "react";

import { ROOM_GRANTS_PREFIX, type RoomGrant } from "../../room-page-policy.js";
import { ROOM_GRANTS_PREFIX, withoutReactionGrant, type RoomGrant } from "../../room-page-policy.js";

/** One live share, and the storage key it sits under. */
export interface ShareRow {
Expand All @@ -20,6 +22,8 @@ export interface RoomSharesState {
/** `null` while reading. */
shares: ShareRow[] | null;
revoke: (row: ShareRow) => Promise<void>;
/** Stop the share's reaction grant, keeping the share. */
stopReactions: (row: ShareRow) => Promise<void>;
}

async function readLive(now: number): Promise<ShareRow[]> {
Expand Down Expand Up @@ -56,5 +60,15 @@ export function useRoomShares(): RoomSharesState {
[load],
);

return { shares, revoke };
const stopReactions = useCallback(
async ({ key, grant }: ShareRow) => {
const current = (await chrome.storage.local.get(key))[key];
const next = withoutReactionGrant(Array.isArray(current) ? (current as RoomGrant[]) : [], grant, grant.roomId);
await chrome.storage.local.set({ [key]: next });
await load();
},
[load],
);

return { shares, revoke, stopReactions };
}
70 changes: 48 additions & 22 deletions packages/extension/src/room-consent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
// is shared here afterwards. A page cannot see this list, only what it is
// given.
// - **Write**: one note or one file, in one room, signed as the member. The
// prompt says what will be written, and there is no "remember".
// prompt says what will be written, and there is no "remember" — except on a
// reaction, which may offer one bounded, revocable grant: this portal may add
// and take back the member's reactions in this one room for 30 minutes.

import { useEffect, useState } from "react";
import { useEffect, useId, useState } from "react";

import { requestOriginPermission } from "./host-permissions.js";
import {
Expand Down Expand Up @@ -86,7 +88,7 @@ export function RoomConsent({
decide,
}: {
consentId: string;
decide: (approved: boolean, selectedRooms?: string[]) => void;
decide: (approved: boolean, selectedRooms?: string[], reactionGrant?: boolean) => void;
}) {
const [view, setView] = useState<RoomShareConsentView | RoomWriteConsentView | RoomOfferConsentView | null>(null);
useEffect(() => {
Expand All @@ -104,7 +106,7 @@ export function RoomConsent({
) : view.kind === "offer" ? (
<OfferConsent view={view} decide={decide} />
) : (
<Write view={view} decide={decide} />
<Write view={view} decide={(ok, reactionGrant) => decide(ok, undefined, reactionGrant)} />
)}
</div>
);
Expand Down Expand Up @@ -232,7 +234,13 @@ function Glimpse({ of }: { of: RecordGlimpse }) {
);
}

function Write({ view, decide }: { view: RoomWriteConsentView; decide: (approved: boolean) => void }) {
function Write({
view,
decide,
}: {
view: RoomWriteConsentView;
decide: (approved: boolean, reactionGrant?: boolean) => void;
}) {
if ("reaction" in view.what) return <React view={view} what={view.what} decide={decide} />;
const isFile = "file" in view.what;
const isMessage = "message" in view.what;
Expand Down Expand Up @@ -315,39 +323,57 @@ function Write({ view, decide }: { view: RoomWriteConsentView; decide: (approved
);
}

/** A reaction, or taking one back: short, since it is one value on one record. */
/**
* A reaction, or taking one back: compact, since it is one value on one record.
* Where the background offers it, one unticked box lets this portal add and take
* back the member's reactions in this one room for a bounded time — never
* messages, notes or files, never another room, never renewed without this box.
*/
function React({
view,
what,
decide,
}: {
view: RoomWriteConsentView;
what: Extract<RoomWriteConsentView["what"], { reaction: true }>;
decide: (approved: boolean) => void;
decide: (approved: boolean, reactionGrant?: boolean) => void;
}) {
const [grant, setGrant] = useState(false);
const boxId = useId();
const room = what.grant?.roomLabel ? `“${what.grant.roomLabel}”` : "this room";
return (
<>
<strong style={{ fontSize: 14 }}>
{what.withdraw ? "Take back your reaction" : "React"} <span style={{ fontSize: 18 }}>{what.value}</span>{" "}
{what.withdraw ? "from" : "to"} this, as you?
<strong style={{ fontSize: 14, display: "flex", alignItems: "center", gap: 8 }}>
<span style={{ fontSize: 22 }} aria-hidden="true">
{what.value}
</span>
<span>
{what.withdraw ? "Take back your reaction" : `React ${what.value}`} as you?
</span>
</strong>
<div style={{ color: "var(--w-muted)", lineHeight: 1.45 }}>
{originHost(view.origin)} asks to {what.withdraw ? "take back a reaction you made" : "add a reaction"} in a room,
signed as you. Every member of the room will see it as yours.
{view.visibility === "open" ? " This room is open: its host can see it too." : ""}
</div>
<Glimpse of={what.on} />
<div>
<div style={label}>Signed as</div>
<div style={card}>
<Did value={view.member} />
</div>
<div style={{ color: "var(--w-muted)", lineHeight: 1.45, fontSize: 12 }}>
Asked by {originHost(view.origin)}. Every member of the room sees it as yours, signed as{" "}
<Did value={view.member} />.
{view.visibility === "open" ? " This room is open: its host can see it too." : ""}
</div>
<div style={buttons}>
{what.grant && (
<label htmlFor={boxId} style={{ display: "flex", gap: 8, alignItems: "flex-start", ...card }}>
<input id={boxId} type="checkbox" checked={grant} onChange={(e) => setGrant(e.target.checked)} />
<span style={{ lineHeight: 1.4 }}>
Let {originHost(view.origin)} add and remove your reactions in {room} for {what.grant.minutes} minutes
without asking.
<span style={{ display: "block", fontSize: 11, color: "var(--w-muted)" }}>
Reactions only — messages, notes and files are always asked. Stop it any time from Communities.
</span>
</span>
</label>
)}
<div style={{ ...buttons, marginTop: 4 }}>
<button autoFocus onClick={() => decide(false)} style={{ padding: "8px 16px", fontSize: 13 }}>
Deny
</button>
<Primary onClick={() => decide(true)}>{what.withdraw ? "Take back" : "React"}</Primary>
<Primary onClick={() => decide(true, what.grant ? grant : undefined)}>{what.withdraw ? "Take back" : "React"}</Primary>
</div>
</>
);
Expand Down
Loading