@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
package/dist/ts-extras.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ declare namespace AiAssist {
|
|
|
33
33
|
IChatMessage,
|
|
34
34
|
AiApiFormat,
|
|
35
35
|
AiImageApiFormat,
|
|
36
|
+
IAiImageModelCapability,
|
|
36
37
|
IAiProviderDescriptor,
|
|
37
38
|
IAiAssistProviderConfig,
|
|
38
39
|
IAiAssistSettings,
|
|
@@ -62,6 +63,8 @@ declare namespace AiAssist {
|
|
|
62
63
|
allProviderIds,
|
|
63
64
|
getProviderDescriptors,
|
|
64
65
|
getProviderDescriptor,
|
|
66
|
+
resolveImageCapability,
|
|
67
|
+
supportsImageGeneration,
|
|
65
68
|
DEFAULT_MODEL_CAPABILITY_CONFIG,
|
|
66
69
|
callProviderCompletion,
|
|
67
70
|
callProxiedCompletion,
|
|
@@ -103,9 +106,20 @@ declare const aiAssistSettings: Converter<IAiAssistSettings>;
|
|
|
103
106
|
|
|
104
107
|
/**
|
|
105
108
|
* API format categories for image-generation provider routing.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* - `'openai-images'` — OpenAI Images API. Routes to `/images/generations`
|
|
112
|
+
* (text-only) or `/images/edits` (when reference images are present).
|
|
113
|
+
* - `'xai-images'` — xAI Images API. Same wire shape as OpenAI but text-only;
|
|
114
|
+
* no reference-image support on grok-2-image.
|
|
115
|
+
* - `'gemini-imagen'` — Google Imagen `:predict` endpoint. Text-only.
|
|
116
|
+
* - `'gemini-image-out'` — Google Gemini chat-style `:generateContent`
|
|
117
|
+
* endpoint that returns image parts (Gemini 2.5 Flash Image / "Nano
|
|
118
|
+
* Banana"). Accepts reference images.
|
|
119
|
+
*
|
|
106
120
|
* @public
|
|
107
121
|
*/
|
|
108
|
-
declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images';
|
|
122
|
+
declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images' | 'gemini-image-out';
|
|
109
123
|
|
|
110
124
|
/**
|
|
111
125
|
* Capability vocabulary used to describe what a model can do. Used as both
|
|
@@ -193,12 +207,30 @@ declare const aiToolEnablement: Converter<IAiToolEnablement>;
|
|
|
193
207
|
*/
|
|
194
208
|
declare const aiWebSearchToolConfig: Converter<IAiWebSearchToolConfig>;
|
|
195
209
|
|
|
210
|
+
/**
|
|
211
|
+
* All valid key pair algorithms.
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
declare const allKeyPairAlgorithms: ReadonlyArray<KeyPairAlgorithm>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* All valid asymmetric secret types.
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
declare const allKeyStoreAsymmetricSecretTypes: ReadonlyArray<KeyStoreAsymmetricSecretType>;
|
|
221
|
+
|
|
196
222
|
/**
|
|
197
223
|
* All valid key store secret types.
|
|
198
224
|
* @public
|
|
199
225
|
*/
|
|
200
226
|
declare const allKeyStoreSecretTypes: ReadonlyArray<KeyStoreSecretType>;
|
|
201
227
|
|
|
228
|
+
/**
|
|
229
|
+
* All valid symmetric secret types.
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
declare const allKeyStoreSymmetricSecretTypes: ReadonlyArray<KeyStoreSymmetricSecretType>;
|
|
233
|
+
|
|
202
234
|
/**
|
|
203
235
|
* All valid {@link ModelSpecKey} values.
|
|
204
236
|
* @public
|
|
@@ -259,12 +291,17 @@ declare function callProviderCompletionStream(params: IProviderCompletionStreamP
|
|
|
259
291
|
/**
|
|
260
292
|
* Calls the appropriate image-generation API for a given provider.
|
|
261
293
|
*
|
|
262
|
-
*
|
|
294
|
+
* Resolves a {@link IAiImageModelCapability} from
|
|
295
|
+
* {@link IAiProviderDescriptor.imageGeneration} for the requested model and
|
|
296
|
+
* routes by its `format`:
|
|
263
297
|
* - `'openai-images'` for OpenAI (DALL-E, gpt-image-1)
|
|
264
298
|
* - `'xai-images'` for xAI Grok image models
|
|
265
|
-
* - `'gemini-imagen'` for Google Imagen
|
|
299
|
+
* - `'gemini-imagen'` for Google Imagen `:predict`
|
|
300
|
+
* - `'gemini-image-out'` for Gemini chat-style image output (Nano Banana)
|
|
266
301
|
*
|
|
267
302
|
* Image-model selection reuses the existing `'image'` {@link ModelSpecKey}.
|
|
303
|
+
* When `request.referenceImages` is non-empty, the call is rejected up front
|
|
304
|
+
* unless the resolved capability declares `acceptsImageReferenceInput`.
|
|
268
305
|
*
|
|
269
306
|
* @param params - Request parameters including descriptor, API key, and prompt
|
|
270
307
|
* @returns The generated images, or a failure
|
|
@@ -335,7 +372,10 @@ declare function callProxiedCompletionStream(proxyUrl: string, params: IProvider
|
|
|
335
372
|
* - Error response body: `{error: string}` (surfaced as `proxy: ${error}`)
|
|
336
373
|
*
|
|
337
374
|
* The proxy server is responsible for descriptor lookup, model resolution,
|
|
338
|
-
* provider dispatch, and response normalization.
|
|
375
|
+
* provider dispatch, and response normalization. When `params.referenceImages`
|
|
376
|
+
* is present, the proxy is also responsible for repackaging it into the
|
|
377
|
+
* upstream wire format (e.g. multipart/form-data for OpenAI `/images/edits`,
|
|
378
|
+
* `inlineData` parts for Gemini `:generateContent`).
|
|
339
379
|
*
|
|
340
380
|
* @param proxyUrl - Base URL of the proxy server (e.g. `http://localhost:3001`)
|
|
341
381
|
* @param params - Same parameters as {@link callProviderImageGeneration}
|
|
@@ -388,6 +428,12 @@ declare namespace Converters_2 {
|
|
|
388
428
|
export {
|
|
389
429
|
keystoreFormat,
|
|
390
430
|
keystoreSecretType,
|
|
431
|
+
keystoreSymmetricSecretType,
|
|
432
|
+
keystoreAsymmetricSecretType,
|
|
433
|
+
keyPairAlgorithm,
|
|
434
|
+
jsonWebKeyShape,
|
|
435
|
+
keystoreSymmetricEntryJson,
|
|
436
|
+
keystoreAsymmetricEntryJson,
|
|
391
437
|
keystoreSecretEntryJson,
|
|
392
438
|
keystoreVaultContents,
|
|
393
439
|
keystoreFile
|
|
@@ -440,6 +486,8 @@ declare namespace CryptoUtils {
|
|
|
440
486
|
Converters_3 as Converters,
|
|
441
487
|
DirectEncryptionProvider,
|
|
442
488
|
IDirectEncryptionProviderParams,
|
|
489
|
+
IKeyPairAlgorithmParams,
|
|
490
|
+
keyPairAlgorithmParams,
|
|
443
491
|
NodeCryptoProvider,
|
|
444
492
|
nodeCryptoProvider,
|
|
445
493
|
createEncryptedFile,
|
|
@@ -453,6 +501,10 @@ declare namespace CryptoUtils {
|
|
|
453
501
|
EncryptedFileFormat,
|
|
454
502
|
INamedSecret,
|
|
455
503
|
IEncryptionResult,
|
|
504
|
+
KeyPairAlgorithm,
|
|
505
|
+
IWrapBytesOptions,
|
|
506
|
+
IWrappedBytes,
|
|
507
|
+
allKeyPairAlgorithms,
|
|
456
508
|
KeyDerivationFunction,
|
|
457
509
|
IKeyDerivationParams,
|
|
458
510
|
IEncryptedFile,
|
|
@@ -829,6 +881,50 @@ declare namespace Hash {
|
|
|
829
881
|
}
|
|
830
882
|
export { Hash }
|
|
831
883
|
|
|
884
|
+
/**
|
|
885
|
+
* Options for adding an asymmetric keypair to the key store.
|
|
886
|
+
* @public
|
|
887
|
+
*/
|
|
888
|
+
declare interface IAddKeyPairOptions {
|
|
889
|
+
/**
|
|
890
|
+
* Algorithm to use for the new keypair.
|
|
891
|
+
*/
|
|
892
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
893
|
+
/**
|
|
894
|
+
* Optional description for the entry.
|
|
895
|
+
*/
|
|
896
|
+
readonly description?: string;
|
|
897
|
+
/**
|
|
898
|
+
* Whether to replace an existing entry with the same name.
|
|
899
|
+
* Replacement mints a fresh storage `id` and best-effort deletes the
|
|
900
|
+
* displaced storage blob; see the keystore design doc for details.
|
|
901
|
+
*/
|
|
902
|
+
readonly replace?: boolean;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Result of adding an asymmetric keypair to the key store.
|
|
907
|
+
* @public
|
|
908
|
+
*/
|
|
909
|
+
declare interface IAddKeyPairResult {
|
|
910
|
+
/**
|
|
911
|
+
* The asymmetric entry that was added.
|
|
912
|
+
*/
|
|
913
|
+
readonly entry: IKeyStoreAsymmetricEntry;
|
|
914
|
+
/**
|
|
915
|
+
* Whether this replaced an existing entry.
|
|
916
|
+
*/
|
|
917
|
+
readonly replaced: boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Best-effort warning from displaced-resource cleanup. Set when this call
|
|
920
|
+
* replaced a prior entry but the corresponding
|
|
921
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
|
|
922
|
+
* keypair is still committed and the orphaned blob is left for consumer-side
|
|
923
|
+
* GC to reconcile.
|
|
924
|
+
*/
|
|
925
|
+
readonly warning?: string;
|
|
926
|
+
}
|
|
927
|
+
|
|
832
928
|
/**
|
|
833
929
|
* Options for adding a secret derived from a password.
|
|
834
930
|
* @public
|
|
@@ -879,11 +975,19 @@ declare interface IAddSecretResult {
|
|
|
879
975
|
/**
|
|
880
976
|
* The secret entry that was added.
|
|
881
977
|
*/
|
|
882
|
-
readonly entry:
|
|
978
|
+
readonly entry: IKeyStoreSymmetricEntry;
|
|
883
979
|
/**
|
|
884
980
|
* Whether this replaced an existing secret.
|
|
885
981
|
*/
|
|
886
982
|
readonly replaced: boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Best-effort warning from displaced-resource cleanup. Set when this call
|
|
985
|
+
* replaced an asymmetric-keypair entry but the corresponding
|
|
986
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
|
|
987
|
+
* entry is still committed and the orphaned blob is left for consumer-side
|
|
988
|
+
* GC to reconcile.
|
|
989
|
+
*/
|
|
990
|
+
readonly warning?: string;
|
|
887
991
|
}
|
|
888
992
|
|
|
889
993
|
/**
|
|
@@ -1039,6 +1143,16 @@ declare interface IAiImageGenerationParams {
|
|
|
1039
1143
|
readonly prompt: string;
|
|
1040
1144
|
/** Optional generation options. */
|
|
1041
1145
|
readonly options?: IAiImageGenerationOptions;
|
|
1146
|
+
/**
|
|
1147
|
+
* Optional reference images. When present, the provider will use them as
|
|
1148
|
+
* visual context (e.g. to preserve a character's appearance across multiple
|
|
1149
|
+
* generations). The dispatcher resolves the
|
|
1150
|
+
* {@link AiAssist.IAiImageModelCapability} for the requested model and
|
|
1151
|
+
* rejects the call up front if `acceptsImageReferenceInput` is not set on
|
|
1152
|
+
* the matching capability. An empty array is treated identically to
|
|
1153
|
+
* `undefined`.
|
|
1154
|
+
*/
|
|
1155
|
+
readonly referenceImages?: ReadonlyArray<IAiImageAttachment>;
|
|
1042
1156
|
}
|
|
1043
1157
|
|
|
1044
1158
|
/**
|
|
@@ -1050,6 +1164,35 @@ declare interface IAiImageGenerationResponse {
|
|
|
1050
1164
|
readonly images: ReadonlyArray<IAiGeneratedImage>;
|
|
1051
1165
|
}
|
|
1052
1166
|
|
|
1167
|
+
/**
|
|
1168
|
+
* Image-generation capability for a model family within a provider. Used as
|
|
1169
|
+
* an entry in {@link IAiProviderDescriptor.imageGeneration}.
|
|
1170
|
+
*
|
|
1171
|
+
* @public
|
|
1172
|
+
*/
|
|
1173
|
+
declare interface IAiImageModelCapability {
|
|
1174
|
+
/**
|
|
1175
|
+
* Prefix matched against the resolved image model id. The empty string is
|
|
1176
|
+
* the catch-all and matches every model. When multiple rules' prefixes
|
|
1177
|
+
* match a model id, the longest prefix wins; ties are broken by
|
|
1178
|
+
* first-encountered.
|
|
1179
|
+
*/
|
|
1180
|
+
readonly modelPrefix: string;
|
|
1181
|
+
/** API format used to dispatch requests for matching models. */
|
|
1182
|
+
readonly format: AiImageApiFormat;
|
|
1183
|
+
/**
|
|
1184
|
+
* Whether matching models accept reference images via
|
|
1185
|
+
* {@link AiAssist.IAiImageGenerationParams.referenceImages}. When false or
|
|
1186
|
+
* undefined, calls that include reference images are rejected up front.
|
|
1187
|
+
*
|
|
1188
|
+
* @remarks
|
|
1189
|
+
* Per-model constraints beyond ref support (e.g. dall-e-3 ignores edits)
|
|
1190
|
+
* are not validated here and surface as provider 400s, consistent with the
|
|
1191
|
+
* existing image-generation policy.
|
|
1192
|
+
*/
|
|
1193
|
+
readonly acceptsImageReferenceInput?: boolean;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1053
1196
|
/**
|
|
1054
1197
|
* Configuration that maps model id patterns to capabilities. Used to
|
|
1055
1198
|
* augment (or, where the provider supplies no capability info, fully
|
|
@@ -1138,15 +1281,27 @@ declare interface IAiProviderDescriptor {
|
|
|
1138
1281
|
*/
|
|
1139
1282
|
readonly acceptsImageInput: boolean;
|
|
1140
1283
|
/**
|
|
1141
|
-
*
|
|
1142
|
-
* does not support image generation.
|
|
1284
|
+
* Image-generation capabilities, scoped to model id prefixes. Empty or
|
|
1285
|
+
* undefined means the provider does not support image generation.
|
|
1143
1286
|
*
|
|
1144
1287
|
* @remarks
|
|
1288
|
+
* The dispatcher matches the resolved model id against each rule's
|
|
1289
|
+
* `modelPrefix` and selects the longest match (see
|
|
1290
|
+
* {@link AiAssist.resolveImageCapability}). An empty `modelPrefix` is the
|
|
1291
|
+
* catch-all and matches every model id.
|
|
1292
|
+
*
|
|
1293
|
+
* Multiple entries support providers that host more than one image-API
|
|
1294
|
+
* surface under one baseUrl. Google Gemini is the canonical case: the
|
|
1295
|
+
* `imagen-*` family is predict-only via `:predict`, while
|
|
1296
|
+
* `gemini-2.5-flash-image` uses chat-style `:generateContent` and accepts
|
|
1297
|
+
* reference images. Listing both lets callers pick the right model and the
|
|
1298
|
+
* dispatcher routes accordingly.
|
|
1299
|
+
*
|
|
1145
1300
|
* Image-model selection reuses the existing `image` {@link ModelSpecKey}.
|
|
1146
|
-
* Providers
|
|
1301
|
+
* Providers that declare `imageGeneration` should declare a model in
|
|
1147
1302
|
* `defaultModel.image`, e.g. `{ base: 'gpt-4o', image: 'dall-e-3' }`.
|
|
1148
1303
|
*/
|
|
1149
|
-
readonly
|
|
1304
|
+
readonly imageGeneration?: ReadonlyArray<IAiImageModelCapability>;
|
|
1150
1305
|
}
|
|
1151
1306
|
|
|
1152
1307
|
/**
|
|
@@ -1389,6 +1544,73 @@ declare interface ICryptoProvider {
|
|
|
1389
1544
|
* @returns Success with decoded bytes, or Failure if invalid base64
|
|
1390
1545
|
*/
|
|
1391
1546
|
fromBase64(base64: string): Result<Uint8Array>;
|
|
1547
|
+
/**
|
|
1548
|
+
* Generates a new asymmetric keypair for the requested algorithm.
|
|
1549
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
|
|
1550
|
+
* @param extractable - Whether the resulting `CryptoKey` objects may be exported.
|
|
1551
|
+
* Set `false` on backends that store `CryptoKey` references directly (e.g.
|
|
1552
|
+
* IndexedDB). Set `true` when the private key must round-trip through JWK or
|
|
1553
|
+
* PKCS#8 (e.g. encrypted-file backends).
|
|
1554
|
+
* @returns Success with the generated `CryptoKeyPair`, or Failure with error context.
|
|
1555
|
+
*/
|
|
1556
|
+
generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
|
|
1557
|
+
/**
|
|
1558
|
+
* Exports the public half of a keypair as a JSON Web Key.
|
|
1559
|
+
* @param publicKey - The public `CryptoKey` to export. Must be an `extractable`
|
|
1560
|
+
* key generated for an asymmetric algorithm.
|
|
1561
|
+
* @returns Success with the JWK, or Failure with error context.
|
|
1562
|
+
*/
|
|
1563
|
+
exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
|
|
1564
|
+
/**
|
|
1565
|
+
* Re-imports a public-key JWK as a `CryptoKey` usable for verification or
|
|
1566
|
+
* encryption (depending on algorithm).
|
|
1567
|
+
* @param jwk - The JSON Web Key produced by {@link CryptoUtils.ICryptoProvider.exportPublicKeyJwk | exportPublicKeyJwk}.
|
|
1568
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} the
|
|
1569
|
+
* key was generated for. Determines the import parameters and key usages.
|
|
1570
|
+
* @returns Success with the imported public `CryptoKey`, or Failure with error context.
|
|
1571
|
+
*/
|
|
1572
|
+
importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
1573
|
+
/**
|
|
1574
|
+
* Wraps `plaintext` for delivery to the holder of the private key paired
|
|
1575
|
+
* with `recipientPublicKey`. Uses ECIES with ECDH P-256, HKDF-SHA256, and
|
|
1576
|
+
* AES-GCM-256.
|
|
1577
|
+
*
|
|
1578
|
+
* Generates a fresh ephemeral keypair per call; the ephemeral private key
|
|
1579
|
+
* is discarded after the shared-secret derive. Only the recipient (with the
|
|
1580
|
+
* matching private key) and the same HKDF parameters can recover
|
|
1581
|
+
* `plaintext`.
|
|
1582
|
+
*
|
|
1583
|
+
* Empty `plaintext` is permitted; the resulting wrap contains only the
|
|
1584
|
+
* 16-byte GCM authentication tag and round-trips back to an empty
|
|
1585
|
+
* `Uint8Array`.
|
|
1586
|
+
* @param plaintext - The bytes to wrap. Any length supported by AES-GCM
|
|
1587
|
+
* (in practice, well below 2^39 - 256 bits).
|
|
1588
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
1589
|
+
* Must have algorithm name `'ECDH'` and named curve `'P-256'`; mismatched
|
|
1590
|
+
* algorithm or curve yields a `Failure` with error context.
|
|
1591
|
+
* @param options - HKDF parameters; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
1592
|
+
* @returns `Success` with the wrapped payload, or `Failure` with error context.
|
|
1593
|
+
*/
|
|
1594
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
1595
|
+
/**
|
|
1596
|
+
* Inverse of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}.
|
|
1597
|
+
* Recovers the original `plaintext` from a wrapped payload using the
|
|
1598
|
+
* recipient's private key.
|
|
1599
|
+
*
|
|
1600
|
+
* Returns a `Failure` (never throws) on any of:
|
|
1601
|
+
* - Tampered nonce or ciphertext (AES-GCM authentication fails)
|
|
1602
|
+
* - Wrong private key (different shared secret derives a different wrap key)
|
|
1603
|
+
* - Wrong HKDF parameters (different wrap key)
|
|
1604
|
+
* - Malformed `ephemeralPublicKey` JWK
|
|
1605
|
+
* - Malformed base64 in `nonce` or `ciphertext`
|
|
1606
|
+
* @param wrapped - The wrapped payload produced by `wrapBytes`.
|
|
1607
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private
|
|
1608
|
+
* `CryptoKey`. Must have algorithm name `'ECDH'` and named curve `'P-256'`,
|
|
1609
|
+
* and key usages including `'deriveKey'` or `'deriveBits'`.
|
|
1610
|
+
* @param options - The same HKDF parameters used at wrap time.
|
|
1611
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with error context.
|
|
1612
|
+
*/
|
|
1613
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
1392
1614
|
}
|
|
1393
1615
|
|
|
1394
1616
|
/**
|
|
@@ -1534,10 +1756,10 @@ declare interface IEncryptionResult {
|
|
|
1534
1756
|
*/
|
|
1535
1757
|
declare interface IImportKeyOptions extends IImportSecretOptions {
|
|
1536
1758
|
/**
|
|
1537
|
-
*
|
|
1759
|
+
* Symmetric secret type classification for the imported key material.
|
|
1538
1760
|
* @defaultValue 'encryption-key'
|
|
1539
1761
|
*/
|
|
1540
|
-
readonly type?:
|
|
1762
|
+
readonly type?: KeyStoreSymmetricSecretType;
|
|
1541
1763
|
}
|
|
1542
1764
|
|
|
1543
1765
|
/**
|
|
@@ -1571,6 +1793,111 @@ declare interface IKeyDerivationParams {
|
|
|
1571
1793
|
readonly iterations: number;
|
|
1572
1794
|
}
|
|
1573
1795
|
|
|
1796
|
+
/**
|
|
1797
|
+
* WebCrypto parameters for a single {@link CryptoUtils.KeyPairAlgorithm}.
|
|
1798
|
+
* Implementations of {@link CryptoUtils.ICryptoProvider} use this table to
|
|
1799
|
+
* translate the small public algorithm enum into the WebCrypto algorithm
|
|
1800
|
+
* objects and key-usage arrays expected by `crypto.subtle`.
|
|
1801
|
+
* @public
|
|
1802
|
+
*/
|
|
1803
|
+
declare interface IKeyPairAlgorithmParams {
|
|
1804
|
+
/**
|
|
1805
|
+
* Algorithm parameters for `crypto.subtle.generateKey`. Always an asymmetric
|
|
1806
|
+
* variant — these algorithms produce a `CryptoKeyPair`, not a single key.
|
|
1807
|
+
*/
|
|
1808
|
+
readonly generateKey: RsaHashedKeyGenParams | EcKeyGenParams;
|
|
1809
|
+
/**
|
|
1810
|
+
* Algorithm parameters for `crypto.subtle.importKey('jwk', ...)` when
|
|
1811
|
+
* importing the public half of a keypair.
|
|
1812
|
+
*/
|
|
1813
|
+
readonly importPublicKey: RsaHashedImportParams | EcKeyImportParams;
|
|
1814
|
+
/**
|
|
1815
|
+
* Default key usages for the generated `CryptoKeyPair`. Both halves receive
|
|
1816
|
+
* the usages WebCrypto considers valid for their role; the platform filters.
|
|
1817
|
+
*/
|
|
1818
|
+
readonly keyPairUsages: ReadonlyArray<KeyUsage>;
|
|
1819
|
+
/**
|
|
1820
|
+
* Key usages applied when re-importing only the public key.
|
|
1821
|
+
*/
|
|
1822
|
+
readonly publicKeyUsages: ReadonlyArray<KeyUsage>;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
/**
|
|
1826
|
+
* An asymmetric keypair entry stored in the vault (in-memory representation).
|
|
1827
|
+
* Holds only the public key (as a JWK) and a stable handle (`id`) the
|
|
1828
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider uses to fetch the private key.
|
|
1829
|
+
* @public
|
|
1830
|
+
*/
|
|
1831
|
+
declare interface IKeyStoreAsymmetricEntry {
|
|
1832
|
+
/**
|
|
1833
|
+
* Unique name for this entry (used as vault lookup key, renameable).
|
|
1834
|
+
*/
|
|
1835
|
+
readonly name: string;
|
|
1836
|
+
/**
|
|
1837
|
+
* Asymmetric secret type discriminator.
|
|
1838
|
+
*/
|
|
1839
|
+
readonly type: KeyStoreAsymmetricSecretType;
|
|
1840
|
+
/**
|
|
1841
|
+
* Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
|
|
1842
|
+
* private key. Independent of `name`; survives renames.
|
|
1843
|
+
*/
|
|
1844
|
+
readonly id: string;
|
|
1845
|
+
/**
|
|
1846
|
+
* Algorithm used to generate this keypair.
|
|
1847
|
+
*/
|
|
1848
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
1849
|
+
/**
|
|
1850
|
+
* The public key as a JSON Web Key.
|
|
1851
|
+
*/
|
|
1852
|
+
readonly publicKeyJwk: JsonWebKey;
|
|
1853
|
+
/**
|
|
1854
|
+
* Optional description for this entry.
|
|
1855
|
+
*/
|
|
1856
|
+
readonly description?: string;
|
|
1857
|
+
/**
|
|
1858
|
+
* When this entry was added (ISO 8601).
|
|
1859
|
+
*/
|
|
1860
|
+
readonly createdAt: string;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* JSON-serializable representation of an asymmetric keypair entry.
|
|
1865
|
+
* The private key is not present here — it lives in the
|
|
1866
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider, addressed by `id`.
|
|
1867
|
+
* @public
|
|
1868
|
+
*/
|
|
1869
|
+
declare interface IKeyStoreAsymmetricEntryJson {
|
|
1870
|
+
/**
|
|
1871
|
+
* Unique name for this entry.
|
|
1872
|
+
*/
|
|
1873
|
+
readonly name: string;
|
|
1874
|
+
/**
|
|
1875
|
+
* Asymmetric secret type discriminator.
|
|
1876
|
+
*/
|
|
1877
|
+
readonly type: KeyStoreAsymmetricSecretType;
|
|
1878
|
+
/**
|
|
1879
|
+
* Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
|
|
1880
|
+
* private key.
|
|
1881
|
+
*/
|
|
1882
|
+
readonly id: string;
|
|
1883
|
+
/**
|
|
1884
|
+
* Algorithm used to generate this keypair.
|
|
1885
|
+
*/
|
|
1886
|
+
readonly algorithm: KeyPairAlgorithm;
|
|
1887
|
+
/**
|
|
1888
|
+
* The public key as a JSON Web Key.
|
|
1889
|
+
*/
|
|
1890
|
+
readonly publicKeyJwk: JsonWebKey;
|
|
1891
|
+
/**
|
|
1892
|
+
* Optional description.
|
|
1893
|
+
*/
|
|
1894
|
+
readonly description?: string;
|
|
1895
|
+
/**
|
|
1896
|
+
* When this entry was added (ISO 8601).
|
|
1897
|
+
*/
|
|
1898
|
+
readonly createdAt: string;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1574
1901
|
/**
|
|
1575
1902
|
* Parameters for creating a new key store.
|
|
1576
1903
|
* @public
|
|
@@ -1584,8 +1911,26 @@ declare interface IKeyStoreCreateParams {
|
|
|
1584
1911
|
* PBKDF2 iterations (defaults to DEFAULT_KEYSTORE_ITERATIONS).
|
|
1585
1912
|
*/
|
|
1586
1913
|
readonly iterations?: number;
|
|
1914
|
+
/**
|
|
1915
|
+
* Optional private-key storage backend. Required to use `addKeyPair` /
|
|
1916
|
+
* `getKeyPair`; absent backends still permit opening, listing, and reading
|
|
1917
|
+
* public-key metadata for asymmetric entries.
|
|
1918
|
+
*/
|
|
1919
|
+
readonly privateKeyStorage?: IPrivateKeyStorage;
|
|
1587
1920
|
}
|
|
1588
1921
|
|
|
1922
|
+
/**
|
|
1923
|
+
* Any vault entry, discriminated by `type`.
|
|
1924
|
+
* @public
|
|
1925
|
+
*/
|
|
1926
|
+
declare type IKeyStoreEntry = IKeyStoreSymmetricEntry | IKeyStoreAsymmetricEntry;
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Any JSON vault entry, discriminated by `type`.
|
|
1930
|
+
* @public
|
|
1931
|
+
*/
|
|
1932
|
+
declare type IKeyStoreEntryJson = IKeyStoreSymmetricEntryJson | IKeyStoreAsymmetricEntryJson;
|
|
1933
|
+
|
|
1589
1934
|
/**
|
|
1590
1935
|
* The encrypted key store file format.
|
|
1591
1936
|
* @public
|
|
@@ -1630,22 +1975,46 @@ declare interface IKeyStoreOpenParams {
|
|
|
1630
1975
|
* The encrypted key store file content.
|
|
1631
1976
|
*/
|
|
1632
1977
|
readonly keystoreFile: IKeyStoreFile;
|
|
1978
|
+
/**
|
|
1979
|
+
* Optional private-key storage backend. Required to use `addKeyPair` /
|
|
1980
|
+
* `getKeyPair`; absent backends still permit opening, listing, and reading
|
|
1981
|
+
* public-key metadata for asymmetric entries.
|
|
1982
|
+
*/
|
|
1983
|
+
readonly privateKeyStorage?: IPrivateKeyStorage;
|
|
1633
1984
|
}
|
|
1634
1985
|
|
|
1635
1986
|
/**
|
|
1636
|
-
*
|
|
1987
|
+
* Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry}.
|
|
1988
|
+
* @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry} for symmetric
|
|
1989
|
+
* entries or {@link CryptoUtils.KeyStore.IKeyStoreEntry} for the discriminated union.
|
|
1637
1990
|
* @public
|
|
1638
1991
|
*/
|
|
1639
|
-
declare
|
|
1992
|
+
declare type IKeyStoreSecretEntry = IKeyStoreSymmetricEntry;
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}.
|
|
1996
|
+
* @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson} for
|
|
1997
|
+
* symmetric entries or {@link CryptoUtils.KeyStore.IKeyStoreEntryJson} for the
|
|
1998
|
+
* discriminated union.
|
|
1999
|
+
* @public
|
|
2000
|
+
*/
|
|
2001
|
+
declare type IKeyStoreSecretEntryJson = IKeyStoreSymmetricEntryJson;
|
|
2002
|
+
|
|
2003
|
+
/**
|
|
2004
|
+
* A symmetric secret entry stored in the vault (in-memory representation).
|
|
2005
|
+
* Holds the raw key material directly — for `'encryption-key'` it is a 32-byte
|
|
2006
|
+
* AES-256 key; for `'api-key'` it is the UTF-8 encoded API key string.
|
|
2007
|
+
* @public
|
|
2008
|
+
*/
|
|
2009
|
+
declare interface IKeyStoreSymmetricEntry {
|
|
1640
2010
|
/**
|
|
1641
2011
|
* Unique name for this secret (used as lookup key).
|
|
1642
2012
|
*/
|
|
1643
2013
|
readonly name: string;
|
|
1644
2014
|
/**
|
|
1645
|
-
*
|
|
1646
|
-
* Defaults to `'encryption-key'` for backwards compatibility.
|
|
2015
|
+
* Symmetric secret type discriminator.
|
|
1647
2016
|
*/
|
|
1648
|
-
readonly type:
|
|
2017
|
+
readonly type: KeyStoreSymmetricSecretType;
|
|
1649
2018
|
/**
|
|
1650
2019
|
* The secret data.
|
|
1651
2020
|
* - For `'encryption-key'`: 32-byte AES-256 key.
|
|
@@ -1663,19 +2032,34 @@ declare interface IKeyStoreSecretEntry {
|
|
|
1663
2032
|
}
|
|
1664
2033
|
|
|
1665
2034
|
/**
|
|
1666
|
-
* JSON-serializable
|
|
2035
|
+
* JSON-serializable representation of a symmetric secret entry.
|
|
2036
|
+
*
|
|
2037
|
+
* @remarks
|
|
2038
|
+
* Describes the *normalized* shape after parsing. `type` is required here
|
|
2039
|
+
* because the converter (see
|
|
2040
|
+
* {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson})
|
|
2041
|
+
* injects the default `'encryption-key'` when reading vaults written before
|
|
2042
|
+
* asymmetric-keypair support added the discriminator. Raw on-wire bytes from
|
|
2043
|
+
* a legacy vault may therefore omit `type`; downstream code only ever sees
|
|
2044
|
+
* the post-conversion shape declared here.
|
|
2045
|
+
*
|
|
1667
2046
|
* @public
|
|
1668
2047
|
*/
|
|
1669
|
-
declare interface
|
|
2048
|
+
declare interface IKeyStoreSymmetricEntryJson {
|
|
1670
2049
|
/**
|
|
1671
2050
|
* Unique name for this secret.
|
|
1672
2051
|
*/
|
|
1673
2052
|
readonly name: string;
|
|
1674
2053
|
/**
|
|
1675
|
-
*
|
|
1676
|
-
*
|
|
2054
|
+
* Symmetric secret type discriminator.
|
|
2055
|
+
*
|
|
2056
|
+
* Required on this normalized model type. Vaults written prior to the
|
|
2057
|
+
* asymmetric-keypair support may omit this field on the wire; the
|
|
2058
|
+
* converter injects `'encryption-key'` when missing for backwards
|
|
2059
|
+
* compatibility, so by the time a value of this type is observed the
|
|
2060
|
+
* discriminator is always present.
|
|
1677
2061
|
*/
|
|
1678
|
-
readonly type
|
|
2062
|
+
readonly type: KeyStoreSymmetricSecretType;
|
|
1679
2063
|
/**
|
|
1680
2064
|
* Base64-encoded secret data.
|
|
1681
2065
|
*/
|
|
@@ -1691,7 +2075,7 @@ declare interface IKeyStoreSecretEntryJson {
|
|
|
1691
2075
|
}
|
|
1692
2076
|
|
|
1693
2077
|
/**
|
|
1694
|
-
* The decrypted vault contents - a versioned map of
|
|
2078
|
+
* The decrypted vault contents - a versioned map of entries.
|
|
1695
2079
|
* @public
|
|
1696
2080
|
*/
|
|
1697
2081
|
declare interface IKeyStoreVaultContents {
|
|
@@ -1700,9 +2084,9 @@ declare interface IKeyStoreVaultContents {
|
|
|
1700
2084
|
*/
|
|
1701
2085
|
readonly version: KeyStoreFormat;
|
|
1702
2086
|
/**
|
|
1703
|
-
* Map of
|
|
2087
|
+
* Map of entry name to entry (symmetric or asymmetric).
|
|
1704
2088
|
*/
|
|
1705
|
-
readonly secrets: Record<string,
|
|
2089
|
+
readonly secrets: Record<string, IKeyStoreEntryJson>;
|
|
1706
2090
|
}
|
|
1707
2091
|
|
|
1708
2092
|
/**
|
|
@@ -1785,6 +2169,55 @@ declare interface INamedSecret {
|
|
|
1785
2169
|
readonly key: Uint8Array;
|
|
1786
2170
|
}
|
|
1787
2171
|
|
|
2172
|
+
/**
|
|
2173
|
+
* Pluggable backend that persists raw asymmetric private keys outside of the
|
|
2174
|
+
* encrypted keystore vault. Concrete implementations live in platform-specific
|
|
2175
|
+
* packages (e.g. an IndexedDB-backed implementation in `@fgv/ts-web-extras` or
|
|
2176
|
+
* an encrypted-file implementation in `@fgv/ts-chocolate`).
|
|
2177
|
+
*
|
|
2178
|
+
* The keystore writes storage-first: a private key is always stored here
|
|
2179
|
+
* before the corresponding public-key vault entry is committed. Conversely,
|
|
2180
|
+
* deletes hit the vault first and then this storage best-effort. As a result,
|
|
2181
|
+
* crashes or skipped saves can leave orphaned blobs here; callers are expected
|
|
2182
|
+
* to reconcile via {@link CryptoUtils.KeyStore.IPrivateKeyStorage.list} cross-referenced
|
|
2183
|
+
* against the keystore's asymmetric entries.
|
|
2184
|
+
*
|
|
2185
|
+
* @public
|
|
2186
|
+
*/
|
|
2187
|
+
declare interface IPrivateKeyStorage {
|
|
2188
|
+
/**
|
|
2189
|
+
* Whether keys generated for this backend may be marked
|
|
2190
|
+
* `extractable: false`. `true` on backends that store `CryptoKey`
|
|
2191
|
+
* objects directly (e.g. IndexedDB). `false` on backends that must
|
|
2192
|
+
* round-trip via JWK (e.g. encrypted-file backends).
|
|
2193
|
+
*/
|
|
2194
|
+
readonly supportsNonExtractable: boolean;
|
|
2195
|
+
/**
|
|
2196
|
+
* Stores `key` under `id`. Returns the stored `id` on success so the
|
|
2197
|
+
* call can compose into a Result chain.
|
|
2198
|
+
* @param id - Storage handle to write under.
|
|
2199
|
+
* @param key - The private `CryptoKey` to persist.
|
|
2200
|
+
*/
|
|
2201
|
+
store(id: string, key: CryptoKey): Promise<Result<string>>;
|
|
2202
|
+
/**
|
|
2203
|
+
* Loads the private key previously stored under `id`.
|
|
2204
|
+
* @param id - Storage handle to look up.
|
|
2205
|
+
*/
|
|
2206
|
+
load(id: string): Promise<Result<CryptoKey>>;
|
|
2207
|
+
/**
|
|
2208
|
+
* Deletes the entry stored under `id`. Returns the deleted `id` on
|
|
2209
|
+
* success so the call can compose into a Result chain.
|
|
2210
|
+
* @param id - Storage handle to remove.
|
|
2211
|
+
*/
|
|
2212
|
+
delete(id: string): Promise<Result<string>>;
|
|
2213
|
+
/**
|
|
2214
|
+
* Lists every `id` currently held by the backend. Used by consumers to
|
|
2215
|
+
* garbage-collect orphans left by crashes or aborted sessions; the
|
|
2216
|
+
* keystore itself does not invoke this automatically.
|
|
2217
|
+
*/
|
|
2218
|
+
list(): Promise<Result<readonly string[]>>;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
1788
2221
|
/**
|
|
1789
2222
|
* Parameters for a provider completion request.
|
|
1790
2223
|
* @public
|
|
@@ -1884,6 +2317,24 @@ declare interface IProviderListModelsParams {
|
|
|
1884
2317
|
readonly signal?: AbortSignal;
|
|
1885
2318
|
}
|
|
1886
2319
|
|
|
2320
|
+
/**
|
|
2321
|
+
* Result of removing a secret from the key store.
|
|
2322
|
+
* @public
|
|
2323
|
+
*/
|
|
2324
|
+
declare interface IRemoveSecretResult {
|
|
2325
|
+
/**
|
|
2326
|
+
* The secret entry that was removed from the vault.
|
|
2327
|
+
*/
|
|
2328
|
+
readonly entry: IKeyStoreEntry;
|
|
2329
|
+
/**
|
|
2330
|
+
* Best-effort warning from {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete
|
|
2331
|
+
* for asymmetric entries when the storage call failed. The vault entry is
|
|
2332
|
+
* still considered removed and the orphaned blob is left for consumer-side
|
|
2333
|
+
* GC to reconcile.
|
|
2334
|
+
*/
|
|
2335
|
+
readonly warning?: string;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
1887
2338
|
/**
|
|
1888
2339
|
* Required version of options with all fields populated.
|
|
1889
2340
|
* @internal
|
|
@@ -1950,6 +2401,59 @@ declare interface IVariableRef {
|
|
|
1950
2401
|
readonly isSection: boolean;
|
|
1951
2402
|
}
|
|
1952
2403
|
|
|
2404
|
+
/**
|
|
2405
|
+
* Caller-supplied HKDF parameters that domain-separate one
|
|
2406
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} call from another.
|
|
2407
|
+
* Two wraps that share recipient but differ on `salt` or `info` derive distinct
|
|
2408
|
+
* wrap keys, so callers should pick values that bind the wrap to its
|
|
2409
|
+
* application context (e.g. a content hash for `salt` and a secret name for
|
|
2410
|
+
* `info`).
|
|
2411
|
+
*
|
|
2412
|
+
* Both fields are required; pass an empty `Uint8Array` if the caller has no
|
|
2413
|
+
* value to bind on a given axis. Silent defaulting would hide protocol
|
|
2414
|
+
* mistakes, so the API does not pick defaults.
|
|
2415
|
+
* @public
|
|
2416
|
+
*/
|
|
2417
|
+
declare interface IWrapBytesOptions {
|
|
2418
|
+
/**
|
|
2419
|
+
* HKDF salt. Domain-separates this wrap from others in different contexts.
|
|
2420
|
+
* Caller picks; common choices include a content hash, document id, channel
|
|
2421
|
+
* id, etc.
|
|
2422
|
+
*/
|
|
2423
|
+
readonly salt: Uint8Array;
|
|
2424
|
+
/**
|
|
2425
|
+
* HKDF info. Further binds the derived key to a specific use within the
|
|
2426
|
+
* calling application. Caller picks; common choices include a secret name,
|
|
2427
|
+
* message type, or version tag.
|
|
2428
|
+
*/
|
|
2429
|
+
readonly info: Uint8Array;
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* Output of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}. The
|
|
2434
|
+
* shape is JSON-serializable so it can travel directly over the wire or be
|
|
2435
|
+
* persisted as-is.
|
|
2436
|
+
* @public
|
|
2437
|
+
*/
|
|
2438
|
+
declare interface IWrappedBytes {
|
|
2439
|
+
/**
|
|
2440
|
+
* Sender's ephemeral ECDH P-256 public key as a JSON Web Key. The matching
|
|
2441
|
+
* ephemeral private key is dropped after the shared-secret derive.
|
|
2442
|
+
*/
|
|
2443
|
+
readonly ephemeralPublicKey: JsonWebKey;
|
|
2444
|
+
/**
|
|
2445
|
+
* AES-GCM nonce, base64-encoded. 12 bytes (96 bits) — the standard AES-GCM
|
|
2446
|
+
* nonce length.
|
|
2447
|
+
*/
|
|
2448
|
+
readonly nonce: string;
|
|
2449
|
+
/**
|
|
2450
|
+
* AES-GCM ciphertext concatenated with the 16-byte authentication tag,
|
|
2451
|
+
* base64-encoded. Tampering with either the nonce or the ciphertext causes
|
|
2452
|
+
* unwrap to fail GCM authentication.
|
|
2453
|
+
*/
|
|
2454
|
+
readonly ciphertext: string;
|
|
2455
|
+
}
|
|
2456
|
+
|
|
1953
2457
|
/**
|
|
1954
2458
|
* Options for YAML serialization, mirroring commonly-used `js-yaml` `DumpOptions`.
|
|
1955
2459
|
* @public
|
|
@@ -2015,6 +2519,24 @@ declare interface JarRecordParserOptions {
|
|
|
2015
2519
|
readonly fixedContinuationSize?: number;
|
|
2016
2520
|
}
|
|
2017
2521
|
|
|
2522
|
+
/**
|
|
2523
|
+
* In-place shape check for a JSON Web Key. Asserts only that the input is a
|
|
2524
|
+
* non-array object whose `kty` discriminator is a string; every other JWK
|
|
2525
|
+
* field passes through untouched. This is intentionally **not** a true JWK
|
|
2526
|
+
* validator — per-algorithm correctness (RSA `n`/`e`, EC `crv`/`x`/`y`,
|
|
2527
|
+
* key-size constraints, etc.) is delegated to `crypto.subtle.importKey` at
|
|
2528
|
+
* first use, which is the authoritative checker. The "shape" suffix in the
|
|
2529
|
+
* name is the warning sign for readers expecting full validation.
|
|
2530
|
+
* @remarks
|
|
2531
|
+
* Built with `Validators.object` (in-place, non-strict) so unknown JWK fields
|
|
2532
|
+
* survive the round-trip; the cast to `FieldValidators<JsonWebKey>` is required
|
|
2533
|
+
* only because TypeScript's mapped type demands an entry for every key in
|
|
2534
|
+
* `JsonWebKey`. At runtime the `ObjectValidator` only inspects keys present in
|
|
2535
|
+
* the field-validators map.
|
|
2536
|
+
* @public
|
|
2537
|
+
*/
|
|
2538
|
+
declare const jsonWebKeyShape: Validator<JsonWebKey>;
|
|
2539
|
+
|
|
2018
2540
|
/**
|
|
2019
2541
|
* Supported key derivation functions.
|
|
2020
2542
|
* @public
|
|
@@ -2033,18 +2555,54 @@ declare const keyDerivationFunction: Converter<KeyDerivationFunction>;
|
|
|
2033
2555
|
*/
|
|
2034
2556
|
declare const keyDerivationParams: Converter<IKeyDerivationParams>;
|
|
2035
2557
|
|
|
2558
|
+
/**
|
|
2559
|
+
* Asymmetric keypair algorithms supported by the crypto provider.
|
|
2560
|
+
* - `'ecdsa-p256'`: ECDSA over the P-256 curve, for signing.
|
|
2561
|
+
* - `'rsa-oaep-2048'`: RSA-OAEP, 2048-bit modulus with SHA-256, for encryption.
|
|
2562
|
+
* @public
|
|
2563
|
+
*/
|
|
2564
|
+
declare type KeyPairAlgorithm = 'ecdsa-p256' | 'rsa-oaep-2048';
|
|
2565
|
+
|
|
2566
|
+
/**
|
|
2567
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyPairAlgorithm | key pair algorithm}.
|
|
2568
|
+
* @public
|
|
2569
|
+
*/
|
|
2570
|
+
declare const keyPairAlgorithm: Converter<KeyPairAlgorithm>;
|
|
2571
|
+
|
|
2572
|
+
/**
|
|
2573
|
+
* Lookup table from {@link CryptoUtils.KeyPairAlgorithm} to the WebCrypto
|
|
2574
|
+
* parameters needed to drive `crypto.subtle`. Shared between every
|
|
2575
|
+
* {@link CryptoUtils.ICryptoProvider} implementation since both Node and
|
|
2576
|
+
* browser providers speak the same WebCrypto API. Exposed for downstream
|
|
2577
|
+
* provider implementations (e.g. browser-side providers in `@fgv/ts-web-extras`).
|
|
2578
|
+
* @public
|
|
2579
|
+
*/
|
|
2580
|
+
declare const keyPairAlgorithmParams: Readonly<Record<KeyPairAlgorithm, IKeyPairAlgorithmParams>>;
|
|
2581
|
+
|
|
2036
2582
|
declare namespace KeyStore {
|
|
2037
2583
|
export {
|
|
2038
2584
|
Converters_2 as Converters,
|
|
2039
2585
|
KeyStore_2 as KeyStore,
|
|
2040
2586
|
isKeyStoreFile,
|
|
2587
|
+
allKeyPairAlgorithms,
|
|
2588
|
+
KeyPairAlgorithm,
|
|
2041
2589
|
KeyStoreFormat,
|
|
2042
2590
|
KEYSTORE_FORMAT,
|
|
2043
2591
|
DEFAULT_KEYSTORE_ITERATIONS,
|
|
2044
2592
|
MIN_SALT_LENGTH,
|
|
2593
|
+
KeyStoreSymmetricSecretType,
|
|
2594
|
+
allKeyStoreSymmetricSecretTypes,
|
|
2595
|
+
KeyStoreAsymmetricSecretType,
|
|
2596
|
+
allKeyStoreAsymmetricSecretTypes,
|
|
2045
2597
|
KeyStoreSecretType,
|
|
2046
2598
|
allKeyStoreSecretTypes,
|
|
2599
|
+
IKeyStoreSymmetricEntry,
|
|
2600
|
+
IKeyStoreAsymmetricEntry,
|
|
2601
|
+
IKeyStoreEntry,
|
|
2047
2602
|
IKeyStoreSecretEntry,
|
|
2603
|
+
IKeyStoreSymmetricEntryJson,
|
|
2604
|
+
IKeyStoreAsymmetricEntryJson,
|
|
2605
|
+
IKeyStoreEntryJson,
|
|
2048
2606
|
IKeyStoreSecretEntryJson,
|
|
2049
2607
|
IKeyStoreVaultContents,
|
|
2050
2608
|
IKeyStoreFile,
|
|
@@ -2057,7 +2615,11 @@ declare namespace KeyStore {
|
|
|
2057
2615
|
IImportKeyOptions,
|
|
2058
2616
|
IAddSecretFromPasswordOptions,
|
|
2059
2617
|
DEFAULT_SECRET_ITERATIONS,
|
|
2060
|
-
IAddSecretFromPasswordResult
|
|
2618
|
+
IAddSecretFromPasswordResult,
|
|
2619
|
+
IAddKeyPairOptions,
|
|
2620
|
+
IAddKeyPairResult,
|
|
2621
|
+
IRemoveSecretResult,
|
|
2622
|
+
IPrivateKeyStorage
|
|
2061
2623
|
}
|
|
2062
2624
|
}
|
|
2063
2625
|
|
|
@@ -2094,6 +2656,7 @@ declare namespace KeyStore {
|
|
|
2094
2656
|
*/
|
|
2095
2657
|
declare class KeyStore_2 implements IEncryptionProvider {
|
|
2096
2658
|
private readonly _cryptoProvider;
|
|
2659
|
+
private readonly _privateKeyStorage;
|
|
2097
2660
|
private readonly _iterations;
|
|
2098
2661
|
private _keystoreFile;
|
|
2099
2662
|
private _salt;
|
|
@@ -2192,12 +2755,23 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2192
2755
|
*/
|
|
2193
2756
|
listSecrets(): Result<readonly string[]>;
|
|
2194
2757
|
/**
|
|
2195
|
-
* Gets a secret by name.
|
|
2758
|
+
* Gets a secret by name. Returns the {@link CryptoUtils.KeyStore.IKeyStoreEntry | discriminated union}
|
|
2759
|
+
* — callers must check `entry.type` before accessing `key`/`id` since asymmetric
|
|
2760
|
+
* entries carry no raw key material.
|
|
2196
2761
|
* @param name - Name of the secret
|
|
2197
2762
|
* @returns Success with secret entry, Failure if not found or locked
|
|
2198
2763
|
* @public
|
|
2199
2764
|
*/
|
|
2200
|
-
getSecret(name: string): Result<
|
|
2765
|
+
getSecret(name: string): Result<IKeyStoreEntry>;
|
|
2766
|
+
/**
|
|
2767
|
+
* Returns the public-key JWK for an asymmetric-keypair entry.
|
|
2768
|
+
* Available without {@link CryptoUtils.KeyStore.IPrivateKeyStorage} since the
|
|
2769
|
+
* public key lives in the vault metadata directly.
|
|
2770
|
+
* @param name - Name of the entry
|
|
2771
|
+
* @returns Success with the JWK, Failure if not found, locked, or wrong type
|
|
2772
|
+
* @public
|
|
2773
|
+
*/
|
|
2774
|
+
getPublicKeyJwk(name: string): Result<JsonWebKey>;
|
|
2201
2775
|
/**
|
|
2202
2776
|
* Checks if a secret exists.
|
|
2203
2777
|
* @param name - Name of the secret
|
|
@@ -2227,7 +2801,7 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2227
2801
|
* @returns Success with entry, Failure if locked, key invalid, or exists and !replace
|
|
2228
2802
|
* @public
|
|
2229
2803
|
*/
|
|
2230
|
-
importSecret(name: string, key: Uint8Array, options?: IImportKeyOptions): Result<IAddSecretResult
|
|
2804
|
+
importSecret(name: string, key: Uint8Array, options?: IImportKeyOptions): Promise<Result<IAddSecretResult>>;
|
|
2231
2805
|
/**
|
|
2232
2806
|
* Adds a secret derived from a password using PBKDF2.
|
|
2233
2807
|
*
|
|
@@ -2244,12 +2818,16 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2244
2818
|
*/
|
|
2245
2819
|
addSecretFromPassword(name: string, password: string, options?: IAddSecretFromPasswordOptions): Promise<Result<IAddSecretFromPasswordResult>>;
|
|
2246
2820
|
/**
|
|
2247
|
-
* Removes a secret by name.
|
|
2821
|
+
* Removes a secret by name. Vault-first: the in-memory vault entry is dropped
|
|
2822
|
+
* before any storage cleanup runs. For asymmetric-keypair entries, best-effort
|
|
2823
|
+
* calls {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete on the entry's
|
|
2824
|
+
* `id`; a failure is reported via `warning` on the result but does not roll
|
|
2825
|
+
* back the vault removal.
|
|
2248
2826
|
* @param name - Name of the secret to remove
|
|
2249
|
-
* @returns Success with removed entry, Failure if not found or locked
|
|
2827
|
+
* @returns Success with removed entry (and optional warning), Failure if not found or locked
|
|
2250
2828
|
* @public
|
|
2251
2829
|
*/
|
|
2252
|
-
removeSecret(name: string): Result<
|
|
2830
|
+
removeSecret(name: string): Promise<Result<IRemoveSecretResult>>;
|
|
2253
2831
|
/**
|
|
2254
2832
|
* Imports an API key string into the vault.
|
|
2255
2833
|
* The string is UTF-8 encoded and stored with type `'api-key'`.
|
|
@@ -2259,7 +2837,7 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2259
2837
|
* @returns Success with entry, Failure if locked, empty, or exists and !replace
|
|
2260
2838
|
* @public
|
|
2261
2839
|
*/
|
|
2262
|
-
importApiKey(name: string, apiKey: string, options?: IImportSecretOptions): Result<IAddSecretResult
|
|
2840
|
+
importApiKey(name: string, apiKey: string, options?: IImportSecretOptions): Promise<Result<IAddSecretResult>>;
|
|
2263
2841
|
/**
|
|
2264
2842
|
* Retrieves an API key string by name.
|
|
2265
2843
|
* Only works for secrets with type `'api-key'`.
|
|
@@ -2268,6 +2846,41 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2268
2846
|
* @public
|
|
2269
2847
|
*/
|
|
2270
2848
|
getApiKey(name: string): Result<string>;
|
|
2849
|
+
/**
|
|
2850
|
+
* Adds a new asymmetric keypair to the vault. Storage-first: the private key
|
|
2851
|
+
* is stored under a freshly-minted `id` before the public-key vault entry is
|
|
2852
|
+
* committed. If the storage call fails, no vault entry is written and the
|
|
2853
|
+
* operation returns Failure.
|
|
2854
|
+
*
|
|
2855
|
+
* When `replace: true` displaces an existing entry (asymmetric or symmetric),
|
|
2856
|
+
* a fresh `id` is minted; the displaced entry's resources are released
|
|
2857
|
+
* best-effort. Failure of the storage delete is reported via `warning` on the
|
|
2858
|
+
* result but does not roll back the replacement.
|
|
2859
|
+
*
|
|
2860
|
+
* Requires a {@link CryptoUtils.KeyStore.IPrivateKeyStorage} backend
|
|
2861
|
+
* supplied at construction.
|
|
2862
|
+
*
|
|
2863
|
+
* @param name - Unique name for the entry
|
|
2864
|
+
* @param options - Algorithm, optional description, replace flag
|
|
2865
|
+
* @returns Success with the new entry, Failure if locked, no provider, or storage write failed
|
|
2866
|
+
* @public
|
|
2867
|
+
*/
|
|
2868
|
+
addKeyPair(name: string, options: IAddKeyPairOptions): Promise<Result<IAddKeyPairResult>>;
|
|
2869
|
+
/**
|
|
2870
|
+
* Retrieves the keypair for an asymmetric-keypair entry. The private key is
|
|
2871
|
+
* loaded from {@link CryptoUtils.KeyStore.IPrivateKeyStorage} on every call —
|
|
2872
|
+
* the keystore never caches private `CryptoKey` references between calls.
|
|
2873
|
+
* The public key is re-imported from the vault's JWK so callers always
|
|
2874
|
+
* receive a `CryptoKey` rather than the JWK form.
|
|
2875
|
+
* @param name - Name of the entry
|
|
2876
|
+
* @returns Success with `{ publicKey, privateKey }`, Failure if not found,
|
|
2877
|
+
* locked, wrong type, no provider, or storage load failed.
|
|
2878
|
+
* @public
|
|
2879
|
+
*/
|
|
2880
|
+
getKeyPair(name: string): Promise<Result<{
|
|
2881
|
+
publicKey: CryptoKey;
|
|
2882
|
+
privateKey: CryptoKey;
|
|
2883
|
+
}>>;
|
|
2271
2884
|
/**
|
|
2272
2885
|
* Lists secret names filtered by type.
|
|
2273
2886
|
* @param type - The secret type to filter by
|
|
@@ -2282,7 +2895,7 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2282
2895
|
* @returns Success with updated entry, Failure if source not found, target exists, or locked
|
|
2283
2896
|
* @public
|
|
2284
2897
|
*/
|
|
2285
|
-
renameSecret(oldName: string, newName: string): Result<
|
|
2898
|
+
renameSecret(oldName: string, newName: string): Result<IKeyStoreEntry>;
|
|
2286
2899
|
/**
|
|
2287
2900
|
* Saves the key store, returning the encrypted file content.
|
|
2288
2901
|
* Requires the master password to encrypt.
|
|
@@ -2339,6 +2952,23 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2339
2952
|
* Shared by `unlock()` and `unlockWithKey()`.
|
|
2340
2953
|
*/
|
|
2341
2954
|
private _decryptVault;
|
|
2955
|
+
/**
|
|
2956
|
+
* Releases the resources held by an entry being displaced from the vault.
|
|
2957
|
+
* Symmetric entries get their key buffer zeroed in place. Asymmetric entries
|
|
2958
|
+
* have their private-key blob best-effort deleted from
|
|
2959
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage}; if the storage call fails,
|
|
2960
|
+
* a warning string is returned but the displacement still proceeds — the
|
|
2961
|
+
* orphaned blob is left for consumer-side GC. Without a configured provider,
|
|
2962
|
+
* asymmetric cleanup is silently skipped.
|
|
2963
|
+
* @returns A warning string if storage cleanup failed, otherwise undefined.
|
|
2964
|
+
*/
|
|
2965
|
+
private _releaseEntryResources;
|
|
2966
|
+
/**
|
|
2967
|
+
* Mints a fresh UUID v4 storage handle using the crypto provider's
|
|
2968
|
+
* {@link CryptoUtils.ICryptoProvider.generateRandomBytes | generateRandomBytes}.
|
|
2969
|
+
* Random-bytes failures propagate as Failure.
|
|
2970
|
+
*/
|
|
2971
|
+
private _generateId;
|
|
2342
2972
|
}
|
|
2343
2973
|
|
|
2344
2974
|
/**
|
|
@@ -2347,6 +2977,31 @@ declare class KeyStore_2 implements IEncryptionProvider {
|
|
|
2347
2977
|
*/
|
|
2348
2978
|
declare const KEYSTORE_FORMAT: KeyStoreFormat;
|
|
2349
2979
|
|
|
2980
|
+
/**
|
|
2981
|
+
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreAsymmetricEntryJson | asymmetric keypair entry} in JSON form.
|
|
2982
|
+
* The `publicKeyJwk` field passes through {@link CryptoUtils.KeyStore.Converters.jsonWebKeyShape | jsonWebKeyShape}
|
|
2983
|
+
* (shape check only — see its docs); cryptographic correctness is enforced by
|
|
2984
|
+
* `crypto.subtle.importKey` at use.
|
|
2985
|
+
* @public
|
|
2986
|
+
*/
|
|
2987
|
+
declare const keystoreAsymmetricEntryJson: Converter<IKeyStoreAsymmetricEntryJson>;
|
|
2988
|
+
|
|
2989
|
+
/**
|
|
2990
|
+
* Discriminator for asymmetric secret types stored in the vault.
|
|
2991
|
+
* - `'asymmetric-keypair'`: A public/private key pair. The public key is held in
|
|
2992
|
+
* the vault as a JWK; the private key lives in the supplied
|
|
2993
|
+
* {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider.
|
|
2994
|
+
* @public
|
|
2995
|
+
*/
|
|
2996
|
+
declare type KeyStoreAsymmetricSecretType = 'asymmetric-keypair';
|
|
2997
|
+
|
|
2998
|
+
/**
|
|
2999
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyStoreAsymmetricSecretType | asymmetric secret type} discriminator.
|
|
3000
|
+
* Accepts only `'asymmetric-keypair'`.
|
|
3001
|
+
* @public
|
|
3002
|
+
*/
|
|
3003
|
+
declare const keystoreAsymmetricSecretType: Converter<KeyStoreAsymmetricSecretType>;
|
|
3004
|
+
|
|
2350
3005
|
/**
|
|
2351
3006
|
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreFile | encrypted key store file}.
|
|
2352
3007
|
* @public
|
|
@@ -2372,25 +3027,59 @@ declare const keystoreFormat: Converter<KeyStoreFormat>;
|
|
|
2372
3027
|
declare type KeyStoreLockState = 'locked' | 'unlocked';
|
|
2373
3028
|
|
|
2374
3029
|
/**
|
|
2375
|
-
*
|
|
2376
|
-
*
|
|
3030
|
+
* Discriminated-union converter for any {@link CryptoUtils.KeyStore.IKeyStoreEntryJson | key store entry} in JSON form.
|
|
3031
|
+
* Routes by the `type` field: `'asymmetric-keypair'` is parsed by
|
|
3032
|
+
* {@link CryptoUtils.KeyStore.Converters.keystoreAsymmetricEntryJson | keystoreAsymmetricEntryJson},
|
|
3033
|
+
* anything else (including a missing `type` field for backwards compatibility) by
|
|
3034
|
+
* {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson}.
|
|
3035
|
+
* @public
|
|
3036
|
+
*/
|
|
3037
|
+
declare const keystoreSecretEntryJson: Converter<IKeyStoreEntryJson>;
|
|
3038
|
+
|
|
3039
|
+
/**
|
|
3040
|
+
* Discriminator for any secret type stored in the vault.
|
|
3041
|
+
* @public
|
|
3042
|
+
*/
|
|
3043
|
+
declare type KeyStoreSecretType = KeyStoreSymmetricSecretType | KeyStoreAsymmetricSecretType;
|
|
3044
|
+
|
|
3045
|
+
/**
|
|
3046
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | any key store secret type} discriminator.
|
|
3047
|
+
* Accepts both symmetric and asymmetric type values.
|
|
3048
|
+
* @public
|
|
3049
|
+
*/
|
|
3050
|
+
declare const keystoreSecretType: Converter<KeyStoreSecretType>;
|
|
3051
|
+
|
|
3052
|
+
/**
|
|
3053
|
+
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson | symmetric secret entry} in JSON form.
|
|
3054
|
+
*
|
|
3055
|
+
* @remarks
|
|
3056
|
+
* Backwards compatibility with vaults written before asymmetric-keypair
|
|
3057
|
+
* support: those entries may lack the `type` discriminator on the wire. To
|
|
3058
|
+
* keep the model type honest (`type` is required on
|
|
3059
|
+
* {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}, see its docs),
|
|
3060
|
+
* we declare `type` in `optionalFields` so the inner `Converters.object` will
|
|
3061
|
+
* accept input without it, then `.map()` injects the default
|
|
3062
|
+
* `'encryption-key'` when missing. The output therefore always carries the
|
|
3063
|
+
* discriminator and downstream code never sees the legacy missing-type form.
|
|
3064
|
+
*
|
|
2377
3065
|
* @public
|
|
2378
3066
|
*/
|
|
2379
|
-
declare const
|
|
3067
|
+
declare const keystoreSymmetricEntryJson: Converter<IKeyStoreSymmetricEntryJson>;
|
|
2380
3068
|
|
|
2381
3069
|
/**
|
|
2382
|
-
* Discriminator for secret types stored in the vault.
|
|
3070
|
+
* Discriminator for symmetric secret types stored in the vault.
|
|
2383
3071
|
* - `'encryption-key'`: A 32-byte AES-256 encryption key.
|
|
2384
3072
|
* - `'api-key'`: An arbitrary-length API key string (UTF-8 encoded).
|
|
2385
3073
|
* @public
|
|
2386
3074
|
*/
|
|
2387
|
-
declare type
|
|
3075
|
+
declare type KeyStoreSymmetricSecretType = 'encryption-key' | 'api-key';
|
|
2388
3076
|
|
|
2389
3077
|
/**
|
|
2390
|
-
* Converter for {@link CryptoUtils.KeyStore.
|
|
3078
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyStoreSymmetricSecretType | symmetric secret type} discriminator.
|
|
3079
|
+
* Accepts only `'encryption-key'` and `'api-key'`.
|
|
2391
3080
|
* @public
|
|
2392
3081
|
*/
|
|
2393
|
-
declare const
|
|
3082
|
+
declare const keystoreSymmetricSecretType: Converter<KeyStoreSymmetricSecretType>;
|
|
2394
3083
|
|
|
2395
3084
|
/**
|
|
2396
3085
|
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreVaultContents | key store vault contents} (decrypted state).
|
|
@@ -2604,6 +3293,50 @@ declare class NodeCryptoProvider implements ICryptoProvider {
|
|
|
2604
3293
|
* @returns Success with decoded bytes, or Failure if invalid base64
|
|
2605
3294
|
*/
|
|
2606
3295
|
fromBase64(base64: string): Result<Uint8Array>;
|
|
3296
|
+
/**
|
|
3297
|
+
* Generates a new asymmetric keypair using Node's WebCrypto.
|
|
3298
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
|
|
3299
|
+
* @param extractable - Whether the resulting keys may be exported.
|
|
3300
|
+
* @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
|
|
3301
|
+
*/
|
|
3302
|
+
generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
|
|
3303
|
+
/**
|
|
3304
|
+
* Exports a public `CryptoKey` as a JSON Web Key.
|
|
3305
|
+
* @remarks
|
|
3306
|
+
* Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
|
|
3307
|
+
* does not enforce public-vs-private; without this guard a caller that
|
|
3308
|
+
* passed an extractable private key would receive its private fields
|
|
3309
|
+
* (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
|
|
3310
|
+
* @param publicKey - Extractable public key to export.
|
|
3311
|
+
* @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
|
|
3312
|
+
*/
|
|
3313
|
+
exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
|
|
3314
|
+
/**
|
|
3315
|
+
* Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
|
|
3316
|
+
* @param jwk - The JSON Web Key produced by a prior export.
|
|
3317
|
+
* @param algorithm - The algorithm the key was generated for.
|
|
3318
|
+
* @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
|
|
3319
|
+
*/
|
|
3320
|
+
importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
3321
|
+
/**
|
|
3322
|
+
* Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
3323
|
+
* ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
|
|
3324
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
|
|
3325
|
+
* @param plaintext - The bytes to wrap.
|
|
3326
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
3327
|
+
* @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
3328
|
+
* @returns `Success` with the wrapped payload, or `Failure` with an error.
|
|
3329
|
+
*/
|
|
3330
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
3331
|
+
/**
|
|
3332
|
+
* Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
3333
|
+
* key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
|
|
3334
|
+
* @param wrapped - The wrapped payload.
|
|
3335
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
|
|
3336
|
+
* @param options - HKDF salt and info matching the wrap call.
|
|
3337
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with an error.
|
|
3338
|
+
*/
|
|
3339
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
2607
3340
|
}
|
|
2608
3341
|
|
|
2609
3342
|
/**
|
|
@@ -2833,6 +3566,22 @@ export { RecordJar }
|
|
|
2833
3566
|
*/
|
|
2834
3567
|
declare function resolveEffectiveTools(descriptor: IAiProviderDescriptor, settingsTools?: ReadonlyArray<IAiToolEnablement>, perCallTools?: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<AiServerToolConfig>;
|
|
2835
3568
|
|
|
3569
|
+
/**
|
|
3570
|
+
* Resolve the image-generation capability that applies to a given model id
|
|
3571
|
+
* for a provider. Returns the entry from
|
|
3572
|
+
* {@link IAiProviderDescriptor.imageGeneration} whose `modelPrefix` is the
|
|
3573
|
+
* longest prefix of `modelId`. Ties are broken by first-encountered, so rule
|
|
3574
|
+
* order does not matter for correctness — only for tie-breaking among rules
|
|
3575
|
+
* with identical-length prefixes (an unusual case).
|
|
3576
|
+
*
|
|
3577
|
+
* @param descriptor - The provider descriptor
|
|
3578
|
+
* @param modelId - The resolved image model id
|
|
3579
|
+
* @returns The matching capability, or `undefined` when no rule matches or
|
|
3580
|
+
* the provider declares no image-generation capabilities.
|
|
3581
|
+
* @public
|
|
3582
|
+
*/
|
|
3583
|
+
declare function resolveImageCapability(descriptor: IAiProviderDescriptor, modelId: string): IAiImageModelCapability | undefined;
|
|
3584
|
+
|
|
2836
3585
|
/**
|
|
2837
3586
|
* Resolves a {@link ModelSpec} to a concrete model string given an optional context key.
|
|
2838
3587
|
*
|
|
@@ -2856,6 +3605,16 @@ declare function resolveModel(spec: ModelSpec, context?: string): string;
|
|
|
2856
3605
|
*/
|
|
2857
3606
|
declare type SecretProvider = (secretName: string) => Promise<Result<Uint8Array>>;
|
|
2858
3607
|
|
|
3608
|
+
/**
|
|
3609
|
+
* Whether a provider declares any image-generation capability at all.
|
|
3610
|
+
*
|
|
3611
|
+
* @param descriptor - The provider descriptor
|
|
3612
|
+
* @returns `true` when {@link IAiProviderDescriptor.imageGeneration} has at
|
|
3613
|
+
* least one entry; `false` otherwise.
|
|
3614
|
+
* @public
|
|
3615
|
+
*/
|
|
3616
|
+
declare function supportsImageGeneration(descriptor: IAiProviderDescriptor): boolean;
|
|
3617
|
+
|
|
2859
3618
|
/**
|
|
2860
3619
|
* Helper function to create a `StringConverter` which converts
|
|
2861
3620
|
* `unknown` to `string`, applying template conversions supplied at construction time or at
|