opticedge-cloud-utils 1.0.26 → 1.0.27
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.
package/dist/utils/thirdweb.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function isValidWebhookSignature(secret: string, body: string, signature: string): boolean;
|
package/dist/utils/thirdweb.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.isValidWebhookSignature = isValidWebhookSignature;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
function
|
|
8
|
+
function isValidWebhookSignature(secret, body, signature) {
|
|
9
9
|
const computedSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
10
10
|
return computedSignature === signature;
|
|
11
11
|
}
|
|
@@ -5,22 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const thirdweb_1 = require("./thirdweb");
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
describe('
|
|
8
|
+
describe('isValidWebhookSignature', () => {
|
|
9
9
|
const secret = 'test_secret';
|
|
10
10
|
const body = '{"message":"hello"}';
|
|
11
11
|
it('returns true for a valid signature', () => {
|
|
12
12
|
const validSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
13
|
-
expect((0, thirdweb_1.
|
|
13
|
+
expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, validSignature)).toBe(true);
|
|
14
14
|
});
|
|
15
15
|
it('returns false for an invalid signature', () => {
|
|
16
16
|
const invalidSignature = 'invalidsignature123';
|
|
17
|
-
expect((0, thirdweb_1.
|
|
17
|
+
expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, invalidSignature)).toBe(false);
|
|
18
18
|
});
|
|
19
19
|
it('returns false if body or secret is tampered', () => {
|
|
20
20
|
const originalSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
21
21
|
// wrong body
|
|
22
|
-
expect((0, thirdweb_1.
|
|
22
|
+
expect((0, thirdweb_1.isValidWebhookSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
|
|
23
23
|
// wrong secret
|
|
24
|
-
expect((0, thirdweb_1.
|
|
24
|
+
expect((0, thirdweb_1.isValidWebhookSignature)('wrong_secret', body, originalSignature)).toBe(false);
|
|
25
25
|
});
|
|
26
26
|
});
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isValidWebhookSignature } from './thirdweb'
|
|
2
2
|
import crypto from 'crypto'
|
|
3
3
|
|
|
4
|
-
describe('
|
|
4
|
+
describe('isValidWebhookSignature', () => {
|
|
5
5
|
const secret = 'test_secret'
|
|
6
6
|
const body = '{"message":"hello"}'
|
|
7
7
|
|
|
8
8
|
it('returns true for a valid signature', () => {
|
|
9
9
|
const validSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
|
|
10
10
|
|
|
11
|
-
expect(
|
|
11
|
+
expect(isValidWebhookSignature(secret, body, validSignature)).toBe(true)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('returns false for an invalid signature', () => {
|
|
15
15
|
const invalidSignature = 'invalidsignature123'
|
|
16
16
|
|
|
17
|
-
expect(
|
|
17
|
+
expect(isValidWebhookSignature(secret, body, invalidSignature)).toBe(false)
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
it('returns false if body or secret is tampered', () => {
|
|
21
21
|
const originalSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
|
|
22
22
|
|
|
23
23
|
// wrong body
|
|
24
|
-
expect(
|
|
24
|
+
expect(isValidWebhookSignature(secret, '{"message":"tampered"}', originalSignature)).toBe(false)
|
|
25
25
|
|
|
26
26
|
// wrong secret
|
|
27
|
-
expect(
|
|
27
|
+
expect(isValidWebhookSignature('wrong_secret', body, originalSignature)).toBe(false)
|
|
28
28
|
})
|
|
29
29
|
})
|
package/src/utils/thirdweb.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function isValidWebhookSignature(secret: string, body: string, signature: string): boolean {
|
|
4
4
|
const computedSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
|
|
5
5
|
return computedSignature === signature
|
|
6
6
|
}
|