opticedge-cloud-utils 1.0.24 → 1.0.26

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/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './utils/env';
10
10
  export * from './utils/regex';
11
11
  export * from './utils/secrets';
12
12
  export * from './utils/task';
13
+ export * from './utils/thirdweb';
package/dist/index.js CHANGED
@@ -26,3 +26,4 @@ __exportStar(require("./utils/env"), exports);
26
26
  __exportStar(require("./utils/regex"), exports);
27
27
  __exportStar(require("./utils/secrets"), exports);
28
28
  __exportStar(require("./utils/task"), exports);
29
+ __exportStar(require("./utils/thirdweb"), exports);
@@ -5,3 +5,67 @@ export declare enum CardApprovalStatus {
5
5
  Approved = 1,
6
6
  Approving = 999
7
7
  }
8
+ export type MarketReport = {
9
+ data: string;
10
+ title: string;
11
+ price: {
12
+ currency: string;
13
+ range: {
14
+ min: number;
15
+ max: number;
16
+ };
17
+ max: number;
18
+ };
19
+ };
20
+ export type Card = {
21
+ _createdAt: number;
22
+ _updatedAt: number;
23
+ amountToReinvest: number;
24
+ approved?: CardApprovalStatus;
25
+ appraisalReport?: string;
26
+ assetID: string;
27
+ backImage: string;
28
+ backImageUncropped: string;
29
+ card_structure: number;
30
+ countryLanguage?: string;
31
+ cardType: string;
32
+ category: string;
33
+ centering_grading: number;
34
+ corner_grading: number;
35
+ edge_grading: number;
36
+ frontImage: string;
37
+ frontImageUncropped: string;
38
+ gradeDate: number;
39
+ grading: number;
40
+ grading_confidence: number;
41
+ grading_environment: number;
42
+ hp: number;
43
+ identifier: string;
44
+ isPulledFromPack: boolean;
45
+ isRead: boolean;
46
+ isSetCostOfCard: boolean;
47
+ isSold: boolean;
48
+ latitude: number;
49
+ longitude: number;
50
+ moneyEarn: number;
51
+ marketLink?: string;
52
+ marketReport?: MarketReport;
53
+ name: string;
54
+ note: string;
55
+ number: string;
56
+ priceHigh: number;
57
+ priceLow: number;
58
+ priceMarket: number;
59
+ priceValue: number;
60
+ releaseDate: number;
61
+ resultInvisible: boolean;
62
+ saleNote: string;
63
+ series: string;
64
+ setName?: string;
65
+ surface_grading: number;
66
+ tcgLargeImageUrl: string;
67
+ tcgSmallImageUrl: string;
68
+ type: number;
69
+ typeOfGrading: number;
70
+ userId: string;
71
+ };
@@ -0,0 +1 @@
1
+ export declare function isValidSignature(secret: string, body: string, signature: string): boolean;
@@ -0,0 +1,11 @@
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.isValidSignature = isValidSignature;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ function isValidSignature(secret, body, signature) {
9
+ const computedSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
10
+ return computedSignature === signature;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
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('isValidSignature', () => {
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.isValidSignature)(secret, body, validSignature)).toBe(true);
14
+ });
15
+ it('returns false for an invalid signature', () => {
16
+ const invalidSignature = 'invalidsignature123';
17
+ expect((0, thirdweb_1.isValidSignature)(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.isValidSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
23
+ // wrong secret
24
+ expect((0, thirdweb_1.isValidSignature)('wrong_secret', body, originalSignature)).toBe(false);
25
+ });
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from './utils/env'
10
10
  export * from './utils/regex'
11
11
  export * from './utils/secrets'
12
12
  export * from './utils/task'
13
+ export * from './utils/thirdweb'
package/src/types/card.ts CHANGED
@@ -5,3 +5,69 @@ export enum CardApprovalStatus {
5
5
  Approved,
6
6
  Approving = 999
7
7
  }
8
+
9
+ export type MarketReport = {
10
+ data: string
11
+ title: string
12
+ price: {
13
+ currency: string
14
+ range: {
15
+ min: number
16
+ max: number
17
+ }
18
+ max: number
19
+ }
20
+ }
21
+
22
+ export type Card = {
23
+ _createdAt: number
24
+ _updatedAt: number
25
+ amountToReinvest: number
26
+ approved?: CardApprovalStatus
27
+ appraisalReport?: string
28
+ assetID: string
29
+ backImage: string
30
+ backImageUncropped: string
31
+ card_structure: number
32
+ countryLanguage?: string
33
+ cardType: string
34
+ category: string
35
+ centering_grading: number
36
+ corner_grading: number
37
+ edge_grading: number
38
+ frontImage: string
39
+ frontImageUncropped: string
40
+ gradeDate: number
41
+ grading: number
42
+ grading_confidence: number
43
+ grading_environment: number
44
+ hp: number
45
+ identifier: string
46
+ isPulledFromPack: boolean
47
+ isRead: boolean
48
+ isSetCostOfCard: boolean
49
+ isSold: boolean
50
+ latitude: number
51
+ longitude: number
52
+ moneyEarn: number
53
+ marketLink?: string
54
+ marketReport?: MarketReport
55
+ name: string
56
+ note: string
57
+ number: string
58
+ priceHigh: number
59
+ priceLow: number
60
+ priceMarket: number
61
+ priceValue: number
62
+ releaseDate: number
63
+ resultInvisible: boolean
64
+ saleNote: string
65
+ series: string
66
+ setName?: string
67
+ surface_grading: number
68
+ tcgLargeImageUrl: string
69
+ tcgSmallImageUrl: string
70
+ type: number
71
+ typeOfGrading: number
72
+ userId: string
73
+ }
@@ -0,0 +1,29 @@
1
+ import { isValidSignature } from './thirdweb'
2
+ import crypto from 'crypto'
3
+
4
+ describe('isValidSignature', () => {
5
+ const secret = 'test_secret'
6
+ const body = '{"message":"hello"}'
7
+
8
+ it('returns true for a valid signature', () => {
9
+ const validSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
10
+
11
+ expect(isValidSignature(secret, body, validSignature)).toBe(true)
12
+ })
13
+
14
+ it('returns false for an invalid signature', () => {
15
+ const invalidSignature = 'invalidsignature123'
16
+
17
+ expect(isValidSignature(secret, body, invalidSignature)).toBe(false)
18
+ })
19
+
20
+ it('returns false if body or secret is tampered', () => {
21
+ const originalSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
22
+
23
+ // wrong body
24
+ expect(isValidSignature(secret, '{"message":"tampered"}', originalSignature)).toBe(false)
25
+
26
+ // wrong secret
27
+ expect(isValidSignature('wrong_secret', body, originalSignature)).toBe(false)
28
+ })
29
+ })
@@ -0,0 +1,6 @@
1
+ import crypto from 'crypto'
2
+
3
+ export function isValidSignature(secret: string, body: string, signature: string): boolean {
4
+ const computedSignature = crypto.createHmac('sha256', secret).update(body).digest('hex')
5
+ return computedSignature === signature
6
+ }