@katlux/providers 0.1.1-alpha.126 → 0.1.1-alpha.128

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.d.cts CHANGED
@@ -17,6 +17,14 @@ interface IEncryptedPayload {
17
17
  }
18
18
  type TRawKey = string | CryptoKey | Uint8Array | ArrayBuffer;
19
19
  type TKeyProvider = TRawKey | (() => TRawKey | Promise<TRawKey>);
20
+ interface IDecryptErrorInfo {
21
+ record: any;
22
+ field: string;
23
+ value: any;
24
+ error: Error;
25
+ index?: number;
26
+ }
27
+ declare const DECRYPT_ERROR_SENTINEL: unique symbol;
20
28
  interface IEncryptionContext {
21
29
  url?: string;
22
30
  method?: string;
@@ -25,12 +33,39 @@ interface IEncryptionContext {
25
33
  bindRequestContextAad?: boolean;
26
34
  /** Whitelist of specific field names to encrypt/decrypt (e.g. ['name', 'surname']). Any unlisted field remains plaintext. */
27
35
  fields?: string[];
36
+ /**
37
+ * Enforces strict encryption validation. When true:
38
+ * 1. Any field in `fields` that is NOT an encrypted envelope triggers a decryption error.
39
+ * 2. Envelope algorithm MUST match `allowedAlgorithms` (defaults to ['AES-GCM']).
40
+ * 3. Envelope `kid` (if present) MUST match `allowedKids`.
41
+ */
42
+ strict?: boolean;
43
+ /** Whitelist of permitted cryptographic algorithms (e.g. ['AES-GCM']). Defaults to ['AES-GCM'] in strict mode. */
44
+ allowedAlgorithms?: string[];
45
+ /** Whitelist of allowed Key Identifiers (kid). */
46
+ allowedKids?: string[];
47
+ /** Built-in Keyring dictionary mapping Key Identifiers (kid) to keys or key provider functions */
48
+ keys?: Record<string, TKeyProvider | IKeyPair>;
49
+ /** Active key identifier from `keys` to use for all outbound encryption operations */
50
+ activeKid?: string;
51
+ /**
52
+ * Hook invoked whenever decryption fails for an individual field or row.
53
+ * Can return a fallback cell value (e.g. sentinel or marker), or string/boolean.
54
+ */
55
+ onDecryptError?: ((info: IDecryptErrorInfo) => any) | boolean | string;
28
56
  key?: TKeyProvider | IKeyPair;
29
57
  /** Optional Key Identifier for multi-role key routing and rotation */
30
58
  kid?: string;
31
59
  keyId?: string;
32
- /** Authenticated Additional Data (AAD) bound to the ciphertext to prevent field/record swapping */
33
- aad?: string | Uint8Array | ArrayBuffer;
60
+ /**
61
+ * Authenticated Additional Data (AAD) bound to the ciphertext to prevent field/record swapping.
62
+ * Can be static string/buffer or dynamic callback evaluated per record and field.
63
+ */
64
+ aad?: string | Uint8Array | ArrayBuffer | ((record: any, field: string) => string | Uint8Array | ArrayBuffer);
65
+ /** Sibling record fields to deterministically bind into AEAD additional data (e.g. ['contact_id', 'version']) */
66
+ aadFields?: string[];
67
+ /** Optional base AAD prefix when aadFields or dynamic aad is enabled */
68
+ baseAad?: string;
34
69
  /** Internal flag indicating that key derivation has already been warmed for this batch */
35
70
  _warmedKey?: any;
36
71
  /** Whether to encrypt/decrypt individual values while preserving JSON keys (default: true) */
@@ -46,12 +81,35 @@ interface IEncryptionContext {
46
81
  kdfHash?: 'SHA-256' | 'SHA-512';
47
82
  info?: string | Uint8Array | ArrayBuffer;
48
83
  }
84
+ /**
85
+ * Context options for single scalar field encryption/decryption with bound AAD.
86
+ */
87
+ interface IFieldEncryptionContext extends Omit<IEncryptionContext, 'aadFields'> {
88
+ /** Record identifier to bind into AAD */
89
+ recordId?: string | number;
90
+ /** Target field name being encrypted/decrypted */
91
+ fieldName?: string;
92
+ /** Sibling record fields (map or array of keys) to deterministically bind into AEAD */
93
+ aadFields?: Record<string, any> | string[];
94
+ /** Optional base AAD prefix */
95
+ baseAad?: string;
96
+ }
49
97
  interface IEncryptionProvider {
50
98
  encrypt(data: any, options?: IEncryptionContext): Promise<IEncryptedPayload | any>;
51
99
  decrypt(payload: IEncryptedPayload | any, options?: IEncryptionContext): Promise<any>;
100
+ /** Encrypts a single scalar value with contextual AAD binding */
101
+ encryptField?(value: any, context?: IFieldEncryptionContext): Promise<IEncryptedPayload>;
102
+ /** Decrypts a single scalar field envelope with contextual AAD */
103
+ decryptField?(envelope: IEncryptedPayload, context?: IFieldEncryptionContext): Promise<any>;
104
+ /** Computes deterministic HMAC-SHA256 blind index hash */
105
+ computeBlindIndex?(value: any, hmacKey?: CryptoKey | TKeyProvider): Promise<string>;
52
106
  warmupKey?(options?: IEncryptionContext): Promise<void>;
53
107
  isEncrypted?(payload: any): boolean;
54
108
  setDefaultKey?(key: TKeyProvider | IKeyPair): void;
109
+ setKeyring?(keys: Record<string, TKeyProvider | IKeyPair>, activeKid?: string): void;
110
+ getKeyring?(): Record<string, TKeyProvider | IKeyPair> | undefined;
111
+ setActiveKid?(kid: string): void;
112
+ getActiveKid?(): string | undefined;
55
113
  clearKeys?(): void;
56
114
  dispose?(): void;
57
115
  [Symbol.dispose]?(): void;
@@ -62,11 +120,22 @@ interface IProviderEncryptionOptions {
62
120
  enabled?: boolean;
63
121
  /** Secret key, passphrase, CryptoKey, key pair, or async key provider function */
64
122
  key?: TKeyProvider | IKeyPair;
123
+ /** Built-in Keyring dictionary mapping Key Identifiers (kid) to keys or key provider functions */
124
+ keys?: Record<string, TKeyProvider | IKeyPair>;
125
+ /** Active key identifier from `keys` to use for all outbound encryption operations */
126
+ activeKid?: string;
65
127
  /** Optional Key Identifier for multi-role key routing and key rotation */
66
128
  kid?: string;
67
129
  keyId?: string;
68
- /** Authenticated Additional Data (AAD) bound to the ciphertext to prevent field/record swapping */
69
- aad?: string | Uint8Array | ArrayBuffer;
130
+ /**
131
+ * Authenticated Additional Data (AAD) bound to the ciphertext to prevent field/record swapping.
132
+ * Can be static string/buffer or dynamic callback evaluated per record and field.
133
+ */
134
+ aad?: string | Uint8Array | ArrayBuffer | ((record: any, field: string) => string | Uint8Array | ArrayBuffer);
135
+ /** Sibling record fields to deterministically bind into AEAD additional data (e.g. ['contact_id', 'version']) */
136
+ aadFields?: string[];
137
+ /** Optional base AAD prefix when aadFields or dynamic aad is enabled */
138
+ baseAad?: string;
70
139
  /**
71
140
  * Whether to bind the request context (HTTP method and URL as `req:${method}:${url}`) into AEAD Authenticated Additional Data (AAD).
72
141
  * Defaults to true when URL or method is provided in context, mitigating replay and cross-endpoint confusion attacks (BUG-015).
@@ -85,8 +154,29 @@ interface IProviderEncryptionOptions {
85
154
  lazy?: boolean;
86
155
  /** Whitelist of specific field names to encrypt/decrypt (e.g. ['name', 'surname']). Any unlisted field remains plaintext. */
87
156
  fields?: string[];
157
+ /**
158
+ * Enforces strict encryption validation. When true:
159
+ * 1. Any field in `fields` that is NOT an encrypted envelope triggers a decryption error.
160
+ * 2. Envelope algorithm MUST match `allowedAlgorithms` (defaults to ['AES-GCM']).
161
+ * 3. Envelope `kid` (if present) MUST match `allowedKids`.
162
+ */
163
+ strict?: boolean;
164
+ /** Whitelist of permitted cryptographic algorithms (e.g. ['AES-GCM']). Defaults to ['AES-GCM'] in strict mode. */
165
+ allowedAlgorithms?: string[];
166
+ /** Whitelist of allowed Key Identifiers (kid). */
167
+ allowedKids?: string[];
168
+ /**
169
+ * Hook invoked whenever decryption fails for an individual field or row.
170
+ * Can return a fallback cell value (e.g. sentinel or marker), or string/boolean.
171
+ */
172
+ onDecryptError?: ((info: IDecryptErrorInfo) => any) | boolean | string;
88
173
  /** Enable HMAC-SHA256 blind indexing and trigram search index on encrypted fields for local DataProviders */
89
174
  searchIndex?: boolean;
175
+ /**
176
+ * Set to true if API endpoints or data sources return pre-encrypted ciphertext envelopes.
177
+ * When true, DataProviders decrypt search fields during ingest to populate CSearchIndex.
178
+ */
179
+ preEncrypted?: boolean;
90
180
  /** Optional dedicated HMAC key for search indexing (defaults to encryption key if omitted) */
91
181
  hmacKey?: TKeyProvider;
92
182
  /** Cryptographic algorithm identifier (defaults to 'AES-GCM') */
@@ -157,6 +247,56 @@ interface IHKDFFromSecretOptions {
157
247
  keyLength?: 128 | 256;
158
248
  extractable?: boolean;
159
249
  }
250
+ /**
251
+ * Structured organization access grant for role-based key sharing.
252
+ */
253
+ interface IAccessGrant {
254
+ grantId: string;
255
+ accountId: string;
256
+ granteeUserId: string;
257
+ granterUserId: string;
258
+ wrappedKey: string;
259
+ expiresAt?: number;
260
+ permissions?: string[];
261
+ }
262
+ /**
263
+ * Digitally signed access grant container with granter key fingerprint.
264
+ */
265
+ interface ISignedGrant {
266
+ grant: IAccessGrant;
267
+ signature: string;
268
+ fingerprint: string;
269
+ }
270
+ /**
271
+ * Options for verifying access grant validity.
272
+ */
273
+ interface IVerifyGrantOptions {
274
+ /** If true, checks whether grant.expiresAt is past the current timestamp */
275
+ checkExpiry?: boolean;
276
+ /** Optional reference timestamp for expiration checking (defaults to Date.now()) */
277
+ now?: number;
278
+ }
279
+ /**
280
+ * Result container for domain-separated key derivation.
281
+ */
282
+ interface IDomainDerivedKeys {
283
+ authKey: CryptoKey;
284
+ encryptionKey: CryptoKey;
285
+ salt: string;
286
+ }
287
+ /**
288
+ * Configuration options for domain-separated key derivation.
289
+ */
290
+ interface IDeriveAuthAndEncryptionOptions {
291
+ iterations?: number;
292
+ hash?: 'SHA-256' | 'SHA-512';
293
+ authKeyLength?: 128 | 256;
294
+ encryptionKeyLength?: 128 | 256;
295
+ authAlgorithm?: 'HMAC' | 'AES-GCM';
296
+ authInfo?: string;
297
+ encryptionInfo?: string;
298
+ extractable?: boolean;
299
+ }
160
300
 
161
301
  /**
162
302
  * types.ts — Framework-agnostic hydration and platform abstraction contracts.
@@ -568,6 +708,11 @@ declare class CSearchIndex {
568
708
  * Computes a deterministic HMAC-SHA256 token for a term.
569
709
  */
570
710
  computeToken(term: any): Promise<string>;
711
+ /**
712
+ * Computes a deterministic HMAC-SHA256 blind index hash for a term using the configured HMAC key.
713
+ * Performs Unicode NFKC normalization, trimming, and lowercasing.
714
+ */
715
+ computeBlindIndex(term: any): Promise<string>;
571
716
  /**
572
717
  * Computes HMAC-SHA256 tokens for all trigrams of a term.
573
718
  */
@@ -576,6 +721,11 @@ declare class CSearchIndex {
576
721
  * Indexes a single row before its fields are encrypted.
577
722
  */
578
723
  indexRow(row: any, plaintextFields?: Record<string, any>): Promise<void>;
724
+ /**
725
+ * Indexes a row using pre-decrypted plaintext field values.
726
+ * Allows indexing rows that contain pre-encrypted ciphertext envelopes in allData.
727
+ */
728
+ indexRowDecrypted(row: any, decryptedPlaintext: Record<string, any>): Promise<void>;
579
729
  /**
580
730
  * Indexes an array of rows.
581
731
  */
@@ -607,6 +757,11 @@ declare abstract class AEncryptedClientProvider<TRow = TDataRow> extends ADataPr
607
757
  clearEncryption(): void;
608
758
  protected encryptRows(rows: TRow[]): Promise<TRow[]>;
609
759
  protected encryptRowsChunked(rows: TRow[], options?: ISetDataChunkedOptions): Promise<TRow[]>;
760
+ /**
761
+ * Indexes pre-encrypted rows by performing a transient in-memory decryption pass
762
+ * on search fields to populate CSearchIndex without mutating underlying encrypted records in allData.
763
+ */
764
+ indexPreEncryptedRows(rows: TRow[]): Promise<void>;
610
765
  decryptRows(rows: TRow[]): Promise<{
611
766
  rows: TRow[];
612
767
  decrypted: boolean;
@@ -1544,7 +1699,17 @@ declare function onPlatformReady(cb: () => void): void;
1544
1699
  */
1545
1700
  declare abstract class AEncryptionProvider implements IEncryptionProvider {
1546
1701
  protected defaultKey?: TKeyProvider | IKeyPair;
1547
- constructor(key?: TKeyProvider | IKeyPair);
1702
+ protected _hmacKey?: TKeyProvider;
1703
+ protected keys?: Record<string, TKeyProvider | IKeyPair>;
1704
+ protected activeKid?: string;
1705
+ protected allowedKids?: string[];
1706
+ constructor(key?: TKeyProvider | IKeyPair, options?: {
1707
+ keys?: Record<string, TKeyProvider | IKeyPair>;
1708
+ activeKid?: string;
1709
+ allowedKids?: string[];
1710
+ hmacKey?: TKeyProvider;
1711
+ [key: string]: any;
1712
+ });
1548
1713
  /**
1549
1714
  * Sets or updates the default secret key, CryptoKey, or async key provider function.
1550
1715
  */
@@ -1553,6 +1718,35 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
1553
1718
  * Retrieves the currently configured default key or key provider callback.
1554
1719
  */
1555
1720
  getDefaultKey(): TKeyProvider | IKeyPair | undefined;
1721
+ /**
1722
+ * Configures a keyring dictionary of keys with an optional active key identifier.
1723
+ */
1724
+ setKeyring(keys: Record<string, TKeyProvider | IKeyPair>, activeKid?: string): void;
1725
+ /**
1726
+ * Retrieves the currently configured keyring dictionary.
1727
+ */
1728
+ getKeyring(): Record<string, TKeyProvider | IKeyPair> | undefined;
1729
+ /**
1730
+ * Sets the active Key Identifier (kid) to use for outbound encryption.
1731
+ */
1732
+ setActiveKid(kid: string): void;
1733
+ /**
1734
+ * Retrieves the active Key Identifier (kid).
1735
+ */
1736
+ getActiveKid(): string | undefined;
1737
+ /**
1738
+ * Sets or updates the dedicated HMAC key or key provider callback for blind indexing.
1739
+ */
1740
+ setHmacKey(key: TKeyProvider): void;
1741
+ /**
1742
+ * Retrieves the currently configured HMAC key or key provider callback.
1743
+ */
1744
+ getHmacKey(): TKeyProvider | undefined;
1745
+ /**
1746
+ * Computes a deterministic HMAC-SHA256 blind index hash for an arbitrary term.
1747
+ * If no hmacKey is explicitly provided, uses the provider's configured hmacKey or default key.
1748
+ */
1749
+ computeBlindIndex(value: any, hmacKey?: CryptoKey | TKeyProvider): Promise<string>;
1556
1750
  /**
1557
1751
  * Pre-derives and caches the native CryptoKey for subsequent cryptographic operations.
1558
1752
  * Subclasses should override this with a dedicated, non-side-effecting implementation.
@@ -1593,10 +1787,33 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
1593
1787
  */
1594
1788
  protected _resolveEffectiveAad(options?: IEncryptionContext, isDecrypt?: boolean): string | Uint8Array | ArrayBuffer | undefined;
1595
1789
  /**
1596
- * Helper to deterministically bind record ID and field name into the AAD
1597
- * to prevent ciphertext swapping between fields or records.
1790
+ * Helper to deterministically bind record ID, contextual sibling fields (aadFields),
1791
+ * dynamic AAD callbacks, and field name into the AAD to prevent ciphertext swapping
1792
+ * between fields, records, or parent entities.
1598
1793
  */
1599
1794
  protected _bindFieldAad(data: any, field: string, options?: IEncryptionContext): IEncryptionContext;
1795
+ /**
1796
+ * Validates envelope metadata against algorithm whitelists and key identifiers (kid).
1797
+ * In strict mode, allowedAlgorithms defaults to ['AES-GCM'].
1798
+ */
1799
+ protected _validateEnvelopeMetadata(payload: any, options?: IEncryptionContext): Error | undefined;
1800
+ /**
1801
+ * Normalizes encryption options with active keyring parameters:
1802
+ * If `keys` and `activeKid` are configured, selects `key = keys[activeKid]` and sets `kid = activeKid`.
1803
+ */
1804
+ protected _resolveOutboundKeyringOptions(options?: IEncryptionContext): IEncryptionContext;
1805
+ /**
1806
+ * Resolves the appropriate decryption key for a specific payload envelope based on its `kid`
1807
+ * and the configured keyring (`keys`, `activeKid`, or fallback `key`).
1808
+ */
1809
+ protected _resolveDecryptionKeyForEnvelope(payload: any, options?: IEncryptionContext): TKeyProvider | IKeyPair | undefined;
1810
+ /**
1811
+ * Handles a per-field or per-payload decryption error according to configured options:
1812
+ * - Invokes onDecryptError callback if provided
1813
+ * - Attaches error metadata (__decryptErrors) to the record object
1814
+ * - Returns fallback cell placeholder ('[⚠ Decryption Error]') or rethrows
1815
+ */
1816
+ protected _handleDecryptError(err: Error, record: any, field: string, value: any, index: number | undefined, options?: IEncryptionContext): any;
1600
1817
  /**
1601
1818
  * Encrypts a single value (string, object, primitive) into an IEncryptedPayload envelope.
1602
1819
  * Implemented by concrete cryptographic providers.
@@ -1607,6 +1824,22 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
1607
1824
  * Implemented by concrete cryptographic providers.
1608
1825
  */
1609
1826
  abstract decryptValue(payload: IEncryptedPayload, options?: IEncryptionContext): Promise<any>;
1827
+ /**
1828
+ * Encrypts a single scalar value with contextual AAD binding into an IEncryptedPayload envelope.
1829
+ * Binds recordId, fieldName, and sibling aadFields deterministically to protect against ciphertext swapping.
1830
+ *
1831
+ * @param value - Scalar value (string, number, boolean, object) to encrypt.
1832
+ * @param context - Field encryption context with recordId, fieldName, and optional sibling aadFields.
1833
+ */
1834
+ encryptField(value: any, context?: IFieldEncryptionContext): Promise<IEncryptedPayload>;
1835
+ /**
1836
+ * Decrypts a single IEncryptedPayload envelope back into its scalar plaintext value using contextual AAD.
1837
+ * Validates recordId, fieldName, and sibling aadFields integrity.
1838
+ *
1839
+ * @param envelope - The IEncryptedPayload envelope to decrypt.
1840
+ * @param context - Field encryption context matching the encryption parameters.
1841
+ */
1842
+ decryptField(envelope: IEncryptedPayload, context?: IFieldEncryptionContext): Promise<any>;
1610
1843
  /**
1611
1844
  * Top-level polymorphic encryption method.
1612
1845
  * Automatically performs value-level encryption:
@@ -1619,16 +1852,13 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
1619
1852
  /**
1620
1853
  * Top-level polymorphic decryption method.
1621
1854
  * Automatically performs value-level decryption:
1622
- * - If payload is an encrypted envelope: decrypts directly via decryptValue.
1623
- * - If payload is an array of objects: decrypts each row.
1624
- * - If payload is an object: decrypts any encrypted value cells across fields.
1625
- */
1626
- /**
1627
- * Top-level polymorphic decryption method.
1628
- * Automatically performs value-level decryption:
1629
- * - If payload is an encrypted envelope: decrypts directly via decryptValue.
1855
+ * - If payload is an encrypted envelope: validates metadata and decrypts directly via decryptValue.
1630
1856
  * - If payload is an array of objects: decrypts each row (batched with local memoization).
1631
1857
  * - If payload is an object: decrypts any encrypted value cells across fields.
1858
+ * In strict mode:
1859
+ * - Unencrypted plaintext in configured `fields` triggers a decryption error.
1860
+ * - Envelopes are validated against `allowedAlgorithms` and `allowedKids`.
1861
+ * - Errors are routed through `onDecryptError` or populated into `__decryptErrors`.
1632
1862
  */
1633
1863
  decrypt(payload: any, options?: IEncryptionContext): Promise<any>;
1634
1864
  }
@@ -1701,11 +1931,19 @@ declare class CKeyManager {
1701
1931
  /**
1702
1932
  * Imports a public key from a PEM (SPKI) or base64 SPKI string.
1703
1933
  */
1704
- static importPublicKeyFromPEM(pem: string, algorithm?: 'RSA-OAEP' | 'ECDH', curve?: 'P-256' | 'P-384' | 'P-521', hash?: 'SHA-256' | 'SHA-512'): Promise<CryptoKey>;
1934
+ static importPublicKeyFromPEM(pem: string, algorithm?: 'RSA-OAEP' | 'ECDH' | 'ECDSA', curve?: 'P-256' | 'P-384' | 'P-521', hash?: 'SHA-256' | 'SHA-512'): Promise<CryptoKey>;
1935
+ /**
1936
+ * Imports an ECDSA public key from PEM (SPKI) or base64 SPKI string for signature verification.
1937
+ */
1938
+ static importECDSAPublicKeyFromPEM(pem: string, curve?: 'P-256' | 'P-384' | 'P-521'): Promise<CryptoKey>;
1705
1939
  /**
1706
1940
  * Imports a private key from a PEM (PKCS#8) or base64 PKCS#8 string.
1707
1941
  */
1708
- static importPrivateKeyFromPEM(pem: string, algorithm?: 'RSA-OAEP' | 'ECDH', curve?: 'P-256' | 'P-384' | 'P-521', hash?: 'SHA-256' | 'SHA-512'): Promise<CryptoKey>;
1942
+ static importPrivateKeyFromPEM(pem: string, algorithm?: 'RSA-OAEP' | 'ECDH' | 'ECDSA', curve?: 'P-256' | 'P-384' | 'P-521', hash?: 'SHA-256' | 'SHA-512'): Promise<CryptoKey>;
1943
+ /**
1944
+ * Imports an ECDSA private key from PEM (PKCS#8) or base64 PKCS#8 string for signing.
1945
+ */
1946
+ static importECDSAPrivateKeyFromPEM(pem: string, curve?: 'P-256' | 'P-384' | 'P-521'): Promise<CryptoKey>;
1709
1947
  /**
1710
1948
  * Exports a public CryptoKey to a standard PEM (SPKI) string.
1711
1949
  */
@@ -1738,6 +1976,26 @@ declare class CKeyManager {
1738
1976
  * Returns the restored AES-GCM CryptoKey ready for use in CWebCryptoEncryptionProvider.
1739
1977
  */
1740
1978
  static unwrapAccountKeyForUser(wrappedKeyBase64: string, userPrivateKey: CryptoKey, unwrappedKeyAlgorithm?: any, extractable?: boolean): Promise<CryptoKey>;
1979
+ /**
1980
+ * Wraps an HMAC blind indexing key for a specific recipient user using their RSA-OAEP public key.
1981
+ * Returns a Base64-encoded wrapped key string suitable for storage in role-map / access tables.
1982
+ */
1983
+ static wrapHMACKeyForUser(hmacKey: CryptoKey, userPublicKey: CryptoKey): Promise<string>;
1984
+ /**
1985
+ * Unwraps a Base64-encoded HMAC key using a recipient's RSA-OAEP private key.
1986
+ * Restores the CryptoKey configured for HMAC signing and verification in search indexing.
1987
+ */
1988
+ static unwrapHMACKeyForUser(wrappedKeyBase64: string, userPrivateKey: CryptoKey, hash?: 'SHA-256' | 'SHA-384' | 'SHA-512', extractable?: boolean): Promise<CryptoKey>;
1989
+ /**
1990
+ * Atomically re-wraps an Account Data Encryption Key (ADEK) for a new recipient
1991
+ * without exposing the raw extractable symmetric key to caller application code.
1992
+ *
1993
+ * @param wrappedKeyBase64 - The existing ADEK envelope wrapped with current user's public key
1994
+ * @param myPrivateKey - Current user's RSA-OAEP private key
1995
+ * @param recipientPublicKey - New recipient's RSA-OAEP public key
1996
+ * @returns Base64-encoded wrapped key envelope for the recipient
1997
+ */
1998
+ static rewrapAccountKeyForUser(wrappedKeyBase64: string, myPrivateKey: CryptoKey, recipientPublicKey: CryptoKey): Promise<string>;
1741
1999
  /**
1742
2000
  * Derives a symmetric AES-GCM CryptoKey from a passphrase using PBKDF2 or HKDF.
1743
2001
  * Returns the derived CryptoKey and the base64-encoded salt.
@@ -1751,6 +2009,59 @@ declare class CKeyManager {
1751
2009
  * using HKDF.
1752
2010
  */
1753
2011
  static deriveKeyFromSecret(secretKey: CryptoKey, options?: IHKDFFromSecretOptions): Promise<CryptoKey>;
2012
+ /**
2013
+ * Derives two domain-separated, cryptographically isolated keys from a user password and salt:
2014
+ * 1. `authKey`: For client authentication, SRP, or server challenge proofs.
2015
+ * 2. `encryptionKey`: For AES-GCM local and field-level data encryption.
2016
+ *
2017
+ * Stage 1 (Password Stretching): PBKDF2-HMAC-SHA256 stretches low-entropy password into master secret.
2018
+ * Stage 2 (Domain Expansion): HKDF-Expand derives subkeys using domain-separated context info tags.
2019
+ * Immediate memory zeroization of intermediate master secret buffer is guaranteed.
2020
+ *
2021
+ * @param password - Master user password or passphrase
2022
+ * @param salt - Salt (or omitted to generate a secure random 16-byte salt)
2023
+ * @param options - PBKDF2 and HKDF configuration options
2024
+ */
2025
+ static deriveAuthAndEncryptionKeys(password: string | Uint8Array | ArrayBuffer, salt?: Uint8Array | ArrayBuffer | string, options?: IDeriveAuthAndEncryptionOptions): Promise<IDomainDerivedKeys>;
2026
+ /**
2027
+ * Generates an ECDSA P-256 signing key pair.
2028
+ */
2029
+ static generateSigningKeyPair(curve?: 'P-256' | 'P-384' | 'P-521', extractable?: boolean): Promise<IKeyPair>;
2030
+ /**
2031
+ * Generates an ECDSA signing key pair. Alias for generateSigningKeyPair.
2032
+ */
2033
+ static generateECDSAKeyPair(curve?: 'P-256' | 'P-384' | 'P-521', extractable?: boolean): Promise<IKeyPair>;
2034
+ /**
2035
+ * Generates a deterministic SHA-256 fingerprint for a public key (SPKI or raw).
2036
+ * Formatted as `SHA256:<base64url>`.
2037
+ */
2038
+ static getKeyFingerprint(publicKey: CryptoKey | Uint8Array | ArrayBuffer | string): Promise<string>;
2039
+ /**
2040
+ * Signs arbitrary data or JSON objects using an ECDSA P-256 private key.
2041
+ * Objects are automatically serialized via canonicalizeJson() before hashing.
2042
+ */
2043
+ static sign(data: any | string | Uint8Array, privateKey: CryptoKey): Promise<string>;
2044
+ /**
2045
+ * Verifies an ECDSA P-256 signature against original data or JSON object.
2046
+ */
2047
+ static verify(data: any | string | Uint8Array, signature: string, publicKey: CryptoKey): Promise<boolean>;
2048
+ /**
2049
+ * Computes a deterministic HMAC-SHA256 blind index hash for an arbitrary term using the supplied CryptoKey.
2050
+ * Performs Unicode NFKC normalization, trimming, and lowercasing before computing the signature.
2051
+ *
2052
+ * @param value - The input string, number, or object to compute the blind index for.
2053
+ * @param hmacKey - CryptoKey configured for HMAC signing.
2054
+ * @returns Lowercase hexadecimal HMAC-SHA256 blind index hash.
2055
+ */
2056
+ static computeBlindIndex(value: any, hmacKey: CryptoKey): Promise<string>;
2057
+ /**
2058
+ * Signs a structured access grant, embedding signature and granter key fingerprint.
2059
+ */
2060
+ static signGrant(grant: IAccessGrant, granterPrivateKey: CryptoKey, granterPublicKey?: CryptoKey): Promise<ISignedGrant>;
2061
+ /**
2062
+ * Verifies the authenticity and integrity of a signed access grant against granter public key.
2063
+ */
2064
+ static verifyGrant(signedGrant: ISignedGrant, granterPublicKey: CryptoKey, options?: IVerifyGrantOptions): Promise<boolean>;
1754
2065
  }
1755
2066
 
1756
2067
  interface ICWebCryptoOptions {
@@ -1761,6 +2072,10 @@ interface ICWebCryptoOptions {
1761
2072
  info?: string | Uint8Array | ArrayBuffer;
1762
2073
  kid?: string;
1763
2074
  keyId?: string;
2075
+ keys?: Record<string, TKeyProvider | IKeyPair>;
2076
+ activeKid?: string;
2077
+ allowedKids?: string[];
2078
+ hmacKey?: TKeyProvider;
1764
2079
  }
1765
2080
  /**
1766
2081
  * Zero-dependency AES-256-GCM cipher provider using native Web Crypto API (crypto.subtle).
@@ -1784,6 +2099,7 @@ declare class CWebCryptoEncryptionProvider extends AEncryptionProvider {
1784
2099
  private _cachedKeyId?;
1785
2100
  private _configuredKid?;
1786
2101
  private _decryptSaltCache;
2102
+ private _keyringCache;
1787
2103
  setDefaultKey(key: TKeyProvider): void;
1788
2104
  clearKeys(): void;
1789
2105
  constructor(key?: TKeyProvider | IKeyPair, options?: ICWebCryptoOptions);
@@ -1993,6 +2309,10 @@ interface ICNodeCryptoOptions {
1993
2309
  info?: string | Uint8Array | ArrayBuffer;
1994
2310
  kid?: string;
1995
2311
  keyId?: string;
2312
+ keys?: Record<string, TKeyProvider | IKeyPair>;
2313
+ activeKid?: string;
2314
+ allowedKids?: string[];
2315
+ hmacKey?: TKeyProvider;
1996
2316
  }
1997
2317
  /**
1998
2318
  * Server-side synchronous AES-GCM-256 encryption provider using Node.js native `node:crypto`.
@@ -2014,6 +2334,8 @@ declare class CNodeCryptoEncryptionProvider extends AEncryptionProvider {
2014
2334
  private _cachedHash?;
2015
2335
  private _cachedKeyId?;
2016
2336
  private _configuredKid?;
2337
+ private _keyringCache;
2338
+ private isKeyRetained;
2017
2339
  setDefaultKey(key: TKeyProvider): void;
2018
2340
  clearKeys(): void;
2019
2341
  warmupKey(options?: IEncryptionContext): Promise<void>;
@@ -2115,11 +2437,17 @@ declare function getKeyIdentifier(keyProvider?: any, defaultKey?: any): string;
2115
2437
  * Conforms to W3C Web Cryptography API specification (OperationError) and Node.js crypto error codes.
2116
2438
  */
2117
2439
  declare function isAuthOrDecryptionError(err: any): boolean;
2440
+ /**
2441
+ * Serializes a JavaScript value to a deterministic, canonical JSON string conforming to RFC 8785 (JCS).
2442
+ * Guarantees consistent property sorting by UTF-16 code units, omission of undefined/symbol/function values,
2443
+ * standard ECMAScript number formatting (-0 serialized as 0), and detection of circular references.
2444
+ */
2445
+ declare function canonicalizeJson(value: any, seen?: Set<any>): string;
2118
2446
 
2119
2447
  /**
2120
2448
  * Universal helper that verifies whether an arbitrary object is a Katlux encrypted payload envelope.
2121
2449
  */
2122
2450
  declare function isEncrypted(payload: any): boolean;
2123
2451
 
2124
- export { AAPIDataProvider, ADataProvider, AEncryptedClientProvider, AEncryptionProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CBrowserSessionCache, CCookieCache, CECDHEncryptionProvider, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CKeyManager, CLocalStorageCache, CMemoryCache, CNodeCryptoEncryptionProvider, CRSAEncryptionProvider, CSearchIndex, CServerSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CWebCryptoAESCBCProvider, CWebCryptoEncryptionProvider, CacheProviderFactory, DefaultHydrationAdapter, ECacheStrategy, EDataFilterOperator, EQueueStorage, KatluxIndexedDB, QueueStorageFactory, RequestProvider, RequestProviderRegistry, RequestQueue, SENSITIVE_HEADER_KEYS, applyOperator, buildEncryptionContext, clearCachedCipherProvider, clearSSRData, compareAnd, compareEqual, compareIn, compareOr, compareValues, createEncryptionProvider, debounce, decryptPageRows, encryptRows, encryptRowsChunked, evaluateFilter, extractTrigrams, fastKeyHash, fetchWithSSR, filterData, filterTreeData, getAppRoute, getAppRouter, getCipherProvider, getHydrationAdapter, getKeyIdentifier, getPlatformApp, getRandomValues, getSSRData, getSSRPayload, getSafeKeyIdentifier, getSubtleCrypto, isAuthOrDecryptionError, isDataEncrypted, isEncrypted, normalizeIndexTerm, onPlatformReady, resolveInfoBytes, safeSetProperty, setHydrationAdapter, sortData, textDecoder, textEncoder, toBase64, useDebounce, useFilterLogic, useSortLogic };
2125
- export type { CacheDriverLoader, ICNodeCryptoOptions, ICWebCryptoAESCBCOptions, ICWebCryptoOptions, ICacheEntry, ICacheQuotaOptions, ICookieCacheOptions, IDataFilter, IDataProviderOptions, IDataProviderSetStateOptions, IDataProviderState, IDataResult, IDataSort, IDeadLetterItem, IDebouncedFunction, IEncryptedPayload, IEncryptionContext, IEncryptionProvider, IFlushOptions, IHKDFFromSecretOptions, IKDFOptions, IKDatatableAction, IKeyPair, IPlatformRouter, IProviderEncryptionOptions, IQueueStorageAdapter, IQueuedOperation, IRequestOptions, ISSRHydrationAdapter, ISearchIndexRowEntry, ISetDataChunkedOptions, ITreeDataProvider, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, IVirtualScrollState, IWrappedKey, KProductItemData, KProductRowAction, TDataProviderListener, TDataProviderStateChangeListener, TDataRow, TECDHCurve, TKatluxStore, TKeyProvider, TPageDataHandler, TQueueItemStatus, TRawKey, TTreePageDataHandler, TTreeRow, TUnsubscribe, TreePaginationMode };
2452
+ export { AAPIDataProvider, ADataProvider, AEncryptedClientProvider, AEncryptionProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CBrowserSessionCache, CCookieCache, CECDHEncryptionProvider, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CKeyManager, CLocalStorageCache, CMemoryCache, CNodeCryptoEncryptionProvider, CRSAEncryptionProvider, CSearchIndex, CServerSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CWebCryptoAESCBCProvider, CWebCryptoEncryptionProvider, CacheProviderFactory, DECRYPT_ERROR_SENTINEL, DefaultHydrationAdapter, ECacheStrategy, EDataFilterOperator, EQueueStorage, KatluxIndexedDB, QueueStorageFactory, RequestProvider, RequestProviderRegistry, RequestQueue, SENSITIVE_HEADER_KEYS, applyOperator, buildEncryptionContext, canonicalizeJson, clearCachedCipherProvider, clearSSRData, compareAnd, compareEqual, compareIn, compareOr, compareValues, createEncryptionProvider, debounce, decryptPageRows, encryptRows, encryptRowsChunked, evaluateFilter, extractTrigrams, fastKeyHash, fetchWithSSR, filterData, filterTreeData, getAppRoute, getAppRouter, getCipherProvider, getHydrationAdapter, getKeyIdentifier, getPlatformApp, getRandomValues, getSSRData, getSSRPayload, getSafeKeyIdentifier, getSubtleCrypto, isAuthOrDecryptionError, isDataEncrypted, isEncrypted, normalizeIndexTerm, onPlatformReady, resolveInfoBytes, safeSetProperty, setHydrationAdapter, sortData, textDecoder, textEncoder, toBase64, useDebounce, useFilterLogic, useSortLogic };
2453
+ export type { CacheDriverLoader, IAccessGrant, ICNodeCryptoOptions, ICWebCryptoAESCBCOptions, ICWebCryptoOptions, ICacheEntry, ICacheQuotaOptions, ICookieCacheOptions, IDataFilter, IDataProviderOptions, IDataProviderSetStateOptions, IDataProviderState, IDataResult, IDataSort, IDeadLetterItem, IDebouncedFunction, IDecryptErrorInfo, IDeriveAuthAndEncryptionOptions, IDomainDerivedKeys, IEncryptedPayload, IEncryptionContext, IEncryptionProvider, IFieldEncryptionContext, IFlushOptions, IHKDFFromSecretOptions, IKDFOptions, IKDatatableAction, IKeyPair, IPlatformRouter, IProviderEncryptionOptions, IQueueStorageAdapter, IQueuedOperation, IRequestOptions, ISSRHydrationAdapter, ISearchIndexRowEntry, ISetDataChunkedOptions, ISignedGrant, ITreeDataProvider, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, IVerifyGrantOptions, IVirtualScrollState, IWrappedKey, KProductItemData, KProductRowAction, TDataProviderListener, TDataProviderStateChangeListener, TDataRow, TECDHCurve, TKatluxStore, TKeyProvider, TPageDataHandler, TQueueItemStatus, TRawKey, TTreePageDataHandler, TTreeRow, TUnsubscribe, TreePaginationMode };