unotoken 0.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.
Files changed (122) hide show
  1. package/README.md +360 -0
  2. package/dist/cli.d.ts +17 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +1207 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/client.d.ts +15 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/client.js +15 -0
  9. package/dist/client.js.map +1 -0
  10. package/dist/db.d.ts +52 -0
  11. package/dist/db.d.ts.map +1 -0
  12. package/dist/db.js +97 -0
  13. package/dist/db.js.map +1 -0
  14. package/dist/dotenv.d.ts +69 -0
  15. package/dist/dotenv.d.ts.map +1 -0
  16. package/dist/dotenv.js +115 -0
  17. package/dist/dotenv.js.map +1 -0
  18. package/dist/env-mapper.d.ts +55 -0
  19. package/dist/env-mapper.d.ts.map +1 -0
  20. package/dist/env-mapper.js +97 -0
  21. package/dist/env-mapper.js.map +1 -0
  22. package/dist/exec.d.ts +80 -0
  23. package/dist/exec.d.ts.map +1 -0
  24. package/dist/exec.js +214 -0
  25. package/dist/exec.js.map +1 -0
  26. package/dist/index.d.ts +12 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +43 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/oauth/commands.d.ts +151 -0
  31. package/dist/oauth/commands.d.ts.map +1 -0
  32. package/dist/oauth/commands.js +322 -0
  33. package/dist/oauth/commands.js.map +1 -0
  34. package/dist/oauth/config.d.ts +84 -0
  35. package/dist/oauth/config.d.ts.map +1 -0
  36. package/dist/oauth/config.js +156 -0
  37. package/dist/oauth/config.js.map +1 -0
  38. package/dist/oauth/crypto-helpers.d.ts +44 -0
  39. package/dist/oauth/crypto-helpers.d.ts.map +1 -0
  40. package/dist/oauth/crypto-helpers.js +94 -0
  41. package/dist/oauth/crypto-helpers.js.map +1 -0
  42. package/dist/oauth/device-secret.d.ts +57 -0
  43. package/dist/oauth/device-secret.d.ts.map +1 -0
  44. package/dist/oauth/device-secret.js +106 -0
  45. package/dist/oauth/device-secret.js.map +1 -0
  46. package/dist/oauth/flow.d.ts +112 -0
  47. package/dist/oauth/flow.d.ts.map +1 -0
  48. package/dist/oauth/flow.js +255 -0
  49. package/dist/oauth/flow.js.map +1 -0
  50. package/dist/oauth/index.d.ts +18 -0
  51. package/dist/oauth/index.d.ts.map +1 -0
  52. package/dist/oauth/index.js +24 -0
  53. package/dist/oauth/index.js.map +1 -0
  54. package/dist/oauth/key-wrap.d.ts +146 -0
  55. package/dist/oauth/key-wrap.d.ts.map +1 -0
  56. package/dist/oauth/key-wrap.js +275 -0
  57. package/dist/oauth/key-wrap.js.map +1 -0
  58. package/dist/oauth/pkce.d.ts +29 -0
  59. package/dist/oauth/pkce.d.ts.map +1 -0
  60. package/dist/oauth/pkce.js +34 -0
  61. package/dist/oauth/pkce.js.map +1 -0
  62. package/dist/oauth/provider.d.ts +79 -0
  63. package/dist/oauth/provider.d.ts.map +1 -0
  64. package/dist/oauth/provider.js +10 -0
  65. package/dist/oauth/provider.js.map +1 -0
  66. package/dist/oauth/providers/github.d.ts +75 -0
  67. package/dist/oauth/providers/github.d.ts.map +1 -0
  68. package/dist/oauth/providers/github.js +119 -0
  69. package/dist/oauth/providers/github.js.map +1 -0
  70. package/dist/oauth/providers/google.d.ts +115 -0
  71. package/dist/oauth/providers/google.d.ts.map +1 -0
  72. package/dist/oauth/providers/google.js +285 -0
  73. package/dist/oauth/providers/google.js.map +1 -0
  74. package/dist/sdk.d.ts +8 -0
  75. package/dist/sdk.d.ts.map +1 -0
  76. package/dist/sdk.js +8 -0
  77. package/dist/sdk.js.map +1 -0
  78. package/dist/server.d.ts +33 -0
  79. package/dist/server.d.ts.map +1 -0
  80. package/dist/server.js +287 -0
  81. package/dist/server.js.map +1 -0
  82. package/dist/signatures/approval-codes.d.ts +192 -0
  83. package/dist/signatures/approval-codes.d.ts.map +1 -0
  84. package/dist/signatures/approval-codes.js +407 -0
  85. package/dist/signatures/approval-codes.js.map +1 -0
  86. package/dist/signatures/commands.d.ts +108 -0
  87. package/dist/signatures/commands.d.ts.map +1 -0
  88. package/dist/signatures/commands.js +270 -0
  89. package/dist/signatures/commands.js.map +1 -0
  90. package/dist/signatures/devices.d.ts +165 -0
  91. package/dist/signatures/devices.d.ts.map +1 -0
  92. package/dist/signatures/devices.js +344 -0
  93. package/dist/signatures/devices.js.map +1 -0
  94. package/dist/signatures/email-config.d.ts +102 -0
  95. package/dist/signatures/email-config.d.ts.map +1 -0
  96. package/dist/signatures/email-config.js +188 -0
  97. package/dist/signatures/email-config.js.map +1 -0
  98. package/dist/signatures/email.d.ts +106 -0
  99. package/dist/signatures/email.d.ts.map +1 -0
  100. package/dist/signatures/email.js +180 -0
  101. package/dist/signatures/email.js.map +1 -0
  102. package/dist/signatures/fingerprint.d.ts +70 -0
  103. package/dist/signatures/fingerprint.d.ts.map +1 -0
  104. package/dist/signatures/fingerprint.js +123 -0
  105. package/dist/signatures/fingerprint.js.map +1 -0
  106. package/dist/signatures/guard.d.ts +118 -0
  107. package/dist/signatures/guard.d.ts.map +1 -0
  108. package/dist/signatures/guard.js +310 -0
  109. package/dist/signatures/guard.js.map +1 -0
  110. package/dist/signatures/resend.d.ts +84 -0
  111. package/dist/signatures/resend.d.ts.map +1 -0
  112. package/dist/signatures/resend.js +248 -0
  113. package/dist/signatures/resend.js.map +1 -0
  114. package/dist/token-requests.d.ts +80 -0
  115. package/dist/token-requests.d.ts.map +1 -0
  116. package/dist/token-requests.js +201 -0
  117. package/dist/token-requests.js.map +1 -0
  118. package/dist/tokens.d.ts +80 -0
  119. package/dist/tokens.d.ts.map +1 -0
  120. package/dist/tokens.js +150 -0
  121. package/dist/tokens.js.map +1 -0
  122. package/package.json +62 -0
