@etsoo/appscript 1.1.67 → 1.1.71
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/__tests__/app/CoreApp.ts +20 -0
- package/lib/cjs/app/CoreApp.d.ts +86 -12
- package/lib/cjs/app/CoreApp.js +170 -19
- package/lib/cjs/dto/InitCallDto.d.ts +13 -0
- package/lib/cjs/dto/InitCallDto.js +2 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/result/IActionResult.d.ts +2 -2
- package/lib/cjs/result/InitCallResult.d.ts +12 -4
- package/lib/cjs/state/User.d.ts +0 -4
- package/lib/mjs/app/CoreApp.d.ts +86 -12
- package/lib/mjs/app/CoreApp.js +170 -19
- package/lib/mjs/dto/InitCallDto.d.ts +13 -0
- package/lib/mjs/dto/InitCallDto.js +1 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/lib/mjs/result/IActionResult.d.ts +2 -2
- package/lib/mjs/result/InitCallResult.d.ts +12 -4
- package/lib/mjs/state/User.d.ts +0 -4
- package/package.json +4 -4
- package/src/app/CoreApp.ts +280 -50
- package/src/dto/InitCallDto.ts +14 -0
- package/src/index.ts +1 -0
- package/src/result/IActionResult.ts +2 -2
- package/src/result/InitCallResult.ts +14 -4
- package/src/state/User.ts +0 -5
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { AddressUtils } from '../../src/address/AddressUtils';
|
|
|
12
12
|
import { IAppSettings } from '../../src/app/AppSettings';
|
|
13
13
|
import { CoreApp } from '../../src/app/CoreApp';
|
|
14
14
|
import { zhCN } from '../../src/i18n/zhCN';
|
|
15
|
+
import { InitCallResultData } from '../../src/result/InitCallResult';
|
|
15
16
|
|
|
16
17
|
// Detected country or region
|
|
17
18
|
const { detectedCountry } = DomUtils;
|
|
@@ -108,6 +109,11 @@ class CoreAppTest extends CoreApp<IAppSettings, {}, NotificationCallProps> {
|
|
|
108
109
|
freshCountdownUI(callback?: () => PromiseLike<unknown>): void {
|
|
109
110
|
throw new Error('Method not implemented.');
|
|
110
111
|
}
|
|
112
|
+
|
|
113
|
+
initCallUpdateLocal(data: InitCallResultData, timestamp: number) {
|
|
114
|
+
this.initCallUpdate(data, timestamp);
|
|
115
|
+
return this.passphrase;
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
const app = new CoreAppTest();
|
|
@@ -122,3 +128,17 @@ test('Tests for encrypt / decrypt', () => {
|
|
|
122
128
|
const plain = app.decrypt(encrypted, passphrase);
|
|
123
129
|
expect(plain).toEqual(input);
|
|
124
130
|
});
|
|
131
|
+
|
|
132
|
+
test('Tests for initCallUpdateLocal', () => {
|
|
133
|
+
// Act
|
|
134
|
+
const passphrase = app.initCallUpdateLocal(
|
|
135
|
+
{
|
|
136
|
+
deviceId:
|
|
137
|
+
'ZmNjZlov+10067A1520126643352C2022735B85DC8F380088468402C98A5631A8CFBE14E134zXfxmw77lFopTTlbqOfsK2KUqPSsTAQb35Ejrm1BAvUaQH3SuZcwGYu3+PQ/Rd56',
|
|
138
|
+
passphrase:
|
|
139
|
+
'01397BF28A93FC031BC8B9B808F880F12C398AB792DF2ADE7A8768CADD2259EB50HJuKhqGuLQO+SmvCVzuEGUN4TdkUuPMWR0E6lliszbNiXboCziXx5SdfX3lMpoBX'
|
|
140
|
+
},
|
|
141
|
+
1639282438620
|
|
142
|
+
);
|
|
143
|
+
expect(passphrase).not.toBeNull();
|
|
144
|
+
});
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
|
3
3
|
import { DataTypes, DateUtils } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
5
5
|
import { IActionResult } from '../result/IActionResult';
|
|
6
|
+
import { InitCallResultData } from '../result/InitCallResult';
|
|
6
7
|
import { IUserData } from '../state/User';
|
|
7
8
|
import { IAppSettings } from './AppSettings';
|
|
8
9
|
import { UserRole } from './UserRole';
|
|
@@ -87,10 +88,6 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
87
88
|
* User data
|
|
88
89
|
*/
|
|
89
90
|
userData?: IUserData;
|
|
90
|
-
/**
|
|
91
|
-
* Passphrase for encryption
|
|
92
|
-
*/
|
|
93
|
-
passphrase?: string;
|
|
94
91
|
/**
|
|
95
92
|
* Search input element
|
|
96
93
|
*/
|
|
@@ -123,7 +120,15 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
123
120
|
* @param passphrase Secret passphrase
|
|
124
121
|
* @returns Pure text
|
|
125
122
|
*/
|
|
126
|
-
decrypt(messageEncrypted: string, passphrase
|
|
123
|
+
decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Enhanced decrypt message
|
|
126
|
+
* @param messageEncrypted Encrypted message
|
|
127
|
+
* @param passphrase Secret passphrase
|
|
128
|
+
* @param durationSeconds Duration seconds, <= 12 will be considered as month
|
|
129
|
+
* @returns Pure text
|
|
130
|
+
*/
|
|
131
|
+
decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
|
|
127
132
|
/**
|
|
128
133
|
* Detect IP data, call only one time
|
|
129
134
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -136,7 +141,15 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
136
141
|
* @param iterations Iterations, 1000 times, 1 - 99
|
|
137
142
|
* @returns Result
|
|
138
143
|
*/
|
|
139
|
-
encrypt(message: string, passphrase
|
|
144
|
+
encrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
145
|
+
/**
|
|
146
|
+
* Enhanced encrypt message
|
|
147
|
+
* @param message Message
|
|
148
|
+
* @param passphrase Secret passphrase
|
|
149
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
150
|
+
* @returns Result
|
|
151
|
+
*/
|
|
152
|
+
encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
|
|
140
153
|
/**
|
|
141
154
|
* Format date to string
|
|
142
155
|
* @param input Input date
|
|
@@ -224,12 +237,25 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
224
237
|
* @param passphrase Secret passphrase
|
|
225
238
|
*/
|
|
226
239
|
hash(message: string, passphrase?: string): string;
|
|
240
|
+
/**
|
|
241
|
+
* Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
|
|
242
|
+
* https://cryptojs.gitbook.io/docs/
|
|
243
|
+
* @param message Message
|
|
244
|
+
* @param passphrase Secret passphrase
|
|
245
|
+
*/
|
|
246
|
+
hashHex(message: string, passphrase?: string): string;
|
|
227
247
|
/**
|
|
228
248
|
* Check use has the specific role permission or not
|
|
229
249
|
* @param roles Roles to check
|
|
230
250
|
* @returns Result
|
|
231
251
|
*/
|
|
232
252
|
hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Init call
|
|
255
|
+
* @param callback Callback
|
|
256
|
+
* @returns Result
|
|
257
|
+
*/
|
|
258
|
+
initCall(callback?: (result: boolean) => void): Promise<void>;
|
|
233
259
|
/**
|
|
234
260
|
* Callback where exit a page
|
|
235
261
|
*/
|
|
@@ -335,10 +361,6 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
335
361
|
* User data
|
|
336
362
|
*/
|
|
337
363
|
userData?: IUserData;
|
|
338
|
-
/**
|
|
339
|
-
* Passphrase for encryption
|
|
340
|
-
*/
|
|
341
|
-
passphrase?: string;
|
|
342
364
|
/**
|
|
343
365
|
* Response token header field name
|
|
344
366
|
*/
|
|
@@ -363,6 +385,18 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
363
385
|
* Token refresh count down seed
|
|
364
386
|
*/
|
|
365
387
|
protected refreshCountdownSeed: number;
|
|
388
|
+
/**
|
|
389
|
+
* Device id field name
|
|
390
|
+
*/
|
|
391
|
+
protected deviceIdField: string;
|
|
392
|
+
/**
|
|
393
|
+
* Device id
|
|
394
|
+
*/
|
|
395
|
+
protected deviceId: string;
|
|
396
|
+
/**
|
|
397
|
+
* Passphrase for encryption
|
|
398
|
+
*/
|
|
399
|
+
protected passphrase: string;
|
|
366
400
|
/**
|
|
367
401
|
* Protected constructor
|
|
368
402
|
* @param settings Settings
|
|
@@ -372,6 +406,23 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
372
406
|
*/
|
|
373
407
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
|
|
374
408
|
protected setApi(api: IApi): void;
|
|
409
|
+
/**
|
|
410
|
+
* Init call
|
|
411
|
+
* @param callback Callback
|
|
412
|
+
* @returns Result
|
|
413
|
+
*/
|
|
414
|
+
initCall(callback?: (result: boolean) => void): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Init call update
|
|
417
|
+
* @param data Result data
|
|
418
|
+
* @param timestamp Timestamp
|
|
419
|
+
*/
|
|
420
|
+
protected initCallUpdate(data: InitCallResultData, timestamp: number): void;
|
|
421
|
+
/**
|
|
422
|
+
* Init call update fields in local storage
|
|
423
|
+
* @returns Fields
|
|
424
|
+
*/
|
|
425
|
+
protected initCallUpdateFields(): string[];
|
|
375
426
|
/**
|
|
376
427
|
* Alert action result
|
|
377
428
|
* @param result Action result
|
|
@@ -400,7 +451,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
400
451
|
* @param passphrase Secret passphrase
|
|
401
452
|
* @returns Pure text
|
|
402
453
|
*/
|
|
403
|
-
decrypt(messageEncrypted: string, passphrase
|
|
454
|
+
decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
455
|
+
/**
|
|
456
|
+
* Enhanced decrypt message
|
|
457
|
+
* @param messageEncrypted Encrypted message
|
|
458
|
+
* @param passphrase Secret passphrase
|
|
459
|
+
* @param durationSeconds Duration seconds, <= 12 will be considered as month
|
|
460
|
+
* @returns Pure text
|
|
461
|
+
*/
|
|
462
|
+
decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
|
|
404
463
|
/**
|
|
405
464
|
* Detect IP data, call only one time
|
|
406
465
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -414,7 +473,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
414
473
|
* @param iterations Iterations, 1000 times, 1 - 99
|
|
415
474
|
* @returns Result
|
|
416
475
|
*/
|
|
417
|
-
encrypt(message: string, passphrase
|
|
476
|
+
encrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
477
|
+
/**
|
|
478
|
+
* Enhanced encrypt message
|
|
479
|
+
* @param message Message
|
|
480
|
+
* @param passphrase Secret passphrase
|
|
481
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
482
|
+
* @returns Result
|
|
483
|
+
*/
|
|
484
|
+
encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
|
|
418
485
|
/**
|
|
419
486
|
* Enchance secret passphrase
|
|
420
487
|
* @param passphrase Secret passphrase
|
|
@@ -504,6 +571,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
504
571
|
* @param passphrase Secret passphrase
|
|
505
572
|
*/
|
|
506
573
|
hash(message: string, passphrase?: string): string;
|
|
574
|
+
/**
|
|
575
|
+
* Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
|
|
576
|
+
* https://cryptojs.gitbook.io/docs/
|
|
577
|
+
* @param message Message
|
|
578
|
+
* @param passphrase Secret passphrase
|
|
579
|
+
*/
|
|
580
|
+
hashHex(message: string, passphrase?: string): string;
|
|
507
581
|
/**
|
|
508
582
|
* Check use has the specific role permission or not
|
|
509
583
|
* @param roles Roles to check
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -34,10 +34,19 @@ class CoreApp {
|
|
|
34
34
|
* Token refresh count down seed
|
|
35
35
|
*/
|
|
36
36
|
this.refreshCountdownSeed = 0;
|
|
37
|
+
/**
|
|
38
|
+
* Device id field name
|
|
39
|
+
*/
|
|
40
|
+
this.deviceIdField = 'SmartERPDeviceId';
|
|
41
|
+
/**
|
|
42
|
+
* Passphrase for encryption
|
|
43
|
+
*/
|
|
44
|
+
this.passphrase = '***';
|
|
37
45
|
this.settings = settings;
|
|
38
46
|
this.api = api;
|
|
39
47
|
this.notifier = notifier;
|
|
40
48
|
this.name = name;
|
|
49
|
+
this.deviceId = shared_1.StorageUtils.getLocalData(this.deviceIdField, '');
|
|
41
50
|
this.setApi(api);
|
|
42
51
|
const { currentCulture, currentRegion } = settings;
|
|
43
52
|
this.changeCulture(currentCulture);
|
|
@@ -108,6 +117,91 @@ class CoreApp {
|
|
|
108
117
|
}
|
|
109
118
|
};
|
|
110
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Init call
|
|
122
|
+
* @param callback Callback
|
|
123
|
+
* @returns Result
|
|
124
|
+
*/
|
|
125
|
+
async initCall(callback) {
|
|
126
|
+
var _a;
|
|
127
|
+
const data = {
|
|
128
|
+
timestamp: new Date().getTime(),
|
|
129
|
+
deviceId: this.deviceId === '' ? undefined : this.deviceId
|
|
130
|
+
};
|
|
131
|
+
const result = await this.api.put('Auth/WebInitCall', data);
|
|
132
|
+
if (result == null) {
|
|
133
|
+
if (callback)
|
|
134
|
+
callback(false);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (result.data == null) {
|
|
138
|
+
this.notifier.alert(this.get('noData'));
|
|
139
|
+
if (callback)
|
|
140
|
+
callback(false);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!result.ok) {
|
|
144
|
+
const seconds = result.data.seconds;
|
|
145
|
+
const validSeconds = result.data.validSeconds;
|
|
146
|
+
if (result.title === 'timeDifferenceInvalid' &&
|
|
147
|
+
seconds != null &&
|
|
148
|
+
validSeconds != null) {
|
|
149
|
+
const title = (_a = this.get('timeDifferenceInvalid')) === null || _a === void 0 ? void 0 : _a.format(seconds.toString(), validSeconds.toString());
|
|
150
|
+
this.notifier.alert(title);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.alertResult(result);
|
|
154
|
+
}
|
|
155
|
+
if (callback)
|
|
156
|
+
callback(false);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.initCallUpdate(result.data, data.timestamp);
|
|
160
|
+
if (callback)
|
|
161
|
+
callback(true);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Init call update
|
|
165
|
+
* @param data Result data
|
|
166
|
+
* @param timestamp Timestamp
|
|
167
|
+
*/
|
|
168
|
+
initCallUpdate(data, timestamp) {
|
|
169
|
+
if (data.deviceId == null || data.passphrase == null)
|
|
170
|
+
return;
|
|
171
|
+
// Decrypt
|
|
172
|
+
// Should be done within 120 seconds after returning from the backend
|
|
173
|
+
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
174
|
+
if (passphrase == null)
|
|
175
|
+
return;
|
|
176
|
+
// Update device id and cache it
|
|
177
|
+
this.deviceId = data.deviceId;
|
|
178
|
+
shared_1.StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
|
|
179
|
+
// Current passphrase
|
|
180
|
+
this.passphrase = passphrase;
|
|
181
|
+
// Previous passphrase
|
|
182
|
+
if (data.previousPassphrase) {
|
|
183
|
+
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
184
|
+
// Update
|
|
185
|
+
const fields = this.initCallUpdateFields();
|
|
186
|
+
for (const field of fields) {
|
|
187
|
+
const currentValue = shared_1.StorageUtils.getLocalData(field, '');
|
|
188
|
+
if (currentValue === '' || currentValue.indexOf('+') === -1)
|
|
189
|
+
continue;
|
|
190
|
+
const newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
191
|
+
if (newValueSource == null)
|
|
192
|
+
continue;
|
|
193
|
+
const newValue = this.encryptEnhanced(newValueSource);
|
|
194
|
+
shared_1.StorageUtils.setLocalData(field, newValue);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Init call update fields in local storage
|
|
200
|
+
* @returns Fields
|
|
201
|
+
*/
|
|
202
|
+
initCallUpdateFields() {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
111
205
|
/**
|
|
112
206
|
* Alert action result
|
|
113
207
|
* @param result Action result
|
|
@@ -203,16 +297,14 @@ class CoreApp {
|
|
|
203
297
|
* @returns Pure text
|
|
204
298
|
*/
|
|
205
299
|
decrypt(messageEncrypted, passphrase) {
|
|
206
|
-
// Timestamp splitter
|
|
207
|
-
const pos = messageEncrypted.indexOf('+');
|
|
208
|
-
const timestamp = messageEncrypted.substring(0, pos);
|
|
209
|
-
const message = messageEncrypted.substring(pos + 1);
|
|
210
300
|
// Iterations
|
|
211
|
-
const iterations = parseInt(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
const
|
|
301
|
+
const iterations = parseInt(messageEncrypted.substring(0, 2), 10);
|
|
302
|
+
if (isNaN(iterations))
|
|
303
|
+
return undefined;
|
|
304
|
+
const salt = crypto_js_1.enc.Hex.parse(messageEncrypted.substring(2, 34));
|
|
305
|
+
const iv = crypto_js_1.enc.Hex.parse(messageEncrypted.substring(34, 66));
|
|
306
|
+
const encrypted = messageEncrypted.substring(66);
|
|
307
|
+
const key = (0, crypto_js_1.PBKDF2)(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
|
|
216
308
|
keySize: 8,
|
|
217
309
|
hasher: crypto_js_1.algo.SHA256,
|
|
218
310
|
iterations: 1000 * iterations
|
|
@@ -223,6 +315,34 @@ class CoreApp {
|
|
|
223
315
|
mode: crypto_js_1.mode.CBC
|
|
224
316
|
}).toString(crypto_js_1.enc.Utf8);
|
|
225
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Enhanced decrypt message
|
|
320
|
+
* @param messageEncrypted Encrypted message
|
|
321
|
+
* @param passphrase Secret passphrase
|
|
322
|
+
* @param durationSeconds Duration seconds, <= 12 will be considered as month
|
|
323
|
+
* @returns Pure text
|
|
324
|
+
*/
|
|
325
|
+
decryptEnhanced(messageEncrypted, passphrase, durationSeconds) {
|
|
326
|
+
// Timestamp splitter
|
|
327
|
+
const pos = messageEncrypted.indexOf('+');
|
|
328
|
+
if (pos === -1 || messageEncrypted.length <= 66)
|
|
329
|
+
return undefined;
|
|
330
|
+
const timestamp = messageEncrypted.substring(0, pos);
|
|
331
|
+
if (durationSeconds != null && durationSeconds > 0) {
|
|
332
|
+
const milseconds = shared_1.Utils.charsToNumber(timestamp);
|
|
333
|
+
if (isNaN(milseconds) || milseconds < 1)
|
|
334
|
+
return undefined;
|
|
335
|
+
const timespan = new Date().substract(new Date(milseconds));
|
|
336
|
+
if ((durationSeconds <= 12 &&
|
|
337
|
+
timespan.totalMonths > durationSeconds) ||
|
|
338
|
+
(durationSeconds > 12 &&
|
|
339
|
+
timespan.totalSeconds > durationSeconds))
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
const message = messageEncrypted.substring(pos + 1);
|
|
343
|
+
passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
|
|
344
|
+
return this.decrypt(message, passphrase);
|
|
345
|
+
}
|
|
226
346
|
/**
|
|
227
347
|
* Detect IP data, call only one time
|
|
228
348
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -266,19 +386,15 @@ class CoreApp {
|
|
|
266
386
|
encrypt(message, passphrase, iterations) {
|
|
267
387
|
// Default 1 * 1000
|
|
268
388
|
iterations !== null && iterations !== void 0 ? iterations : (iterations = 1);
|
|
269
|
-
// Timestamp
|
|
270
|
-
const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
|
|
271
389
|
const bits = 16; // 128 / 8
|
|
272
390
|
const salt = crypto_js_1.lib.WordArray.random(bits);
|
|
273
|
-
const key = (0, crypto_js_1.PBKDF2)(this.
|
|
391
|
+
const key = (0, crypto_js_1.PBKDF2)(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
|
|
274
392
|
keySize: 8,
|
|
275
393
|
hasher: crypto_js_1.algo.SHA256,
|
|
276
394
|
iterations: 1000 * iterations
|
|
277
395
|
});
|
|
278
396
|
const iv = crypto_js_1.lib.WordArray.random(bits);
|
|
279
|
-
return (
|
|
280
|
-
'+' +
|
|
281
|
-
iterations.toString().padStart(2, '0') +
|
|
397
|
+
return (iterations.toString().padStart(2, '0') +
|
|
282
398
|
salt.toString(crypto_js_1.enc.Hex) +
|
|
283
399
|
iv.toString(crypto_js_1.enc.Hex) +
|
|
284
400
|
crypto_js_1.AES.encrypt(message, key, {
|
|
@@ -288,6 +404,19 @@ class CoreApp {
|
|
|
288
404
|
}).toString() // enc.Base64
|
|
289
405
|
);
|
|
290
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Enhanced encrypt message
|
|
409
|
+
* @param message Message
|
|
410
|
+
* @param passphrase Secret passphrase
|
|
411
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
412
|
+
* @returns Result
|
|
413
|
+
*/
|
|
414
|
+
encryptEnhanced(message, passphrase, iterations) {
|
|
415
|
+
// Timestamp
|
|
416
|
+
const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
|
|
417
|
+
passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
|
|
418
|
+
return timestamp + '+' + this.encrypt(message, passphrase, iterations);
|
|
419
|
+
}
|
|
291
420
|
/**
|
|
292
421
|
* Enchance secret passphrase
|
|
293
422
|
* @param passphrase Secret passphrase
|
|
@@ -295,10 +424,9 @@ class CoreApp {
|
|
|
295
424
|
* @returns Enhanced passphrase
|
|
296
425
|
*/
|
|
297
426
|
encryptionEnhance(passphrase, timestamp) {
|
|
298
|
-
var _a;
|
|
299
427
|
passphrase += timestamp;
|
|
300
428
|
passphrase += passphrase.length.toString();
|
|
301
|
-
return passphrase
|
|
429
|
+
return passphrase;
|
|
302
430
|
}
|
|
303
431
|
/**
|
|
304
432
|
* Format date to string
|
|
@@ -360,7 +488,19 @@ class CoreApp {
|
|
|
360
488
|
* @param forceToLocal Force to local labels
|
|
361
489
|
*/
|
|
362
490
|
formatResult(result, forceToLocal) {
|
|
363
|
-
|
|
491
|
+
const title = result.title;
|
|
492
|
+
if (title && /^\w+$/.test(title)) {
|
|
493
|
+
const key = title.formatInitial(false);
|
|
494
|
+
const localTitle = this.get(key);
|
|
495
|
+
if (localTitle) {
|
|
496
|
+
result.title = localTitle;
|
|
497
|
+
// Hold the original title in type when type is null
|
|
498
|
+
if (result.type == null)
|
|
499
|
+
result.type = title;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
else if ((title == null || forceToLocal) && result.type != null) {
|
|
503
|
+
// Get label from type
|
|
364
504
|
const key = result.type.formatInitial(false);
|
|
365
505
|
result.title = this.get(key);
|
|
366
506
|
}
|
|
@@ -438,6 +578,18 @@ class CoreApp {
|
|
|
438
578
|
else
|
|
439
579
|
return (0, crypto_js_1.HmacSHA512)(message, passphrase).toString(crypto_js_1.enc.Base64);
|
|
440
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
|
|
583
|
+
* https://cryptojs.gitbook.io/docs/
|
|
584
|
+
* @param message Message
|
|
585
|
+
* @param passphrase Secret passphrase
|
|
586
|
+
*/
|
|
587
|
+
hashHex(message, passphrase) {
|
|
588
|
+
if (passphrase == null)
|
|
589
|
+
return (0, crypto_js_1.SHA3)(message, { outputLength: 512 }).toString(crypto_js_1.enc.Hex);
|
|
590
|
+
else
|
|
591
|
+
return (0, crypto_js_1.HmacSHA512)(message, passphrase).toString(crypto_js_1.enc.Hex);
|
|
592
|
+
}
|
|
441
593
|
/**
|
|
442
594
|
* Check use has the specific role permission or not
|
|
443
595
|
* @param roles Roles to check
|
|
@@ -587,7 +739,6 @@ class CoreApp {
|
|
|
587
739
|
*/
|
|
588
740
|
userLogin(user, refreshToken, keep = false) {
|
|
589
741
|
this.userData = user;
|
|
590
|
-
this.passphrase = user.passphrase;
|
|
591
742
|
this.authorize(user.token, refreshToken, keep);
|
|
592
743
|
}
|
|
593
744
|
/**
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './def/ListItem';
|
|
|
16
16
|
export * from './dto/IdDto';
|
|
17
17
|
export * from './dto/IdLabelDto';
|
|
18
18
|
export * from './dto/IdLabelPrimaryDto';
|
|
19
|
+
export * from './dto/InitCallDto';
|
|
19
20
|
export * from './dto/UpdateDto';
|
|
20
21
|
export * from './i18n/enUS';
|
|
21
22
|
export * from './i18n/zhCN';
|
package/lib/cjs/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __exportStar(require("./def/ListItem"), exports);
|
|
|
35
35
|
__exportStar(require("./dto/IdDto"), exports);
|
|
36
36
|
__exportStar(require("./dto/IdLabelDto"), exports);
|
|
37
37
|
__exportStar(require("./dto/IdLabelPrimaryDto"), exports);
|
|
38
|
+
__exportStar(require("./dto/InitCallDto"), exports);
|
|
38
39
|
__exportStar(require("./dto/UpdateDto"), exports);
|
|
39
40
|
// i18n
|
|
40
41
|
__exportStar(require("./i18n/enUS"), exports);
|
|
@@ -48,11 +48,11 @@ export interface IActionResult<D extends IResultData = IResultData> {
|
|
|
48
48
|
/**
|
|
49
49
|
* Trace id
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
traceId?: string;
|
|
52
52
|
/**
|
|
53
53
|
* Type
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
type: string;
|
|
56
56
|
/**
|
|
57
57
|
* Success or not
|
|
58
58
|
*/
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { IActionResult, IResultData } from './IActionResult';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Init call result data
|
|
4
4
|
*/
|
|
5
5
|
export interface InitCallResultData extends IResultData {
|
|
6
|
+
/**
|
|
7
|
+
* Device id
|
|
8
|
+
*/
|
|
9
|
+
deviceId?: string;
|
|
6
10
|
/**
|
|
7
11
|
* Secret passphrase
|
|
8
12
|
*/
|
|
9
|
-
passphrase
|
|
13
|
+
passphrase?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Previous secret passphrase
|
|
16
|
+
*/
|
|
17
|
+
previousPassphrase?: string;
|
|
10
18
|
/**
|
|
11
19
|
* Actual seconds gap
|
|
12
20
|
*/
|
|
13
|
-
seconds
|
|
21
|
+
seconds?: number;
|
|
14
22
|
/**
|
|
15
23
|
* Valid seconds gap
|
|
16
24
|
*/
|
|
17
|
-
validSeconds
|
|
25
|
+
validSeconds?: number;
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* Init call result
|