@abraca/nuxt 2.36.0 → 2.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +6 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/ADocPickModal.vue +1 -1
- package/dist/runtime/components/ADocSubPageList.d.vue.ts +46 -0
- package/dist/runtime/components/ADocSubPageList.vue +1006 -0
- package/dist/runtime/components/ADocSubPageList.vue.d.ts +46 -0
- package/dist/runtime/components/ADocumentTree.vue +3 -2
- package/dist/runtime/components/AEditor.d.vue.ts +9 -0
- package/dist/runtime/components/AEditor.vue +14 -2
- package/dist/runtime/components/AEditor.vue.d.ts +9 -0
- package/dist/runtime/components/AIconPicker.vue +27 -180
- package/dist/runtime/components/ANodePanel.d.vue.ts +8 -5
- package/dist/runtime/components/ANodePanel.vue +1 -1
- package/dist/runtime/components/ANodePanel.vue.d.ts +8 -5
- package/dist/runtime/components/AWindowLayer.vue +4 -2
- package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +2 -2
- package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +2 -2
- package/dist/runtime/components/editor/ADocSuggestMenu.vue +1 -1
- package/dist/runtime/components/editor/ALocationPickerPopover.vue +31 -16
- package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue +309 -68
- package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/AChecklistRenderer.vue +259 -40
- package/dist/runtime/components/renderers/ADashboardRenderer.vue +493 -89
- package/dist/runtime/components/renderers/AGraphRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AGraphRenderer.vue +2113 -576
- package/dist/runtime/components/renderers/AGraphRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue +460 -86
- package/dist/runtime/components/renderers/AMapRenderer.d.vue.ts +7 -1
- package/dist/runtime/components/renderers/AMapRenderer.vue +999 -166
- package/dist/runtime/components/renderers/AMapRenderer.vue.d.ts +7 -1
- package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue +285 -81
- package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AOverviewRenderer.vue +3 -2
- package/dist/runtime/components/renderers/ASheetsRenderer.client.vue +255 -87
- package/dist/runtime/components/renderers/ATimelineRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ATimelineRenderer.vue +224 -31
- package/dist/runtime/components/renderers/ATimelineRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue +12 -1
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue +15 -3
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.d.vue.ts +14 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue +6 -1
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue.d.ts +14 -0
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.d.vue.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue +25 -7
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue.d.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.d.vue.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.vue.d.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue +130 -23
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/timeline/ATimelineAxis.vue +5 -3
- package/dist/runtime/components/renderers/timeline/ATimelineBar.vue +1 -1
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.d.vue.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue +16 -14
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue.d.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineLabelPanel.vue +4 -2
- package/dist/runtime/composables/useAbracadabraAuth.d.ts +1 -0
- package/dist/runtime/composables/useAbracadabraAuth.js +1 -0
- package/dist/runtime/composables/useCalendarView.js +34 -11
- package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
- package/dist/runtime/composables/useGraphReferenceEdges.d.ts +26 -0
- package/dist/runtime/composables/useGraphReferenceEdges.js +138 -0
- package/dist/runtime/composables/useGraphSim.d.ts +79 -0
- package/dist/runtime/composables/useGraphSim.js +231 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.d.ts +26 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.js +76 -0
- package/dist/runtime/composables/useSheetsFormulas.d.ts +4 -3
- package/dist/runtime/composables/useSheetsFormulas.js +575 -26
- package/dist/runtime/composables/useTimelineView.d.ts +4 -0
- package/dist/runtime/composables/useTimelineView.js +45 -11
- package/dist/runtime/composables/useWindowManager.d.ts +4 -0
- package/dist/runtime/composables/useWindowManager.js +11 -0
- package/dist/runtime/composables/useWorkspace.d.ts +57 -0
- package/dist/runtime/composables/useWorkspace.js +58 -0
- package/dist/runtime/middleware/abracadabra-auth.js +11 -1
- package/dist/runtime/plugin-abracadabra.client.js +121 -12
- package/dist/runtime/utils/dateField.d.ts +17 -0
- package/dist/runtime/utils/dateField.js +19 -0
- package/dist/runtime/utils/itemLabel.d.ts +27 -0
- package/dist/runtime/utils/itemLabel.js +8 -0
- package/dist/runtime/utils/localDate.d.ts +15 -0
- package/dist/runtime/utils/localDate.js +16 -0
- package/dist/runtime/utils/lucideIcons.d.ts +16 -10
- package/dist/runtime/utils/lucideIcons.js +1391 -69
- package/dist/runtime/utils/resolveDocColor.d.ts +7 -0
- package/dist/runtime/utils/resolveDocColor.js +32 -0
- package/dist/runtime/utils/resolveDocIcon.d.ts +10 -0
- package/dist/runtime/utils/resolveDocIcon.js +44 -0
- package/dist/runtime/utils/rowEdges.d.ts +22 -0
- package/dist/runtime/utils/rowEdges.js +29 -0
- package/dist/runtime/utils/softKeystore.d.ts +55 -0
- package/dist/runtime/utils/softKeystore.js +160 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DocPageMeta } from '../types.js';
|
|
2
|
+
import type { DocIconEntryLike } from './resolveDocIcon.js';
|
|
3
|
+
export interface ResolveDocColorOpts {
|
|
4
|
+
selfId?: string;
|
|
5
|
+
lookup?: (id: string) => DocIconEntryLike | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function resolveDocColor(meta: DocPageMeta | undefined, type: string | undefined, opts?: ResolveDocColorOpts): string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolveDocType } from "./docTypes.js";
|
|
2
|
+
import { getMetaColor } from "./getMetaColor.js";
|
|
3
|
+
export function resolveDocColor(meta, type, opts) {
|
|
4
|
+
const metaColor = getMetaColor(meta);
|
|
5
|
+
if (metaColor) return metaColor;
|
|
6
|
+
if (!meta) return void 0;
|
|
7
|
+
const ownSchema = resolveDocType(type).metaSchema;
|
|
8
|
+
const ownColorField = ownSchema?.find(
|
|
9
|
+
(f) => f.type === "colorPreset" || f.type === "colorPicker"
|
|
10
|
+
);
|
|
11
|
+
if (ownColorField && "key" in ownColorField) {
|
|
12
|
+
const val = meta[ownColorField.key];
|
|
13
|
+
if (typeof val === "string" && val) return val;
|
|
14
|
+
}
|
|
15
|
+
if (opts?.selfId && opts.lookup) {
|
|
16
|
+
let ancestorId = opts.lookup(opts.selfId)?.parentId ?? null;
|
|
17
|
+
while (ancestorId) {
|
|
18
|
+
const ancestorEntry = opts.lookup(ancestorId);
|
|
19
|
+
const ancestorSchema = resolveDocType(ancestorEntry?.type).metaSchema;
|
|
20
|
+
const schemaColorField = ancestorSchema?.find(
|
|
21
|
+
(f) => f.type === "colorPreset" || f.type === "colorPicker"
|
|
22
|
+
);
|
|
23
|
+
if (schemaColorField && "key" in schemaColorField) {
|
|
24
|
+
const val = meta[schemaColorField.key];
|
|
25
|
+
if (typeof val === "string" && val) return val;
|
|
26
|
+
}
|
|
27
|
+
if (ancestorSchema && ancestorSchema.length > 0) break;
|
|
28
|
+
ancestorId = ancestorEntry?.parentId ?? null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DocPageMeta } from '../types.js';
|
|
2
|
+
export interface DocIconEntryLike {
|
|
3
|
+
parentId?: string | null;
|
|
4
|
+
type?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ResolveDocIconOpts {
|
|
7
|
+
selfId?: string;
|
|
8
|
+
lookup?: (id: string) => DocIconEntryLike | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveDocIcon(meta: DocPageMeta | undefined, type: string | undefined, opts?: ResolveDocIconOpts): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { resolveDocType } from "./docTypes.js";
|
|
2
|
+
export function resolveDocIcon(meta, type, opts) {
|
|
3
|
+
let result;
|
|
4
|
+
if (meta?.geoType === "marker") result = `i-lucide-${meta.icon ?? "map-pin"}`;
|
|
5
|
+
else if (meta?.geoType === "line") result = "i-lucide-route";
|
|
6
|
+
else if (meta?.geoType === "measure") result = "i-lucide-ruler";
|
|
7
|
+
else if (meta?.icon && typeof meta.icon === "string") result = `i-lucide-${meta.icon}`;
|
|
8
|
+
if (!result) {
|
|
9
|
+
const userIconField = meta?._metaFields?.find(
|
|
10
|
+
(f) => f.type === "icon" && f.key
|
|
11
|
+
);
|
|
12
|
+
if (userIconField?.key) {
|
|
13
|
+
const val = meta?.[userIconField.key];
|
|
14
|
+
if (val && typeof val === "string") result = `i-lucide-${val}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (!result) {
|
|
18
|
+
const ownSchema = resolveDocType(type).metaSchema;
|
|
19
|
+
const ownIconField = ownSchema?.find((f) => f.type === "icon");
|
|
20
|
+
if (ownIconField && "key" in ownIconField) {
|
|
21
|
+
const val = meta?.[ownIconField.key];
|
|
22
|
+
if (val && typeof val === "string") result = `i-lucide-${val}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!result && opts?.selfId && opts.lookup) {
|
|
26
|
+
let ancestorId = opts.lookup(opts.selfId)?.parentId ?? null;
|
|
27
|
+
while (ancestorId) {
|
|
28
|
+
const ancestorEntry = opts.lookup(ancestorId);
|
|
29
|
+
const ancestorSchema = resolveDocType(ancestorEntry?.type).metaSchema;
|
|
30
|
+
const schemaIconField = ancestorSchema?.find((f) => f.type === "icon");
|
|
31
|
+
if (schemaIconField && "key" in schemaIconField) {
|
|
32
|
+
const val = meta?.[schemaIconField.key];
|
|
33
|
+
if (val && typeof val === "string") {
|
|
34
|
+
result = `i-lucide-${val}`;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (ancestorSchema && ancestorSchema.length > 0) break;
|
|
39
|
+
ancestorId = ancestorEntry?.parentId ?? null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!result) result = resolveDocType(type).icon;
|
|
43
|
+
return result.startsWith("i-") ? result : `i-lucide-${result}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rowEdges — "row" links between cells at the same positional index across
|
|
3
|
+
* sibling columns. For any node with 2+ children where at least 2 of those
|
|
4
|
+
* children also have children, connect the Nth grandchild of adjacent columns.
|
|
5
|
+
* Chain-style: A0→B0→C0 (not fully connected).
|
|
6
|
+
*
|
|
7
|
+
* Ported from cou-sh/app/utils/rowEdges.ts.
|
|
8
|
+
*/
|
|
9
|
+
interface TreeLike {
|
|
10
|
+
childrenOf(parentId: string | null): Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
interface Entry {
|
|
15
|
+
id: string;
|
|
16
|
+
parentId: string | null;
|
|
17
|
+
}
|
|
18
|
+
export declare function computeRowEdges(allEntries: Entry[], tree: TreeLike): Array<{
|
|
19
|
+
source: string;
|
|
20
|
+
target: string;
|
|
21
|
+
}>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function computeRowEdges(allEntries, tree) {
|
|
2
|
+
const edges = [];
|
|
3
|
+
const parentIds = /* @__PURE__ */ new Set();
|
|
4
|
+
for (const e of allEntries) parentIds.add(e.parentId);
|
|
5
|
+
const childParents = /* @__PURE__ */ new Set();
|
|
6
|
+
for (const e of allEntries) {
|
|
7
|
+
if (parentIds.has(e.id)) childParents.add(e.id);
|
|
8
|
+
}
|
|
9
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10
|
+
for (const e of allEntries) {
|
|
11
|
+
const pid = e.parentId;
|
|
12
|
+
if (pid === null || seen.has(pid)) continue;
|
|
13
|
+
seen.add(pid);
|
|
14
|
+
const columns = tree.childrenOf(pid);
|
|
15
|
+
if (columns.length < 2) continue;
|
|
16
|
+
const columnsWithKids = columns.filter((c) => childParents.has(c.id));
|
|
17
|
+
if (columnsWithKids.length < 2) continue;
|
|
18
|
+
const columnCells = columns.map((col) => tree.childrenOf(col.id));
|
|
19
|
+
for (let i = 0; i < columns.length - 1; i++) {
|
|
20
|
+
const cellsA = columnCells[i];
|
|
21
|
+
const cellsB = columnCells[i + 1];
|
|
22
|
+
const maxRow = Math.min(cellsA.length, cellsB.length);
|
|
23
|
+
for (let row = 0; row < maxRow; row++) {
|
|
24
|
+
edges.push({ source: cellsA[row].id, target: cellsB[row].id });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return edges;
|
|
29
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SoftKeystore (module port)
|
|
3
|
+
*
|
|
4
|
+
* Stores Ed25519 private keys for guest (unclaimed) and recovery-phrase
|
|
5
|
+
* identities in IndexedDB, encrypted with a non-extractable AES-256-GCM
|
|
6
|
+
* CryptoKey — instead of the legacy plaintext `abracadabra_privkey`
|
|
7
|
+
* localStorage entry.
|
|
8
|
+
*
|
|
9
|
+
* This prevents XSS from reading the raw key material out of localStorage.
|
|
10
|
+
* An attacker with JS execution can still _use_ the key (sign challenges)
|
|
11
|
+
* while the page is open, but cannot exfiltrate it for offline use.
|
|
12
|
+
*
|
|
13
|
+
* Mirrors `cou-sh/app/utils/softKeystore.ts` so the Nuxt module and the
|
|
14
|
+
* reference app persist soft identities identically. Encoding helpers are
|
|
15
|
+
* inlined here to keep the util self-contained (the module has no shared
|
|
16
|
+
* encoding util).
|
|
17
|
+
*/
|
|
18
|
+
/** Whether the browser supports the APIs required for secure soft key storage. */
|
|
19
|
+
export declare function softKeystoreAvailable(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize or retrieve the soft key. Returns the Ed25519 private key bytes
|
|
22
|
+
* and the base64url-encoded public key.
|
|
23
|
+
*
|
|
24
|
+
* On first call, generates a new keypair, encrypts the private key, and stores
|
|
25
|
+
* everything in IndexedDB. On subsequent calls, decrypts and returns the
|
|
26
|
+
* existing key. Automatically migrates a plaintext key from localStorage.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getOrCreateSoftKey(): Promise<{
|
|
29
|
+
privateKey: Uint8Array;
|
|
30
|
+
publicKey: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Persist an externally-supplied Ed25519 seed (e.g. derived from a recovery
|
|
34
|
+
* phrase) as the active soft key, encrypted at rest exactly like a generated
|
|
35
|
+
* guest key. This lets a mnemonic-recovered identity survive JWT expiry / page
|
|
36
|
+
* reloads in the browser, where there is no OS keychain to fall back on.
|
|
37
|
+
*
|
|
38
|
+
* The store holds a SINGLE record, so this overwrites any existing guest soft
|
|
39
|
+
* key — the intended semantics of "this recovered identity is now active".
|
|
40
|
+
*
|
|
41
|
+
* @param seed 32-byte Ed25519 secret. The caller still owns the passed buffer.
|
|
42
|
+
*/
|
|
43
|
+
export declare function importSoftKeyFromSeed(seed: Uint8Array): Promise<{
|
|
44
|
+
publicKey: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** Retrieve the stored public key without decrypting the private key. */
|
|
47
|
+
export declare function getSoftKeyPublicKey(): Promise<string | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Sign a base64url-encoded challenge using the stored soft key.
|
|
50
|
+
* Returns a base64url-encoded Ed25519 signature. Decrypts on demand and wipes
|
|
51
|
+
* the private key from memory afterwards.
|
|
52
|
+
*/
|
|
53
|
+
export declare function signWithSoftKey(challengeB64: string): Promise<string>;
|
|
54
|
+
/** Delete the stored soft key identity (and any legacy plaintext entry). */
|
|
55
|
+
export declare function clearSoftKey(): Promise<void>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as ed from "@noble/ed25519";
|
|
2
|
+
import { sha512 } from "@noble/hashes/sha2.js";
|
|
3
|
+
if (!ed.hashes.sha512) {
|
|
4
|
+
ed.hashes.sha512 = sha512;
|
|
5
|
+
ed.hashes.sha512Async = (m) => Promise.resolve(sha512(m));
|
|
6
|
+
}
|
|
7
|
+
function toBase64Url(bytes) {
|
|
8
|
+
let bin = "";
|
|
9
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
10
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
11
|
+
}
|
|
12
|
+
function fromBase64Url(str) {
|
|
13
|
+
const b64 = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
14
|
+
const bin = atob(b64);
|
|
15
|
+
const bytes = new Uint8Array(bin.length);
|
|
16
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
17
|
+
return bytes;
|
|
18
|
+
}
|
|
19
|
+
const DB_NAME = "abracadabra:softkey";
|
|
20
|
+
const STORE_NAME = "identity";
|
|
21
|
+
const RECORD_KEY = "current";
|
|
22
|
+
const LEGACY_LS_KEY = "abracadabra_privkey";
|
|
23
|
+
function openDb() {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const req = indexedDB.open(DB_NAME, 1);
|
|
26
|
+
req.onupgradeneeded = () => {
|
|
27
|
+
req.result.createObjectStore(STORE_NAME);
|
|
28
|
+
};
|
|
29
|
+
req.onsuccess = () => resolve(req.result);
|
|
30
|
+
req.onerror = () => reject(req.error);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function dbGet(db) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const tx = db.transaction(STORE_NAME, "readonly");
|
|
36
|
+
const req = tx.objectStore(STORE_NAME).get(RECORD_KEY);
|
|
37
|
+
req.onsuccess = () => resolve(req.result);
|
|
38
|
+
req.onerror = () => reject(req.error);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function dbPut(db, value) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
44
|
+
const req = tx.objectStore(STORE_NAME).put(value, RECORD_KEY);
|
|
45
|
+
req.onsuccess = () => resolve();
|
|
46
|
+
req.onerror = () => reject(req.error);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function dbDelete(db) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
52
|
+
const req = tx.objectStore(STORE_NAME).delete(RECORD_KEY);
|
|
53
|
+
req.onsuccess = () => resolve();
|
|
54
|
+
req.onerror = () => reject(req.error);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function generateWrappingKey() {
|
|
58
|
+
return crypto.subtle.generateKey(
|
|
59
|
+
{ name: "AES-GCM", length: 256 },
|
|
60
|
+
false,
|
|
61
|
+
// non-extractable
|
|
62
|
+
["encrypt", "decrypt"]
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
async function encryptPrivateKey(wrappingKey, privateKey) {
|
|
66
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
67
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
68
|
+
{ name: "AES-GCM", iv },
|
|
69
|
+
wrappingKey,
|
|
70
|
+
privateKey
|
|
71
|
+
);
|
|
72
|
+
return { ciphertext, iv };
|
|
73
|
+
}
|
|
74
|
+
async function decryptPrivateKey(wrappingKey, ciphertext, iv) {
|
|
75
|
+
const plain = await crypto.subtle.decrypt(
|
|
76
|
+
{ name: "AES-GCM", iv },
|
|
77
|
+
wrappingKey,
|
|
78
|
+
ciphertext
|
|
79
|
+
);
|
|
80
|
+
return new Uint8Array(plain);
|
|
81
|
+
}
|
|
82
|
+
export function softKeystoreAvailable() {
|
|
83
|
+
return typeof globalThis.crypto?.subtle !== "undefined" && typeof globalThis.indexedDB !== "undefined";
|
|
84
|
+
}
|
|
85
|
+
export async function getOrCreateSoftKey() {
|
|
86
|
+
const db = await openDb();
|
|
87
|
+
try {
|
|
88
|
+
const stored = await dbGet(db);
|
|
89
|
+
if (stored) {
|
|
90
|
+
const privateKey2 = await decryptPrivateKey(stored.wrappingKey, stored.encryptedPrivateKey, stored.iv);
|
|
91
|
+
return { privateKey: privateKey2, publicKey: stored.publicKey };
|
|
92
|
+
}
|
|
93
|
+
const legacyKey = localStorage.getItem(LEGACY_LS_KEY);
|
|
94
|
+
let privateKey;
|
|
95
|
+
if (legacyKey) {
|
|
96
|
+
privateKey = fromBase64Url(legacyKey);
|
|
97
|
+
localStorage.removeItem(LEGACY_LS_KEY);
|
|
98
|
+
} else {
|
|
99
|
+
privateKey = ed.utils.randomSecretKey();
|
|
100
|
+
}
|
|
101
|
+
const publicKey = toBase64Url(ed.getPublicKey(privateKey));
|
|
102
|
+
const wrappingKey = await generateWrappingKey();
|
|
103
|
+
const { ciphertext, iv } = await encryptPrivateKey(wrappingKey, privateKey);
|
|
104
|
+
await dbPut(db, { publicKey, encryptedPrivateKey: ciphertext, iv, wrappingKey });
|
|
105
|
+
return { privateKey, publicKey };
|
|
106
|
+
} finally {
|
|
107
|
+
db.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function importSoftKeyFromSeed(seed) {
|
|
111
|
+
const publicKey = toBase64Url(ed.getPublicKey(seed));
|
|
112
|
+
const wrappingKey = await generateWrappingKey();
|
|
113
|
+
const seedCopy = seed.slice();
|
|
114
|
+
try {
|
|
115
|
+
const { ciphertext, iv } = await encryptPrivateKey(wrappingKey, seedCopy);
|
|
116
|
+
const db = await openDb();
|
|
117
|
+
try {
|
|
118
|
+
await dbPut(db, { publicKey, encryptedPrivateKey: ciphertext, iv, wrappingKey });
|
|
119
|
+
} finally {
|
|
120
|
+
db.close();
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
seedCopy.fill(0);
|
|
124
|
+
}
|
|
125
|
+
return { publicKey };
|
|
126
|
+
}
|
|
127
|
+
export async function getSoftKeyPublicKey() {
|
|
128
|
+
const db = await openDb();
|
|
129
|
+
try {
|
|
130
|
+
const stored = await dbGet(db);
|
|
131
|
+
return stored?.publicKey ?? null;
|
|
132
|
+
} finally {
|
|
133
|
+
db.close();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export async function signWithSoftKey(challengeB64) {
|
|
137
|
+
const db = await openDb();
|
|
138
|
+
try {
|
|
139
|
+
const stored = await dbGet(db);
|
|
140
|
+
if (!stored) throw new Error("No soft key stored");
|
|
141
|
+
const privateKey = await decryptPrivateKey(stored.wrappingKey, stored.encryptedPrivateKey, stored.iv);
|
|
142
|
+
try {
|
|
143
|
+
const sig = await ed.sign(fromBase64Url(challengeB64), privateKey);
|
|
144
|
+
return toBase64Url(sig);
|
|
145
|
+
} finally {
|
|
146
|
+
privateKey.fill(0);
|
|
147
|
+
}
|
|
148
|
+
} finally {
|
|
149
|
+
db.close();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export async function clearSoftKey() {
|
|
153
|
+
const db = await openDb();
|
|
154
|
+
try {
|
|
155
|
+
await dbDelete(db);
|
|
156
|
+
} finally {
|
|
157
|
+
db.close();
|
|
158
|
+
}
|
|
159
|
+
localStorage.removeItem(LEGACY_LS_KEY);
|
|
160
|
+
}
|