@hugoalh/github-sodium 1.1.6 → 2.0.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.
package/LICENSE.md CHANGED
@@ -1,27 +1,35 @@
1
1
  # MIT License
2
2
 
3
- © 2020 hugoalh Studio
3
+ Copyright © 2020\~2022 hugoalh Studio
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
 
7
7
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
9
- The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
10
 
11
11
  ---
12
12
 
13
- *This is a short and simple list that mostly concluded this license about the permissions 🟢, conditions 🔵, and limitations 🔴, this license content section shall prevail.*
14
-
15
- - Commercial Use 🟢
16
- - Distribution 🟢
17
- - Modification 🟢
18
- - Patent Use
19
- - Private Use 🟢
20
- - Disclose Source
21
- - License & Copyright Notice 🔵
22
- - Network Use Is Distribution
23
- - Same License
24
- - State Changes
25
- - Liability 🔴
26
- - Trademark Use
27
- - Warranty 🔴
13
+ ## TLDR
14
+
15
+ This is a short and simple list that mostly concluded this license about the permissions, conditions, and limitations, this license content section shall prevail.
16
+
17
+ ### Permissions
18
+
19
+ - **Commercial Use:** The licensed material and derivatives may be used for commercial purposes.
20
+ - **Distribution:** The licensed material may be distributed.
21
+ - **Modification:** The licensed material may be modified.
22
+ - **Private Use:** The licensed material may be used and modified in private.
23
+
24
+ ### Conditions
25
+
26
+ - **License & Copyright Notice:** A copy of the license and copyright notice must be included with the licensed material.
27
+
28
+ ### Limitations
29
+
30
+ - **Liability:** This license includes a limitation of liability.
31
+ - **Warranty:** This license explicitly states that it does not provide any warranty.
32
+
33
+ ## Attribution
34
+
35
+ This license is adopted from [Choose A License](https://choosealicense.com/), available at [here](https://choosealicense.com/licenses/mit).
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/hugoalh-studio/github-sodium-nodejs?label=Grade&logo=codefactor&logoColor=ffffff&style=flat-square)](https://www.codefactor.io/repository/github/hugoalh-studio/github-sodium-nodejs)
12
12
  [![LGTM Alerts](https://img.shields.io/lgtm/alerts/g/hugoalh-studio/github-sodium-nodejs?label=Alerts&logo=lgtm&logoColor=ffffff&style=flat-square)
13
13
  ![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/g/hugoalh-studio/github-sodium-nodejs?label=Grade&logo=lgtm&logoColor=ffffff&style=flat-square)](https://lgtm.com/projects/g/hugoalh-studio/github-sodium-nodejs)
14
- [![License](https://img.shields.io/static/v1?label=License&message=MIT&color=brightgreen&style=flat-square)](./LICENSE.md)
14
+ [![License](https://img.shields.io/static/v1?label=License&message=MIT&style=flat-square)](./LICENSE.md)
15
15
 
16
16
  | **Release** | **Latest** (![GitHub Latest Release Date](https://img.shields.io/github/release-date/hugoalh-studio/github-sodium-nodejs?label=%20&style=flat-square)) | **Pre** (![GitHub Latest Pre-Release Date](https://img.shields.io/github/release-date-pre/hugoalh-studio/github-sodium-nodejs?label=%20&style=flat-square)) |
17
17
  |:-:|:-:|:-:|
@@ -22,7 +22,7 @@
22
22
 
23
23
  A NodeJS module to provide an easier sodium for GitHub secret.
24
24
 
25
- This project is based on TweetSodium ([GitHub](https://github.com/github/tweetsodium))([NPM](https://www.npmjs.com/package/tweetsodium)) with optimization for GitHub secret.
25
+ This project is based on `libsodium.js` ([GitHub](https://github.com/jedisct1/libsodium.js))([NPM](https://www.npmjs.com/package/libsodium))(for ModuleJS) and `tweetsodium` ([GitHub](https://github.com/github/tweetsodium))([NPM](https://www.npmjs.com/package/tweetsodium))(for CommonJS) with optimization for GitHub secret.
26
26
 
27
27
  ## 📚 Documentation
28
28
 
@@ -30,7 +30,8 @@ This project is based on TweetSodium ([GitHub](https://github.com/github/tweetso
30
30
 
31
31
  #### Install
32
32
 
33
- NodeJS (>= v14.15.0) + NPM (>= v6.14.8):
33
+ - NodeJS >= v14.15.0
34
+ - NPM >= v6.14.8
34
35
 
35
36
  ```sh
36
37
  npm install @hugoalh/github-sodium
@@ -45,21 +46,27 @@ const githubSodium = require("@hugoalh/github-sodium");
45
46
  #### Use In ModuleJS
46
47
 
47
48
  ```js
48
- import githubSodium from "@hugoalh/github-sodium";
49
+ /* Either */
50
+ import * as githubSodium from "@hugoalh/github-sodium";// All
51
+ import githubSodium from "@hugoalh/github-sodium";// All (>= v2.0.0)
52
+ import { ... } from "@hugoalh/github-sodium";// Part / Tree-shake
49
53
  ```
50
54
 
51
55
  ### API
52
56
 
53
- ```ts
54
- githubSodium(// Encrypt value to GitHub secret value.
55
- publicKey: string,// Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
56
- value: string// Value that need to encrypt as secret value.
57
- ): string// An encrypted GitHub secret value.
58
- ```
57
+ #### Class
58
+
59
+ - `GitHubSodiumSealer`
60
+ - `@constructor(publicKey)`
61
+ - `encrypt(value)`
62
+
63
+ #### Function
64
+
65
+ - `seal(publicKey, value)`
59
66
 
60
67
  ### Example
61
68
 
62
69
  ```js
63
- githubSodium("base64-encoded-public-key", "plain-text-secret");
70
+ new GitHubSodiumSealer("base64-encoded-public-key").encrypt("plain-text-secret");
64
71
  //=> "+ZYvJDZMHUfBkJdyq5Zm9SKqeuBQ4sj+6sfjlH4CgG0="
65
72
  ```
@@ -0,0 +1,20 @@
1
+ export default GitHubSodiumSealer;
2
+ /**
3
+ * @class GitHubSodiumSealer
4
+ * @description Encrypt value to GitHub secret value.
5
+ */
6
+ declare class GitHubSodiumSealer {
7
+ /**
8
+ * @constructor
9
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
10
+ */
11
+ constructor(publicKey: string);
12
+ /**
13
+ * @method
14
+ * @param {string} value Value that need to encrypt as secret value.
15
+ * @returns {string} An encrypted GitHub secret value.
16
+ */
17
+ encrypt(value: string): string;
18
+ #private;
19
+ }
20
+ //# sourceMappingURL=github-sodium-sealer.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-sodium-sealer.d.mts","sourceRoot":"","sources":["github-sodium-sealer.mjs"],"names":[],"mappings":";AAGA;;;GAGG;AACH;IAEC;;;OAGG;IACH,uBAFW,MAAM,EAOhB;IACD;;;;OAIG;IACH,eAHW,MAAM,GACJ,MAAM,CAOlB;;CACD"}
@@ -0,0 +1,20 @@
1
+ export = GitHubSodiumSealer;
2
+ /**
3
+ * @class GitHubSodiumSealer
4
+ * @description Encrypt value to GitHub secret value.
5
+ */
6
+ declare class GitHubSodiumSealer {
7
+ /**
8
+ * @constructor
9
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
10
+ */
11
+ constructor(publicKey: string);
12
+ /**
13
+ * @method
14
+ * @param {string} value Value that need to encrypt as secret value.
15
+ * @returns {string} An encrypted GitHub secret value.
16
+ */
17
+ encrypt(value: string): string;
18
+ #private;
19
+ }
20
+ //# sourceMappingURL=github-sodium-sealer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-sodium-sealer.d.ts","sourceRoot":"","sources":["github-sodium-sealer.js"],"names":[],"mappings":";AAEA;;;GAGG;AACH;IAEC;;;OAGG;IACH,uBAFW,MAAM,EAOhB;IACD;;;;OAIG;IACH,eAHW,MAAM,GACJ,MAAM,CAOlB;;CACD"}
@@ -0,0 +1,31 @@
1
+ const advancedDetermine = require("@hugoalh/advanced-determine");
2
+ const tweetsodium = require("tweetsodium");
3
+ /**
4
+ * @class GitHubSodiumSealer
5
+ * @description Encrypt value to GitHub secret value.
6
+ */
7
+ class GitHubSodiumSealer {
8
+ #publicKeyStorage;
9
+ /**
10
+ * @constructor
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 (!advancedDetermine.isString(publicKey, { empty: false })) {
15
+ throw new TypeError(`Argument \`publicKey\` must be type of string (non-empty)!`);
16
+ };
17
+ this.#publicKeyStorage = Buffer.from(publicKey, "base64");
18
+ };
19
+ /**
20
+ * @method
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 (!advancedDetermine.isString(value, { empty: false })) {
26
+ throw new TypeError(`Argument \`value\` must be type of string (non-empty)!`);
27
+ };
28
+ return Buffer.from(tweetsodium.seal(Buffer.from(value), this.#publicKeyStorage)).toString("base64");
29
+ };
30
+ };
31
+ module.exports = GitHubSodiumSealer;
@@ -0,0 +1,32 @@
1
+ import { isString as adIsString } from "@hugoalh/advanced-determine";
2
+ import libsodium from "libsodium-wrappers";
3
+ await libsodium.ready;
4
+ /**
5
+ * @class GitHubSodiumSealer
6
+ * @description Encrypt value to GitHub secret value.
7
+ */
8
+ class GitHubSodiumSealer {
9
+ #publicKeyStorage;
10
+ /**
11
+ * @constructor
12
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
13
+ */
14
+ constructor(publicKey) {
15
+ if (!adIsString(publicKey, { empty: false })) {
16
+ throw new TypeError(`Argument \`publicKey\` must be type of string (non-empty)!`);
17
+ };
18
+ this.#publicKeyStorage = Buffer.from(publicKey, "base64");
19
+ };
20
+ /**
21
+ * @method
22
+ * @param {string} value Value that need to encrypt as secret value.
23
+ * @returns {string} An encrypted GitHub secret value.
24
+ */
25
+ encrypt(value) {
26
+ if (!adIsString(value, { empty: false })) {
27
+ throw new TypeError(`Argument \`value\` must be type of string (non-empty)!`);
28
+ };
29
+ return Buffer.from(libsodium.crypto_box_seal(Buffer.from(value), this.#publicKeyStorage)).toString("base64");
30
+ };
31
+ };
32
+ export default GitHubSodiumSealer;
package/lib/main.d.mts ADDED
@@ -0,0 +1,9 @@
1
+ declare namespace _default {
2
+ export { GitHubSodiumSealer };
3
+ export { seal };
4
+ }
5
+ export default _default;
6
+ import GitHubSodiumSealer from "./github-sodium-sealer.mjs";
7
+ import seal from "./seal.mjs";
8
+ export { GitHubSodiumSealer, seal };
9
+ //# sourceMappingURL=main.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.mts","sourceRoot":"","sources":["main.mjs"],"names":[],"mappings":""}
package/lib/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import GitHubSodiumSealer = require("./github-sodium-sealer.js");
2
+ import seal = require("./seal.js");
3
+ export { GitHubSodiumSealer, seal };
4
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["main.js"],"names":[],"mappings":""}
package/lib/main.js CHANGED
@@ -1,24 +1,6 @@
1
- const sodium = require("tweetsodium");
2
- /**
3
- * @function githubSodium
4
- * @description Encrypt value to GitHub secret value.
5
- * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
6
- * @param {string} value Value that need to encrypt as secret value.
7
- * @returns {string} An encrypted GitHub secret value.
8
- */
9
- function githubSodium(publicKey, value) {
10
- if (
11
- typeof publicKey !== "string" ||
12
- publicKey.length === 0
13
- ) {
14
- throw new TypeError(`Argument \`publicKey\` must be type of string (non-empty)!`);
15
- };
16
- if (
17
- typeof value !== "string" ||
18
- value.length === 0
19
- ) {
20
- throw new TypeError(`Argument \`value\` must be type of string (non-empty)!`);
21
- };
22
- return Buffer.from(sodium.seal(Buffer.from(value), Buffer.from(publicKey, "base64"))).toString("base64");
1
+ const GitHubSodiumSealer = require("./github-sodium-sealer.js");
2
+ const seal = require("./seal.js");
3
+ module.exports = {
4
+ GitHubSodiumSealer,
5
+ seal
23
6
  };
24
- module.exports = githubSodium;
package/lib/main.mjs CHANGED
@@ -1,24 +1,10 @@
1
- import * as sodium from "tweetsodium";
2
- /**
3
- * @function githubSodium
4
- * @description Encrypt value to GitHub secret value.
5
- * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
6
- * @param {string} value Value that need to encrypt as secret value.
7
- * @returns {string} An encrypted GitHub secret value.
8
- */
9
- function githubSodium(publicKey, value) {
10
- if (
11
- typeof publicKey !== "string" ||
12
- publicKey.length === 0
13
- ) {
14
- throw new TypeError(`Argument \`publicKey\` must be type of string (non-empty)!`);
15
- };
16
- if (
17
- typeof value !== "string" ||
18
- value.length === 0
19
- ) {
20
- throw new TypeError(`Argument \`value\` must be type of string (non-empty)!`);
21
- };
22
- return Buffer.from(sodium.seal(Buffer.from(value), Buffer.from(publicKey, "base64"))).toString("base64");
1
+ import GitHubSodiumSealer from "./github-sodium-sealer.mjs";
2
+ import seal from "./seal.mjs";
3
+ export {
4
+ GitHubSodiumSealer,
5
+ seal
6
+ };
7
+ export default {
8
+ GitHubSodiumSealer,
9
+ seal
23
10
  };
24
- export default githubSodium;
@@ -1,10 +1,9 @@
1
- export = githubSodium;
2
- /**
3
- * @function githubSodium
4
- * @description Encrypt value to GitHub secret value.
5
- * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
6
- * @param {string} value Value that need to encrypt as secret value.
7
- * @returns {string} An encrypted GitHub secret value.
8
- */
9
- declare function githubSodium(publicKey: string, value: string): string;
10
- //# sourceMappingURL=main.d.ts.map
1
+ export default seal;
2
+ /**
3
+ * @function seal
4
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
5
+ * @param {string} value Value that need to encrypt as secret value.
6
+ * @returns {string} An encrypted GitHub secret value.
7
+ */
8
+ declare function seal(publicKey: string, value: string): string;
9
+ //# sourceMappingURL=seal.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seal.d.mts","sourceRoot":"","sources":["seal.mjs"],"names":[],"mappings":";AACA;;;;;GAKG;AACH,iCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB"}
@@ -1,10 +1,9 @@
1
- export default githubSodium;
2
- /**
3
- * @function githubSodium
4
- * @description Encrypt value to GitHub secret value.
5
- * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
6
- * @param {string} value Value that need to encrypt as secret value.
7
- * @returns {string} An encrypted GitHub secret value.
8
- */
9
- declare function githubSodium(publicKey: string, value: string): string;
10
- //# sourceMappingURL=main.d.mts.map
1
+ export = seal;
2
+ /**
3
+ * @function seal
4
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
5
+ * @param {string} value Value that need to encrypt as secret value.
6
+ * @returns {string} An encrypted GitHub secret value.
7
+ */
8
+ declare function seal(publicKey: string, value: string): string;
9
+ //# sourceMappingURL=seal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seal.d.ts","sourceRoot":"","sources":["seal.js"],"names":[],"mappings":";AACA;;;;;GAKG;AACH,iCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB"}
package/lib/seal.js ADDED
@@ -0,0 +1,11 @@
1
+ const GitHubSodiumSealer = require("./github-sodium-sealer.js");
2
+ /**
3
+ * @function seal
4
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
5
+ * @param {string} value Value that need to encrypt as secret value.
6
+ * @returns {string} An encrypted GitHub secret value.
7
+ */
8
+ function seal(publicKey, value) {
9
+ return new GitHubSodiumSealer(publicKey).encrypt(value);
10
+ };
11
+ module.exports = seal;
package/lib/seal.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import GitHubSodiumSealer from "./github-sodium-sealer.mjs";
2
+ /**
3
+ * @function seal
4
+ * @param {string} publicKey Organization's or repository's public key, which need for encrypt value to secret value before create or update a secret.
5
+ * @param {string} value Value that need to encrypt as secret value.
6
+ * @returns {string} An encrypted GitHub secret value.
7
+ */
8
+ function seal(publicKey, value) {
9
+ return new GitHubSodiumSealer(publicKey).encrypt(value);
10
+ };
11
+ export default seal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hugoalh/github-sodium",
3
- "version": "1.1.6",
3
+ "version": "2.0.1",
4
4
  "description": "A module to provide an easier sodium for GitHub secret.",
5
5
  "keywords": [
6
6
  "github",
@@ -18,13 +18,18 @@
18
18
  "import": "./lib/main.mjs",
19
19
  "require": "./lib/main.js"
20
20
  },
21
- "types": "./@types/main.d.ts",
21
+ "types": "./lib/main.d.ts",
22
22
  "repository": {
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/hugoalh-studio/github-sodium-nodejs.git"
25
25
  },
26
26
  "dependencies": {
27
- "tweetsodium": "^0.0.5"
27
+ "@hugoalh/advanced-determine": "^7.1.3",
28
+ "libsodium-wrappers": "^0.7.10",
29
+ "tweetsodium": "^0.0.6"
30
+ },
31
+ "devDependencies": {
32
+ "@types/libsodium-wrappers": "^0.7.9"
28
33
  },
29
34
  "engines": {
30
35
  "node": ">= 14.15.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.mts","sourceRoot":"","sources":["../lib/main.mjs"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,yCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAgBlB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../lib/main.js"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,yCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAgBlB"}