mvc-common-toolkit 1.43.8 → 1.43.9

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.
Files changed (152) hide show
  1. package/dist/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +1 -1
  3. package/dist/src/constants.d.ts +0 -42
  4. package/dist/src/constants.js +0 -50
  5. package/dist/src/constants.js.map +0 -1
  6. package/dist/src/gateways/alibaba-cloud-gateway.d.ts +0 -30
  7. package/dist/src/gateways/alibaba-cloud-gateway.js +0 -120
  8. package/dist/src/gateways/alibaba-cloud-gateway.js.map +0 -1
  9. package/dist/src/gateways/http-audit-gateway.d.ts +0 -20
  10. package/dist/src/gateways/http-audit-gateway.js +0 -76
  11. package/dist/src/gateways/http-audit-gateway.js.map +0 -1
  12. package/dist/src/gateways/index.d.ts +0 -5
  13. package/dist/src/gateways/index.js +0 -22
  14. package/dist/src/gateways/index.js.map +0 -1
  15. package/dist/src/gateways/internal-auth-gateway.d.ts +0 -8
  16. package/dist/src/gateways/internal-auth-gateway.js +0 -40
  17. package/dist/src/gateways/internal-auth-gateway.js.map +0 -1
  18. package/dist/src/gateways/stdout-audit-gateway.d.ts +0 -7
  19. package/dist/src/gateways/stdout-audit-gateway.js +0 -25
  20. package/dist/src/gateways/stdout-audit-gateway.js.map +0 -1
  21. package/dist/src/gateways/webhook-audit-gateway.d.ts +0 -14
  22. package/dist/src/gateways/webhook-audit-gateway.js +0 -27
  23. package/dist/src/gateways/webhook-audit-gateway.js.map +0 -1
  24. package/dist/src/interfaces.d.ts +0 -215
  25. package/dist/src/interfaces.js +0 -3
  26. package/dist/src/interfaces.js.map +0 -1
  27. package/dist/src/models/audit-log.d.ts +0 -77
  28. package/dist/src/models/audit-log.js +0 -92
  29. package/dist/src/models/audit-log.js.map +0 -1
  30. package/dist/src/models/index.d.ts +0 -1
  31. package/dist/src/models/index.js +0 -18
  32. package/dist/src/models/index.js.map +0 -1
  33. package/dist/src/pkg/array-helper.d.ts +0 -1
  34. package/dist/src/pkg/array-helper.js +0 -12
  35. package/dist/src/pkg/array-helper.js.map +0 -1
  36. package/dist/src/pkg/bcrypt-helper.d.ts +0 -2
  37. package/dist/src/pkg/bcrypt-helper.js +0 -36
  38. package/dist/src/pkg/bcrypt-helper.js.map +0 -1
  39. package/dist/src/pkg/crypto-helper.d.ts +0 -2
  40. package/dist/src/pkg/crypto-helper.js +0 -16
  41. package/dist/src/pkg/crypto-helper.js.map +0 -1
  42. package/dist/src/pkg/encryption-helper.d.ts +0 -18
  43. package/dist/src/pkg/encryption-helper.js +0 -89
  44. package/dist/src/pkg/encryption-helper.js.map +0 -1
  45. package/dist/src/pkg/encryption-helper.spec.d.ts +0 -1
  46. package/dist/src/pkg/encryption-helper.spec.js +0 -238
  47. package/dist/src/pkg/encryption-helper.spec.js.map +0 -1
  48. package/dist/src/pkg/filter-helper.d.ts +0 -2
  49. package/dist/src/pkg/filter-helper.js +0 -102
  50. package/dist/src/pkg/filter-helper.js.map +0 -1
  51. package/dist/src/pkg/filter-helper.spec.d.ts +0 -1
  52. package/dist/src/pkg/filter-helper.spec.js +0 -94
  53. package/dist/src/pkg/filter-helper.spec.js.map +0 -1
  54. package/dist/src/pkg/geoip-helper.d.ts +0 -2
  55. package/dist/src/pkg/geoip-helper.js +0 -32
  56. package/dist/src/pkg/geoip-helper.js.map +0 -1
  57. package/dist/src/pkg/hash-helper.d.ts +0 -1
  58. package/dist/src/pkg/hash-helper.js +0 -37
  59. package/dist/src/pkg/hash-helper.js.map +0 -1
  60. package/dist/src/pkg/http-request-utils.d.ts +0 -4
  61. package/dist/src/pkg/http-request-utils.js +0 -55
  62. package/dist/src/pkg/http-request-utils.js.map +0 -1
  63. package/dist/src/pkg/index.d.ts +0 -18
  64. package/dist/src/pkg/index.js +0 -45
  65. package/dist/src/pkg/index.js.map +0 -1
  66. package/dist/src/pkg/key-helper.d.ts +0 -2
  67. package/dist/src/pkg/key-helper.js +0 -20
  68. package/dist/src/pkg/key-helper.js.map +0 -1
  69. package/dist/src/pkg/logger.d.ts +0 -9
  70. package/dist/src/pkg/logger.js +0 -23
  71. package/dist/src/pkg/logger.js.map +0 -1
  72. package/dist/src/pkg/object-helper.d.ts +0 -2
  73. package/dist/src/pkg/object-helper.js +0 -37
  74. package/dist/src/pkg/object-helper.js.map +0 -1
  75. package/dist/src/pkg/paginated-cache-registry.d.ts +0 -8
  76. package/dist/src/pkg/paginated-cache-registry.js +0 -23
  77. package/dist/src/pkg/paginated-cache-registry.js.map +0 -1
  78. package/dist/src/pkg/query-helper.d.ts +0 -3
  79. package/dist/src/pkg/query-helper.js +0 -60
  80. package/dist/src/pkg/query-helper.js.map +0 -1
  81. package/dist/src/pkg/referral-tree-utils.d.ts +0 -33
  82. package/dist/src/pkg/referral-tree-utils.js +0 -71
  83. package/dist/src/pkg/referral-tree-utils.js.map +0 -1
  84. package/dist/src/pkg/scripts/index.d.ts +0 -1
  85. package/dist/src/pkg/scripts/index.js +0 -28
  86. package/dist/src/pkg/scripts/index.js.map +0 -1
  87. package/dist/src/pkg/scripts/lua.d.ts +0 -10
  88. package/dist/src/pkg/scripts/lua.js +0 -109
  89. package/dist/src/pkg/scripts/lua.js.map +0 -1
  90. package/dist/src/pkg/sort-helper.d.ts +0 -3
  91. package/dist/src/pkg/sort-helper.js +0 -18
  92. package/dist/src/pkg/sort-helper.js.map +0 -1
  93. package/dist/src/pkg/string-utils.d.ts +0 -10
  94. package/dist/src/pkg/string-utils.js +0 -79
  95. package/dist/src/pkg/string-utils.js.map +0 -1
  96. package/dist/src/pkg/task-helper.d.ts +0 -2
  97. package/dist/src/pkg/task-helper.js +0 -30
  98. package/dist/src/pkg/task-helper.js.map +0 -1
  99. package/dist/src/pkg/workflow/delayed-task-registry.d.ts +0 -10
  100. package/dist/src/pkg/workflow/delayed-task-registry.js +0 -67
  101. package/dist/src/pkg/workflow/delayed-task-registry.js.map +0 -1
  102. package/dist/src/pkg/workflow/delayed-task.d.ts +0 -18
  103. package/dist/src/pkg/workflow/delayed-task.js +0 -95
  104. package/dist/src/pkg/workflow/delayed-task.js.map +0 -1
  105. package/dist/src/pkg/workflow/index.d.ts +0 -5
  106. package/dist/src/pkg/workflow/index.js +0 -22
  107. package/dist/src/pkg/workflow/index.js.map +0 -1
  108. package/dist/src/pkg/workflow/processing-milestone.d.ts +0 -18
  109. package/dist/src/pkg/workflow/processing-milestone.js +0 -39
  110. package/dist/src/pkg/workflow/processing-milestone.js.map +0 -1
  111. package/dist/src/pkg/workflow/retry-task.d.ts +0 -24
  112. package/dist/src/pkg/workflow/retry-task.js +0 -89
  113. package/dist/src/pkg/workflow/retry-task.js.map +0 -1
  114. package/dist/src/pkg/workflow/retry-task.spec.d.ts +0 -1
  115. package/dist/src/pkg/workflow/retry-task.spec.js +0 -145
  116. package/dist/src/pkg/workflow/retry-task.spec.js.map +0 -1
  117. package/dist/src/pkg/workflow/sync-taskqueue.d.ts +0 -32
  118. package/dist/src/pkg/workflow/sync-taskqueue.js +0 -108
  119. package/dist/src/pkg/workflow/sync-taskqueue.js.map +0 -1
  120. package/dist/src/pkg/worksheet.utils.d.ts +0 -27
  121. package/dist/src/pkg/worksheet.utils.js +0 -116
  122. package/dist/src/pkg/worksheet.utils.js.map +0 -1
  123. package/dist/src/services/audit-service.d.ts +0 -7
  124. package/dist/src/services/audit-service.js +0 -32
  125. package/dist/src/services/audit-service.js.map +0 -1
  126. package/dist/src/services/excel.service.d.ts +0 -25
  127. package/dist/src/services/excel.service.js +0 -95
  128. package/dist/src/services/excel.service.js.map +0 -1
  129. package/dist/src/services/http-service.d.ts +0 -7
  130. package/dist/src/services/http-service.js +0 -67
  131. package/dist/src/services/http-service.js.map +0 -1
  132. package/dist/src/services/index.d.ts +0 -8
  133. package/dist/src/services/index.js +0 -25
  134. package/dist/src/services/index.js.map +0 -1
  135. package/dist/src/services/kafka-service.d.ts +0 -15
  136. package/dist/src/services/kafka-service.js +0 -68
  137. package/dist/src/services/kafka-service.js.map +0 -1
  138. package/dist/src/services/mailer-service.d.ts +0 -15
  139. package/dist/src/services/mailer-service.js +0 -44
  140. package/dist/src/services/mailer-service.js.map +0 -1
  141. package/dist/src/services/paginated-cache.d.ts +0 -16
  142. package/dist/src/services/paginated-cache.js +0 -115
  143. package/dist/src/services/paginated-cache.js.map +0 -1
  144. package/dist/src/services/paginated-cache.spec.d.ts +0 -1
  145. package/dist/src/services/paginated-cache.spec.js +0 -284
  146. package/dist/src/services/paginated-cache.spec.js.map +0 -1
  147. package/dist/src/services/redis-service.d.ts +0 -33
  148. package/dist/src/services/redis-service.js +0 -216
  149. package/dist/src/services/redis-service.js.map +0 -1
  150. package/dist/src/services/security-service.d.ts +0 -11
  151. package/dist/src/services/security-service.js +0 -68
  152. package/dist/src/services/security-service.js.map +0 -1
