Skip to content

Commit

Permalink
Changed HMAC library from sodium to crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Y committed Jul 8, 2024
1 parent d85c648 commit 898d810
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Message: {"context":{"domain":"retail","action":"search","bap_id":"retail.bap","

Shared Key: juWDOTzzK7Eyrzm6hZwQmlJkolesm8x0

HMAC: HMAC-SHA-256 8d2b129d83512b53ddd6e3657748a2e22cd05de3f7c4780cdf39da564a843884
HMAC: HMAC-SHA-256 287662f35c63bb66710d96749ea87b5a8fa8073f919c8da628451a3c8567a1ff
```
Expand Down
9 changes: 4 additions & 5 deletions src/utils/auth.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _sodium, { base64_variants } from "libsodium-wrappers";
import * as crypto from 'crypto';
import { writeFile } from "fs/promises";
import logger from "./logger.utils";
import { Request, Response } from "express";
Expand Down Expand Up @@ -210,12 +211,10 @@ export const createAuthHeaderConfig = async (request: any) => {
};

const createBppWebhookAuthHeader = async (request: any) => {
const sodium = _sodium;
const key = getConfig().app.sharedKeyForWebhookHMAC || "";
const keyUint8Array = sodium.from_string(key);
const messageUint8Array = sodium.from_string(JSON.stringify(request));
const hmac = sodium.crypto_auth(messageUint8Array, keyUint8Array);
return sodium.to_hex(hmac);
const hmac = crypto.createHmac('sha256', key);
hmac.update(JSON.stringify(request));
return hmac.digest('hex');
};

export const createBppWebhookAuthHeaderConfig = async (request: any) => {
Expand Down

0 comments on commit 898d810

Please sign in to comment.