@katlux/toolkit 0.1.1-alpha.137 → 0.1.1-alpha.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +1 -1
  3. package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +1 -1
  4. package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
  5. package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
  6. package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
  7. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +2 -2
  8. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +2 -2
  9. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +2 -2
  10. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +2 -2
  11. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +7 -7
  12. package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +7 -7
  13. package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
  14. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +4 -4
  15. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +4 -4
  16. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +2 -2
  17. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +2 -2
  18. package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +11 -0
  19. package/dist/runtime/components/KGantt/KGantt.global.vue +3 -0
  20. package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +11 -0
  21. package/dist/runtime/components/KGantt/KGantt.logic.d.ts +7 -1
  22. package/dist/runtime/components/KGantt/KGantt.logic.js +26 -7
  23. package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +2 -2
  24. package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +2 -2
  25. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +2 -2
  26. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +2 -2
  27. package/dist/runtime/components/KRadiobox/KRadiobox.global.d.vue.ts +1 -1
  28. package/dist/runtime/components/KRadiobox/KRadiobox.global.vue.d.ts +1 -1
  29. package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +2 -2
  30. package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +2 -2
  31. package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +3 -3
  32. package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +3 -3
  33. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +1 -1
  34. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +1 -1
  35. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
  36. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
  37. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +3 -3
  38. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +3 -3
  39. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +1 -1
  40. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +1 -1
  41. package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +11 -0
  42. package/dist/runtime/presets/default/components/KGantt/KGantt.vue +53 -12
  43. package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +11 -0
  44. package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue +2 -0
  45. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +1 -1
  46. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +1 -1
  47. package/dist/skills/KATLUX_INDEX.md +1 -0
  48. package/dist/skills/katlux-components/components/KGantt.md +10 -1
  49. package/dist/skills/katlux-config/SKILL.md +7 -7
  50. package/dist/skills/katlux-presets/SKILL.md +2 -0
  51. package/dist/skills/katlux-presets/creating-a-preset.md +269 -0
  52. package/dist/skills/katlux-providers/SKILL.md +1 -1
  53. package/dist/skills/katlux-providers/providers/encryption.md +43 -6
  54. package/package.json +2 -2
