orgnote-api 0.7.12 → 0.7.14

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.
@@ -66,24 +66,18 @@ exports[`Should encrypt note via keys 1`] = `
66
66
  }
67
67
  `;
68
68
 
69
- exports[`Should not encrypt note with disabled encryption 1`] = `
69
+ exports[`Should encrypt note with empty encrypted property 1`] = `
70
70
  {
71
71
  "author": {
72
72
  "email": "test@mail.com",
73
73
  "id": "1",
74
74
  "name": "John Doe",
75
75
  },
76
- "content": "#+ID: qweqwe
77
- #+TITLE: Hello worlld
78
-
79
- * Hello?",
80
- "encrypted": null,
76
+ "encrypted": "gpgPassword",
81
77
  "id": "id",
82
78
  "meta": {
83
- "description": "Awesome description",
84
- "images": [],
79
+ "id": undefined,
85
80
  "published": false,
86
- "title": "My note title",
87
81
  },
88
82
  }
89
83
  `;
@@ -109,25 +103,3 @@ exports[`Should not encrypt public note 1`] = `
109
103
  },
110
104
  }
111
105
  `;
112
-
113
- exports[`Should not encrypt publick note 1`] = `
114
- {
115
- "author": {
116
- "email": "test@mail.com",
117
- "id": "1",
118
- "name": "John Doe",
119
- },
120
- "content": "#+ID: qweqwe
121
- #+TITLE: Hello worlld
122
-
123
- * Hello?",
124
- "encrypted": "gpgPassword",
125
- "id": "id",
126
- "meta": {
127
- "description": "Awesome description",
128
- "images": [],
129
- "published": true,
130
- "title": "My note title",
131
- },
132
- }
133
- `;
@@ -3,6 +3,7 @@ import {
3
3
  decryptViaKeys,
4
4
  encryptViaPassword,
5
5
  decryptViaPassword,
6
+ IncorrectOrMissingPrivateKeyPasswordError,
6
7
  } from '../encryption';
7
8
  import { test, expect } from 'vitest';
8
9
 
@@ -85,3 +86,43 @@ aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
85
86
  'Hello world'
86
87
  );
87
88
  });
89
+
90
+ test('Should raise incorrect or missing private key error', async () => {
91
+ const encryptedMsg = `-----B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 ZBmKzI4mvzDTFsd7VguB7frpsb+agUvhXXAJEHWEE4ZR3vQa1sWEnmxyAdNp
110
+ H9UFoIhGf9mSPlbBTMKEcAJmqzEIrb6z4psmmt6oYLXDR8PCxxK+g0xdrmbO
111
+ Az//AD0eRm8XHCHpwGf8YYWrNHOidDYpgmJTy7qFUwknWS+t3NlkU3CsCR+j
112
+ i9Km3edjOwPpJtgI0LeRRqXs3eUhLQARC5nFePbRWnFSXPBuFxBVZyL9AYrS
113
+ KQn4dM1p4eTtsiEu1NaTzRtQNZAFHcJpZ8qAL67LHoNdFe/atpCdlyV3yur9
114
+ RvAA3cB7cj7wab3beX+cTqxdhpGePZh0TrNd3liV69FtbnYfeDrtUYIL1jfT
115
+ EJN3l+qpveimyX655RrgFX3DNGrVbbhpx+FDF9Ky9kqb2BJBTFKoCBxbf0dS
116
+ sniNAsC/t/k6ErG8NKNQsNh1aeN6plXnxeVi1vv6SvO2mwZRVvDNT1hg9Cyc
117
+ UO1Pw43TRLO50HgR9+ERNXL491TJA0aCj14oXwsm0Dtg6EOltX0GUDwcPjv6
118
+ 6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
119
+ YQ==
120
+ =f4F1
121
+ -----END PGP MESSAGE-----`;
122
+
123
+ try {
124
+ await decryptViaPassword(encryptedMsg, 'password');
125
+ } catch (e) {
126
+ expect(e).toBeInstanceOf(IncorrectOrMissingPrivateKeyPasswordError);
127
+ }
128
+ });
@@ -195,7 +195,7 @@ test('Should not encrypt public note', async () => {
195
195
  expect(encryptedNote).toMatchSnapshot();
196
196
  });
197
197
 
198
- test('Should not encrypt note with disabled encryption', async () => {
198
+ test('Should encrypt note with empty encrypted property', async () => {
199
199
  const content = `#+ID: qweqwe
200
200
  #+TITLE: Hello worlld
201
201
 
@@ -203,7 +203,6 @@ test('Should not encrypt note with disabled encryption', async () => {
203
203
 
204
204
  const note: Note = {
205
205
  id: 'id',
206
- encrypted: null,
207
206
  meta: {
208
207
  title: 'My note title',
209
208
  images: [],
@@ -224,7 +223,9 @@ test('Should not encrypt note with disabled encryption', async () => {
224
223
  });
225
224
 
226
225
  expect(encryptedNote.content.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
227
- false
226
+ true
228
227
  );
228
+
229
+ delete encryptedNote.content;
229
230
  expect(encryptedNote).toMatchSnapshot();
230
231
  });
@@ -25,6 +25,9 @@ const decriptionFailedErrorMsg =
25
25
  const incorrectEncryptionPasswordErrorMsg =
26
26
  'Error decrypting message: Modification detected.';
27
27
 
28
+ const noSymmetricallyEncryptedSessionKey =
29
+ 'Error decrypting message: No symmetrically encrypted session key packet found.';
30
+
28
31
  export const encryptViaKeys = withCustomErrors(_encryptViaKeys);
29
32
  export const encryptViaPassword = withCustomErrors(_encryptViaPassword);
30
33
  export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
@@ -136,6 +139,7 @@ function withCustomErrors<P extends unknown[], T>(
136
139
  incorrectPrivateKeyPassphraseErrorMsg,
137
140
  corruptedPrivateKeyErrorMsg,
138
141
  decryptionKeyIsNotDecryptedErrorMsg,
142
+ noSymmetricallyEncryptedSessionKey,
139
143
  ].includes(e.message)
140
144
  ) {
141
145
  throw new IncorrectOrMissingPrivateKeyPasswordError(e.message);
@@ -23,7 +23,6 @@ export async function encryptNote<T extends AbstractEncryptedNote>(
23
23
  encryptionParams: OrgNoteEncryption
24
24
  ): Promise<T> {
25
25
  if (
26
- !note.encrypted ||
27
26
  !encryptionParams.type ||
28
27
  encryptionParams.type === ModelsPublicNoteEncryptedEnum.Disabled ||
29
28
  note.meta.published
@@ -80,7 +79,7 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
80
79
  encryptionParams: OrgNoteEncryption
81
80
  ): Promise<T> {
82
81
  if (
83
- !note.encrypted ||
82
+ note.meta.published ||
84
83
  !encryptionParams.type ||
85
84
  encryptionParams.type === ModelsPublicNoteEncryptedEnum.Disabled
86
85
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orgnote-api",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "description": "Official API for creating extensions for OrgNote app",
5
5
  "type": "module",
6
6
  "main": "./index.ts",