orgnote-api 0.15.0 → 0.15.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.
@@ -9,6 +9,8 @@ import {
9
9
  encrypt,
10
10
  decrypt,
11
11
  _encryptViaKeys,
12
+ armor,
13
+ unarmor,
12
14
  } from '../encryption';
13
15
  import { test, expect } from 'vitest';
14
16
 
@@ -306,3 +308,24 @@ test('Should encrypt to armored text and decrypt as binary format', async () =>
306
308
 
307
309
  expect(decryptedMessage).toBeInstanceOf(Uint8Array);
308
310
  });
311
+
312
+ test('Should armor and unarmor encrypted file', async () => {
313
+ const content: Uint8Array = new Uint8Array([
314
+ 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
315
+ ]);
316
+
317
+ const armored = armor(content);
318
+
319
+ expect(armored).toMatchInlineSnapshot(`
320
+ "-----BEGIN PGP MESSAGE-----
321
+
322
+ SGVsbG8gd29ybGQ=
323
+ =7asC
324
+ -----END PGP MESSAGE-----
325
+ "
326
+ `);
327
+
328
+ const { text, data } = await unarmor(armored);
329
+
330
+ expect(data).toEqual(content);
331
+ });
@@ -6,6 +6,7 @@ import {
6
6
  readKey,
7
7
  readMessage,
8
8
  readPrivateKey,
9
+ Stream,
9
10
  } from 'openpgp';
10
11
  import { ModelsPublicNoteEncryptionTypeEnum } from '../remote-api';
11
12
  import {
@@ -14,6 +15,7 @@ import {
14
15
  WithDecryptionContent,
15
16
  } from '../models/encryption';
16
17
  import { OrgNoteGpgEncryption, WithEncryptionContent } from 'src/models';
18
+ import { armor as _armor, unarmor as _unarmor, enums } from 'openpgp';
17
19
 
18
20
  export class IncorrectOrMissingPrivateKeyPasswordError extends Error {}
19
21
  export class ImpossibleToDecryptWithProvidedKeysError extends Error {}
@@ -249,3 +251,14 @@ function withCustomErrors<P extends unknown[], T>(
249
251
  }
250
252
  };
251
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
+ }
@@ -1,16 +1,6 @@
1
- import {
2
- ModelsPublicNote,
3
- ModelsPublicNoteEncryptionTypeEnum,
4
- } from '../remote-api';
1
+ import { ModelsPublicNoteEncryptionTypeEnum } from '../remote-api';
5
2
 
6
- import {
7
- decrypt,
8
- decryptViaKeys,
9
- decryptViaPassword,
10
- encrypt,
11
- encryptViaKeys,
12
- encryptViaPassword,
13
- } from './encryption';
3
+ import { decrypt, encrypt } from './encryption';
14
4
  import {
15
5
  OrgNoteEncryption,
16
6
  WithDecryptionContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orgnote-api",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Official API for creating extensions for OrgNote app",
5
5
  "type": "module",
6
6
  "main": "./index.ts",