orgnote-api 0.17.0 → 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.
- package/dist/api.d.ts +112 -0
- package/dist/api.js +1 -0
- package/dist/encryption/__tests__/encryption-keys.d.ts +3 -0
- package/{encryption/__tests__/encryption-keys.ts → dist/encryption/__tests__/encryption-keys.js} +0 -2
- package/dist/encryption/__tests__/encryption.spec.d.ts +1 -0
- package/dist/encryption/__tests__/encryption.spec.js +287 -0
- package/dist/encryption/__tests__/note-encryption.spec.d.ts +1 -0
- package/dist/encryption/__tests__/note-encryption.spec.js +364 -0
- package/dist/encryption/encryption.d.ts +27 -0
- package/dist/encryption/encryption.js +156 -0
- package/dist/encryption/index.js +2 -0
- package/dist/encryption/note-encryption.d.ts +12 -0
- package/dist/encryption/note-encryption.js +42 -0
- package/dist/files-api.d.ts +7 -0
- package/dist/files-api.js +22 -0
- package/dist/index.js +5 -0
- package/dist/models/command.d.ts +29 -0
- package/dist/models/command.js +1 -0
- package/dist/models/completion.d.ts +22 -0
- package/dist/models/completion.js +1 -0
- package/dist/models/default-commands.d.ts +30 -0
- package/dist/models/default-commands.js +41 -0
- package/dist/models/editor.d.ts +23 -0
- package/dist/models/editor.js +1 -0
- package/dist/models/encryption.d.ts +31 -0
- package/dist/models/encryption.js +1 -0
- package/dist/models/extension.d.ts +34 -0
- package/dist/models/extension.js +1 -0
- package/dist/models/file-system.d.ts +23 -0
- package/dist/models/file-system.js +1 -0
- package/{models/index.ts → dist/models/index.d.ts} +2 -0
- package/dist/models/index.js +13 -0
- package/dist/models/modal.d.ts +10 -0
- package/dist/models/modal.js +1 -0
- package/dist/models/note.d.ts +23 -0
- package/dist/models/note.js +1 -0
- package/dist/models/sync.d.ts +34 -0
- package/dist/models/sync.js +1 -0
- package/dist/models/theme-variables.d.ts +192 -0
- package/dist/models/theme-variables.js +194 -0
- package/{models/vue-component.ts → dist/models/vue-component.d.ts} +1 -1
- package/dist/models/vue-component.js +1 -0
- package/dist/models/widget-type.d.ts +5 -0
- package/dist/models/widget-type.js +6 -0
- package/dist/models/widget.d.ts +51 -0
- package/dist/models/widget.js +1 -0
- package/dist/remote-api/api.d.ts +1525 -0
- package/{remote-api/api.ts → dist/remote-api/api.js} +246 -1149
- package/dist/remote-api/base.d.ts +66 -0
- package/{remote-api/base.ts → dist/remote-api/base.js} +13 -36
- package/dist/remote-api/common.d.ts +65 -0
- package/{remote-api/common.ts → dist/remote-api/common.js} +31 -48
- package/{remote-api/configuration.ts → dist/remote-api/configuration.d.ts} +3 -22
- package/dist/remote-api/configuration.js +95 -0
- package/dist/remote-api/index.d.ts +13 -0
- package/{remote-api/index.ts → dist/remote-api/index.js} +0 -3
- package/dist/tools/__tests__/find-files-diff.spec.d.ts +1 -0
- package/dist/tools/__tests__/find-files-diff.spec.js +110 -0
- package/dist/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
- package/dist/tools/__tests__/find-note-files-diff.spec.js +168 -0
- package/dist/tools/__tests__/get-file-name.spec.d.ts +1 -0
- package/dist/tools/__tests__/get-file-name.spec.js +14 -0
- package/dist/tools/__tests__/get-string-path.spec.d.ts +1 -0
- package/dist/tools/__tests__/get-string-path.spec.js +27 -0
- package/dist/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
- package/{tools/__tests__/is-gpg-encrypted.spec.ts → dist/tools/__tests__/is-gpg-encrypted.spec.js} +4 -8
- package/dist/tools/__tests__/is-org-file.spec.d.ts +1 -0
- package/dist/tools/__tests__/is-org-file.spec.js +54 -0
- package/dist/tools/__tests__/join.spec.d.ts +1 -0
- package/dist/tools/__tests__/join.spec.js +14 -0
- package/dist/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
- package/dist/tools/__tests__/read-org-files-recursively.spec.js +51 -0
- package/dist/tools/extend-notes-files-diff.d.ts +3 -0
- package/dist/tools/extend-notes-files-diff.js +21 -0
- package/dist/tools/find-notes-files-diff.d.ts +5 -0
- package/dist/tools/find-notes-files-diff.js +108 -0
- package/dist/tools/get-file-name.d.ts +2 -0
- package/dist/tools/get-file-name.js +6 -0
- package/dist/tools/get-string-path.d.ts +1 -0
- package/dist/tools/get-string-path.js +6 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/is-gpg-encrypted.d.ts +1 -0
- package/dist/tools/is-gpg-encrypted.js +6 -0
- package/dist/tools/is-org-file.d.ts +2 -0
- package/dist/tools/is-org-file.js +4 -0
- package/dist/tools/join.d.ts +1 -0
- package/dist/tools/join.js +3 -0
- package/dist/tools/mock-server.d.ts +1 -0
- package/dist/tools/mock-server.js +12 -0
- package/package.json +6 -14
- package/api.ts +0 -123
- package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -231
- package/encryption/__tests__/encryption.spec.ts +0 -352
- package/encryption/__tests__/note-encryption.spec.ts +0 -425
- package/encryption/encryption.ts +0 -264
- package/encryption/note-encryption.ts +0 -77
- package/files-api.ts +0 -25
- package/models/command.ts +0 -45
- package/models/completion.ts +0 -30
- package/models/default-commands.ts +0 -44
- package/models/editor.ts +0 -27
- package/models/encryption.ts +0 -50
- package/models/extension.ts +0 -45
- package/models/modal.ts +0 -12
- package/models/note.ts +0 -26
- package/models/theme-variables.ts +0 -194
- package/models/widget-type.ts +0 -5
- package/models/widget.ts +0 -59
- package/remote-api/.gitignore +0 -4
- package/remote-api/.npmignore +0 -1
- package/remote-api/.openapi-generator/FILES +0 -8
- package/remote-api/.openapi-generator/VERSION +0 -1
- package/remote-api/.openapi-generator-ignore +0 -23
- package/remote-api/git_push.sh +0 -57
- package/tools/__tests__/find-notes-files-diff.spec.ts +0 -176
- package/tools/__tests__/get-string-path.spec.ts +0 -32
- package/tools/__tests__/is-org-file.spec.ts +0 -62
- package/tools/find-notes-files-diff.ts +0 -48
- package/tools/get-string-path.ts +0 -6
- package/tools/index.ts +0 -3
- package/tools/is-gpg-encrypted.ts +0 -6
- package/tools/is-org-file.ts +0 -7
- package/tools/mock-server.ts +0 -16
- /package/{encryption/index.ts → dist/encryption/index.d.ts} +0 -0
- /package/{index.ts → dist/index.d.ts} +0 -0
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
import { decryptNote, encryptNote } from '../note-encryption';
|
|
3
|
-
import { Note } from '../../models';
|
|
4
|
-
import {
|
|
5
|
-
armoredPublicKey,
|
|
6
|
-
armoredPrivateKey,
|
|
7
|
-
privateKeyPassphrase,
|
|
8
|
-
} from './encryption-keys';
|
|
9
|
-
import { ModelsPublicNoteEncryptionTypeEnum } from '../../remote-api';
|
|
10
|
-
|
|
11
|
-
test('Should encrypt note content via password', async () => {
|
|
12
|
-
const noteText = `#+ID: qweqwe
|
|
13
|
-
|
|
14
|
-
#+TITLE: Hello worlld
|
|
15
|
-
|
|
16
|
-
* Hello?`;
|
|
17
|
-
|
|
18
|
-
const note: Note = {
|
|
19
|
-
id: 'id',
|
|
20
|
-
meta: {
|
|
21
|
-
title: 'My note title',
|
|
22
|
-
images: [],
|
|
23
|
-
published: false,
|
|
24
|
-
description: 'Awesome description',
|
|
25
|
-
},
|
|
26
|
-
author: {
|
|
27
|
-
id: '1',
|
|
28
|
-
name: 'John Doe',
|
|
29
|
-
email: 'test@mail.com',
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
34
|
-
content: noteText,
|
|
35
|
-
type: 'gpgPassword',
|
|
36
|
-
password: '123',
|
|
37
|
-
format: 'armored',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
41
|
-
true
|
|
42
|
-
);
|
|
43
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('Should encrypt note content via password to binary format', async () => {
|
|
47
|
-
const noteText = `#+ID: qweqwe
|
|
48
|
-
|
|
49
|
-
#+TITLE: Hello worlld
|
|
50
|
-
|
|
51
|
-
* Hello?`;
|
|
52
|
-
|
|
53
|
-
const note: Note = {
|
|
54
|
-
id: 'id',
|
|
55
|
-
meta: {
|
|
56
|
-
title: 'My note title',
|
|
57
|
-
images: [],
|
|
58
|
-
published: false,
|
|
59
|
-
description: 'Awesome description',
|
|
60
|
-
},
|
|
61
|
-
author: {
|
|
62
|
-
id: '1',
|
|
63
|
-
name: 'John Doe',
|
|
64
|
-
email: 'test@mail.com',
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
69
|
-
content: noteText,
|
|
70
|
-
type: 'gpgPassword',
|
|
71
|
-
password: '123',
|
|
72
|
-
format: 'binary',
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
76
|
-
expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('Should decrypt note content via password', async () => {
|
|
80
|
-
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
81
|
-
|
|
82
|
-
wy4ECQMI/CCaKMJEqy/gyROJeRgW9I738dDFBltFlxIjhxrN7nQ6gkX4GgX6
|
|
83
|
-
zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
|
|
84
|
-
2k3g68Afayke2nLkDNkH62tdOPiTkx7bSlp1zL4uU440IM1g6dC72JkmtoTJ
|
|
85
|
-
5Bjlwt4ZhxFsh+c=
|
|
86
|
-
=csID
|
|
87
|
-
-----END PGP MESSAGE-----`;
|
|
88
|
-
|
|
89
|
-
const note: Note = {
|
|
90
|
-
id: 'id',
|
|
91
|
-
meta: {
|
|
92
|
-
title: 'My note title',
|
|
93
|
-
images: [],
|
|
94
|
-
published: false,
|
|
95
|
-
description: 'Awesome description',
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const decryptedNote = await decryptNote(note, {
|
|
100
|
-
content: noteText,
|
|
101
|
-
type: 'gpgPassword',
|
|
102
|
-
password: '123',
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('Should encrypt note via keys', async () => {
|
|
109
|
-
const noteText = `#+ID: qweqwe
|
|
110
|
-
#+TITLE: Hello worlld
|
|
111
|
-
|
|
112
|
-
* Hello?`;
|
|
113
|
-
|
|
114
|
-
const note: Note = {
|
|
115
|
-
id: 'id',
|
|
116
|
-
meta: {
|
|
117
|
-
title: 'My note title for encryption via keys',
|
|
118
|
-
images: [],
|
|
119
|
-
published: false,
|
|
120
|
-
description: 'Awesome description',
|
|
121
|
-
},
|
|
122
|
-
author: {
|
|
123
|
-
id: '1',
|
|
124
|
-
name: 'John Doe',
|
|
125
|
-
email: 'test@mail.com',
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
130
|
-
content: noteText,
|
|
131
|
-
type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
132
|
-
publicKey: armoredPublicKey,
|
|
133
|
-
privateKey: armoredPrivateKey,
|
|
134
|
-
privateKeyPassphrase,
|
|
135
|
-
format: 'armored',
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
139
|
-
true
|
|
140
|
-
);
|
|
141
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('Should decrypt note via provided keys', async () => {
|
|
145
|
-
const encryptedNoteText = `-----BEGIN PGP MESSAGE-----
|
|
146
|
-
|
|
147
|
-
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|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|
163
|
-
O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
|
|
164
|
-
sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
|
|
165
|
-
Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
|
|
166
|
-
LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
|
|
167
|
-
+ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
|
|
168
|
-
p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
|
|
169
|
-
gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
|
|
170
|
-
AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
|
|
171
|
-
cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
172
|
-
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
173
|
-
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
174
|
-
=LjkG
|
|
175
|
-
-----END PGP MESSAGE-----`;
|
|
176
|
-
|
|
177
|
-
const note: Note = {
|
|
178
|
-
id: 'id',
|
|
179
|
-
meta: {
|
|
180
|
-
title: 'My note title for decryption via keys',
|
|
181
|
-
images: [],
|
|
182
|
-
published: false,
|
|
183
|
-
description: 'Awesome description',
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const decryptedNote = await decryptNote(note, {
|
|
188
|
-
content: encryptedNoteText,
|
|
189
|
-
type: 'gpgKeys',
|
|
190
|
-
publicKey: armoredPublicKey,
|
|
191
|
-
privateKey: armoredPrivateKey,
|
|
192
|
-
privateKeyPassphrase,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('Should not encrypt public note', async () => {
|
|
199
|
-
const noteText = `#+ID: qweqwe
|
|
200
|
-
#+TITLE: Hello worlld
|
|
201
|
-
|
|
202
|
-
* Hello?`;
|
|
203
|
-
|
|
204
|
-
const note: Note = {
|
|
205
|
-
id: 'id',
|
|
206
|
-
meta: {
|
|
207
|
-
title: 'My note title',
|
|
208
|
-
images: [],
|
|
209
|
-
published: true,
|
|
210
|
-
description: 'Awesome description',
|
|
211
|
-
},
|
|
212
|
-
author: {
|
|
213
|
-
id: '1',
|
|
214
|
-
name: 'John Doe',
|
|
215
|
-
email: 'test@mail.com',
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
220
|
-
content: noteText,
|
|
221
|
-
type: 'gpgPassword',
|
|
222
|
-
password: '123',
|
|
223
|
-
format: 'armored',
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
227
|
-
false
|
|
228
|
-
);
|
|
229
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('Should encrypt note with empty encrypted property', async () => {
|
|
233
|
-
const noteText = `#+ID: qweqwe
|
|
234
|
-
#+TITLE: Hello worlld
|
|
235
|
-
|
|
236
|
-
* Hello?`;
|
|
237
|
-
|
|
238
|
-
const note: Note = {
|
|
239
|
-
id: 'id',
|
|
240
|
-
meta: {
|
|
241
|
-
title: 'My note title',
|
|
242
|
-
images: [],
|
|
243
|
-
published: false,
|
|
244
|
-
description: 'Awesome description',
|
|
245
|
-
},
|
|
246
|
-
author: {
|
|
247
|
-
id: '1',
|
|
248
|
-
name: 'John Doe',
|
|
249
|
-
email: 'test@mail.com',
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
254
|
-
content: noteText,
|
|
255
|
-
type: 'gpgPassword',
|
|
256
|
-
password: '123',
|
|
257
|
-
format: 'armored',
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
261
|
-
true
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test('Should not decrypt note without provided encrypted type', async () => {
|
|
268
|
-
const noteText = `#+ID: qweqwe
|
|
269
|
-
#+TITLE: Hello worlld
|
|
270
|
-
|
|
271
|
-
* Hello?`;
|
|
272
|
-
const note: Note = {
|
|
273
|
-
id: 'id',
|
|
274
|
-
meta: {
|
|
275
|
-
title: 'My note title',
|
|
276
|
-
images: [],
|
|
277
|
-
published: false,
|
|
278
|
-
description: 'Awesome description',
|
|
279
|
-
},
|
|
280
|
-
encrypted: undefined,
|
|
281
|
-
author: {
|
|
282
|
-
id: '1',
|
|
283
|
-
name: 'John Doe',
|
|
284
|
-
email: 'test@mail.com',
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const decryptedInfo = await decryptNote(note, {
|
|
289
|
-
content: noteText,
|
|
290
|
-
type: 'gpgPassword',
|
|
291
|
-
password: '123',
|
|
292
|
-
format: 'armored',
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
expect(decryptedInfo).toMatchSnapshot();
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('Should decrypt note and note meta', async () => {
|
|
299
|
-
const meta = {
|
|
300
|
-
title: 'My note title',
|
|
301
|
-
images: ['./image1.png'],
|
|
302
|
-
published: false,
|
|
303
|
-
description: 'Awesome description',
|
|
304
|
-
fileTags: ['tag1', 'tag2'],
|
|
305
|
-
};
|
|
306
|
-
const note: Note = {
|
|
307
|
-
id: 'id',
|
|
308
|
-
meta: { ...meta },
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
const noteText = `#+TITLE: My note title
|
|
312
|
-
#+DESCRIPTION: Awesome description
|
|
313
|
-
#+PUBLISHED: false
|
|
314
|
-
#+FILETAGS: :tag1:tag2:
|
|
315
|
-
|
|
316
|
-
[[./image1.png]]
|
|
317
|
-
|
|
318
|
-
Hello world`;
|
|
319
|
-
|
|
320
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
321
|
-
content: noteText,
|
|
322
|
-
type: 'gpgPassword',
|
|
323
|
-
password: '123',
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const [decryptedNote, decryptedNoteText] = await decryptNote(encryptedNote, {
|
|
327
|
-
content: encryptedNoteText,
|
|
328
|
-
type: 'gpgPassword',
|
|
329
|
-
password: '123',
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
expect(decryptedNote.meta).toEqual(meta);
|
|
333
|
-
expect(decryptedNoteText).toEqual(noteText);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
test('Should set not encrypted status when params type does not provided', async () => {
|
|
337
|
-
const note: Note = {
|
|
338
|
-
id: 'id',
|
|
339
|
-
meta: {
|
|
340
|
-
title: 'My note title for decryption via keys',
|
|
341
|
-
images: [],
|
|
342
|
-
published: false,
|
|
343
|
-
description: 'Awesome description',
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
348
|
-
|
|
349
|
-
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|
|
350
|
-
+CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXht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
|
|
366
|
-
sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
|
|
367
|
-
Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
|
|
368
|
-
LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
|
|
369
|
-
+ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
|
|
370
|
-
p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
|
|
371
|
-
gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
|
|
372
|
-
AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
|
|
373
|
-
cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
374
|
-
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
375
|
-
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
376
|
-
=LjkG
|
|
377
|
-
-----END PGP MESSAGE-----`;
|
|
378
|
-
|
|
379
|
-
const decryptedNote = await decryptNote(note, {
|
|
380
|
-
content: noteText,
|
|
381
|
-
type: 'disabled',
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
expect(decryptedNote).toMatchSnapshot();
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
test('Should encrypt note to binary format', async () => {
|
|
388
|
-
const noteText = `#+ID: qweqwe
|
|
389
|
-
#+TITLE: Hello worlld
|
|
390
|
-
|
|
391
|
-
* Hello?`;
|
|
392
|
-
|
|
393
|
-
const note: Note = {
|
|
394
|
-
id: 'id',
|
|
395
|
-
meta: {
|
|
396
|
-
title: 'My note title',
|
|
397
|
-
images: [],
|
|
398
|
-
published: false,
|
|
399
|
-
description: 'Awesome description',
|
|
400
|
-
},
|
|
401
|
-
author: {
|
|
402
|
-
id: '1',
|
|
403
|
-
name: 'John Doe',
|
|
404
|
-
email: 'test@mail.com',
|
|
405
|
-
},
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
409
|
-
content: noteText,
|
|
410
|
-
type: 'gpgPassword',
|
|
411
|
-
password: '123',
|
|
412
|
-
format: 'binary',
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
|
|
416
|
-
expect(encryptedNote).toMatchSnapshot();
|
|
417
|
-
|
|
418
|
-
const [_, decryptedNoteText] = await decryptNote(encryptedNote, {
|
|
419
|
-
content: encryptedNoteText,
|
|
420
|
-
type: 'gpgPassword',
|
|
421
|
-
password: '123',
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
expect(decryptedNoteText).toEqual(noteText);
|
|
425
|
-
});
|
package/encryption/encryption.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createMessage,
|
|
3
|
-
decrypt as _decrypt,
|
|
4
|
-
decryptKey,
|
|
5
|
-
encrypt as _encrypt,
|
|
6
|
-
readKey,
|
|
7
|
-
readMessage,
|
|
8
|
-
readPrivateKey,
|
|
9
|
-
Stream,
|
|
10
|
-
} from 'openpgp';
|
|
11
|
-
import { ModelsPublicNoteEncryptionTypeEnum } from '../remote-api';
|
|
12
|
-
import {
|
|
13
|
-
OrgNoteEncryption,
|
|
14
|
-
OrgNotePasswordEncryption,
|
|
15
|
-
WithDecryptionContent,
|
|
16
|
-
} from '../models/encryption';
|
|
17
|
-
import { OrgNoteGpgEncryption, WithEncryptionContent } from '../models';
|
|
18
|
-
import { armor as _armor, unarmor as _unarmor, enums } from 'openpgp';
|
|
19
|
-
|
|
20
|
-
export class IncorrectOrMissingPrivateKeyPasswordError extends Error {}
|
|
21
|
-
export class ImpossibleToDecryptWithProvidedKeysError extends Error {}
|
|
22
|
-
export class IncorrectEncryptionPasswordError extends Error {}
|
|
23
|
-
export class NoKeysProvidedError extends Error {}
|
|
24
|
-
export class NoPasswordProvidedError extends Error {}
|
|
25
|
-
|
|
26
|
-
const noPrivateKeyPassphraseProvidedErrorMsg =
|
|
27
|
-
'Error: Signing key is not decrypted.';
|
|
28
|
-
const incorrectPrivateKeyPassphraseErrorMsg =
|
|
29
|
-
'Error decrypting private key: Incorrect key passphrase';
|
|
30
|
-
const decryptionKeyIsNotDecryptedErrorMsg =
|
|
31
|
-
'Error decrypting message: Decryption key is not decrypted.';
|
|
32
|
-
const corruptedPrivateKeyErrorMsg = 'Misformed armored text';
|
|
33
|
-
|
|
34
|
-
const decriptionFailedErrorMsg =
|
|
35
|
-
'Error decrypting message: Session key decryption failed.';
|
|
36
|
-
const incorrectEncryptionPasswordErrorMsg =
|
|
37
|
-
'Error decrypting message: Modification detected.';
|
|
38
|
-
|
|
39
|
-
const noSymmetricallyEncryptedSessionKeyErrorMsg =
|
|
40
|
-
'Error decrypting message: No symmetrically encrypted session key packet found.';
|
|
41
|
-
|
|
42
|
-
const armoredTextNotTypePrivateKeyErrorMsg =
|
|
43
|
-
'Armored text not of type private key';
|
|
44
|
-
|
|
45
|
-
const notPrivateKeyErrprMsg =
|
|
46
|
-
'Error decrypting message: No public key encrypted session key packet found.';
|
|
47
|
-
|
|
48
|
-
export const encryptViaKeys = withCustomErrors(_encryptViaKeys);
|
|
49
|
-
export const encryptViaPassword = withCustomErrors(_encryptViaPassword);
|
|
50
|
-
export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
|
|
51
|
-
export const decryptViaKeys = withCustomErrors(_decryptViaKeys);
|
|
52
|
-
|
|
53
|
-
export const encrypt = async <
|
|
54
|
-
T extends WithEncryptionContent<OrgNoteEncryption>,
|
|
55
|
-
>(
|
|
56
|
-
encryptionParams: T
|
|
57
|
-
): Promise<T['format'] extends 'binary' ? Uint8Array : string> => {
|
|
58
|
-
if (
|
|
59
|
-
!encryptionParams.type ||
|
|
60
|
-
encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled
|
|
61
|
-
) {
|
|
62
|
-
return encryptionParams.content as any;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const res = (encryptionParams.type ===
|
|
66
|
-
ModelsPublicNoteEncryptionTypeEnum.GpgKeys
|
|
67
|
-
? await encryptViaKeys(encryptionParams)
|
|
68
|
-
: await encryptViaPassword(encryptionParams)) as unknown as Promise<
|
|
69
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
70
|
-
>;
|
|
71
|
-
|
|
72
|
-
return res;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const decrypt = async <
|
|
76
|
-
T extends WithDecryptionContent<OrgNoteEncryption>,
|
|
77
|
-
>(
|
|
78
|
-
decryptionParams: T
|
|
79
|
-
): Promise<T['format'] extends 'binary' ? Uint8Array : string> => {
|
|
80
|
-
if (
|
|
81
|
-
!decryptionParams.type ||
|
|
82
|
-
decryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled
|
|
83
|
-
) {
|
|
84
|
-
return decryptionParams.content as any;
|
|
85
|
-
}
|
|
86
|
-
const decryptedNote = (decryptionParams.type ===
|
|
87
|
-
ModelsPublicNoteEncryptionTypeEnum.GpgKeys
|
|
88
|
-
? await decryptViaKeys(decryptionParams)
|
|
89
|
-
: await decryptViaPassword(decryptionParams)) as unknown as Promise<
|
|
90
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
91
|
-
>;
|
|
92
|
-
|
|
93
|
-
return decryptedNote;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
async function _encryptViaPassword<
|
|
97
|
-
T extends WithEncryptionContent<OrgNotePasswordEncryption>,
|
|
98
|
-
>({
|
|
99
|
-
content,
|
|
100
|
-
password,
|
|
101
|
-
format = 'binary',
|
|
102
|
-
}: T): Promise<T['format'] extends 'binary' ? Uint8Array : string> {
|
|
103
|
-
const message = await createMessage({
|
|
104
|
-
text: content,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const encryptedMessage = await _encrypt({
|
|
108
|
-
message,
|
|
109
|
-
format: format as any,
|
|
110
|
-
passwords: [password],
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return encryptedMessage as Promise<
|
|
114
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
115
|
-
>;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export async function _encryptViaKeys<
|
|
119
|
-
T extends WithEncryptionContent<OrgNoteGpgEncryption>,
|
|
120
|
-
>({
|
|
121
|
-
content,
|
|
122
|
-
publicKey: armoredPublicKey,
|
|
123
|
-
privateKey: armoredPrivateKey,
|
|
124
|
-
privateKeyPassphrase,
|
|
125
|
-
format = 'binary',
|
|
126
|
-
}: T): Promise<T['format'] extends 'binary' ? Uint8Array : string> {
|
|
127
|
-
const publicKey = await readKey({ armoredKey: armoredPublicKey });
|
|
128
|
-
|
|
129
|
-
const message = await createMessage({
|
|
130
|
-
text: content,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const encryptedPrivateKey = await readPrivateKey({
|
|
134
|
-
armoredKey: armoredPrivateKey,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const privateKey = privateKeyPassphrase
|
|
138
|
-
? await decryptKey({
|
|
139
|
-
privateKey: encryptedPrivateKey,
|
|
140
|
-
passphrase: privateKeyPassphrase,
|
|
141
|
-
})
|
|
142
|
-
: encryptedPrivateKey;
|
|
143
|
-
|
|
144
|
-
const encryptedMessage = await _encrypt({
|
|
145
|
-
message,
|
|
146
|
-
format: format as any,
|
|
147
|
-
encryptionKeys: publicKey,
|
|
148
|
-
signingKeys: privateKey,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return encryptedMessage as Promise<
|
|
152
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
153
|
-
>;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function _decryptViaPassword<
|
|
157
|
-
T extends Omit<WithDecryptionContent<OrgNotePasswordEncryption>, 'type'>,
|
|
158
|
-
>({
|
|
159
|
-
content,
|
|
160
|
-
password,
|
|
161
|
-
format = 'utf8',
|
|
162
|
-
}: T): Promise<T['format'] extends 'binary' ? Uint8Array : string> {
|
|
163
|
-
const isArmoredContent = typeof content === 'string';
|
|
164
|
-
|
|
165
|
-
const message = await (isArmoredContent
|
|
166
|
-
? readMessage({ armoredMessage: content })
|
|
167
|
-
: readMessage({ binaryMessage: content }));
|
|
168
|
-
|
|
169
|
-
const { data: decryptedText } = await _decrypt({
|
|
170
|
-
message,
|
|
171
|
-
format,
|
|
172
|
-
passwords: password,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
return decryptedText as Promise<
|
|
176
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
177
|
-
>;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async function _decryptViaKeys<
|
|
181
|
-
T extends Omit<WithDecryptionContent<OrgNoteGpgEncryption>, 'type'>,
|
|
182
|
-
>({
|
|
183
|
-
privateKey: armoredPrivateKey,
|
|
184
|
-
privateKeyPassphrase,
|
|
185
|
-
content,
|
|
186
|
-
format = 'utf8',
|
|
187
|
-
}: T): Promise<T['format'] extends 'binary' ? Uint8Array : string> {
|
|
188
|
-
const encryptedPrivateKey = await readPrivateKey({
|
|
189
|
-
armoredKey: armoredPrivateKey,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const privateKey = privateKeyPassphrase
|
|
193
|
-
? await decryptKey({
|
|
194
|
-
privateKey: encryptedPrivateKey,
|
|
195
|
-
passphrase: privateKeyPassphrase,
|
|
196
|
-
})
|
|
197
|
-
: encryptedPrivateKey;
|
|
198
|
-
|
|
199
|
-
const isString = typeof content === 'string';
|
|
200
|
-
const message = await (isString
|
|
201
|
-
? readMessage({ armoredMessage: content })
|
|
202
|
-
: readMessage({ binaryMessage: content }));
|
|
203
|
-
|
|
204
|
-
const { data: decryptedText } = await _decrypt({
|
|
205
|
-
message,
|
|
206
|
-
format,
|
|
207
|
-
decryptionKeys: privateKey,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
return decryptedText as Promise<
|
|
211
|
-
T['format'] extends 'binary' ? Uint8Array : string
|
|
212
|
-
>;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function withCustomErrors<P extends unknown[], T>(
|
|
216
|
-
fn: (...args: P) => Promise<T | never>
|
|
217
|
-
) {
|
|
218
|
-
return async (...args: P): Promise<T> => {
|
|
219
|
-
try {
|
|
220
|
-
return await fn(...args);
|
|
221
|
-
} catch (e: unknown) {
|
|
222
|
-
if (!(e instanceof Error)) {
|
|
223
|
-
throw e;
|
|
224
|
-
}
|
|
225
|
-
if (
|
|
226
|
-
[
|
|
227
|
-
noPrivateKeyPassphraseProvidedErrorMsg,
|
|
228
|
-
incorrectPrivateKeyPassphraseErrorMsg,
|
|
229
|
-
corruptedPrivateKeyErrorMsg,
|
|
230
|
-
decryptionKeyIsNotDecryptedErrorMsg,
|
|
231
|
-
armoredTextNotTypePrivateKeyErrorMsg,
|
|
232
|
-
].includes(e.message)
|
|
233
|
-
) {
|
|
234
|
-
throw new IncorrectOrMissingPrivateKeyPasswordError(e.message);
|
|
235
|
-
}
|
|
236
|
-
if (e.message === decriptionFailedErrorMsg) {
|
|
237
|
-
throw new ImpossibleToDecryptWithProvidedKeysError(e.message);
|
|
238
|
-
}
|
|
239
|
-
if (e.message === incorrectEncryptionPasswordErrorMsg) {
|
|
240
|
-
throw new IncorrectEncryptionPasswordError();
|
|
241
|
-
}
|
|
242
|
-
if (e.message === noSymmetricallyEncryptedSessionKeyErrorMsg) {
|
|
243
|
-
throw new NoKeysProvidedError();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (e.message === notPrivateKeyErrprMsg) {
|
|
247
|
-
throw new NoPasswordProvidedError();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
throw e;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// TODO: feat/native-encryption-support add custom error handling
|
|
256
|
-
export function armor(data: Uint8Array): string {
|
|
257
|
-
return _armor(enums.armor.message, data);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export async function unarmor(
|
|
261
|
-
data: string
|
|
262
|
-
): Promise<{ text: string; data: Stream<Uint8Array>; type: enums.armor }> {
|
|
263
|
-
return await _unarmor(data);
|
|
264
|
-
}
|