From de37ee9f1c2bed7118caf334d9c14f8434125aa4 Mon Sep 17 00:00:00 2001 From: dominicbachmann Date: Wed, 6 Apr 2022 21:10:37 +0200 Subject: [PATCH] Added types for crypto --- src/lib/api.ts | 2 ++ src/lib/crypto.ts | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/api.ts b/src/lib/api.ts index 85d4ccf26..867ed338e 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,3 +1,5 @@ +// TODO: Make this functions generic + async function send({ method, path, diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index 861a25510..dfb38991f 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -1,13 +1,13 @@ import crypto from 'crypto'; const algorithm = 'aes-256-ctr'; -export const base64Encode = (text: string) => { +export const base64Encode = (text: string): string => { return Buffer.from(text).toString('base64'); }; -export const base64Decode = (text: string) => { +export const base64Decode = (text: string): string => { return Buffer.from(text, 'base64').toString('ascii'); }; -export const encrypt = (text: string) => { +export const encrypt = (text: string): string => { if (text) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(algorithm, process.env['COOLIFY_SECRET_KEY'], iv); @@ -19,7 +19,7 @@ export const encrypt = (text: string) => { } }; -export const decrypt = (hashString: string) => { +export const decrypt = (hashString: string): string => { if (hashString) { const hash: Hash = JSON.parse(hashString); const decipher = crypto.createDecipheriv(