@etsoo/appscript 1.1.61 → 1.1.65

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.
@@ -87,6 +87,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
87
87
  * User data
88
88
  */
89
89
  userData?: IUserData;
90
+ /**
91
+ * Passphrase for encryption
92
+ */
93
+ passphrase?: string;
90
94
  /**
91
95
  * Search input element
92
96
  */
@@ -323,6 +327,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
323
327
  * User data
324
328
  */
325
329
  userData?: IUserData;
330
+ /**
331
+ * Passphrase for encryption
332
+ */
333
+ passphrase?: string;
326
334
  /**
327
335
  * Response token header field name
328
336
  */
@@ -401,9 +409,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
401
409
  /**
402
410
  * Enchance secret passphrase
403
411
  * @param passphrase Secret passphrase
412
+ * @param timestamp Timestamp
404
413
  * @returns Enhanced passphrase
405
414
  */
406
- protected encryptionEnhance(passphrase: string): string;
415
+ protected encryptionEnhance(passphrase: string, timestamp: string): string;
407
416
  /**
408
417
  * Format date to string
409
418
  * @param input Input date
@@ -4,6 +4,7 @@ exports.CoreApp = void 0;
4
4
  const notificationbase_1 = require("@etsoo/notificationbase");
5
5
  const restclient_1 = require("@etsoo/restclient");
6
6
  const shared_1 = require("@etsoo/shared");
7
+ const crypto_js_1 = require("crypto-js");
7
8
  const AddressRegion_1 = require("../address/AddressRegion");
8
9
  const AddressUtils_1 = require("../address/AddressUtils");
9
10
  const ActionResultError_1 = require("../result/ActionResultError");
@@ -202,7 +203,10 @@ class CoreApp {
202
203
  * @returns Pure text
203
204
  */
204
205
  decrypt(messageEncrypted, passphrase) {
205
- return CryptoJS.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
206
+ const pos = messageEncrypted.indexOf('+');
207
+ const timestamp = messageEncrypted.substring(0, pos);
208
+ const message = messageEncrypted.substring(pos + 1);
209
+ return crypto_js_1.AES.decrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString();
206
210
  }
207
211
  /**
208
212
  * Detect IP data, call only one time
@@ -244,19 +248,22 @@ class CoreApp {
244
248
  * @returns Result
245
249
  */
246
250
  encrypt(message, passphrase) {
247
- return CryptoJS.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
251
+ const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
252
+ return (timestamp +
253
+ '+' +
254
+ crypto_js_1.AES.encrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString());
248
255
  }
249
256
  /**
250
257
  * Enchance secret passphrase
251
258
  * @param passphrase Secret passphrase
259
+ * @param timestamp Timestamp
252
260
  * @returns Enhanced passphrase
253
261
  */
254
- encryptionEnhance(passphrase) {
255
- var _a, _b;
256
- passphrase += passphrase.length;
257
- if (this.authorized)
258
- return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
259
- return passphrase;
262
+ encryptionEnhance(passphrase, timestamp) {
263
+ var _a;
264
+ passphrase += timestamp;
265
+ passphrase += passphrase.length.toString();
266
+ return passphrase + ((_a = this.passphrase) !== null && _a !== void 0 ? _a : '');
260
267
  }
261
268
  /**
262
269
  * Format date to string
@@ -533,6 +540,7 @@ class CoreApp {
533
540
  */
534
541
  userLogin(user, refreshToken, keep = false) {
535
542
  this.userData = user;
543
+ this.passphrase = user.passphrase;
536
544
  this.authorize(user.token, refreshToken, keep);
537
545
  }
538
546
  /**
@@ -28,7 +28,7 @@ export interface IUserData {
28
28
  */
29
29
  readonly token: string;
30
30
  /**
31
- * Passphrase for encryption
31
+ * Secret passphrase
32
32
  */
33
33
  readonly passphrase: string;
34
34
  }
@@ -87,6 +87,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
87
87
  * User data
88
88
  */
89
89
  userData?: IUserData;
