orgnote-api 0.20.2 → 0.40.9
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/api.d.ts +93 -98
- package/constants/{command-groups.contant.d.ts → command-groups.d.ts} +2 -1
- package/constants/{command-groups.contant.js → command-groups.js} +2 -0
- package/constants/extension-errors.d.ts +9 -0
- package/constants/extension-errors.js +18 -0
- package/constants/file-guard-errors.d.ts +8 -0
- package/constants/file-guard-errors.js +18 -0
- package/constants/git-errors.d.ts +9 -0
- package/constants/git-errors.js +18 -0
- package/constants/i18n-keys.d.ts +369 -0
- package/constants/i18n-keys.js +157 -0
- package/constants/index.d.ts +9 -1
- package/constants/index.js +9 -1
- package/constants/oauth-providers.d.ts +1 -0
- package/constants/oauth-providers.js +1 -0
- package/constants/route-names.d.ts +36 -0
- package/constants/route-names.js +37 -0
- package/constants/route-paths.d.ts +5 -0
- package/constants/route-paths.js +4 -0
- package/constants/style-sizes.d.ts +1 -0
- package/constants/style-sizes.js +1 -0
- package/encryption/__tests__/encryption.spec.js +4 -5
- package/encryption/__tests__/note-encryption.spec.js +49 -340
- package/encryption/encryption.d.ts +9 -4
- package/encryption/encryption.js +25 -5
- package/encryption/note-encryption.d.ts +1 -1
- package/encryption/note-encryption.js +6 -6
- package/files-api.d.ts +0 -1
- package/index.d.ts +4 -1
- package/index.js +4 -1
- package/mappers/orgnode-to-note.d.ts +2 -2
- package/mappers/orgnode-to-note.js +3 -2
- package/models/auth-state.d.ts +9 -0
- package/models/auth-state.js +12 -0
- package/models/auth-store.d.ts +3 -3
- package/models/buffer-store.d.ts +14 -0
- package/models/buffer.d.ts +24 -0
- package/models/colors.d.ts +1 -0
- package/models/command.d.ts +13 -8
- package/models/commands-group-store.d.ts +11 -0
- package/models/commands-store.d.ts +13 -0
- package/models/completion-store.d.ts +14 -0
- package/models/completion.d.ts +16 -7
- package/models/config-store.d.ts +9 -0
- package/models/confirmation-modal.d.ts +11 -0
- package/models/context-menu-store.d.ts +10 -0
- package/models/cron-store.d.ts +21 -0
- package/models/cron-task.d.ts +30 -0
- package/models/css-utils.d.ts +17 -0
- package/models/default-commands.d.ts +52 -3
- package/models/default-commands.js +59 -2
- package/models/encryption-store.d.ts +10 -0
- package/models/encryption-store.js +1 -0
- package/models/encryption.d.ts +54 -11
- package/models/encryption.js +28 -1
- package/models/extension-registry-store.d.ts +9 -0
- package/models/extension-registry-store.js +1 -0
- package/models/extension-store.d.ts +18 -0
- package/models/extension-store.js +1 -0
- package/models/extension.d.ts +96 -24
- package/models/extension.js +88 -1
- package/models/file-guard-store.d.ts +14 -0
- package/models/file-guard-store.js +1 -0
- package/models/file-guard.d.ts +27 -0
- package/models/file-guard.js +1 -0
- package/models/{file-cache.d.ts → file-info.d.ts} +1 -1
- package/models/file-info.js +1 -0
- package/models/file-manager-store.d.ts +10 -12
- package/models/file-opener-store.d.ts +6 -4
- package/models/file-system-manager-store.d.ts +13 -0
- package/models/file-system-manager-store.js +1 -0
- package/models/file-system-store.d.ts +19 -0
- package/models/file-system-store.js +1 -0
- package/models/file-system.d.ts +32 -5
- package/models/file-system.js +2 -0
- package/models/file-upload.d.ts +6 -0
- package/models/file-upload.js +1 -0
- package/models/file-watcher-store.d.ts +18 -0
- package/models/file-watcher-store.js +1 -0
- package/models/files-store.d.ts +2 -2
- package/models/git-store.d.ts +12 -0
- package/models/git-store.js +1 -0
- package/models/git.d.ts +47 -0
- package/models/git.js +1 -0
- package/models/i18n-keys.d.ts +2 -0
- package/models/i18n-keys.js +1 -0
- package/models/index.d.ts +57 -2
- package/models/index.js +60 -2
- package/models/layout-snapshot-repository.d.ts +14 -0
- package/models/layout-snapshot-repository.js +1 -0
- package/models/layout-store.d.ts +17 -0
- package/models/layout-store.js +1 -0
- package/models/layout.d.ts +16 -0
- package/models/layout.js +1 -0
- package/models/log-repository.d.ts +17 -0
- package/models/log-repository.js +1 -0
- package/models/log-store.d.ts +15 -0
- package/models/log-store.js +1 -0
- package/models/log.d.ts +12 -0
- package/models/log.js +1 -0
- package/models/logger.d.ts +8 -0
- package/models/logger.js +1 -0
- package/models/menu-action.d.ts +18 -0
- package/models/menu-action.js +1 -0
- package/models/modal-store.d.ts +16 -0
- package/models/modal-store.js +1 -0
- package/models/modal.d.ts +10 -2
- package/models/note.d.ts +30 -13
- package/models/notification-config.d.ts +14 -0
- package/models/notification-config.js +1 -0
- package/models/notifications-store.d.ts +20 -0
- package/models/notifications-store.js +1 -0
- package/models/oauth-provider.d.ts +2 -1
- package/models/orgnote-config.d.ts +80 -0
- package/models/orgnote-config.js +42 -0
- package/models/orgnote-url.d.ts +6 -0
- package/models/orgnote-url.js +1 -0
- package/models/pane-snapshot-repository.d.ts +0 -0
- package/models/pane-snapshot-repository.js +0 -0
- package/models/pane.d.ts +38 -0
- package/models/pane.js +1 -0
- package/models/panes-store.d.ts +30 -0
- package/models/panes-store.js +1 -0
- package/models/platform-detection.d.ts +11 -0
- package/models/platform-detection.js +1 -0
- package/models/platform-specific.d.ts +1 -0
- package/models/platform-specific.js +1 -0
- package/models/platform.d.ts +2 -0
- package/models/platform.js +1 -0
- package/models/queue-store.d.ts +49 -0
- package/models/queue-store.js +1 -0
- package/models/queue-task.d.ts +15 -0
- package/models/queue-task.js +1 -0
- package/models/repositories.d.ts +58 -38
- package/models/screen-detection.d.ts +10 -0
- package/models/screen-detection.js +1 -0
- package/models/settings-store.d.ts +12 -0
- package/models/settings-store.js +1 -0
- package/models/settings-ui-store.d.ts +7 -0
- package/models/settings-ui-store.js +1 -0
- package/models/sidebar-store.d.ts +22 -0
- package/models/sidebar-store.js +1 -0
- package/models/splash-screen.d.ts +13 -0
- package/models/splash-screen.js +1 -0
- package/models/store.d.ts +1 -1
- package/models/style-size.d.ts +2 -0
- package/models/style-size.js +1 -0
- package/models/style-variant.d.ts +1 -0
- package/models/style-variant.js +1 -0
- package/models/sync-store.d.ts +8 -6
- package/models/sync.d.ts +0 -5
- package/models/system-info.d.ts +47 -0
- package/models/system-info.js +1 -0
- package/models/theme-store.d.ts +16 -0
- package/models/theme-store.js +1 -0
- package/models/theme-variables.d.ts +4 -189
- package/models/theme-variables.js +2 -191
- package/models/toolbar-store.d.ts +9 -0
- package/models/toolbar-store.js +1 -0
- package/models/ui-store.d.ts +6 -0
- package/models/ui-store.js +1 -0
- package/models/user.d.ts +4 -7
- package/models/vue-component.d.ts +4 -2
- package/package.json +38 -27
- package/remote-api/api.d.ts +288 -669
- package/remote-api/api.js +199 -485
- package/remote-api/base.js +1 -1
- package/remote-api/common.d.ts +1 -1
- package/remote-api/index.d.ts +2 -2
- package/remote-api/index.js +0 -1
- package/sync/__tests__/memory-state.spec.d.ts +1 -0
- package/sync/__tests__/memory-state.spec.js +49 -0
- package/sync/__tests__/plan.spec.d.ts +1 -0
- package/sync/__tests__/plan.spec.js +116 -0
- package/sync/create-sync-plan.d.ts +2 -0
- package/sync/create-sync-plan.js +13 -0
- package/sync/fetch.d.ts +8 -0
- package/sync/fetch.js +32 -0
- package/sync/index.d.ts +10 -0
- package/sync/index.js +9 -0
- package/sync/memory-state.d.ts +2 -0
- package/sync/memory-state.js +22 -0
- package/sync/operations/conflict.d.ts +10 -0
- package/sync/operations/conflict.js +56 -0
- package/sync/operations/delete-local.d.ts +2 -0
- package/sync/operations/delete-local.js +17 -0
- package/sync/operations/delete-remote.d.ts +2 -0
- package/sync/operations/delete-remote.js +26 -0
- package/sync/operations/download.d.ts +2 -0
- package/sync/operations/download.js +20 -0
- package/sync/operations/index.d.ts +5 -0
- package/sync/operations/index.js +5 -0
- package/sync/operations/synced-file.d.ts +14 -0
- package/sync/operations/synced-file.js +5 -0
- package/sync/operations/upload.d.ts +2 -0
- package/sync/operations/upload.js +30 -0
- package/sync/plan.d.ts +9 -0
- package/sync/plan.js +57 -0
- package/sync/recovery.d.ts +2 -0
- package/sync/recovery.js +6 -0
- package/sync/scan.d.ts +4 -0
- package/sync/scan.js +40 -0
- package/sync/types.d.ts +74 -0
- package/sync/types.js +7 -0
- package/sync/utils/__tests__/oldest-synced-at.spec.d.ts +1 -0
- package/sync/utils/__tests__/oldest-synced-at.spec.js +38 -0
- package/sync/utils/oldest-synced-at.d.ts +2 -0
- package/sync/utils/oldest-synced-at.js +9 -0
- package/types/index.d.ts +0 -0
- package/types/index.js +0 -0
- package/utils/__tests__/find-files-diff.spec.d.ts +1 -0
- package/{tools → utils}/__tests__/find-files-diff.spec.js +3 -3
- package/utils/__tests__/find-note-files-diff.spec.d.ts +1 -0
- package/{tools → utils}/__tests__/find-note-files-diff.spec.js +5 -5
- package/utils/__tests__/get-file-name.spec.d.ts +1 -0
- package/utils/__tests__/get-string-path.spec.d.ts +1 -0
- package/utils/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
- package/utils/__tests__/is-org-file.spec.d.ts +1 -0
- package/utils/__tests__/join.spec.d.ts +1 -0
- package/utils/__tests__/join.spec.js +32 -0
- package/utils/__tests__/nullable-guards.spec.d.ts +1 -0
- package/utils/__tests__/nullable-guards.spec.js +44 -0
- package/utils/__tests__/parent-folder.spec.d.ts +1 -0
- package/utils/__tests__/read-org-files-recursively.spec.d.ts +1 -0
- package/utils/__tests__/split-path.spec.d.ts +1 -0
- package/utils/__tests__/to-absolute-path.spec.d.ts +1 -0
- package/utils/__tests__/to-absolute-path.spec.js +26 -0
- package/utils/__tests__/to-error.spec.d.ts +1 -0
- package/utils/__tests__/to-error.spec.js +112 -0
- package/utils/__tests__/with-root.spec.d.ts +1 -0
- package/utils/__tests__/with-root.spec.js +20 -0
- package/utils/auth-state.d.ts +5 -0
- package/utils/auth-state.js +18 -0
- package/{tools → utils}/find-notes-files-diff.js +6 -3
- package/{tools → utils}/index.d.ts +5 -1
- package/{tools → utils}/index.js +5 -1
- package/utils/join-path.d.ts +1 -0
- package/utils/join-path.js +13 -0
- package/utils/nullable-guards.d.ts +2 -0
- package/utils/nullable-guards.js +6 -0
- package/utils/to-absolute-path.d.ts +2 -0
- package/utils/to-absolute-path.js +2 -0
- package/utils/to-error.d.ts +6 -0
- package/utils/to-error.js +33 -0
- package/utils/toml.d.ts +3 -0
- package/utils/toml.js +31 -0
- package/utils/with-root.d.ts +1 -0
- package/utils/with-root.js +6 -0
- package/websocket/client.d.ts +24 -0
- package/websocket/client.js +83 -0
- package/models/file-tree.d.ts +0 -12
- package/tools/__tests__/join.spec.js +0 -24
- package/tools/join-path.d.ts +0 -1
- package/tools/join-path.js +0 -7
- package/tools/mock-server.d.ts +0 -1
- package/tools/mock-server.js +0 -12
- /package/models/{file-cache.js → buffer-store.js} +0 -0
- /package/models/{file-tree.js → buffer.js} +0 -0
- /package/{tools/__tests__/find-files-diff.spec.d.ts → models/colors.js} +0 -0
- /package/{tools/__tests__/find-note-files-diff.spec.d.ts → models/commands-group-store.js} +0 -0
- /package/{tools/__tests__/get-file-name.spec.d.ts → models/commands-store.js} +0 -0
- /package/{tools/__tests__/get-string-path.spec.d.ts → models/completion-store.js} +0 -0
- /package/{tools/__tests__/is-gpg-encrypted.spec.d.ts → models/config-store.js} +0 -0
- /package/{tools/__tests__/is-org-file.spec.d.ts → models/confirmation-modal.js} +0 -0
- /package/{tools/__tests__/join.spec.d.ts → models/context-menu-store.js} +0 -0
- /package/{tools/__tests__/parent-folder.spec.d.ts → models/cron-store.js} +0 -0
- /package/{tools/__tests__/read-org-files-recursively.spec.d.ts → models/cron-task.js} +0 -0
- /package/{tools/__tests__/split-path.spec.d.ts → models/css-utils.js} +0 -0
- /package/{tools → utils}/__tests__/get-file-name.spec.js +0 -0
- /package/{tools → utils}/__tests__/get-string-path.spec.js +0 -0
- /package/{tools → utils}/__tests__/is-gpg-encrypted.spec.js +0 -0
- /package/{tools → utils}/__tests__/is-org-file.spec.js +0 -0
- /package/{tools → utils}/__tests__/parent-folder.spec.js +0 -0
- /package/{tools → utils}/__tests__/read-org-files-recursively.spec.js +0 -0
- /package/{tools → utils}/__tests__/split-path.spec.js +0 -0
- /package/{tools → utils}/find-notes-files-diff.d.ts +0 -0
- /package/{tools → utils}/get-file-name.d.ts +0 -0
- /package/{tools → utils}/get-file-name.js +0 -0
- /package/{tools → utils}/get-parent-dir.d.ts +0 -0
- /package/{tools → utils}/get-parent-dir.js +0 -0
- /package/{tools → utils}/get-string-path.d.ts +0 -0
- /package/{tools → utils}/get-string-path.js +0 -0
- /package/{tools → utils}/is-gpg-encrypted.d.ts +0 -0
- /package/{tools → utils}/is-gpg-encrypted.js +0 -0
- /package/{tools → utils}/is-org-file.d.ts +0 -0
- /package/{tools → utils}/is-org-file.js +0 -0
- /package/{tools → utils}/split-path.d.ts +0 -0
- /package/{tools → utils}/split-path.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { encryptViaKeys, decryptViaKeys, encryptViaPassword, decryptViaPassword, NoKeysProvidedError, NoPasswordProvidedError, IncorrectOrMissingPrivateKeyPasswordError, encrypt, decrypt, armor, unarmor, ImpossibleToDecryptWithProvidedKeysError, } from "../encryption.js";
|
|
2
2
|
import { test, expect } from 'vitest';
|
|
3
3
|
import { armoredPublicKey, armoredPrivateKey, privateKeyPassphrase, } from "./encryption-keys.js";
|
|
4
|
-
import {
|
|
4
|
+
import { EncryptionType } from "../../models/encryption.js";
|
|
5
5
|
test('Should encrypt text as armored message via keys', async () => {
|
|
6
6
|
const res = await encryptViaKeys({
|
|
7
|
-
type:
|
|
7
|
+
type: EncryptionType.GpgKeys,
|
|
8
8
|
content: 'Hello world',
|
|
9
9
|
publicKey: armoredPublicKey,
|
|
10
10
|
privateKey: armoredPrivateKey,
|
|
@@ -15,7 +15,7 @@ test('Should encrypt text as armored message via keys', async () => {
|
|
|
15
15
|
});
|
|
16
16
|
test('Should encrypt text via keys', async () => {
|
|
17
17
|
const res = await encryptViaKeys({
|
|
18
|
-
type:
|
|
18
|
+
type: EncryptionType.GpgKeys,
|
|
19
19
|
content: 'Hello world',
|
|
20
20
|
publicKey: armoredPublicKey,
|
|
21
21
|
privateKey: armoredPrivateKey,
|
|
@@ -66,7 +66,7 @@ YQ==
|
|
|
66
66
|
test('Should encrypt via password', async () => {
|
|
67
67
|
const password = 'test';
|
|
68
68
|
const res = await encryptViaPassword({
|
|
69
|
-
type:
|
|
69
|
+
type: EncryptionType.GpgPassword,
|
|
70
70
|
content: 'Hello world',
|
|
71
71
|
password,
|
|
72
72
|
format: 'armored',
|
|
@@ -262,7 +262,6 @@ test('Should armor and unarmor encrypted file', async () => {
|
|
|
262
262
|
"-----BEGIN PGP MESSAGE-----
|
|
263
263
|
|
|
264
264
|
SGVsbG8gd29ybGQ=
|
|
265
|
-
=7asC
|
|
266
265
|
-----END PGP MESSAGE-----
|
|
267
266
|
"
|
|
268
267
|
`);
|
|
@@ -1,112 +1,48 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
1
|
+
import { beforeEach, expect, test } from 'vitest';
|
|
2
2
|
import { decryptNote, encryptNote } from "../note-encryption.js";
|
|
3
3
|
import { armoredPublicKey, armoredPrivateKey, privateKeyPassphrase, } from "./encryption-keys.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Hello?`;
|
|
11
|
-
const note = {
|
|
12
|
-
id: 'id',
|
|
13
|
-
meta: {
|
|
14
|
-
title: 'My note title',
|
|
15
|
-
images: [],
|
|
16
|
-
published: false,
|
|
17
|
-
description: 'Awesome description',
|
|
18
|
-
},
|
|
19
|
-
author: {
|
|
20
|
-
id: '1',
|
|
21
|
-
name: 'John Doe',
|
|
22
|
-
email: 'test@mail.com',
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
26
|
-
content: noteText,
|
|
27
|
-
type: 'gpgPassword',
|
|
28
|
-
password: '123',
|
|
29
|
-
format: 'armored',
|
|
30
|
-
});
|
|
31
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
|
|
32
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
4
|
+
import { EncryptionType } from "../../models/encryption.js";
|
|
5
|
+
import { faker } from '@faker-js/faker';
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
faker.seed(1);
|
|
8
|
+
faker.setDefaultRefDate(new Date('2024-01-01T00:00:00.000Z'));
|
|
33
9
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#+TITLE: Hello worlld
|
|
38
|
-
|
|
39
|
-
* Hello?`;
|
|
40
|
-
const note = {
|
|
41
|
-
id: 'id',
|
|
10
|
+
function generateNoteInfo(overrides = {}) {
|
|
11
|
+
return {
|
|
12
|
+
id: faker.string.uuid(),
|
|
42
13
|
meta: {
|
|
43
|
-
title:
|
|
44
|
-
images:
|
|
45
|
-
published:
|
|
46
|
-
description:
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
14
|
+
title: faker.lorem.sentence(),
|
|
15
|
+
images: faker.helpers.uniqueArray(() => faker.image.url(), 3),
|
|
16
|
+
published: faker.datatype.boolean(),
|
|
17
|
+
description: faker.lorem.paragraph(),
|
|
18
|
+
},
|
|
19
|
+
createdAt: faker.date.past().toISOString(),
|
|
20
|
+
updatedAt: faker.date.recent().toISOString(),
|
|
21
|
+
touchedAt: faker.date.recent().toISOString(),
|
|
22
|
+
deletedAt: faker.datatype.boolean()
|
|
23
|
+
? faker.date.recent().toISOString()
|
|
24
|
+
: undefined,
|
|
25
|
+
filePath: faker.helpers.uniqueArray(() => faker.system.filePath(), 2),
|
|
26
|
+
isMy: faker.datatype.boolean(),
|
|
27
|
+
author: faker.datatype.boolean()
|
|
28
|
+
? {
|
|
29
|
+
id: faker.string.uuid(),
|
|
30
|
+
name: faker.person.fullName(),
|
|
31
|
+
email: faker.internet.email(),
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
bookmarked: faker.datatype.boolean(),
|
|
35
|
+
encrypted: faker.datatype.boolean(),
|
|
36
|
+
...overrides,
|
|
53
37
|
};
|
|
54
|
-
|
|
55
|
-
content: noteText,
|
|
56
|
-
type: 'gpgPassword',
|
|
57
|
-
password: '123',
|
|
58
|
-
format: 'binary',
|
|
59
|
-
});
|
|
60
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
61
|
-
expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
|
|
62
|
-
});
|
|
63
|
-
test('Should decrypt note content via password', async () => {
|
|
64
|
-
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
65
|
-
|
|
66
|
-
wy4ECQMI/CCaKMJEqy/gyROJeRgW9I738dDFBltFlxIjhxrN7nQ6gkX4GgX6
|
|
67
|
-
zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
|
|
68
|
-
2k3g68Afayke2nLkDNkH62tdOPiTkx7bSlp1zL4uU440IM1g6dC72JkmtoTJ
|
|
69
|
-
5Bjlwt4ZhxFsh+c=
|
|
70
|
-
=csID
|
|
71
|
-
-----END PGP MESSAGE-----`;
|
|
72
|
-
const note = {
|
|
73
|
-
id: 'id',
|
|
74
|
-
meta: {
|
|
75
|
-
title: 'My note title',
|
|
76
|
-
images: [],
|
|
77
|
-
published: false,
|
|
78
|
-
description: 'Awesome description',
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
const decryptedNote = await decryptNote(note, {
|
|
82
|
-
content: noteText,
|
|
83
|
-
type: 'gpgPassword',
|
|
84
|
-
password: '123',
|
|
85
|
-
});
|
|
86
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
87
|
-
});
|
|
38
|
+
}
|
|
88
39
|
test('Should encrypt note via keys', async () => {
|
|
89
|
-
const noteText =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* Hello?`;
|
|
93
|
-
const note = {
|
|
94
|
-
id: 'id',
|
|
95
|
-
meta: {
|
|
96
|
-
title: 'My note title for encryption via keys',
|
|
97
|
-
images: [],
|
|
98
|
-
published: false,
|
|
99
|
-
description: 'Awesome description',
|
|
100
|
-
},
|
|
101
|
-
author: {
|
|
102
|
-
id: '1',
|
|
103
|
-
name: 'John Doe',
|
|
104
|
-
email: 'test@mail.com',
|
|
105
|
-
},
|
|
106
|
-
};
|
|
40
|
+
const noteText = '#+title: Test note\n\nBody text';
|
|
41
|
+
const note = generateNoteInfo();
|
|
42
|
+
note.meta.published = false;
|
|
107
43
|
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
108
44
|
content: noteText,
|
|
109
|
-
type:
|
|
45
|
+
type: EncryptionType.GpgKeys,
|
|
110
46
|
publicKey: armoredPublicKey,
|
|
111
47
|
privateKey: armoredPrivateKey,
|
|
112
48
|
privateKeyPassphrase,
|
|
@@ -115,251 +51,24 @@ test('Should encrypt note via keys', async () => {
|
|
|
115
51
|
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
|
|
116
52
|
expect(encryptedNote).toMatchSnapshot();
|
|
117
53
|
});
|
|
118
|
-
test('Should decrypt note via
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
0KW88Nr435S6n6mVw/zpitXIgEKpkqh46mhG+1W3aC0lYx6j9lHm3bjtdb4r
|
|
126
|
-
2mtZbWKwfdBggEy8qEeiUeslvKd6uWtEccomzFgJkaqWVGknLmrBdHfztRIV
|
|
127
|
-
fbZhxHz+J3GFOIgXf/5+fv+zg0nTazgz1mDUfnTHw3+qcAyEJ0ADdyg9EZc+
|
|
128
|
-
bKbK0GwzMDPQeM+cCRDWUTiIa1ruyEETiwMdhWUDztF8XxY2o8jXPerZ0NhG
|
|
129
|
-
R8l+SvAdYQQXPfxEh9lA3thkyz/Vp72pW46lUeJHGSq/fS6KIdLHLP9Z2e1J
|
|
130
|
-
aCFpNMgyAN+BaXwnbLZfz6k5hV8awbRScSWQLEg69D9b287SFDPOYW7OZikn
|
|
131
|
-
CKXL7xyQ5LrWJZN9Z/UPGjy+PdEw1SBhyluW6DQ+Sz1j4K8USTLqY89EInDl
|
|
132
|
-
G7AxHGujR9UkUGyUvvc71XW7jEOogiDgn1ZMoj9Y58LSweUB8vfkY3VF84Fy
|
|
133
|
-
zGVvLFWnFbtnWuoQC4OOXv1F6ETdmEsSMEMWKzRLDGPyqNX7FhG3cejlEuiK
|
|
134
|
-
EsT5oQhz00RECmnR8mJkGmJhzWmmeoQvaucFqhTOZjvYl9ivuEMBZ2jtkdHn
|
|
135
|
-
R6UNcNZRpCbfnl7YoikqbGBgqDFYydFGHXKHDpYhcQYWJsMDUayzUiPtzmaE
|
|
136
|
-
tgfTgNNqgPxkLnWA99KYNU8DH+FwgaYBuw9dwdqwcjxSbZjHhCFGUfsqM+ik
|
|
137
|
-
O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
|
|
138
|
-
sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
|
|
139
|
-
Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
|
|
140
|
-
LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
|
|
141
|
-
+ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
|
|
142
|
-
p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
|
|
143
|
-
gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
|
|
144
|
-
AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
|
|
145
|
-
cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
146
|
-
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
147
|
-
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
148
|
-
=LjkG
|
|
149
|
-
-----END PGP MESSAGE-----`;
|
|
150
|
-
const note = {
|
|
151
|
-
id: 'id',
|
|
152
|
-
meta: {
|
|
153
|
-
title: 'My note title for decryption via keys',
|
|
154
|
-
images: [],
|
|
155
|
-
published: false,
|
|
156
|
-
description: 'Awesome description',
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
const decryptedNote = await decryptNote(note, {
|
|
160
|
-
content: encryptedNoteText,
|
|
161
|
-
type: 'gpgKeys',
|
|
54
|
+
test('Should decrypt note via keys', async () => {
|
|
55
|
+
const noteText = '#+title: Test note\n\nBody text';
|
|
56
|
+
const note = generateNoteInfo();
|
|
57
|
+
note.meta.published = false;
|
|
58
|
+
const [, encryptedNoteText] = await encryptNote(note, {
|
|
59
|
+
content: noteText,
|
|
60
|
+
type: EncryptionType.GpgKeys,
|
|
162
61
|
publicKey: armoredPublicKey,
|
|
163
62
|
privateKey: armoredPrivateKey,
|
|
164
63
|
privateKeyPassphrase,
|
|
165
|
-
});
|
|
166
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
167
|
-
});
|
|
168
|
-
test('Should not encrypt public note', async () => {
|
|
169
|
-
const noteText = `#+ID: qweqwe
|
|
170
|
-
#+TITLE: Hello worlld
|
|
171
|
-
|
|
172
|
-
* Hello?`;
|
|
173
|
-
const note = {
|
|
174
|
-
id: 'id',
|
|
175
|
-
meta: {
|
|
176
|
-
title: 'My note title',
|
|
177
|
-
images: [],
|
|
178
|
-
published: true,
|
|
179
|
-
description: 'Awesome description',
|
|
180
|
-
},
|
|
181
|
-
author: {
|
|
182
|
-
id: '1',
|
|
183
|
-
name: 'John Doe',
|
|
184
|
-
email: 'test@mail.com',
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
188
|
-
content: noteText,
|
|
189
|
-
type: 'gpgPassword',
|
|
190
|
-
password: '123',
|
|
191
64
|
format: 'armored',
|
|
192
65
|
});
|
|
193
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(false);
|
|
194
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
195
|
-
});
|
|
196
|
-
test('Should encrypt note with empty encrypted property', async () => {
|
|
197
|
-
const noteText = `#+ID: qweqwe
|
|
198
|
-
#+TITLE: Hello worlld
|
|
199
|
-
|
|
200
|
-
* Hello?`;
|
|
201
|
-
const note = {
|
|
202
|
-
id: 'id',
|
|
203
|
-
meta: {
|
|
204
|
-
title: 'My note title',
|
|
205
|
-
images: [],
|
|
206
|
-
published: false,
|
|
207
|
-
description: 'Awesome description',
|
|
208
|
-
},
|
|
209
|
-
author: {
|
|
210
|
-
id: '1',
|
|
211
|
-
name: 'John Doe',
|
|
212
|
-
email: 'test@mail.com',
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
216
|
-
content: noteText,
|
|
217
|
-
type: 'gpgPassword',
|
|
218
|
-
password: '123',
|
|
219
|
-
format: 'armored',
|
|
220
|
-
});
|
|
221
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
|
|
222
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
223
|
-
});
|
|
224
|
-
test('Should not decrypt note without provided encrypted type', async () => {
|
|
225
|
-
const noteText = `#+ID: qweqwe
|
|
226
|
-
#+TITLE: Hello worlld
|
|
227
|
-
|
|
228
|
-
* Hello?`;
|
|
229
|
-
const note = {
|
|
230
|
-
id: 'id',
|
|
231
|
-
meta: {
|
|
232
|
-
title: 'My note title',
|
|
233
|
-
images: [],
|
|
234
|
-
published: false,
|
|
235
|
-
description: 'Awesome description',
|
|
236
|
-
},
|
|
237
|
-
encrypted: undefined,
|
|
238
|
-
author: {
|
|
239
|
-
id: '1',
|
|
240
|
-
name: 'John Doe',
|
|
241
|
-
email: 'test@mail.com',
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
const decryptedInfo = await decryptNote(note, {
|
|
245
|
-
content: noteText,
|
|
246
|
-
type: 'gpgPassword',
|
|
247
|
-
password: '123',
|
|
248
|
-
});
|
|
249
|
-
expect(decryptedInfo).toMatchSnapshot();
|
|
250
|
-
});
|
|
251
|
-
test('Should decrypt note and note meta', async () => {
|
|
252
|
-
const meta = {
|
|
253
|
-
title: 'My note title',
|
|
254
|
-
images: ['./image1.png'],
|
|
255
|
-
published: false,
|
|
256
|
-
description: 'Awesome description',
|
|
257
|
-
fileTags: ['tag1', 'tag2'],
|
|
258
|
-
};
|
|
259
|
-
const note = {
|
|
260
|
-
id: 'id',
|
|
261
|
-
meta: { ...meta },
|
|
262
|
-
};
|
|
263
|
-
const noteText = `#+TITLE: My note title
|
|
264
|
-
#+DESCRIPTION: Awesome description
|
|
265
|
-
#+PUBLISHED: false
|
|
266
|
-
#+FILETAGS: :tag1:tag2:
|
|
267
|
-
|
|
268
|
-
[[./image1.png]]
|
|
269
|
-
|
|
270
|
-
Hello world`;
|
|
271
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
272
|
-
content: noteText,
|
|
273
|
-
type: 'gpgPassword',
|
|
274
|
-
password: '123',
|
|
275
|
-
});
|
|
276
|
-
const [decryptedNote, decryptedNoteText] = await decryptNote(encryptedNote, {
|
|
277
|
-
content: encryptedNoteText,
|
|
278
|
-
type: 'gpgPassword',
|
|
279
|
-
password: '123',
|
|
280
|
-
});
|
|
281
|
-
expect(decryptedNote.meta).toEqual(meta);
|
|
282
|
-
expect(decryptedNoteText).toEqual(noteText);
|
|
283
|
-
});
|
|
284
|
-
test('Should set not encrypted status when params type does not provided', async () => {
|
|
285
|
-
const note = {
|
|
286
|
-
id: 'id',
|
|
287
|
-
meta: {
|
|
288
|
-
title: 'My note title for decryption via keys',
|
|
289
|
-
images: [],
|
|
290
|
-
published: false,
|
|
291
|
-
description: 'Awesome description',
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
295
|
-
|
|
296
|
-
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|
|
297
|
-
+CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
|
|
298
|
-
gfe2f/6zsge9ux+mXF2BG4z+V5T8XIOrfzxosVprdJHZHM3x7cW5USQ0t2i2
|
|
299
|
-
FiOUWxSZO1899J3yICpMvhDXvTLVZuKpSNQho5PyXSeZa83eN+uYkhgt9lsk
|
|
300
|
-
0KW88Nr435S6n6mVw/zpitXIgEKpkqh46mhG+1W3aC0lYx6j9lHm3bjtdb4r
|
|
301
|
-
2mtZbWKwfdBggEy8qEeiUeslvKd6uWtEccomzFgJkaqWVGknLmrBdHfztRIV
|
|
302
|
-
fbZhxHz+J3GFOIgXf/5+fv+zg0nTazgz1mDUfnTHw3+qcAyEJ0ADdyg9EZc+
|
|
303
|
-
bKbK0GwzMDPQeM+cCRDWUTiIa1ruyEETiwMdhWUDztF8XxY2o8jXPerZ0NhG
|
|
304
|
-
R8l+SvAdYQQXPfxEh9lA3thkyz/Vp72pW46lUeJHGSq/fS6KIdLHLP9Z2e1J
|
|
305
|
-
aCFpNMgyAN+BaXwnbLZfz6k5hV8awbRScSWQLEg69D9b287SFDPOYW7OZikn
|
|
306
|
-
CKXL7xyQ5LrWJZN9Z/UPGjy+PdEw1SBhyluW6DQ+Sz1j4K8USTLqY89EInDl
|
|
307
|
-
G7AxHGujR9UkUGyUvvc71XW7jEOogiDgn1ZMoj9Y58LSweUB8vfkY3VF84Fy
|
|
308
|
-
zGVvLFWnFbtnWuoQC4OOXv1F6ETdmEsSMEMWKzRLDGPyqNX7FhG3cejlEuiK
|
|
309
|
-
EsT5oQhz00RECmnR8mJkGmJhzWmmeoQvaucFqhTOZjvYl9ivuEMBZ2jtkdHn
|
|
310
|
-
R6UNcNZRpCbfnl7YoikqbGBgqDFYydFGHXKHDpYhcQYWJsMDUayzUiPtzmaE
|
|
311
|
-
tgfTgNNqgPxkLnWA99KYNU8DH+FwgaYBuw9dwdqwcjxSbZjHhCFGUfsqM+ik
|
|
312
|
-
O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
|
|
313
|
-
sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
|
|
314
|
-
Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
|
|
315
|
-
LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
|
|
316
|
-
+ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
|
|
317
|
-
p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
|
|
318
|
-
gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
|
|
319
|
-
AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
|
|
320
|
-
cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
321
|
-
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
322
|
-
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
323
|
-
=LjkG
|
|
324
|
-
-----END PGP MESSAGE-----`;
|
|
325
66
|
const decryptedNote = await decryptNote(note, {
|
|
326
|
-
content: noteText,
|
|
327
|
-
type: 'disabled',
|
|
328
|
-
});
|
|
329
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
330
|
-
});
|
|
331
|
-
test('Should encrypt note to binary format', async () => {
|
|
332
|
-
const noteText = `#+ID: qweqwe
|
|
333
|
-
#+TITLE: Hello worlld
|
|
334
|
-
|
|
335
|
-
* Hello?`;
|
|
336
|
-
const note = {
|
|
337
|
-
id: 'id',
|
|
338
|
-
meta: {
|
|
339
|
-
title: 'My note title',
|
|
340
|
-
images: [],
|
|
341
|
-
published: false,
|
|
342
|
-
description: 'Awesome description',
|
|
343
|
-
},
|
|
344
|
-
author: {
|
|
345
|
-
id: '1',
|
|
346
|
-
name: 'John Doe',
|
|
347
|
-
email: 'test@mail.com',
|
|
348
|
-
},
|
|
349
|
-
};
|
|
350
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
351
|
-
content: noteText,
|
|
352
|
-
type: 'gpgPassword',
|
|
353
|
-
password: '123',
|
|
354
|
-
format: 'binary',
|
|
355
|
-
});
|
|
356
|
-
expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
|
|
357
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
358
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
359
|
-
const [_, decryptedNoteText] = await decryptNote(encryptedNote, {
|
|
360
67
|
content: encryptedNoteText,
|
|
361
|
-
type:
|
|
362
|
-
|
|
68
|
+
type: EncryptionType.GpgKeys,
|
|
69
|
+
publicKey: armoredPublicKey,
|
|
70
|
+
privateKey: armoredPrivateKey,
|
|
71
|
+
privateKeyPassphrase,
|
|
363
72
|
});
|
|
364
|
-
expect(
|
|
73
|
+
expect(decryptedNote).toMatchSnapshot();
|
|
365
74
|
});
|
|
@@ -3,19 +3,24 @@ import { OrgNoteEncryption, OrgNotePasswordEncryption, WithDecryptionContent } f
|
|
|
3
3
|
import { OrgNoteGpgEncryption, WithEncryptionContent } from '../models/index.js';
|
|
4
4
|
import { enums } from 'openpgp';
|
|
5
5
|
export declare class IncorrectOrMissingPrivateKeyPasswordError extends Error {
|
|
6
|
+
constructor(message?: string);
|
|
6
7
|
}
|
|
7
8
|
export declare class ImpossibleToDecryptWithProvidedKeysError extends Error {
|
|
9
|
+
constructor(message?: string);
|
|
8
10
|
}
|
|
9
11
|
export declare class IncorrectEncryptionPasswordError extends Error {
|
|
12
|
+
constructor(message?: string);
|
|
10
13
|
}
|
|
11
14
|
export declare class NoKeysProvidedError extends Error {
|
|
15
|
+
constructor(message?: string);
|
|
12
16
|
}
|
|
13
17
|
export declare class NoPasswordProvidedError extends Error {
|
|
18
|
+
constructor(message?: string);
|
|
14
19
|
}
|
|
15
|
-
export declare const encryptViaKeys: <T extends WithEncryptionContent<OrgNoteGpgEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
16
|
-
export declare const encryptViaPassword: <T extends WithEncryptionContent<OrgNotePasswordEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
17
|
-
export declare const decryptViaPassword: <T extends Omit<WithDecryptionContent<OrgNotePasswordEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
18
|
-
export declare const decryptViaKeys: <T extends Omit<WithDecryptionContent<OrgNoteGpgEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
20
|
+
export declare const encryptViaKeys: <T extends WithEncryptionContent<OrgNoteGpgEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array<ArrayBufferLike> : string>;
|
|
21
|
+
export declare const encryptViaPassword: <T extends WithEncryptionContent<OrgNotePasswordEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array<ArrayBufferLike> : string>;
|
|
22
|
+
export declare const decryptViaPassword: <T extends Omit<WithDecryptionContent<OrgNotePasswordEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array<ArrayBufferLike> : string>;
|
|
23
|
+
export declare const decryptViaKeys: <T extends Omit<WithDecryptionContent<OrgNoteGpgEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array<ArrayBufferLike> : string>;
|
|
19
24
|
export declare const encrypt: <T extends WithEncryptionContent<OrgNoteEncryption>>(encryptionParams: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
20
25
|
export declare const decrypt: <T extends WithDecryptionContent<OrgNoteEncryption>>(decryptionParams: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
|
|
21
26
|
export declare function _encryptViaKeys<T extends WithEncryptionContent<OrgNoteGpgEncryption>>({ content, publicKey: armoredPublicKey, privateKey: armoredPrivateKey, privateKeyPassphrase, format, }: T): Promise<T['format'] extends 'binary' ? Uint8Array : string>;
|
package/encryption/encryption.js
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { createMessage, decrypt as _decrypt, decryptKey, encrypt as _encrypt, readKey, readMessage, readPrivateKey, } from 'openpgp';
|
|
2
|
-
import {
|
|
2
|
+
import { EncryptionType, } from "../models/encryption.js";
|
|
3
3
|
import { armor as _armor, unarmor as _unarmor, enums } from 'openpgp';
|
|
4
4
|
export class IncorrectOrMissingPrivateKeyPasswordError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'IncorrectOrMissingPrivateKeyPasswordError';
|
|
8
|
+
}
|
|
5
9
|
}
|
|
6
10
|
export class ImpossibleToDecryptWithProvidedKeysError extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'ImpossibleToDecryptWithProvidedKeysError';
|
|
14
|
+
}
|
|
7
15
|
}
|
|
8
16
|
export class IncorrectEncryptionPasswordError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'IncorrectEncryptionPasswordError';
|
|
20
|
+
}
|
|
9
21
|
}
|
|
10
22
|
export class NoKeysProvidedError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'NoKeysProvidedError';
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
28
|
export class NoPasswordProvidedError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'NoPasswordProvidedError';
|
|
32
|
+
}
|
|
13
33
|
}
|
|
14
34
|
const noPrivateKeyPassphraseProvidedErrorMsg = 'Error: Signing key is not decrypted.';
|
|
15
35
|
const incorrectPrivateKeyPassphraseErrorMsg = 'Error decrypting private key: Incorrect key passphrase';
|
|
@@ -26,24 +46,24 @@ export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
|
|
|
26
46
|
export const decryptViaKeys = withCustomErrors(_decryptViaKeys);
|
|
27
47
|
export const encrypt = async (encryptionParams) => {
|
|
28
48
|
if (!encryptionParams.type ||
|
|
29
|
-
encryptionParams.type ===
|
|
49
|
+
encryptionParams.type === EncryptionType.Disabled) {
|
|
30
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
51
|
return encryptionParams.content;
|
|
32
52
|
}
|
|
33
53
|
const res = (encryptionParams.type ===
|
|
34
|
-
|
|
54
|
+
EncryptionType.GpgKeys
|
|
35
55
|
? await encryptViaKeys(encryptionParams)
|
|
36
56
|
: await encryptViaPassword(encryptionParams));
|
|
37
57
|
return res;
|
|
38
58
|
};
|
|
39
59
|
export const decrypt = async (decryptionParams) => {
|
|
40
60
|
if (!decryptionParams.type ||
|
|
41
|
-
decryptionParams.type ===
|
|
61
|
+
decryptionParams.type === EncryptionType.Disabled) {
|
|
42
62
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
63
|
return decryptionParams.content;
|
|
44
64
|
}
|
|
45
65
|
const decryptedNote = (decryptionParams.type ===
|
|
46
|
-
|
|
66
|
+
EncryptionType.GpgKeys
|
|
47
67
|
? await decryptViaKeys(decryptionParams)
|
|
48
68
|
: await decryptViaPassword(decryptionParams));
|
|
49
69
|
return decryptedNote;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ModelsPublicNoteEncryptionTypeEnum } from "../remote-api/index.js";
|
|
2
1
|
import { decrypt, encrypt } from "./encryption.js";
|
|
2
|
+
import { EncryptionType } from "../models/encryption.js";
|
|
3
3
|
import { parse, withMetaInfo } from 'org-mode-ast';
|
|
4
4
|
import { isGpgEncrypted } from '../index.js';
|
|
5
5
|
// TODO: master change signature for encrypt notes without content
|
|
6
6
|
export async function encryptNote(note, encryptionParams) {
|
|
7
7
|
note.encrypted = false;
|
|
8
8
|
if (!encryptionParams.type ||
|
|
9
|
-
encryptionParams.type ===
|
|
10
|
-
note.meta
|
|
9
|
+
encryptionParams.type === EncryptionType.Disabled ||
|
|
10
|
+
note.meta?.published) {
|
|
11
11
|
return [note, encryptionParams.content];
|
|
12
12
|
}
|
|
13
|
-
note.meta = { id: note.meta
|
|
13
|
+
note.meta = { id: note.meta?.id, published: note.meta?.published };
|
|
14
14
|
const encryptedContent = await encrypt(encryptionParams);
|
|
15
15
|
const encryptedNote = { ...note, encrypted: true };
|
|
16
16
|
return [encryptedNote, encryptedContent];
|
|
17
17
|
}
|
|
18
18
|
export async function decryptNote(note, encryptionParams) {
|
|
19
19
|
const isContentEncrypted = isGpgEncrypted(encryptionParams.content);
|
|
20
|
-
if (note.meta
|
|
20
|
+
if (note.meta?.published ||
|
|
21
21
|
!encryptionParams.type ||
|
|
22
|
-
encryptionParams.type ===
|
|
22
|
+
encryptionParams.type === EncryptionType.Disabled ||
|
|
23
23
|
!isContentEncrypted) {
|
|
24
24
|
note.encrypted = isContentEncrypted;
|
|
25
25
|
return [note, encryptionParams.content];
|
package/files-api.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ export * from './api.js';
|
|
|
2
2
|
export * from './models/index.js';
|
|
3
3
|
import type * as ast from 'org-mode-ast';
|
|
4
4
|
export * from './encryption/index.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './utils/index.js';
|
|
6
6
|
export * from './files-api.js';
|
|
7
7
|
export * from './mappers/index.js';
|
|
8
8
|
export * from './constants/index.js';
|
|
9
|
+
export * from './utils/with-root.js';
|
|
10
|
+
export * from './sync/index.js';
|
|
9
11
|
export { ast };
|
|
12
|
+
export * from './websocket/client.js';
|
package/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from "./api.js";
|
|
2
2
|
export * from "./models/index.js";
|
|
3
3
|
export * from "./encryption/index.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./utils/index.js";
|
|
5
5
|
export * from "./files-api.js";
|
|
6
6
|
export * from "./mappers/index.js";
|
|
7
7
|
export * from "./constants/index.js";
|
|
8
|
+
export * from "./utils/with-root.js";
|
|
9
|
+
export * from "./sync/index.js";
|
|
10
|
+
export * from "./websocket/client.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OrgNode } from 'org-mode-ast';
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
2
|
+
import { DiskFile, NoteInfo } from "../models/index.js";
|
|
3
|
+
export declare function orgnodeToNoteInfo(orgnode: OrgNode, fileInfo: DiskFile, isMy?: boolean): NoteInfo;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { splitPath } from "../
|
|
2
|
-
export function
|
|
1
|
+
import { splitPath } from "../utils/index.js";
|
|
2
|
+
export function orgnodeToNoteInfo(orgnode, fileInfo, isMy) {
|
|
3
3
|
return {
|
|
4
4
|
id: orgnode.meta.id,
|
|
5
|
+
isMy,
|
|
5
6
|
meta: orgnode.meta,
|
|
6
7
|
filePath: splitPath(fileInfo.path),
|
|
7
8
|
touchedAt: fileInfo.atime && new Date(fileInfo.atime).toISOString(),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type InferOutput } from 'valibot';
|
|
2
|
+
export declare const AUTH_ENVIRONMENTS: readonly ["web", "mobile", "electron", "desktop"];
|
|
3
|
+
export type AuthEnvironment = (typeof AUTH_ENVIRONMENTS)[number];
|
|
4
|
+
export declare const AUTH_ENVIRONMENT_SCHEMA: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"web", undefined>, import("valibot").LiteralSchema<"mobile", undefined>, import("valibot").LiteralSchema<"electron", undefined>, import("valibot").LiteralSchema<"desktop", undefined>], undefined>;
|
|
5
|
+
export declare const AUTH_STATE_SCHEMA: import("valibot").ObjectSchema<{
|
|
6
|
+
readonly environment: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"web", undefined>, import("valibot").LiteralSchema<"mobile", undefined>, import("valibot").LiteralSchema<"electron", undefined>, import("valibot").LiteralSchema<"desktop", undefined>], undefined>;
|
|
7
|
+
readonly redirectUrl: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
8
|
+
}, undefined>;
|
|
9
|
+
export type AuthState = InferOutput<typeof AUTH_STATE_SCHEMA>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { literal, object, optional, string, union, } from 'valibot';
|
|
2
|
+
export const AUTH_ENVIRONMENTS = ['web', 'mobile', 'electron', 'desktop'];
|
|
3
|
+
export const AUTH_ENVIRONMENT_SCHEMA = union([
|
|
4
|
+
literal('web'),
|
|
5
|
+
literal('mobile'),
|
|
6
|
+
literal('electron'),
|
|
7
|
+
literal('desktop'),
|
|
8
|
+
]);
|
|
9
|
+
export const AUTH_STATE_SCHEMA = object({
|
|
10
|
+
environment: AUTH_ENVIRONMENT_SCHEMA,
|
|
11
|
+
redirectUrl: optional(string()),
|
|
12
|
+
});
|