@@ -0,0 +1,269 @@
1
+ # Creating a Custom Katlux Preset from Scratch
2
+
3
+ This guide details how to create and maintain a custom preset in a Katlux project from scratch, covering both **project-level presets** (in a Nuxt application) and **reusable standalone npm preset packages**.
4
+
5
+ ---
6
+
7
+ ## 1. Overview of Katlux Presets
8
+
9
+ Katlux presets are designed around a **zero-copy, cascading fallback** architecture:
10
+ - **Token-Only by default**: Over 90% of theming is handled purely through CSS custom properties without modifying component templates.
11
+ - **Selective Component Overrides**: You only create component templates (`.vue` files) for the specific components you want to restructure or customize beyond CSS.
12
+ - **Automatic Fallback Cascade**: Any token or component not defined in your preset automatically cascades back to the base preset (e.g. `modern`) or the built-in `default` preset.
13
+
14
+ ---
15
+
16
+ ## 2. Quick Scaffolding
17
+
18
+ ### Option A: Using the CLI
19
+ Run the `create-preset` command from the root of your project:
20
+
21
+ ```bash
22
+ # Based on 'modern' preset
23
+ npx @katlux/toolkit create-preset my-brand --base=modern
24
+
25
+ # Or without a base (falls back directly to 'default')
26
+ npx @katlux/toolkit create-preset my-brand
27
+ ```
28
+
29
+ ### Option B: Using the MCP Tool
30
+ If you have Katlux MCP installed:
31
+ ```json
32
+ {
33
+ "name": "my-brand",
34
+ "base": "modern"
35
+ }
36
+ ```
37
+ Tool: `katlux_create_preset`
38
+
39
+ ---
40
+
41
+ ## 3. Directory Structure
42
+
43
+ A project preset lives in the `presets/` folder at your project root:
44
+
45
+ ```text
46
+ presets/
47
+ └── my-brand/
48
+ ├── assets/
49
+ │ └── css-variables.scss # Design tokens scoped to the preset
50
+ └── components/ # Optional component template overrides
51
+ ├── KButton/
52
+ │ └── KButton.vue
53
+ └── KLayout/
54
+ └── KLayout.vue
55
+ ```
56
+
57
+ > [!NOTE]
58
+ > `@katlux/toolkit` **automatically discovers and injects** stylesheets found in `presets/<preset-name>/assets/css-variables.scss` (or `.css`). No manual import in `nuxt.config.ts` is required.
59
+
60
+ ---
61
+
62
+ ## 4. Step 1: Defining Design Tokens (`css-variables.scss`)
63
+
64
+ All CSS custom properties must be scoped to the preset's attribute selector: `[data-preset~="<preset-name>"]`.
65
+
66
+ ```scss
67
+ /* presets/my-brand/assets/css-variables.scss */
68
+
69
+ [data-preset~="my-brand"] {
70
+ /* 1. Brand Colors */
71
+ --primary-50: #eef2ff;
72
+ --primary-500: #6366f1;
73
+ --primary-600: #4f46e5;
74
+ --primary-700: #4338ca;
75
+
76
+ /* 2. Surfaces & Backgrounds */
77
+ --bg-primary: #ffffff;
78
+ --bg-secondary: #f8fafc;
79
+ --border-color: #e2e8f0;
80
+
81
+ /* 3. Typography & Spacing */
82
+ --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
83
+ --border-radius-sm: 6px;
84
+ --border-radius-md: 10px;
85
+ --border-radius-lg: 16px;
86
+
87
+ /* 4. Component-Specific Tokens */
88
+ --button-padding: 0.625rem 1.25rem;
89
+ --button-radius: var(--border-radius-md);
90
+ --button-bg-primary: var(--primary-500);
91
+ --button-color-primary: #ffffff;
92
+ }
93
+ ```
94
+
95
+ > [!TIP]
96
+ > Always use `[data-preset~="my-brand"]` (space-separated attribute selector) to support preset stacks like `activePreset: ['my-brand', 'dark']`. Avoid using `!important`.
97
+
98
+ ---
99
+
100
+ ## 5. Step 2: Overriding Component Templates (Optional)
101
+
102
+ You only need to add components if you want to alter the DOM structure, replace internal sub-elements, or customize behavior beyond CSS variables.
103
+
104
+ ### Folder and Naming Conventions
105
+ - Component overrides are **case-sensitive**.
106
+ - The path must follow: `presets/<preset-name>/components/<ComponentName>/<ComponentName>.vue`.
107
+ - Example: `presets/my-brand/components/KButton/KButton.vue`.
108
+
109
+ ### Writing a Component Template
110
+ Use the component's logic props and standard slots.
111
+
112
+ ```vue
113
+ <!-- presets/my-brand/components/KButton/KButton.vue -->
114
+ <template lang="pug">
115
+ button.KButton.my-brand(
116
+ :type="type"
117
+ :class="[buttonClasses, customClasses]"
118
+ :disabled="disabled || loading"
119
+ @click="handleClick"
120
+ )
121
+ span.k-spinner(v-if="loading")
122
+ slot(name="prefix")
123
+ slot
124
+ slot(name="suffix")
125
+ </template>
126
+
127
+ <script lang="ts" setup>
128
+ interface ButtonProps {
129
+ type?: 'button' | 'submit' | 'reset'
130
+ buttonClasses?: any
131
+ disabled?: boolean
132
+ loading?: boolean
133
+ customClasses?: string
134
+ handleClick?: (e: MouseEvent) => void
135
+ }
136
+
137
+ withDefaults(defineProps<ButtonProps>(), {
138
+ type: 'button',
139
+ disabled: false,
140
+ loading: false
141
+ })
142
+ </script>
143
+
144
+ <style lang="scss" scoped>
145
+ .KButton.my-brand {
146
+ display: inline-flex;
147
+ align-items: center;
148
+ justify-content: center;
149
+ gap: var(--gap-sm, 0.5rem);
150
+ padding: var(--button-padding);
151
+ border-radius: var(--button-radius);
152
+ font-family: var(--font-family-base);
153
+ transition: all 0.2s ease-in-out;
154
+
155
+ &:hover:not(:disabled) {
156
+ transform: translateY(-1px);
157
+ box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
158
+ }
159
+ }
160
+ </style>
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 6. Step 3: Registering & Activating the Preset (`app.config.ts`)
166
+
167
+ Enable your preset in your project's `app.config.ts`:
168
+
169
+ ### A. When Based on Another Preset (e.g. `modern`)
170
+ ```typescript
171
+ // app.config.ts
172
+ export default defineAppConfig({
173
+ katluxToolkit: {
174
+ presetList: [
175
+ { name: 'Default', value: 'default' },
176
+ { name: 'Modern', value: 'modern' },
177
+ { name: 'My Brand', value: ['my-brand', 'modern'] }
178
+ ],
179
+ // Priority: my-brand -> modern -> default
180
+ activePreset: ['my-brand', 'modern']
181
+ }
182
+ })
183
+ ```
184
+
185
+ ### B. When Standalone (Direct Fallback to `default`)
186
+ ```typescript
187
+ // app.config.ts
188
+ export default defineAppConfig({
189
+ katluxToolkit: {
190
+ presetList: [
191
+ { name: 'Default', value: 'default' },
192
+ { name: 'My Brand', value: 'my-brand' }
193
+ ],
194
+ activePreset: 'my-brand'
195
+ }
196
+ })
197
+ ```
198
+
199
+ ---
200
+
201
+ ## 7. Creating an Installable NPM Preset Package
202
+
203
+ If you are developing a standalone preset package (e.g. `@my-org/katlux-preset-corp`):
204
+
205
+ ### 1. Package Directory Structure
206
+ ```text
207
+ katlux-preset-corp/
208
+ ├── package.json
209
+ ├── src/
210
+ │ ├── module.ts # Nuxt module definition
211
+ │ └── runtime/
212
+ │ ├── assets/
213
+ │ │ └── css-variables.scss
214
+ │ ├── components/
215
+ │ │ └── KButton/KButton.vue
216
+ │ └── plugin.ts # Runtime component registration
217
+ ```
218
+
219
+ ### 2. Runtime Plugin (`src/runtime/plugin.ts`)
220
+ Register component loaders using `registerPresetComponents`:
221
+
222
+ ```typescript
223
+ import { defineNuxtPlugin } from '#app'
224
+ // @ts-ignore
225
+ import { registerPresetComponents } from '#imports'
226
+
227
+ export default defineNuxtPlugin(() => {
228
+ const loaders = {
229
+ './components/KButton/KButton.vue': () => import('./components/KButton/KButton.vue')
230
+ }
231
+
232
+ if (typeof registerPresetComponents === 'function') {
233
+ registerPresetComponents('corp', loaders)
234
+ }
235
+ })
236
+ ```
237
+
238
+ ### 3. Nuxt Module (`src/module.ts`)
239
+ Inject the stylesheet and register the runtime plugin:
240
+
241
+ ```typescript
242
+ import { defineNuxtModule, createResolver, addPlugin } from '@nuxt/kit'
243
+
244
+ export default defineNuxtModule({
245
+ meta: {
246
+ name: '@my-org/katlux-preset-corp',
247
+ configKey: 'katluxPresetCorp'
248
+ },
249
+ setup(options, nuxt) {
250
+ const resolver = createResolver(import.meta.url)
251
+
252
+ // Automatically inject CSS variables
253
+ nuxt.options.css = nuxt.options.css || []
254
+ nuxt.options.css.push(resolver.resolve('./runtime/assets/css-variables.scss'))
255
+
256
+ // Register runtime plugin
257
+ addPlugin(resolver.resolve('./runtime/plugin'))
258
+ }
259
+ })
260
+ ```
261
+
262
+ ---
263
+
264
+ ## 8. Best Practices Checklist
265
+
266
+ - [ ] **Do not copy entire base presets**: Only write tokens you intend to customize. Let uncustomized tokens fall back.
267
+ - [ ] **Scope to `[data-preset~="name"]`**: Avoid unscoped root styles or `!important`.
268
+ - [ ] **Preserve logic and props**: When overriding a component template, maintain the props and slot signatures exposed by the component logic layer.
269
+ - [ ] **Persist dynamic UI state externally**: Switching presets with structural component overrides causes container unmounting; keep transient state (active tabs, table selections) in Pinia or URL query params.
@@ -50,7 +50,7 @@ description: Complete reference and atomic index for Katlux data management arch
50
50
  | `RequestQueue` | Offline PWA operation queue | Queues mutations offline in IndexedDB, auto-flushes on reconnect | [RequestQueue.md](providers/RequestQueue.md) |
51
51
  | `KatluxIndexedDB` | High-performance IndexedDB wrapper | Client-side persistent storage for offline data and large cache entries | [KatluxIndexedDB.md](providers/KatluxIndexedDB.md) |
52
52
  | `CacheProvider` | Tiered multi-layer caching engine | Memory, BrowserSession, LocalStorage, IndexedDB, Cookie tiers | [caching.md](providers/caching.md) |
53
- | `EncryptionProvider` | WebCrypto & NodeCrypto encryption | AES-GCM 256-bit payload encryption, SSR zero-knowledge transit, AAD validation | [encryption.md](providers/encryption.md) |
53
+ | `EncryptionProvider` & `CKeyManager` | WebCrypto & NodeCrypto cryptographic suite | AES-GCM 256-bit field/payload encryption, built-in keyring rotation, strict decryption, dynamic AAD, zero-leak ADEK re-wrapping, RFC 8785 JCS access grants, domain-separated derivation | [encryption.md](providers/encryption.md) |
54
54
 
55
55
  ---
56
56
 
@@ -19,20 +19,40 @@ Zero-dependency, native cryptographic toolkit for end-to-end client-side, in-fli
19
19
  - `CWebCryptoEncryptionProvider`: AES-GCM-256 with optional PBKDF2/HKDF key derivation. Built-in AEAD, 100% backward-compatible.
20
20
  - `CWebCryptoAESCBCProvider`: Authenticated AES-CBC-256 + HMAC-SHA-256 (Encrypt-then-MAC) for legacy system compatibility.
21
21
  - `CRSAEncryptionProvider`: Asymmetric RSA-OAEP-4096 + AES-GCM-256 hybrid cipher for arbitrary-sized single-recipient payloads.
22
- - `CECDHEncryptionProvider`: Forward-secure Elliptic Curve Diffie-Hellman (P-256/384/521) + HKDF + AES-GCM. Ephemeral key per encryption. Ideal for multi-user role sharing (e.g. Kazan Ledger Account Symmetric Key wrapping).
22
+ - `CECDHEncryptionProvider`: Forward-secure Elliptic Curve Diffie-Hellman (P-256/384/521) + HKDF + AES-GCM. Ephemeral key per encryption. Ideal for multi-user role sharing (e.g. Account Symmetric Key wrapping).
23
23
  - `CNodeCryptoEncryptionProvider`: Server-side synchronous AES-GCM via `node:crypto` (`encryptSync`/`decryptSync`). 100% binary-interoperable with `CWebCryptoEncryptionProvider`.
24
24
  - **Provider Methods (`IEncryptionProvider` / `AEncryptionProvider`)**:
25
- - `encrypt(data: any, options?: IEncryptionContext): Promise<IEncryptedPayload | any>`: Encrypts data into an envelope or field-encrypted record (strictly idempotent; already-encrypted fields/envelopes are never double-encrypted). Attaches `kid` when specified.
26
- - `decrypt(payload: any, options?: IEncryptionContext): Promise<any>`: Decrypts envelope back into original data, immediately zeroing plaintext byte buffers in memory. Automatically leverages record-level DEK caching across multi-field records for up to 90% latency reduction.
27
- - `warmupKey(options?: IEncryptionContext): Promise<void>`: Pre-derives and caches CryptoKey / Buffer in memory. Supported on `CWebCrypto`, `CWebCryptoAESCBC`, and `CNodeCrypto`.
25
+ - `encrypt(data: any, options?: IEncryptionContext): Promise<IEncryptedPayload | any>`: Encrypts data into an envelope or field-encrypted record (strictly idempotent; already-encrypted fields/envelopes are never double-encrypted). Attaches `kid` when specified or uses `activeKid`.
26
+ - `decrypt(payload: any, options?: IEncryptionContext): Promise<any>`: Decrypts envelope back into original data, immediately zeroing plaintext byte buffers in memory. Dynamically routes decryption through `keys[envelope.kid]` or fallback keys, validating against `allowedKids`. Automatically leverages record-level DEK caching across multi-field records for up to 90% latency reduction.
27
+ - `warmupKey(options?: IEncryptionContext): Promise<void>`: Pre-derives and caches CryptoKey / Buffer in memory. When a keyring (`keys`) is configured, resolves and warms up all keys concurrently via `Promise.all`. Supported on `CWebCrypto`, `CWebCryptoAESCBC`, and `CNodeCrypto` (`warmupKeySync` also available on Node).
28
+ - `setKeyring(keys: Record<string, TKeyProvider | IKeyPair>, activeKid?: string): void`: Replaces or updates the active keyring dictionary and optionally sets the active outbound key identifier.
29
+ - `getKeyring(): Record<string, TKeyProvider | IKeyPair>`: Returns the currently configured keyring dictionary.
30
+ - `setActiveKid(kid: string): void`: Sets the active key identifier used for all outbound encryption.
31
+ - `getActiveKid(): string | undefined`: Returns the currently active outbound key identifier.
28
32
  - `isEncrypted(payload: any): boolean`: Polymorphic check if given object is an encrypted envelope. Also available as static `AEncryptionProvider.isEncrypted(payload)`.
29
- - `clearKeys() / dispose()`: Wipes in-memory key caches, zeroes mutable Buffer bytes, and clears sensitive asymmetric keys upon logout/session end.
33
+ - `clearKeys() / dispose()`: Wipes in-memory key caches, zeroes mutable Buffer bytes and keyring caches, and clears sensitive asymmetric keys upon logout/session end.
30
34
  - `resolveRawKey(keyProvider?: TKeyProvider)`: (Protected on `AEncryptionProvider`) Resolves key or async keyProvider callback. Supports `string`, `Uint8Array`, `ArrayBuffer`, and `CryptoKey` without byte corruption.
31
35
  - **PEM Import/Export (`CKeyManager` / `CRSA` / `CECDH`)**:
32
36
  - `importPublicKeyFromPEM(pem, ...)`: Imports SPKI PEM string to `CryptoKey`.
33
37
  - `importPrivateKeyFromPEM(pem, ...)`: Imports PKCS#8 PEM string to `CryptoKey`.
34
38
  - `exportPublicKeyToPEM(key)`: Exports `CryptoKey` to standard SPKI PEM string.
35
39
  - `exportPrivateKeyToPEM(key)`: Exports `CryptoKey` to standard PKCS#8 PEM string.
40
+ - **Account Key Wrapping & Re-Wrapping (`CKeyManager`)**:
41
+ - `wrapAccountKeyForUser(adek, userPublicKey): Promise<string>`: Wraps an ADEK for a user using RSA-OAEP.
42
+ - `unwrapAccountKeyForUser(wrappedKeyBase64, userPrivateKey, unwrappedKeyAlgorithm?, extractable?): Promise<CryptoKey>`: Restores an unextractable AES-GCM ADEK from envelope using RSA-OAEP.
43
+ - `rewrapAccountKeyForUser(wrappedKeyBase64, myPrivateKey, recipientPublicKey): Promise<string>`: Atomically re-wraps an ADEK envelope for a new recipient without exposing raw extractable keys to application memory, guaranteeing memory zeroization via `finally`.
44
+ - **Digital Signatures & Access Grants (`CKeyManager` / `canonicalizeJson`)**:
45
+ - `canonicalizeJson(value): string`: Serializes a JavaScript value to a deterministic, canonical JSON string conforming to RFC 8785 (JCS).
46
+ - `generateSigningKeyPair(curve?, extractable?): Promise<IKeyPair>`: Generates an ECDSA P-256 signing key pair.
47
+ - `getKeyFingerprint(publicKey): Promise<string>`: Generates a deterministic SHA-256 fingerprint for a public key formatted as `SHA256:<base64url>`.
48
+ - `sign(data, privateKey): Promise<string>`: Signs arbitrary data or JSON objects using an ECDSA P-256 private key (objects automatically canonicalized via RFC 8785).
49
+ - `verify(data, signature, publicKey): Promise<boolean>`: Verifies an ECDSA P-256 signature against original data or JSON object.
50
+ - `signGrant(grant: IAccessGrant, granterPrivateKey, granterPublicKey?): Promise<ISignedGrant>`: Signs a structured access grant, embedding signature and granter key fingerprint.
51
+ - `verifyGrant(signedGrant: ISignedGrant, granterPublicKey, options?): Promise<boolean>`: Verifies authenticity, integrity, and granter key fingerprint of an access grant, defeating key-substitution attacks.
52
+ - **Domain-Separated Key Derivation (`CKeyManager.deriveAuthAndEncryptionKeys`)**:
53
+ - `deriveAuthAndEncryptionKeys(password, salt?, options?): Promise<IDomainDerivedKeys>`: Hardened two-stage derivation pipeline. PBKDF2 stretches low-entropy user password and salt, then HKDF-Expand produces two cryptographically isolated keys (`authKey` for authentication challenges and `encryptionKey` for AES-GCM data encryption) using domain-separated context tags (`katlux-auth-key-v1` and `katlux-encryption-key-v1`). Full compromise of `authKey` reveals zero mathematical information about `encryptionKey`. Intermediate master secret buffers are immediately zeroized in memory.
54
+
55
+
36
56
 
37
57
  - **Envelope Contract (`IEncryptedPayload`)**:
38
58
  ```ts