90
+ /**
91
+ * Passphrase for encryption
92
+ */
93
+ passphrase?: string;
90
94
  /**
91
95
  * Search input element
92
96
  */
@@ -323,6 +327,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
323
327
  * User data
324
328
  */
325
329
  userData?: IUserData;
330
+ /**
331
+ * Passphrase for encryption
332
+ */
333
+ passphrase?: string;
326
334
  /**
327
335
  * Response token header field name
328
336
  */
@@ -401,9 +409,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
401
409
  /**
402
410
  * Enchance secret passphrase
403
411
  * @param passphrase Secret passphrase
412
+ * @param timestamp Timestamp
404
413
  * @returns Enhanced passphrase
405
414
  */
406
- protected encryptionEnhance(passphrase: string): string;
415
+ protected encryptionEnhance(passphrase: string, timestamp: string): string;
407
416
  /**
408
417
  * Format date to string
409
418
  * @param input Input date
@@ -1,6 +1,7 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
2
  import { ApiDataError } from '@etsoo/restclient';
3
- import { DateUtils, DomUtils, NumberUtils, StorageUtils } from '@etsoo/shared';
3
+ import { DateUtils, DomUtils, NumberUtils, StorageUtils, Utils } from '@etsoo/shared';
4
+ import { AES } from 'crypto-js';
4
5
  import { AddressRegion } from '../address/AddressRegion';
5
6
  import { AddressUtils } from '../address/AddressUtils';
6
7
  import { ActionResultError } from '../result/ActionResultError';
@@ -199,7 +200,10 @@ export class CoreApp {
199
200
  * @returns Pure text
200
201
  */
201
202
  decrypt(messageEncrypted, passphrase) {
202
- return CryptoJS.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
203
+ const pos = messageEncrypted.indexOf('+');
204
+ const timestamp = messageEncrypted.substring(0, pos);
205
+ const message = messageEncrypted.substring(pos + 1);
206
+ return AES.decrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString();
203
207
  }
204
208
  /**
205
209
  * Detect IP data, call only one time
@@ -241,19 +245,22 @@ export class CoreApp {
241
245
  * @returns Result
242
246
  */
243
247
  encrypt(message, passphrase) {
244
- return CryptoJS.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
248
+ const timestamp = Utils.numberToChars(new Date().getTime());
249
+ return (timestamp +
250
+ '+' +
251
+ AES.encrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString());
245
252
  }
246
253
  /**
247
254
  * Enchance secret passphrase
248
255
  * @param passphrase Secret passphrase
256
+ * @param timestamp Timestamp
249
257
  * @returns Enhanced passphrase
250
258
  */
251
- encryptionEnhance(passphrase) {
252
- var _a, _b;
253
- passphrase += passphrase.length;
254
- if (this.authorized)
255
- return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
256
- return passphrase;
259
+ encryptionEnhance(passphrase, timestamp) {
260
+ var _a;
261
+ passphrase += timestamp;
262
+ passphrase += passphrase.length.toString();
263
+ return passphrase + ((_a = this.passphrase) !== null && _a !== void 0 ? _a : '');
257
264
  }
258
265
  /**
259
266
  * Format date to string
@@ -530,6 +537,7 @@ export class CoreApp {
530
537
  */
531
538
  userLogin(user, refreshToken, keep = false) {
532
539
  this.userData = user;
540
+ this.passphrase = user.passphrase;
533
541
  this.authorize(user.token, refreshToken, keep);
534
542
  }
535
543
  /**
@@ -28,7 +28,7 @@ export interface IUserData {
28
28
  */
29
29
  readonly token: string;
30
30
  /**
31
- * Passphrase for encryption
31
+ * Secret passphrase
32
32
  */
33
33
  readonly passphrase: string;
34
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.61",
3
+ "version": "1.1.65",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.0.94",
56
56
  "@etsoo/restclient": "^1.0.62",
57
- "@etsoo/shared": "^1.0.75",
57
+ "@etsoo/shared": "^1.0.76",
58
58
  "@types/crypto-js": "^4.0.2",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -71,7 +71,7 @@
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.25.3",
73
73
  "jest": "^27.4.3",
74
- "ts-jest": "^27.0.7",
74
+ "ts-jest": "^27.1.0",
75
75
  "typescript": "^4.5.2"
76
76
  }
