orgnote-api 0.17.1 → 0.17.3
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/README.md +158 -0
- package/api.d.ts +112 -0
- package/api.js +1 -0
- package/encryption/__tests__/encryption-keys.d.ts +3 -0
- package/encryption/__tests__/{encryption-keys.ts → encryption-keys.js} +0 -2
- package/encryption/__tests__/encryption.spec.d.ts +1 -0
- package/encryption/__tests__/encryption.spec.js +287 -0
- package/encryption/__tests__/note-encryption.spec.d.ts +1 -0
- package/encryption/__tests__/note-encryption.spec.js +364 -0
- package/encryption/encryption.d.ts +27 -0
- package/encryption/encryption.js +156 -0
- package/encryption/index.js +2 -0
- package/encryption/note-encryption.d.ts +12 -0
- package/encryption/note-encryption.js +42 -0
- package/files-api.d.ts +7 -0
- package/files-api.js +22 -0
- package/index.js +5 -0
- package/models/command.d.ts +29 -0
- package/models/command.js +1 -0
- package/models/completion.d.ts +22 -0
- package/models/completion.js +1 -0
- package/models/default-commands.d.ts +30 -0
- package/models/default-commands.js +41 -0
- package/models/editor.d.ts +23 -0
- package/models/editor.js +1 -0
- package/models/encryption.d.ts +31 -0
- package/models/encryption.js +1 -0
- package/models/extension.d.ts +34 -0
- package/models/extension.js +1 -0
- package/models/file-system.d.ts +23 -0
- package/models/file-system.js +1 -0
- package/models/index.js +13 -0
- package/models/modal.d.ts +10 -0
- package/models/modal.js +1 -0
- package/models/note.d.ts +23 -0
- package/models/note.js +1 -0
- package/models/sync.d.ts +34 -0
- package/models/sync.js +1 -0
- package/models/theme-variables.d.ts +192 -0
- package/models/theme-variables.js +194 -0
- package/models/{vue-component.ts → vue-component.d.ts} +1 -1
- package/models/vue-component.js +1 -0
- package/models/widget-type.d.ts +5 -0
- package/models/widget-type.js +6 -0
- package/models/widget.d.ts +51 -0
- package/models/widget.js +1 -0
- package/package.json +8 -17
- package/remote-api/api.d.ts +1525 -0
- package/remote-api/{api.ts → api.js} +246 -1149
- package/remote-api/base.d.ts +66 -0
- package/remote-api/{base.ts → base.js} +13 -36
- package/remote-api/common.d.ts +65 -0
- package/remote-api/{common.ts → common.js} +31 -48
- package/remote-api/{configuration.ts → configuration.d.ts} +3 -22
- package/remote-api/configuration.js +95 -0
- package/remote-api/index.d.ts +13 -0
- package/remote-api/{index.ts → index.js} +0 -3
- package/tools/__tests__/find-files-diff.spec.d.ts +1 -0
- package/tools/__tests__/find-files-diff.spec.js +110 -0
- package/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
- package/tools/__tests__/find-note-files-diff.spec.js +168 -0
- package/tools/__tests__/get-file-name.spec.d.ts +1 -0
- package/tools/__tests__/{get-file-name.spec.ts → get-file-name.spec.js} +4 -8
- package/tools/__tests__/get-string-path.spec.d.ts +1 -0
- package/tools/__tests__/get-string-path.spec.js +27 -0
- package/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
- package/tools/__tests__/{is-gpg-encrypted.spec.ts → is-gpg-encrypted.spec.js} +4 -8
- package/tools/__tests__/is-org-file.spec.d.ts +1 -0
- package/tools/__tests__/is-org-file.spec.js +54 -0
- package/tools/__tests__/join.spec.d.ts +1 -0
- package/tools/__tests__/join.spec.js +14 -0
- package/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
- package/tools/__tests__/read-org-files-recursively.spec.js +51 -0
- package/tools/extend-notes-files-diff.d.ts +3 -0
- package/tools/extend-notes-files-diff.js +21 -0
- package/tools/find-notes-files-diff.d.ts +5 -0
- package/tools/find-notes-files-diff.js +108 -0
- package/tools/get-file-name.d.ts +2 -0
- package/tools/get-file-name.js +6 -0
- package/tools/get-string-path.d.ts +1 -0
- package/tools/get-string-path.js +6 -0
- package/tools/index.js +6 -0
- package/tools/is-gpg-encrypted.d.ts +1 -0
- package/tools/is-gpg-encrypted.js +6 -0
- package/tools/is-org-file.d.ts +2 -0
- package/tools/is-org-file.js +4 -0
- package/tools/join.d.ts +1 -0
- package/tools/join.js +3 -0
- package/tools/mock-server.d.ts +1 -0
- package/tools/mock-server.js +12 -0
- package/LICENSE +0 -674
- package/README.org +0 -97
- package/api.ts +0 -123
- package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -215
- package/encryption/__tests__/encryption.spec.ts +0 -355
- package/encryption/__tests__/note-encryption.spec.ts +0 -424
- package/encryption/encryption.ts +0 -265
- package/encryption/note-encryption.ts +0 -78
- 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 -54
- package/models/extension.ts +0 -45
- package/models/file-system.ts +0 -30
- package/models/modal.ts +0 -12
- package/models/note.ts +0 -26
- package/models/sync.ts +0 -43
- 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__/__snapshots__/join.spec.ts.snap +0 -9
- package/tools/__tests__/find-files-diff.spec.ts +0 -177
- package/tools/__tests__/find-note-files-diff.spec.ts +0 -207
- package/tools/__tests__/get-string-path.spec.ts +0 -32
- package/tools/__tests__/is-org-file.spec.ts +0 -62
- package/tools/__tests__/join.spec.ts +0 -16
- package/tools/__tests__/read-org-files-recursively.spec.ts +0 -61
- package/tools/extend-notes-files-diff.ts +0 -35
- package/tools/find-notes-files-diff.ts +0 -185
- package/tools/get-file-name.ts +0 -7
- package/tools/get-string-path.ts +0 -6
- package/tools/is-gpg-encrypted.ts +0 -6
- package/tools/is-org-file.ts +0 -7
- package/tools/join.ts +0 -3
- package/tools/mock-server.ts +0 -16
- /package/encryption/{index.ts → index.d.ts} +0 -0
- /package/{index.ts → index.d.ts} +0 -0
- /package/models/{index.ts → index.d.ts} +0 -0
- /package/tools/{index.ts → index.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
# Table of Contents
|
|
3
|
+
|
|
4
|
+
1. [Introduction](#orged65399)
|
|
5
|
+
2. [Connected links](#orgc368352)
|
|
6
|
+
3. [Extension structure](#org1370386)
|
|
7
|
+
1. [Folder structure](#org6a7f73b)
|
|
8
|
+
2. [Extension entrypoint](#orge2d0f79)
|
|
9
|
+
3. [Extension manifest](#org1e76d43)
|
|
10
|
+
4. [Extension API](#orgbb09389)
|
|
11
|
+
4. [Publish to official repository](#orgdd94657)
|
|
12
|
+
5. [Extensions example](#orgf459c20)
|
|
13
|
+
6. [Contribute guide](#org383a272)
|
|
14
|
+
|
|
15
|
+
<div align='center'>
|
|
16
|
+
|
|
17
|
+
<img src='./images/image.png' width='256px' height='256px'>
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<div align='center'>
|
|
24
|
+
|
|
25
|
+
<span class='badge-buymeacoffee'>
|
|
26
|
+
|
|
27
|
+
<a href='https://www.paypal.me/darkawower' title='Paypal' target='_blank'><img src='https://img.shields.io/badge/paypal-donate-blue.svg' alt='Buy Me A Coffee donate button' /></a>
|
|
28
|
+
|
|
29
|
+
</span>
|
|
30
|
+
|
|
31
|
+
<span class='badge-patreon'>
|
|
32
|
+
|
|
33
|
+
<a href='https://patreon.com/artawower' target='_blank' title='Donate to this project using Patreon'><img src='https://img.shields.io/badge/patreon-donate-orange.svg' alt='Patreon donate button' /></a>
|
|
34
|
+
|
|
35
|
+
</span>
|
|
36
|
+
|
|
37
|
+
<a href='https://wakatime.com/badge/github/Artawower/orgnote-api'><img src='https://wakatime.com/badge/github/Artawower/orgnote-api.svg' alt='wakatime'></a>
|
|
38
|
+
|
|
39
|
+
<a href='https://github.com/artawower/orgnote-api/actions/workflows/melpazoid.yml/badge.svg'><img src='https://github.com/artawower/orgnote-api/actions/workflows/melpazoid.yml/badge.svg' alt='ci' /></a>
|
|
40
|
+
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<a id="orged65399"></a>
|
|
45
|
+
|
|
46
|
+
# Introduction
|
|
47
|
+
|
|
48
|
+
This is API for [OrgNote](https://github.com/artawower/orgnote) extensions.
|
|
49
|
+
|
|
50
|
+
**Warning** This API is not stable yet, so it can be changed in the future.
|
|
51
|
+
|
|
52
|
+
You can find all available methods here. They are currently undocumented.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
<a id="orgc368352"></a>
|
|
56
|
+
|
|
57
|
+
# Connected links
|
|
58
|
+
|
|
59
|
+
- [Built-in extensions](https://github.com/Artawower/orgnote-client/tree/master/src/components/extensions)
|
|
60
|
+
- [Type definition for existing extension API](https://github.com/Artawower/orgnote-api/blob/master/src/api.ts#L24)
|
|
61
|
+
- [OrgNote entrypoint](https://github.com/artawower/orgnote)
|
|
62
|
+
- [Official website](https://org-note.com/)
|
|
63
|
+
- [Org Note client](https://github.com/Artawower/orgnote-client)
|
|
64
|
+
- [Repository with collection of extensions](https://github.com/Artawower/orgnote-extensions)
|
|
65
|
+
- [Typescript abstract syntax tree for org mode.](https://github.com/Artawower/org-mode-ast)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
<a id="org1370386"></a>
|
|
69
|
+
|
|
70
|
+
# Extension structure
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
<a id="org6a7f73b"></a>
|
|
74
|
+
|
|
75
|
+
## Folder structure
|
|
76
|
+
|
|
77
|
+
**Compiled extension should be placed in the `index.js` file or `/dist/index.js` file in the public GIT repository**
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
<a id="orge2d0f79"></a>
|
|
81
|
+
|
|
82
|
+
## Extension entrypoint
|
|
83
|
+
|
|
84
|
+
Each extension should **export an object by default** with the following structure:
|
|
85
|
+
|
|
86
|
+
interface Extension {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
|
|
89
|
+
onMounted: (api: OrgNoteApi) => Promise<void>;
|
|
90
|
+
onUnmounted?: (api: OrgNoteApi) => Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
You can find available methods of `OrgNoteApi` [here](https://github.com/Artawower/orgnote-api/blob/master/src/api.ts#L24)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<a id="org1e76d43"></a>
|
|
97
|
+
|
|
98
|
+
## Extension manifest
|
|
99
|
+
|
|
100
|
+
Also, each extension should export manifest const:
|
|
101
|
+
|
|
102
|
+
interface ExtensionManifest {
|
|
103
|
+
/* Should be unique in the extension repo */
|
|
104
|
+
name: string;
|
|
105
|
+
version: string;
|
|
106
|
+
category: 'theme' | 'extension' | 'language pack' | 'other';
|
|
107
|
+
/* OrgNote api semver, 0.13.4 for example */
|
|
108
|
+
apiVersion?: string;
|
|
109
|
+
author?: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
keywords?: string[];
|
|
112
|
+
// Repository url
|
|
113
|
+
sourceType: 'git' | 'file' | 'builtin';
|
|
114
|
+
/* Default value is README.org */
|
|
115
|
+
readmeFilePath?: string;
|
|
116
|
+
/* WIP */
|
|
117
|
+
permissions?: Array<'files' | 'personal info' | '*' | 'third party'>;
|
|
118
|
+
reloadRequired?: boolean;
|
|
119
|
+
sourceUrl?: string;
|
|
120
|
+
sponsor?: string[];
|
|
121
|
+
development?: boolean;
|
|
122
|
+
icon?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
<a id="orgbb09389"></a>
|
|
127
|
+
|
|
128
|
+
## Extension API
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
<a id="orgdd94657"></a>
|
|
132
|
+
|
|
133
|
+
# Publish to official repository
|
|
134
|
+
|
|
135
|
+
OrgNote has an official [repository](https://github.com/Artawower/orgnote-extensions) for user-based extensions. You can easily add new `recipes/<package>.json`
|
|
136
|
+
with `ExtensionManifest`
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
<a id="orgf459c20"></a>
|
|
140
|
+
|
|
141
|
+
# Extensions example
|
|
142
|
+
|
|
143
|
+
*Themes*
|
|
144
|
+
|
|
145
|
+
- [Atom One Dark theme (pure js)](https://github.com/Artawower/orgnote-atom-one-dark)
|
|
146
|
+
|
|
147
|
+
*UI*
|
|
148
|
+
|
|
149
|
+
- [Colorful Headlines (typescript + API package)](https://github.com/Artawower/orgnote-colorful-headlines)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
<a id="org383a272"></a>
|
|
153
|
+
|
|
154
|
+
# Contribute guide
|
|
155
|
+
|
|
156
|
+
Any contribution is very much appreciated! Please read the [style guide](./CONTRIBUTE.md) before contributing to avoid misunderstandings!
|
|
157
|
+
I would also appreciate it if you would consider becoming my [patron](https://www.patreon.com/artawower)
|
|
158
|
+
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Command, CSSVariable, ThemeVariable, Note, InlineEmbeddedWidget, MultilineEmbeddedWidget, OrgLineClass, WidgetBuilder, CommandPreview, OrgNoteEncryption, Modal } from './models';
|
|
2
|
+
import type { NavigationFailure } from 'vue-router';
|
|
3
|
+
import { WidgetType } from './models/widget-type';
|
|
4
|
+
import type { Component } from 'vue';
|
|
5
|
+
import { NodeType } from 'org-mode-ast';
|
|
6
|
+
import { EditorExtension } from './models/editor';
|
|
7
|
+
type WithNodeType<T> = {
|
|
8
|
+
nodeType: NodeType;
|
|
9
|
+
} & T;
|
|
10
|
+
export type WidgetMeta = ({
|
|
11
|
+
type: WidgetType.Inline;
|
|
12
|
+
} & WithNodeType<InlineEmbeddedWidget>) | ({
|
|
13
|
+
type: WidgetType.Multiline;
|
|
14
|
+
} & WithNodeType<MultilineEmbeddedWidget>) | ({
|
|
15
|
+
type: WidgetType.LineClass;
|
|
16
|
+
} & WithNodeType<OrgLineClass>);
|
|
17
|
+
export interface OrgNoteApi {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
getExtension?<T>(config: string): T;
|
|
20
|
+
system: {
|
|
21
|
+
reload: (params?: {
|
|
22
|
+
verbose: boolean;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
setNewFilesAvailable: (status?: boolean) => void;
|
|
25
|
+
};
|
|
26
|
+
navigation: {
|
|
27
|
+
openNote: (id: string) => Promise<void | NavigationFailure>;
|
|
28
|
+
editNote: (id: string) => Promise<void | NavigationFailure>;
|
|
29
|
+
};
|
|
30
|
+
ui: {
|
|
31
|
+
applyTheme: (theme: {
|
|
32
|
+
[key in ThemeVariable]: string | number;
|
|
33
|
+
}) => void;
|
|
34
|
+
applyCssVariables: (styles: {
|
|
35
|
+
[key in CSSVariable]: string | number;
|
|
36
|
+
}) => void;
|
|
37
|
+
setThemeByMode: (themeName?: string) => void;
|
|
38
|
+
setDarkTheme: (themeName?: string) => void;
|
|
39
|
+
setLightTheme: (themeName?: string) => void;
|
|
40
|
+
applyStyles: (scopeName: string, styles: string) => void;
|
|
41
|
+
removeStyles: (scopeName: string) => void;
|
|
42
|
+
resetTheme: () => void;
|
|
43
|
+
openModal: (modal: Modal) => void;
|
|
44
|
+
};
|
|
45
|
+
interaction: {
|
|
46
|
+
confirm: (title: string, message: string) => Promise<boolean>;
|
|
47
|
+
};
|
|
48
|
+
currentNote: {
|
|
49
|
+
get: () => Note;
|
|
50
|
+
};
|
|
51
|
+
editor: {
|
|
52
|
+
extensions: {
|
|
53
|
+
add: (...extension: EditorExtension[]) => void;
|
|
54
|
+
remove: (...extension: EditorExtension[]) => void;
|
|
55
|
+
};
|
|
56
|
+
widgets: {
|
|
57
|
+
add: (...widgetMeta: WidgetMeta[]) => void;
|
|
58
|
+
createWidgetBuilder: (cmp: Component, props?: {
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}) => WidgetBuilder;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
fileSystem: {
|
|
64
|
+
readPath: () => Promise<string>;
|
|
65
|
+
};
|
|
66
|
+
commands: {
|
|
67
|
+
add(...commands: Command[]): void;
|
|
68
|
+
remove(...commands: Command[]): void;
|
|
69
|
+
get(name: string): Command;
|
|
70
|
+
getAll(): Command[];
|
|
71
|
+
addCommandToSidebar(...commands: CommandPreview[]): void;
|
|
72
|
+
removeCommandFromSidebar(...commands: CommandPreview[]): void;
|
|
73
|
+
addCommandToEditorPanel(...commands: CommandPreview[]): void;
|
|
74
|
+
removeCommandFromEditorPanel(...commands: CommandPreview[]): void;
|
|
75
|
+
};
|
|
76
|
+
configuration: () => OrgNoteConfig;
|
|
77
|
+
}
|
|
78
|
+
export interface OrgNoteConfig {
|
|
79
|
+
editor: {
|
|
80
|
+
showSpecialSymbols: boolean;
|
|
81
|
+
showPropertyDrawer: boolean;
|
|
82
|
+
};
|
|
83
|
+
developer: {
|
|
84
|
+
developerMode: boolean;
|
|
85
|
+
maximumLogsCount: number;
|
|
86
|
+
};
|
|
87
|
+
completion: {
|
|
88
|
+
showGroup: boolean;
|
|
89
|
+
defaultCompletionLimit: number;
|
|
90
|
+
};
|
|
91
|
+
system: {
|
|
92
|
+
language: string;
|
|
93
|
+
};
|
|
94
|
+
synchronization: {
|
|
95
|
+
type: 'none' | 'api';
|
|
96
|
+
};
|
|
97
|
+
vault: {
|
|
98
|
+
type: 'inmemory' | 'filesystem';
|
|
99
|
+
path?: string;
|
|
100
|
+
};
|
|
101
|
+
ui: {
|
|
102
|
+
showUserProfiles: boolean;
|
|
103
|
+
theme: 'light' | 'dark' | 'auto';
|
|
104
|
+
darkThemeName?: string;
|
|
105
|
+
lightThemeName?: string;
|
|
106
|
+
};
|
|
107
|
+
extensions: {
|
|
108
|
+
sources: string[];
|
|
109
|
+
};
|
|
110
|
+
encryption: OrgNoteEncryption;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
package/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const armoredPublicKey = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBGYaZm0BEADfaOXr8cXcU3esPh7gBRq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OnlEq4iRym+sL0KmowhEVHG5aiPiaWSg2yc6xoAdQIDkATX2KqeHS0LJ5dST6\nCLkvHgKQEcUNflqPHQztxoCDOeywy5bGz88i8KWNsH9GctNL2wRY70e+aWfdCpek\nMaZkUct/HTTrBfde7QxI6F8AEQEAAYkCNgQYAQgAIBYhBAbW1zGyD3dzVFeGsZBF\nmM9W00woBQJmGmZtAhsMAAoJEJBFmM9W00woG9EQAJSz3C2RhO8jGajDjLX/ZewJ\nOuQ2tmEftRFYJLhLFfVWXAK+ZwQWzszy/AexpulL1C3NsKdjhgPoqEffsMW32vwE\nsTggej8EPHL0NLqPjK+1R7xsPm7Ezsy+mtYYstaCAY3MkYgBCzVKWIAvAJ8H1QZB\n+F9rYu2iHhyiLNOsbZJc5fmSiTfsXfkgAfN2prB2bKBm7ntPAK7vX1+m5jihbqLL\njr0DECo7rBfjyuPXrJb/PTdEc5cQ1I/RCkb0CNazHnwlG0c2vmsYY87ruilBw4zv\nMiN0CRWcqVQmuzyiNNmQt7ueM/UHJRTgid7friQtU2fL6UUrhD6H/Yb7KVVQSMgn\n0yvkUOxNYzQRFOZFRYtBopkDSiEsV62AVtaCQoteImJwgU5fESLq11oIbwi2kM2a\nVPCuOIKPBx7Ghomq6wmCvzxIgYojCJSvxt4FefOvGA4A8nJgRKc/lT8e8CV02V2d\nkOpMbrPz57R5RsQ5WNYVTtk6K6uPTkajrSVMopLJV0QQ77ksc4pujII9guprz2bK\nxZb7T0xLBBAqaTakZc1NGOwSV0hofu79DlKvLR2BB+2XhseO3iLWihpLRjJShamg\ni9M1qY7gk2elhW/+2IWifgTJfmlvNaqWCyqH/FrRyj8fw0/JUCKlNPwt9ITm9ffm\nPYl38WJh5gV98/obb+Mp\n=fslD\n-----END PGP PUBLIC KEY BLOCK-----";
|
|
2
|
+
export declare const armoredPrivateKey = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\nlQdGBGYaZm0BEADfaOXr8cXcU3esPh7gBRqgdUNl/qNFVUOkfoaxM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J\ngr88SIGKIwiUr8beBXnzrxgOAPJyYESnP5U/HvAldNldnZDqTG6z8+e0eUbEOVjW\nFU7ZOiurj05Go60lTKKSyVdEEO+5LHOKboyCPYLqa89mysWW+09MSwQQKmk2pGXN\nTRjsEldIaH7u/Q5Sry0dgQftl4bHjt4i1ooaS0YyUoWpoIvTNamO4JNnpYVv/tiF\non4EyX5pbzWqlgsqh/xa0co/H8NPyVAipTT8LfSE5vX35j2Jd/FiYeYFffP6G2/j\nKQ==\n=OrI7\n-----END PGP PRIVATE KEY BLOCK-----";
|
|
3
|
+
export declare const privateKeyPassphrase = "test";
|
|
@@ -50,7 +50,6 @@ i9M1qY7gk2elhW/+2IWifgTJfmlvNaqWCyqH/FrRyj8fw0/JUCKlNPwt9ITm9ffm
|
|
|
50
50
|
PYl38WJh5gV98/obb+Mp
|
|
51
51
|
=fslD
|
|
52
52
|
-----END PGP PUBLIC KEY BLOCK-----`;
|
|
53
|
-
|
|
54
53
|
export const armoredPrivateKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
|
55
54
|
|
|
56
55
|
lQdGBGYaZm0BEADfaOXr8cXcU3esPh7gBRqgdUNl/qNFVUOkfoaxMK0m2uDrI03w
|
|
@@ -159,5 +158,4 @@ on4EyX5pbzWqlgsqh/xa0co/H8NPyVAipTT8LfSE5vX35j2Jd/FiYeYFffP6G2/j
|
|
|
159
158
|
KQ==
|
|
160
159
|
=OrI7
|
|
161
160
|
-----END PGP PRIVATE KEY BLOCK-----`;
|
|
162
|
-
|
|
163
161
|
export const privateKeyPassphrase = 'test';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { encryptViaKeys, decryptViaKeys, encryptViaPassword, decryptViaPassword, NoKeysProvidedError, NoPasswordProvidedError, IncorrectOrMissingPrivateKeyPasswordError, encrypt, decrypt, armor, unarmor, } from '../encryption';
|
|
2
|
+
import { test, expect } from 'vitest';
|
|
3
|
+
import { armoredPublicKey, armoredPrivateKey, privateKeyPassphrase, } from './encryption-keys';
|
|
4
|
+
import { ModelsPublicNoteEncryptionTypeEnum } from 'src/remote-api';
|
|
5
|
+
test('Should encrypt text as armored message via keys', async () => {
|
|
6
|
+
const res = await encryptViaKeys({
|
|
7
|
+
type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
8
|
+
content: 'Hello world',
|
|
9
|
+
publicKey: armoredPublicKey,
|
|
10
|
+
privateKey: armoredPrivateKey,
|
|
11
|
+
privateKeyPassphrase: privateKeyPassphrase,
|
|
12
|
+
format: 'armored',
|
|
13
|
+
});
|
|
14
|
+
expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
test('Should encrypt text via keys', async () => {
|
|
17
|
+
const res = await encryptViaKeys({
|
|
18
|
+
type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
|
|
19
|
+
content: 'Hello world',
|
|
20
|
+
publicKey: armoredPublicKey,
|
|
21
|
+
privateKey: armoredPrivateKey,
|
|
22
|
+
privateKeyPassphrase,
|
|
23
|
+
format: 'armored',
|
|
24
|
+
});
|
|
25
|
+
expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
test('Should decrypt via provided keys', async () => {
|
|
28
|
+
const decryptedMessage = await decryptViaKeys({
|
|
29
|
+
content: `-----BEGIN PGP MESSAGE-----
|
|
30
|
+
|
|
31
|
+
wcFMA/vryg+TTn0rARAAhXuEjOHa856iCNVmdeIGHF+IEoeEwTc5tIcr6Lri
|
|
32
|
+
V6xs//3WnwVwUlyxYrum3yCpx8t5gyWTXFfTNH08VoVqPVP45fkk1H7jdC6Q
|
|
33
|
+
I+tHfn8nXZApdKQlMOku+XMXtRuqvOUQHutqHj4ka3qC+wGIPcOsy2TIoFsS
|
|
34
|
+
xauk13hMggmVHOdQkMzWA1QlxDcz6lFl86SvX18uc7H62s36gHxARmOLZfBd
|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lkU3CsCR+j
|
|
50
|
+
i9Km3edjOwPpJtgI0LeRRqXs3eUhLQARC5nFePbRWnFSXPBuFxBVZyL9AYrS
|
|
51
|
+
KQn4dM1p4eTtsiEu1NaTzRtQNZAFHcJpZ8qAL67LHoNdFe/atpCdlyV3yur9
|
|
52
|
+
RvAA3cB7cj7wab3beX+cTqxdhpGePZh0TrNd3liV69FtbnYfeDrtUYIL1jfT
|
|
53
|
+
EJN3l+qpveimyX655RrgFX3DNGrVbbhpx+FDF9Ky9kqb2BJBTFKoCBxbf0dS
|
|
54
|
+
sniNAsC/t/k6ErG8NKNQsNh1aeN6plXnxeVi1vv6SvO2mwZRVvDNT1hg9Cyc
|
|
55
|
+
UO1Pw43TRLO50HgR9+ERNXL491TJA0aCj14oXwsm0Dtg6EOltX0GUDwcPjv6
|
|
56
|
+
6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
|
|
57
|
+
YQ==
|
|
58
|
+
=f4F1
|
|
59
|
+
-----END PGP MESSAGE-----
|
|
60
|
+
`,
|
|
61
|
+
privateKey: armoredPrivateKey,
|
|
62
|
+
privateKeyPassphrase,
|
|
63
|
+
});
|
|
64
|
+
expect(decryptedMessage).toEqual('Hello world');
|
|
65
|
+
});
|
|
66
|
+
test('Should encrypt via password', async () => {
|
|
67
|
+
const password = 'test';
|
|
68
|
+
const res = await encryptViaPassword({
|
|
69
|
+
type: ModelsPublicNoteEncryptionTypeEnum.GpgPassword,
|
|
70
|
+
content: 'Hello world',
|
|
71
|
+
password,
|
|
72
|
+
format: 'armored',
|
|
73
|
+
});
|
|
74
|
+
expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
|
|
75
|
+
});
|
|
76
|
+
test('Should decrypt via password', async () => {
|
|
77
|
+
const password = 'test';
|
|
78
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
79
|
+
|
|
80
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
81
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
82
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
83
|
+
=B4Tc
|
|
84
|
+
-----END PGP MESSAGE-----
|
|
85
|
+
`;
|
|
86
|
+
expect(await decryptViaPassword({ content: encryptedMsg, password })).toEqual('Hello world');
|
|
87
|
+
});
|
|
88
|
+
test('Should raise incorrect or missing private key error', async () => {
|
|
89
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
90
|
+
|
|
91
|
+
wcFMA/vryg+TTn0rARAAhXuEjOHa856iCNVmdeIGHF+IEoeEwTc5tIcr6Lri
|
|
92
|
+
V6xs//3WnwVwUlyxYrum3yCpx8t5gyWTXFfTNH08VoVqPVP45fkk1H7jdC6Q
|
|
93
|
+
I+tHfn8nXZApdKQlMOku+XMXtRuqvOUQHutqHj4ka3qC+wGIPcOsy2TIoFsS
|
|
94
|
+
xauk13hMggmVHOdQkMzWA1QlxDcz6lFl86SvX18uc7H62s36gHxARmOLZfBd
|
|
95
|
+
nRFdnPgLKNOPGWb6QvYfvxiv03vGSsKlb0tIpwP1Ot0nyZax+yH9CJmIEni/
|
|
96
|
+
rW9Wu/Ph+PRcB2L9kp/X4Opol3RwJ0lI9ilTRw9+GGFipXhCmJcjPJC7WNIg
|
|
97
|
+
vg0/xVUjSmlxQQAZlC9/sefvoXjY0CP+h+djtoZsxLpN4P4iTO1reuoVD0iO
|
|
98
|
+
UwT9JCUR1uDEiNXvh6AmrLlH3ceBynJcBtHXAnx1vcgtY8oKKYBjsoTeEngg
|
|
99
|
+
P5w5ZXcceoPuYLe6g1YPsFECAgGF+e/QuZ9CCfUgr4o7nSteHQRShP2gXZzc
|
|
100
|
+
oHKR4tiV71VVGKzv0EYhCvVt9NGkxIklft9Lq4ZOXeT9QOnJ/7gRofX2veg2
|
|
101
|
+
T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
+
6QMreKTATPLytbhCdPO+JOzObsptU/IlsQQWlMz8yKXwqyuN8z8SOaddJIHR
|
|
117
|
+
YQ==
|
|
118
|
+
=f4F1
|
|
119
|
+
-----END PGP MESSAGE-----`;
|
|
120
|
+
try {
|
|
121
|
+
await decryptViaPassword({ content: encryptedMsg, password: 'password' });
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
expect(e).toBeInstanceOf(NoKeysProvidedError);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
test('Should raise IncorrectOrMissingPrivateKeyPasswordError error when incorrect armored key provided', async () => {
|
|
128
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
129
|
+
|
|
130
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
131
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
132
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
133
|
+
=B4Tc
|
|
134
|
+
-----END PGP MESSAGE-----
|
|
135
|
+
`;
|
|
136
|
+
try {
|
|
137
|
+
await decryptViaKeys({
|
|
138
|
+
content: encryptedMsg,
|
|
139
|
+
publicKey: armoredPublicKey,
|
|
140
|
+
privateKey: privateKeyPassphrase,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
expect(e).toBeInstanceOf(IncorrectOrMissingPrivateKeyPasswordError);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
test('Should raise NoPasswordProvidedError error when try to use keys instead of password', async () => {
|
|
148
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
149
|
+
|
|
150
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
151
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
152
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
153
|
+
=B4Tc
|
|
154
|
+
-----END PGP MESSAGE-----
|
|
155
|
+
`;
|
|
156
|
+
try {
|
|
157
|
+
await decryptViaKeys({
|
|
158
|
+
content: encryptedMsg,
|
|
159
|
+
privateKey: armoredPrivateKey,
|
|
160
|
+
privateKeyPassphrase,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
expect(e).toBeInstanceOf(NoPasswordProvidedError);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
test('Should encrypt and decrypt text by provided configs via password', async () => {
|
|
168
|
+
const text = 'Hello world';
|
|
169
|
+
const password = '123';
|
|
170
|
+
const res = await encrypt({
|
|
171
|
+
content: text,
|
|
172
|
+
type: 'gpgPassword',
|
|
173
|
+
password,
|
|
174
|
+
format: 'armored',
|
|
175
|
+
});
|
|
176
|
+
expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
|
|
177
|
+
const decryptedMessage = await decrypt({
|
|
178
|
+
content: res,
|
|
179
|
+
type: 'gpgPassword',
|
|
180
|
+
password,
|
|
181
|
+
});
|
|
182
|
+
expect(decryptedMessage).toEqual(text);
|
|
183
|
+
});
|
|
184
|
+
test('Should encrypt and decrypt text by provided configs via keys', async () => {
|
|
185
|
+
const text = 'Hello world';
|
|
186
|
+
const res = await encrypt({
|
|
187
|
+
content: text,
|
|
188
|
+
type: 'gpgKeys',
|
|
189
|
+
format: 'armored',
|
|
190
|
+
publicKey: armoredPublicKey,
|
|
191
|
+
privateKey: armoredPrivateKey,
|
|
192
|
+
privateKeyPassphrase,
|
|
193
|
+
});
|
|
194
|
+
expect(res.startsWith('-----BEGIN PGP MESSAGE-----')).toBeTruthy();
|
|
195
|
+
const decryptedMessage = await decrypt({
|
|
196
|
+
content: res,
|
|
197
|
+
type: 'gpgKeys',
|
|
198
|
+
publicKey: armoredPublicKey,
|
|
199
|
+
privateKey: armoredPrivateKey,
|
|
200
|
+
privateKeyPassphrase,
|
|
201
|
+
format: 'utf8',
|
|
202
|
+
});
|
|
203
|
+
expect(decryptedMessage).toEqual(text);
|
|
204
|
+
});
|
|
205
|
+
test('Should encrypt to binary and decrypt to format armored!', async () => {
|
|
206
|
+
const text = 'Hello world';
|
|
207
|
+
const res = await encrypt({
|
|
208
|
+
content: text,
|
|
209
|
+
type: 'gpgPassword',
|
|
210
|
+
password: '123',
|
|
211
|
+
format: 'binary',
|
|
212
|
+
});
|
|
213
|
+
expect(res).toBeInstanceOf(Uint8Array);
|
|
214
|
+
const decryptedMessage = await decrypt({
|
|
215
|
+
content: res,
|
|
216
|
+
type: 'gpgPassword',
|
|
217
|
+
format: 'utf8',
|
|
218
|
+
password: '123',
|
|
219
|
+
});
|
|
220
|
+
expect(decryptedMessage).toEqual(text);
|
|
221
|
+
});
|
|
222
|
+
test('Should encrypt to binary and decrypt to binary format', async () => {
|
|
223
|
+
const text = 'Hello world';
|
|
224
|
+
const res = await encrypt({
|
|
225
|
+
content: text,
|
|
226
|
+
type: 'gpgPassword',
|
|
227
|
+
password: '123',
|
|
228
|
+
format: 'binary',
|
|
229
|
+
});
|
|
230
|
+
expect(res).toBeInstanceOf(Uint8Array);
|
|
231
|
+
const decryptedMessage = await decrypt({
|
|
232
|
+
content: res,
|
|
233
|
+
type: 'gpgPassword',
|
|
234
|
+
format: 'binary',
|
|
235
|
+
password: '123',
|
|
236
|
+
});
|
|
237
|
+
expect(decryptedMessage.toString()).toMatchInlineSnapshot(`"72,101,108,108,111,32,119,111,114,108,100"`);
|
|
238
|
+
});
|
|
239
|
+
test('Should encrypt to armored text and decrypt as binary format', async () => {
|
|
240
|
+
const text = 'Hello world';
|
|
241
|
+
const res = await encrypt({
|
|
242
|
+
content: text,
|
|
243
|
+
type: 'gpgPassword',
|
|
244
|
+
password: '123',
|
|
245
|
+
format: 'armored',
|
|
246
|
+
});
|
|
247
|
+
expect(res).toBeTypeOf('string');
|
|
248
|
+
const decryptedMessage = await decrypt({
|
|
249
|
+
content: res,
|
|
250
|
+
type: 'gpgPassword',
|
|
251
|
+
format: 'binary',
|
|
252
|
+
password: '123',
|
|
253
|
+
});
|
|
254
|
+
expect(decryptedMessage).toBeInstanceOf(Uint8Array);
|
|
255
|
+
});
|
|
256
|
+
test('Should armor and unarmor encrypted file', async () => {
|
|
257
|
+
const content = new Uint8Array([
|
|
258
|
+
72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
|
|
259
|
+
]);
|
|
260
|
+
const armored = armor(content);
|
|
261
|
+
expect(armored).toMatchInlineSnapshot(`
|
|
262
|
+
"-----BEGIN PGP MESSAGE-----
|
|
263
|
+
|
|
264
|
+
SGVsbG8gd29ybGQ=
|
|
265
|
+
=7asC
|
|
266
|
+
-----END PGP MESSAGE-----
|
|
267
|
+
"
|
|
268
|
+
`);
|
|
269
|
+
const { data } = await unarmor(armored);
|
|
270
|
+
expect(data).toEqual(content);
|
|
271
|
+
});
|
|
272
|
+
test('Should decrypt value from provided real world data and passwords', async () => {
|
|
273
|
+
const text = `Hello world!`;
|
|
274
|
+
const password = 'qweqwebebe1';
|
|
275
|
+
const encryptedContent = await encrypt({
|
|
276
|
+
content: text,
|
|
277
|
+
type: 'gpgPassword',
|
|
278
|
+
password,
|
|
279
|
+
});
|
|
280
|
+
const armoredContent = armor(encryptedContent);
|
|
281
|
+
const decryptedMessage = await decrypt({
|
|
282
|
+
content: armoredContent,
|
|
283
|
+
type: 'gpgPassword',
|
|
284
|
+
password,
|
|
285
|
+
});
|
|
286
|
+
expect(decryptedMessage).toEqual('Hello world!');
|
|
287
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|