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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -30,6 +30,6 @@
"typescript-eslint": "8.72.1"
},
"dependencies": {
"@flow-industries/seal": "^0.2.0"
"@flow-industries/seal": "^0.3.0"
}
}
2 changes: 2 additions & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }),
});
Expand Down
13 changes: 13 additions & 0 deletions src/link-page.ts
Original file line number Diff line number Diff line change
@@ -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;
}
55 changes: 21 additions & 34 deletions src/obsidian/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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}$/,
);
Expand Down
21 changes: 21 additions & 0 deletions tests/link-page.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading