@chamesh2020/keystone 0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 chames
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # @chamesh2020/keystone
2
+
3
+ A Zero-Knowledge Secret Vault CLI tool and SDK built with TypeScript.
4
+
5
+ Keystone allows you to store and retrieve application secrets securely. It employs **hybrid encryption (AES-256-GCM + RSA-OAEP envelope)** to encrypt all secrets locally before transmitting them to the server. The server only sees encrypted ciphertext, ensuring that your raw secrets and private keys are never exposed.
6
+
7
+ ## Features
8
+
9
+ - **Zero-Knowledge Architecture:** Cryptographic keys are generated and stored locally. Encryption and decryption occur entirely client-side.
10
+ - **Hybrid Cryptography:** Combines the speed and size-limitless flexibility of AES-256-GCM with the secure key distribution of RSA-OAEP.
11
+ - **Secure by Default:** Generated credentials files are locked down with `0o600` permissions (read/write only by owner) and automatically added to `.gitignore` and `.npmignore`.
12
+ - **Dotenv Integration:** Automatically loads your `.env` files and resolves placeholders (e.g., `LOAD_FROM_KEYSTONE`) dynamically from the Keystone vault at runtime.
13
+ - **Programmatic & CLI Access:** Fully-featured CLI tool and Node.js SDK.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ Install globally via npm:
20
+
21
+ ```bash
22
+ npm install -g @chamesh2020/keystone
23
+ ```
24
+
25
+ Or run it directly without installing using `npx`:
26
+
27
+ ```bash
28
+ npx @chamesh2020/keystone --help
29
+ ```
30
+
31
+ ---
32
+
33
+ ## CLI Usage
34
+
35
+ ### 1. Initialize a Project
36
+
37
+ Initialize your project, generate local cryptographic keys, and register the project on the server:
38
+
39
+ ```bash
40
+ keystone init <projectId>
41
+ ```
42
+
43
+ - **What it does:**
44
+ - Generates an Ed25519 key pair for authenticating requests and an RSA-OAEP key pair for encryption/decryption.
45
+ - Stores the keys locally at `.keystone/project-credentials.json` with secure file permissions (`chmod 600`).
46
+ - Registers your public keys on the Keystone server.
47
+ - Automatically appends `.keystone` to your `.gitignore` and `.npmignore` files to prevent committing credentials.
48
+
49
+ ### 2. Store a Secret
50
+
51
+ Store an encrypted secret on the server:
52
+
53
+ ```bash
54
+ keystone set <secretName> [secretValue]
55
+ ```
56
+
57
+ _Alias: `keystone store`, `keystone add`_
58
+
59
+ - If `secretValue` is omitted and the terminal is interactive (TTY), you will be securely prompted to type it.
60
+ - If the terminal is non-interactive, it will read from `stdin`. This allows piping values:
61
+ ```bash
62
+ cat password.txt | keystone set MY_DB_PASSWORD
63
+ ```
64
+ - **Automatic `.env` Update:** Storing a secret automatically appends or updates the key-value pair in your local `.env` file (or equivalent, e.g., `.env.local`, `.env.development`, `.env.dev`) with the `LOAD_FROM_KEYSTONE` placeholder, ensuring it is ready for programmatic resolution.
65
+
66
+ ### 3. Retrieve a Secret
67
+
68
+ Retrieve and decrypt a secret:
69
+
70
+ ```bash
71
+ keystone get <secretName>
72
+ ```
73
+
74
+ _Alias: `keystone retrieve`_
75
+
76
+ - Decrypts the secret locally using your RSA private key.
77
+ - Prints **only** the raw decrypted secret value to `stdout` (with all logging/errors sent to `stderr`), allowing for clean pipes:
78
+ ```bash
79
+ export DB_PASSWORD=$(keystone get MY_DB_PASSWORD)
80
+ ```
81
+
82
+ ### Global Options
83
+
84
+ - `-c, --credentials <path>`: Path to credentials file (defaults to `.keystone/project-credentials.json` or `KEYSTONE_CREDENTIALS` env variable).
85
+ - `-u, --url <url>`: Base URL of the Keystone server (defaults to `https://keystone.chames.dev` or `KEYSTONE_URL` env variable).
86
+ - `-h, --help`: Show help text.
87
+ - `-v, --version`: Show version number.
88
+
89
+ ---
90
+
91
+ ## Programmatic SDK Integration
92
+
93
+ You can integrate Keystone into your Node.js/TypeScript applications to load secrets dynamically at runtime.
94
+
95
+ ### Dynamic `.env` Integration
96
+
97
+ Add placeholders to your `.env` (or `.env.local`, `.env.production`) file:
98
+
99
+ ```env
100
+ # .env
101
+ PORT=3000
102
+ DATABASE_URL=LOAD_FROM_KEYSTONE
103
+ API_CLIENT_SECRET=LOAD_FROM_KEYSTONE
104
+ ```
105
+
106
+ Then, call `loadSecrets` early in your application's entrypoint:
107
+
108
+ ```typescript
109
+ import { loadSecrets } from "@chamesh2020/keystone";
110
+
111
+ async function bootstrap() {
112
+ // 1. Reads standard .env files
113
+ // 2. Fetches & decrypts marked secrets from the Keystone vault
114
+ // 3. Injects them directly into process.env
115
+ await loadSecrets();
116
+
117
+ console.log(process.env.DATABASE_URL); // => "postgres://..."
118
+ }
119
+
120
+ bootstrap();
121
+ ```
122
+
123
+ `loadSecrets` (and its snake_case alias `load_secrets`) accepts an optional options object:
124
+
125
+ ```typescript
126
+ await loadSecrets({
127
+ credentialsPath: "./custom/path/credentials.json",
128
+ baseUrl: "https://custom-keystone-server.com",
129
+ cwd: process.cwd(),
130
+ });
131
+ ```
132
+
133
+ ### Low-Level Cryptography & API Client
134
+
135
+ For custom workflows, you can import the cryptographic and network clients directly:
136
+
137
+ ```typescript
138
+ import {
139
+ generateProjectKeys,
140
+ encryptSecret,
141
+ decryptSecret,
142
+ initProject,
143
+ storeSecret,
144
+ retrieveSecret,
145
+ } from "@chamesh2020/keystone";
146
+
147
+ // Generate keys programmatically
148
+ const keys = await generateProjectKeys("my-custom-project");
149
+
150
+ // Encrypt locally
151
+ const ciphertext = await encryptSecret(
152
+ "my-secret-payload",
153
+ keys.encryption.publicJwk,
154
+ );
155
+
156
+ // Decrypt locally
157
+ const decrypted = await decryptSecret(ciphertext, keys.encryption.privateJwk);
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Configuration Settings
163
+
164
+ You can configure Keystone using the following environment variables:
165
+
166
+ | Environment Variable | Description | Default |
167
+ | ---------------------- | --------------------------------------------- | ------------------------------------ |
168
+ | `KEYSTONE_URL` | Base URL of the backend Keystone API | `https://keystone.chames.dev` |
169
+ | `KEYSTONE_CREDENTIALS` | Path to the JSON file containing project keys | `.keystone/project-credentials.json` |
170
+
171
+ ---
172
+
173
+ ## Development & Testing
174
+
175
+ To set up Keystone locally for development:
176
+
177
+ ```bash
178
+ # Install dependencies
179
+ npm install
180
+
181
+ # Build the project
182
+ npm run build
183
+
184
+ # Run in watch mode
185
+ npm run dev
186
+
187
+ # Run Vitest test suite
188
+ npm test
189
+
190
+ # Format code
191
+ npm run format
192
+
193
+ # Run linter
194
+ npm run lint
195
+
196
+ # Run TypeScript typechecks
197
+ npm run typecheck
198
+ ```
199
+
200
+ ---
201
+
202
+ ## License
203
+
204
+ MIT