Skip to content

Commit 8752f06

Browse files
committed
fix: update encryption methods to return promises in EncryptedHandler
1 parent aedbd93 commit 8752f06

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

packages/runtime/src/enhancements/node/encrypted.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
5656

5757
private async encrypt(field: FieldInfo, data: string): Promise<string> {
5858
if (this.isCustomEncryption(this.options.encryption!)) {
59-
return this.options.encryption.encrypt(this.model, field, data);
59+
return await this.options.encryption.encrypt(this.model, field, data);
6060
}
6161

6262
const key = await getKey(this.options.encryption!.encryptionKey);
@@ -80,7 +80,7 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
8080

8181
private async decrypt(field: FieldInfo, data: string): Promise<string> {
8282
if (this.isCustomEncryption(this.options.encryption!)) {
83-
return this.options.encryption.decrypt(this.model, field, data);
83+
return await this.options.encryption.decrypt(this.model, field, data);
8484
}
8585

8686
const key = await getKey(this.options.encryption!.encryptionKey);
@@ -145,10 +145,6 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
145145
field: async (field, _action, data, context) => {
146146
const encAttr = field.attributes?.find((attr) => attr.name === '@encrypted');
147147
if (encAttr && field.type === 'String') {
148-
// encrypt value
149-
150-
const secret: string = encAttr.args.find((arg) => arg.name === 'secret')?.value as string;
151-
152148
context.parent[field.name] = await this.encrypt(field, data);
153149
}
154150
},

packages/runtime/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export type ZodSchemas = {
174174
};
175175

176176
export type CustomEncryption = {
177-
encrypt: (model: string, field: FieldInfo, plain: string) => string;
178-
decrypt: (model: string, field: FieldInfo, cipher: string) => string;
177+
encrypt: (model: string, field: FieldInfo, plain: string) => Promise<string>;
178+
decrypt: (model: string, field: FieldInfo, cipher: string) => Promise<string>;
179179
};
180180

181181
export type SimpleEncryption = { encryptionKey: string };

0 commit comments

Comments
 (0)