coffee-pay-sdk 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,8 @@ export declare class CryptoUtils {
4
4
  * This matches the logic provided in the requirements.
5
5
  */
6
6
  static generateWebSignature(accountKey: string, integrityKey: string, timestamp: number): string;
7
+ /**
8
+ * Verifies the signature of a webhook notification.
9
+ */
10
+ static verifyWebhookSignature(payload: any, signature: string, integrityKey: string): boolean;
7
11
  }
@@ -45,5 +45,13 @@ class CryptoUtils {
45
45
  const hash = crypto.SHA256(dataToSign);
46
46
  return hash.toString(crypto.enc.Hex);
47
47
  }
48
+ /**
49
+ * Verifies the signature of a webhook notification.
50
+ */
51
+ static verifyWebhookSignature(payload, signature, integrityKey) {
52
+ const payloadString = JSON.stringify(payload);
53
+ const expectedSignature = crypto.HmacSHA256(payloadString, integrityKey).toString(crypto.enc.Hex);
54
+ return signature === expectedSignature;
55
+ }
48
56
  }
49
57
  exports.CryptoUtils = CryptoUtils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coffee-pay-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Node.js SDK for Coffee-Pay payment gateway",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",