desktopr 1.3.0 → 2.0.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.
Files changed (52) hide show
  1. package/dist-sdk/_companion_context.js +10 -5
  2. package/dist-sdk/_helpers.js +1 -1
  3. package/dist-sdk/desktopr/_helpers.js +1 -1
  4. package/dist-sdk/desktopr/_types.d.ts +2 -2
  5. package/dist-sdk/modules/rs/app/_types.d.ts +1 -1
  6. package/dist-sdk/modules/rs/badge/_types.d.ts +1 -1
  7. package/dist-sdk/modules/rs/contextMenu/_helpers.js +1 -1
  8. package/dist-sdk/modules/rs/diagnostics/_helpers.js +1 -1
  9. package/dist-sdk/modules/rs/diagnostics/_types.d.ts +1 -1
  10. package/dist-sdk/modules/rs/files/_types.d.ts +1 -1
  11. package/dist-sdk/modules/rs/fs/_main.js +44 -1
  12. package/dist-sdk/modules/rs/fs/_types.d.ts +27 -19
  13. package/dist-sdk/modules/rs/menu/_helpers.js +1 -1
  14. package/dist-sdk/modules/rs/network/_types.d.ts +1 -1
  15. package/dist-sdk/modules/rs/plugins/_helpers.d.ts +1 -0
  16. package/dist-sdk/modules/rs/plugins/_helpers.js +9 -0
  17. package/dist-sdk/modules/rs/plugins/_main.d.ts +5 -0
  18. package/dist-sdk/modules/rs/plugins/_main.js +15 -0
  19. package/dist-sdk/modules/rs/plugins/_types.d.ts +38 -0
  20. package/dist-sdk/modules/rs/plugins/_types.js +2 -0
  21. package/dist-sdk/modules/rs/window/_helpers.js +1 -1
  22. package/dist-sdk/modules/rs/worker/_main.d.ts +1 -1
  23. package/dist-sdk/modules/rs/worker/_types.d.ts +1 -1
  24. package/dist-sdk/utils/crypto/_crypto.d.ts +31 -0
  25. package/dist-sdk/utils/crypto/_crypto.js +116 -0
  26. package/dist-sdk/utils/crypto/index.d.ts +1 -0
  27. package/dist-sdk/utils/crypto/index.js +17 -0
  28. package/dist-sdk/utils/index.d.ts +2 -0
  29. package/dist-sdk/utils/index.js +18 -0
  30. package/dist-sdk/utils/shared/_types.d.ts +64 -0
  31. package/dist-sdk/utils/shared/_types.js +2 -0
  32. package/dist-sdk/utils/utils/_browserStorage.d.ts +22 -0
  33. package/dist-sdk/utils/utils/_browserStorage.js +149 -0
  34. package/dist-sdk/utils/utils/_integerUtils.d.ts +50 -0
  35. package/dist-sdk/utils/utils/_integerUtils.js +74 -0
  36. package/dist-sdk/utils/utils/_jitter.d.ts +4 -0
  37. package/dist-sdk/utils/utils/_jitter.js +25 -0
  38. package/dist-sdk/utils/utils/_json.d.ts +63 -0
  39. package/dist-sdk/utils/utils/_json.js +510 -0
  40. package/dist-sdk/utils/utils/_logger.d.ts +16 -0
  41. package/dist-sdk/utils/utils/_logger.js +43 -0
  42. package/dist-sdk/utils/utils/_pageStore.d.ts +37 -0
  43. package/dist-sdk/utils/utils/_pageStore.js +61 -0
  44. package/dist-sdk/utils/utils/_regexPatterns.d.ts +113 -0
  45. package/dist-sdk/utils/utils/_regexPatterns.js +150 -0
  46. package/dist-sdk/utils/utils/_typesValidation.d.ts +50 -0
  47. package/dist-sdk/utils/utils/_typesValidation.js +125 -0
  48. package/dist-sdk/utils/utils/_utils.d.ts +201 -0
  49. package/dist-sdk/utils/utils/_utils.js +1200 -0
  50. package/dist-sdk/utils/utils/index.d.ts +9 -0
  51. package/dist-sdk/utils/utils/index.js +25 -0
  52. package/package.json +1 -1
