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
37 changes: 35 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ Someone acting for the person with a key they delegated — their assistant over
`vtc-mcp`, say — can redeem a VTC step-up but never make one. The community
refuses it with a single-use handle beside the inline request, and the
assistant shows the person a `step-up` link. The person pastes it into the
popup (`OpenStepUpLink`, `RUNTIME_STEP_UP_LINK`, extension pages only) or
popup (`OpenPastedLink`, `RUNTIME_PASTED_LINK`, extension pages only) or
clicks it on a page (`handleTriggerLink` routes `step-up` away from the
sign-in window). `background.ts::runStepUpLink` drives it:

Expand All @@ -1944,10 +1944,43 @@ The outcome is a notification, since the popup closes when the prompt opens.
**What breaks it:** showing anything from the link or the link's producer as
what is being approved; reading a step-up for a community not in the records;
skipping the binding recompute; answering through anything but the
community's own endpoint; or letting a page send `RUNTIME_STEP_UP_LINK`.
community's own endpoint; or letting a page send `RUNTIME_PASTED_LINK`.
`core/tests/vtc.step-up-handoff.mjs` and `extension/tests/step-up-flows.test.mts`
pin these.

## A pasted sign-in code: the assistant's key, the person's number (VTI-LNK-105 – 107)

An assistant over `vtc-mcp` signs its own key in as the person with
`vtc_sign_in`: it opens an `auth/oob` request and hands the person a
`sign-in` link. It has no page on the community's portal, so the link can
never be clicked there, and a click anywhere else is `wrong-origin`. The
popup's paste box (`OpenPastedLink`, `RUNTIME_PASTED_LINK`) therefore takes a
`sign-in` link as well as a `step-up` one, and `openPastedSignIn` opens the
sign-in window with a flow record carrying **`pasted: true` and no origin**.

VTI-LNK-105 binds a reader that *recorded* an activation origin; a paste has
none, which is the footing of a code scanned with a camera. What stands in for
the page is what the spec gives a scan:

- **Nothing is skipped.** The confirm screen is shown even for one identity,
with a note that the code was pasted (`pasted` on the `confirm` result):
there was no click on the portal to take as the go-ahead (VTI-LNK-106).
- **The person types the number.** The flow never waits for, or takes, a
page's number (`pageNumber` drops it; `handleTriggerLinkNumber` skips a
pasted record), so the number the assistant shows is entered by hand and
checked by the community (VTI-LNK-107).
- **Only a community already in the records.** A pasted code for a site the
wallet does not know is `not-member`: joining and adopting a DID host start
on the site's own page, where the origin can be checked.
- **No origin is pinned** for a pasted sign-in (`pinSignInOrigin`).

**What breaks it:** inferring "pasted" from a missing `origin` (a click whose
origin went missing must stay `wrong-origin` — `pasted` is an explicit flag
set only by the popup path); letting a pasted flow auto-continue or read a
page number; offering a join from a pasted code; or letting a page send
`RUNTIME_PASTED_LINK`. `extension/tests/sign-in-flows.test.mts` and
`sign-in-view.render.test.mts` pin these.

## Repo mechanics worth knowing before you start

- **Task modules are generated here, from `packages/core/trust-tasks.lock`.**
Expand Down
64 changes: 48 additions & 16 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ import { parseTriggerLink, outcomeOf, triggerLinkMessage } from "@openvtc/pnm-co
import { isTriggerLinkShaped } from "./trigger-link-click.js";
import type { StepUpReadResult, StepUpAnswerResult } from "./step-up-flows.js";
import {
RUNTIME_STEP_UP_LINK,
RUNTIME_PASTED_LINK,
OFFSCREEN_STEP_UP_FLOW,
type RuntimeStepUpLinkRequest,
type RuntimePastedLinkRequest,
type RuntimeStepUpLinkResponse,
type OffscreenStepUpFlowOp,
type OffscreenStepUpFlowResponse,
Expand Down Expand Up @@ -3757,7 +3757,10 @@ const SIGN_IN_FLOW_PREFIX = "sign-in-flow:";

interface SignInFlowRecord {
link: string;
origin: string;
/** The browser-attested origin of the page the code was clicked on. Absent
* only for a pasted code, which says so with `pasted`. */
origin?: string;
pasted?: true;
intent?: "join";
}

Expand All @@ -3782,12 +3785,26 @@ async function handleTriggerLink(msg: RuntimeTriggerLinkRequest, tabId: number |
void runStepUpLink(link).then(notifyStepUpOutcome);
return;
}
const flowId = crypto.randomUUID();
const record: SignInFlowRecord = {
await openSignInWindow({
link: msg.link,
origin: msg.origin,
...(msg.intent === "join" ? { intent: "join" as const } : {}),
};
});
}