@@ -56,10 +76,19 @@ interface IEncryptedPayload {
56
76
  ```ts
57
77
  interface IProviderEncryptionOptions {
58
78
  enabled?: boolean // Master toggle (default: false)
59
- key?: TKeyProvider // string | Uint8Array | ArrayBuffer | CryptoKey | (() => Promise<...>)
79
+ key?: TKeyProvider // Single key or key provider (legacy/simple mode)
80
+ keys?: Record<string, TKeyProvider | IKeyPair> // Built-in Keyring dictionary mapping kid to keys
81
+ activeKid?: string // Active key identifier from keys to use for outbound encryption
60
82
  kid?: string // Key identifier / version (e.g. 'v1', 'tenant-a-key-2026')
83
+ aad?: string | Uint8Array | ArrayBuffer | ((record: any, field: string) => string | Uint8Array | ArrayBuffer) // AEAD Additional Data or dynamic callback
84
+ aadFields?: string[] // Sibling record fields to deterministically bind into AAD (e.g. ['contact_id', 'version'])
85
+ baseAad?: string // Optional base prefix for AAD context binding
61
86
  decryptOnSSR?: boolean // default: false. Prevents SSR decryption unless explicitly enabled with server secrets
62
87
  fields?: string[] // Field-level encryption: only encrypt listed fields
88
+ strict?: boolean // Enforces strict decryption: unencrypted plaintext in `fields` triggers injection violation; defaults allowedAlgorithms to ['AES-GCM']
89
+ allowedAlgorithms?: string[] // Whitelist of permitted cipher algorithms (e.g. ['AES-GCM'])
90
+ allowedKids?: string[] // Whitelist of permitted Key Identifiers (kid); defaults to Object.keys(keys)
91
+ onDecryptError?: ((info: IDecryptErrorInfo) => any) | boolean | string // Per-field error hook, safe fallback marker, or true for '[⚠ Decryption Error]'
63
92
  searchIndex?: boolean // Enables HMAC-SHA256 blind index and trigram search index on encrypted fields
64
93
  hmacKey?: TKeyProvider // Optional dedicated HMAC key for search indexing (defaults to encryption key)
65
94
  algorithm?: 'AES-GCM' | string // default: 'AES-GCM'
@@ -148,4 +177,12 @@ In multi-tenant, field-encrypted, and SSR scenarios, Katlux cryptographic provid
148
177
  - **Nonce Misuse Resistance**: Initialization Vectors (IVs) are freshly generated via cryptographically secure RNG per operation (12 bytes for GCM, 16 bytes for CBC) with proven uniqueness across sibling fields, batch arrays, and concurrent executions.
149
178
  - **Deterministic Search Token Segregation**: `CSearchIndex` HMAC-SHA256 blind index tokens are deterministic for search matching and strictly segregated from non-deterministic ciphertext IVs.
150
179
  - **Non-Extractable Tenant Keys**: `CKeyManager.generateAccountDataKey()` and `CKeyManager.unwrapAccountKeyForUser()` produce `CryptoKey` instances with `extractable: false` by default, safeguarding unwrapped symmetric tenant keys against exfiltration via developer tools or malicious extensions.
180
+ - **Atomic Key Re-Wrapping (`CKeyManager.rewrapAccountKeyForUser`)**: When sharing an Account Data Encryption Key (ADEK) between users, `CKeyManager.rewrapAccountKeyForUser(wrappedKey, myPrivateKey, recipientPublicKey)` atomically decrypts the raw key material and re-encrypts it with the recipient's RSA-OAEP public key without ever exposing the raw extractable symmetric key to caller application memory or leaving extractable CryptoKeys in memory. Immediate memory zeroization (`fill(0)`) is guaranteed across all paths.
151
181
  - **SSR Confidentiality & Cache Auth Guard**: With `decryptOnSSR: false` (the secure zero-trust default), plaintext is never exposed in server memory or serialized HTML hydration payloads. Requests with `cookie` or `Authorization` headers automatically bypass shared server caches (`CApplicationCache`), preventing cross-user session cache poisoning.
182
+
183
+ #### Built-in Keyring & Multi-Key Rotation Architecture
184
+ - **Zero-Downtime Key Rotation**: Configuring `keys: { 'k2025': key1, 'k2026': key2 }` alongside `activeKid: 'k2026'` ensures all outbound writes are automatically tagged with `kid: 'k2026'` and encrypted with `key2`, while legacy records tagged with `k2025` decrypt seamlessly under `key1`.
185
+ - **Automatic Whitelisting & Untrusted `kid` Protection**: `allowedKids` automatically defaults to `Object.keys(keys)` when `keys` is provided. Incoming envelopes carrying an unknown or unregistered `kid` are immediately rejected with an unauthorized key security error (`Unauthorized key: kid '${payload.kid}' is not in allowedKids.`).
186
+ - **Concurrent Multi-Key Warmup**: Calling `warmupKey()` (or `warmupKeySync()` on Node) resolves and primes all cryptographic keys across the entire keyring concurrently using `Promise.all`, preventing runtime latency spikes or race conditions during rotation periods.
187
+ - **Dynamic Runtime Keyring Management**: Keyrings can be rotated dynamically at runtime using `provider.setKeyring(newKeys, newActiveKid)` or `provider.setActiveKid(newKid)` without recreating provider instances or dropping existing session caches.
188
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
- "version": "0.1.1-alpha.137",
3
+ "version": "0.1.1-alpha.139",
4
4
  "description": "Core UI toolkit and utilities for the Katlux ecosystem",
5
5
  "author": "Katlux",
6
6
  "license": "Apache-2.0",
@@ -54,7 +54,7 @@
54
54
  "**/*.sass"
55
55
  ],
56
56
  "dependencies": {
57
- "@katlux/providers": "^0.1.1-alpha.124",
57
+ "@katlux/providers": "^0.1.1-alpha.127",
58
58
  "@nuxt/kit": "^3.12.0",
59
59
  "@nuxtjs/i18n": "^10.4.0",
60
60
  "pug": "^3.0.0",