diff --git a/README.md b/README.md index da359d8..58bc02c 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ FLOW NOTE Sync needs a Flow ID account with a NOTE notepad, and Obsidian 1.11.5 ## Linking 1. Open **Settings → FLOW NOTE Sync** and select **Link**, or run **FLOW NOTE Sync: Link this vault** from the command palette. -2. The plugin shows a Flow ID code and an 8-character device code (`XXXX XXXX`), and opens `note.flow.talk/link` in your default browser. -3. Approve from the browser where you use NOTE. If that's another browser or profile, select **Copy link** and open the link there, such as the browser that set up or recovered your notepad. A browser that has never opened your notepad can't approve, and neither can one that NOTE says can't change who has access to your notepad. On that page, sign in if asked, enter the Flow ID code if the page asks for one, type the device code and approve with your passkey. The device code never leaves this device any other way: Flow ID only ever sees a slow hash of it, so it can't swap in keys or a notepad of its own. +2. The plugin shows a Flow ID code and an 8-character device code (`XXXX XXXX`), and opens `note.flow.talk/link` in your default browser, at an address it builds itself from the Flow ID code. +3. Approve from the browser where you use NOTE, such as the one that set up or recovered your notepad. If that's another browser or profile, select **Copy link** and open the link there. A browser that has never opened your notepad can't approve, and neither can one that NOTE says can't change who has access to your notepad. On that page, sign in if asked, enter the Flow ID code if the page asks for one, type the device code and approve with your passkey. The device code never leaves this device any other way: Flow ID only ever sees a slow hash of it, so it can't swap in keys or a notepad of its own. 4. Back in Obsidian, the plugin shows the account it was linked to: its DID, and its handle when the handle checks out both ways, with the domain that vouched for it set apart so a lookalike such as `alice-flow.talk.example` reads as `talk.example`. **Nothing syncs until you confirm it is yours.** A code someone else guessed and approved would otherwise bind your vault to their notepad. A link has to be approved within ten minutes. A vault that is still linked can't be linked again: if syncing stopped, settings offer **Retry** and **Unlink**, and you link again only after unlinking. diff --git a/bun.lock b/bun.lock index 55bea76..15caef1 100644 --- a/bun.lock +++ b/bun.lock @@ -5,7 +5,7 @@ "": { "name": "flow-note-sync", "dependencies": { - "@flow-industries/seal": "^0.2.0", + "@flow-industries/seal": "^0.3.0", }, "devDependencies": { "@biomejs/biome": "2.5.8", @@ -87,7 +87,7 @@ "@flow-industries/lint": ["@flow-industries/lint@0.3.1", "", {}, "sha512-oKTw7fMCZBlshRixumpXrUJUmbJx3HqiGs72F43d920yy1fCtOuAjlnbY8SXBZZ7TnEibuYY2FVjAZcQSg6COQ=="], - "@flow-industries/seal": ["@flow-industries/seal@0.2.0", "", { "dependencies": { "@flow-industries/id": "^0.36.0", "@lezer/markdown": "1.8.0", "dexie": "^4.4.6", "fflate": "^0.8.3", "libsodium-wrappers-sumo": "0.8.4", "yaml": "^2.9.1", "zod": "^4.6.5" } }, "sha512-wUdHg7NQC73fxzhxYev0LHgdAIuAwYVTc0m4mm1jvyr/PG6cZdXlfbG67FxWiXPQ+kQjuFYhEOxfcda/3AYx2g=="], + "@flow-industries/seal": ["@flow-industries/seal@0.3.0", "", { "dependencies": { "@flow-industries/id": "^0.36.0", "@lezer/markdown": "1.8.0", "dexie": "^4.4.6", "fflate": "^0.8.3", "libsodium-wrappers-sumo": "0.8.4", "yaml": "^2.9.1", "zod": "^4.6.5" } }, "sha512-dC5/NwQWrq2sw61GhH/WM2sveXVFwb3gdM8VL/LGKUxSQIxP2ExU24WhKtaklQ9HuYOf2XB8wLuH0aXgBNq3OA=="], "@flow-industries/ui": ["@flow-industries/ui@0.27.0", "", { "dependencies": { "@base-ui/react": "^1.3.0", "@hookform/resolvers": "^5.2.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "date-fns": "^4.1.0", "embla-carousel-react": "^8.6.0", "input-otp": "^1.4.2", "lucide-react": "^0.562.0", "motion": "^12.24.0", "react-hook-form": "^7.70.0", "react-resizable-panels": "^4.9.0", "recharts": "3.8.0", "tailwind-merge": "^3.4.0", "tw-animate-css": "^1.4.0", "zod": "^4.3.5" }, "peerDependencies": { "@flow-industries/id": ">=0.22.0", "react": ">=19.0.0", "react-dom": ">=19.0.0", "tailwindcss": ">=4.0.0" }, "optionalPeers": ["@flow-industries/id"] }, "sha512-lTrfDnt8B1o2c/ny3lst3b8sjYWmluo6T7jVGtjKpwxsxzCdiVapqcF80lIkuUeqytdaXkhm8H7+//KCF9+crQ=="], diff --git a/manifest.json b/manifest.json index 25a4f9a..a7d48ec 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "flow-note", "name": "FLOW NOTE Sync", - "version": "0.1.1", + "version": "0.1.2", "minAppVersion": "1.11.5", "description": "Sync your vault both ways with your end-to-end encrypted NOTE notepad, linked once through your browser.", "author": "Flow Industries", diff --git a/package.json b/package.json index 1dab6ea..c4a7608 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "flow-note-sync", "private": true, - "version": "0.1.1", + "version": "0.1.2", "description": "FLOW NOTE Sync for Obsidian", "license": "MIT", "type": "module", @@ -30,6 +30,6 @@ "typescript-eslint": "8.72.1" }, "dependencies": { - "@flow-industries/seal": "^0.2.0" + "@flow-industries/seal": "^0.3.0" } } diff --git a/src/controller.ts b/src/controller.ts index 1691d32..521ab1c 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -16,6 +16,7 @@ import { type SyncIndex, } from "./engine"; import type { IndexKey } from "./index-store"; +import { NOTE_ORIGIN } from "./link-page"; /** The device client calls the controller makes. */ export interface DeviceClient { @@ -230,6 +231,7 @@ export class SyncController { await device.linkDevice(seed, { ...this.deviceOptions(), label, + noteOrigin: NOTE_ORIGIN, signal, onPrompt: (prompt) => this.set({ kind: "linking", prompt }), }); diff --git a/src/link-page.ts b/src/link-page.ts new file mode 100644 index 0000000..e8dd857 --- /dev/null +++ b/src/link-page.ts @@ -0,0 +1,13 @@ +/** Where approving a link happens. */ +export const NOTE_ORIGIN = "https://note.flow.talk"; + +/** + * NOTE's link page for a Flow ID user code, built here. It is never an + * address Flow ID chose, whose path, query or fragment could lead the person + * to a request other than this vault's. + */ +export function linkPageFor(userCode: string): string { + const url = new URL("/link", NOTE_ORIGIN); + url.searchParams.set("code", userCode); + return url.href; +} diff --git a/src/obsidian/modals.ts b/src/obsidian/modals.ts index 6033aab..afbf045 100644 --- a/src/obsidian/modals.ts +++ b/src/obsidian/modals.ts @@ -2,18 +2,7 @@ import { type App, Modal, Notice, Setting } from "obsidian"; import { handleDomain, type LinkedAccount } from "../account"; import type { SyncController } from "../controller"; import type { LinkPrompt } from "../device"; - -/** Where approving a link happens; a verification address anywhere else is shown, never opened. */ -export const NOTE_ORIGIN = "https://note.flow.talk"; - -const linkPage = (prompt: LinkPrompt) => { - try { - const url = new URL(prompt.verificationUri); - return url.origin === NOTE_ORIGIN ? url.href : null; - } catch { - return null; - } -}; +import { linkPageFor } from "../link-page"; /** Asks a yes-or-no question; closing the modal answers no. */ export function confirm( @@ -127,15 +116,13 @@ export class LinkModal extends Modal { contentEl.createEl("p", { text: "Asking Flow ID for a code…" }); return; } - const page = linkPage(prompt); - if (page && !this.opened) { + const page = linkPageFor(prompt.userCode); + if (!this.opened) { this.opened = true; window.open(page); } contentEl.createEl("p", { - text: page - ? "NOTE's link page opened in your default browser. Approve from the browser where you use NOTE: if that's another browser or profile, copy the link and open it there. Sign in if asked, enter the Flow ID code if the page asks for it, then type the device code below." - : `Open ${NOTE_ORIGIN}/link in the browser where you use NOTE, enter the Flow ID code below, and type the device code.`, + text: "NOTE's link page opened in your default browser. Approve from the browser where you use NOTE: if that's another browser or profile, copy the link and open it there. Sign in if asked, enter the Flow ID code if the page asks for it, then type the device code below.", }); new Setting(contentEl).setName("Flow ID code").setDesc(prompt.userCode); const secret = new Setting(contentEl) @@ -147,23 +134,21 @@ export class LinkModal extends Modal { cls: "flow-note-code", text: prompt.pairingCode, }); - const row = new Setting(contentEl); - if (page) - row - .addButton((button) => - button - .setButtonText("Copy link") - .onClick(() => void this.copyLink(page)), - ) - .addButton((button) => - button - .setButtonText("Open link page again") - .onClick(() => window.open(page)), - ); - row.addButton((button) => - button.setButtonText("Cancel").onClick(() => this.close()), - ); - if (page && this.copyFailed) + new Setting(contentEl) + .addButton((button) => + button + .setButtonText("Copy link") + .onClick(() => void this.copyLink(page)), + ) + .addButton((button) => + button + .setButtonText("Open link page again") + .onClick(() => window.open(page)), + ) + .addButton((button) => + button.setButtonText("Cancel").onClick(() => this.close()), + ); + if (this.copyFailed) new Setting(contentEl) .setName("Link") .setDesc( @@ -233,6 +218,8 @@ export class LinkModal extends Modal { private async link() { if (!(await this.beforeLink())) return; this.error = null; + this.opened = false; + this.copyFailed = false; this.abort = new AbortController(); try { await this.controller.link( diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 3a0d9a3..81441d6 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -28,6 +28,7 @@ import { type TrustLoss, } from "../src/device"; import { SyncEngine, type SyncIndex } from "../src/engine"; +import { linkPageFor } from "../src/link-page"; import { MemoryIndex, MemoryVault } from "./fakes"; /** @@ -117,6 +118,11 @@ async function link(admin: AdminBrowser, vault: Obsidian) { await new Promise((resolve) => setTimeout(resolve, 10)); const [prompt] = vault.prompts; if (!prompt) throw new Error("No prompt"); + // The test Flow ID answers with its own verification address; neither seal nor the plugin passes it on. + expect(linkPageFor(prompt.userCode)).toBe( + "https://note.flow.talk/link?code=BCDF-GHJK", + ); + expect(prompt.linkPage).toBe(linkPageFor(prompt.userCode)); expect(prompt.pairingCode).toMatch( /^[0-9A-HJKMNP-TV-Z]{4} [0-9A-HJKMNP-TV-Z]{4}$/, ); diff --git a/tests/link-page.test.ts b/tests/link-page.test.ts new file mode 100644 index 0000000..5defae4 --- /dev/null +++ b/tests/link-page.test.ts @@ -0,0 +1,21 @@ +import { expect, test } from "bun:test"; +import { linkPageFor, NOTE_ORIGIN } from "../src/link-page"; + +test("the link page is NOTE's own, built from the user code alone", () => { + expect(linkPageFor("BCDF-GHJK")).toBe( + "https://note.flow.talk/link?code=BCDF-GHJK", + ); + for (const userCode of [ + "BCDF-GHJK#passkey=eyJyZXF1ZXN0Ijp0cnVlfQ", + "BCDF-GHJK&passkey=1", + "../recover?code=BCDF-GHJK", + "//evil.example/link", + ]) { + const url = new URL(linkPageFor(userCode)); + expect(url.origin).toBe(NOTE_ORIGIN); + expect(url.pathname).toBe("/link"); + expect(url.hash).toBe(""); + expect([...url.searchParams.keys()]).toEqual(["code"]); + expect(url.searchParams.get("code")).toBe(userCode); + } +}); diff --git a/versions.json b/versions.json index 118aa46..ff8dd16 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { "0.1.0": "1.11.5", - "0.1.1": "1.11.5" + "0.1.1": "1.11.5", + "0.1.2": "1.11.5" }