@etsoo/appscript 1.5.22 → 1.5.24
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/lib/cjs/app/CoreApp.d.ts +5 -0
- package/lib/cjs/app/CoreApp.js +37 -25
- package/lib/mjs/app/CoreApp.d.ts +5 -0
- package/lib/mjs/app/CoreApp.js +37 -25
- package/package.json +1 -1
- package/src/app/CoreApp.ts +50 -36
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -251,6 +251,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
251
251
|
* @returns Result
|
|
252
252
|
*/
|
|
253
253
|
initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Update passphrase
|
|
256
|
+
* @param passphrase Secret passphrase
|
|
257
|
+
*/
|
|
258
|
+
protected updatePassphrase(passphrase: string): void;
|
|
254
259
|
/**
|
|
255
260
|
* Init call update
|
|
256
261
|
* @param data Result data
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -227,7 +227,7 @@ class CoreApp {
|
|
|
227
227
|
async restore() {
|
|
228
228
|
// Devices
|
|
229
229
|
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
230
|
-
if (this.
|
|
230
|
+
if (this._deviceId === '') {
|
|
231
231
|
// First vist, restore and keep the source
|
|
232
232
|
this.storage.copyFrom(this.persistedFields, false);
|
|
233
233
|
// Reset device id
|
|
@@ -529,33 +529,16 @@ class CoreApp {
|
|
|
529
529
|
callback(updateResult);
|
|
530
530
|
}
|
|
531
531
|
/**
|
|
532
|
-
*
|
|
533
|
-
* @param
|
|
534
|
-
* @param timestamp Timestamp
|
|
532
|
+
* Update passphrase
|
|
533
|
+
* @param passphrase Secret passphrase
|
|
535
534
|
*/
|
|
536
|
-
|
|
537
|
-
//
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
// Decrypt
|
|
541
|
-
// Should be done within 120 seconds after returning from the backend
|
|
542
|
-
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
543
|
-
if (passphrase == null)
|
|
544
|
-
return false;
|
|
545
|
-
// Update device id and cache it
|
|
546
|
-
this._deviceId = data.deviceId;
|
|
547
|
-
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
548
|
-
// Devices
|
|
549
|
-
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
550
|
-
devices.push(this.getDeviceId());
|
|
551
|
-
this.storage.setPersistedData(this.fields.devices, devices);
|
|
552
|
-
// Current passphrase
|
|
535
|
+
updatePassphrase(passphrase) {
|
|
536
|
+
// Previous passphrase
|
|
537
|
+
const prev = this.passphrase;
|
|
538
|
+
// Update
|
|
553
539
|
this.passphrase = passphrase;
|
|
554
540
|
this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
|
|
555
|
-
|
|
556
|
-
if (data.previousPassphrase) {
|
|
557
|
-
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
558
|
-
// Update
|
|
541
|
+
if (prev) {
|
|
559
542
|
const fields = this.initCallEncryptedUpdateFields();
|
|
560
543
|
for (const field of fields) {
|
|
561
544
|
const currentValue = this.storage.getData(field);
|
|
@@ -585,6 +568,35 @@ class CoreApp {
|
|
|
585
568
|
this.storage.setData(field, newValue);
|
|
586
569
|
}
|
|
587
570
|
}
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Init call update
|
|
574
|
+
* @param data Result data
|
|
575
|
+
* @param timestamp Timestamp
|
|
576
|
+
*/
|
|
577
|
+
async initCallUpdate(data, timestamp) {
|
|
578
|
+
// Data check
|
|
579
|
+
if (data.deviceId == null || data.passphrase == null)
|
|
580
|
+
return false;
|
|
581
|
+
// Decrypt
|
|
582
|
+
// Should be done within 120 seconds after returning from the backend
|
|
583
|
+
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
584
|
+
if (passphrase == null)
|
|
585
|
+
return false;
|
|
586
|
+
// Update device id and cache it
|
|
587
|
+
this._deviceId = data.deviceId;
|
|
588
|
+
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
589
|
+
// Devices
|
|
590
|
+
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
591
|
+
devices.push(this.getDeviceId());
|
|
592
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
593
|
+
// Previous passphrase
|
|
594
|
+
if (data.previousPassphrase) {
|
|
595
|
+
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
596
|
+
this.passphrase = prev ?? '';
|
|
597
|
+
}
|
|
598
|
+
// Update passphrase
|
|
599
|
+
this.updatePassphrase(passphrase);
|
|
588
600
|
return true;
|
|
589
601
|
}
|
|
590
602
|
/**
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -251,6 +251,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
251
251
|
* @returns Result
|
|
252
252
|
*/
|
|
253
253
|
initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Update passphrase
|
|
256
|
+
* @param passphrase Secret passphrase
|
|
257
|
+
*/
|
|
258
|
+
protected updatePassphrase(passphrase: string): void;
|
|
254
259
|
/**
|
|
255
260
|
* Init call update
|
|
256
261
|
* @param data Result data
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -224,7 +224,7 @@ export class CoreApp {
|
|
|
224
224
|
async restore() {
|
|
225
225
|
// Devices
|
|
226
226
|
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
227
|
-
if (this.
|
|
227
|
+
if (this._deviceId === '') {
|
|
228
228
|
// First vist, restore and keep the source
|
|
229
229
|
this.storage.copyFrom(this.persistedFields, false);
|
|
230
230
|
// Reset device id
|
|
@@ -526,33 +526,16 @@ export class CoreApp {
|
|
|
526
526
|
callback(updateResult);
|
|
527
527
|
}
|
|
528
528
|
/**
|
|
529
|
-
*
|
|
530
|
-
* @param
|
|
531
|
-
* @param timestamp Timestamp
|
|
529
|
+
* Update passphrase
|
|
530
|
+
* @param passphrase Secret passphrase
|
|
532
531
|
*/
|
|
533
|
-
|
|
534
|
-
//
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
// Decrypt
|
|
538
|
-
// Should be done within 120 seconds after returning from the backend
|
|
539
|
-
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
540
|
-
if (passphrase == null)
|
|
541
|
-
return false;
|
|
542
|
-
// Update device id and cache it
|
|
543
|
-
this._deviceId = data.deviceId;
|
|
544
|
-
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
545
|
-
// Devices
|
|
546
|
-
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
547
|
-
devices.push(this.getDeviceId());
|
|
548
|
-
this.storage.setPersistedData(this.fields.devices, devices);
|
|
549
|
-
// Current passphrase
|
|
532
|
+
updatePassphrase(passphrase) {
|
|
533
|
+
// Previous passphrase
|
|
534
|
+
const prev = this.passphrase;
|
|
535
|
+
// Update
|
|
550
536
|
this.passphrase = passphrase;
|
|
551
537
|
this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
|
|
552
|
-
|
|
553
|
-
if (data.previousPassphrase) {
|
|
554
|
-
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
555
|
-
// Update
|
|
538
|
+
if (prev) {
|
|
556
539
|
const fields = this.initCallEncryptedUpdateFields();
|
|
557
540
|
for (const field of fields) {
|
|
558
541
|
const currentValue = this.storage.getData(field);
|
|
@@ -582,6 +565,35 @@ export class CoreApp {
|
|
|
582
565
|
this.storage.setData(field, newValue);
|
|
583
566
|
}
|
|
584
567
|
}
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Init call update
|
|
571
|
+
* @param data Result data
|
|
572
|
+
* @param timestamp Timestamp
|
|
573
|
+
*/
|
|
574
|
+
async initCallUpdate(data, timestamp) {
|
|
575
|
+
// Data check
|
|
576
|
+
if (data.deviceId == null || data.passphrase == null)
|
|
577
|
+
return false;
|
|
578
|
+
// Decrypt
|
|
579
|
+
// Should be done within 120 seconds after returning from the backend
|
|
580
|
+
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
581
|
+
if (passphrase == null)
|
|
582
|
+
return false;
|
|
583
|
+
// Update device id and cache it
|
|
584
|
+
this._deviceId = data.deviceId;
|
|
585
|
+
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
586
|
+
// Devices
|
|
587
|
+
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
588
|
+
devices.push(this.getDeviceId());
|
|
589
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
590
|
+
// Previous passphrase
|
|
591
|
+
if (data.previousPassphrase) {
|
|
592
|
+
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
593
|
+
this.passphrase = prev ?? '';
|
|
594
|
+
}
|
|
595
|
+
// Update passphrase
|
|
596
|
+
this.updatePassphrase(passphrase);
|
|
585
597
|
return true;
|
|
586
598
|
}
|
|
587
599
|
/**
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -427,7 +427,7 @@ export abstract class CoreApp<
|
|
|
427
427
|
[]
|
|
428
428
|
);
|
|
429
429
|
|
|
430
|
-
if (this.
|
|
430
|
+
if (this._deviceId === '') {
|
|
431
431
|
// First vist, restore and keep the source
|
|
432
432
|
this.storage.copyFrom(this.persistedFields, false);
|
|
433
433
|
|
|
@@ -837,49 +837,21 @@ export abstract class CoreApp<
|
|
|
837
837
|
}
|
|
838
838
|
|
|
839
839
|
/**
|
|
840
|
-
*
|
|
841
|
-
* @param
|
|
842
|
-
* @param timestamp Timestamp
|
|
840
|
+
* Update passphrase
|
|
841
|
+
* @param passphrase Secret passphrase
|
|
843
842
|
*/
|
|
844
|
-
protected
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
): Promise<boolean> {
|
|
848
|
-
// Data check
|
|
849
|
-
if (data.deviceId == null || data.passphrase == null) return false;
|
|
850
|
-
|
|
851
|
-
// Decrypt
|
|
852
|
-
// Should be done within 120 seconds after returning from the backend
|
|
853
|
-
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
854
|
-
if (passphrase == null) return false;
|
|
855
|
-
|
|
856
|
-
// Update device id and cache it
|
|
857
|
-
this._deviceId = data.deviceId;
|
|
858
|
-
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
859
|
-
|
|
860
|
-
// Devices
|
|
861
|
-
const devices = this.storage.getPersistedData<string[]>(
|
|
862
|
-
this.fields.devices,
|
|
863
|
-
[]
|
|
864
|
-
);
|
|
865
|
-
devices.push(this.getDeviceId());
|
|
866
|
-
this.storage.setPersistedData(this.fields.devices, devices);
|
|
843
|
+
protected updatePassphrase(passphrase: string) {
|
|
844
|
+
// Previous passphrase
|
|
845
|
+
const prev = this.passphrase;
|
|
867
846
|
|
|
868
|
-
//
|
|
847
|
+
// Update
|
|
869
848
|
this.passphrase = passphrase;
|
|
870
849
|
this.storage.setData(
|
|
871
850
|
this.fields.devicePassphrase,
|
|
872
851
|
this.encrypt(passphrase, this.name)
|
|
873
852
|
);
|
|
874
853
|
|
|
875
|
-
|
|
876
|
-
if (data.previousPassphrase) {
|
|
877
|
-
const prev = this.decrypt(
|
|
878
|
-
data.previousPassphrase,
|
|
879
|
-
timestamp.toString()
|
|
880
|
-
);
|
|
881
|
-
|
|
882
|
-
// Update
|
|
854
|
+
if (prev) {
|
|
883
855
|
const fields = this.initCallEncryptedUpdateFields();
|
|
884
856
|
for (const field of fields) {
|
|
885
857
|
const currentValue = this.storage.getData<string>(field);
|
|
@@ -917,6 +889,48 @@ export abstract class CoreApp<
|
|
|
917
889
|
this.storage.setData(field, newValue);
|
|
918
890
|
}
|
|
919
891
|
}
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Init call update
|
|
896
|
+
* @param data Result data
|
|
897
|
+
* @param timestamp Timestamp
|
|
898
|
+
*/
|
|
899
|
+
protected async initCallUpdate(
|
|
900
|
+
data: InitCallResultData,
|
|
901
|
+
timestamp: number
|
|
902
|
+
): Promise<boolean> {
|
|
903
|
+
// Data check
|
|
904
|
+
if (data.deviceId == null || data.passphrase == null) return false;
|
|
905
|
+
|
|
906
|
+
// Decrypt
|
|
907
|
+
// Should be done within 120 seconds after returning from the backend
|
|
908
|
+
const passphrase = this.decrypt(data.passphrase, timestamp.toString());
|
|
909
|
+
if (passphrase == null) return false;
|
|
910
|
+
|
|
911
|
+
// Update device id and cache it
|
|
912
|
+
this._deviceId = data.deviceId;
|
|
913
|
+
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
914
|
+
|
|
915
|
+
// Devices
|
|
916
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
917
|
+
this.fields.devices,
|
|
918
|
+
[]
|
|
919
|
+
);
|
|
920
|
+
devices.push(this.getDeviceId());
|
|
921
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
922
|
+
|
|
923
|
+
// Previous passphrase
|
|
924
|
+
if (data.previousPassphrase) {
|
|
925
|
+
const prev = this.decrypt(
|
|
926
|
+
data.previousPassphrase,
|
|
927
|
+
timestamp.toString()
|
|
928
|
+
);
|
|
929
|
+
this.passphrase = prev ?? '';
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// Update passphrase
|
|
933
|
+
this.updatePassphrase(passphrase);
|
|
920
934
|
|
|
921
935
|
return true;
|
|
922
936
|
}
|