orgnote-api 0.17.1 → 0.17.2

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 (134) hide show
  1. package/dist/api.d.ts +112 -0
  2. package/dist/api.js +1 -0
  3. package/dist/encryption/__tests__/encryption-keys.d.ts +3 -0
  4. package/{encryption/__tests__/encryption-keys.ts → dist/encryption/__tests__/encryption-keys.js} +0 -2
  5. package/dist/encryption/__tests__/encryption.spec.d.ts +1 -0
  6. package/dist/encryption/__tests__/encryption.spec.js +287 -0
  7. package/dist/encryption/__tests__/note-encryption.spec.d.ts +1 -0
  8. package/dist/encryption/__tests__/note-encryption.spec.js +364 -0
  9. package/dist/encryption/encryption.d.ts +27 -0
  10. package/dist/encryption/encryption.js +156 -0
  11. package/dist/encryption/index.js +2 -0
  12. package/dist/encryption/note-encryption.d.ts +12 -0
  13. package/dist/encryption/note-encryption.js +42 -0
  14. package/dist/files-api.d.ts +7 -0
  15. package/dist/files-api.js +22 -0
  16. package/dist/index.js +5 -0
  17. package/dist/models/command.d.ts +29 -0
  18. package/dist/models/command.js +1 -0
  19. package/dist/models/completion.d.ts +22 -0
  20. package/dist/models/completion.js +1 -0
  21. package/dist/models/default-commands.d.ts +30 -0
  22. package/dist/models/default-commands.js +41 -0
  23. package/dist/models/editor.d.ts +23 -0
  24. package/dist/models/editor.js +1 -0
  25. package/dist/models/encryption.d.ts +31 -0
  26. package/dist/models/encryption.js +1 -0
  27. package/dist/models/extension.d.ts +34 -0
  28. package/dist/models/extension.js +1 -0
  29. package/dist/models/file-system.d.ts +23 -0
  30. package/dist/models/file-system.js +1 -0
  31. package/dist/models/index.js +13 -0
  32. package/dist/models/modal.d.ts +10 -0
  33. package/dist/models/modal.js +1 -0
  34. package/dist/models/note.d.ts +23 -0
  35. package/dist/models/note.js +1 -0
  36. package/dist/models/sync.d.ts +34 -0
  37. package/dist/models/sync.js +1 -0
  38. package/dist/models/theme-variables.d.ts +192 -0
  39. package/dist/models/theme-variables.js +194 -0
  40. package/{models/vue-component.ts → dist/models/vue-component.d.ts} +1 -1
  41. package/dist/models/vue-component.js +1 -0
  42. package/dist/models/widget-type.d.ts +5 -0
  43. package/dist/models/widget-type.js +6 -0
  44. package/dist/models/widget.d.ts +51 -0
  45. package/dist/models/widget.js +1 -0
  46. package/dist/remote-api/api.d.ts +1525 -0
  47. package/{remote-api/api.ts → dist/remote-api/api.js} +246 -1149
  48. package/dist/remote-api/base.d.ts +66 -0
  49. package/{remote-api/base.ts → dist/remote-api/base.js} +13 -36
  50. package/dist/remote-api/common.d.ts +65 -0
  51. package/{remote-api/common.ts → dist/remote-api/common.js} +31 -48
  52. package/{remote-api/configuration.ts → dist/remote-api/configuration.d.ts} +3 -22
  53. package/dist/remote-api/configuration.js +95 -0
  54. package/dist/remote-api/index.d.ts +13 -0
  55. package/{remote-api/index.ts → dist/remote-api/index.js} +0 -3
  56. package/dist/tools/__tests__/find-files-diff.spec.d.ts +1 -0
  57. package/dist/tools/__tests__/find-files-diff.spec.js +110 -0
  58. package/dist/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
  59. package/dist/tools/__tests__/find-note-files-diff.spec.js +168 -0
  60. package/dist/tools/__tests__/get-file-name.spec.d.ts +1 -0
  61. package/{tools/__tests__/get-file-name.spec.ts → dist/tools/__tests__/get-file-name.spec.js} +4 -8
  62. package/dist/tools/__tests__/get-string-path.spec.d.ts +1 -0
  63. package/dist/tools/__tests__/get-string-path.spec.js +27 -0
  64. package/dist/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
  65. package/{tools/__tests__/is-gpg-encrypted.spec.ts → dist/tools/__tests__/is-gpg-encrypted.spec.js} +4 -8
  66. package/dist/tools/__tests__/is-org-file.spec.d.ts +1 -0
  67. package/dist/tools/__tests__/is-org-file.spec.js +54 -0
  68. package/dist/tools/__tests__/join.spec.d.ts +1 -0
  69. package/dist/tools/__tests__/join.spec.js +14 -0
  70. package/dist/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
  71. package/dist/tools/__tests__/read-org-files-recursively.spec.js +51 -0
  72. package/dist/tools/extend-notes-files-diff.d.ts +3 -0
  73. package/dist/tools/extend-notes-files-diff.js +21 -0
  74. package/dist/tools/find-notes-files-diff.d.ts +5 -0
  75. package/dist/tools/find-notes-files-diff.js +108 -0
  76. package/dist/tools/get-file-name.d.ts +2 -0
  77. package/dist/tools/get-file-name.js +6 -0
  78. package/dist/tools/get-string-path.d.ts +1 -0
  79. package/dist/tools/get-string-path.js +6 -0
  80. package/dist/tools/index.js +6 -0
  81. package/dist/tools/is-gpg-encrypted.d.ts +1 -0
  82. package/dist/tools/is-gpg-encrypted.js +6 -0
  83. package/dist/tools/is-org-file.d.ts +2 -0
  84. package/dist/tools/is-org-file.js +4 -0
  85. package/dist/tools/join.d.ts +1 -0
  86. package/dist/tools/join.js +3 -0
  87. package/dist/tools/mock-server.d.ts +1 -0
  88. package/dist/tools/mock-server.js +12 -0
  89. package/package.json +6 -14
  90. package/api.ts +0 -123
  91. package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -215
  92. package/encryption/__tests__/encryption.spec.ts +0 -355
  93. package/encryption/__tests__/note-encryption.spec.ts +0 -424
  94. package/encryption/encryption.ts +0 -265
  95. package/encryption/note-encryption.ts +0 -78
  96. package/files-api.ts +0 -25
  97. package/models/command.ts +0 -45
  98. package/models/completion.ts +0 -30
  99. package/models/default-commands.ts +0 -44
  100. package/models/editor.ts +0 -27
  101. package/models/encryption.ts +0 -54
  102. package/models/extension.ts +0 -45
  103. package/models/file-system.ts +0 -30
  104. package/models/modal.ts +0 -12
  105. package/models/note.ts +0 -26
  106. package/models/sync.ts +0 -43
  107. package/models/theme-variables.ts +0 -194
  108. package/models/widget-type.ts +0 -5
  109. package/models/widget.ts +0 -59
  110. package/remote-api/.gitignore +0 -4
  111. package/remote-api/.npmignore +0 -1
  112. package/remote-api/.openapi-generator/FILES +0 -8
  113. package/remote-api/.openapi-generator/VERSION +0 -1
  114. package/remote-api/.openapi-generator-ignore +0 -23
  115. package/remote-api/git_push.sh +0 -57
  116. package/tools/__tests__/__snapshots__/join.spec.ts.snap +0 -9
  117. package/tools/__tests__/find-files-diff.spec.ts +0 -177
  118. package/tools/__tests__/find-note-files-diff.spec.ts +0 -207
  119. package/tools/__tests__/get-string-path.spec.ts +0 -32
  120. package/tools/__tests__/is-org-file.spec.ts +0 -62
  121. package/tools/__tests__/join.spec.ts +0 -16
  122. package/tools/__tests__/read-org-files-recursively.spec.ts +0 -61
  123. package/tools/extend-notes-files-diff.ts +0 -35
  124. package/tools/find-notes-files-diff.ts +0 -185
  125. package/tools/get-file-name.ts +0 -7
  126. package/tools/get-string-path.ts +0 -6
  127. package/tools/is-gpg-encrypted.ts +0 -6
  128. package/tools/is-org-file.ts +0 -7
  129. package/tools/join.ts +0 -3
  130. package/tools/mock-server.ts +0 -16
  131. /package/{encryption/index.ts → dist/encryption/index.d.ts} +0 -0
  132. /package/{index.ts → dist/index.d.ts} +0 -0
  133. /package/{models/index.ts → dist/models/index.d.ts} +0 -0
  134. /package/{tools/index.ts → dist/tools/index.d.ts} +0 -0
