@fgv/ts-extras 5.1.0-17 → 5.1.0-19
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/dist/packlets/ai-assist/apiClient.js +247 -24
- package/dist/packlets/ai-assist/index.js +1 -1
- package/dist/packlets/ai-assist/registry.js +49 -4
- package/dist/packlets/crypto-utils/index.browser.js +2 -0
- package/dist/packlets/crypto-utils/index.js +2 -0
- package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js +47 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +101 -9
- package/dist/packlets/crypto-utils/keystore/index.js +1 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +271 -46
- package/dist/packlets/crypto-utils/keystore/model.js +22 -1
- package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js +21 -0
- package/dist/packlets/crypto-utils/model.js +5 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +140 -1
- package/dist/test/unit/crypto/keystore/inMemoryPrivateKeyStorage.js +78 -0
- package/dist/ts-extras.d.ts +799 -40
- package/lib/packlets/ai-assist/apiClient.d.ts +11 -3
- package/lib/packlets/ai-assist/apiClient.js +245 -22
- package/lib/packlets/ai-assist/index.d.ts +2 -2
- package/lib/packlets/ai-assist/index.js +3 -1
- package/lib/packlets/ai-assist/model.d.ts +66 -5
- package/lib/packlets/ai-assist/registry.d.ts +25 -1
- package/lib/packlets/ai-assist/registry.js +51 -4
- package/lib/packlets/crypto-utils/index.browser.d.ts +1 -0
- package/lib/packlets/crypto-utils/index.browser.js +4 -1
- package/lib/packlets/crypto-utils/index.d.ts +1 -0
- package/lib/packlets/crypto-utils/index.js +4 -1
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts +39 -0
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js +50 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +68 -6
- package/lib/packlets/crypto-utils/keystore/converters.js +100 -8
- package/lib/packlets/crypto-utils/keystore/index.d.ts +1 -0
- package/lib/packlets/crypto-utils/keystore/index.js +1 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +77 -9
- package/lib/packlets/crypto-utils/keystore/keyStore.js +271 -46
- package/lib/packlets/crypto-utils/keystore/model.d.ts +238 -19
- package/lib/packlets/crypto-utils/keystore/model.js +24 -2
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts +50 -0
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js +22 -0
- package/lib/packlets/crypto-utils/model.d.ts +130 -0
- package/lib/packlets/crypto-utils/model.js +6 -1
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +45 -1
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +139 -0
- package/package.json +7 -7
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { EncryptionAlgorithm, ICryptoProvider, IKeyDerivationParams } from '../model';
|
|
1
|
+
import { EncryptionAlgorithm, ICryptoProvider, IKeyDerivationParams, KeyPairAlgorithm } from '../model';
|
|
2
|
+
import { IPrivateKeyStorage } from './privateKeyStorage';
|
|
3
|
+
export { allKeyPairAlgorithms, KeyPairAlgorithm } from '../model';
|
|
2
4
|
/**
|
|
3
5
|
* Format version for key store files.
|
|
4
6
|
* @public
|
|
@@ -21,31 +23,55 @@ export declare const DEFAULT_KEYSTORE_ITERATIONS: number;
|
|
|
21
23
|
*/
|
|
22
24
|
export declare const MIN_SALT_LENGTH: number;
|
|
23
25
|
/**
|
|
24
|
-
* Discriminator for secret types stored in the vault.
|
|
26
|
+
* Discriminator for symmetric secret types stored in the vault.
|
|
25
27
|
* - `'encryption-key'`: A 32-byte AES-256 encryption key.
|
|
26
28
|
* - `'api-key'`: An arbitrary-length API key string (UTF-8 encoded).
|
|
27
29
|
* @public
|
|
28
30
|
*/
|
|
29
|
-
export type
|
|
31
|
+
export type KeyStoreSymmetricSecretType = 'encryption-key' | 'api-key';
|
|
32
|
+
/**
|
|
33
|
+
* All valid symmetric secret types.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const allKeyStoreSymmetricSecretTypes: ReadonlyArray<KeyStoreSymmetricSecretType>;
|
|
37
|
+
/**
|
|
38
|
+
* Discriminator for asymmetric secret types stored in the vault.
|
|
39
|
+
* - `'asymmetric-keypair'`: A public/private key pair. The public key is held in
|
|
40
|
+
* the vault as a JWK; the private key lives in the supplied
|
|
41
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export type KeyStoreAsymmetricSecretType = 'asymmetric-keypair';
|
|
45
|
+
/**
|
|
46
|
+
* All valid asymmetric secret types.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare const allKeyStoreAsymmetricSecretTypes: ReadonlyArray<KeyStoreAsymmetricSecretType>;
|
|
50
|
+
/**
|
|
51
|
+
* Discriminator for any secret type stored in the vault.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export type KeyStoreSecretType = KeyStoreSymmetricSecretType | KeyStoreAsymmetricSecretType;
|
|
30
55
|
/**
|
|
31
56
|
* All valid key store secret types.
|
|
32
57
|
* @public
|
|
33
58
|
*/
|
|
34
59
|
export declare const allKeyStoreSecretTypes: ReadonlyArray<KeyStoreSecretType>;
|
|
35
60
|
/**
|
|
36
|
-
* A secret entry stored in the vault (in-memory representation).
|
|
61
|
+
* A symmetric secret entry stored in the vault (in-memory representation).
|
|
62
|
+
* Holds the raw key material directly — for `'encryption-key'` it is a 32-byte
|
|
63
|
+
* AES-256 key; for `'api-key'` it is the UTF-8 encoded API key string.
|
|
37
64
|
* @public
|
|
38
65
|
*/
|
|
39
|
-
export interface
|
|
66
|
+
export interface IKeyStoreSymmetricEntry {
|
|
40
67
|
/**
|
|
41
68
|
* Unique name for this secret (used as lookup key).
|
|
42
69
|
*/
|
|
43
70
|
readonly name: string;
|
|
44
71
|
/**
|
|
45
|
-
*
|
|
46
|
-
* Defaults to `'encryption-key'` for backwards compatibility.
|
|
72
|
+
* Symmetric secret type discriminator.
|
|
47
73
|
*/
|
|
48
|
-
readonly type:
|
|
74
|
+
readonly type: KeyStoreSymmetricSecretType;
|
|
49
75
|
/**
|
|
50
76
|
* The secret data.
|
|
51
77
|
* - For `'encryption-key'`: 32-byte AES-256 key.
|
|
@@ -62,19 +88,83 @@ export interface IKeyStoreSecretEntry {
|
|
|
62
88
|
readonly createdAt: string;
|
|
63
89
|
}
|
|
64
90
|
/**
|
|
65
|
-
*
|
|
91
|
+
* An asymmetric keypair entry stored in the vault (in-memory representation).
|
|
92
|
+
* Holds only the public key (as a JWK) and a stable handle (`id`) the
|
|
93
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider uses to fetch the private key.
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export interface IKeyStoreAsymmetricEntry {
|
|
97
|
+
/**
|
|
98
|
+
* Unique name for this entry (used as vault lookup key, renameable).
|
|
99
|
+
*/
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Asymmetric secret type discriminator.
|
|
103
|
+
*/
|
|
104
|
+
readonly type: KeyStoreAsymmetricSecretType;
|
|
105
|
+
/**
|
|
106
|
+
* Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
|
|
107
|
+
* private key. Independent of `name`; survives renames.
|
|
108
|
+
*/
|
|
109
|
+
readonly id: string;
|
|
110
|
+
/**
|
|
111
|
+
* Algorithm used to generate this keypair.
|
|
112
|
+
*/
|
|
113
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
114
|
+
/**
|
|
115
|
+
* The public key as a JSON Web Key.
|
|
116
|
+
*/
|
|
117
|
+
readonly publicKeyJwk: JsonWebKey;
|
|
118
|
+
/**
|
|
119
|
+
* Optional description for this entry.
|
|
120
|
+
*/
|
|
121
|
+
readonly description?: string;
|
|
122
|
+
/**
|
|
123
|
+
* When this entry was added (ISO 8601).
|
|
124
|
+
*/
|
|
125
|
+
readonly createdAt: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Any vault entry, discriminated by `type`.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export type IKeyStoreEntry = IKeyStoreSymmetricEntry | IKeyStoreAsymmetricEntry;
|
|
132
|
+
/**
|
|
133
|
+
* Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry}.
|
|
134
|
+
* @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry} for symmetric
|
|
135
|
+
* entries or {@link CryptoUtils.KeyStore.IKeyStoreEntry} for the discriminated union.
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export type IKeyStoreSecretEntry = IKeyStoreSymmetricEntry;
|
|
139
|
+
/**
|
|
140
|
+
* JSON-serializable representation of a symmetric secret entry.
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* Describes the *normalized* shape after parsing. `type` is required here
|
|
144
|
+
* because the converter (see
|
|
145
|
+
* {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson})
|
|
146
|
+
* injects the default `'encryption-key'` when reading vaults written before
|
|
147
|
+
* asymmetric-keypair support added the discriminator. Raw on-wire bytes from
|
|
148
|
+
* a legacy vault may therefore omit `type`; downstream code only ever sees
|
|
149
|
+
* the post-conversion shape declared here.
|
|
150
|
+
*
|
|
66
151
|
* @public
|
|
67
152
|
*/
|
|
68
|
-
export interface
|
|
153
|
+
export interface IKeyStoreSymmetricEntryJson {
|
|
69
154
|
/**
|
|
70
155
|
* Unique name for this secret.
|
|
71
156
|
*/
|
|
72
157
|
readonly name: string;
|
|
73
158
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
159
|
+
* Symmetric secret type discriminator.
|
|
160
|
+
*
|
|
161
|
+
* Required on this normalized model type. Vaults written prior to the
|
|
162
|
+
* asymmetric-keypair support may omit this field on the wire; the
|
|
163
|
+
* converter injects `'encryption-key'` when missing for backwards
|
|
164
|
+
* compatibility, so by the time a value of this type is observed the
|
|
165
|
+
* discriminator is always present.
|
|
76
166
|
*/
|
|
77
|
-
readonly type
|
|
167
|
+
readonly type: KeyStoreSymmetricSecretType;
|
|
78
168
|
/**
|
|
79
169
|
* Base64-encoded secret data.
|
|
80
170
|
*/
|
|
@@ -89,7 +179,57 @@ export interface IKeyStoreSecretEntryJson {
|
|
|
89
179
|
readonly createdAt: string;
|
|
90
180
|
}
|
|
91
181
|
/**
|
|
92
|
-
*
|
|
182
|
+
* JSON-serializable representation of an asymmetric keypair entry.
|
|
183
|
+
* The private key is not present here — it lives in the
|
|
184
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider, addressed by `id`.
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
export interface IKeyStoreAsymmetricEntryJson {
|
|
188
|
+
/**
|
|
189
|
+
* Unique name for this entry.
|
|
190
|
+
*/
|
|
191
|
+
readonly name: string;
|
|
192
|
+
/**
|
|
193
|
+
* Asymmetric secret type discriminator.
|
|
194
|
+
*/
|
|
195
|
+
readonly type: KeyStoreAsymmetricSecretType;
|
|
196
|
+
/**
|
|
197
|
+
* Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
|
|
198
|
+
* private key.
|
|
199
|
+
*/
|
|
200
|
+
readonly id: string;
|
|
201
|
+
/**
|
|
202
|
+
* Algorithm used to generate this keypair.
|
|
203
|
+
*/
|
|
204
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
205
|
+
/**
|
|
206
|
+
* The public key as a JSON Web Key.
|
|
207
|
+
*/
|
|
208
|
+
readonly publicKeyJwk: JsonWebKey;
|
|
209
|
+
/**
|
|
210
|
+
* Optional description.
|
|
211
|
+
*/
|
|
212
|
+
readonly description?: string;
|
|
213
|
+
/**
|
|
214
|
+
* When this entry was added (ISO 8601).
|
|
215
|
+
*/
|
|
216
|
+
readonly createdAt: string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Any JSON vault entry, discriminated by `type`.
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export type IKeyStoreEntryJson = IKeyStoreSymmetricEntryJson | IKeyStoreAsymmetricEntryJson;
|
|
223
|
+
/**
|
|
224
|
+
* Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}.
|
|
225
|
+
* @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson} for
|
|
226
|
+
* symmetric entries or {@link CryptoUtils.KeyStore.IKeyStoreEntryJson} for the
|
|
227
|
+
* discriminated union.
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
export type IKeyStoreSecretEntryJson = IKeyStoreSymmetricEntryJson;
|
|
231
|
+
/**
|
|
232
|
+
* The decrypted vault contents - a versioned map of entries.
|
|
93
233
|
* @public
|
|
94
234
|
*/
|
|
95
235
|
export interface IKeyStoreVaultContents {
|
|
@@ -98,9 +238,9 @@ export interface IKeyStoreVaultContents {
|
|
|
98
238
|
*/
|
|
99
239
|
readonly version: KeyStoreFormat;
|
|
100
240
|
/**
|
|
101
|
-
* Map of
|
|
241
|
+
* Map of entry name to entry (symmetric or asymmetric).
|
|
102
242
|
*/
|
|
103
|
-
readonly secrets: Record<string,
|
|
243
|
+
readonly secrets: Record<string, IKeyStoreEntryJson>;
|
|
104
244
|
}
|
|
105
245
|
/**
|
|
106
246
|
* The encrypted key store file format.
|
|
@@ -150,6 +290,12 @@ export interface IKeyStoreCreateParams {
|
|
|
150
290
|
* PBKDF2 iterations (defaults to DEFAULT_KEYSTORE_ITERATIONS).
|
|
151
291
|
*/
|
|
152
292
|
readonly iterations?: number;
|
|
293
|
+
/**
|
|
294
|
+
* Optional private-key storage backend. Required to use `addKeyPair` /
|
|
295
|
+
* `getKeyPair`; absent backends still permit opening, listing, and reading
|
|
296
|
+
* public-key metadata for asymmetric entries.
|
|
297
|
+
*/
|
|
298
|
+
readonly privateKeyStorage?: IPrivateKeyStorage;
|
|
153
299
|
}
|
|
154
300
|
/**
|
|
155
301
|
* Parameters for opening an existing key store.
|
|
@@ -164,6 +310,12 @@ export interface IKeyStoreOpenParams {
|
|
|
164
310
|
* The encrypted key store file content.
|
|
165
311
|
*/
|
|
166
312
|
readonly keystoreFile: IKeyStoreFile;
|
|
313
|
+
/**
|
|
314
|
+
* Optional private-key storage backend. Required to use `addKeyPair` /
|
|
315
|
+
* `getKeyPair`; absent backends still permit opening, listing, and reading
|
|
316
|
+
* public-key metadata for asymmetric entries.
|
|
317
|
+
*/
|
|
318
|
+
readonly privateKeyStorage?: IPrivateKeyStorage;
|
|
167
319
|
}
|
|
168
320
|
/**
|
|
169
321
|
* Result of adding a secret to the key store.
|
|
@@ -173,11 +325,19 @@ export interface IAddSecretResult {
|
|
|
173
325
|
/**
|
|
174
326
|
* The secret entry that was added.
|
|
175
327
|
*/
|
|
176
|
-
readonly entry:
|
|
328
|
+
readonly entry: IKeyStoreSymmetricEntry;
|
|
177
329
|
/**
|
|
178
330
|
* Whether this replaced an existing secret.
|
|
179
331
|
*/
|
|
180
332
|
readonly replaced: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Best-effort warning from displaced-resource cleanup. Set when this call
|
|
335
|
+
* replaced an asymmetric-keypair entry but the corresponding
|
|
336
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
|
|
337
|
+
* entry is still committed and the orphaned blob is left for consumer-side
|
|
338
|
+
* GC to reconcile.
|
|
339
|
+
*/
|
|
340
|
+
readonly warning?: string;
|
|
181
341
|
}
|
|
182
342
|
/**
|
|
183
343
|
* Options for adding a secret.
|
|
@@ -206,10 +366,10 @@ export interface IImportSecretOptions extends IAddSecretOptions {
|
|
|
206
366
|
*/
|
|
207
367
|
export interface IImportKeyOptions extends IImportSecretOptions {
|
|
208
368
|
/**
|
|
209
|
-
*
|
|
369
|
+
* Symmetric secret type classification for the imported key material.
|
|
210
370
|
* @defaultValue 'encryption-key'
|
|
211
371
|
*/
|
|
212
|
-
readonly type?:
|
|
372
|
+
readonly type?: KeyStoreSymmetricSecretType;
|
|
213
373
|
}
|
|
214
374
|
/**
|
|
215
375
|
* Options for adding a secret derived from a password.
|
|
@@ -246,6 +406,65 @@ export interface IAddSecretFromPasswordResult extends IAddSecretResult {
|
|
|
246
406
|
*/
|
|
247
407
|
readonly keyDerivation: IKeyDerivationParams;
|
|
248
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Options for adding an asymmetric keypair to the key store.
|
|
411
|
+
* @public
|
|
412
|
+
*/
|
|
413
|
+
export interface IAddKeyPairOptions {
|
|
414
|
+
/**
|
|
415
|
+
* Algorithm to use for the new keypair.
|
|
416
|
+
*/
|
|
417
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
418
|
+
/**
|
|
419
|
+
* Optional description for the entry.
|
|
420
|
+
*/
|
|
421
|
+
readonly description?: string;
|
|
422
|
+
/**
|
|
423
|
+
* Whether to replace an existing entry with the same name.
|
|
424
|
+
* Replacement mints a fresh storage `id` and best-effort deletes the
|
|
425
|
+
* displaced storage blob; see the keystore design doc for details.
|
|
426
|
+
*/
|
|
427
|
+
readonly replace?: boolean;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Result of adding an asymmetric keypair to the key store.
|
|
431
|
+
* @public
|
|
432
|
+
*/
|
|
433
|
+
export interface IAddKeyPairResult {
|
|
434
|
+
/**
|
|
435
|
+
* The asymmetric entry that was added.
|
|
436
|
+
*/
|
|
437
|
+
readonly entry: IKeyStoreAsymmetricEntry;
|
|
438
|
+
/**
|
|
439
|
+
* Whether this replaced an existing entry.
|
|
440
|
+
*/
|
|
441
|
+
readonly replaced: boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Best-effort warning from displaced-resource cleanup. Set when this call
|
|
444
|
+
* replaced a prior entry but the corresponding
|
|
445
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
|
|
446
|
+
* keypair is still committed and the orphaned blob is left for consumer-side
|
|
447
|
+
* GC to reconcile.
|
|
448
|
+
*/
|
|
449
|
+
readonly warning?: string;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Result of removing a secret from the key store.
|
|
453
|
+
* @public
|
|
454
|
+
*/
|
|
455
|
+
export interface IRemoveSecretResult {
|
|
456
|
+
/**
|
|
457
|
+
* The secret entry that was removed from the vault.
|
|
458
|
+
*/
|
|
459
|
+
readonly entry: IKeyStoreEntry;
|
|
460
|
+
/**
|
|
461
|
+
* Best-effort warning from {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete
|
|
462
|
+
* for asymmetric entries when the storage call failed. The vault entry is
|
|
463
|
+
* still considered removed and the orphaned blob is left for consumer-side
|
|
464
|
+
* GC to reconcile.
|
|
465
|
+
*/
|
|
466
|
+
readonly warning?: string;
|
|
467
|
+
}
|
|
249
468
|
/**
|
|
250
469
|
* Checks if a JSON object appears to be a key store file.
|
|
251
470
|
* Uses the format field as a discriminator.
|
|
@@ -19,8 +19,12 @@
|
|
|
19
19
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
20
|
// SOFTWARE.
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.DEFAULT_SECRET_ITERATIONS = exports.allKeyStoreSecretTypes = exports.MIN_SALT_LENGTH = exports.DEFAULT_KEYSTORE_ITERATIONS = exports.KEYSTORE_FORMAT = void 0;
|
|
22
|
+
exports.DEFAULT_SECRET_ITERATIONS = exports.allKeyStoreSecretTypes = exports.allKeyStoreAsymmetricSecretTypes = exports.allKeyStoreSymmetricSecretTypes = exports.MIN_SALT_LENGTH = exports.DEFAULT_KEYSTORE_ITERATIONS = exports.KEYSTORE_FORMAT = exports.allKeyPairAlgorithms = void 0;
|
|
23
23
|
exports.isKeyStoreFile = isKeyStoreFile;
|
|
24
|
+
// Re-export so consumers can continue to access the algorithm enum via the
|
|
25
|
+
// CryptoUtils.KeyStore namespace alongside the rest of the keystore types.
|
|
26
|
+
var model_1 = require("../model");
|
|
27
|
+
Object.defineProperty(exports, "allKeyPairAlgorithms", { enumerable: true, get: function () { return model_1.allKeyPairAlgorithms; } });
|
|
24
28
|
/**
|
|
25
29
|
* Current format version constant.
|
|
26
30
|
* @public
|
|
@@ -37,11 +41,29 @@ exports.DEFAULT_KEYSTORE_ITERATIONS = 600000;
|
|
|
37
41
|
* @public
|
|
38
42
|
*/
|
|
39
43
|
exports.MIN_SALT_LENGTH = 16;
|
|
44
|
+
/**
|
|
45
|
+
* All valid symmetric secret types.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
exports.allKeyStoreSymmetricSecretTypes = [
|
|
49
|
+
'encryption-key',
|
|
50
|
+
'api-key'
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* All valid asymmetric secret types.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
exports.allKeyStoreAsymmetricSecretTypes = [
|
|
57
|
+
'asymmetric-keypair'
|
|
58
|
+
];
|
|
40
59
|
/**
|
|
41
60
|
* All valid key store secret types.
|
|
42
61
|
* @public
|
|
43
62
|
*/
|
|
44
|
-
exports.allKeyStoreSecretTypes = [
|
|
63
|
+
exports.allKeyStoreSecretTypes = [
|
|
64
|
+
...exports.allKeyStoreAsymmetricSecretTypes,
|
|
65
|
+
...exports.allKeyStoreSymmetricSecretTypes
|
|
66
|
+
];
|
|
45
67
|
/**
|
|
46
68
|
* Default PBKDF2 iterations for secret-level key derivation.
|
|
47
69
|
* Lower than keystore encryption since these are used more frequently.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Pluggable backend that persists raw asymmetric private keys outside of the
|
|
4
|
+
* encrypted keystore vault. Concrete implementations live in platform-specific
|
|
5
|
+
* packages (e.g. an IndexedDB-backed implementation in `@fgv/ts-web-extras` or
|
|
6
|
+
* an encrypted-file implementation in `@fgv/ts-chocolate`).
|
|
7
|
+
*
|
|
8
|
+
* The keystore writes storage-first: a private key is always stored here
|
|
9
|
+
* before the corresponding public-key vault entry is committed. Conversely,
|
|
10
|
+
* deletes hit the vault first and then this storage best-effort. As a result,
|
|
11
|
+
* crashes or skipped saves can leave orphaned blobs here; callers are expected
|
|
12
|
+
* to reconcile via {@link CryptoUtils.KeyStore.IPrivateKeyStorage.list} cross-referenced
|
|
13
|
+
* against the keystore's asymmetric entries.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface IPrivateKeyStorage {
|
|
18
|
+
/**
|
|
19
|
+
* Whether keys generated for this backend may be marked
|
|
20
|
+
* `extractable: false`. `true` on backends that store `CryptoKey`
|
|
21
|
+
* objects directly (e.g. IndexedDB). `false` on backends that must
|
|
22
|
+
* round-trip via JWK (e.g. encrypted-file backends).
|
|
23
|
+
*/
|
|
24
|
+
readonly supportsNonExtractable: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Stores `key` under `id`. Returns the stored `id` on success so the
|
|
27
|
+
* call can compose into a Result chain.
|
|
28
|
+
* @param id - Storage handle to write under.
|
|
29
|
+
* @param key - The private `CryptoKey` to persist.
|
|
30
|
+
*/
|
|
31
|
+
store(id: string, key: CryptoKey): Promise<Result<string>>;
|
|
32
|
+
/**
|
|
33
|
+
* Loads the private key previously stored under `id`.
|
|
34
|
+
* @param id - Storage handle to look up.
|
|
35
|
+
*/
|
|
36
|
+
load(id: string): Promise<Result<CryptoKey>>;
|
|
37
|
+
/**
|
|
38
|
+
* Deletes the entry stored under `id`. Returns the deleted `id` on
|
|
39
|
+
* success so the call can compose into a Result chain.
|
|
40
|
+
* @param id - Storage handle to remove.
|
|
41
|
+
*/
|
|
42
|
+
delete(id: string): Promise<Result<string>>;
|
|
43
|
+
/**
|
|
44
|
+
* Lists every `id` currently held by the backend. Used by consumers to
|
|
45
|
+
* garbage-collect orphans left by crashes or aborted sessions; the
|
|
46
|
+
* keystore itself does not invoke this automatically.
|
|
47
|
+
*/
|
|
48
|
+
list(): Promise<Result<readonly string[]>>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=privateKeyStorage.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2026 Erik Fortune
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
// copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
//# sourceMappingURL=privateKeyStorage.js.map
|
|
@@ -44,6 +44,69 @@ export interface IEncryptionResult {
|
|
|
44
44
|
*/
|
|
45
45
|
readonly encryptedData: Uint8Array;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Asymmetric keypair algorithms supported by the crypto provider.
|
|
49
|
+
* - `'ecdsa-p256'`: ECDSA over the P-256 curve, for signing.
|
|
50
|
+
* - `'rsa-oaep-2048'`: RSA-OAEP, 2048-bit modulus with SHA-256, for encryption.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export type KeyPairAlgorithm = 'ecdsa-p256' | 'rsa-oaep-2048';
|
|
54
|
+
/**
|
|
55
|
+
* Caller-supplied HKDF parameters that domain-separate one
|
|
56
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} call from another.
|
|
57
|
+
* Two wraps that share recipient but differ on `salt` or `info` derive distinct
|
|
58
|
+
* wrap keys, so callers should pick values that bind the wrap to its
|
|
59
|
+
* application context (e.g. a content hash for `salt` and a secret name for
|
|
60
|
+
* `info`).
|
|
61
|
+
*
|
|
62
|
+
* Both fields are required; pass an empty `Uint8Array` if the caller has no
|
|
63
|
+
* value to bind on a given axis. Silent defaulting would hide protocol
|
|
64
|
+
* mistakes, so the API does not pick defaults.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export interface IWrapBytesOptions {
|
|
68
|
+
/**
|
|
69
|
+
* HKDF salt. Domain-separates this wrap from others in different contexts.
|
|
70
|
+
* Caller picks; common choices include a content hash, document id, channel
|
|
71
|
+
* id, etc.
|
|
72
|
+
*/
|
|
73
|
+
readonly salt: Uint8Array;
|
|
74
|
+
/**
|
|
75
|
+
* HKDF info. Further binds the derived key to a specific use within the
|
|
76
|
+
* calling application. Caller picks; common choices include a secret name,
|
|
77
|
+
* message type, or version tag.
|
|
78
|
+
*/
|
|
79
|
+
readonly info: Uint8Array;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Output of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}. The
|
|
83
|
+
* shape is JSON-serializable so it can travel directly over the wire or be
|
|
84
|
+
* persisted as-is.
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
export interface IWrappedBytes {
|
|
88
|
+
/**
|
|
89
|
+
* Sender's ephemeral ECDH P-256 public key as a JSON Web Key. The matching
|
|
90
|
+
* ephemeral private key is dropped after the shared-secret derive.
|
|
91
|
+
*/
|
|
92
|
+
readonly ephemeralPublicKey: JsonWebKey;
|
|
93
|
+
/**
|
|
94
|
+
* AES-GCM nonce, base64-encoded. 12 bytes (96 bits) — the standard AES-GCM
|
|
95
|
+
* nonce length.
|
|
96
|
+
*/
|
|
97
|
+
readonly nonce: string;
|
|
98
|
+
/**
|
|
99
|
+
* AES-GCM ciphertext concatenated with the 16-byte authentication tag,
|
|
100
|
+
* base64-encoded. Tampering with either the nonce or the ciphertext causes
|
|
101
|
+
* unwrap to fail GCM authentication.
|
|
102
|
+
*/
|
|
103
|
+
readonly ciphertext: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* All valid key pair algorithms.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare const allKeyPairAlgorithms: ReadonlyArray<KeyPairAlgorithm>;
|
|
47
110
|
/**
|
|
48
111
|
* Supported key derivation functions.
|
|
49
112
|
* @public
|
|
@@ -169,6 +232,73 @@ export interface ICryptoProvider {
|
|
|
169
232
|
* @returns Success with decoded bytes, or Failure if invalid base64
|
|
170
233
|
*/
|
|
171
234
|
fromBase64(base64: string): Result<Uint8Array>;
|
|
235
|
+
/**
|
|
236
|
+
* Generates a new asymmetric keypair for the requested algorithm.
|
|
237
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
|
|
238
|
+
* @param extractable - Whether the resulting `CryptoKey` objects may be exported.
|
|
239
|
+
* Set `false` on backends that store `CryptoKey` references directly (e.g.
|
|
240
|
+
* IndexedDB). Set `true` when the private key must round-trip through JWK or
|
|
241
|
+
* PKCS#8 (e.g. encrypted-file backends).
|
|
242
|
+
* @returns Success with the generated `CryptoKeyPair`, or Failure with error context.
|
|
243
|
+
*/
|
|
244
|
+
generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
|
|
245
|
+
/**
|
|
246
|
+
* Exports the public half of a keypair as a JSON Web Key.
|
|
247
|
+
* @param publicKey - The public `CryptoKey` to export. Must be an `extractable`
|
|
248
|
+
* key generated for an asymmetric algorithm.
|
|
249
|
+
* @returns Success with the JWK, or Failure with error context.
|
|
250
|
+
*/
|
|
251
|
+
exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
|
|
252
|
+
/**
|
|
253
|
+
* Re-imports a public-key JWK as a `CryptoKey` usable for verification or
|
|
254
|
+
* encryption (depending on algorithm).
|
|
255
|
+
* @param jwk - The JSON Web Key produced by {@link CryptoUtils.ICryptoProvider.exportPublicKeyJwk | exportPublicKeyJwk}.
|
|
256
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} the
|
|
257
|
+
* key was generated for. Determines the import parameters and key usages.
|
|
258
|
+
* @returns Success with the imported public `CryptoKey`, or Failure with error context.
|
|
259
|
+
*/
|
|
260
|
+
importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
261
|
+
/**
|
|
262
|
+
* Wraps `plaintext` for delivery to the holder of the private key paired
|
|
263
|
+
* with `recipientPublicKey`. Uses ECIES with ECDH P-256, HKDF-SHA256, and
|
|
264
|
+
* AES-GCM-256.
|
|
265
|
+
*
|
|
266
|
+
* Generates a fresh ephemeral keypair per call; the ephemeral private key
|
|
267
|
+
* is discarded after the shared-secret derive. Only the recipient (with the
|
|
268
|
+
* matching private key) and the same HKDF parameters can recover
|
|
269
|
+
* `plaintext`.
|
|
270
|
+
*
|
|
271
|
+
* Empty `plaintext` is permitted; the resulting wrap contains only the
|
|
272
|
+
* 16-byte GCM authentication tag and round-trips back to an empty
|
|
273
|
+
* `Uint8Array`.
|
|
274
|
+
* @param plaintext - The bytes to wrap. Any length supported by AES-GCM
|
|
275
|
+
* (in practice, well below 2^39 - 256 bits).
|
|
276
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
277
|
+
* Must have algorithm name `'ECDH'` and named curve `'P-256'`; mismatched
|
|
278
|
+
* algorithm or curve yields a `Failure` with error context.
|
|
279
|
+
* @param options - HKDF parameters; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
280
|
+
* @returns `Success` with the wrapped payload, or `Failure` with error context.
|
|
281
|
+
*/
|
|
282
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
283
|
+
/**
|
|
284
|
+
* Inverse of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}.
|
|
285
|
+
* Recovers the original `plaintext` from a wrapped payload using the
|
|
286
|
+
* recipient's private key.
|
|
287
|
+
*
|
|
288
|
+
* Returns a `Failure` (never throws) on any of:
|
|
289
|
+
* - Tampered nonce or ciphertext (AES-GCM authentication fails)
|
|
290
|
+
* - Wrong private key (different shared secret derives a different wrap key)
|
|
291
|
+
* - Wrong HKDF parameters (different wrap key)
|
|
292
|
+
* - Malformed `ephemeralPublicKey` JWK
|
|
293
|
+
* - Malformed base64 in `nonce` or `ciphertext`
|
|
294
|
+
* @param wrapped - The wrapped payload produced by `wrapBytes`.
|
|
295
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private
|
|
296
|
+
* `CryptoKey`. Must have algorithm name `'ECDH'` and named curve `'P-256'`,
|
|
297
|
+
* and key usages including `'deriveKey'` or `'deriveBits'`.
|
|
298
|
+
* @param options - The same HKDF parameters used at wrap time.
|
|
299
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with error context.
|
|
300
|
+
*/
|
|
301
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
172
302
|
}
|
|
173
303
|
/**
|
|
174
304
|
* High-level interface for encrypting JSON content by secret name.
|
|
@@ -52,10 +52,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
52
52
|
};
|
|
53
53
|
})();
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
exports.Constants = void 0;
|
|
55
|
+
exports.allKeyPairAlgorithms = exports.Constants = void 0;
|
|
56
56
|
exports.isEncryptedFile = isEncryptedFile;
|
|
57
57
|
const Constants = __importStar(require("./constants"));
|
|
58
58
|
exports.Constants = Constants;
|
|
59
|
+
/**
|
|
60
|
+
* All valid key pair algorithms.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
exports.allKeyPairAlgorithms = ['ecdsa-p256', 'rsa-oaep-2048'];
|
|
59
64
|
// ============================================================================
|
|
60
65
|
// Detection Helper
|
|
61
66
|
// ============================================================================
|