-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.d.ts
303 lines (263 loc) · 10.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
declare module "ciphersweet-js" {
export interface EncryptionBackend {
multiTenantSafe(): boolean;
getFileEncryptionSaltOffset(): number;
decrypt(ciphertext: string, key: SymmetricKey, aad?: string): Promise<Buffer>;
encrypt(plaintext: string|Buffer, key: SymmetricKey, aad?: string): Promise<string>;
}
export class BoringCrypto implements EncryptionBackend {
public multiTenantSafe(): true;
public getFileEncryptionSaltOffset(): number;
public decrypt(ciphertext: string, key: SymmetricKey, aad?: string): Promise<Buffer>;
public encrypt(plaintext: string|Buffer, key: SymmetricKey, aad?: string): Promise<string>;
}
export class FIPSCrypto implements EncryptionBackend {
public multiTenantSafe(): true;
public getFileEncryptionSaltOffset(): number;
public decrypt(ciphertext: string, key: SymmetricKey, aad?: string): Promise<Buffer>;
public encrypt(plaintext: string|Buffer, key: SymmetricKey, aad?: string): Promise<string>;
}
export class ModernCrypto implements EncryptionBackend {
public multiTenantSafe(): false;
public getFileEncryptionSaltOffset(): number;
public decrypt(ciphertext: string, key: SymmetricKey, aad?: string): Promise<Buffer>;
public encrypt(plaintext: string|Buffer, key: SymmetricKey, aad?: string): Promise<string>;
}
export interface CalculatedBlindIndex {
type: string;
value: string;
}
export class FieldIndexPlanner {
public setEstimatedPopulation(population: number);
public addExistingIndex(
indexName: string,
outputSizeInBits: number,
bloomFilterSizeInBits: number
);
public recommend(
inputDomainInBits?: number
): { min: number; max: number };
}
// Encrypted Field API
export type FieldStorageTuple = [string, { [indexName: string]: string }];
export class EncryptedField {
constructor(
engine: CipherSweet,
tableName: string,
fieldName: string,
usedTypedIndexes?: boolean
);
public setTypedIndexes(enable: boolean);
public addBlindIndex(
blindIndex: BlindIndex,
indexName?: string
): EncryptedField;
public getBlindIndex(
plaintext: string,
indexName: string
): Promise<CalculatedBlindIndex>;
public getAllBlindIndexes(
plaintext: string
): Promise<{ [indexName: string]: CalculatedBlindIndex }>;
public encryptValue(plaintext: string, aad?: string): Promise<string>;
public decryptValue(ciphertext: string, aad?: string): Promise<Buffer>;
// Returns [ciphertext, indexes]
public prepareForStorage(
plaintext: string,
aad?: string
): Promise<FieldStorageTuple>;
}
export interface ModernCryptoHashConfig {
opslimit: number;
memlimit: number;
}
export interface BoringCryptoHashConfig {
opslimit: number;
memlimit: number;
}
export interface FIPSCryptoHashConfig {
iterations: number;
}
export class BlindIndex {
constructor(
name: string,
transforms: Transformation[],
bloomFilterSizeInBits?: number,
fastHash?: boolean,
config?: ModernCryptoHashConfig | FIPSCryptoHashConfig | BoringCryptoHashConfig
);
}
export class CompoundIndex {
constructor(
indexName: string,
fieldNames: string[],
bloomFilterSizeInBits?: number,
fastHash?: boolean,
config?: ModernCryptoHashConfig | FIPSCryptoHashConfig | BoringCryptoHashConfig
);
public addTransform(
fieldName: string,
transform: Transformation
): CompoundIndex;
public addRowTransform(transform: RowTransformation): CompoundIndex;
}
// Encrypted Row API
export type RowStorageTuple = [any, { [fieldName: string]: any }];
export class EncryptedRow {
constructor(engine: CipherSweet, tableName: string);
public setTypedIndexes(boolean);
public setFlatIndexes(boolean);
public setAadSourceField(fieldName: string);
public addTextField(fieldName: string, aad?: string): EncryptedRow;
public addBooleanField(fieldName: string, aad?: string): EncryptedRow;
public addFloatField(fieldName: string, aad?: string): EncryptedRow;
public addBlindIndex(fieldName: string, index: BlindIndex);
public addCompoundIndex(index: CompoundIndex);
public createCompoundIndex(
indexName: string,
fieldNames: string[],
bloomFilterSizeInBits?: number,
fastHash?: boolean,
config?: ModernCryptoHashConfig | FIPSCryptoHashConfig
): CompoundIndex;
public decryptRow(row: Map<string, any>): Promise<Map<string, any>>;
public encryptRow(row: Map<string, any>): Promise<Map<string, any>>;
public prepareRowForStorage(row: any): Promise<RowStorageTuple>;
}
export class RowTransformation {
/**
* @param {Array<string, string>} input
* @return {string}
*/
public invoke(input: any): Promise<string>;
/**
* @param {Array<string, string>|Object<string, string>} input
* @return {string}
*/
public static processArray(input: any): Promise<string>;
}
// Encrypted Multi Rows
export type MultiRowStorageTuple = [
{ [tableName: string]: { [fieldName: string]: any } },
{ [tableName: string]: { [indexName: string]: any } }
];
export class EncryptedMultiRows {
constructor(engine: CipherSweet);
public setAadSourceField(
tableName: string,
indexName: string,
aadFieldName: string
);
public addTextField(
tableName: string,
fieldName: string,
aad?: string
): EncryptedMultiRows;
public addBooleanField(
tableName: string,
fieldName: string,
aad?: string
): EncryptedMultiRows;
public addFloatField(
tableName: string,
fieldName: string,
aad?: string
): EncryptedMultiRows;
public addCompoundIndex(tableName: string, index: CompoundIndex);
public createCompoundIndex(
tableName: string,
indexName: string,
fieldNames: string[],
bloomFilterSizeInBits?: number,
fastHash?: boolean,
config?: ModernCryptoHashConfig | FIPSCryptoHashConfig
): CompoundIndex;
public prepareForStorage(input: any): Promise<MultiRowStorageTuple>;
}
// Encrypted Files
export class EncryptedFile {
constructor(engine: CipherSweet);
public isFileEncrypted(inputPath: string): Promise<boolean>;
public encryptFile(
inputPath: string,
outputPath: string
): Promise<void>;
public decryptFile(
inputPath: string,
outputPath: string
): Promise<void>;
public encryptFileWithPassword(
inputPath: string,
outputPath: string,
password: string
): Promise<void>;
public decryptFileWithPassword(
inputPath: string,
outputPath: string,
password: string
): Promise<void>;
}
// Field Rotation
export class FieldRotator {
constructor(oldField: EncryptedField, newField: EncryptedField);
public needsReEncrypt(ciphertext: string): boolean;
public prepareForUpdate(
ciphertext: string,
oldAuthenticationTag?: string,
newAuthenticationTag?: string
): FieldStorageTuple;
}
export class RowRotator {
constructor(oldField: EncryptedRow, newField: EncryptedRow);
public needsReEncrypt(ciphertext: string): boolean;
public prepareForUpdate(ciphertext: string): RowStorageTuple;
}
export class MultiRowsRotator {
constructor(oldField: EncryptedMultiRows, newField: EncryptedMultiRows);
public needsReEncrypt(ciphertext: string): boolean;
public prepareForUpdate(ciphertext: string): MultiRowStorageTuple;
}
// Transforms
export class Transform {} // leaving in for backwards compat
export class Transformation extends Transform {}
export class LastFourDigits extends Transformation {}
export class AlphaCharactersOnly extends Transformation {}
export class FirstCharacter extends Transformation {}
export class Lowercase extends Transformation {}
// Key Providers
export class SymmetricKey {
constructor(rawKeyMaterial: string | Buffer);
static isSymmetricKey(key: any): boolean;
getRawKey(): Buffer;
}
export class KeyProvider {
getSymmetricKey(): SymmetricKey;
}
export class StringProvider extends KeyProvider {
constructor(hexEncodedKey: string);
}
export class MultiTenantAwareProvider extends KeyProvider {
public getActiveTenant(): KeyProvider;
public getTenant(name: string): KeyProvider;
public setActiveTenant(index: string): MultiTenantAwareProvider;
public getTenantFromRow(row: Map<string, any>, tableName: string): string;
public injectTenantMetadata(row: Map<string, any>, tableName: string): Map<string, any>;
}
export class MultiTenantProvider extends MultiTenantAwareProvider {
constructor(keyProviders: Map<string, KeyProvider>, active?: string);
}
// Main Engine
export class CipherSweet {
constructor(
keyProvider: KeyProvider,
encryptionBackend?: EncryptionBackend
);
public getBackend(): EncryptionBackend;
public getKeyProviderForActiveTenant(): KeyProvider;
public getKeyProviderForTenant(name: string): KeyProvider;
public getTenantFromRow(row: Map<string, any>, tableName?: string): string;
public setActiveTenant(tenant: string): void;
public injectTenantMetadata(row: Map<string, any>, tableName: string): Map<string, any>;
public isMultiTenantSupported(): boolean;
}
}