@hugoalh/github-sodium 1.1.6 → 2.0.0-beta.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.
@@ -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":["../lib/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":["../lib/github-sodium-sealer.js"],"names":[],"mappings":";AAEA;;;GAGG;AACH;IAEC;;;OAGG;IACH,uBAFW,MAAM,EAOhB;IACD;;;;OAIG;IACH,eAHW,MAAM,GACJ,MAAM,CAOlB;;CACD"}
package/@types/main.d.mts CHANGED
@@ -1,10 +1,13 @@
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;
1
+ declare namespace _default {
2
+ export { GitHubSodiumSealer };
3
+ export { seal };
4
+ export { version as v };
5
+ export { version as ver };
6
+ export { version };
7
+ }
8
+ export default _default;
9
+ import GitHubSodiumSealer from "./github-sodium-sealer.mjs";
10
+ import seal from "./seal.mjs";
11
+ export const version: 1;
12
+ export { GitHubSodiumSealer, seal, version as v, version as ver };
10
13
  //# sourceMappingURL=main.d.mts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"main.d.mts","sourceRoot":"","sources":["../lib/main.mjs"],"names":[],"mappings":";;;;;;;;;;AAEA,wBAAkB"}
package/@types/main.d.ts CHANGED
@@ -1,10 +1,5 @@
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;
1
+ import GitHubSodiumSealer = require("./github-sodium-sealer.js");
2
+ import seal = require("./seal.js");
3
+ export const version: 1;
4
+ export { GitHubSodiumSealer, seal, version as v, version as ver };
10
5
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../lib/main.js"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,yCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAgBlB"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../lib/main.js"],"names":[],"mappings":";;AAEA,wBAAkB"}
@@ -0,0 +1,9 @@
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":["../lib/seal.mjs"],"names":[],"mappings":";AACA;;;;;GAKG;AACH,iCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB"}
@@ -0,0 +1,9 @@
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":["../lib/seal.js"],"names":[],"mappings":";AACA;;;;;GAKG;AACH,iCAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB"}
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- © 2020 hugoalh Studio
3
+ © 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
 
package/README.md CHANGED
@@ -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 LibSodiumJS ([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,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
+ #publicKey;
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.#publicKey = publicKey;
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), Buffer.from(this.#publicKey, "base64"))).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
+ #publicKey;
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.#publicKey = publicKey;
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), Buffer.from(this.#publicKey, "base64"))).toString("base64");
30
+ };
31
+ };
32
+ export default GitHubSodiumSealer;
package/lib/main.js CHANGED
@@ -1,24 +1,10 @@
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
+ const version = 1;
4
+ module.exports = {
5
+ GitHubSodiumSealer,
6
+ seal,
7
+ v: version,
8
+ ver: version,
9
+ version
23
10
  };
24
- module.exports = githubSodium;
package/lib/main.mjs CHANGED
@@ -1,24 +1,17 @@
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
+ const version = 1;
4
+ export {
5
+ GitHubSodiumSealer,
6
+ seal,
7
+ version as v,
8
+ version as ver,
9
+ version
10
+ };
11
+ export default {
12
+ GitHubSodiumSealer,
13
+ seal,
14
+ v: version,
15
+ ver: version,
16
+ version
23
17
  };
24
- export default githubSodium;
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.0-beta.1",
4
4
  "description": "A module to provide an easier sodium for GitHub secret.",
5
5
  "keywords": [
6
6
  "github",
@@ -24,7 +24,10 @@
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.0.2",
28
+ "@types/libsodium-wrappers": "^0.7.9",
29
+ "libsodium-wrappers": "^0.7.10",
30
+ "tweetsodium": "^0.0.6"
28
31
  },
29
32
  "engines": {
30
33
  "node": ">= 14.15.0",