package/README.md ADDED
@@ -0,0 +1,360 @@
1
+ # unotoken
2
+
3
+ **yokotoken + cloud features.**
4
+
5
+ unotoken is a private extension of [yokotoken](https://github.com/indigoai-us/yokotoken), the agent-native encrypted credential vault. It adds cloud features on top of the open-source MIT core:
6
+
7
+ - **OAuth unlock** -- Sign in with Google or GitHub to unlock your vault (no passphrase needed)
8
+ - **Device signatures** -- New devices must be approved via email code before accessing the vault
9
+ - **Team vaults** -- Share encrypted vaults across a team (coming soon)
10
+ - **Key escrow** -- Recovery keys held by your organization (coming soon)
11
+
12
+ ## How it works
13
+
14
+ unotoken depends on `yokotoken` as an npm package. All of yokotoken's public API is re-exported, so unotoken is a drop-in replacement:
15
+
16
+ ```ts
17
+ // Before
18
+ import { getSecret } from 'yokotoken/sdk';
19
+ import { NetworkVaultClient } from 'yokotoken/client';
20
+
21
+ // After (identical API)
22
+ import { getSecret } from 'unotoken/sdk';
23
+ import { NetworkVaultClient } from 'unotoken/client';
24
+ ```
25
+
26
+ The CLI wraps yokotoken and adds new commands:
27
+
28
+ ```bash
29
+ # All yokotoken commands work as-is
30
+ unotoken init
31
+ unotoken serve
32
+ unotoken unlock
33
+ unotoken set my/secret "value"
34
+ unotoken get my/secret
35
+
36
+ # New: OAuth commands
37
+ unotoken auth link google # Link Google account for passwordless unlock
38
+ unotoken auth link github # Link GitHub account
39
+ unotoken auth list # Show linked providers
40
+ unotoken auth unlink google # Remove a linked provider
41
+ unotoken auth config --show # View OAuth configuration
42
+ ```
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ npm install unotoken
48
+ ```
49
+
50
+ Or for CLI usage:
51
+
52
+ ```bash
53
+ npm install -g unotoken
54
+ ```
55
+
56
+ ## Package exports
57
+
58
+ | Import path | Description |
59
+ |-------------|-------------|
60
+ | `unotoken` | Full vault API (re-exports `yokotoken`) |
61
+ | `unotoken/sdk` | Worker SDK for agent access (re-exports `yokotoken/sdk`) |
62
+ | `unotoken/client` | Network client for remote vaults (re-exports `yokotoken/client`) |
63
+
64
+ ## Development
65
+
66
+ ```bash
67
+ npm install
68
+ npm run typecheck
69
+ npm test
70
+ npm run build
71
+ ```
72
+
73
+ ## Build-Time Env Injection
74
+
75
+ unotoken replaces `.env` files with vault-backed secrets. Two modes:
76
+
77
+ ### exec -- inject secrets into a child process
78
+
79
+ No `.env` file needed. Secrets are injected as environment variables directly:
80
+
81
+ ```bash
82
+ # Run your app with vault secrets injected
83
+ unotoken exec --prefix myapp/ -- npm run dev
84
+
85
+ # In package.json:
86
+ "scripts": {
87
+ "dev": "unotoken exec --prefix myapp/ -- next dev",
88
+ "build": "unotoken exec --prefix myapp/ -- next build"
89
+ }
90
+ ```
91
+
92
+ Path mapping: `myapp/stripe/secret/key` becomes `STRIPE_SECRET_KEY`.
93
+
94
+ ### dotenv -- generate .env files from vault
95
+
96
+ For tools that require a `.env` file on disk:
97
+
98
+ ```bash
99
+ # Generate .env.local from vault
100
+ unotoken dotenv --prefix myapp/ --out .env.local
101
+
102
+ # Clean up after build (CI/CD)
103
+ unotoken dotenv --clean .env.local
104
+ ```
105
+
106
+ ### Scoped tokens
107
+
108
+ Create tokens that only access specific prefixes:
109
+
110
+ ```bash
111
+ # Create a token restricted to myapp/* secrets
112
+ unotoken token create --name myapp-ci --prefix myapp/
113
+
114
+ # Multi-prefix tokens
115
+ unotoken token create --name shared --prefix myapp/ --prefix common/
116
+ ```
117
+
118
+ ### Real-app demo (levelfit)
119
+
120
+ A hands-on demo script walks through the complete flow using real secrets:
121
+
122
+ ```bash
123
+ bash scripts/demo-levelfit.sh
124
+ ```
125
+
126
+ The demo covers:
127
+ 1. **Scoped token creation** -- create a token restricted to `levelfit/*`
128
+ 2. **Access verification** -- confirm the token can access `levelfit/` but not other prefixes
129
+ 3. **exec injection** -- run a process with vault secrets as env vars (no file on disk)
130
+ 4. **dotenv generation** -- produce a `.env` file equivalent to a hand-maintained `.env.local`
131
+ 5. **Cleanup** -- remove generated files and revoke demo tokens
132
+
133
+ Prerequisites: vault running (`unotoken serve`), vault unlocked (`unotoken unlock`), secrets stored under `levelfit/` prefix.
134
+
135
+ ## Package.json Scripts Integration
136
+
137
+ Replace `.env` files with vault-backed secrets in your npm scripts. Here are before/after patterns for common setups.
138
+
139
+ ### Next.js
140
+
141
+ **Before (.env.local on disk):**
142
+
143
+ ```json
144
+ {
145
+ "scripts": {
146
+ "dev": "next dev",
147
+ "build": "next build",
148
+ "start": "next start"
149
+ }
150
+ }
151
+ ```
152
+
153
+ **After (vault-backed):**
154
+
155
+ ```json
156
+ {
157
+ "scripts": {
158
+ "dev": "unotoken exec --prefix myapp/ -- next dev",
159
+ "build": "unotoken exec --prefix myapp/ -- next build",
160
+ "start": "unotoken exec --prefix myapp/ -- next start"
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Vite
166
+
167
+ **Before:**
168
+
169
+ ```json
170
+ {
171
+ "scripts": {
172
+ "dev": "vite",
173
+ "build": "vite build",
174
+ "preview": "vite preview"
175
+ }
176
+ }
177
+ ```
178
+
179
+ **After:**
180
+
181
+ ```json
182
+ {
183
+ "scripts": {
184
+ "dev": "unotoken exec --prefix myapp/ -- vite",
185
+ "build": "unotoken exec --prefix myapp/ -- vite build",
186
+ "preview": "unotoken exec --prefix myapp/ -- vite preview"
187
+ }
188
+ }
189
+ ```
190
+
191
+ ### Node.js API Server
192
+
193
+ **Before:**
194
+
195
+ ```json
196
+ {
197
+ "scripts": {
198
+ "dev": "tsx watch src/server.ts",
199
+ "start": "node dist/server.js"
200
+ }
201
+ }
202
+ ```
203
+
204
+ **After:**
205
+
206
+ ```json
207
+ {
208
+ "scripts": {
209
+ "dev": "unotoken exec --prefix myapi/ -- tsx watch src/server.ts",
210
+ "start": "unotoken exec --prefix myapi/ -- node dist/server.js"
211
+ }
212
+ }
213
+ ```
214
+
215
+ ### CI/CD (GitHub Actions)
216
+
217
+ Use `UNOTOKEN_TOKEN` and `UNOTOKEN_URL` environment variables for remote vault access:
218
+
219
+ ```yaml
220
+ # .github/workflows/deploy.yml
221
+ jobs:
222
+ build:
223
+ runs-on: ubuntu-latest
224
+ steps:
225
+ - uses: actions/checkout@v4
226
+ - uses: actions/setup-node@v4
227
+ with:
228
+ node-version: 22
229
+ - run: npm ci
230
+ - name: Build with vault secrets
231
+ env:
232
+ UNOTOKEN_TOKEN: ${{ secrets.VAULT_TOKEN }}
233
+ UNOTOKEN_URL: https://vault.example.com:13100
234
+ run: unotoken exec --prefix myapp/ -- npm run build
235
+ ```
236
+
237
+ Or as a single inline command:
238
+
239
+ ```bash
240
+ UNOTOKEN_TOKEN=${{ secrets.VAULT_TOKEN }} UNOTOKEN_URL=https://vault.example.com unotoken exec --prefix myapp/ -- npm run build
241
+ ```
242
+
243
+ ### Fallback Pattern
244
+
245
+ If the vault might be unavailable (e.g., a new team member who hasn't set up the vault yet), use a fallback to `.env.local`:
246
+
247
+ ```json
248
+ {
249
+ "scripts": {
250
+ "dev": "unotoken exec --prefix myapp/ -- next dev || (echo 'Vault unavailable, using .env.local fallback' && next dev)",
251
+ "build": "unotoken exec --prefix myapp/ -- next build || (echo 'Vault unavailable, using .env.local fallback' && next build)"
252
+ }
253
+ }
254
+ ```
255
+
256
+ This runs with vault secrets when available, and falls back to any `.env.local` file on disk when the vault is locked or unreachable.
257
+
258
+ ## Moving from .env to unotoken
259
+
260
+ A step-by-step migration guide for replacing hand-maintained `.env` files with vault-backed secrets.
261
+
262
+ ### Step 1: Import existing secrets into the vault
263
+
264
+ ```bash
265
+ # Start the vault if not running
266
+ unotoken serve &
267
+ unotoken unlock
268
+
269
+ # Import each secret from your .env.local
270
+ unotoken set myapp/database/url "postgresql://user:pass@host/db"
271
+ unotoken set myapp/stripe/secret/key "sk_live_..."
272
+ unotoken set myapp/next/public/stripe/publishable/key "pk_live_..."
273
+
274
+ # Or bulk-import from a .env file (one per line)
275
+ while IFS='=' read -r key value; do
276
+ # Convert KEY_NAME to key/name path format
277
+ path=$(echo "$key" | tr '[:upper:]' '[:lower:]' | tr '_' '/')
278
+ unotoken set "myapp/$path" "$value"
279
+ done < .env.local
280
+ ```
281
+
282
+ ### Step 2: Create a scoped token
283
+
284
+ ```bash
285
+ # Create a token restricted to your app's prefix
286
+ unotoken token create --name myapp-dev --prefix myapp/
287
+
288
+ # Save the displayed token -- it's only shown once
289
+ # For CI/CD, store it as a GitHub Actions secret (VAULT_TOKEN)
290
+ ```
291
+
292
+ ### Step 3: Update package.json scripts
293
+
294
+ Replace direct commands with `unotoken exec`:
295
+
296
+ ```diff
297
+ {
298
+ "scripts": {
299
+ - "dev": "next dev",
300
+ - "build": "next build"
301
+ + "dev": "unotoken exec --prefix myapp/ -- next dev",
302
+ + "build": "unotoken exec --prefix myapp/ -- next build"
303
+ }
304
+ }
305
+ ```
306
+
307
+ ### Step 4: Update .gitignore
308
+
309
+ If using `dotenv` mode (generating `.env.local` from the vault), add the generated file to `.gitignore` since it's now a build artifact:
310
+
311
+ ```gitignore
312
+ # Generated by unotoken (vault-backed, not hand-maintained)
313
+ .env.local
314
+ ```
315
+
316
+ ### Step 5: Remove .env.local
317
+
318
+ Once you've verified everything works with vault-backed secrets:
319
+
320
+ ```bash
321
+ # Verify vault injection works
322
+ npm run dev # should start with all env vars injected
323
+
324
+ # Remove the old .env.local
325
+ rm .env.local
326
+ ```
327
+
328
+ ### Path-to-Variable Mapping Reference
329
+
330
+ Vault paths are converted to environment variable names by:
331
+ 1. Stripping the prefix (e.g., `myapp/`)
332
+ 2. Replacing `/` with `_`
333
+ 3. Uppercasing the result
334
+
335
+ | Vault Path | Env Variable |
336
+ |------------|-------------|
337
+ | `myapp/stripe/secret/key` | `STRIPE_SECRET_KEY` |
338
+ | `myapp/database/url` | `DATABASE_URL` |
339
+ | `myapp/next/public/stripe/publishable/key` | `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` |
340
+ | `myapp/resend/api/key` | `RESEND_API_KEY` |
341
+
342
+ ## Architecture
343
+
344
+ ```
345
+ yokotoken (MIT, public)
346
+ |
347
+ +-- unotoken (private, cloud add-on)
348
+ |-- Re-exports all yokotoken API
349
+ |-- OAuth PKCE browser flow engine
350
+ |-- Google + GitHub OIDC/OAuth providers
351
+ |-- Wrapped key storage for OAuth-derived unlock
352
+ |-- Device signatures (email-verified device approval)
353
+ |-- CLI extensions (auth link, auth unlink, auth list, auth config)
354
+ ```
355
+
356
+ Upstream updates are clean: just bump the `yokotoken` version in `package.json`.
357
+
358
+ ## License
359
+
360
+ UNLICENSED (private)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * unotoken CLI — yokotoken + cloud features.
4
+ *
5
+ * Wraps the yokotoken CLI and extends it with OAuth-related commands:
6
+ * - auth link <provider> Link an OAuth identity for passwordless unlock
7
+ * - auth unlink <provider> Remove an OAuth identity link
8
+ * - auth list List linked OAuth providers
9
+ * - auth config Configure custom OAuth client credentials
10
+ * - unlock --oauth Unlock the vault using linked OAuth identity
11
+ * - config email <address> Register and verify email for device signatures
12
+ * - device guard check on all vault operations (unlock, get, set, list)
13
+ *
14
+ * All other commands are delegated to the underlying yokotoken CLI.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;GAaG"}