mirror of
https://github.com/status-im/keycard-exit.git
synced 2025-02-02 14:03:28 +00:00
check that correct card is tapped
This commit is contained in:
parent
f31564e8ec
commit
ec01d39f27
42
src/Main.tsx
42
src/Main.tsx
@ -27,6 +27,7 @@ enum Step {
|
|||||||
LoginError,
|
LoginError,
|
||||||
FactoryReset,
|
FactoryReset,
|
||||||
NotAuthentic,
|
NotAuthentic,
|
||||||
|
WrongCard
|
||||||
}
|
}
|
||||||
|
|
||||||
const Main = () => {
|
const Main = () => {
|
||||||
@ -44,6 +45,7 @@ const Main = () => {
|
|||||||
const pinRef = useRef("");
|
const pinRef = useRef("");
|
||||||
const mnemonicRef = useRef("");
|
const mnemonicRef = useRef("");
|
||||||
const walletKey = useRef("");
|
const walletKey = useRef("");
|
||||||
|
const keyUID = useRef("");
|
||||||
const sessionRef = useRef("")
|
const sessionRef = useRef("")
|
||||||
const challengeRef = useRef("")
|
const challengeRef = useRef("")
|
||||||
|
|
||||||
@ -76,6 +78,20 @@ const Main = () => {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rememberCard = async (uid) => {
|
||||||
|
walletKey.current = await Keycard.exportKeyWithPath(pinRef.current, WALLET_DERIVATION_PATH);
|
||||||
|
keyUID.current = uid;
|
||||||
|
await AsyncStorage.setItem("wallet-key", walletKey.current);
|
||||||
|
await AsyncStorage.setItem("key-uid", keyUID.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
const forgetCard = () => {
|
||||||
|
walletKey.current = "";
|
||||||
|
keyUID.current = ""
|
||||||
|
AsyncStorage.removeItem("wallet-key");
|
||||||
|
AsyncStorage.removeItem("key-uid");
|
||||||
|
}
|
||||||
|
|
||||||
const loginRequest = async () => {
|
const loginRequest = async () => {
|
||||||
var req = {'session-id': sessionRef.current};
|
var req = {'session-id': sessionRef.current};
|
||||||
|
|
||||||
@ -130,22 +146,23 @@ const Main = () => {
|
|||||||
break;
|
break;
|
||||||
case Step.Loading:
|
case Step.Loading:
|
||||||
await Keycard.saveMnemonic(mnemonicRef.current, pinRef.current);
|
await Keycard.saveMnemonic(mnemonicRef.current, pinRef.current);
|
||||||
walletKey.current = await Keycard.exportKeyWithPath(pinRef.current, WALLET_DERIVATION_PATH);
|
await rememberCard(appInfo["key-uid"]);
|
||||||
await AsyncStorage.setItem("wallet-key", walletKey.current);
|
|
||||||
setStep(Step.LoadSuccess)
|
setStep(Step.LoadSuccess)
|
||||||
break;
|
break;
|
||||||
case Step.Authentication:
|
case Step.Authentication:
|
||||||
walletKey.current = await Keycard.exportKeyWithPath(pinRef.current, WALLET_DERIVATION_PATH);
|
await rememberCard(appInfo["key-uid"]);
|
||||||
await AsyncStorage.setItem("wallet-key", walletKey.current);
|
|
||||||
setStep(Step.Home);
|
setStep(Step.Home);
|
||||||
break;
|
break;
|
||||||
case Step.Home:
|
case Step.Home:
|
||||||
loginReq = await loginRequest();
|
if (appInfo["key-uid"] != keyUID.current) {
|
||||||
|
setStep(Step.WrongCard);
|
||||||
|
} else {
|
||||||
|
loginReq = await loginRequest();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Step.FactoryReset:
|
case Step.FactoryReset:
|
||||||
await Keycard.factoryReset();
|
await Keycard.factoryReset();
|
||||||
walletKey.current = "";
|
forgetCard();
|
||||||
AsyncStorage.removeItem("wallet-key");
|
|
||||||
setStep(Step.Discovery);
|
setStep(Step.Discovery);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -178,8 +195,6 @@ const Main = () => {
|
|||||||
await stopNFC();
|
await stopNFC();
|
||||||
|
|
||||||
if (loginReq) {
|
if (loginReq) {
|
||||||
console.log(loginReq);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(LOGIN_ENDPOINT, {
|
const resp = await fetch(LOGIN_ENDPOINT, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -216,8 +231,11 @@ const Main = () => {
|
|||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
await Keycard.setPairings(await getPairings());
|
await Keycard.setPairings(await getPairings());
|
||||||
await Keycard.setCertificationAuthorities(["029ab99ee1e7a71bdf45b3f9c58c99866ff1294d2c1e304e228a86e10c3343501c"]);
|
await Keycard.setCertificationAuthorities(["029ab99ee1e7a71bdf45b3f9c58c99866ff1294d2c1e304e228a86e10c3343501c"]);
|
||||||
const tmp = await AsyncStorage.getItem("wallet-key");
|
|
||||||
|
let tmp = await AsyncStorage.getItem("wallet-key");
|
||||||
walletKey.current = tmp !== null ? tmp : "";
|
walletKey.current = tmp !== null ? tmp : "";
|
||||||
|
tmp = await AsyncStorage.getItem("key-uid");
|
||||||
|
keyUID.current = tmp !== null ? tmp : "";
|
||||||
|
|
||||||
if (walletKey.current) {
|
if (walletKey.current) {
|
||||||
setStep(Step.Home);
|
setStep(Step.Home);
|
||||||
@ -282,8 +300,7 @@ const Main = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
walletKey.current = "";
|
forgetCard();
|
||||||
AsyncStorage.removeItem("wallet-key");
|
|
||||||
setStep(Step.Discovery);
|
setStep(Step.Discovery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,6 +345,7 @@ const Main = () => {
|
|||||||
{step == Step.LoginSuccess && <InfoScreen icon="check-circle" title="Success!" message="Login successful. You can now proceed to the Operator Dashboard in your browser" onPressFunc={toHome}></InfoScreen>}
|
{step == Step.LoginSuccess && <InfoScreen icon="check-circle" title="Success!" message="Login successful. You can now proceed to the Operator Dashboard in your browser" onPressFunc={toHome}></InfoScreen>}
|
||||||
{step == Step.LoginError && <InfoScreen icon="close-circle" title="Error" message={errorMessage} onPressFunc={toHome}></InfoScreen>}
|
{step == Step.LoginError && <InfoScreen icon="close-circle" title="Error" message={errorMessage} onPressFunc={toHome}></InfoScreen>}
|
||||||
{step == Step.NotAuthentic && <InfoScreen icon="close-circle" title="Error" message="We couldn't verify that this is an authentic Keycard. Please contact your distributor." onPressFunc={cancel}></InfoScreen>}
|
{step == Step.NotAuthentic && <InfoScreen icon="close-circle" title="Error" message="We couldn't verify that this is an authentic Keycard. Please contact your distributor." onPressFunc={cancel}></InfoScreen>}
|
||||||
|
{step == Step.WrongCard && <InfoScreen icon="close-circle" title="Wrong card" message="You tapped a card different from the one logged in. Please either re-login with this card or tap the currently logged in card." onPressFunc={toHome}></InfoScreen>}
|
||||||
<NFCModal isVisible={isModalVisible} onChangeFunc={stopNFC}></NFCModal>
|
<NFCModal isVisible={isModalVisible} onChangeFunc={stopNFC}></NFCModal>
|
||||||
</ImageBackground>
|
</ImageBackground>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user