Accessing Environment Variables in an Effect Function
export const verifySignature = (requestContent: string, signature: string) => {
const signingSecret = Config.string("WEBHOOK_SECRET");
// const signingSecret = process.env.WEBHOOK_SECRET!
return Effect.try({
try: () => {
// Compute the HMAC hash with sha256 algorithm
const computedSignature = crypto
.createHmac("sha256", signingSecret)
.update(requestContent)
.digest("hex");
// Compare the provided signature with the computed signature
const verified = crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(computedSignature)
);
if (!verified) {
throw new Error("signature no verificada");
}
return true;
},
catch: () => new HttpUnknownOriginError(),
});
};export const verifySignature = (requestContent: string, signature: string) => {
const signingSecret = Config.string("WEBHOOK_SECRET");
// const signingSecret = process.env.WEBHOOK_SECRET!
return Effect.try({
try: () => {
// Compute the HMAC hash with sha256 algorithm
const computedSignature = crypto
.createHmac("sha256", signingSecret)
.update(requestContent)
.digest("hex");
// Compare the provided signature with the computed signature
const verified = crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(computedSignature)
);
if (!verified) {
throw new Error("signature no verificada");
}
return true;
},
catch: () => new HttpUnknownOriginError(),
});
};how can I do that? should I pass it as a paremeter? and yield* it from my upper function? or is there another way?
