diff --git a/CLAUDE.md b/CLAUDE.md index 2eb39ec..d3ac326 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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: @@ -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`.** diff --git a/packages/extension/src/background.ts b/packages/extension/src/background.ts index 520ad21..53bb0cb 100644 --- a/packages/extension/src/background.ts +++ b/packages/extension/src/background.ts @@ -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, @@ -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"; } @@ -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 { + await openSignInWindow({ link, pasted: true }); +} + +async function openSignInWindow(record: SignInFlowRecord): Promise { + 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); @@ -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; @@ -4016,8 +4034,9 @@ async function handleSignInStep(msg: RuntimeSignInStepRequest): Promise { - 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); @@ -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); diff --git a/packages/extension/src/bridge-protocol.ts b/packages/extension/src/bridge-protocol.ts index 85d0d61..d814c02 100644 --- a/packages/extension/src/bridge-protocol.ts +++ b/packages/extension/src/bridge-protocol.ts @@ -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 @@ -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). @@ -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 @@ -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; } diff --git a/packages/extension/src/popup.tsx b/packages/extension/src/popup.tsx index 13e79e6..07845c5 100644 --- a/packages/extension/src/popup.tsx +++ b/packages/extension/src/popup.tsx @@ -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, @@ -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(null); async function open(): Promise { 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 (
-
Approve a step-up link
+
Open a link from your assistant
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 }} />
)} + {screen.pasted && ( +
+ + You pasted this code, so the wallet can't see the page it came + from. Continue only if you started this sign-in yourself — for + example, by asking your assistant to sign in as you. You'll type + the number your assistant shows you. + +
+ )} {screen.alreadyMember && (
diff --git a/packages/extension/tests/sign-in-flows.test.mts b/packages/extension/tests/sign-in-flows.test.mts index fa95ccb..4b3a6bb 100644 --- a/packages/extension/tests/sign-in-flows.test.mts +++ b/packages/extension/tests/sign-in-flows.test.mts @@ -572,6 +572,66 @@ test("a link clicked on a page that is not the portal is wrong-origin, and nothi assert.equal((await step(w, { step: "claim", entryId: "e-alice" })).kind, "failed", "no flow to claim on"); }); +test("a click whose origin went missing is still wrong-origin: only `pasted` waives the page (VTI-LNK-105)", async () => { + const w = world(); + const r = await step(w, { step: "prepare", link: LINK }); + assert.equal(r.kind, "refused"); + assert.equal((r as { detail: { reason: string } }).detail.reason, "wrong-origin"); + assert.equal(w.sent.length, 0); +}); + +// ── A code pasted into the popup: no page, no origin, the person types the number ── + +test("a pasted code: the screen is kept and says so, and nothing is sent before Continue", async () => { + const w = world(); + const confirm = await step(w, { step: "prepare", link: LINK, pasted: true }); + assert.deepEqual(confirm, { + kind: "confirm", + communityName: "Example Community", + portalOrigin: PORTAL, + identities: [{ entryId: "e-alice", did: ALICE, label: "Example Community" }], + pasted: true, + }); + assert.equal(w.sent.length, 0); +}); + +test("a pasted code never takes a number from a page: the person types it, at once (VTI-LNK-107)", async () => { + // A long page-number wait would stall the claim if the flow waited for one. + const w = world({ pageNumberWaitMs: 60_000 }); + await step(w, { step: "prepare", link: LINK, pasted: true }); + w.flows.pageNumber("f1", "05"); + const enter = await step(w, { step: "claim", entryId: "e-alice" }); + assert.equal(enter.kind, "enter-number"); + assert.equal(w.sent.length, 1, "only the claim"); + const review = await step(w, { step: "prove", enteredNumber: "47" }); + assert.equal(review.kind, "review"); + assert.equal(identifyNumber(w), "47", "the typed number, not the page's"); + await step(w, { step: "grant-digest" }); + const done = await step(w, { step: "respond", decision: "approve", prfOutputB64u: PRF_B64U }); + assert.deepEqual(done, { kind: "done", decision: "approve", status: "approved" }); + const grant = (w.sent[2]!.doc as { payload: { grant: { payload: Record } } }).payload.grant.payload; + assert.equal(grant.origin, PORTAL, "the grant still names the verified portal origin"); +}); + +test("a pasted code that carries an origin is not a paste: wrong-origin, nothing sent", async () => { + const w = world(); + const r = await step(w, { step: "prepare", link: LINK, pasted: true, origin: "https://evil.example" }); + assert.equal(r.kind, "refused"); + assert.equal((r as { detail: { reason: string } }).detail.reason, "wrong-origin"); + assert.equal(w.sent.length, 0); +}); + +test("a pasted code for a site not in the records: not-member, no offer, nothing sent", async () => { + for (const doc of [communityDoc, hostingDoc]) { + const w = world({ known: entries.filter((e) => e.id !== "e-alice"), doc }); + const r = await step(w, { step: "prepare", link: LINK, pasted: true }); + assert.deepEqual(r, { kind: "not-member", contactLabel: "members.example.org", portalOrigin: PORTAL }); + assert.equal(w.sent.length, 0); + assert.equal(w.vtaCalls.some((c) => c.what === "personas" || c.what === "bind"), false); + assert.equal((await step(w, { step: "join-manifest" })).kind, "failed", "nothing to join"); + } +}); + test("refusals about the service's DID document carry what was wrong, and the message stays the outcome's", async () => { const cases: Array<[Record, Record, string]> = [ [ diff --git a/packages/extension/tests/sign-in-view.render.test.mts b/packages/extension/tests/sign-in-view.render.test.mts index 3d97085..86572f2 100644 --- a/packages/extension/tests/sign-in-view.render.test.mts +++ b/packages/extension/tests/sign-in-view.render.test.mts @@ -204,6 +204,26 @@ test("one identity, but the page was pinned to another community: the screen is await screen.unmount(); }); +test("one identity, but the code was pasted: the screen is shown, says so, and waits for the person", async () => { + const { steps, send } = script({ + ...RESULTS, + prepare: { + ...(RESULTS.prepare as Extract), + identities: [{ entryId: "e1", did: "did:web:alice.example", label: "Alice" }], + pasted: true, + }, + }); + const screen = await render( + h(SignInView, { flowId: "f", send, uv: ENROLLED_UV, close: () => {} }), + ); + await screen.settle(); + assert.deepEqual(steps, [{ step: "prepare" }], "no claim goes out on its own"); + assert.ok(screen.container.querySelector('[data-testid="continue"]'), "the person continues, or not"); + assert.ok(screen.container.querySelector('[data-testid="pasted"]')); + assert.match(screen.text(), /You pasted this code/); + await screen.unmount(); +}); + test("one identity that was already a member: the screen says so, and waits for the person", async () => { const { steps, send } = script({ ...RESULTS,