This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
/
AuthenticationSourceLocalPasscode.js
95 lines (80 loc) · 2.21 KB
/
AuthenticationSourceLocalPasscode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import SF from '@SFJS/sfjs'
import Storage from '@SFJS/storageManager'
import KeysManager from '@Lib/keysManager'
import AuthenticationSource from "./AuthenticationSource"
import StyleKit from "@Style/StyleKit"
export default class AuthenticationSourceLocalPasscode extends AuthenticationSource {
constructor() {
super();
Storage.get().getItem("passcodeKeyboardType").then((result) => {
this.keyboardType = result || 'default';
this.requiresInterfaceReload();
});
}
get headerButtonText() {
return this.isWaitingForInput() && "Change Keyboard";
}
get headerButtonStyles() {
return {
color: StyleKit.variables.stylekitNeutralColor,
fontSize: StyleKit.constants.mainTextFontSize - 5
}
}
headerButtonAction = () => {
if(this.keyboardType == "default") {
this.keyboardType = "numeric";
} else {
this.keyboardType = "default";
}
this.requiresInterfaceReload();
}
get sort() {
return 0;
}
get identifier() {
return "local-passcode-auth-source";
}
get title() {
return "Local Passcode";
}
get label() {
switch (this.status) {
case "waiting-turn":
case "waiting-input":
return "Enter your local passcode"
case "processing":
return "Verifying keys...";
case "did-fail":
return "Invalid local passcode. Please try again."
case "did-succeed":
return "Success | Local Passcode"
default:
return "Status not accounted for: " + this.status
}
}
get type() {
return "input";
}
get inputPlaceholder() {
return "Local Passcode";
}
async authenticate() {
this.didBegin();
var authParams = KeysManager.get().offlineAuthParams;
let keys = await SF.get().crypto.computeEncryptionKeysForUser(this.authenticationValue, authParams);
if(keys.pw === KeysManager.get().offlinePasscodeHash()) {
await KeysManager.get().setOfflineKeys(keys);
return this._success();
} else {
return this._fail("Invalid local passcode. Please try again.");
}
}
_success() {
this.didSucceed();
return {success: true};
}
_fail(message) {
this.didFail();
return {success: false, error: {message: message}};
}
}