@fgv/ts-extras 5.0.2 → 5.1.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +6 -2
- package/dist/index.js +5 -1
- package/dist/packlets/ai-assist/apiClient.js +484 -0
- package/dist/packlets/ai-assist/converters.js +121 -0
- package/dist/packlets/ai-assist/index.js +10 -0
- package/dist/packlets/ai-assist/model.js +90 -0
- package/dist/packlets/ai-assist/registry.js +145 -0
- package/dist/packlets/ai-assist/toolFormats.js +160 -0
- package/dist/packlets/crypto-utils/constants.js +48 -0
- package/dist/packlets/crypto-utils/converters.js +155 -0
- package/dist/packlets/crypto-utils/directEncryptionProvider.js +86 -0
- package/dist/packlets/crypto-utils/encryptedFile.js +161 -0
- package/dist/packlets/crypto-utils/index.browser.js +41 -0
- package/dist/packlets/crypto-utils/index.js +41 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +84 -0
- package/dist/packlets/crypto-utils/keystore/index.js +31 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +758 -0
- package/dist/packlets/crypto-utils/keystore/model.js +64 -0
- package/dist/packlets/crypto-utils/model.js +39 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +159 -0
- package/dist/packlets/experimental/formatter.js +1 -1
- package/dist/packlets/mustache/index.js +23 -0
- package/dist/packlets/mustache/interfaces.js +25 -0
- package/dist/packlets/mustache/mustacheTemplate.js +242 -0
- package/dist/packlets/record-jar/recordJarHelpers.js +1 -1
- package/dist/packlets/yaml/converters.js +46 -0
- package/dist/packlets/yaml/index.js +23 -0
- package/dist/packlets/zip-file-tree/index.js +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +6 -2
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +40 -0
- package/dist/ts-extras.d.ts +1964 -112
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +3 -1
- package/lib/index.browser.js +6 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -1
- package/lib/packlets/ai-assist/apiClient.d.ts +60 -0
- package/lib/packlets/ai-assist/apiClient.js +488 -0
- package/lib/packlets/ai-assist/converters.d.ts +55 -0
- package/lib/packlets/ai-assist/converters.js +124 -0
- package/lib/packlets/ai-assist/index.d.ts +10 -0
- package/lib/packlets/ai-assist/index.js +33 -0
- package/lib/packlets/ai-assist/model.d.ts +222 -0
- package/lib/packlets/ai-assist/model.js +95 -0
- package/lib/packlets/ai-assist/registry.d.ts +25 -0
- package/lib/packlets/ai-assist/registry.js +150 -0
- package/lib/packlets/ai-assist/toolFormats.d.ts +44 -0
- package/lib/packlets/ai-assist/toolFormats.js +166 -0
- package/lib/packlets/crypto-utils/constants.d.ts +26 -0
- package/lib/packlets/crypto-utils/constants.js +51 -0
- package/lib/packlets/crypto-utils/converters.d.ts +58 -0
- package/lib/packlets/crypto-utils/converters.js +192 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts +69 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.js +90 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts +88 -0
- package/lib/packlets/crypto-utils/encryptedFile.js +201 -0
- package/lib/packlets/crypto-utils/index.browser.d.ts +14 -0
- package/lib/packlets/crypto-utils/index.browser.js +91 -0
- package/lib/packlets/crypto-utils/index.d.ts +15 -0
- package/lib/packlets/crypto-utils/index.js +88 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +29 -0
- package/lib/packlets/crypto-utils/keystore/converters.js +87 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts +9 -0
- package/lib/packlets/crypto-utils/keystore/index.js +71 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +239 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +795 -0
- package/lib/packlets/crypto-utils/keystore/model.d.ts +245 -0
- package/lib/packlets/crypto-utils/keystore/model.js +68 -0
- package/lib/packlets/crypto-utils/model.d.ts +236 -0
- package/lib/packlets/crypto-utils/model.js +76 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +62 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +196 -0
- package/lib/packlets/experimental/formatter.d.ts +1 -1
- package/lib/packlets/experimental/formatter.js +1 -1
- package/lib/packlets/mustache/index.d.ts +3 -0
- package/lib/packlets/mustache/index.js +27 -0
- package/lib/packlets/mustache/interfaces.d.ts +97 -0
- package/lib/packlets/mustache/interfaces.js +26 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts +76 -0
- package/lib/packlets/mustache/mustacheTemplate.js +249 -0
- package/lib/packlets/record-jar/recordJarHelpers.js +1 -1
- package/lib/packlets/yaml/converters.d.ts +9 -0
- package/lib/packlets/yaml/converters.js +82 -0
- package/lib/packlets/yaml/index.d.ts +2 -0
- package/lib/packlets/yaml/index.js +39 -0
- package/lib/packlets/zip-file-tree/index.d.ts +1 -0
- package/lib/packlets/zip-file-tree/index.js +15 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +5 -1
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +6 -2
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +27 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +43 -0
- package/package.json +50 -31
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Copyright (c) 2024 Erik Fortune
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
// copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
// SOFTWARE.
|
|
20
|
+
import { captureResult, fail, succeed } from '@fgv/ts-utils';
|
|
21
|
+
import * as Constants from './constants';
|
|
22
|
+
import { createEncryptedFileConverter } from './converters';
|
|
23
|
+
import { isEncryptedFile } from './model';
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Base64 Utilities
|
|
26
|
+
// ============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Encodes a `Uint8Array` to a base64 string.
|
|
29
|
+
* @param bytes - Bytes to encode
|
|
30
|
+
* @returns Base64 string
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
/* c8 ignore start - Browser-only fallback cannot be tested in Node.js environment */
|
|
34
|
+
export function toBase64(bytes) {
|
|
35
|
+
if (typeof Buffer !== 'undefined') {
|
|
36
|
+
return Buffer.from(bytes).toString('base64');
|
|
37
|
+
}
|
|
38
|
+
// Browser fallback
|
|
39
|
+
let binary = '';
|
|
40
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
41
|
+
binary += String.fromCharCode(bytes[i]);
|
|
42
|
+
}
|
|
43
|
+
return btoa(binary);
|
|
44
|
+
}
|
|
45
|
+
/* c8 ignore stop */
|
|
46
|
+
/**
|
|
47
|
+
* Decodes a base64 string to a `Uint8Array`.
|
|
48
|
+
* @param base64 - Base64 string to decode
|
|
49
|
+
* @returns Decoded bytes
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
/* c8 ignore start - Browser-only fallback cannot be tested in Node.js environment */
|
|
53
|
+
export function fromBase64(base64) {
|
|
54
|
+
if (typeof Buffer !== 'undefined') {
|
|
55
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
56
|
+
}
|
|
57
|
+
// Browser fallback
|
|
58
|
+
const binary = atob(base64);
|
|
59
|
+
const bytes = new Uint8Array(binary.length);
|
|
60
|
+
for (let i = 0; i < binary.length; i++) {
|
|
61
|
+
bytes[i] = binary.charCodeAt(i);
|
|
62
|
+
}
|
|
63
|
+
return bytes;
|
|
64
|
+
}
|
|
65
|
+
// ============================================================================
|
|
66
|
+
// Encryption Functions
|
|
67
|
+
// ============================================================================
|
|
68
|
+
/**
|
|
69
|
+
* Creates an {@link CryptoUtils.IEncryptedFile | encrypted file} from JSON content.
|
|
70
|
+
* @typeParam TMetadata - Type of optional unencrypted metadata
|
|
71
|
+
* @param params - Encryption parameters
|
|
72
|
+
* @returns `Success` with encrypted file structure, or `Failure` with an error.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export async function createEncryptedFile(params) {
|
|
76
|
+
const { content, secretName, key, metadata, metadataConverter, keyDerivation, cryptoProvider } = params;
|
|
77
|
+
// Validate metadata if converter provided
|
|
78
|
+
/* c8 ignore next 6 - metadata validation path exercised via higher-level tests */
|
|
79
|
+
if (metadata !== undefined && metadataConverter !== undefined) {
|
|
80
|
+
const metadataResult = metadataConverter.convert(metadata);
|
|
81
|
+
if (metadataResult.isFailure()) {
|
|
82
|
+
return fail(`Invalid metadata: ${metadataResult.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Serialize content to JSON string
|
|
86
|
+
const jsonResult = captureResult(() => JSON.stringify(content));
|
|
87
|
+
if (jsonResult.isFailure()) {
|
|
88
|
+
return fail(`Failed to serialize content: ${jsonResult.message}`);
|
|
89
|
+
}
|
|
90
|
+
// Encrypt the JSON string
|
|
91
|
+
const encryptResult = await cryptoProvider.encrypt(jsonResult.value, key);
|
|
92
|
+
if (encryptResult.isFailure()) {
|
|
93
|
+
return fail(`Encryption failed: ${encryptResult.message}`);
|
|
94
|
+
}
|
|
95
|
+
const { iv, authTag, encryptedData } = encryptResult.value;
|
|
96
|
+
// Build the encrypted file structure
|
|
97
|
+
const encryptedFile = Object.assign(Object.assign({ format: Constants.ENCRYPTED_FILE_FORMAT, secretName, algorithm: Constants.DEFAULT_ALGORITHM, iv: toBase64(iv), authTag: toBase64(authTag), encryptedData: toBase64(encryptedData) }, (metadata !== undefined ? { metadata } : {})), (keyDerivation !== undefined ? { keyDerivation } : {}));
|
|
98
|
+
return succeed(encryptedFile);
|
|
99
|
+
}
|
|
100
|
+
// ============================================================================
|
|
101
|
+
// Decryption Functions
|
|
102
|
+
// ============================================================================
|
|
103
|
+
/**
|
|
104
|
+
* Decrypts an {@link CryptoUtils.IEncryptedFile | encrypted file} and returns the JSON content.
|
|
105
|
+
* @typeParam TPayload - Expected type of decrypted content
|
|
106
|
+
* @param file - The encrypted file structure
|
|
107
|
+
* @param key - The decryption key (32 bytes for AES-256)
|
|
108
|
+
* @param cryptoProvider - {@link CryptoUtils.ICryptoProvider | Crypto provider} to use for decryption
|
|
109
|
+
* @param payloadConverter - Optional converter to validate and convert decrypted content
|
|
110
|
+
* @returns `Success` with decrypted content, or `Failure` with an error.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export async function decryptFile(file, key, cryptoProvider, payloadConverter) {
|
|
114
|
+
// Decode base64 values
|
|
115
|
+
const iv = fromBase64(file.iv);
|
|
116
|
+
const authTag = fromBase64(file.authTag);
|
|
117
|
+
const encryptedData = fromBase64(file.encryptedData);
|
|
118
|
+
// Decrypt
|
|
119
|
+
const decryptResult = await cryptoProvider.decrypt(encryptedData, key, iv, authTag);
|
|
120
|
+
if (decryptResult.isFailure()) {
|
|
121
|
+
return fail(decryptResult.message);
|
|
122
|
+
}
|
|
123
|
+
// Parse JSON
|
|
124
|
+
const parseResult = captureResult(() => JSON.parse(decryptResult.value)).withErrorFormat((e) => `Failed to parse decrypted content as JSON: ${e}`);
|
|
125
|
+
/* c8 ignore next 3 - JSON parse failure only occurs with corrupted encrypted data */
|
|
126
|
+
if (parseResult.isFailure()) {
|
|
127
|
+
return parseResult;
|
|
128
|
+
}
|
|
129
|
+
// Validate with converter if provided
|
|
130
|
+
/* c8 ignore next 3 - payload converter path exercised via higher-level tests */
|
|
131
|
+
if (payloadConverter !== undefined) {
|
|
132
|
+
return payloadConverter.convert(parseResult.value);
|
|
133
|
+
}
|
|
134
|
+
return parseResult;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Attempts to parse and decrypt a JSON object as an {@link CryptoUtils.IEncryptedFile | encrypted file}.
|
|
138
|
+
* @typeParam TPayload - Expected type of decrypted content
|
|
139
|
+
* @typeParam TMetadata - Type of optional unencrypted metadata
|
|
140
|
+
* @param json - JSON object that may be an encrypted file
|
|
141
|
+
* @param key - The decryption key (32 bytes for AES-256)
|
|
142
|
+
* @param cryptoProvider - {@link CryptoUtils.ICryptoProvider | Crypto provider} to use for decryption
|
|
143
|
+
* @param payloadConverter - Optional converter to validate and convert decrypted content
|
|
144
|
+
* @param metadataConverter - Optional converter to validate metadata before decryption
|
|
145
|
+
* @returns `Success` with decrypted content, or `Failure` with an error (including if not encrypted)
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
export async function tryDecryptFile(json, key, cryptoProvider, payloadConverter, metadataConverter) {
|
|
149
|
+
// Check if it's an encrypted file
|
|
150
|
+
if (!isEncryptedFile(json)) {
|
|
151
|
+
return fail('Not an encrypted file');
|
|
152
|
+
}
|
|
153
|
+
// Validate and convert to typed encrypted file
|
|
154
|
+
const fileConverter = createEncryptedFileConverter(metadataConverter);
|
|
155
|
+
const fileResult = fileConverter.convert(json);
|
|
156
|
+
if (fileResult.isFailure()) {
|
|
157
|
+
return fail(`Invalid encrypted file format: ${fileResult.message}`);
|
|
158
|
+
}
|
|
159
|
+
return decryptFile(fileResult.value, key, cryptoProvider, payloadConverter);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=encryptedFile.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) 2024 Erik Fortune
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
// copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
// SOFTWARE.
|
|
20
|
+
/**
|
|
21
|
+
* Crypto utilities for encrypted file handling and key management (browser version).
|
|
22
|
+
* Note: For browser crypto provider, use \@fgv/ts-web-extras.
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
// Re-export all types from model
|
|
26
|
+
export * from './model';
|
|
27
|
+
// Constants
|
|
28
|
+
export { AES_256_KEY_SIZE, DEFAULT_ALGORITHM, ENCRYPTED_FILE_FORMAT, GCM_AUTH_TAG_SIZE, GCM_IV_SIZE } from './constants';
|
|
29
|
+
// KeyStore namespace
|
|
30
|
+
import * as KeyStore from './keystore';
|
|
31
|
+
export { KeyStore };
|
|
32
|
+
// Converters namespace
|
|
33
|
+
import * as Converters from './converters';
|
|
34
|
+
export { Converters };
|
|
35
|
+
// Direct encryption provider
|
|
36
|
+
export { DirectEncryptionProvider } from './directEncryptionProvider';
|
|
37
|
+
// Note: NodeCryptoProvider is NOT exported in browser version
|
|
38
|
+
// Use BrowserCryptoProvider from @fgv/ts-web-extras instead
|
|
39
|
+
// Encrypted file helpers
|
|
40
|
+
export { createEncryptedFile, decryptFile, fromBase64, toBase64, tryDecryptFile } from './encryptedFile';
|
|
41
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) 2024 Erik Fortune
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
// copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
// SOFTWARE.
|
|
20
|
+
/**
|
|
21
|
+
* Crypto utilities for encrypted file handling and key management.
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
// Re-export all types from model
|
|
25
|
+
export * from './model';
|
|
26
|
+
// Constants
|
|
27
|
+
import * as Constants from './constants';
|
|
28
|
+
export { Constants };
|
|
29
|
+
// KeyStore namespace
|
|
30
|
+
import * as KeyStore from './keystore';
|
|
31
|
+
export { KeyStore };
|
|
32
|
+
// Converters namespace
|
|
33
|
+
import * as Converters from './converters';
|
|
34
|
+
export { Converters };
|
|
35
|
+
// Direct encryption provider
|
|
36
|
+
export { DirectEncryptionProvider } from './directEncryptionProvider';
|
|
37
|
+
// Node.js crypto provider (Node.js environment only)
|
|
38
|
+
export { NodeCryptoProvider, nodeCryptoProvider } from './nodeCryptoProvider';
|
|
39
|
+
// Encrypted file helpers
|
|
40
|
+
export { createEncryptedFile, decryptFile, fromBase64, toBase64, tryDecryptFile } from './encryptedFile';
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) 2026 Erik Fortune
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
// copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
// SOFTWARE.
|
|
20
|
+
import { Converters } from '@fgv/ts-utils';
|
|
21
|
+
import { base64String, encryptionAlgorithm, keyDerivationParams } from '../converters';
|
|
22
|
+
import { allKeyStoreSecretTypes, KEYSTORE_FORMAT } from './model';
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Key Store Format Converter
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyStoreFormat | key store format} version.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const keystoreFormat = Converters.enumeratedValue([
|
|
31
|
+
KEYSTORE_FORMAT
|
|
32
|
+
]);
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// Secret Type Converter
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | key store secret type} discriminator.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export const keystoreSecretType = Converters.enumeratedValue(allKeyStoreSecretTypes);
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Secret Entry Converters
|
|
43
|
+
// ============================================================================
|
|
44
|
+
/**
|
|
45
|
+
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreSecretEntryJson | key store secret entry} in JSON format.
|
|
46
|
+
* The `type` field is optional for backwards compatibility — missing means `'encryption-key'`.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export const keystoreSecretEntryJson = Converters.object({
|
|
50
|
+
name: Converters.string,
|
|
51
|
+
type: keystoreSecretType,
|
|
52
|
+
key: base64String,
|
|
53
|
+
description: Converters.string,
|
|
54
|
+
createdAt: Converters.string
|
|
55
|
+
}, {
|
|
56
|
+
optionalFields: ['type', 'description']
|
|
57
|
+
});
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// Vault Contents Converter
|
|
60
|
+
// ============================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreVaultContents | key store vault contents} (decrypted state).
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export const keystoreVaultContents = Converters.object({
|
|
66
|
+
version: keystoreFormat,
|
|
67
|
+
secrets: Converters.recordOf(keystoreSecretEntryJson)
|
|
68
|
+
});
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Key Store File Converter
|
|
71
|
+
// ============================================================================
|
|
72
|
+
/**
|
|
73
|
+
* Converter for {@link CryptoUtils.KeyStore.IKeyStoreFile | encrypted key store file}.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export const keystoreFile = Converters.object({
|
|
77
|
+
format: keystoreFormat,
|
|
78
|
+
algorithm: encryptionAlgorithm,
|
|
79
|
+
iv: base64String,
|
|
80
|
+
authTag: base64String,
|
|
81
|
+
encryptedData: base64String,
|
|
82
|
+
keyDerivation: keyDerivationParams
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) 2026 Erik Fortune
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
// copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
// SOFTWARE.
|
|
20
|
+
/**
|
|
21
|
+
* Key store module for password-protected secret management.
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
// Types and interfaces
|
|
25
|
+
export * from './model';
|
|
26
|
+
// Converters namespace
|
|
27
|
+
import * as Converters from './converters';
|
|
28
|
+
export { Converters };
|
|
29
|
+
// Key store class
|
|
30
|
+
export { KeyStore } from './keyStore';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|