77
77
  }
@@ -12,8 +12,10 @@ import {
12
12
  DateUtils,
13
13
  DomUtils,
14
14
  NumberUtils,
15
- StorageUtils
15
+ StorageUtils,
16
+ Utils
16
17
  } from '@etsoo/shared';
18
+ import { AES } from 'crypto-js';
17
19
  import { AddressRegion } from '../address/AddressRegion';
18
20
  import { AddressUtils } from '../address/AddressUtils';
19
21
  import { ActionResultError } from '../result/ActionResultError';
@@ -128,6 +130,11 @@ export interface ICoreApp<
128
130
  */
129
131
  userData?: IUserData;
130
132
 
133
+ /**
134
+ * Passphrase for encryption
135
+ */
136
+ passphrase?: string;
137
+
131
138
  /**
132
139
  * Search input element
133
140
  */
@@ -431,6 +438,11 @@ export abstract class CoreApp<
431
438
  */
432
439
  userData?: IUserData;
433
440
 
441
+ /**
442
+ * Passphrase for encryption
443
+ */
444
+ passphrase?: string;
445
+
434
446
  /**
435
447
  * Response token header field name
436
448
  */
@@ -648,9 +660,12 @@ export abstract class CoreApp<
648
660
  * @returns Pure text
649
661
  */
650
662
  decrypt(messageEncrypted: string, passphrase: string) {
651
- return CryptoJS.AES.decrypt(
652
- messageEncrypted,
653
- this.encryptionEnhance(passphrase)
663
+ const pos = messageEncrypted.indexOf('+');
664
+ const timestamp = messageEncrypted.substring(0, pos);
665
+ const message = messageEncrypted.substring(pos + 1);
666
+ return AES.decrypt(
667
+ message,
668
+ this.encryptionEnhance(passphrase, timestamp)
654
669
  ).toString();
655
670
  }
656
671
 
@@ -701,22 +716,27 @@ export abstract class CoreApp<
701
716
  * @returns Result
702
717
  */
703
718
  encrypt(message: string, passphrase: string) {
704
- return CryptoJS.AES.encrypt(
705
- message,
706
- this.encryptionEnhance(passphrase)
707
- ).toString();
719
+ const timestamp = Utils.numberToChars(new Date().getTime());
720
+ return (
721
+ timestamp +
722
+ '+' +
723
+ AES.encrypt(
724
+ message,
725
+ this.encryptionEnhance(passphrase, timestamp)
726
+ ).toString()
727
+ );
708
728
  }
709
729
 
710
730
  /**
711
731
  * Enchance secret passphrase
712
732
  * @param passphrase Secret passphrase
733
+ * @param timestamp Timestamp
713
734
  * @returns Enhanced passphrase
714
735
  */
715
- protected encryptionEnhance(passphrase: string) {
716
- passphrase += passphrase.length;
717
- if (this.authorized)
718
- return passphrase + (this.userData?.passphrase ?? '');
719
- return passphrase;
736
+ protected encryptionEnhance(passphrase: string, timestamp: string) {
737
+ passphrase += timestamp;
738
+ passphrase += passphrase.length.toString();
739
+ return passphrase + (this.passphrase ?? '');
720
740
  }
721
741
 
722
742
  /**
@@ -1045,6 +1065,7 @@ export abstract class CoreApp<
1045
1065
  */
1046
1066
  userLogin(user: IUserData, refreshToken: string, keep: boolean = false) {
1047
1067
  this.userData = user;
1068
+ this.passphrase = user.passphrase;
1048
1069
  this.authorize(user.token, refreshToken, keep);
1049
1070
  }
1050
1071
 
package/src/state/User.ts CHANGED
@@ -35,7 +35,7 @@ export interface IUserData {
35
35
  readonly token: string;
36
36
 
37
37
  /**
38
- * Passphrase for encryption
38
+ * Secret passphrase
39
39
  */
40
40
  readonly passphrase: string;
41
41
  }