package/api.ts DELETED
@@ -1,123 +0,0 @@
1
- import {
2
- Command,
3
- CSSVariable,
4
- ThemeVariable,
5
- Note,
6
- InlineEmbeddedWidget,
7
- MultilineEmbeddedWidget,
8
- OrgLineClass,
9
- WidgetBuilder,
10
- CommandPreview,
11
- OrgNoteEncryption,
12
- Modal,
13
- } from './models';
14
- import type { NavigationFailure } from 'vue-router';
15
- import { WidgetType } from './models/widget-type';
16
- import type { Component } from 'vue';
17
- import { NodeType } from 'org-mode-ast';
18
- import { EditorExtension } from './models/editor';
19
-
20
- type WithNodeType<T> = { nodeType: NodeType } & T;
21
-
22
- export type WidgetMeta =
23
- | ({ type: WidgetType.Inline } & WithNodeType<InlineEmbeddedWidget>)
24
- | ({ type: WidgetType.Multiline } & WithNodeType<MultilineEmbeddedWidget>)
25
- | ({ type: WidgetType.LineClass } & WithNodeType<OrgLineClass>);
26
-
27
- export interface OrgNoteApi {
28
- [key: string]: unknown;
29
- getExtension?<T>(config: string): T;
30
-
31
- system: {
32
- reload: (params?: { verbose: boolean }) => Promise<void>;
33
- setNewFilesAvailable: (status?: boolean) => void;
34
- };
35
- navigation: {
36
- openNote: (id: string) => Promise<void | NavigationFailure>;
37
- editNote: (id: string) => Promise<void | NavigationFailure>;
38
- };
39
- ui: {
40
- applyTheme: (theme: { [key in ThemeVariable]: string | number }) => void;
41
- applyCssVariables: (styles: {
42
- [key in CSSVariable]: string | number;
43
- }) => void;
44
- setThemeByMode: (themeName?: string) => void;
45
- setDarkTheme: (themeName?: string) => void;
46
- setLightTheme: (themeName?: string) => void;
47
- applyStyles: (scopeName: string, styles: string) => void;
48
- removeStyles: (scopeName: string) => void;
49
- resetTheme: () => void;
50
- openModal: (modal: Modal) => void;
51
- };
52
- interaction: {
53
- confirm: (title: string, message: string) => Promise<boolean>;
54
- };
55
- currentNote: {
56
- get: () => Note;
57
- };
58
- editor: {
59
- extensions: {
60
- add: (...extension: EditorExtension[]) => void;
61
- remove: (...extension: EditorExtension[]) => void;
62
- };
63
- widgets: {
64
- add: (...widgetMeta: WidgetMeta[]) => void;
65
- createWidgetBuilder: (
66
- cmp: Component,
67
- props?: { [key: string]: unknown }
68
- ) => WidgetBuilder;
69
- };
70
- };
71
- // Available only on mobile apps
72
- fileSystem: {
73
- readPath: () => Promise<string>;
74
- };
75
- commands: {
76
- add(...commands: Command[]): void;
77
- remove(...commands: Command[]): void;
78
- get(name: string): Command;
79
- getAll(): Command[];
80
- addCommandToSidebar(...commands: CommandPreview[]): void;
81
- removeCommandFromSidebar(...commands: CommandPreview[]): void;
82
- addCommandToEditorPanel(...commands: CommandPreview[]): void;
83
- removeCommandFromEditorPanel(...commands: CommandPreview[]): void;
84
- };
85
- configuration: () => OrgNoteConfig;
86
- }
87
-
88
- // TODO: master move model to the backend service
89
- export interface OrgNoteConfig {
90
- editor: {
91
- showSpecialSymbols: boolean;
92
- showPropertyDrawer: boolean;
93
- };
94
- developer: {
95
- developerMode: boolean;
96
- maximumLogsCount: number;
97
- };
98
- completion: {
99
- showGroup: boolean;
100
- defaultCompletionLimit: number;
101
- };
102
- system: {
103
- language: string;
104
- };
105
- synchronization: {
106
- type: 'none' | 'api';
107
- };
108
- vault: {
109
- /* File system available only for mobile devices */
110
- type: 'inmemory' | 'filesystem';
111
- path?: string;
112
- };
113
- ui: {
114
- showUserProfiles: boolean;
115
- theme: 'light' | 'dark' | 'auto';
116
- darkThemeName?: string;
117
- lightThemeName?: string;
118
- };
119
- extensions: {
120
- sources: string[];
121
- };
122
- encryption: OrgNoteEncryption;
123
- }
@@ -1,215 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`Should decrypt note content via password 1`] = `
4
- [
5
- {
6
- "encrypted": false,
7
- "id": "id",
8
- "meta": {
9
- "headings": [
10
- {
11
- "level": 1,
12
- "title": "Hello?",
13
- },
14
- ],
15
- "id": "qweqwe",
16
- "title": "Hello worlld",
17
- },
18
- },
19
- "#+ID: qweqwe
20
- #+TITLE: Hello worlld
21
-
22
- * Hello?",
23
- ]
24
- `;
25
-
26
- exports[`Should decrypt note via provided keys 1`] = `
27
- [
28
- {
29
- "encrypted": false,
30
- "id": "id",
31
- "meta": {
32
- "headings": [
33
- {
34
- "level": 1,
35
- "title": "Hello?",
36
- },
37
- ],
38
- "id": "qweqwe",
39
- "title": "Hello worlld",
40
- },
41
- },
42
- "#+ID: qweqwe
43
- #+TITLE: Hello worlld
44
-
45
- * Hello?",
46
- ]
47
- `;
48
-
49
- exports[`Should encrypt note content via password 1`] = `
50
- {
51
- "author": {
52
- "email": "test@mail.com",
53
- "id": "1",
54
- "name": "John Doe",
55
- },
56
- "encrypted": true,
57
- "id": "id",
58
- "meta": {
59
- "id": undefined,
60
- "published": false,
61
- },
62
- }
63
- `;
64
-
65
- exports[`Should encrypt note content via password to binary format 1`] = `
66
- {
67
- "author": {
68
- "email": "test@mail.com",
69
- "id": "1",
70
- "name": "John Doe",
71
- },
72
- "encrypted": true,
73
- "id": "id",
74
- "meta": {
75
- "id": undefined,
76
- "published": false,
77
- },
78
- }
79
- `;
80
-
81
- exports[`Should encrypt note to binary format 1`] = `
82
- {
83
- "author": {
84
- "email": "test@mail.com",
85
- "id": "1",
86
- "name": "John Doe",
87
- },
88
- "encrypted": true,
89
- "id": "id",
90
- "meta": {
91
- "id": undefined,
92
- "published": false,
93
- },
94
- }
95
- `;
96
-
97
- exports[`Should encrypt note via keys 1`] = `
98
- {
99
- "author": {
100
- "email": "test@mail.com",
101
- "id": "1",
102
- "name": "John Doe",
103
- },
104
- "encrypted": true,
105
- "id": "id",
106
- "meta": {
107
- "id": undefined,
108
- "published": false,
109
- },
110
- }
111
- `;
112
-
113
- exports[`Should encrypt note with empty encrypted property 1`] = `
114
- {
115
- "author": {
116
- "email": "test@mail.com",
117
- "id": "1",
118
- "name": "John Doe",
119
- },
120
- "encrypted": true,
121
- "id": "id",
122
- "meta": {
123
- "id": undefined,
124
- "published": false,
125
- },
126
- }
127
- `;
128
-
129
- exports[`Should not decrypt note without provided encrypted type 1`] = `
130
- [
131
- {
132
- "author": {
133
- "email": "test@mail.com",
134
- "id": "1",
135
- "name": "John Doe",
136
- },
137
- "encrypted": false,
138
- "id": "id",
139
- "meta": {
140
- "description": "Awesome description",
141
- "images": [],
142
- "published": false,
143
- "title": "My note title",
144
- },
145
- },
146
- "#+ID: qweqwe
147
- #+TITLE: Hello worlld
148
-
149
- * Hello?",
150
- ]
151
- `;
152
-
153
- exports[`Should not encrypt public note 1`] = `
154
- {
155
- "author": {
156
- "email": "test@mail.com",
157
- "id": "1",
158
- "name": "John Doe",
159
- },
160
- "encrypted": false,
161
- "id": "id",
162
- "meta": {
163
- "description": "Awesome description",
164
- "images": [],
165
- "published": true,
166
- "title": "My note title",
167
- },
168
- }
169
- `;
170
-
171
- exports[`Should set not encrypted status when params type does not provided 1`] = `
172
- [
173
- {
174
- "encrypted": true,
175
- "id": "id",
176
- "meta": {
177
- "description": "Awesome description",
178
- "images": [],
179
- "published": false,
180
- "title": "My note title for decryption via keys",
181
- },
182
- },
183
- "-----BEGIN PGP MESSAGE-----
184
-
185
- wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
186
- +CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
187
- gfe2f/6zsge9ux+mXF2BG4z+V5T8XIOrfzxosVprdJHZHM3x7cW5USQ0t2i2
188
- FiOUWxSZO1899J3yICpMvhDXvTLVZuKpSNQho5PyXSeZa83eN+uYkhgt9lsk
189
- 0KW88Nr435S6n6mVw/zpitXIgEKpkqh46mhG+1W3aC0lYx6j9lHm3bjtdb4r
190
- 2mtZbWKwfdBggEy8qEeiUeslvKd6uWtEccomzFgJkaqWVGknLmrBdHfztRIV
191
- fbZhxHz+J3GFOIgXf/5+fv+zg0nTazgz1mDUfnTHw3+qcAyEJ0ADdyg9EZc+
192
- bKbK0GwzMDPQeM+cCRDWUTiIa1ruyEETiwMdhWUDztF8XxY2o8jXPerZ0NhG
193
- R8l+SvAdYQQXPfxEh9lA3thkyz/Vp72pW46lUeJHGSq/fS6KIdLHLP9Z2e1J
194
- aCFpNMgyAN+BaXwnbLZfz6k5hV8awbRScSWQLEg69D9b287SFDPOYW7OZikn
195
- CKXL7xyQ5LrWJZN9Z/UPGjy+PdEw1SBhyluW6DQ+Sz1j4K8USTLqY89EInDl
196
- G7AxHGujR9UkUGyUvvc71XW7jEOogiDgn1ZMoj9Y58LSweUB8vfkY3VF84Fy
197
- zGVvLFWnFbtnWuoQC4OOXv1F6ETdmEsSMEMWKzRLDGPyqNX7FhG3cejlEuiK
198
- EsT5oQhz00RECmnR8mJkGmJhzWmmeoQvaucFqhTOZjvYl9ivuEMBZ2jtkdHn
199
- R6UNcNZRpCbfnl7YoikqbGBgqDFYydFGHXKHDpYhcQYWJsMDUayzUiPtzmaE
200
- tgfTgNNqgPxkLnWA99KYNU8DH+FwgaYBuw9dwdqwcjxSbZjHhCFGUfsqM+ik
201
- O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
202
- sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
203
- Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
204
- LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
205
- +ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
206
- p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
207
- gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
208
- AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
209
- cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
210
- PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
211
- yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
212
- =LjkG
213
- -----END PGP MESSAGE-----",
214
- ]
215
- `;
@@ -1,355 +0,0 @@
1
- import {
2
- encryptViaKeys,
3
- decryptViaKeys,
4
- encryptViaPassword,
5
- decryptViaPassword,
6
- NoKeysProvidedError,
7
- NoPasswordProvidedError,
8
- IncorrectOrMissingPrivateKeyPasswordError,
9
- encrypt,
10
- decrypt,
11
- _encryptViaKeys,
12
- armor,
13
- unarmor,
14
- } from '../encryption';
15
- import { test, expect } from 'vitest';
16
-
17
- import {
18
- armoredPublicKey,
19
- armoredPrivateKey,
20
- privateKeyPassphrase,
21
- } from './encryption-keys';
22
- import { ModelsPublicNoteEncryptionTypeEnum } from 'src/remote-api';
23
-
24
- test('Should encrypt text as armored message via keys', async () => {
25
- const res = await encryptViaKeys({
26
- type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
27
- content: 'Hello world',
28
- publicKey: armoredPublicKey,
29
- privateKey: armoredPrivateKey,
30
- privateKeyPassphrase: privateKeyPassphrase,
31
- format: 'armored',
32
- });
33
-
34
- expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
35
- });
36
-
37
- test('Should encrypt text via keys', async () => {
38
- const res = await encryptViaKeys({
39
- type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
40
- content: 'Hello world',
41
- publicKey: armoredPublicKey,
42
- privateKey: armoredPrivateKey,
43
- privateKeyPassphrase,
44
- format: 'armored',
45
- });
46
-
47
- expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
48
- });
49
-
50
- test('Should decrypt via provided keys', async () => {
51
- const decryptedMessage = await decryptViaKeys({
52
- content: `-----BEGIN PGP MESSAGE-----
53
-
54
- wcFMA/vryg+TTn0rARAAhXuEjOHa856iCNVmdeIGHF+IEoeEwTc5tIcr6Lri
55
- V6xs//3WnwVwUlyxYrum3yCpx8t5gyWTXFfTNH08VoVqPVP45fkk1H7jdC6Q
56
- I+tHfn8nXZApdKQlMOku+XMXtRuqvOUQHutqHj4ka3qC+wGIPcOsy2TIoFsS
57
- xauk13hMggmVHOdQkMzWA1QlxDcz6lFl86SvX18uc7H62s36gHxARmOLZfBd
58
- nRFdnPgLKNOPGWb6QvYfvxiv03vGSsKlb0tIpwP1Ot0nyZax+yH9CJmIEni/
59
- rW9Wu/Ph+PRcB2L9kp/X4Opol3RwJ0lI9ilTRw9+GGFipXhCmJcjPJC7WNIg
60
- vg0/xVUjSmlxQQAZlC9/sefvoXjY0CP+h+djtoZsxLpN4P4iTO1reuoVD0iO
61
- UwT9JCUR1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ZRVvDNT1hg9Cyc
78
- UO1Pw43TRLO50HgR9+ERNXL491TJA0aCj14oXwsm0Dtg6EOltX0GUDwcPjv6
79
- 6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
80
- YQ==
81
- =f4F1
82
- -----END PGP MESSAGE-----
83
- `,
84
- privateKey: armoredPrivateKey,
85
- privateKeyPassphrase,
86
- });
87
- expect(decryptedMessage).toEqual('Hello world');
88
- });
89
-
90
- test('Should encrypt via password', async () => {
91
- const password = 'test';
92
- const res = await encryptViaPassword({
93
- type: ModelsPublicNoteEncryptionTypeEnum.GpgPassword,
94
- content: 'Hello world',
95
- password,
96
- format: 'armored',
97
- });
98
-
99
- expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
100
- });
101
-
102
- test('Should decrypt via password', async () => {
103
- const password = 'test';
104
- const encryptedMsg = `-----BEGIN PGP MESSAGE-----
105
-
106
- wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
107
- aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
108
- 5iO5mEqoXWXg6nAvNxciA56dKuI=
109
- =B4Tc
110
- -----END PGP MESSAGE-----
111
- `;
112
-
113
- expect(await decryptViaPassword({ content: encryptedMsg, password })).toEqual(
114
- 'Hello world'
115
- );
116
- });
117
-
118
- test('Should raise incorrect or missing private key error', async () => {
119
- const encryptedMsg = `-----BEGIN PGP MESSAGE-----
120
-
121
- wcFMA/vryg+TTn0rARAAhXuEjOHa856iCNVmdeIGHF+IEoeEwTc5tIcr6Lri
122
- V6xs//3WnwVwUlyxYrum3yCpx8t5gyWTXFfTNH08VoVqPVP45fkk1H7jdC6Q
123
- I+tHfn8nXZApdKQlMOku+XMXtRuqvOUQHutqHj4ka3qC+wGIPcOsy2TIoFsS
124
- xauk13hMggmVHOdQkMzWA1QlxDcz6lFl86SvX18uc7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TtsiEu1NaTzRtQNZAFHcJpZ8qAL67LHoNdFe/atpCdlyV3yur9
142
- RvAA3cB7cj7wab3beX+cTqxdhpGePZh0TrNd3liV69FtbnYfeDrtUYIL1jfT
143
- EJN3l+qpveimyX655RrgFX3DNGrVbbhpx+FDF9Ky9kqb2BJBTFKoCBxbf0dS
144
- sniNAsC/t/k6ErG8NKNQsNh1aeN6plXnxeVi1vv6SvO2mwZRVvDNT1hg9Cyc
145
- UO1Pw43TRLO50HgR9+ERNXL491TJA0aCj14oXwsm0Dtg6EOltX0GUDwcPjv6
146
- 6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
147
- YQ==
148
- =f4F1
149
- -----END PGP MESSAGE-----`;
150
-
151
- try {
152
- await decryptViaPassword({ content: encryptedMsg, password: 'password' });
153
- } catch (e) {
154
- expect(e).toBeInstanceOf(NoKeysProvidedError);
155
- }
156
- });
157
-
158
- test('Should raise IncorrectOrMissingPrivateKeyPasswordError error when incorrect armored key provided', async () => {
159
- const encryptedMsg = `-----BEGIN PGP MESSAGE-----
160
-
161
- wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
162
- aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
163
- 5iO5mEqoXWXg6nAvNxciA56dKuI=
164
- =B4Tc
165
- -----END PGP MESSAGE-----
166
- `;
167
-
168
- try {
169
- await decryptViaKeys({
170
- content: encryptedMsg,
171
- publicKey: armoredPublicKey,
172
- privateKey: privateKeyPassphrase,
173
- });
174
- } catch (e) {
175
- expect(e).toBeInstanceOf(IncorrectOrMissingPrivateKeyPasswordError);
176
- }
177
- });
178
-
179
- test('Should raise NoPasswordProvidedError error when try to use keys instead of password', async () => {
180
- const encryptedMsg = `-----BEGIN PGP MESSAGE-----
181
-
182
- wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
183
- aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
184
- 5iO5mEqoXWXg6nAvNxciA56dKuI=
185
- =B4Tc
186
- -----END PGP MESSAGE-----
187
- `;
188
-
189
- try {
190
- await decryptViaKeys({
191
- content: encryptedMsg,
192
- privateKey: armoredPrivateKey,
193
- privateKeyPassphrase,
194
- });
195
- } catch (e) {
196
- expect(e).toBeInstanceOf(NoPasswordProvidedError);
197
- }
198
- });
199
-
200
- test('Should encrypt and decrypt text by provided configs via password', async () => {
201
- const text = 'Hello world';
202
- const password = '123';
203
-
204
- const res = await encrypt({
205
- content: text,
206
- type: 'gpgPassword',
207
- password,
208
- format: 'armored',
209
- });
210
-
211
- expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
212
-
213
- const decryptedMessage = await decrypt({
214
- content: res,
215
- type: 'gpgPassword',
216
- password,
217
- });
218
-
219
- expect(decryptedMessage).toEqual(text);
220
- });
221
-
222
- test('Should encrypt and decrypt text by provided configs via keys', async () => {
223
- const text = 'Hello world';
224
- const res = await encrypt({
225
- content: text,
226
- type: 'gpgKeys',
227
- format: 'armored',
228
- publicKey: armoredPublicKey,
229
- privateKey: armoredPrivateKey,
230
- privateKeyPassphrase,
231
- });
232
-
233
- expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
234
-
235
- const decryptedMessage = await decrypt({
236
- content: res,
237
- type: 'gpgKeys',
238
- publicKey: armoredPublicKey,
239
- privateKey: armoredPrivateKey,
240
- privateKeyPassphrase,
241
- format: 'utf8',
242
- });
243
-
244
- expect(decryptedMessage).toEqual(text);
245
- });
246
-
247
- test('Should encrypt to binary and decrypt to format armored!', async () => {
248
- const text = 'Hello world';
249
-
250
- const res = await encrypt({
251
- content: text,
252
- type: 'gpgPassword',
253
- password: '123',
254
- format: 'binary',
255
- });
256
-
257
- expect(res).toBeInstanceOf(Uint8Array);
258
-
259
- const decryptedMessage = await decrypt({
260
- content: res,
261
- type: 'gpgPassword',
262
- format: 'utf8',
263
- password: '123',
264
- });
265
-
266
- expect(decryptedMessage).toEqual(text);
267
- });
268
-
269
- test('Should encrypt to binary and decrypt to binary format', async () => {
270
- const text = 'Hello world';
271
-
272
- const res = await encrypt({
273
- content: text,
274
- type: 'gpgPassword',
275
- password: '123',
276
- format: 'binary',
277
- });
278
-
279
- expect(res).toBeInstanceOf(Uint8Array);
280
-
281
- const decryptedMessage = await decrypt({
282
- content: res,
283
- type: 'gpgPassword',
284
- format: 'binary',
285
- password: '123',
286
- });
287
-
288
- expect(decryptedMessage.toString()).toMatchInlineSnapshot(
289
- `"72,101,108,108,111,32,119,111,114,108,100"`
290
- );
291
- });
292
-
293
- test('Should encrypt to armored text and decrypt as binary format', async () => {
294
- const text = 'Hello world';
295
-
296
- const res = await encrypt({
297
- content: text,
298
- type: 'gpgPassword',
299
- password: '123',
300
- format: 'armored',
301
- });
302
-
303
- expect(res).toBeTypeOf('string');
304
-
305
- const decryptedMessage = await decrypt({
306
- content: res,
307
- type: 'gpgPassword',
308
- format: 'binary',
309
- password: '123',
310
- });
311
-
312
- expect(decryptedMessage).toBeInstanceOf(Uint8Array);
313
- });
314
-
315
- test('Should armor and unarmor encrypted file', async () => {
316
- const content: Uint8Array = new Uint8Array([
317
- 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
318
- ]);
319
-
320
- const armored = armor(content);
321
-
322
- expect(armored).toMatchInlineSnapshot(`
323
- "-----BEGIN PGP MESSAGE-----
324
-
325
- SGVsbG8gd29ybGQ=
326
- =7asC
327
- -----END PGP MESSAGE-----
328
- "
329
- `);
330
-
331
- const { data } = await unarmor(armored);
332
-
333
- expect(data).toEqual(content);
334
- });
335
-
336
- test('Should decrypt value from provided real world data and passwords', async () => {
337
- const text = `Hello world!`;
338
- const password = 'qweqwebebe1';
339
-
340
- const encryptedContent = await encrypt({
341
- content: text,
342
- type: 'gpgPassword',
343
- password,
344
- });
345
-
346
- const armoredContent = armor(encryptedContent as unknown as Uint8Array);
347
-
348
- const decryptedMessage = await decrypt({
349
- content: armoredContent,
350
- type: 'gpgPassword',
351
- password,
352
- });
353
-
354
- expect(decryptedMessage).toEqual('Hello world!');
355
- });