@hugoalh/github-sodium 5.0.3 → 5.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright © 2020\~2024 hugoalh Studio
3
+ Copyright © 2020\~2024 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,161 +2,82 @@
2
2
 
3
3
  [**⚖️** MIT](./LICENSE.md)
4
4
 
5
- [![GitHub: hugoalh-studio/github-sodium-es](https://img.shields.io/github/v/release/hugoalh-studio/github-sodium-es?label=hugoalh-studio/github-sodium-es&labelColor=181717&logo=github&logoColor=ffffff&sort=semver&style=flat "GitHub: hugoalh-studio/github-sodium-es")](https://github.com/hugoalh-studio/github-sodium-es)
6
- [![JSR: @hugoalh/github-sodium](https://img.shields.io/jsr/v/@hugoalh/github-sodium?label=JSR%20@hugoalh/github-sodium&labelColor=F7DF1E&logoColor=000000&style=flat "JSR: @hugoalh/github-sodium")](https://jsr.io/@hugoalh/github-sodium)
5
+ [![GitHub: hugoalh/github-sodium-es](https://img.shields.io/github/v/release/hugoalh/github-sodium-es?label=hugoalh/github-sodium-es&labelColor=181717&logo=github&logoColor=ffffff&sort=semver&style=flat "GitHub: hugoalh/github-sodium-es")](https://github.com/hugoalh/github-sodium-es)
6
+ [![JSR: @hugoalh/github-sodium](https://img.shields.io/jsr/v/@hugoalh/github-sodium?label=@hugoalh/github-sodium&labelColor=F7DF1E&logo=jsr&logoColor=000000&style=flat "JSR: @hugoalh/github-sodium")](https://jsr.io/@hugoalh/github-sodium)
7
7
  [![NPM: @hugoalh/github-sodium](https://img.shields.io/npm/v/@hugoalh/github-sodium?label=@hugoalh/github-sodium&labelColor=CB3837&logo=npm&logoColor=ffffff&style=flat "NPM: @hugoalh/github-sodium")](https://www.npmjs.com/package/@hugoalh/github-sodium)
8
8
 
9
- An ES (JavaScript & TypeScript) module to provide an easier sodium for GitHub secrets.
9
+ An ES (JavaScript & TypeScript) module to provide an easier and simplified method for encrypt GitHub secrets, based on the NPM package [`libsodium.js`](https://www.npmjs.com/package/libsodium-wrappers).
10
10
 
11
- This project is based on "[libsodium.js](https://github.com/jedisct1/libsodium.js)" with optimization for GitHub secrets.
11
+ ## 🔰 Begin
12
12
 
13
- ## 🎯 Target
13
+ ### 🎯 Targets
14
14
 
15
- - Bun ^ v1.0.0
16
- - Cloudflare Workers
17
- - Deno >= v1.34.0 / >= v1.41.1 (For JSR Only)
18
- > **🛡️ Require Permission**
19
- >
20
- > *N/A*
21
- - NodeJS >= v16.13.0
15
+ | | **Remote** | **JSR** | **NPM** |
16
+ |:--|:--|:--|:--|
17
+ | **[Bun](https://bun.sh/)** >= v1.1.0 | ❌ | ❓ | ✔️ |
18
+ | **[Cloudflare Workers](https://workers.cloudflare.com/)** | ❌ | ❓ | ✔️ |
19
+ | **[Deno](https://deno.land/)** >= v1.42.0 | ✔️ | ✔️ | ✔️ |
20
+ | **[NodeJS](https://nodejs.org/)** >= v16.13.0 | ❌ | ❓ | ✔️ |
22
21
 
23
- ## 🔰 Usage
22
+ > [!NOTE]
23
+ > - It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.
24
24
 
25
- ### Via JSR With `node_modules`
25
+ ### #️⃣ Resources Identifier
26
26
 
27
- > **🎯 Supported Target**
28
- >
29
- > - Bun
30
- > - Cloudflare Workers
31
- > - NodeJS
32
-
33
- 1. Install via:
34
- - Bun
35
- ```sh
36
- bunx jsr add @hugoalh/github-sodium[@${Tag}]
37
- ```
38
- - NPM
39
- ```sh
40
- npx jsr add @hugoalh/github-sodium[@${Tag}]
41
- ```
42
- - PNPM
43
- ```sh
44
- pnpm dlx jsr add @hugoalh/github-sodium[@${Tag}]
45
- ```
46
- - Yarn
47
- ```sh
48
- yarn dlx jsr add @hugoalh/github-sodium[@${Tag}]
49
- ```
50
- 2. Import at the script:
51
- ```ts
52
- import ... from "@hugoalh/github-sodium";
53
- ```
54
-
55
- > **ℹ️ Note**
56
- >
57
- > - 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.
58
- > - It is recommended to import the module with tag for immutability.
59
-
60
- ### Via JSR With Specifier
61
-
62
- > **🎯 Supported Target**
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
- ```
27
+ - **Remote - GitHub Raw:**
28
+ ```
29
+ https://raw.githubusercontent.com/hugoalh/github-sodium-es/{Tag}/mod.ts
30
+ ```
31
+ - **JSR:**
32
+ ```
33
+ [jsr:]@hugoalh/github-sodium[@{Tag}]
34
+ ```
35
+ - **NPM:**
36
+ ```
37
+ [npm:]@hugoalh/github-sodium[@{Tag}]
38
+ ```
134
39
 
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:
40
+ > [!NOTE]
41
+ > - For usage of remote resources, it is recommended to import the entire module with the main path `mod.ts`, however it is also able to import part of the module with sub path if available, but do not import if:
138
42
  >
139
- > - it's file path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
43
+ > - it's path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
140
44
  > - 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() {}`).
45
+ > - it's symbol has an underscore prefix (e.g.: `_bar`, `_foo`).
142
46
  >
143
47
  > 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.
48
+ > - For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub entrypoints.
49
+ > - It is recommended to use this module with tag for immutability.
145
50
 
146
- ## 🧩 API
51
+ ### 🛡️ Require Runtime Permissions
52
+
53
+ *This module does not require any runtime permission.*
54
+
55
+ ## 🧩 APIs (Excerpt)
147
56
 
148
57
  - ```ts
149
58
  class GitHubSodiumSealer {
150
- constructor(publicKey: string): GitHubSodiumSealer;
59
+ constructor(publicKey: string, keyID?: string);
151
60
  encrypt(value: string): string;
152
- static seal(publicKey: string, value: string): string;
61
+ encryptToRequestBody(value: string): GitHubRESTSetPublicKeyRequestBody;
62
+ getKeyID(): string | undefined;
63
+ get keyID(): string | undefined;
64
+ static fromJSON(input: JSONObject): GitHubSodiumSealer;
65
+ static async fromResponse(input: Response): Promise<GitHubSodiumSealer>;
153
66
  }
154
67
  ```
155
68
  - ```ts
156
- function seal(publicKey: string, value: string): string;
69
+ interface GitHubRESTSetPublicKeyRequestBody {
70
+ encrypted_value: string;
71
+ key_id: string;
72
+ }
157
73
  ```
158
74
 
159
- ## ✍️ Example
75
+ > [!NOTE]
76
+ > - For the full or prettier documentation, can visit via:
77
+ > - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/documentation_generator/)
78
+ > - [JSR](https://jsr.io/@hugoalh/github-sodium)
79
+
80
+ ## ✍️ Examples
160
81
 
161
82
  - ```ts
162
83
  new GitHubSodiumSealer("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234").encrypt("plain-text-secret");
package/mod.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { type JSONObject } from "@hugoalh/is-json";
2
+ export interface GitHubRESTSetPublicKeyRequestBody {
3
+ encrypted_value: string;
4
+ key_id: string;
5
+ }
6
+ /**
7
+ * GitHub sodium sealer for encrypt value to the GitHub secret value.
8
+ */
9
+ export declare class GitHubSodiumSealer {
10
+ #private;
11
+ get [Symbol.toStringTag](): string;
12
+ /**
13
+ * Initialize the GitHub sodium sealer.
14
+ * @param {string} publicKey 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.
15
+ * @param {string} [keyID] ID of the key, which get from the GitHub organization or repository, need for create or update the GitHub secret. This parameter is optional if no need to output as part of the {@linkcode Request} body.
16
+ */
17
+ constructor(publicKey: string, keyID?: string);
18
+ /**
19
+ * Encrypt value to the GitHub secret value.
20
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
21
+ * @returns {string} An encrypted GitHub secret value.
22
+ */
23
+ encrypt(value: string): string;
24
+ /**
25
+ * Encrypt value to the GitHub secret value, and output as part of the {@linkcode Request} body for create or update GitHub secret via the GitHub REST API.
26
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
27
+ * @returns {GitHubRESTSetPublicKeyRequestBody} Part of the {@linkcode Request} body for create or update GitHub secret via the GitHub REST API.
28
+ */
29
+ encryptToRequestBody(value: string): GitHubRESTSetPublicKeyRequestBody;
30
+ /**
31
+ * Get the ID of the key.
32
+ * @returns {string | undefined} ID of the key.
33
+ */
34
+ getKeyID(): string | undefined;
35
+ /**
36
+ * Get the ID of the key.
37
+ * @returns {string | undefined} ID of the key.
38
+ */
39
+ get keyID(): string | undefined;
40
+ /**
41
+ * Initialize the GitHub sodium sealer with the {@linkcode Response} JSON body from get GitHub secret public key via the GitHub REST API.
42
+ * @param {JSONObject} input {@linkcode Response} JSON body.
43
+ * @returns {GitHubSodiumSealer} GitHub sodium sealer.
44
+ */
45
+ static fromJSON(input: JSONObject): GitHubSodiumSealer;
46
+ /**
47
+ * Initialize the GitHub sodium sealer with the {@linkcode Response} from get GitHub secret public key via the GitHub REST API.
48
+ * @param {Response} input {@linkcode Response}.
49
+ * @returns {Promise<GitHubSodiumSealer>} GitHub sodium sealer.
50
+ */
51
+ static fromResponse(input: Response): Promise<GitHubSodiumSealer>;
52
+ /**
53
+ * Encrypt value to the GitHub secret value.
54
+ * @param {string} publicKey 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.
55
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
56
+ * @returns {string} An encrypted GitHub secret value.
57
+ * @deprecated Migrate to `new GitHubSodiumSealer(publicKey).encrypt(value)`.
58
+ */
59
+ static seal(publicKey: string, value: string): string;
60
+ }
61
+ export default GitHubSodiumSealer;
62
+ /**
63
+ * Encrypt value to the GitHub secret value.
64
+ * @param {string} publicKey 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.
65
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
66
+ * @returns {string} An encrypted GitHub secret value.
67
+ * @deprecated Migrate to `new GitHubSodiumSealer(publicKey).encrypt(value)`.
68
+ */
69
+ export declare function seal(publicKey: string, value: string): string;
70
+ //# sourceMappingURL=mod.d.ts.map
package/mod.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,UAAU,EACf,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,iCAAiC;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CACf;AACD;;GAEG;AACH,qBAAa,kBAAkB;;IAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAGD;;;;OAIG;gBACS,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAa7C;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM9B;;;;OAIG;IACH,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,iCAAiC;IAStE;;;OAGG;IACH,QAAQ,IAAI,MAAM,GAAG,SAAS;IAG9B;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IACD;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB;IAStD;;;;OAIG;WACU,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAOvE;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAGrD;AACD,eAAe,kBAAkB,CAAC;AAClC;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D"}
package/mod.js ADDED
@@ -0,0 +1,114 @@
1
+ import { Buffer } from "node:buffer";
2
+ import libsodium from "libsodium-wrappers";
3
+ import { isJSONObject } from "@hugoalh/is-json";
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";
11
+ }
12
+ #keyID;
13
+ #publicKey;
14
+ /**
15
+ * Initialize the GitHub sodium sealer.
16
+ * @param {string} publicKey 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
+ * @param {string} [keyID] ID of the key, which get from the GitHub organization or repository, need for create or update the GitHub secret. This parameter is optional if no need to output as part of the {@linkcode Request} body.
18
+ */
19
+ constructor(publicKey, keyID) {
20
+ if (!(typeof keyID === "undefined" ||
21
+ (typeof keyID === "string" && keyID.length > 0))) {
22
+ throw new TypeError(`Parameter \`keyID\` is not \`undefined\`, or a string which is non empty!`);
23
+ }
24
+ if (!(publicKey.length > 0)) {
25
+ throw new SyntaxError(`Parameter \`publicKey\` is not a string which is non empty!`);
26
+ }
27
+ this.#keyID = keyID;
28
+ this.#publicKey = Buffer.from(publicKey, "base64");
29
+ }
30
+ /**
31
+ * Encrypt value to the GitHub secret value.
32
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
33
+ * @returns {string} An encrypted GitHub secret value.
34
+ */
35
+ encrypt(value) {
36
+ if (!(value.length > 0)) {
37
+ throw new SyntaxError(`Parameter \`value\` is not a string which is non empty!`);
38
+ }
39
+ return Buffer.from(libsodium.crypto_box_seal(Buffer.from(value), this.#publicKey)).toString("base64");
40
+ }
41
+ /**
42
+ * Encrypt value to the GitHub secret value, and output as part of the {@linkcode Request} body for create or update GitHub secret via the GitHub REST API.
43
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
44
+ * @returns {GitHubRESTSetPublicKeyRequestBody} Part of the {@linkcode Request} body for create or update GitHub secret via the GitHub REST API.
45
+ */
46
+ encryptToRequestBody(value) {
47
+ if (this.#keyID !== "string") {
48
+ throw new Error(`Key ID was not defined at the initialize stage!`);
49
+ }
50
+ return {
51
+ encrypted_value: this.encrypt(value),
52
+ key_id: this.#keyID
53
+ };
54
+ }
55
+ /**
56
+ * Get the ID of the key.
57
+ * @returns {string | undefined} ID of the key.
58
+ */
59
+ getKeyID() {
60
+ return this.#keyID;
61
+ }
62
+ /**
63
+ * Get the ID of the key.
64
+ * @returns {string | undefined} ID of the key.
65
+ */
66
+ get keyID() {
67
+ return this.#keyID;
68
+ }
69
+ /**
70
+ * Initialize the GitHub sodium sealer with the {@linkcode Response} JSON body from get GitHub secret public key via the GitHub REST API.
71
+ * @param {JSONObject} input {@linkcode Response} JSON body.
72
+ * @returns {GitHubSodiumSealer} GitHub sodium sealer.
73
+ */
74
+ static fromJSON(input) {
75
+ if (typeof input.key !== "string" ||
76
+ typeof input.key_id !== "string") {
77
+ throw new Error(`Parameter \`input\` is not a valid response JSON body!`);
78
+ }
79
+ return new this(input.key, input.key_id);
80
+ }
81
+ /**
82
+ * Initialize the GitHub sodium sealer with the {@linkcode Response} from get GitHub secret public key via the GitHub REST API.
83
+ * @param {Response} input {@linkcode Response}.
84
+ * @returns {Promise<GitHubSodiumSealer>} GitHub sodium sealer.
85
+ */
86
+ static async fromResponse(input) {
87
+ const responsePayload = await input.clone().json();
88
+ if (!isJSONObject(responsePayload)) {
89
+ throw new Error(`Parameter \`input\` is not a valid response!`);
90
+ }
91
+ return GitHubSodiumSealer.fromJSON(responsePayload);
92
+ }
93
+ /**
94
+ * Encrypt value to the GitHub secret value.
95
+ * @param {string} publicKey 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.
96
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
97
+ * @returns {string} An encrypted GitHub secret value.
98
+ * @deprecated Migrate to `new GitHubSodiumSealer(publicKey).encrypt(value)`.
99
+ */
100
+ static seal(publicKey, value) {
101
+ return new this(publicKey).encrypt(value);
102
+ }
103
+ }
104
+ export default GitHubSodiumSealer;
105
+ /**
106
+ * Encrypt value to the GitHub secret value.
107
+ * @param {string} publicKey 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.
108
+ * @param {string} value Value that need to encrypt as the GitHub secret value.
109
+ * @returns {string} An encrypted GitHub secret value.
110
+ * @deprecated Migrate to `new GitHubSodiumSealer(publicKey).encrypt(value)`.
111
+ */
112
+ export function seal(publicKey, value) {
113
+ return new GitHubSodiumSealer(publicKey).encrypt(value);
114
+ }
package/package.json CHANGED
@@ -1,47 +1,40 @@
1
1
  {
2
2
  "name": "@hugoalh/github-sodium",
3
- "version": "5.0.3",
4
- "description": "A module to provide an easier sodium for GitHub secrets.",
3
+ "version": "5.1.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-studio/github-sodium-es#readme",
9
+ "homepage": "https://github.com/hugoalh/github-sodium-es#readme",
10
10
  "bugs": {
11
- "url": "https://github.com/hugoalh-studio/github-sodium-es/issues"
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
- "main": "./dist/mod.js",
16
+ "main": "./mod.js",
17
+ "module": "./mod.js",
26
18
  "exports": {
27
- "types": "./dist/mod.d.ts",
28
- "import": "./dist/mod.js"
19
+ ".": {
20
+ "import": {
21
+ "types": "./mod.d.ts",
22
+ "default": "./mod.js"
23
+ }
24
+ }
29
25
  },
30
- "types": "./dist/mod.d.ts",
26
+ "types": "./mod.d.ts",
31
27
  "repository": {
32
28
  "type": "git",
33
- "url": "git+https://github.com/hugoalh-studio/github-sodium-es.git"
34
- },
35
- "scripts": {
36
- "build": "tsc"
29
+ "url": "git+https://github.com/hugoalh/github-sodium-es.git"
37
30
  },
31
+ "scripts": {},
38
32
  "dependencies": {
39
- "libsodium-wrappers": "0.7.13"
33
+ "@hugoalh/is-json": "^1.0.4",
34
+ "libsodium-wrappers": "^0.7.15"
40
35
  },
41
36
  "devDependencies": {
42
- "@types/libsodium-wrappers": "0.7.14",
43
- "@types/node": "20.12.7",
44
- "typescript": "^5.4.5"
37
+ "@types/node": "^20.9.0"
45
38
  },
46
39
  "engines": {
47
40
  "node": ">=16.13.0"
@@ -49,5 +42,6 @@
49
42
  "private": false,
50
43
  "publishConfig": {
51
44
  "access": "public"
52
- }
53
- }
45
+ },
46
+ "_generatedBy": "dnt@dev"
47
+ }
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
- }