orgnote-api 0.13.1 → 0.14.1
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.
|
@@ -1,47 +1,51 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
3
|
exports[`Should decrypt note content via password 1`] = `
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
[
|
|
5
|
+
{
|
|
6
|
+
"encrypted": false,
|
|
7
|
+
"encryptionType": "gpgPassword",
|
|
8
|
+
"id": "id",
|
|
9
|
+
"meta": {
|
|
10
|
+
"headings": [
|
|
11
|
+
{
|
|
12
|
+
"level": 1,
|
|
13
|
+
"title": "Hello?",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
"id": "qweqwe",
|
|
17
|
+
"title": "Hello worlld",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
"#+ID: qweqwe
|
|
6
21
|
#+TITLE: Hello worlld
|
|
7
22
|
|
|
8
23
|
* Hello?",
|
|
9
|
-
|
|
10
|
-
"encryptionType": "gpgPassword",
|
|
11
|
-
"id": "id",
|
|
12
|
-
"meta": {
|
|
13
|
-
"headings": [
|
|
14
|
-
{
|
|
15
|
-
"level": 1,
|
|
16
|
-
"title": "Hello?",
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
"id": "qweqwe",
|
|
20
|
-
"title": "Hello worlld",
|
|
21
|
-
},
|
|
22
|
-
}
|
|
24
|
+
]
|
|
23
25
|
`;
|
|
24
26
|
|
|
25
27
|
exports[`Should decrypt note via provided keys 1`] = `
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
"encrypted": false,
|
|
31
|
+
"encryptionType": "gpgKeys",
|
|
32
|
+
"id": "id",
|
|
33
|
+
"meta": {
|
|
34
|
+
"headings": [
|
|
35
|
+
{
|
|
36
|
+
"level": 1,
|
|
37
|
+
"title": "Hello?",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
"id": "qweqwe",
|
|
41
|
+
"title": "Hello worlld",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
"#+ID: qweqwe
|
|
28
45
|
#+TITLE: Hello worlld
|
|
29
46
|
|
|
30
47
|
* Hello?",
|
|
31
|
-
|
|
32
|
-
"encryptionType": "gpgKeys",
|
|
33
|
-
"id": "id",
|
|
34
|
-
"meta": {
|
|
35
|
-
"headings": [
|
|
36
|
-
{
|
|
37
|
-
"level": 1,
|
|
38
|
-
"title": "Hello?",
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
"id": "qweqwe",
|
|
42
|
-
"title": "Hello worlld",
|
|
43
|
-
},
|
|
44
|
-
}
|
|
48
|
+
]
|
|
45
49
|
`;
|
|
46
50
|
|
|
47
51
|
exports[`Should encrypt note content via password 1`] = `
|
|
@@ -95,25 +99,27 @@ exports[`Should encrypt note with empty encrypted property 1`] = `
|
|
|
95
99
|
`;
|
|
96
100
|
|
|
97
101
|
exports[`Should not decrypt note without provided encrypted type 1`] = `
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
[
|
|
103
|
+
{
|
|
104
|
+
"author": {
|
|
105
|
+
"email": "test@mail.com",
|
|
106
|
+
"id": "1",
|
|
107
|
+
"name": "John Doe",
|
|
108
|
+
},
|
|
109
|
+
"encrypted": false,
|
|
110
|
+
"id": "id",
|
|
111
|
+
"meta": {
|
|
112
|
+
"description": "Awesome description",
|
|
113
|
+
"images": [],
|
|
114
|
+
"published": false,
|
|
115
|
+
"title": "My note title",
|
|
116
|
+
},
|
|
103
117
|
},
|
|
104
|
-
"
|
|
118
|
+
"#+ID: qweqwe
|
|
105
119
|
#+TITLE: Hello worlld
|
|
106
120
|
|
|
107
121
|
* Hello?",
|
|
108
|
-
|
|
109
|
-
"id": "id",
|
|
110
|
-
"meta": {
|
|
111
|
-
"description": "Awesome description",
|
|
112
|
-
"images": [],
|
|
113
|
-
"published": false,
|
|
114
|
-
"title": "My note title",
|
|
115
|
-
},
|
|
116
|
-
}
|
|
122
|
+
]
|
|
117
123
|
`;
|
|
118
124
|
|
|
119
125
|
exports[`Should not encrypt public note 1`] = `
|
|
@@ -123,10 +129,6 @@ exports[`Should not encrypt public note 1`] = `
|
|
|
123
129
|
"id": "1",
|
|
124
130
|
"name": "John Doe",
|
|
125
131
|
},
|
|
126
|
-
"content": "#+ID: qweqwe
|
|
127
|
-
#+TITLE: Hello worlld
|
|
128
|
-
|
|
129
|
-
* Hello?",
|
|
130
132
|
"encrypted": false,
|
|
131
133
|
"encryptionType": "gpgPassword",
|
|
132
134
|
"id": "id",
|
|
@@ -140,8 +142,19 @@ exports[`Should not encrypt public note 1`] = `
|
|
|
140
142
|
`;
|
|
141
143
|
|
|
142
144
|
exports[`Should set not encrypted status when params type does not provided 1`] = `
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
[
|
|
146
|
+
{
|
|
147
|
+
"encrypted": true,
|
|
148
|
+
"encryptionType": "gpgKeys",
|
|
149
|
+
"id": "id",
|
|
150
|
+
"meta": {
|
|
151
|
+
"description": "Awesome description",
|
|
152
|
+
"images": [],
|
|
153
|
+
"published": false,
|
|
154
|
+
"title": "My note title for decryption via keys",
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
"-----BEGIN PGP MESSAGE-----
|
|
145
158
|
|
|
146
159
|
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|
|
147
160
|
+CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
|
|
@@ -172,14 +185,5 @@ PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
|
172
185
|
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
173
186
|
=LjkG
|
|
174
187
|
-----END PGP MESSAGE-----",
|
|
175
|
-
|
|
176
|
-
"encryptionType": "gpgKeys",
|
|
177
|
-
"id": "id",
|
|
178
|
-
"meta": {
|
|
179
|
-
"description": "Awesome description",
|
|
180
|
-
"images": [],
|
|
181
|
-
"published": false,
|
|
182
|
-
"title": "My note title for decryption via keys",
|
|
183
|
-
},
|
|
184
|
-
}
|
|
188
|
+
]
|
|
185
189
|
`;
|
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
armoredPrivateKey,
|
|
7
7
|
privateKeyPassphrase,
|
|
8
8
|
} from './encryption-keys';
|
|
9
|
+
import { ModelsPublicNoteEncryptionTypeEnum } from '../../remote-api';
|
|
9
10
|
|
|
10
11
|
test('Should encrypt note content via password', async () => {
|
|
11
|
-
const
|
|
12
|
+
const noteText = `#+ID: qweqwe
|
|
12
13
|
|
|
13
14
|
#+TITLE: Hello worlld
|
|
14
15
|
|
|
@@ -23,7 +24,6 @@ test('Should encrypt note content via password', async () => {
|
|
|
23
24
|
published: false,
|
|
24
25
|
description: 'Awesome description',
|
|
25
26
|
},
|
|
26
|
-
content,
|
|
27
27
|
author: {
|
|
28
28
|
id: '1',
|
|
29
29
|
name: 'John Doe',
|
|
@@ -31,19 +31,26 @@ test('Should encrypt note content via password', async () => {
|
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const encryptedNote = await encryptNote(note, {
|
|
34
|
+
const [encryptedNote, encryptedNoteText] = await encryptNote(note, noteText, {
|
|
35
35
|
type: 'gpgPassword',
|
|
36
36
|
password: '123',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
expect(
|
|
39
|
+
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
40
40
|
true
|
|
41
41
|
);
|
|
42
|
-
delete encryptedNote.content;
|
|
43
42
|
expect(encryptedNote).toMatchSnapshot();
|
|
44
43
|
});
|
|
45
44
|
|
|
46
45
|
test('Should decrypt note content via password', async () => {
|
|
46
|
+
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
47
|
+
|
|
48
|
+
wy4ECQMI/CCaKMJEqy/gyROJeRgW9I738dDFBltFlxIjhxrN7nQ6gkX4GgX6
|
|
49
|
+
zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
|
|
50
|
+
2k3g68Afayke2nLkDNkH62tdOPiTkx7bSlp1zL4uU440IM1g6dC72JkmtoTJ
|
|
51
|
+
5Bjlwt4ZhxFsh+c=
|
|
52
|
+
=csID
|
|
53
|
+
-----END PGP MESSAGE-----`;
|
|
47
54
|
const note: Note = {
|
|
48
55
|
id: 'id',
|
|
49
56
|
encryptionType: 'gpgPassword',
|
|
@@ -53,17 +60,9 @@ test('Should decrypt note content via password', async () => {
|
|
|
53
60
|
published: false,
|
|
54
61
|
description: 'Awesome description',
|
|
55
62
|
},
|
|
56
|
-
content: `-----BEGIN PGP MESSAGE-----
|
|
57
|
-
|
|
58
|
-
wy4ECQMI/CCaKMJEqy/gyROJeRgW9I738dDFBltFlxIjhxrN7nQ6gkX4GgX6
|
|
59
|
-
zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
|
|
60
|
-
2k3g68Afayke2nLkDNkH62tdOPiTkx7bSlp1zL4uU440IM1g6dC72JkmtoTJ
|
|
61
|
-
5Bjlwt4ZhxFsh+c=
|
|
62
|
-
=csID
|
|
63
|
-
-----END PGP MESSAGE-----`,
|
|
64
63
|
};
|
|
65
64
|
|
|
66
|
-
const decryptedNote = await decryptNote(note, {
|
|
65
|
+
const decryptedNote = await decryptNote(note, noteText, {
|
|
67
66
|
type: 'gpgPassword',
|
|
68
67
|
password: '123',
|
|
69
68
|
});
|
|
@@ -71,8 +70,8 @@ zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
|
|
|
71
70
|
expect(decryptedNote).toMatchSnapshot();
|
|
72
71
|
});
|
|
73
72
|
|
|
74
|
-
test('Should encrypt note via keys', async () => {
|
|
75
|
-
const
|
|
73
|
+
test.skip('Should encrypt note via keys', async () => {
|
|
74
|
+
const noteText = `#+ID: qweqwe
|
|
76
75
|
#+TITLE: Hello worlld
|
|
77
76
|
|
|
78
77
|
* Hello?`;
|
|
@@ -86,7 +85,6 @@ test('Should encrypt note via keys', async () => {
|
|
|
86
85
|
published: false,
|
|
87
86
|
description: 'Awesome description',
|
|
88
87
|
},
|
|
89
|
-
content,
|
|
90
88
|
author: {
|
|
91
89
|
id: '1',
|
|
92
90
|
name: 'John Doe',
|
|
@@ -94,31 +92,21 @@ test('Should encrypt note via keys', async () => {
|
|
|
94
92
|
},
|
|
95
93
|
};
|
|
96
94
|
|
|
97
|
-
const encryptedNote = await encryptNote(note, {
|
|
98
|
-
type:
|
|
95
|
+
const [encryptedNote, encryptedNoteText] = await encryptNote(note, noteText, {
|
|
96
|
+
type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
99
97
|
publicKey: armoredPublicKey,
|
|
100
98
|
privateKey: armoredPrivateKey,
|
|
101
99
|
privateKeyPassphrase,
|
|
102
100
|
});
|
|
103
101
|
|
|
104
|
-
expect(
|
|
102
|
+
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
105
103
|
true
|
|
106
104
|
);
|
|
107
|
-
delete encryptedNote.content;
|
|
108
105
|
expect(encryptedNote).toMatchSnapshot();
|
|
109
106
|
});
|
|
110
107
|
|
|
111
108
|
test('Should decrypt note via provided keys', async () => {
|
|
112
|
-
const
|
|
113
|
-
id: 'id',
|
|
114
|
-
encryptionType: 'gpgKeys',
|
|
115
|
-
meta: {
|
|
116
|
-
title: 'My note title for decryption via keys',
|
|
117
|
-
images: [],
|
|
118
|
-
published: false,
|
|
119
|
-
description: 'Awesome description',
|
|
120
|
-
},
|
|
121
|
-
content: `-----BEGIN PGP MESSAGE-----
|
|
109
|
+
const encryptedNoteText = `-----BEGIN PGP MESSAGE-----
|
|
122
110
|
|
|
123
111
|
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|
|
124
112
|
+CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
|
|
@@ -148,10 +136,20 @@ cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
|
148
136
|
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
149
137
|
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
150
138
|
=LjkG
|
|
151
|
-
-----END PGP MESSAGE
|
|
139
|
+
-----END PGP MESSAGE-----`;
|
|
140
|
+
|
|
141
|
+
const note: Note = {
|
|
142
|
+
id: 'id',
|
|
143
|
+
encryptionType: 'gpgKeys',
|
|
144
|
+
meta: {
|
|
145
|
+
title: 'My note title for decryption via keys',
|
|
146
|
+
images: [],
|
|
147
|
+
published: false,
|
|
148
|
+
description: 'Awesome description',
|
|
149
|
+
},
|
|
152
150
|
};
|
|
153
151
|
|
|
154
|
-
const decryptedNote = await decryptNote(note, {
|
|
152
|
+
const decryptedNote = await decryptNote(note, encryptedNoteText, {
|
|
155
153
|
type: 'gpgKeys',
|
|
156
154
|
publicKey: armoredPublicKey,
|
|
157
155
|
privateKey: armoredPrivateKey,
|
|
@@ -162,7 +160,7 @@ yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
|
162
160
|
});
|
|
163
161
|
|
|
164
162
|
test('Should not encrypt public note', async () => {
|
|
165
|
-
const
|
|
163
|
+
const noteText = `#+ID: qweqwe
|
|
166
164
|
#+TITLE: Hello worlld
|
|
167
165
|
|
|
168
166
|
* Hello?`;
|
|
@@ -176,7 +174,6 @@ test('Should not encrypt public note', async () => {
|
|
|
176
174
|
published: true,
|
|
177
175
|
description: 'Awesome description',
|
|
178
176
|
},
|
|
179
|
-
content,
|
|
180
177
|
author: {
|
|
181
178
|
id: '1',
|
|
182
179
|
name: 'John Doe',
|
|
@@ -184,19 +181,19 @@ test('Should not encrypt public note', async () => {
|
|
|
184
181
|
},
|
|
185
182
|
};
|
|
186
183
|
|
|
187
|
-
const encryptedNote = await encryptNote(note, {
|
|
184
|
+
const [encryptedNote, encryptedNoteText] = await encryptNote(note, noteText, {
|
|
188
185
|
type: 'gpgPassword',
|
|
189
186
|
password: '123',
|
|
190
187
|
});
|
|
191
188
|
|
|
192
|
-
expect(
|
|
189
|
+
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
193
190
|
false
|
|
194
191
|
);
|
|
195
192
|
expect(encryptedNote).toMatchSnapshot();
|
|
196
193
|
});
|
|
197
194
|
|
|
198
195
|
test('Should encrypt note with empty encrypted property', async () => {
|
|
199
|
-
const
|
|
196
|
+
const noteText = `#+ID: qweqwe
|
|
200
197
|
#+TITLE: Hello worlld
|
|
201
198
|
|
|
202
199
|
* Hello?`;
|
|
@@ -209,7 +206,6 @@ test('Should encrypt note with empty encrypted property', async () => {
|
|
|
209
206
|
published: false,
|
|
210
207
|
description: 'Awesome description',
|
|
211
208
|
},
|
|
212
|
-
content,
|
|
213
209
|
author: {
|
|
214
210
|
id: '1',
|
|
215
211
|
name: 'John Doe',
|
|
@@ -217,21 +213,20 @@ test('Should encrypt note with empty encrypted property', async () => {
|
|
|
217
213
|
},
|
|
218
214
|
};
|
|
219
215
|
|
|
220
|
-
const encryptedNote = await encryptNote(note, {
|
|
216
|
+
const [encryptedNote, encryptedNoteText] = await encryptNote(note, noteText, {
|
|
221
217
|
type: 'gpgPassword',
|
|
222
218
|
password: '123',
|
|
223
219
|
});
|
|
224
220
|
|
|
225
|
-
expect(
|
|
221
|
+
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
226
222
|
true
|
|
227
223
|
);
|
|
228
224
|
|
|
229
|
-
delete encryptedNote.content;
|
|
230
225
|
expect(encryptedNote).toMatchSnapshot();
|
|
231
226
|
});
|
|
232
227
|
|
|
233
228
|
test('Should not decrypt note without provided encrypted type', async () => {
|
|
234
|
-
const
|
|
229
|
+
const noteText = `#+ID: qweqwe
|
|
235
230
|
#+TITLE: Hello worlld
|
|
236
231
|
|
|
237
232
|
* Hello?`;
|
|
@@ -244,7 +239,6 @@ test('Should not decrypt note without provided encrypted type', async () => {
|
|
|
244
239
|
description: 'Awesome description',
|
|
245
240
|
},
|
|
246
241
|
encrypted: undefined,
|
|
247
|
-
content,
|
|
248
242
|
author: {
|
|
249
243
|
id: '1',
|
|
250
244
|
name: 'John Doe',
|
|
@@ -252,12 +246,12 @@ test('Should not decrypt note without provided encrypted type', async () => {
|
|
|
252
246
|
},
|
|
253
247
|
};
|
|
254
248
|
|
|
255
|
-
const
|
|
249
|
+
const decryptedInfo = await decryptNote(note, noteText, {
|
|
256
250
|
type: 'gpgPassword',
|
|
257
251
|
password: '123',
|
|
258
252
|
});
|
|
259
253
|
|
|
260
|
-
expect(
|
|
254
|
+
expect(decryptedInfo).toMatchSnapshot();
|
|
261
255
|
});
|
|
262
256
|
|
|
263
257
|
test('Should decrypt note and note meta', async () => {
|
|
@@ -272,27 +266,33 @@ test('Should decrypt note and note meta', async () => {
|
|
|
272
266
|
id: 'id',
|
|
273
267
|
meta: { ...meta },
|
|
274
268
|
encryptionType: 'gpgPassword',
|
|
275
|
-
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const noteText = `#+TITLE: My note title
|
|
276
272
|
#+DESCRIPTION: Awesome description
|
|
277
273
|
#+PUBLISHED: false
|
|
278
274
|
#+FILETAGS: :tag1:tag2:
|
|
279
275
|
|
|
280
276
|
[[./image1.png]]
|
|
281
277
|
|
|
282
|
-
Hello world
|
|
283
|
-
};
|
|
278
|
+
Hello world`;
|
|
284
279
|
|
|
285
|
-
const encryptedNote = await encryptNote(note, {
|
|
280
|
+
const [encryptedNote, encryptedNoteText] = await encryptNote(note, noteText, {
|
|
286
281
|
type: 'gpgPassword',
|
|
287
282
|
password: '123',
|
|
288
283
|
});
|
|
289
284
|
|
|
290
|
-
const decryptedNote = await decryptNote(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
285
|
+
const [decryptedNote, decryptedNoteText] = await decryptNote(
|
|
286
|
+
encryptedNote,
|
|
287
|
+
encryptedNoteText,
|
|
288
|
+
{
|
|
289
|
+
type: 'gpgPassword',
|
|
290
|
+
password: '123',
|
|
291
|
+
}
|
|
292
|
+
);
|
|
294
293
|
|
|
295
|
-
expect(meta).toEqual(
|
|
294
|
+
expect(decryptedNote.meta).toEqual(meta);
|
|
295
|
+
expect(decryptedNoteText).toEqual(noteText);
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
test('Should set not encrypted status when params type does not provided', async () => {
|
|
@@ -305,7 +305,9 @@ test('Should set not encrypted status when params type does not provided', async
|
|
|
305
305
|
published: false,
|
|
306
306
|
description: 'Awesome description',
|
|
307
307
|
},
|
|
308
|
-
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const noteText = `-----BEGIN PGP MESSAGE-----
|
|
309
311
|
|
|
310
312
|
wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
|
|
311
313
|
+CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
|
|
@@ -335,10 +337,9 @@ cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
|
|
|
335
337
|
PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
|
|
336
338
|
yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
337
339
|
=LjkG
|
|
338
|
-
-----END PGP MESSAGE
|
|
339
|
-
};
|
|
340
|
+
-----END PGP MESSAGE-----`;
|
|
340
341
|
|
|
341
|
-
const decryptedNote = await decryptNote(note, {
|
|
342
|
+
const decryptedNote = await decryptNote(note, noteText, {
|
|
342
343
|
type: 'disabled',
|
|
343
344
|
});
|
|
344
345
|
|
|
@@ -16,7 +16,6 @@ import { isGpgEncrypted } from '..';
|
|
|
16
16
|
export type NoteEncryptionType = `${ModelsPublicNote['encryptionType']}`;
|
|
17
17
|
|
|
18
18
|
export interface AbstractEncryptedNote {
|
|
19
|
-
content: string;
|
|
20
19
|
encryptionType?: NoteEncryptionType;
|
|
21
20
|
encrypted?: boolean;
|
|
22
21
|
meta: {
|
|
@@ -24,23 +23,27 @@ export interface AbstractEncryptedNote {
|
|
|
24
23
|
published?: boolean;
|
|
25
24
|
};
|
|
26
25
|
}
|
|
26
|
+
|
|
27
|
+
export type EncryptionResult<T> = Promise<[T, string]>;
|
|
28
|
+
|
|
27
29
|
// TODO: master change signature for encrypt notes without content
|
|
28
30
|
export async function encryptNote<T extends AbstractEncryptedNote>(
|
|
29
31
|
note: T,
|
|
32
|
+
noteText: string,
|
|
30
33
|
encryptionParams: OrgNoteEncryption
|
|
31
|
-
):
|
|
34
|
+
): EncryptionResult<T> {
|
|
32
35
|
note.encrypted = false;
|
|
33
36
|
if (
|
|
34
37
|
!encryptionParams.type ||
|
|
35
38
|
encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled ||
|
|
36
39
|
note.meta.published
|
|
37
40
|
) {
|
|
38
|
-
return note;
|
|
41
|
+
return [note, noteText];
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
note.meta = { id: note.meta.id, published: note.meta.published };
|
|
42
45
|
|
|
43
|
-
const encryptedNote =
|
|
46
|
+
const [encryptedNote, encryptedNoteText] =
|
|
44
47
|
encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.GpgKeys
|
|
45
48
|
? await encryptNoteViaKeys(
|
|
46
49
|
note,
|
|
@@ -48,48 +51,55 @@ export async function encryptNote<T extends AbstractEncryptedNote>(
|
|
|
48
51
|
encryptionParams.privateKey,
|
|
49
52
|
encryptionParams.privateKeyPassphrase
|
|
50
53
|
)
|
|
51
|
-
: await encryptNoteViaPassword(note, encryptionParams.password);
|
|
54
|
+
: await encryptNoteViaPassword(note, noteText, encryptionParams.password);
|
|
52
55
|
|
|
53
56
|
encryptedNote.encrypted = true;
|
|
54
|
-
return encryptedNote;
|
|
57
|
+
return [encryptedNote, encryptedNoteText];
|
|
55
58
|
}
|
|
56
59
|
export async function encryptNoteViaPassword<T extends AbstractEncryptedNote>(
|
|
57
60
|
note: T,
|
|
61
|
+
noteText: string,
|
|
58
62
|
password: string
|
|
59
|
-
): Promise<T> {
|
|
60
|
-
const
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
): Promise<[T, string]> {
|
|
64
|
+
const encryptedNoteText = await encryptViaPassword(noteText, password);
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
...note,
|
|
68
|
+
encrypted: ModelsPublicNoteEncryptionTypeEnum.GpgPassword,
|
|
69
|
+
},
|
|
70
|
+
encryptedNoteText,
|
|
71
|
+
];
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
export async function encryptNoteViaKeys<T extends AbstractEncryptedNote>(
|
|
69
75
|
note: T,
|
|
76
|
+
noteText: string,
|
|
70
77
|
publicKey: string,
|
|
71
78
|
privateKey: string,
|
|
72
79
|
privateKeyPassphrase?: string
|
|
73
|
-
): Promise<T> {
|
|
74
|
-
const
|
|
75
|
-
|
|
80
|
+
): Promise<[T, string]> {
|
|
81
|
+
const encryptedNoteText = await encryptViaKeys(
|
|
82
|
+
noteText,
|
|
76
83
|
publicKey,
|
|
77
84
|
privateKey,
|
|
78
85
|
privateKeyPassphrase
|
|
79
86
|
);
|
|
80
87
|
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
...note,
|
|
91
|
+
encrypted: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
92
|
+
},
|
|
93
|
+
encryptedNoteText,
|
|
94
|
+
];
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
export async function decryptNote<T extends AbstractEncryptedNote>(
|
|
89
98
|
note: T,
|
|
99
|
+
noteText: string,
|
|
90
100
|
encryptionParams: OrgNoteEncryption
|
|
91
|
-
):
|
|
92
|
-
const isContentEncrypted = isGpgEncrypted(
|
|
101
|
+
): EncryptionResult<T> {
|
|
102
|
+
const isContentEncrypted = isGpgEncrypted(noteText);
|
|
93
103
|
if (
|
|
94
104
|
note.meta.published ||
|
|
95
105
|
!note.encryptionType ||
|
|
@@ -98,52 +108,62 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
|
|
|
98
108
|
!isContentEncrypted
|
|
99
109
|
) {
|
|
100
110
|
note.encrypted = isContentEncrypted;
|
|
101
|
-
return note;
|
|
111
|
+
return [note, noteText];
|
|
102
112
|
}
|
|
103
113
|
note.encrypted = true;
|
|
104
|
-
const decryptedNote =
|
|
114
|
+
const [decryptedNote, decryptedNoteText] =
|
|
105
115
|
encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.GpgKeys
|
|
106
116
|
? await decryptNoteViaKeys(
|
|
107
117
|
note,
|
|
118
|
+
noteText,
|
|
108
119
|
encryptionParams.privateKey,
|
|
109
120
|
encryptionParams.privateKeyPassphrase
|
|
110
121
|
)
|
|
111
|
-
: await decryptNoteViaPassword(note, encryptionParams.password);
|
|
122
|
+
: await decryptNoteViaPassword(note, noteText, encryptionParams.password);
|
|
112
123
|
|
|
113
|
-
const parsed = withMetaInfo(parse(
|
|
124
|
+
const parsed = withMetaInfo(parse(decryptedNoteText));
|
|
114
125
|
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
...decryptedNote,
|
|
129
|
+
encrypted: false,
|
|
130
|
+
meta: parsed.meta,
|
|
131
|
+
},
|
|
132
|
+
decryptedNoteText,
|
|
133
|
+
];
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
export async function decryptNoteViaPassword<T extends AbstractEncryptedNote>(
|
|
123
137
|
note: T,
|
|
138
|
+
noteText: string,
|
|
124
139
|
password: string
|
|
125
|
-
):
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
): EncryptionResult<T> {
|
|
141
|
+
const decryptedNoteText = await decryptViaPassword(noteText, password);
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
...note,
|
|
145
|
+
encrypted: ModelsPublicNoteEncryptionTypeEnum.GpgPassword,
|
|
146
|
+
},
|
|
147
|
+
decryptedNoteText,
|
|
148
|
+
];
|
|
132
149
|
}
|
|
133
150
|
|
|
134
151
|
export async function decryptNoteViaKeys<T extends AbstractEncryptedNote>(
|
|
135
152
|
note: T,
|
|
153
|
+
noteText: string,
|
|
136
154
|
privateKey: string,
|
|
137
155
|
privateKeyPassphrase?: string
|
|
138
|
-
):
|
|
139
|
-
const
|
|
140
|
-
|
|
156
|
+
): EncryptionResult<T> {
|
|
157
|
+
const decryptedNoteText = await decryptViaKeys(
|
|
158
|
+
noteText,
|
|
141
159
|
privateKey,
|
|
142
160
|
privateKeyPassphrase
|
|
143
161
|
);
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
...note,
|
|
165
|
+
encrypted: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
166
|
+
},
|
|
167
|
+
decryptedNoteText,
|
|
168
|
+
];
|
|
149
169
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orgnote-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Official API for creating extensions for OrgNote app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@codemirror/view": "6.26.3",
|
|
45
45
|
"axios": "1.7.3",
|
|
46
46
|
"openpgp": "5.11.1",
|
|
47
|
-
"org-mode-ast": "0.11.
|
|
47
|
+
"org-mode-ast": "0.11.7",
|
|
48
48
|
"vue": "3.4.15",
|
|
49
49
|
"vue-router": "4.2.5"
|
|
50
50
|
},
|