/**
* A `sign-in` code the person pasted into the popup. There is no page, so no
* origin is recorded and the flow is told it was pasted (`sign-in-flows.ts`):
* a community already in the wallet's records only, no screen skipped, the
* number typed by the person. This is how the key of an assistant that has no
* page on the portal (`vtc-mcp`'s `vtc_sign_in`) is signed in.
*/
async function openPastedSignIn(link: string): Promise<void> {
await openSignInWindow({ link, pasted: true });
}

async function openSignInWindow(record: SignInFlowRecord): Promise<void> {
const flowId = crypto.randomUUID();
await chrome.storage.session.set({ [`${SIGN_IN_FLOW_PREFIX}${flowId}`]: record });
const url = `${chrome.runtime.getURL("confirm.html")}?kind=sign-in&flow=${flowId}`;
const bounds = await consentWindowBounds(660, 560);
Expand Down Expand Up @@ -3942,7 +3959,8 @@ async function handleTriggerLinkNumber(msg: RuntimeTriggerLinkNumberRequest): Pr
for (const [key, value] of Object.entries(all)) {
if (!key.startsWith(SIGN_IN_FLOW_PREFIX)) continue;
const record = value as SignInFlowRecord;
if (record.origin !== msg.origin) continue;
// A pasted code was shown on no page.
if (record.pasted || record.origin === undefined || record.origin !== msg.origin) continue;
// Expiry is the flow's to judge; only the id is read here.
const parsed = parseTriggerLink(record.link, { now: 0 });
if (!parsed.ok || parsed.link.id !== msg.requestId) continue;
Expand Down Expand Up @@ -4016,8 +4034,9 @@ async function handleSignInStep(msg: RuntimeSignInStepRequest): Promise<RuntimeS
...(msg.step === "prepare"
? {
link: record.link,
origin: record.origin,
...(await signInPinnedDid(record.origin)),
...(record.pasted
? { pasted: true as const }
: { origin: record.origin, ...(await signInPinnedDid(record.origin)) }),
...(record.intent ? { intent: record.intent } : {}),
}
: {}),
Expand Down Expand Up @@ -4065,7 +4084,8 @@ async function signInPinnedDid(origin: string | undefined): Promise<{ pinnedDid?
* link that lapsed while the person approved still names the community.
*/
async function pinSignInOrigin(record: SignInFlowRecord): Promise<void> {
if (!record.origin) return;
// A pasted code signed in no page, so there is no origin to pin.
if (record.pasted || !record.origin) return;
const parsed = parseTriggerLink(record.link, { now: 0 });
if (!parsed.ok) return;
await pinOrigin(record.origin, parsed.link.from.value);
Expand Down Expand Up @@ -4592,23 +4612,35 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
return true; // async sendResponse
}

if ((message as { type?: string })?.type === RUNTIME_STEP_UP_LINK) {
if ((message as { type?: string })?.type === RUNTIME_PASTED_LINK) {
// The popup only: a pasted link is the person's own act (VTI-LNK-056). A
// page cannot reach this type — it is not in the content script's table.
if (!isExtensionPageSender(sender)) {
sendResponse({ ok: false, error: "step-up links are opened from the wallet itself" });
sendResponse({ ok: false, error: "pasted links are opened from the wallet itself" });
return false;
}
const link = String((message as RuntimeStepUpLinkRequest).link ?? "").trim();
// The popup closes when the approver prompt takes focus, so it is answered
// at once: whether the text is a step-up link. The outcome is a notice.
const link = String((message as RuntimePastedLinkRequest).link ?? "").trim();
// The popup closes when the next window takes focus, so it is answered at
// once: whether the text is a code the wallet opens. The outcome is a
// notice (step-up) or the sign-in window itself.
const parsed = parseTriggerLink(link, { now: Math.floor(Date.now() / 1000) });
if (!parsed.ok) {
sendResponse({ ok: false, error: stepUpReasonMessage(parsed.reason) } satisfies RuntimeStepUpLinkResponse);
return false;
}
if (parsed.link.flow?.spec.name === "sign-in") {
void readActiveConnection().then(async (active) => {
if (!active.ok) {
sendResponse({ ok: false, error: active.error } satisfies RuntimeStepUpLinkResponse);
return;
}
sendResponse({ ok: true, result: { outcome: "opened" } } satisfies RuntimeStepUpLinkResponse);
await openPastedSignIn(link);
});
return true; // async sendResponse
}
if (parsed.link.flow?.spec.name !== "step-up") {
sendResponse({ ok: false, error: "This is not a step-up code." } satisfies RuntimeStepUpLinkResponse);
sendResponse({ ok: false, error: "This is not a sign-in or step-up code." } satisfies RuntimeStepUpLinkResponse);
return false;
}
sendResponse({ ok: true, result: { outcome: "opened" } } satisfies RuntimeStepUpLinkResponse);
Expand Down
24 changes: 18 additions & 6 deletions packages/extension/src/bridge-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3206,6 +3206,10 @@ export type OffscreenSignInStepRequest = {
/** Present on `prepare` only, from the background's own record. */
link?: string;
origin?: string;
/** Present on `prepare` only: the person pasted the code into the wallet,
* so there is no page and `origin` is absent by design (VTI-LNK-105 has
* nothing to compare). Never inferred from a missing `origin`. */
pasted?: true;
/** Present on `prepare` only, when `origin` is pinned to a relying party
* (`origin-pin.ts`, M5): that DID. The flow names it on the confirm screen
* when the link's community is a different one, so a changed pairing gets
Expand Down Expand Up @@ -3337,6 +3341,9 @@ export type SignInStepResult =
* the window does not skip the screen, and offers `join-new` beside
* signing in. */
joinOffered?: true;
/** The code was pasted into the wallet, not clicked on the portal: the
* window does not skip the screen, and says so. */
pasted?: true;
}
/** After the claim: type the number. `nameMismatch` is the community's own
* name for itself when it differs from this wallet's record (VTI-LNK-104).
Expand Down Expand Up @@ -3962,10 +3969,12 @@ export type OffscreenRoomOffersResponse = { ok: true; result: unknown } | { ok:

// ─── A step-up handed to the person by a trigger link (VTI-LNK-125 – 131) ───
//
// popup / content script ──RUNTIME_STEP_UP_LINK / RUNTIME_TRIGGER_LINK──▶ background
// popup / content script ──RUNTIME_PASTED_LINK / RUNTIME_TRIGGER_LINK──▶ background
// The person pasted a `step-up` link into the popup, or clicked one on a
// page. The background re-parses it and runs the flow; nothing is
// answered to a page.
// answered to a page. (The popup's box also takes a `sign-in` link,
// which opens the sign-in window with no page origin: see
// `sign-in-flows.ts`.)
//
// background ──OFFSCREEN_STEP_UP_FLOW──▶ offscreen
// `read`: the offscreen document reads the step-up from the community
Expand All @@ -3975,11 +3984,14 @@ export type OffscreenRoomOffersResponse = { ok: true; result: unknown } | { ok:
// approve-response the person's agent signs as the subject, sent to the
// community. `end`: the person declined; forget the flow.

/** popup → background: a `step-up` link the person pasted. */
export const RUNTIME_STEP_UP_LINK = "vta-wallet/step-up-link" as const;
/** popup → background: a trigger link the person pasted — a `step-up` link,
* or a `sign-in` link an assistant opened for its own key (`vtc-mcp`'s
* `vtc_sign_in`). Extension pages only: pasting is the person's own act
* (VTI-LNK-056), and a page has no business claiming it. */
export const RUNTIME_PASTED_LINK = "vta-wallet/pasted-link" as const;

export interface RuntimeStepUpLinkRequest {
type: typeof RUNTIME_STEP_UP_LINK;
export interface RuntimePastedLinkRequest {
type: typeof RUNTIME_PASTED_LINK;
link: string;
}

Expand Down
32 changes: 19 additions & 13 deletions packages/extension/src/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
} from "./store.js";
import {
RUNTIME_CREATE_CONTEXT,
RUNTIME_STEP_UP_LINK,
type RuntimeStepUpLinkRequest,
RUNTIME_PASTED_LINK,
type RuntimePastedLinkRequest,
type RuntimeStepUpLinkResponse,
RUNTIME_DERIVE_SIGNING_KEY_ID,
RUNTIME_HOLDER_STATE,
Expand Down Expand Up @@ -274,34 +274,40 @@ function VtaSwitcher({
}

/**
* A `step-up` link someone acting for you — your assistant, say — gave you
* (VTI-LNK-125 – 131). Pasting it here is your own act (VTI-LNK-056); the
* wallet reads the step-up from the community itself and shows you what will
* be done before anything is approved. The outcome arrives as a notice, since
* this popup closes when the approver prompt opens.
* A link someone acting for you — your assistant, say — gave you. Pasting it
* here is your own act (VTI-LNK-056).
*
* - A `step-up` link (VTI-LNK-125 – 131): the wallet reads the step-up from
* the community itself and shows you what will be done before anything is
* approved. The outcome arrives as a notice, since this popup closes when
* the approver prompt opens.
* - A `sign-in` link for a community you belong to: your assistant's own key
* asking for a session as you (`vtc-mcp`'s `vtc_sign_in`). The sign-in
* window opens, never skips a screen, and asks you to type the number your
* assistant shows you.
*/
function OpenStepUpLink(): React.JSX.Element {
function OpenPastedLink(): React.JSX.Element {
const [link, setLink] = useState("");
const [error, setError] = useState<string | null>(null);
async function open(): Promise<void> {
setError(null);
const res = (await chrome.runtime.sendMessage({
type: RUNTIME_STEP_UP_LINK,
type: RUNTIME_PASTED_LINK,
link,
} satisfies RuntimeStepUpLinkRequest)) as RuntimeStepUpLinkResponse | undefined;
} satisfies RuntimePastedLinkRequest)) as RuntimeStepUpLinkResponse | undefined;
if (!res) setError("The wallet did not answer.");
else if (!res.ok) setError(res.error);
else setLink("");
}
return (
<div style={{ display: "grid", gap: 4, marginTop: 8 }}>
<div style={{ fontSize: 12, color: "var(--w-muted)" }}>Approve a step-up link</div>
<div style={{ fontSize: 12, color: "var(--w-muted)" }}>Open a link from your assistant</div>
<div style={{ display: "flex", gap: 6 }}>
<input
value={link}
onChange={(e) => setLink(e.target.value)}
placeholder="https://link.trustoverip.org/t#…"
aria-label="Step-up link"
aria-label="Sign-in or step-up link"
style={{ flex: 1, fontSize: 12 }}
/>
<button onClick={() => void open()} disabled={link.trim().length === 0}>
Expand Down Expand Up @@ -501,7 +507,7 @@ function ConnectedView({
This adds no admin code to the popup bundle — it opens a URL. The
CI guard that keeps `pnm-core/admin` out of every wallet surface
is unaffected, and still passes. */}
<OpenStepUpLink />
<OpenPastedLink />

<button
onClick={() => void chrome.tabs.create({ url: chrome.runtime.getURL("manager.html") })}
Expand Down
Loading