@@ -2,7 +2,7 @@ import bindings = require('bindings');
2
2
3
3
const mc = bindings ( 'mongocrypt' ) ;
4
4
5
- interface MongoCryptKMSRequest {
5
+ export interface MongoCryptKMSRequest {
6
6
addResponse ( response : Buffer ) : void ;
7
7
readonly status : MongoCryptStatus ;
8
8
readonly bytesNeeded : number ;
@@ -11,18 +11,18 @@ interface MongoCryptKMSRequest {
11
11
readonly message : Buffer ;
12
12
}
13
13
14
- interface MongoCryptStatus {
14
+ export interface MongoCryptStatus {
15
15
type : number ;
16
16
code : number ;
17
17
message ?: string ;
18
18
}
19
19
20
- interface MongoCryptContext {
20
+ export interface MongoCryptContext {
21
21
nextMongoOperation ( ) : Buffer ;
22
- addMongoOperationResponse ( response : Buffer ) : void ;
22
+ addMongoOperationResponse ( response : Uint8Array ) : void ;
23
23
finishMongoOperation ( ) : void ;
24
24
nextKMSRequest ( ) : MongoCryptKMSRequest | null ;
25
- provideKMSProviders ( providers : Buffer ) : void ;
25
+ provideKMSProviders ( providers : Uint8Array ) : void ;
26
26
finishKMSRequests ( ) : void ;
27
27
finalize ( ) : Buffer ;
28
28
@@ -31,19 +31,28 @@ interface MongoCryptContext {
31
31
}
32
32
33
33
export interface MongoCryptConstructor {
34
- new ( ) : MongoCrypt ;
34
+ new ( options : {
35
+ kmsProviders ?: Buffer ;
36
+ schemaMap ?: Buffer ;
37
+ encryptedFieldsMap ?: Buffer ;
38
+ logger ?: unknown ;
39
+ cryptoCallbacks ?: Record < string , unknown > ;
40
+ cryptSharedLibSearchPaths ?: string [ ] ;
41
+ cryptSharedLibPath ?: string ;
42
+ bypassQueryAnalysis ?: boolean ;
43
+ } ) : MongoCrypt ;
35
44
libmongocryptVersion : string ;
36
45
}
37
46
38
47
export interface MongoCrypt {
39
- makeEncryptionContext ( ns : string , command : Buffer ) : MongoCryptContext ;
48
+ makeEncryptionContext ( ns : string , command : Uint8Array ) : MongoCryptContext ;
40
49
makeExplicitEncryptionContext (
41
- value : Buffer ,
50
+ value : Uint8Array ,
42
51
options ?: {
43
- keyId ?: Buffer ;
44
- keyAltName ?: Buffer ;
52
+ keyId ?: Uint8Array ;
53
+ keyAltName ?: Uint8Array ;
45
54
algorithm ?: string ;
46
- rangeOptions ?: Buffer ;
55
+ rangeOptions ?: Uint8Array ;
47
56
contentionFactor ?: bigint | number ;
48
57
queryType ?: string ;
49
58
@@ -56,21 +65,33 @@ export interface MongoCrypt {
56
65
expressionMode : boolean ;
57
66
}
58
67
) : MongoCryptContext ;
59
- makeDecryptionContext ( buffer : Buffer ) : MongoCryptContext ;
60
- makeExplicitDecryptionContext ( buffer : Buffer ) : MongoCryptContext ;
68
+ makeDecryptionContext ( buffer : Uint8Array ) : MongoCryptContext ;
69
+ makeExplicitDecryptionContext ( buffer : Uint8Array ) : MongoCryptContext ;
61
70
makeDataKeyContext (
62
- optionsBuffer : Buffer ,
71
+ optionsBuffer : Uint8Array ,
63
72
options : {
64
- keyAltNames : Buffer [ ] ;
65
- keyMaterial : Buffer ;
73
+ keyAltNames ?: Uint8Array [ ] ;
74
+ keyMaterial ?: Uint8Array ;
66
75
}
67
- ) : void ;
68
- makeRewrapManyDataKeyContext ( filter : Buffer , encryptionKey : Buffer ) : void ;
76
+ ) : MongoCryptContext ;
77
+ makeRewrapManyDataKeyContext ( filter : Uint8Array , encryptionKey ?: Uint8Array ) : MongoCryptContext ;
69
78
readonly status : MongoCryptStatus ;
70
79
readonly cryptSharedLibVersionInfo : {
71
80
version : bigint ;
72
81
versionStr : string ;
73
82
} | null ;
74
83
}
75
84
85
+ export type ExplicitEncryptionContextOptions = NonNullable <
86
+ Parameters < MongoCrypt [ 'makeExplicitEncryptionContext' ] > [ 1 ]
87
+ > ;
88
+ export type DataKeyContextOptions = NonNullable < Parameters < MongoCrypt [ 'makeDataKeyContext' ] > [ 1 ] > ;
89
+ export type MongoCryptOptions = NonNullable < ConstructorParameters < MongoCryptConstructor > [ 0 ] > ;
90
+
76
91
export const MongoCrypt : MongoCryptConstructor = mc . MongoCrypt ;
92
+
93
+ /** exported for testing only. */
94
+ interface MongoCryptContextCtor {
95
+ new ( ) : MongoCryptContext ;
96
+ }
97
+ export const MongoCryptContextCtor : MongoCryptContextCtor = mc . MongoCryptContextCtor ;
0 commit comments