@syncular/client-plugin-encryption 0.0.1-60

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.
@@ -0,0 +1,78 @@
1
+ import type { SyncClientDb, SyncClientPlugin, SyncClientPluginContext, SyncEngine } from '@syncular/client';
2
+ import { type Kysely } from 'kysely';
3
+ export * from './key-sharing';
4
+ type FieldDecryptionErrorMode = 'throw' | 'keepCiphertext';
5
+ interface FieldEncryptionRule {
6
+ scope: string;
7
+ /**
8
+ * Optional table selector. Strongly recommended for correctness:
9
+ * - Push/incremental changes have a table name.
10
+ * - Snapshot rows often do not; if omitted, the plugin must be able to infer it.
11
+ */
12
+ table?: string;
13
+ /** Column names to encrypt/decrypt */
14
+ fields: string[];
15
+ /**
16
+ * Row id column in snapshot row objects (defaults to "id").
17
+ * Push/incremental changes use the protocol `row_id` and ignore this.
18
+ */
19
+ rowIdField?: string;
20
+ }
21
+ export interface FieldEncryptionKeys {
22
+ /**
23
+ * Resolve a 32-byte symmetric key for a given key id.
24
+ * Throws (or rejects) when the key is unavailable.
25
+ */
26
+ getKey: (kid: string) => Uint8Array | Promise<Uint8Array>;
27
+ /**
28
+ * Select which key id to use when encrypting new values.
29
+ * Defaults to "default".
30
+ */
31
+ getEncryptionKid?: (ctx: SyncClientPluginContext, args: {
32
+ scope: string;
33
+ table: string;
34
+ rowId: string;
35
+ field: string;
36
+ }) => string | Promise<string>;
37
+ }
38
+ interface FieldEncryptionPluginOptions {
39
+ name?: string;
40
+ rules: FieldEncryptionRule[];
41
+ keys: FieldEncryptionKeys;
42
+ /**
43
+ * Controls what happens when ciphertext is present but decryption fails
44
+ * (unknown key, bad AAD, corrupted data).
45
+ */
46
+ decryptionErrorMode?: FieldDecryptionErrorMode;
47
+ /**
48
+ * Envelope prefix written into the DB. Changing this breaks decryption
49
+ * for existing rows.
50
+ */
51
+ envelopePrefix?: string;
52
+ }
53
+ interface RefreshEncryptedFieldsTarget {
54
+ scope: string;
55
+ table: string;
56
+ fields?: string[];
57
+ }
58
+ export interface RefreshEncryptedFieldsResult {
59
+ tablesProcessed: number;
60
+ rowsScanned: number;
61
+ rowsUpdated: number;
62
+ fieldsUpdated: number;
63
+ }
64
+ export interface FieldEncryptionPluginRefreshRequest<DB extends SyncClientDb = SyncClientDb> {
65
+ db: Kysely<DB>;
66
+ engine?: Pick<SyncEngine<DB>, 'recordLocalMutations'>;
67
+ targets?: RefreshEncryptedFieldsTarget[];
68
+ ctx?: Partial<SyncClientPluginContext>;
69
+ }
70
+ export interface FieldEncryptionPlugin extends SyncClientPlugin {
71
+ refreshEncryptedFields: <DB extends SyncClientDb = SyncClientDb>(options: FieldEncryptionPluginRefreshRequest<DB>) => Promise<RefreshEncryptedFieldsResult>;
72
+ }
73
+ export declare function createStaticFieldEncryptionKeys(args: {
74
+ keys: Record<string, Uint8Array | string>;
75
+ encryptionKid?: string;
76
+ }): FieldEncryptionKeys;
77
+ export declare function createFieldEncryptionPlugin(pluginOptions: FieldEncryptionPluginOptions): FieldEncryptionPlugin;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EAAE,KAAK,MAAM,EAAO,MAAM,QAAQ,CAAC;AAG1C,cAAc,eAAe,CAAC;AAI9B,KAAK,wBAAwB,GAAG,OAAO,GAAG,gBAAgB,CAAC;AAE3D,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;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