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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import{v as e}from"./index-BqKtmCPh.js";var t={ar:()=>e(()=>import(`./ar-DPJDxCQI-DVxXrl8b.js`),[]),de:()=>e(()=>import(`./de-CakHBokE-Bc7uuGiX.js`),[]),en:()=>e(()=>import(`./en-BGdzE27X-TW1aad9S.js`),[]),es:()=>e(()=>import(`./es-VeBX6MEG-Kiej93jn.js`),[]),fa:()=>e(()=>import(`./fa-Dt7EYtKf-B5W0KSh4.js`),[]),fr:()=>e(()=>import(`./fr-DUhhjxrJ-ZlHjDAmJ.js`),[]),he:()=>e(()=>import(`./he-BShJg1dK-LKJKt0F1.js`),[]),hr:()=>e(()=>import(`./hr-BXtyqmwg-DyP3pX1K.js`),[]),is:()=>e(()=>import(`./is-2Fb-0w_j-BgcKBDLw.js`),[]),it:()=>e(()=>import(`./it-CiZtVb3Y-DvxSJeVo.js`),[]),ja:()=>e(()=>import(`./ja-CsxD3kEL-CvaZrDnL.js`),[]),ko:()=>e(()=>import(`./ko-It6g03Cy-ZSCK4kOT.js`),[]),nb:()=>e(()=>import(`./nb-CLao87La-CG_xJQwn.js`),[]),nl:()=>e(()=>import(`./nl-JQSo8dht-CaVSlD7w.js`),[]),pl:()=>e(()=>import(`./pl-DEMBgHEP-Dj8IbNR0.js`),[]),pt:()=>e(()=>import(`./pt-CBCdYAax-CxE-Nyim.js`),[]),ru:()=>e(()=>import(`./ru-BQk_9Q-L-c3bOsG2P.js`),[]),sk:()=>e(()=>import(`./sk-kgB2DtDL-Dc169kAC.js`),[]),tr:()=>e(()=>import(`./tr-DkcSXX8f-jMWTyLfk.js`),[]),uk:()=>e(()=>import(`./uk-Bib-e6bV-ErQ7vi1L.js`),[]),uz:()=>e(()=>import(`./uz-B2jaKhJb-BWnnlbUQ.js`),[]),vi:()=>e(()=>import(`./vi-V_GFRxE8-B_ZUa_6s.js`),[]),zh:()=>e(()=>import(`./zh-jglyCmjs-BDbB1o9o.js`),[]),"zh-hant":()=>e(()=>import(`./zh-hant-2ZrAkFnC-CdiPnK-W.js`),[])},n={no:`nb`,"zh-tw":`zh-hant`},r=new Map;function i(e){return{light:e(0),"medium-light":e(1),medium:e(2),"medium-dark":e(3),dark:e(4)}}function a(e){let[t,n,r,...a]=e.split(`
import{v as e}from"./index-DcxPhBy8.js";var t={ar:()=>e(()=>import(`./ar-DPJDxCQI-DVxXrl8b.js`),[]),de:()=>e(()=>import(`./de-CakHBokE-Bc7uuGiX.js`),[]),en:()=>e(()=>import(`./en-BGdzE27X-TW1aad9S.js`),[]),es:()=>e(()=>import(`./es-VeBX6MEG-Kiej93jn.js`),[]),fa:()=>e(()=>import(`./fa-Dt7EYtKf-B5W0KSh4.js`),[]),fr:()=>e(()=>import(`./fr-DUhhjxrJ-ZlHjDAmJ.js`),[]),he:()=>e(()=>import(`./he-BShJg1dK-LKJKt0F1.js`),[]),hr:()=>e(()=>import(`./hr-BXtyqmwg-DyP3pX1K.js`),[]),is:()=>e(()=>import(`./is-2Fb-0w_j-BgcKBDLw.js`),[]),it:()=>e(()=>import(`./it-CiZtVb3Y-DvxSJeVo.js`),[]),ja:()=>e(()=>import(`./ja-CsxD3kEL-CvaZrDnL.js`),[]),ko:()=>e(()=>import(`./ko-It6g03Cy-ZSCK4kOT.js`),[]),nb:()=>e(()=>import(`./nb-CLao87La-CG_xJQwn.js`),[]),nl:()=>e(()=>import(`./nl-JQSo8dht-CaVSlD7w.js`),[]),pl:()=>e(()=>import(`./pl-DEMBgHEP-Dj8IbNR0.js`),[]),pt:()=>e(()=>import(`./pt-CBCdYAax-CxE-Nyim.js`),[]),ru:()=>e(()=>import(`./ru-BQk_9Q-L-c3bOsG2P.js`),[]),sk:()=>e(()=>import(`./sk-kgB2DtDL-Dc169kAC.js`),[]),tr:()=>e(()=>import(`./tr-DkcSXX8f-jMWTyLfk.js`),[]),uk:()=>e(()=>import(`./uk-Bib-e6bV-ErQ7vi1L.js`),[]),uz:()=>e(()=>import(`./uz-B2jaKhJb-BWnnlbUQ.js`),[]),vi:()=>e(()=>import(`./vi-V_GFRxE8-B_ZUa_6s.js`),[]),zh:()=>e(()=>import(`./zh-jglyCmjs-BDbB1o9o.js`),[]),"zh-hant":()=>e(()=>import(`./zh-hant-2ZrAkFnC-CdiPnK-W.js`),[])},n={no:`nb`,"zh-tw":`zh-hant`},r=new Map;function i(e){return{light:e(0),"medium-light":e(1),medium:e(2),"medium-dark":e(3),dark:e(4)}}function a(e){let[t,n,r,...a]=e.split(`
`),o=`0,1,3,4,5,6,7,8,9`.split(`,`).map(Number),s=`😀 0 1
😃 0 0.6
😄 0 0.6
Expand Down

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

38 changes: 0 additions & 38 deletions internal/web/dist/assets/index-BqKtmCPh.js

This file was deleted.

38 changes: 38 additions & 0 deletions internal/web/dist/assets/index-DcxPhBy8.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/web/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="theme-color" content="#0d0f14" />
<meta name="description" content="Private, encrypted notes" />
<title>KyNotes</title>
<script type="module" crossorigin src="/assets/index-BqKtmCPh.js"></script>
<script type="module" crossorigin src="/assets/index-DcxPhBy8.js"></script>
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-COiEfhsA.js">
<link rel="stylesheet" crossorigin href="/assets/index-DXs7t0vx.css">
</head>
Expand Down
32 changes: 32 additions & 0 deletions web/e2e/persistent-storage.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from "@playwright/test";
import { adminConsole, OWNER, person, signIn } from "./people";

declare global {
interface Window { persistAsked?: number }
}

test("signing in asks the browser to keep the storage that holds the encryption key", async ({ browser }) => {
const admin = await person(browser);
const owner = await person(browser);
try {
await adminConsole(admin.page);
const { page } = owner;
// Counts the requests; the browser still answers them itself.
await page.addInitScript(() => {
const storage = navigator.storage;
const persist = storage.persist.bind(storage);
window.persistAsked = 0;
storage.persist = () => {
window.persistAsked = (window.persistAsked ?? 0) + 1;
return persist();
};
});
await signIn(page, OWNER.username, OWNER.password);
// Asked once the vault keeps the key, unless the browser already keeps this site's storage.
await expect.poll(() => page.evaluate(async () => (window.persistAsked ?? 0) > 0 || (await navigator.storage.persisted()))).toBe(true);
expect(owner.unexpected).toEqual([]);
} finally {
await admin.page.context().close();
await owner.page.context().close();
}
});
30 changes: 30 additions & 0 deletions web/src/persist.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { keepStorage } from "./persist";

const storage = (persisted: boolean, granted: boolean) => {
const asked: string[] = [];
return {
asked,
persisted: async () => { asked.push("persisted"); return persisted; },
persist: async () => { asked.push("persist"); return granted; },
};
};

describe("keepStorage", () => {
it("does not ask again once storage is kept", async () => {
const kept = storage(true, false);
expect(await keepStorage(kept)).toBe(true);
expect(kept.asked).toEqual(["persisted"]);
});
it("asks once, and reports the browser's answer", async () => {
const granted = storage(false, true);
expect(await keepStorage(granted)).toBe(true);
expect(granted.asked).toEqual(["persisted", "persist"]);
expect(await keepStorage(storage(false, false))).toBe(false);
});
it("is false without the API, or when the browser throws", async () => {
expect(await keepStorage(undefined)).toBe(false);
expect(await keepStorage({})).toBe(false);
expect(await keepStorage({ persisted: async () => { throw new Error("no"); }, persist: async () => true })).toBe(false);
});
});
15 changes: 15 additions & 0 deletions web/src/persist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type Persistable = Pick<StorageManager, "persisted" | "persist">;

/**
* Asks the browser not to clear this site's storage on its own (to free space, or after Safari's
* days without a visit), since it holds this browser's encryption key. Firefox asks the user;
* Chromium and Safari decide silently. Best effort: true only when storage is kept.
*/
export async function keepStorage(storage: Partial<Persistable> | undefined = globalThis.navigator?.storage): Promise<boolean> {
if (!storage?.persisted || !storage.persist) return false;
try {
return (await storage.persisted()) || (await storage.persist());
} catch {
return false;
}
}
5 changes: 4 additions & 1 deletion web/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { x25519 } from "@noble/curves/ed25519.js";
import type { HeldIdentity } from "./identity";
import type { KeyState } from "./keyring";
import { keepStorage } from "./persist";
import { isPinConfirmation, sameKey, type PinConfirmation, type Pins } from "./pins";
import { sameBytes } from "./teamKeys";
const databaseName = "kynotes-web";
Expand Down Expand Up @@ -332,12 +333,14 @@ const holds = (record: VaultRecord, userID: string, expected: HeldIdentity | nul
export async function storeIdentityKey(username: string, userID: string, identity: HeldIdentity, expected?: HeldIdentity | null): Promise<boolean> {
const stored = await sealForDevice(userID, identity).catch(() => undefined);
// Only in an opened vault record: updateRecord never creates one.
return stored ? updateRecord(username, (record) => {
const kept = stored ? await updateRecord(username, (record) => {
if (expected !== undefined && !holds(record, userID, expected)) return undefined;
const { resetSent, ...rest } = record;
// Keeping the key a reset sent finishes that reset here.
return resetSent && resetSent.userID === userID && sameBytes(resetSent.publicKey, identity.publicKey) ? { ...rest, identity: stored } : { ...record, identity: stored };
}) : false;
if (kept) void keepStorage();
return kept;
}

/** Records, before a reset is sent, the new public key; best-effort (M4: an unanswered reset is explained on the next load). */
Expand Down