Skip to content

Commit 76642a4

Browse files
committed
Extract calculateHmacSignature method
1 parent d124574 commit 76642a4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/utils/hmacValidator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class HmacValidator {
3535
*/
3636
public calculateHmac(data: string | NotificationRequestItem, key: string): string {
3737
const dataString = typeof data !== "string" ? this.getDataToSign(data) : data;
38-
const rawKey = Buffer.from(key, "hex");
39-
return createHmac(HmacValidator.HMAC_SHA256_ALGORITHM, rawKey).update(dataString, "utf8").digest("base64");
38+
return this.calculateHmacSignature(dataString, key);
4039
}
4140

4241
/**
@@ -131,6 +130,13 @@ class HmacValidator {
131130
return [...keys, ...values].join(HmacValidator.DATA_SEPARATOR);
132131
}
133132
}
133+
134+
public calculateHmacSignature(data: string, key: string): string {
135+
const rawKey = Buffer.from(key, "hex");
136+
return createHmac(HmacValidator.HMAC_SHA256_ALGORITHM, rawKey).update(data, "utf8").digest("base64");
137+
}
138+
134139
}
135140

141+
136142
export default HmacValidator;

0 commit comments

Comments
 (0)