@hugoalh/github-sodium 5.0.3 → 6.0.0
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/LICENSE.md +1 -1
- package/README.md +75 -148
- package/_dnt.polyfills.d.ts +101 -0
- package/_dnt.polyfills.d.ts.map +1 -0
- package/_dnt.polyfills.js +127 -0
- package/_dnt.shims.d.ts +12 -0
- package/_dnt.shims.d.ts.map +1 -0
- package/_dnt.shims.js +70 -0
- package/_polyfill.d.ts +1 -0
- package/_polyfill.d.ts.map +1 -0
- package/_polyfill.js +9 -0
- package/libsodium/cli.d.ts +3 -0
- package/libsodium/cli.d.ts.map +1 -0
- package/libsodium/cli.js +9 -0
- package/libsodium.d.ts +22 -0
- package/libsodium.d.ts.map +1 -0
- package/libsodium.js +35 -0
- package/package.json +60 -30
- package/tweetsodium/cli.d.ts +3 -0
- package/tweetsodium/cli.d.ts.map +1 -0
- package/tweetsodium/cli.js +9 -0
- package/tweetsodium.d.ts +22 -0
- package/tweetsodium.d.ts.map +1 -0
- package/tweetsodium.js +43 -0
- package/dist/mod.d.ts +0 -33
- package/dist/mod.d.ts.map +0 -1
- package/dist/mod.js +0 -49
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2020\~
|
|
3
|
+
Copyright © 2020\~2026 HUGOALH
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -2,162 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
[**⚖️** MIT](./LICENSE.md)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
>
|
|
56
|
-
>
|
|
57
|
-
> -
|
|
58
|
-
> -
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
> - Deno
|
|
65
|
-
|
|
66
|
-
1. Import at the script:
|
|
67
|
-
```ts
|
|
68
|
-
import ... from "jsr:@hugoalh/github-sodium[@${Tag}]";
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
> **ℹ️ Note**
|
|
72
|
-
>
|
|
73
|
-
> - Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub paths.
|
|
74
|
-
> - It is recommended to import the module with tag for immutability.
|
|
75
|
-
|
|
76
|
-
### Via NPM With `node_modules`
|
|
77
|
-
|
|
78
|
-
> **🎯 Supported Target**
|
|
79
|
-
>
|
|
80
|
-
> - Cloudflare Workers
|
|
81
|
-
> - NodeJS
|
|
82
|
-
|
|
83
|
-
1. Install via:
|
|
84
|
-
- NPM
|
|
85
|
-
```sh
|
|
86
|
-
npm install @hugoalh/github-sodium[@${Tag}]
|
|
87
|
-
```
|
|
88
|
-
- PNPM
|
|
89
|
-
```sh
|
|
90
|
-
pnpm add @hugoalh/github-sodium[@${Tag}]
|
|
91
|
-
```
|
|
92
|
-
- Yarn
|
|
93
|
-
```sh
|
|
94
|
-
yarn add @hugoalh/github-sodium[@${Tag}]
|
|
95
|
-
```
|
|
96
|
-
2. Import at the script:
|
|
97
|
-
```ts
|
|
98
|
-
import ... from "@hugoalh/github-sodium";
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> **ℹ️ Note**
|
|
102
|
-
>
|
|
103
|
-
> - Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub paths.
|
|
104
|
-
> - It is recommended to import the module with tag for immutability.
|
|
105
|
-
|
|
106
|
-
### Via NPM With Specifier
|
|
107
|
-
|
|
108
|
-
> **🎯 Supported Target**
|
|
109
|
-
>
|
|
110
|
-
> - Bun
|
|
111
|
-
> - Deno
|
|
112
|
-
|
|
113
|
-
1. Import at the script:
|
|
114
|
-
```ts
|
|
115
|
-
import ... from "npm:@hugoalh/github-sodium[@${Tag}]";
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
> **ℹ️ Note**
|
|
119
|
-
>
|
|
120
|
-
> - Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub paths.
|
|
121
|
-
> - It is recommended to import the module with tag for immutability.
|
|
122
|
-
|
|
123
|
-
### Via Remote Import
|
|
124
|
-
|
|
125
|
-
> **🎯 Supported Target**
|
|
126
|
-
>
|
|
127
|
-
> - Deno
|
|
128
|
-
|
|
129
|
-
1. Import at the script:
|
|
130
|
-
```ts
|
|
131
|
-
/* Via GitHub Raw (Require Tag) */
|
|
132
|
-
import ... from "https://raw.githubusercontent.com/hugoalh-studio/github-sodium-es/${Tag}/mod.ts";
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
> **ℹ️ Note**
|
|
136
|
-
>
|
|
137
|
-
> - Although it is recommended to import the entire module with the main path `mod.ts`, it is also able to import part of the module with sub path if available, but do not import if:
|
|
138
|
-
>
|
|
139
|
-
> - it's file path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
|
|
140
|
-
> - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
|
|
141
|
-
> - it's symbol has an underscore prefix (e.g.: `export function _baz() {}`).
|
|
142
|
-
>
|
|
143
|
-
> These elements are not considered part of the public API, thus no stability is guaranteed for them.
|
|
144
|
-
> - Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.
|
|
145
|
-
|
|
146
|
-
## 🧩 API
|
|
5
|
+
🔗
|
|
6
|
+
[DistBoard @hugoalh](https://hugoalh.github.io/distboard/github_sodium_ecmascript)
|
|
7
|
+
● [GitHub](https://github.com/hugoalh/github-sodium-es)
|
|
8
|
+
● [JSR](https://jsr.io/@hugoalh/github-sodium)
|
|
9
|
+
● [NPM](https://www.npmjs.com/package/@hugoalh/github-sodium)
|
|
10
|
+
|
|
11
|
+
An ECMAScript module to provide an easier and simplified method for encrypt GitHub secrets.
|
|
12
|
+
|
|
13
|
+
## 🌟 Features
|
|
14
|
+
|
|
15
|
+
- Support multiple implementations:
|
|
16
|
+
- **LibSodium:** Default; Recommended by GitHub; Bad compatibility with bundler or compiler.
|
|
17
|
+
- **TweetSodium:** Originally created by GitHub but deprecated and unmaintained ([Repository](https://github.com/github/tweetsodium)), currently maintain here; Good compatibility with bundler or compiler.
|
|
18
|
+
|
|
19
|
+
## 🎯 Runtime Targets
|
|
20
|
+
|
|
21
|
+
Any runtime which support ECMAScript should able to use this; These runtimes are officially supported:
|
|
22
|
+
|
|
23
|
+
- **[Bun](https://bun.sh/)** >= v1.1.0
|
|
24
|
+
- **[Deno](https://deno.land/)** >= v2.1.0
|
|
25
|
+
- **[NodeJS](https://nodejs.org/)** >= v20.9.0
|
|
26
|
+
|
|
27
|
+
## 🛡️ Runtime Permissions
|
|
28
|
+
|
|
29
|
+
This does not request any runtime permission.
|
|
30
|
+
|
|
31
|
+
## #️⃣ Sources & Entrypoints
|
|
32
|
+
|
|
33
|
+
- GitHub Raw
|
|
34
|
+
```
|
|
35
|
+
https://raw.githubusercontent.com/hugoalh/github-sodium-es/{Tag}/mod.ts
|
|
36
|
+
```
|
|
37
|
+
- JSR
|
|
38
|
+
```
|
|
39
|
+
jsr:@hugoalh/github-sodium[@{Tag}]
|
|
40
|
+
```
|
|
41
|
+
- NPM
|
|
42
|
+
```
|
|
43
|
+
npm:@hugoalh/github-sodium[@{Tag}]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| **Name** | **Path** | **Description** |
|
|
47
|
+
|:--|:--|:--|
|
|
48
|
+
| `.` | `./mod.ts` | Default (LibSodium). |
|
|
49
|
+
| `./cli` | N/A | CLI for default (LibSodium). |
|
|
50
|
+
| `./libsodium` | `./libsodium.ts` | LibSodium. |
|
|
51
|
+
| `./libsodium/cli` | `./libsodium/cli.ts` | CLI for LibSodium. |
|
|
52
|
+
| `./tweetsodium` | `./tweetsodium.ts` | TweetSodium. |
|
|
53
|
+
| `./tweetsodium/cli` | `./tweetsodium/cli.ts` | CLI for TweetSodium. |
|
|
54
|
+
|
|
55
|
+
> [!NOTE]
|
|
56
|
+
> - Different runtimes have vary support for the sources and entrypoints, visit the runtime documentation for more information.
|
|
57
|
+
> - It is recommended to include tag for immutability.
|
|
58
|
+
> - These are not part of the public APIs hence should not be used:
|
|
59
|
+
> - Benchmark/Test file (e.g.: `example.bench.ts`, `example.test.ts`).
|
|
60
|
+
> - Entrypoint name or path include any underscore prefix (e.g.: `_example.ts`, `foo/_example.ts`).
|
|
61
|
+
> - Identifier/Namespace/Symbol include any underscore prefix (e.g.: `_example`, `Foo._example`).
|
|
62
|
+
|
|
63
|
+
## 🧩 APIs
|
|
147
64
|
|
|
148
65
|
- ```ts
|
|
149
66
|
class GitHubSodiumSealer {
|
|
150
|
-
constructor(publicKey: string)
|
|
67
|
+
constructor(publicKey: string);
|
|
151
68
|
encrypt(value: string): string;
|
|
152
|
-
static seal(publicKey: string, value: string): string;
|
|
153
69
|
}
|
|
154
70
|
```
|
|
155
|
-
- ```ts
|
|
156
|
-
function seal(publicKey: string, value: string): string;
|
|
157
|
-
```
|
|
158
71
|
|
|
159
|
-
|
|
72
|
+
> [!NOTE]
|
|
73
|
+
> - For the full or prettier documentation, can visit via:
|
|
74
|
+
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/doc/)
|
|
75
|
+
> - [JSR](https://jsr.io/@hugoalh/github-sodium)
|
|
76
|
+
|
|
77
|
+
## 🧩 CLIs
|
|
78
|
+
|
|
79
|
+
```powershell
|
|
80
|
+
ghs {PublicKey} {SecretValue}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## ✍️ Examples
|
|
160
84
|
|
|
161
85
|
- ```ts
|
|
162
86
|
new GitHubSodiumSealer("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234").encrypt("plain-text-secret");
|
|
163
87
|
```
|
|
88
|
+
- ```powershell
|
|
89
|
+
ghs '2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234' 'plain-text-secret'
|
|
90
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { type URL } from "node:url";
|
|
15
|
+
declare global {
|
|
16
|
+
interface ImportMeta {
|
|
17
|
+
/** A string representation of the fully qualified module URL. When the
|
|
18
|
+
* module is loaded locally, the value will be a file URL (e.g.
|
|
19
|
+
* `file:///path/module.ts`).
|
|
20
|
+
*
|
|
21
|
+
* You can also parse the string as a URL to determine more information about
|
|
22
|
+
* how the current module was loaded. For example to determine if a module was
|
|
23
|
+
* local or not:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const url = new URL(import.meta.url);
|
|
27
|
+
* if (url.protocol === "file:") {
|
|
28
|
+
* console.log("this module was loaded locally");
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
url: string;
|
|
33
|
+
/**
|
|
34
|
+
* A function that returns resolved specifier as if it would be imported
|
|
35
|
+
* using `import(specifier)`.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* console.log(import.meta.resolve("./foo.js"));
|
|
39
|
+
* // file:///dev/foo.js
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param specifier The module specifier to resolve relative to `parent`.
|
|
43
|
+
* @param parent The absolute parent module URL to resolve from.
|
|
44
|
+
* @returns The absolute (`file:`) URL string for the resolved module.
|
|
45
|
+
*/
|
|
46
|
+
resolve(specifier: string, parent?: string | URL | undefined): string;
|
|
47
|
+
/** A flag that indicates if the current module is the main module that was
|
|
48
|
+
* called when starting the program under Deno.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* if (import.meta.main) {
|
|
52
|
+
* // this was loaded as the main module, maybe do some bootstrapping
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
main: boolean;
|
|
57
|
+
/** The absolute path of the current module.
|
|
58
|
+
*
|
|
59
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```
|
|
63
|
+
* // Unix
|
|
64
|
+
* console.log(import.meta.filename); // /home/alice/my_module.ts
|
|
65
|
+
*
|
|
66
|
+
* // Windows
|
|
67
|
+
* console.log(import.meta.filename); // C:\alice\my_module.ts
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
filename: string;
|
|
71
|
+
/** The absolute path of the directory containing the current module.
|
|
72
|
+
*
|
|
73
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
74
|
+
*
|
|
75
|
+
* * Example:
|
|
76
|
+
* ```
|
|
77
|
+
* // Unix
|
|
78
|
+
* console.log(import.meta.dirname); // /home/alice
|
|
79
|
+
*
|
|
80
|
+
* // Windows
|
|
81
|
+
* console.log(import.meta.dirname); // C:\alice
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
dirname: string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
type NodeRequest = ReturnType<typeof createRequire>;
|
|
88
|
+
type NodeModule = NonNullable<NodeRequest["main"]>;
|
|
89
|
+
interface ImportMetaPonyfillCommonjs {
|
|
90
|
+
(require: NodeRequest, module: NodeModule): ImportMeta;
|
|
91
|
+
}
|
|
92
|
+
interface ImportMetaPonyfillEsmodule {
|
|
93
|
+
(importMeta: ImportMeta): ImportMeta;
|
|
94
|
+
}
|
|
95
|
+
interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
|
|
96
|
+
}
|
|
97
|
+
export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
|
|
98
|
+
export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
|
|
99
|
+
export declare let import_meta_ponyfill: ImportMetaPonyfill;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
import { dirname } from "node:path";
|
|
19
|
+
const defineGlobalPonyfill = (symbolFor, fn) => {
|
|
20
|
+
if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
|
|
21
|
+
Object.defineProperty(globalThis, Symbol.for(symbolFor), {
|
|
22
|
+
configurable: true,
|
|
23
|
+
get() {
|
|
24
|
+
return fn;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
|
|
30
|
+
(() => {
|
|
31
|
+
const moduleImportMetaWM = new WeakMap();
|
|
32
|
+
return (require, module) => {
|
|
33
|
+
let importMetaCache = moduleImportMetaWM.get(module);
|
|
34
|
+
if (importMetaCache == null) {
|
|
35
|
+
const importMeta = Object.assign(Object.create(null), {
|
|
36
|
+
url: pathToFileURL(module.filename).href,
|
|
37
|
+
main: require.main == module,
|
|
38
|
+
resolve: (specifier, parentURL = importMeta.url) => {
|
|
39
|
+
return pathToFileURL((importMeta.url === parentURL
|
|
40
|
+
? require
|
|
41
|
+
: createRequire(parentURL))
|
|
42
|
+
.resolve(specifier)).href;
|
|
43
|
+
},
|
|
44
|
+
filename: module.filename,
|
|
45
|
+
dirname: module.path,
|
|
46
|
+
});
|
|
47
|
+
moduleImportMetaWM.set(module, importMeta);
|
|
48
|
+
importMetaCache = importMeta;
|
|
49
|
+
}
|
|
50
|
+
return importMetaCache;
|
|
51
|
+
};
|
|
52
|
+
})());
|
|
53
|
+
defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
|
|
54
|
+
export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
|
|
55
|
+
((importMeta) => {
|
|
56
|
+
const resolveFunStr = String(importMeta.resolve);
|
|
57
|
+
const shimWs = new WeakSet();
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
|
|
60
|
+
.replace(/\/{3,}/, "///");
|
|
61
|
+
const commonShim = (importMeta) => {
|
|
62
|
+
if (typeof importMeta.main !== "boolean") {
|
|
63
|
+
importMeta.main = importMeta.url === mainUrl;
|
|
64
|
+
}
|
|
65
|
+
if (typeof importMeta.filename !== "string") {
|
|
66
|
+
importMeta.filename = fileURLToPath(importMeta.url);
|
|
67
|
+
importMeta.dirname = dirname(importMeta.filename);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (
|
|
71
|
+
// v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
|
|
72
|
+
resolveFunStr === "undefined" ||
|
|
73
|
+
// v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
|
|
74
|
+
resolveFunStr.startsWith("async")
|
|
75
|
+
// enable by --experimental-import-meta-resolve flag
|
|
76
|
+
) {
|
|
77
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
78
|
+
if (!shimWs.has(importMeta)) {
|
|
79
|
+
shimWs.add(importMeta);
|
|
80
|
+
const importMetaUrlRequire = {
|
|
81
|
+
url: importMeta.url,
|
|
82
|
+
require: createRequire(importMeta.url),
|
|
83
|
+
};
|
|
84
|
+
importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
|
|
85
|
+
return pathToFileURL((importMetaUrlRequire.url === parentURL
|
|
86
|
+
? importMetaUrlRequire.require
|
|
87
|
+
: createRequire(parentURL)).resolve(specifier)).href;
|
|
88
|
+
};
|
|
89
|
+
commonShim(importMeta);
|
|
90
|
+
}
|
|
91
|
+
return importMeta;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
/// native support
|
|
96
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
97
|
+
if (!shimWs.has(importMeta)) {
|
|
98
|
+
shimWs.add(importMeta);
|
|
99
|
+
commonShim(importMeta);
|
|
100
|
+
}
|
|
101
|
+
return importMeta;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return import_meta_ponyfill_esmodule(importMeta);
|
|
105
|
+
}));
|
|
106
|
+
defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
|
|
107
|
+
export let import_meta_ponyfill = ((...args) => {
|
|
108
|
+
const _MODULE = (() => {
|
|
109
|
+
if (typeof require === "function" && typeof module === "object") {
|
|
110
|
+
return "commonjs";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// eval("typeof import.meta");
|
|
114
|
+
return "esmodule";
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
if (_MODULE === "commonjs") {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
|
|
124
|
+
}
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
return import_meta_ponyfill(...args);
|
|
127
|
+
});
|
package/_dnt.shims.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
3
|
+
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
4
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "Deno" | "alert" | "confirm" | "prompt" | "setInterval" | "setTimeout"> & {
|
|
5
|
+
Deno: any;
|
|
6
|
+
alert: any;
|
|
7
|
+
confirm: any;
|
|
8
|
+
prompt: any;
|
|
9
|
+
setInterval: any;
|
|
10
|
+
setTimeout: any;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=_dnt.shims.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["src/_dnt.shims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU5D,eAAO,MAAM,aAAa;;;;;;;CAA2C,CAAC"}
|
package/_dnt.shims.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
import { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
4
|
+
export { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
5
|
+
import { setInterval, setTimeout } from "@deno/shim-timers";
|
|
6
|
+
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
7
|
+
const dntGlobals = {
|
|
8
|
+
Deno,
|
|
9
|
+
alert,
|
|
10
|
+
confirm,
|
|
11
|
+
prompt,
|
|
12
|
+
setInterval,
|
|
13
|
+
setTimeout,
|
|
14
|
+
};
|
|
15
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
16
|
+
function createMergeProxy(baseObj, extObj) {
|
|
17
|
+
return new Proxy(baseObj, {
|
|
18
|
+
get(_target, prop, _receiver) {
|
|
19
|
+
if (prop in extObj) {
|
|
20
|
+
return extObj[prop];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return baseObj[prop];
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
set(_target, prop, value) {
|
|
27
|
+
if (prop in extObj) {
|
|
28
|
+
delete extObj[prop];
|
|
29
|
+
}
|
|
30
|
+
baseObj[prop] = value;
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
deleteProperty(_target, prop) {
|
|
34
|
+
let success = false;
|
|
35
|
+
if (prop in extObj) {
|
|
36
|
+
delete extObj[prop];
|
|
37
|
+
success = true;
|
|
38
|
+
}
|
|
39
|
+
if (prop in baseObj) {
|
|
40
|
+
delete baseObj[prop];
|
|
41
|
+
success = true;
|
|
42
|
+
}
|
|
43
|
+
return success;
|
|
44
|
+
},
|
|
45
|
+
ownKeys(_target) {
|
|
46
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
47
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
48
|
+
const extKeysSet = new Set(extKeys);
|
|
49
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
50
|
+
},
|
|
51
|
+
defineProperty(_target, prop, desc) {
|
|
52
|
+
if (prop in extObj) {
|
|
53
|
+
delete extObj[prop];
|
|
54
|
+
}
|
|
55
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
56
|
+
return true;
|
|
57
|
+
},
|
|
58
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
59
|
+
if (prop in extObj) {
|
|
60
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
has(_target, prop) {
|
|
67
|
+
return prop in extObj || prop in baseObj;
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
package/_polyfill.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=_polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_polyfill.d.ts","sourceRoot":"","sources":["src/_polyfill.ts"],"names":[],"mappings":""}
|
package/_polyfill.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
if (typeof Uint8Array.fromBase64 === "undefined") {
|
|
3
|
+
//deno-lint-ignore hugoalh/no-import-dynamic -- Polyfill.
|
|
4
|
+
await import("es-arraybuffer-base64/Uint8Array.fromBase64/auto");
|
|
5
|
+
}
|
|
6
|
+
if (typeof Uint8Array.prototype.toBase64 === "undefined") {
|
|
7
|
+
//deno-lint-ignore hugoalh/no-import-dynamic -- Polyfill.
|
|
8
|
+
await import("es-arraybuffer-base64/Uint8Array.prototype.toBase64/auto");
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/libsodium/cli.ts"],"names":[],"mappings":";AACA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC"}
|
package/libsodium/cli.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../_dnt.polyfills.js";
|
|
3
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
4
|
+
import { GitHubSodiumSealer } from "../libsodium.js";
|
|
5
|
+
if (!globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
|
|
6
|
+
throw new Error(`This entrypoint is for command line only!`);
|
|
7
|
+
}
|
|
8
|
+
const [publicKey = "", secretValue = ""] = dntShim.Deno.args;
|
|
9
|
+
console.log(new GitHubSodiumSealer(publicKey).encrypt(secretValue));
|
package/libsodium.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
2
|
+
import "./_polyfill.js";
|
|
3
|
+
/**
|
|
4
|
+
* GitHub sodium sealer for encrypt value to the GitHub secret value.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GitHubSodiumSealer {
|
|
7
|
+
#private;
|
|
8
|
+
get [Symbol.toStringTag](): string;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize.
|
|
11
|
+
* @param {string} publicKey Public key (recipient's public key), which get from the GitHub organization or repository, need for encrypt value to the GitHub secret value before create or update the GitHub secret.
|
|
12
|
+
*/
|
|
13
|
+
constructor(publicKey: string);
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt value to the GitHub secret value.
|
|
16
|
+
* @param {string} value Value that need to encrypt as the GitHub secret value.
|
|
17
|
+
* @returns {string} An encrypted GitHub secret value.
|
|
18
|
+
*/
|
|
19
|
+
encrypt(value: string): string;
|
|
20
|
+
}
|
|
21
|
+
export default GitHubSodiumSealer;
|
|
22
|
+
//# sourceMappingURL=libsodium.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsodium.d.ts","sourceRoot":"","sources":["src/libsodium.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAE7B,OAAO,gBAAgB,CAAC;AAExB;;GAEG;AACH,qBAAa,kBAAkB;;IAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED;;;OAGG;gBACS,SAAS,EAAE,MAAM;IAM7B;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAM9B;AACD,eAAe,kBAAkB,CAAC"}
|
package/libsodium.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
2
|
+
import libsodium from "libsodium-wrappers";
|
|
3
|
+
import "./_polyfill.js";
|
|
4
|
+
await libsodium.ready;
|
|
5
|
+
/**
|
|
6
|
+
* GitHub sodium sealer for encrypt value to the GitHub secret value.
|
|
7
|
+
*/
|
|
8
|
+
export class GitHubSodiumSealer {
|
|
9
|
+
get [Symbol.toStringTag]() {
|
|
10
|
+
return "GitHubSodiumSealer/LibSodium";
|
|
11
|
+
}
|
|
12
|
+
#publicKey;
|
|
13
|
+
/**
|
|
14
|
+
* Initialize.
|
|
15
|
+
* @param {string} publicKey Public key (recipient's public key), which get from the GitHub organization or repository, need for encrypt value to the GitHub secret value before create or update the GitHub secret.
|
|
16
|
+
*/
|
|
17
|
+
constructor(publicKey) {
|
|
18
|
+
if (!(publicKey.length > 0)) {
|
|
19
|
+
throw new SyntaxError(`Parameter \`publicKey\` is not a string which is non empty!`);
|
|
20
|
+
}
|
|
21
|
+
this.#publicKey = Uint8Array.fromBase64(publicKey);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt value to the GitHub secret value.
|
|
25
|
+
* @param {string} value Value that need to encrypt as the GitHub secret value.
|
|
26
|
+
* @returns {string} An encrypted GitHub secret value.
|
|
27
|
+
*/
|
|
28
|
+
encrypt(value) {
|
|
29
|
+
if (!(value.length > 0)) {
|
|
30
|
+
throw new SyntaxError(`Parameter \`value\` is not a string which is non empty!`);
|
|
31
|
+
}
|
|
32
|
+
return libsodium.crypto_box_seal(new TextEncoder().encode(value), this.#publicKey).toBase64();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export default GitHubSodiumSealer;
|
package/package.json
CHANGED
|
@@ -1,53 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hugoalh/github-sodium",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A module to provide an easier
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "A module to provide an easier and simplified method for encrypt GitHub secrets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
7
7
|
"sodium"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://github.com/hugoalh
|
|
9
|
+
"homepage": "https://github.com/hugoalh/github-sodium-es#readme",
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/hugoalh
|
|
11
|
+
"url": "https://github.com/hugoalh/github-sodium-es/issues"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "hugoalh",
|
|
15
|
-
"files": [
|
|
16
|
-
"asset/**",
|
|
17
|
-
"bin/**",
|
|
18
|
-
"dist/**",
|
|
19
|
-
"lib/**",
|
|
20
|
-
"LICENSE*.md",
|
|
21
|
-
"package.json",
|
|
22
|
-
"README*.md"
|
|
23
|
-
],
|
|
24
15
|
"type": "module",
|
|
25
|
-
"
|
|
16
|
+
"bin": {
|
|
17
|
+
"ghs": "./libsodium/cli.js",
|
|
18
|
+
"ghs-ls": "./libsodium/cli.js",
|
|
19
|
+
"ghs-ts": "./tweetsodium/cli.js"
|
|
20
|
+
},
|
|
21
|
+
"main": "./libsodium.js",
|
|
22
|
+
"module": "./libsodium.js",
|
|
26
23
|
"exports": {
|
|
27
|
-
"
|
|
28
|
-
|
|
24
|
+
"./cli": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./libsodium/cli.d.ts",
|
|
27
|
+
"default": "./libsodium/cli.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./libsodium": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./libsodium.d.ts",
|
|
33
|
+
"default": "./libsodium.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./libsodium/cli": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./libsodium/cli.d.ts",
|
|
39
|
+
"default": "./libsodium/cli.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./tweetsodium": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./tweetsodium.d.ts",
|
|
45
|
+
"default": "./tweetsodium.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./tweetsodium/cli": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./tweetsodium/cli.d.ts",
|
|
51
|
+
"default": "./tweetsodium/cli.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
".": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./libsodium.d.ts",
|
|
57
|
+
"default": "./libsodium.js"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
29
60
|
},
|
|
30
|
-
"types": "./
|
|
61
|
+
"types": "./libsodium.d.ts",
|
|
31
62
|
"repository": {
|
|
32
63
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/hugoalh
|
|
34
|
-
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "tsc"
|
|
64
|
+
"url": "git+https://github.com/hugoalh/github-sodium-es.git"
|
|
37
65
|
},
|
|
38
66
|
"dependencies": {
|
|
39
|
-
"
|
|
67
|
+
"@hugoalh/blake": "^0.2.2",
|
|
68
|
+
"@hugoalh/nacl": "^0.2.1",
|
|
69
|
+
"es-arraybuffer-base64": "^1.1.2",
|
|
70
|
+
"libsodium-wrappers": "^0.8.4",
|
|
71
|
+
"@deno/shim-deno": "^0.19.2",
|
|
72
|
+
"@deno/shim-prompts": "^0.1.1",
|
|
73
|
+
"@deno/shim-timers": "^0.1.0"
|
|
40
74
|
},
|
|
41
75
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/node": "20.12.7",
|
|
44
|
-
"typescript": "^5.4.5"
|
|
45
|
-
},
|
|
46
|
-
"engines": {
|
|
47
|
-
"node": ">=16.13.0"
|
|
76
|
+
"@types/node": "^24.5.0"
|
|
48
77
|
},
|
|
49
78
|
"private": false,
|
|
50
79
|
"publishConfig": {
|
|
51
80
|
"access": "public"
|
|
52
|
-
}
|
|
53
|
-
|
|
81
|
+
},
|
|
82
|
+
"_generatedBy": "dnt@dev"
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/tweetsodium/cli.ts"],"names":[],"mappings":";AACA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../_dnt.polyfills.js";
|
|
3
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
4
|
+
import { GitHubSodiumSealer } from "../tweetsodium.js";
|
|
5
|
+
if (!globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
|
|
6
|
+
throw new Error(`This entrypoint is for command line only!`);
|
|
7
|
+
}
|
|
8
|
+
const [publicKey = "", secretValue = ""] = dntShim.Deno.args;
|
|
9
|
+
console.log(new GitHubSodiumSealer(publicKey).encrypt(secretValue));
|
package/tweetsodium.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
2
|
+
import "./_polyfill.js";
|
|
3
|
+
/**
|
|
4
|
+
* GitHub sodium sealer for encrypt value to the GitHub secret value.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GitHubSodiumSealer {
|
|
7
|
+
#private;
|
|
8
|
+
get [Symbol.toStringTag](): string;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize.
|
|
11
|
+
* @param {string} publicKey Public key (recipient's public key), which get from the GitHub organization or repository, need for encrypt value to the GitHub secret value before create or update the GitHub secret.
|
|
12
|
+
*/
|
|
13
|
+
constructor(publicKey: string);
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt value to the GitHub secret value.
|
|
16
|
+
* @param {string} value Value that need to encrypt as the GitHub secret value.
|
|
17
|
+
* @returns {string} An encrypted GitHub secret value.
|
|
18
|
+
*/
|
|
19
|
+
encrypt(value: string): string;
|
|
20
|
+
}
|
|
21
|
+
export default GitHubSodiumSealer;
|
|
22
|
+
//# sourceMappingURL=tweetsodium.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tweetsodium.d.ts","sourceRoot":"","sources":["src/tweetsodium.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAU7B,OAAO,gBAAgB,CAAC;AAExB;;GAEG;AACH,qBAAa,kBAAkB;;IAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED;;;OAGG;gBACS,SAAS,EAAE,MAAM;IAM7B;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAe9B;AACD,eAAe,kBAAkB,CAAC"}
|
package/tweetsodium.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
2
|
+
import { Blake2B } from "@hugoalh/blake/2b";
|
|
3
|
+
import { box, boxKeyPair, boxNonceLength, boxOverheadLength, boxPublicKeyLength } from "@hugoalh/nacl";
|
|
4
|
+
import "./_polyfill.js";
|
|
5
|
+
const sodiumOverheadLength = boxOverheadLength + boxPublicKeyLength;
|
|
6
|
+
/**
|
|
7
|
+
* GitHub sodium sealer for encrypt value to the GitHub secret value.
|
|
8
|
+
*/
|
|
9
|
+
export class GitHubSodiumSealer {
|
|
10
|
+
get [Symbol.toStringTag]() {
|
|
11
|
+
return "GitHubSodiumSealer/TweetSodium";
|
|
12
|
+
}
|
|
13
|
+
#publicKey;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize.
|
|
16
|
+
* @param {string} publicKey Public key (recipient's public key), which get from the GitHub organization or repository, need for encrypt value to the GitHub secret value before create or update the GitHub secret.
|
|
17
|
+
*/
|
|
18
|
+
constructor(publicKey) {
|
|
19
|
+
if (!(publicKey.length > 0)) {
|
|
20
|
+
throw new SyntaxError(`Parameter \`publicKey\` is not a string which is non empty!`);
|
|
21
|
+
}
|
|
22
|
+
this.#publicKey = Uint8Array.fromBase64(publicKey);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Encrypt value to the GitHub secret value.
|
|
26
|
+
* @param {string} value Value that need to encrypt as the GitHub secret value.
|
|
27
|
+
* @returns {string} An encrypted GitHub secret value.
|
|
28
|
+
*/
|
|
29
|
+
encrypt(value) {
|
|
30
|
+
if (!(value.length > 0)) {
|
|
31
|
+
throw new SyntaxError(`Parameter \`value\` is not a string which is non empty!`);
|
|
32
|
+
}
|
|
33
|
+
const ekp = boxKeyPair();
|
|
34
|
+
const result = new Uint8Array(sodiumOverheadLength + value.length);
|
|
35
|
+
result.set(ekp.publicKey, 0);
|
|
36
|
+
// 24 bytes nonce, which is a Blake2B digest from the ephemeral public key and the recipient's public key.
|
|
37
|
+
const nonce = new Blake2B({ length: boxNonceLength }).update(ekp.publicKey).update(this.#publicKey).hash();
|
|
38
|
+
const cipherText = box(new TextEncoder().encode(value), nonce, this.#publicKey, ekp.secretKey);
|
|
39
|
+
result.set(cipherText, boxPublicKeyLength);
|
|
40
|
+
return result.toBase64();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export default GitHubSodiumSealer;
|
package/dist/mod.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GitHub sodium sealer for encrypt value to GitHub secret value.
|
|
3
|
-
*/
|
|
4
|
-
export declare class GitHubSodiumSealer {
|
|
5
|
-
#private;
|
|
6
|
-
/**
|
|
7
|
-
* Initialize GitHub sodium sealer.
|
|
8
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
9
|
-
*/
|
|
10
|
-
constructor(publicKey: string);
|
|
11
|
-
/**
|
|
12
|
-
* Encrypt value to GitHub secret value.
|
|
13
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
14
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
15
|
-
*/
|
|
16
|
-
encrypt(value: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* Encrypt value to GitHub secret value.
|
|
19
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
20
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
21
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
22
|
-
*/
|
|
23
|
-
static seal(publicKey: string, value: string): string;
|
|
24
|
-
}
|
|
25
|
-
export default GitHubSodiumSealer;
|
|
26
|
-
/**
|
|
27
|
-
* Encrypt value to GitHub secret value.
|
|
28
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
29
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
30
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
31
|
-
*/
|
|
32
|
-
export declare function seal(publicKey: string, value: string): string;
|
|
33
|
-
//# sourceMappingURL=mod.d.ts.map
|
package/dist/mod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,qBAAa,kBAAkB;;IAE9B;;;OAGG;gBACS,SAAS,EAAE,MAAM;IAM7B;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM9B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAGrD;AACD,eAAe,kBAAkB,CAAC;AAClC;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
package/dist/mod.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
import libsodium from "libsodium-wrappers";
|
|
3
|
-
await libsodium.ready;
|
|
4
|
-
/**
|
|
5
|
-
* GitHub sodium sealer for encrypt value to GitHub secret value.
|
|
6
|
-
*/
|
|
7
|
-
export class GitHubSodiumSealer {
|
|
8
|
-
#publicKey;
|
|
9
|
-
/**
|
|
10
|
-
* Initialize GitHub sodium sealer.
|
|
11
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
12
|
-
*/
|
|
13
|
-
constructor(publicKey) {
|
|
14
|
-
if (!(publicKey.length > 0)) {
|
|
15
|
-
throw new SyntaxError(`Argument \`publicKey\` is not a string which is non-empty!`);
|
|
16
|
-
}
|
|
17
|
-
this.#publicKey = Buffer.from(publicKey, "base64");
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Encrypt value to GitHub secret value.
|
|
21
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
22
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
23
|
-
*/
|
|
24
|
-
encrypt(value) {
|
|
25
|
-
if (!(value.length > 0)) {
|
|
26
|
-
throw new SyntaxError(`Argument \`value\` is not a string which is non-empty!`);
|
|
27
|
-
}
|
|
28
|
-
return Buffer.from(libsodium.crypto_box_seal(Buffer.from(value), this.#publicKey)).toString("base64");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Encrypt value to GitHub secret value.
|
|
32
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
33
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
34
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
35
|
-
*/
|
|
36
|
-
static seal(publicKey, value) {
|
|
37
|
-
return new this(publicKey).encrypt(value);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export default GitHubSodiumSealer;
|
|
41
|
-
/**
|
|
42
|
-
* Encrypt value to GitHub secret value.
|
|
43
|
-
* @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
|
|
44
|
-
* @param {string} value Value that need to encrypt as secret value.
|
|
45
|
-
* @returns {string} An encrypted GitHub secret value.
|
|
46
|
-
*/
|
|
47
|
-
export function seal(publicKey, value) {
|
|
48
|
-
return new GitHubSodiumSealer(publicKey).encrypt(value);
|
|
49
|
-
}
|