@@ -1,77 +0,0 @@
1
- import { LOG_LEVEL } from "../constants";
2
- export type LogObject = ErrorLog | InfoLog | DebugLog;
3
- export interface LogObjectData {
4
- logId: string;
5
- userId?: string;
6
- level: LOG_LEVEL;
7
- action: string;
8
- message?: any;
9
- payload?: any;
10
- metadata?: any;
11
- }
12
- export declare abstract class BaseLog {
13
- logId: string;
14
- userId: string;
15
- level: LOG_LEVEL;
16
- action: string;
17
- message?: any;
18
- payload?: any;
19
- metadata?: any;
20
- constructor(data: Omit<LogObjectData, "level">);
21
- abstract toJSON(): Record<string, any>;
22
- }
23
- export declare class ErrorLog extends BaseLog {
24
- constructor(data: Omit<LogObjectData, "level">);
25
- toJSON(): {
26
- logId: string;
27
- userId: string;
28
- level: LOG_LEVEL;
29
- action: string;
30
- message: any;
31
- metadata: any;
32
- payload: any;
33
- };
34
- }
35
- export declare class FatalLog extends BaseLog {
36
- constructor(data: Omit<LogObjectData, "level">);
37
- toJSON(): {
38
- logId: string;
39
- userId: string;
40
- level: LOG_LEVEL;
41
- action: string;
42
- message: any;
43
- metadata: any;
44
- payload: any;
45
- };
46
- }
47
- export declare class InfoLog extends BaseLog {
48
- constructor(data: Omit<LogObjectData, "level">);
49
- toJSON(): {
50
- logId: string;
51
- userId: string;
52
- level: LOG_LEVEL;
53
- action: string;
54
- message: any;
55
- metadata: any;
56
- payload: any;
57
- };
58
- }
59
- export declare class DebugLog extends BaseLog {
60
- parentLogId?: string;
61
- parentLogType?: LOG_LEVEL;
62
- constructor(data: Omit<LogObjectData, "level"> & {
63
- parentLogId?: string;
64
- parentLogType?: LOG_LEVEL;
65
- });
66
- toJSON(): {
67
- logId: string;
68
- userId: string;
69
- level: LOG_LEVEL;
70
- action: string;
71
- message: any;
72
- metadata: any;
73
- payload: any;
74
- parentLogId: string;
75
- parentLogType: LOG_LEVEL;
76
- };
77
- }
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DebugLog = exports.InfoLog = exports.FatalLog = exports.ErrorLog = exports.BaseLog = void 0;
4
- const constants_1 = require("../constants");
5
- class BaseLog {
6
- constructor(data) {
7
- this.logId = data.logId;
8
- this.userId = data.userId;
9
- this.action = data.action;
10
- this.message = data.message;
11
- this.metadata = data.metadata;
12
- this.payload = data.payload;
13
- }
14
- }
15
- exports.BaseLog = BaseLog;
16
- class ErrorLog extends BaseLog {
17
- constructor(data) {
18
- super(data);
19
- this.level = constants_1.LOG_LEVEL.ERROR;
20
- }
21
- toJSON() {
22
- return {
23
- logId: this.logId,
24
- userId: this.userId,
25
- level: this.level,
26
- action: this.action,
27
- message: this.message,
28
- metadata: this.metadata,
29
- payload: this.payload,
30
- };
31
- }
32
- }
33
- exports.ErrorLog = ErrorLog;
34
- class FatalLog extends BaseLog {
35
- constructor(data) {
36
- super(data);
37
- this.level = constants_1.LOG_LEVEL.FATAL;
38
- }
39
- toJSON() {
40
- return {
41
- logId: this.logId,
42
- userId: this.userId,
43
- level: this.level,
44
- action: this.action,
45
- message: this.message,
46
- metadata: this.metadata,
47
- payload: this.payload,
48
- };
49
- }
50
- }
51
- exports.FatalLog = FatalLog;
52
- class InfoLog extends BaseLog {
53
- constructor(data) {
54
- super(data);
55
- this.level = constants_1.LOG_LEVEL.INFO;
56
- }
57
- toJSON() {
58
- return {
59
- logId: this.logId,
60
- userId: this.userId,
61
- level: this.level,
62
- action: this.action,
63
- message: this.message,
64
- metadata: this.metadata,
65
- payload: this.payload,
66
- };
67
- }
68
- }
69
- exports.InfoLog = InfoLog;
70
- class DebugLog extends BaseLog {
71
- constructor(data) {
72
- super(data);
73
- this.level = constants_1.LOG_LEVEL.DEBUG;
74
- this.parentLogId = data.parentLogId;
75
- this.parentLogType = data.parentLogType;
76
- }
77
- toJSON() {
78
- return {
79
- logId: this.logId,
80
- userId: this.userId,
81
- level: this.level,
82
- action: this.action,
83
- message: this.message,
84
- metadata: this.metadata,
85
- payload: this.payload,
86
- parentLogId: this.parentLogId,
87
- parentLogType: this.parentLogType,
88
- };
89
- }
90
- }
91
- exports.DebugLog = DebugLog;
92
- //# sourceMappingURL=audit-log.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audit-log.js","sourceRoot":"","sources":["../../../src/models/audit-log.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AAczC,MAAsB,OAAO;IAS3B,YAAY,IAAkC;QAC5C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;CAGF;AAnBD,0BAmBC;AAED,MAAa,QAAS,SAAQ,OAAO;IACnC,YAAY,IAAkC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,KAAK,GAAG,qBAAS,CAAC,KAAK,CAAC;IAC/B,CAAC;IAEM,M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CAAC;IACJ,CAAC;CACF;AAlBD,0BAkBC;AAED,MAAa,QAAS,SAAQ,OAAO;IAInC,YACE,IAGC;QAED,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,KAAK,GAAG,qBAAS,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;IAC1C,CAAC;IAEM,MAAM;QACX,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;CACF;AA9BD,4BA8BC"}
@@ -1 +0,0 @@
1
- export * from "./audit-log";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./audit-log"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
@@ -1 +0,0 @@
1
- export declare function shuffle<T>(array: T[]): T[];
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shuffle = void 0;
4
- function shuffle(array) {
5
- for (let i = array.length - 1; i > 0; i--) {
6
- const j = Math.floor(Math.random() * (i + 1));
7
- [array[i], array[j]] = [array[j], array[i]];
8
- }
9
- return array;
10
- }
11
- exports.shuffle = shuffle;
12
- //# sourceMappingURL=array-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-helper.js","sourceRoot":"","sources":["../../../src/pkg/array-helper.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO,CAAI,KAAU;IACnC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAND,0BAMC"}
@@ -1,2 +0,0 @@
1
- export declare function hash(data: string, salt?: string | number): Promise<string>;
2
- export declare function compare(raw: string, hashed: string): Promise<boolean>;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.compare = exports.hash = void 0;
27
- const bcrypt = __importStar(require("bcrypt"));
28
- function hash(data, salt) {
29
- return bcrypt.hash(data, salt || 12);
30
- }
31
- exports.hash = hash;
32
- function compare(raw, hashed) {
33
- return bcrypt.compare(raw, hashed);
34
- }
35
- exports.compare = compare;
36
- //# sourceMappingURL=bcrypt-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bcrypt-helper.js","sourceRoot":"","sources":["../../../src/pkg/bcrypt-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,SAAgB,IAAI,CAAC,IAAY,EAAE,IAAsB;IACvD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC;AAFD,oBAEC;AAED,SAAgB,OAAO,CAAC,GAAW,EAAE,MAAc;IACjD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACrC,CAAC;AAFD,0BAEC"}
@@ -1,2 +0,0 @@
1
- export declare const sha512Encrypt: (data: string, privateKey: string) => string;
2
- export declare const sha512Verify: (hashedToVerify: string, data: string, privateKey: string) => boolean;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sha512Verify = exports.sha512Encrypt = void 0;
4
- const crypto_1 = require("crypto");
5
- const sha512Encrypt = (data, privateKey) => {
6
- const sha512Hasher = (0, crypto_1.createHash)("sha512");
7
- const finalData = `${data}_${privateKey}`;
8
- return sha512Hasher.update(finalData).digest("hex");
9
- };
10
- exports.sha512Encrypt = sha512Encrypt;
11
- const sha512Verify = (hashedToVerify, data, privateKey) => {
12
- const hashed = (0, exports.sha512Encrypt)(data, privateKey);
13
- return hashedToVerify === hashed;
14
- };
15
- exports.sha512Verify = sha512Verify;
16
- //# sourceMappingURL=crypto-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto-helper.js","sourceRoot":"","sources":["../../../src/pkg/crypto-helper.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAE7B,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,UAAkB,EAAE,EAAE;IAChE,MAAM,YAAY,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,UAAU,EAAE,CAAC;IAE1C,OAAO,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB;AAEK,MAAM,YAAY,GAAG,CAC1B,cAAsB,EACtB,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,MAAM,GAAG,IAAA,qBAAa,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAE/C,OAAO,cAAc,KAAK,MAAM,CAAC;AACnC,CAAC,CAAC;AARW,QAAA,YAAY,gBAQvB"}
@@ -1,18 +0,0 @@
1
- interface EncryptedPayload {
2
- iv: string;
3
- salt: string;
4
- ciphertext: string;
5
- tag: string;
6
- }
7
- interface EncryptedPayload2FA {
8
- iv: string;
9
- saltUser: string;
10
- saltServer: string;
11
- ciphertext: string;
12
- tag: string;
13
- }
14
- export declare function encrypt(text: string, password: string): EncryptedPayload;
15
- export declare function decrypt(payload: EncryptedPayload, password: string): string;
16
- export declare function encryptWithTwoFactors(plaintext: string, userPassword: string, serverSecret: string): EncryptedPayload2FA;
17
- export declare function decryptWithTwoFactors(payload: EncryptedPayload2FA, userPassword: string, serverSecret: string): string;
18
- export {};
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptWithTwoFactors = exports.encryptWithTwoFactors = exports.decrypt = exports.encrypt = void 0;
4
- const crypto_1 = require("crypto");
5
- const PBKDF2_ITERATIONS = 310000;
6
- const KEY_LEN = 32;
7
- const IV_LEN = 12;
8
- const SALT_LEN = 16;
9
- function encrypt(text, password) {
10
- const salt = (0, crypto_1.randomBytes)(SALT_LEN);
11
- const key = (0, crypto_1.pbkdf2Sync)(password, salt, PBKDF2_ITERATIONS, KEY_LEN, "sha256");
12
- const iv = (0, crypto_1.randomBytes)(IV_LEN);
13
- const cipher = (0, crypto_1.createCipheriv)("aes-256-gcm", key, iv);
14
- const ciphertext = Buffer.concat([
15
- cipher.update(text, "utf8"),
16
- cipher.final(),
17
- ]);
18
- const tag = cipher.getAuthTag();
19
- return {
20
- iv: iv.toString("hex"),
21
- salt: salt.toString("hex"),
22
- ciphertext: ciphertext.toString("hex"),
23
- tag: tag.toString("hex"),
24
- };
25
- }
26
- exports.encrypt = encrypt;
27
- function decrypt(payload, password) {
28
- const { iv, salt, ciphertext, tag } = payload;
29
- const key = (0, crypto_1.pbkdf2Sync)(Buffer.from(password), Buffer.from(salt, "hex"), PBKDF2_ITERATIONS, KEY_LEN, "sha256");
30
- const decipher = (0, crypto_1.createDecipheriv)("aes-256-gcm", key, Buffer.from(iv, "hex"));
31
- decipher.setAuthTag(Buffer.from(tag, "hex"));
32
- const plaintext = Buffer.concat([
33
- decipher.update(Buffer.from(ciphertext, "hex")),
34
- decipher.final(),
35
- ]);
36
- return plaintext.toString("utf8");
37
- }
38
- exports.decrypt = decrypt;
39
- function deriveKey(password, salt) {
40
- return (0, crypto_1.pbkdf2Sync)(password, salt, PBKDF2_ITERATIONS, KEY_LEN, "sha256");
41
- }
42
- function encryptWithTwoFactors(plaintext, userPassword, serverSecret) {
43
- const saltUser = (0, crypto_1.randomBytes)(SALT_LEN);
44
- const saltServer = (0, crypto_1.randomBytes)(SALT_LEN);
45
- const userKey = deriveKey(userPassword, saltUser);
46
- const serverKey = deriveKey(serverSecret, saltServer);
47
- const finalKey = Buffer.alloc(KEY_LEN);
48
- for (let i = 0; i < KEY_LEN; i++) {
49
- finalKey[i] = userKey[i] ^ serverKey[i];
50
- }
51
- const iv = (0, crypto_1.randomBytes)(IV_LEN);
52
- const cipher = (0, crypto_1.createCipheriv)("aes-256-gcm", finalKey, iv);
53
- const ciphertext = Buffer.concat([
54
- cipher.update(plaintext, "utf8"),
55
- cipher.final(),
56
- ]);
57
- const tag = cipher.getAuthTag();
58
- userKey.fill(0);
59
- serverKey.fill(0);
60
- finalKey.fill(0);
61
- return {
62
- iv: iv.toString("hex"),
63
- saltUser: saltUser.toString("hex"),
64
- saltServer: saltServer.toString("hex"),
65
- ciphertext: ciphertext.toString("hex"),
66
- tag: tag.toString("hex"),
67
- };
68
- }
69
- exports.encryptWithTwoFactors = encryptWithTwoFactors;
70
- function decryptWithTwoFactors(payload, userPassword, serverSecret) {
71
- const userKey = deriveKey(userPassword, Buffer.from(payload.saltUser, "hex"));
72
- const serverKey = deriveKey(serverSecret, Buffer.from(payload.saltServer, "hex"));
73
- const finalKey = Buffer.alloc(KEY_LEN);
74
- for (let i = 0; i < KEY_LEN; i++) {
75
- finalKey[i] = userKey[i] ^ serverKey[i];
76
- }
77
- const decipher = (0, crypto_1.createDecipheriv)("aes-256-gcm", finalKey, Buffer.from(payload.iv, "hex"));
78
- decipher.setAuthTag(Buffer.from(payload.tag, "hex"));
79
- const plaintext = Buffer.concat([
80
- decipher.update(Buffer.from(payload.ciphertext, "hex")),
81
- decipher.final(),
82
- ]);
83
- userKey.fill(0);
84
- serverKey.fill(0);
85
- finalKey.fill(0);
86
- return plaintext.toString("utf8");
87
- }
88
- exports.decryptWithTwoFactors = decryptWithTwoFactors;
89
- //# sourceMappingURL=encryption-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption-helper.js","sourceRoot":"","sources":["../../../src/pkg/encryption-helper.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAEhB,MAAM,iBAAiB,GAAG,MAAO,CAAC;AAClC,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,QAAQ,GAAG,EAAE,CAAC;AAoBpB,SAAgB,OAAO,CAAC,IAAY,EAAE,QAAgB;IACpD,MAAM,IAAI,GAAG,IAAA,oBAAW,EAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,IAAA,mBAAU,EAAC,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE7E,MAAM,EAAE,GAAG,IAAA,oBAAW,EAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAA,uBAAc,EAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAEtD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,KAAK,EAAE;KACf,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAEhC,OAAO;QACL,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC1B,UAAU,EAAE,U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CAAC,CAAC;AACpC,CAAC;AAlCD,sDAkCC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,238 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chai_1 = require("chai");
4
- const encryption_helper_1 = require("./encryption-helper");
5
- describe("encryption helper", () => {
6
- describe("single factor encryption", () => {
7
- it("should encrypt and decrypt text correctly", () => {
8
- const plaintext = "Hello, World!";
9
- const password = "my-secret-password";
10
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
11
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, password);
12
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
13
- });
14
- it("should handle empty string", () => {
15
- const plaintext = "";
16
- const password = "my-secret-password";
17
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
18
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, password);
19
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
20
- });
21
- it("should handle special characters and unicode", () => {
22
- const plaintext = "Hello 世界! 🚀 测试";
23
- const password = "my-secret-password";
24
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
25
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, password);
26
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
27
- });
28
- it("should handle long text", () => {
29
- const plaintext = "A".repeat(1000);
30
- const password = "my-secret-password";
31
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
32
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, password);
33
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
34
- });
35
- it("should produce different ciphertext for same plaintext with different passwords", () => {
36
- const plaintext = "Hello, World!";
37
- const password1 = "password1";
38
- const password2 = "password2";
39
- const encrypted1 = (0, encryption_helper_1.encrypt)(plaintext, password1);
40
- const encrypted2 = (0, encryption_helper_1.encrypt)(plaintext, password2);
41
- (0, chai_1.expect)(encrypted1.ciphertext).to.not.equal(encrypted2.ciphertext);
42
- });
43
- it("should produce different ciphertext for same plaintext and password (due to random salt/iv)", () => {
44
- const plaintext = "Hello, World!";
45
- const password = "my-secret-password";
46
- const encrypted1 = (0, encryption_helper_1.encrypt)(plaintext, password);
47
- const encrypted2 = (0, encryption_helper_1.encrypt)(plaintext, password);
48
- (0, chai_1.expect)(encrypted1.ciphertext).to.not.equal(encrypted2.ciphertext);
49
- (0, chai_1.expect)(encrypted1.iv).to.not.equal(encrypted2.iv);
50
- (0, chai_1.expect)(encrypted1.salt).to.not.equal(encrypted2.salt);
51
- });
52
- it("should fail decryption with wrong password", () => {
53
- const plaintext = "Hello, World!";
54
- const correctPassword = "correct-password";
55
- const wrongPassword = "wrong-password";
56
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, correctPassword);
57
- (0, chai_1.expect)(() => (0, encryption_helper_1.decrypt)(encrypted, wrongPassword)).to.throw();
58
- });
59
- it("should fail decryption with corrupted payload", () => {
60
- const plaintext = "Hello, World!";
61
- const password = "my-secret-password";
62
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
63
- const corruptedPayload = Object.assign(Object.assign({}, encrypted), { ciphertext: "corrupted-ciphertext" });
64
- (0, chai_1.expect)(() => (0, encryption_helper_1.decrypt)(corruptedPayload, password)).to.throw();
65
- });
66
- it("should fail decryption with corrupted auth tag", () => {
67
- const plaintext = "Hello, World!";
68
- const password = "my-secret-password";
69
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
70
- const corruptedPayload = Object.assign(Object.assign({}, encrypted), { tag: "corrupted-tag" });
71
- (0, chai_1.expect)(() => (0, encryption_helper_1.decrypt)(corruptedPayload, password)).to.throw();
72
- });
73
- it("should have correct payload structure", () => {
74
- const plaintext = "Hello, World!";
75
- const password = "my-secret-password";
76
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
77
- (0, chai_1.expect)(encrypted).to.have.property("iv");
78
- (0, chai_1.expect)(encrypted).to.have.property("salt");
79
- (0, chai_1.expect)(encrypted).to.have.property("ciphertext");
80
- (0, chai_1.expect)(encrypted).to.have.property("tag");
81
- (0, chai_1.expect)(encrypted.iv).to.be.a("string");
82
- (0, chai_1.expect)(encrypted.salt).to.be.a("string");
83
- (0, chai_1.expect)(encrypted.ciphertext).to.be.a("string");
84
- (0, chai_1.expect)(encrypted.tag).to.be.a("string");
85
- (0, chai_1.expect)(encrypted.iv).to.match(/^[0-9a-f]+$/);
86
- (0, chai_1.expect)(encrypted.salt).to.match(/^[0-9a-f]+$/);
87
- (0, chai_1.expect)(encrypted.ciphertext).to.match(/^[0-9a-f]+$/);
88
- (0, chai_1.expect)(encrypted.tag).to.match(/^[0-9a-f]+$/);
89
- });
90
- });
91
- describe("two factor encryption", () => {
92
- it("should encrypt and decrypt text correctly with two factors", () => {
93
- const plaintext = "Hello, World!";
94
- const userPassword = "user-password";
95
- const serverSecret = "server-secret";
96
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
97
- const decrypted = (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, userPassword, serverSecret);
98
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
99
- });
100
- it("should handle empty string with two factors", () => {
101
- const plaintext = "";
102
- const userPassword = "user-password";
103
- const serverSecret = "server-secret";
104
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
105
- const decrypted = (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, userPassword, serverSecret);
106
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
107
- });
108
- it("should handle special characters and unicode with two factors", () => {
109
- const plaintext = "Hello 世界! 🚀 测试";
110
- const userPassword = "user-password";
111
- const serverSecret = "server-secret";
112
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
113
- const decrypted = (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, userPassword, serverSecret);
114
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
115
- });
116
- it("should handle long text with two factors", () => {
117
- const plaintext = "A".repeat(1000);
118
- const userPassword = "user-password";
119
- const serverSecret = "server-secret";
120
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
121
- const decrypted = (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, userPassword, serverSecret);
122
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
123
- });
124
- it("should produce different ciphertext for same plaintext with different factors", () => {
125
- const plaintext = "Hello, World!";
126
- const userPassword1 = "user1";
127
- const userPassword2 = "user2";
128
- const serverSecret = "server-secret";
129
- const encrypted1 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword1, serverSecret);
130
- const encrypted2 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword2, serverSecret);
131
- (0, chai_1.expect)(encrypted1.ciphertext).to.not.equal(encrypted2.ciphertext);
132
- });
133
- it("should produce different ciphertext for same plaintext and factors (due to random salt/iv)", () => {
134
- const plaintext = "Hello, World!";
135
- const userPassword = "user-password";
136
- const serverSecret = "server-secret";
137
- const encrypted1 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
138
- const encrypted2 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
139
- (0, chai_1.expect)(encrypted1.ciphertext).to.not.equal(encrypted2.ciphertext);
140
- (0, chai_1.expect)(encrypted1.iv).to.not.equal(encrypted2.iv);
141
- (0, chai_1.expect)(encrypted1.saltUser).to.not.equal(encrypted2.saltUser);
142
- (0, chai_1.expect)(encrypted1.saltServer).to.not.equal(encrypted2.saltServer);
143
- });
144
- it("should fail decryption with wrong user password", () => {
145
- const plaintext = "Hello, World!";
146
- const correctUserPassword = "correct-user-password";
147
- const wrongUserPassword = "wrong-user-password";
148
- const serverSecret = "server-secret";
149
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, correctUserPassword, serverSecret);
150
- (0, chai_1.expect)(() => (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, wrongUserPassword, serverSecret)).to.throw();
151
- });
152
- it("should fail decryption with wrong server secret", () => {
153
- const plaintext = "Hello, World!";
154
- const userPassword = "user-password";
155
- const correctServerSecret = "correct-server-secret";
156
- const wrongServerSecret = "wrong-server-secret";
157
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, correctServerSecret);
158
- (0, chai_1.expect)(() => (0, encryption_helper_1.decryptWithTwoFactors)(encrypted, userPassword, wrongServerSecret)).to.throw();
159
- });
160
- it("should fail decryption with corrupted payload", () => {
161
- const plaintext = "Hello, World!";
162
- const userPassword = "user-password";
163
- const serverSecret = "server-secret";
164
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
165
- const corruptedPayload = Object.assign(Object.assign({}, encrypted), { ciphertext: "corrupted-ciphertext" });
166
- (0, chai_1.expect)(() => (0, encryption_helper_1.decryptWithTwoFactors)(corruptedPayload, userPassword, serverSecret)).to.throw();
167
- });
168
- it("should fail decryption with corrupted auth tag", () => {
169
- const plaintext = "Hello, World!";
170
- const userPassword = "user-password";
171
- const serverSecret = "server-secret";
172
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
173
- const corruptedPayload = Object.assign(Object.assign({}, encrypted), { tag: "corrupted-tag" });
174
- (0, chai_1.expect)(() => (0, encryption_helper_1.decryptWithTwoFactors)(corruptedPayload, userPassword, serverSecret)).to.throw();
175
- });
176
- it("should have correct payload structure for two factors", () => {
177
- const plaintext = "Hello, World!";
178
- const userPassword = "user-password";
179
- const serverSecret = "server-secret";
180
- const encrypted = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
181
- (0, chai_1.expect)(encrypted).to.have.property("iv");
182
- (0, chai_1.expect)(encrypted).to.have.property("saltUser");
183
- (0, chai_1.expect)(encrypted).to.have.property("saltServer");
184
- (0, chai_1.expect)(encrypted).to.have.property("ciphertext");
185
- (0, chai_1.expect)(encrypted).to.have.property("tag");
186
- (0, chai_1.expect)(encrypted.iv).to.be.a("string");
187
- (0, chai_1.expect)(encrypted.saltUser).to.be.a("string");
188
- (0, chai_1.expect)(encrypted.saltServer).to.be.a("string");
189
- (0, chai_1.expect)(encrypted.ciphertext).to.be.a("string");
190
- (0, chai_1.expect)(encrypted.tag).to.be.a("string");
191
- (0, chai_1.expect)(encrypted.iv).to.match(/^[0-9a-f]+$/);
192
- (0, chai_1.expect)(encrypted.saltUser).to.match(/^[0-9a-f]+$/);
193
- (0, chai_1.expect)(encrypted.saltServer).to.match(/^[0-9a-f]+$/);
194
- (0, chai_1.expect)(encrypted.ciphertext).to.match(/^[0-9a-f]+$/);
195
- (0, chai_1.expect)(encrypted.tag).to.match(/^[0-9a-f]+$/);
196
- });
197
- it("should be secure against known plaintext attacks", () => {
198
- const plaintext = "Hello, World!";
199
- const userPassword = "user-password";
200
- const serverSecret = "server-secret";
201
- const encrypted1 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
202
- const encrypted2 = (0, encryption_helper_1.encryptWithTwoFactors)(plaintext, userPassword, serverSecret);
203
- (0, chai_1.expect)(encrypted1.ciphertext).to.not.equal(encrypted2.ciphertext);
204
- (0, chai_1.expect)(encrypted1.iv).to.not.equal(encrypted2.iv);
205
- });
206
- });
207
- describe("edge cases and error handling", () => {
208
- it("should handle very long passwords", () => {
209
- const plaintext = "Hello, World!";
210
- const longPassword = "A".repeat(1000);
211
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, longPassword);
212
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, longPassword);
213
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
214
- });
215
- it("should handle very short passwords", () => {
216
- const plaintext = "Hello, World!";
217
- const shortPassword = "a";
218
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, shortPassword);
219
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, shortPassword);
220
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
221
- });
222
- it("should handle passwords with special characters", () => {
223
- const plaintext = "Hello, World!";
224
- const specialPassword = "!@#$%^&*()_+-=[]{}|;':\",./<>?";
225
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, specialPassword);
226
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, specialPassword);
227
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
228
- });
229
- it("should handle binary data as string", () => {
230
- const plaintext = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04]).toString("utf8");
231
- const password = "my-secret-password";
232
- const encrypted = (0, encryption_helper_1.encrypt)(plaintext, password);
233
- const decrypted = (0, encryption_helper_1.decrypt)(encrypted, password);
234
- (0, chai_1.expect)(decrypted).to.equal(plaintext);
235
- });
236
- });
237
- });
238
- //# sourceMappingURL=encryption-helper.spec.js.map