@@ -25,15 +25,20 @@ async function getCacheOnlyWindowContext() {
25
25
  if (initialized)
26
26
  return;
27
27
  initialized = true;
28
- if (typeof window === 'undefined' || !window?.Desktopr) {
28
+ if (typeof window === "undefined" || !window?.Desktopr) {
29
29
  console.error("Error executing setupCompanionContext():\nwindow.Desktopr undefined or not yet initialized.");
30
30
  return;
31
31
  }
32
- const windowInfo = await window.Desktopr.window.getInfo();
33
- const compState = parseCompanionWindowLabel(windowInfo.label);
34
- if (window?.Desktopr?.window?.state)
32
+ try {
33
+ const windowInfo = await window.Desktopr.window.getInfo();
34
+ const compState = parseCompanionWindowLabel(windowInfo.label);
35
+ state = compState;
35
36
  window.Desktopr.window.state = compState;
36
- // if(window?.Desktopr?.companion?.state) window.Desktopr.companion.state = compState;
37
+ // if (window?.Desktopr?.companion?.state) window.Desktopr.companion.state = compState;
38
+ }
39
+ catch (error) {
40
+ console.warn("[Desktopr bridge] Failed to initialize cache-only window context:", error);
41
+ }
37
42
  }
38
43
  // Simple getters
39
44
  function isCacheOnlyWindow() {
@@ -36,7 +36,7 @@ __exportStar(require("./modules/rs/worker/_helpers"), exports);
36
36
  __exportStar(require("./modules/rs/contextMenu/_helpers"), exports);
37
37
  __exportStar(require("./modules/rs/companion/_helpers"), exports);
38
38
  __exportStar(require("./modules/rs/globalVariables/_helpers"), exports);
39
- const utils_1 = require("suffro-lib/utils");
39
+ const utils_1 = require("./utils");
40
40
  const tauriReadyCheck = () => (typeof window !== "undefined" && (window.__TAURI__) && (window.Desktopr));
41
41
  exports.tauriReadyCheck = tauriReadyCheck;
42
42
  const waitTauri = async () => {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.platformSpecifcFilter = exports.normalizeString = void 0;
4
- const utils_1 = require("suffro-lib/utils");
4
+ const utils_1 = require("../utils");
5
5
  const normalizeString = (str, options = {
6
6
  toLowerCase: true,
7
7
  spacesFiller: "",
@@ -9,12 +9,12 @@ import type { FsInterface } from "../modules/rs/fs/_types";
9
9
  import type { MenuInterface } from "../modules/rs/menu/_types";
10
10
  import type { DiagnosticsInterface } from "../modules/rs/diagnostics/_types";
11
11
  import type { BadgeInterface } from "../modules/rs/badge/_types";
12
- import type { WorkerInterface } from "../modules/rs/worker/_types";
13
12
  import type { ContextMenuInterface } from "../modules/rs/contextMenu/_types";
14
13
  import type { AutostartInterface } from "../modules/rs/autostart/_types";
15
14
  import type { NetworkInterface } from "../modules/rs/network/_types";
16
15
  import type { GlobalVariablesInterface } from "../modules/rs/globalVariables/_types";
17
16
  import { WindowTauri } from "../core/_types";
17
+ import { PluginsInterface } from "../modules/rs/plugins/_types";
18
18
  export type DtrPlatform = "macos" | "linux" | "windows";
19
19
  /**
20
20
  * Desktopr API exposed in the webview.
@@ -46,7 +46,7 @@ export type DesktoprAPI = {
46
46
  network: NetworkInterface;
47
47
  autostart: AutostartInterface;
48
48
  badge?: BadgeInterface;
49
- worker: WorkerInterface;
49
+ plugins: PluginsInterface;
50
50
  tauri?: WindowTauri;
51
51
  onReady: (callback: Function) => void;
52
52
  globalVariables: GlobalVariablesInterface;
@@ -1,5 +1,5 @@
1
1
  import { DtrPlatform } from "../../../_types";
2
- import { I32 } from "suffro-lib/utils";
2
+ import { I32 } from "../../../utils";
3
3
  /**
4
4
  * Information about a window managed by Desktopr.
5
5
  */
@@ -1,4 +1,4 @@
1
- import { U32 } from "suffro-lib/utils";
1
+ import { U32 } from "../../../utils";
2
2
  export interface BadgeInterface {
3
3
  set: (count: U32) => Promise<void>;
4
4
  clear: () => Promise<void>;
@@ -5,7 +5,7 @@ exports.isCmType = isCmType;
5
5
  exports.parseCmType = parseCmType;
6
6
  exports.normalizeEntries = normalizeEntries;
7
7
  const _helpers_1 = require("../../../_helpers");
8
- const utils_1 = require("suffro-lib/utils");
8
+ const utils_1 = require("../../../utils");
9
9
  // Keep CM_TYPES as a readonly tuple and assert it matches CmType[]
10
10
  exports.CM_TYPES = [
11
11
  "item",
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.diagnosticsSettings = void 0;
4
4
  exports.buildDiagnosticsTestFunctions = buildDiagnosticsTestFunctions;
5
- const utils_1 = require("suffro-lib/utils");
5
+ const utils_1 = require("../../../utils");
6
6
  const diagnosticsSettings = async (core, settings) => {
7
7
  if (settings?.retentionDaysAnalytics && !utils_1.Num.isU32(settings.retentionDaysAnalytics))
8
8
  throw ("[retentionDaysAnalytics] the value must be a U32 integer number");
@@ -1,4 +1,4 @@
1
- import { U32 } from "suffro-lib/utils";
1
+ import { U32 } from "../../../utils";
2
2
  export interface DiagnosticsInterface {
3
3
  settings: {
4
4
  set: (settings?: PrivacySettings) => Promise<unknown>;
@@ -1,4 +1,4 @@
1
- import { U64, U8 } from "suffro-lib/utils";
1
+ import { U64, U8 } from "../../../utils";
2
2
  export type FileWithBytes = {
3
3
  path: string;
4
4
  bytes: U8[];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildFs = buildFs;
4
+ const _helpers_1 = require("../../../_helpers");
4
5
  const getWindowLabelIfCompanion = () => {
5
6
  const compState = window?.Desktopr?.window
6
7
  ?.state;
@@ -10,7 +11,7 @@ const getWindowLabelIfCompanion = () => {
10
11
  return label;
11
12
  };
12
13
  // Comments are in English
13
- function scope(core, permanent) {
14
+ function scopeCoreMethods(core, permanent, plugin) {
14
15
  // Guard that prevents persistent data operations from isolated (companion) windows.
15
16
  const ensureDataNotIsolated = () => {
16
17
  if (!permanent)
@@ -20,6 +21,7 @@ function scope(core, permanent) {
20
21
  throw new Error("Persistent data operations are not available in isolated companion windows. Use the cache scope (Desktopr.fs.cache) for per-session storage.");
21
22
  }
22
23
  };
24
+ const pluginStorageModule = ((plugin?.trim()) ?? undefined);
23
25
  return {
24
26
  listContent: (rel = "") => {
25
27
  ensureDataNotIsolated();
@@ -27,6 +29,7 @@ function scope(core, permanent) {
27
29
  rel,
28
30
  permanent,
29
31
  windowLabel: getWindowLabelIfCompanion(),
32
+ pluginStorageModule
30
33
  });
31
34
  },
32
35
  newDirectory: (rel) => {
@@ -35,6 +38,7 @@ function scope(core, permanent) {
35
38
  rel,
36
39
  permanent,
37
40
  windowLabel: getWindowLabelIfCompanion(),
41
+ pluginStorageModule
38
42
  });
39
43
  },
40
44
  remove: (rel, recursive = false) => {
@@ -44,6 +48,7 @@ function scope(core, permanent) {
44
48
  recursive,
45
49
  permanent,
46
50
  windowLabel: getWindowLabelIfCompanion(),
51
+ pluginStorageModule
47
52
  });
48
53
  },
49
54
  stat: (rel = "") => {
@@ -52,6 +57,7 @@ function scope(core, permanent) {
52
57
  rel,
53
58
  permanent,
54
59
  windowLabel: getWindowLabelIfCompanion(),
60
+ pluginStorageModule
55
61
  });
56
62
  },
57
63
  writeText: (rel, contents, opts) => {
@@ -63,6 +69,7 @@ function scope(core, permanent) {
63
69
  createDirs: opts?.createDirs,
64
70
  append: opts?.append,
65
71
  windowLabel: getWindowLabelIfCompanion(),
72
+ pluginStorageModule
66
73
  });
67
74
  },
68
75
  readText: (rel) => {
@@ -71,6 +78,7 @@ function scope(core, permanent) {
71
78
  rel,
72
79
  permanent,
73
80
  windowLabel: getWindowLabelIfCompanion(),
81
+ pluginStorageModule
74
82
  });
75
83
  },
76
84
  writeBytes: (rel, base64, opts) => {
@@ -81,6 +89,7 @@ function scope(core, permanent) {
81
89
  dataBase64: base64,
82
90
  createDirs: opts?.createDirs,
83
91
  windowLabel: getWindowLabelIfCompanion(),
92
+ pluginStorageModule
84
93
  });
85
94
  },
86
95
  readBytes: (rel) => {
@@ -89,6 +98,7 @@ function scope(core, permanent) {
89
98
  rel,
90
99
  permanent,
91
100
  windowLabel: getWindowLabelIfCompanion(),
101
+ pluginStorageModule
92
102
  });
93
103
  },
94
104
  exists: (rel) => {
@@ -97,6 +107,7 @@ function scope(core, permanent) {
97
107
  rel,
98
108
  permanent,
99
109
  windowLabel: getWindowLabelIfCompanion(),
110
+ pluginStorageModule
100
111
  });
101
112
  },
102
113
  move: (src, dest, opts) => {
@@ -108,6 +119,7 @@ function scope(core, permanent) {
108
119
  createDirs: opts?.createDirs,
109
120
  overwrite: opts?.overwrite,
110
121
  windowLabel: getWindowLabelIfCompanion(),
122
+ pluginStorageModule
111
123
  });
112
124
  },
113
125
  copy: (src, dest, opts) => {
@@ -120,8 +132,26 @@ function scope(core, permanent) {
120
132
  createDirs: opts?.createDirs,
121
133
  overwrite: opts?.overwrite,
122
134
  windowLabel: getWindowLabelIfCompanion(),
135
+ pluginStorageModule
123
136
  });
124
137
  },
138
+ };
139
+ }
140
+ ;
141
+ // Comments are in English
142
+ function scope(core, permanent) {
143
+ // Guard that prevents persistent data operations from isolated (companion) windows.
144
+ const ensureDataNotIsolated = () => {
145
+ if (!permanent)
146
+ return;
147
+ const label = getWindowLabelIfCompanion();
148
+ if (label && label.trim().length > 0) {
149
+ throw new Error("Persistent data operations are not available in isolated companion windows. Use the cache scope (Desktopr.fs.cache) for per-session storage.");
150
+ }
151
+ };
152
+ const coreMethods = scopeCoreMethods(core, permanent);
153
+ const mainScopeMethods = {
154
+ ...coreMethods,
125
155
  path: async () => {
126
156
  ensureDataNotIsolated();
127
157
  const p = await core.invoke("dtr_fs_paths");
@@ -136,6 +166,18 @@ function scope(core, permanent) {
136
166
  },
137
167
  base: permanent ? ".data" : ".cache",
138
168
  };
169
+ return mainScopeMethods;
170
+ }
171
+ function pluginFsScope(core, plugin) {
172
+ const pluginModuleName = ((plugin?.trim()) ?? undefined);
173
+ const santizedluginModuleName = ((0, _helpers_1.normalizeModuleName)(pluginModuleName)?.trim()) ?? undefined;
174
+ if (!santizedluginModuleName)
175
+ throw ("Invalid plugin name");
176
+ const coreMethods = scopeCoreMethods(core, true, santizedluginModuleName);
177
+ return {
178
+ ...coreMethods,
179
+ clearStorage: async () => core.invoke("dtr_plugin_storage_clear", { module: santizedluginModuleName })
180
+ };
139
181
  }
140
182
  function buildFs(core) {
141
183
  const cache = scope(core, false);
@@ -143,6 +185,7 @@ function buildFs(core) {
143
185
  return {
144
186
  cache,
145
187
  data,
188
+ pluginFs: (plugin) => pluginFsScope(core, plugin),
146
189
  paths: async () => core.invoke("dtr_fs_paths"),
147
190
  base: { cache: ".cache", data: ".data" },
148
191
  trash: {
@@ -8,7 +8,7 @@ export type FsPaths = {
8
8
  cache: string;
9
9
  data: string;
10
10
  };
11
- export type FsScopeMethods = {
11
+ export type FsCoreMethods = {
12
12
  listContent: (rel: string) => Promise<FsEntry[]>;
13
13
  newDirectory: (rel: string) => Promise<void>;
14
14
  remove: (rel: string, recursive?: boolean) => Promise<void>;
@@ -32,34 +32,42 @@ export type FsScopeMethods = {
32
32
  createDirs?: boolean;
33
33
  overwrite?: boolean;
34
34
  }) => Promise<void>;
35
+ };
36
+ export type FsScopeMethods = FsCoreMethods & {
35
37
  clear: () => Promise<void>;
36
38
  path: () => Promise<string>;
37
39
  base: string;
38
40
  };
41
+ export type FsPluginMethods = FsCoreMethods & {
42
+ clearStorage: () => Promise<void>;
43
+ };
44
+ export interface FsTrashMethods {
45
+ clear: () => Promise<void>;
46
+ recover: () => Promise<void>;
47
+ listContent: (rel?: string | undefined) => Promise<FsEntry[]>;
48
+ stat: (rel?: string) => Promise<FsEntry>;
49
+ exists: (rel?: string) => Promise<boolean>;
50
+ readText: (rel: string) => Promise<string>;
51
+ readBytes: (rel: string) => Promise<string>;
52
+ }
53
+ export interface FsDiagnosticMethods {
54
+ clear: () => Promise<void>;
55
+ remove: (rel: string, recursive?: boolean | undefined) => Promise<void>;
56
+ listContent: (rel?: string | undefined) => Promise<FsEntry[]>;
57
+ stat: (rel?: string) => Promise<FsEntry>;
58
+ exists: (rel?: string) => Promise<boolean>;
59
+ readText: (rel: string) => Promise<string>;
60
+ readBytes: (rel: string) => Promise<string>;
61
+ }
39
62
  export interface FsInterface {
40
63
  cache: FsScopeMethods;
41
64
  data: FsScopeMethods;
65
+ pluginFs: (plugin: string) => FsPluginMethods;
42
66
  paths: () => Promise<FsPaths>;
43
67
  base: {
44
68
  cache: string;
45
69
  data: string;
46
70
  };
47
- trash: {
48
- clear: () => Promise<void>;
49
- recover: () => Promise<void>;
50
- listContent: (rel?: string) => Promise<FsEntry[]>;
51
- stat: (rel?: string) => Promise<FsEntry>;
52
- exists: (rel?: string) => Promise<boolean>;
53
- readText: (rel: string) => Promise<string>;
54
- readBytes: (rel: string) => Promise<string>;
55
- };
56
- diagnostics: {
57
- clear: () => Promise<void>;
58
- remove: (rel: string, recursive?: boolean) => Promise<void>;
59
- listContent: (rel?: string) => Promise<FsEntry[]>;
60
- stat: (rel?: string) => Promise<FsEntry>;
61
- exists: (rel?: string) => Promise<boolean>;
62
- readText: (rel: string) => Promise<string>;
63
- readBytes: (rel: string) => Promise<string>;
64
- };
71
+ trash: FsTrashMethods;
72
+ diagnostics: FsDiagnosticMethods;
65
73
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initMenuConfig = void 0;
4
- const utils_1 = require("suffro-lib/utils");
4
+ const utils_1 = require("../../../utils");
5
5
  function isMacOS() {
6
6
  if (typeof navigator === "undefined") {
7
7
  return false;
@@ -1,4 +1,4 @@
1
- import { U64 } from "suffro-lib/utils";
1
+ import { U64 } from "../../../utils";
2
2
  export interface NetworkInterface {
3
3
  status: () => Promise<void>;
4
4
  ping: (url: string, timeout?: U64) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const normalizeModuleName: (name: string) => string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeModuleName = void 0;
4
+ const normalizeModuleName = (name) => {
5
+ const sanitizeWasmExtensions = name.replaceAll(".wasm", "");
6
+ const addWasmExtensions = `${sanitizeWasmExtensions}.wasm`;
7
+ return addWasmExtensions;
8
+ };
9
+ exports.normalizeModuleName = normalizeModuleName;
@@ -0,0 +1,5 @@
1
+ import { DesktoprAPI } from "../../../_types";
2
+ import { PluginsInterface } from "./_types";
3
+ export declare function buildPlugins(core: {
4
+ invoke: DesktoprAPI["invoke"];
5
+ }): PluginsInterface;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPlugins = buildPlugins;
4
+ const _helpers_1 = require("./_helpers");
5
+ function buildPlugins(core) {
6
+ return {
7
+ call: (module, payload, timeoutMs) => core.invoke("dtr_plugin_call", { module: (0, _helpers_1.normalizeModuleName)(module), payload, timeoutMs }),
8
+ status: () => core.invoke("dtr_plugin_status"),
9
+ list: () => core.invoke("dtr_plugin_list_modules"),
10
+ remove: (name) => core.invoke("dtr_plugin_remove_module", { name: (0, _helpers_1.normalizeModuleName)(name) }),
11
+ addFromBytes: (name, contents) => core.invoke("dtr_plugin_add_module", { name: (0, _helpers_1.normalizeModuleName)(name), contents }),
12
+ add: (name, maxBytes) => core.invoke("dtr_plugin_pick_and_add_module", { maxBytes, defaultName: (0, _helpers_1.normalizeModuleName)(name) }),
13
+ killJobs: () => core.invoke("dtr_plugin_clear_all_jobs")
14
+ };
15
+ }
@@ -0,0 +1,38 @@
1
+ import { U64, U8 } from "../../../utils";
2
+ export interface PluginsInterface {
3
+ call: (module: string, payload: PluginCallPayload, timeoutMs?: U64) => Promise<PluginCallResult>;
4
+ status: () => Promise<PluginStatusResult>;
5
+ list: () => Promise<string[]>;
6
+ remove: (name: string) => Promise<boolean>;
7
+ addFromBytes: (name: string, contents: U8[]) => Promise<any>;
8
+ add: (name: string, maxBytes?: U64 | undefined) => Promise<PluginAddResult>;
9
+ killJobs: () => Promise<boolean>;
10
+ }
11
+ export type PluginCallPayload = {
12
+ fn: string;
13
+ args: number[] | Record<string, unknown>;
14
+ [key: string]: any;
15
+ };
16
+ export type PluginStatusResult = {
17
+ ready: true;
18
+ runtime: string;
19
+ };
20
+ export type PluginCallResult = {
21
+ durationMs: number;
22
+ error: string | null | undefined;
23
+ id: string;
24
+ ok: boolean;
25
+ stderr: string;
26
+ stdout: string;
27
+ value: {
28
+ error?: string;
29
+ value?: string | number;
30
+ ok: boolean;
31
+ };
32
+ };
33
+ export type PluginAddResult = {
34
+ bytes: number;
35
+ name: string;
36
+ path: string;
37
+ saved: boolean;
38
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.closeWindow = exports.newWindow = exports.waitTauri = exports.tauriReadyCheck = void 0;
4
4
  const sdk_1 = require("../../../sdk");
5
5
  const _constants_1 = require("../../../_constants");
6
- const utils_1 = require("suffro-lib/utils");
6
+ const utils_1 = require("../../../utils");
7
7
  const tauriReadyCheck = () => typeof window !== "undefined" &&
8
8
  window.__TAURI__ &&
9
9
  window.Desktopr;
@@ -1,5 +1,5 @@
1
1
  import { DesktoprAPI } from "../../../_types";
2
- import { U64, U8 } from "suffro-lib/utils";
2
+ import { U64, U8 } from "../../../utils";
3
3
  import { WorkerCallPayload } from "./_types";
4
4
  export declare function buildWorker(core: {
5
5
  invoke: DesktoprAPI["invoke"];
@@ -1,4 +1,4 @@
1
- import { U64, U8 } from "suffro-lib/utils";
1
+ import { U64, U8 } from "../../../utils";
2
2
  export interface WorkerInterface {
3
3
  call: (method: string, payload: WorkerCallPayload, timeoutMs?: U64) => Promise<string>;
4
4
  status: () => Promise<boolean>;
@@ -0,0 +1,31 @@
1
+ declare function digestHex(input: string, algorithm: "SHA-1" | "SHA-256" | "SHA-512"): Promise<string>;
2
+ declare function hmacSha256Hex(key: string, message: string): Promise<string>;
3
+ /**
4
+ * Simple 32-bit hash for change detection.
5
+ * Do NOT use for security-sensitive purposes.
6
+ */
7
+ export declare function nonCryptographicHash(input: string): string;
8
+ export declare function sha256(input: string, nonCryptographicFallback?: boolean): Promise<string>;
9
+ declare function encodeBase64(input: string): string;
10
+ declare function decodeBase64(base64: string): string;
11
+ declare function generateRandomInitializationVector(): Uint8Array;
12
+ declare function aesGcmEncrypt(plaintext: string, key: CryptoKey, iv: BufferSource): Promise<Uint8Array>;
13
+ declare function aesGcmDecrypt(ciphertext: BufferSource, key: CryptoKey, iv: BufferSource): Promise<string>;
14
+ export declare const cryptoTools: {
15
+ digest: {
16
+ digestHex: typeof digestHex;
17
+ sha256: typeof sha256;
18
+ hmacSha256Hex: typeof hmacSha256Hex;
19
+ nonCryptographicHash: typeof nonCryptographicHash;
20
+ };
21
+ base64: {
22
+ encode: typeof encodeBase64;
23
+ decode: typeof decodeBase64;
24
+ };
25
+ AES: {
26
+ encode: typeof aesGcmEncrypt;
27
+ decode: typeof aesGcmDecrypt;
28
+ randomInitializationVector: typeof generateRandomInitializationVector;
29
+ };
30
+ };
31
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ // encryption-utils.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.cryptoTools = void 0;
5
+ exports.nonCryptographicHash = nonCryptographicHash;
6
+ exports.sha256 = sha256;
7
+ // ==============================
8
+ // 🔒 Hash / Digest
9
+ // ==============================
10
+ async function digestHex(input, algorithm) {
11
+ const data = new TextEncoder().encode(input);
12
+ const hash = await crypto.subtle.digest(algorithm, data);
13
+ return Array.from(new Uint8Array(hash))
14
+ .map((b) => b.toString(16).padStart(2, "0"))
15
+ .join("");
16
+ }
17
+ // ==============================
18
+ // 🔐 HMAC (digest con chiave)
19
+ // ==============================
20
+ async function hmacSha256Hex(key, message) {
21
+ const enc = new TextEncoder();
22
+ const keyData = enc.encode(key);
23
+ const msgData = enc.encode(message);
24
+ const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: { name: "SHA-256" } }, false, ["sign"]);
25
+ const signature = await crypto.subtle.sign("HMAC", cryptoKey, msgData);
26
+ return Array.from(new Uint8Array(signature))
27
+ .map((b) => b.toString(16).padStart(2, "0"))
28
+ .join("");
29
+ }
30
+ /**
31
+ * Simple 32-bit hash for change detection.
32
+ * Do NOT use for security-sensitive purposes.
33
+ */
34
+ function nonCryptographicHash(input) {
35
+ let hash = 0;
36
+ for (let i = 0; i < input.length; i++) {
37
+ hash = (hash * 31 + input.charCodeAt(i)) | 0;
38
+ }
39
+ // convert to unsigned and hex
40
+ return (hash >>> 0).toString(16);
41
+ }
42
+ async function sha256(input, nonCryptographicFallback = true) {
43
+ if (typeof crypto === "undefined" || !crypto.subtle) {
44
+ if (!nonCryptographicFallback)
45
+ throw "crypto not found in this contex";
46
+ console.warn(`[crypto not found] using unsafe non-cryptographic fallback, useful only as weak "checksum"`);
47
+ return nonCryptographicHash(input);
48
+ }
49
+ const encoder = new TextEncoder();
50
+ const data = encoder.encode(input);
51
+ const digest = await crypto.subtle.digest("SHA-256", data);
52
+ const bytes = new Uint8Array(digest);
53
+ return Array.from(bytes)
54
+ .map((b) => b.toString(16).padStart(2, "0"))
55
+ .join("");
56
+ }
57
+ // ==============================
58
+ // 📦 Base64
59
+ // ==============================
60
+ function encodeBase64(input) {
61
+ const bytes = new TextEncoder().encode(input);
62
+ let binary = "";
63
+ const chunkSize = 0x8000; // 32 KB per evitare troppi argomenti a String.fromCharCode
64
+ for (let i = 0; i < bytes.length; i += chunkSize) {
65
+ const chunk = bytes.subarray(i, i + chunkSize);
66
+ binary += String.fromCharCode(...chunk);
67
+ }
68
+ return btoa(binary);
69
+ }
70
+ function decodeBase64(base64) {
71
+ const binary = atob(base64);
72
+ const len = binary.length;
73
+ const bytes = new Uint8Array(len);
74
+ for (let i = 0; i < len; i++) {
75
+ bytes[i] = binary.charCodeAt(i);
76
+ }
77
+ return new TextDecoder().decode(bytes);
78
+ }
79
+ // ==============================
80
+ // 🔐 AES-GCM (reversibile)
81
+ // ==============================
82
+ async function generateAesKey() {
83
+ return crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, [
84
+ "encrypt",
85
+ "decrypt",
86
+ ]);
87
+ }
88
+ function generateRandomInitializationVector() {
89
+ return crypto.getRandomValues(new Uint8Array(12)); // 96-bit IV
90
+ }
91
+ async function aesGcmEncrypt(plaintext, key, iv) {
92
+ const encoded = new TextEncoder().encode(plaintext);
93
+ const ciphertext = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, encoded);
94
+ return new Uint8Array(ciphertext);
95
+ }
96
+ async function aesGcmDecrypt(ciphertext, key, iv) {
97
+ const decrypted = await crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, ciphertext);
98
+ return new TextDecoder().decode(decrypted);
99
+ }
100
+ exports.cryptoTools = {
101
+ digest: {
102
+ digestHex,
103
+ sha256,
104
+ hmacSha256Hex,
105
+ nonCryptographicHash
106
+ },
107
+ base64: {
108
+ encode: encodeBase64,
109
+ decode: decodeBase64,
110
+ },
111
+ AES: {
112
+ encode: aesGcmEncrypt,
113
+ decode: aesGcmDecrypt,
114
+ randomInitializationVector: generateRandomInitializationVector,
115
+ },
116
+ };
@@ -0,0 +1 @@
1
+ export * from "./_crypto";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./_crypto"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./utils";
2
+ export * from "./crypto";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utils"), exports);
18
+ __exportStar(require("./crypto"), exports);