opticedge-cloud-utils 1.0.35 → 1.0.37
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/types/user.d.ts +31 -0
- package/dist/utils/tw-utils.js +10 -2
- package/package.json +1 -1
- package/src/types/user.ts +32 -0
- package/src/utils/tw-utils.ts +14 -2
- package/dist/utils/thirdweb.d.ts +0 -1
- package/dist/utils/thirdweb.js +0 -11
- package/dist/utils/thirdweb.test.d.ts +0 -1
- package/dist/utils/thirdweb.test.js +0 -26
package/dist/types/user.d.ts
CHANGED
|
@@ -4,3 +4,34 @@ export declare enum UserCollectorType {
|
|
|
4
4
|
Rookie = 1,
|
|
5
5
|
Free = 2
|
|
6
6
|
}
|
|
7
|
+
export type User = {
|
|
8
|
+
cards: {
|
|
9
|
+
count: number;
|
|
10
|
+
};
|
|
11
|
+
collections: {
|
|
12
|
+
count: number;
|
|
13
|
+
};
|
|
14
|
+
email: string;
|
|
15
|
+
fcmTokens: Record<string, boolean>;
|
|
16
|
+
firstName: string;
|
|
17
|
+
fundAmount: number;
|
|
18
|
+
fundalert: number;
|
|
19
|
+
id: string;
|
|
20
|
+
insights: {
|
|
21
|
+
count: number;
|
|
22
|
+
};
|
|
23
|
+
isAppleUser: boolean;
|
|
24
|
+
isFacebookUser: boolean;
|
|
25
|
+
lastCardIndex: number;
|
|
26
|
+
lastGradingTime: number;
|
|
27
|
+
lastName: string;
|
|
28
|
+
soldCards: {
|
|
29
|
+
count: number;
|
|
30
|
+
};
|
|
31
|
+
thumbnail: string | undefined;
|
|
32
|
+
_collectorType: UserCollectorType;
|
|
33
|
+
_createdAt: number;
|
|
34
|
+
_currency: string;
|
|
35
|
+
_id: string;
|
|
36
|
+
_updatedAt: number;
|
|
37
|
+
};
|
package/dist/utils/tw-utils.js
CHANGED
|
@@ -5,7 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isValidWebhookSignature = isValidWebhookSignature;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const generateSignature = (body, secret) => {
|
|
9
|
+
return crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
10
|
+
};
|
|
8
11
|
function isValidWebhookSignature(secret, body, signature) {
|
|
9
|
-
const
|
|
10
|
-
|
|
12
|
+
const expectedSignature = generateSignature(body, secret);
|
|
13
|
+
const expectedBuffer = Buffer.from(expectedSignature);
|
|
14
|
+
const signatureBuffer = Buffer.from(signature);
|
|
15
|
+
if (expectedBuffer.length !== signatureBuffer.length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return crypto_1.default.timingSafeEqual(expectedBuffer, signatureBuffer);
|
|
11
19
|
}
|
package/package.json
CHANGED
package/src/types/user.ts
CHANGED
|
@@ -4,3 +4,35 @@ export enum UserCollectorType {
|
|
|
4
4
|
Rookie,
|
|
5
5
|
Free
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
export type User = {
|
|
9
|
+
cards: {
|
|
10
|
+
count: number
|
|
11
|
+
}
|
|
12
|
+
collections: {
|
|
13
|
+
count: number
|
|
14
|
+
}
|
|
15
|
+
email: string
|
|
16
|
+
fcmTokens: Record<string, boolean>
|
|
17
|
+
firstName: string
|
|
18
|
+
fundAmount: number
|
|
19
|
+
fundalert: number
|
|
20
|
+
id: string
|
|
21
|
+
insights: {
|
|
22
|
+
count: number
|
|
23
|
+
}
|
|
24
|
+
isAppleUser: boolean
|
|
25
|
+
isFacebookUser: boolean
|
|
26
|
+
lastCardIndex: number
|
|
27
|
+
lastGradingTime: number
|
|
28
|
+
lastName: string
|
|
29
|
+
soldCards: {
|
|
30
|
+
count: number
|
|
31
|
+
}
|
|
32
|
+
thumbnail: string | undefined
|
|
33
|
+
_collectorType: UserCollectorType
|
|
34
|
+
_createdAt: number
|
|
35
|
+
_currency: string
|
|
36
|
+
_id: string
|
|
37
|
+
_updatedAt: number
|
|
38
|
+
}
|
package/src/utils/tw-utils.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
|
|
3
|
+
const generateSignature = (body: string, secret: string): string => {
|
|
4
|
+
return crypto.createHmac('sha256', secret).update(body).digest('hex')
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
export function isValidWebhookSignature(secret: string, body: string, signature: string): boolean {
|
|
4
|
-
const
|
|
5
|
-
|
|
8
|
+
const expectedSignature = generateSignature(body, secret)
|
|
9
|
+
|
|
10
|
+
const expectedBuffer = Buffer.from(expectedSignature)
|
|
11
|
+
const signatureBuffer = Buffer.from(signature)
|
|
12
|
+
|
|
13
|
+
if (expectedBuffer.length !== signatureBuffer.length) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return crypto.timingSafeEqual(expectedBuffer, signatureBuffer)
|
|
6
18
|
}
|
package/dist/utils/thirdweb.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValidWebhookSignature(secret: string, body: string, signature: string): boolean;
|
package/dist/utils/thirdweb.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isValidWebhookSignature = isValidWebhookSignature;
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
function isValidWebhookSignature(secret, body, signature) {
|
|
9
|
-
const computedSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
10
|
-
return computedSignature === signature;
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const thirdweb_1 = require("./thirdweb");
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
describe('isValidWebhookSignature', () => {
|
|
9
|
-
const secret = 'test_secret';
|
|
10
|
-
const body = '{"message":"hello"}';
|
|
11
|
-
it('returns true for a valid signature', () => {
|
|
12
|
-
const validSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
13
|
-
expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, validSignature)).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it('returns false for an invalid signature', () => {
|
|
16
|
-
const invalidSignature = 'invalidsignature123';
|
|
17
|
-
expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, invalidSignature)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
it('returns false if body or secret is tampered', () => {
|
|
20
|
-
const originalSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
|
|
21
|
-
// wrong body
|
|
22
|
-
expect((0, thirdweb_1.isValidWebhookSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
|
|
23
|
-
// wrong secret
|
|
24
|
-
expect((0, thirdweb_1.isValidWebhookSignature)('wrong_secret', body, originalSignature)).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
});
|