|
1 |
| -import bindings = require('bindings'); |
| 1 | +import { cryptoCallbacks } from './crypto_callbacks'; |
| 2 | +export { cryptoCallbacks }; |
2 | 3 |
|
3 |
| -const mc = bindings('mongocrypt'); |
| 4 | +import bindings = require('bindings'); |
| 5 | +const mc: MongoCryptBindings = bindings('mongocrypt'); |
4 | 6 |
|
5 |
| -export { cryptoCallbacks } from './crypto_callbacks'; |
| 7 | +/** |
| 8 | + * The value returned by the native bindings |
| 9 | + * reference the `Init(Env env, Object exports)` function in the c++ |
| 10 | + */ |
| 11 | +type MongoCryptBindings = { |
| 12 | + MongoCrypt: MongoCryptConstructor; |
| 13 | + MongoCryptContextCtor: MongoCryptContextCtor; |
| 14 | + MongoCryptKMSRequestCtor: MongoCryptKMSRequest; |
| 15 | +}; |
6 | 16 |
|
7 | 17 | export interface MongoCryptKMSRequest {
|
8 | 18 | addResponse(response: Uint8Array): void;
|
@@ -32,17 +42,19 @@ export interface MongoCryptContext {
|
32 | 42 | readonly state: number;
|
33 | 43 | }
|
34 | 44 |
|
| 45 | +type MongoCryptConstructorOptions = { |
| 46 | + kmsProviders?: Uint8Array; |
| 47 | + schemaMap?: Uint8Array; |
| 48 | + encryptedFieldsMap?: Uint8Array; |
| 49 | + logger?: unknown; |
| 50 | + cryptoCallbacks?: Record<string, unknown>; |
| 51 | + cryptSharedLibSearchPaths?: string[]; |
| 52 | + cryptSharedLibPath?: string; |
| 53 | + bypassQueryAnalysis?: boolean; |
| 54 | +}; |
| 55 | + |
35 | 56 | export interface MongoCryptConstructor {
|
36 |
| - new (options: { |
37 |
| - kmsProviders?: Uint8Array; |
38 |
| - schemaMap?: Uint8Array; |
39 |
| - encryptedFieldsMap?: Uint8Array; |
40 |
| - logger?: unknown; |
41 |
| - cryptoCallbacks?: Record<string, unknown>; |
42 |
| - cryptSharedLibSearchPaths?: string[]; |
43 |
| - cryptSharedLibPath?: string; |
44 |
| - bypassQueryAnalysis?: boolean; |
45 |
| - }): MongoCrypt; |
| 57 | + new (options: MongoCryptConstructorOptions): MongoCrypt; |
46 | 58 | libmongocryptVersion: string;
|
47 | 59 | }
|
48 | 60 |
|
@@ -91,7 +103,13 @@ export type ExplicitEncryptionContextOptions = NonNullable<
|
91 | 103 | export type DataKeyContextOptions = NonNullable<Parameters<MongoCrypt['makeDataKeyContext']>[1]>;
|
92 | 104 | export type MongoCryptOptions = NonNullable<ConstructorParameters<MongoCryptConstructor>[0]>;
|
93 | 105 |
|
94 |
| -export const MongoCrypt: MongoCryptConstructor = mc.MongoCrypt; |
| 106 | +export const MongoCrypt: MongoCryptConstructor = class MongoCrypt extends mc.MongoCrypt { |
| 107 | + constructor(options: MongoCryptConstructorOptions) { |
| 108 | + // Pass in JS cryptoCallbacks implementation by default. |
| 109 | + // If the Node.js openssl version is supported this will be ignored. |
| 110 | + super({ cryptoCallbacks, ...options }); |
| 111 | + } |
| 112 | +}; |
95 | 113 |
|
96 | 114 | /** exported for testing only. */
|
97 | 115 | interface MongoCryptContextCtor {
|
|
0 commit comments