Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Bugfix verifier #114

Merged
merged 6 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private void saveToFile(HashMap<String, Boolean> userIDMap) {
}
}
}

//legg til bruker, userID: false
public void addUserId(String id, boolean verified) {
HashMap<String, Boolean> map = loadFromFile();
Expand All @@ -99,10 +100,14 @@ public void addUserId(String id, boolean verified) {

//getIsUserVerified(id) return true/false, kalle i checkVerified
public boolean getIsUserVerified(String id) {
if (loadFromFile().get(id).equals(true)) {
if (loadFromFile().get(id) == null) {
return false;
}
else if (loadFromFile().get(id).equals(true)) {
System.out.println("true");
return true;
} return false;
}
return false;
}


Expand Down
14 changes: 1 addition & 13 deletions verifier/src/main/resources/userID.json
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
{
"37837": false,
"23505": false,
"97548": false,
"2298": false,
"55715": false,
"76504": false,
"27413": false,
"35581": false,
"52820": false,
"99123": false,
"55271": false
}
{}
15 changes: 1 addition & 14 deletions verifier/verifier-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import './App.css';
import React from "react";
import VerifyAge from './Pages/VerifyAge';
import Verified from './Pages/Verified';
import NotVerified from './Pages/NotVerified';
import {
BrowserRouter as Router,
Switch,
Route
} from "react-router-dom";

function App() {
return (
<div className="App">
<Router>
<Switch>
<Route exact path='/' component={VerifyAge}/>
<Route exact path='/verified' component={Verified}/>
<Route exact path='/notVerified' component={NotVerified}/>
</Switch>
</Router>
<VerifyAge/>
</div>
);
}
Expand Down
14 changes: 0 additions & 14 deletions verifier/verifier-app/src/Pages/NotVerified.jsx

This file was deleted.

12 changes: 0 additions & 12 deletions verifier/verifier-app/src/Pages/Verified.jsx

This file was deleted.

71 changes: 40 additions & 31 deletions verifier/verifier-app/src/Pages/VerifyAge.jsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,73 @@
import React from "react";
import {Link, useHistory} from "react-router-dom";
import React, {useState, useEffect} from "react";
import QRCode from "react-qr-code";
import localIpUrl from 'local-ip-url';
import { useInterval } from "../hooks/useInterval";

export default function VerifyAge() {

function VerifyAge() {

let history = useHistory()
const path = localIpUrl() + ':3000/api/sendVP'
const userID = Math.floor((Math.random() * 100000))
const VERIFY_REFRESH_INTERVAL = 2000;

async function checkAge(id) {
let response = await fetch('/api/checkVerified?id='+ id)
.then(response => response.json())
//.catch(err => console.log('There was an error:' + err))
console.log(response)
const [userID, setUserID] = useState();
const [verified, setVerified] = useState(false);

if (response === false) {
console.log(response)
history.push('/notVerified')
} else {
history.push('/verified')
console.log(response)
}
function generateUserID() {
const id = Math.floor((Math.random() * 100000));
console.log("Generated userID: " + id);
return id;
}

async function httpGetVerifiedAge(id) {
let response = await fetch('/api/checkVerified?id='+ id)
.then(response => response.json());
//.catch(err => console.log('There was an error:' + err))
console.log("GET verified: " + response);
return response;
}

async function httpSendUserId(id) {
console.log(userID)
console.log("POST userID argument: " + id)
try {
const response = await fetch("/api/sendUserID", {
method: "POST",
body: JSON.stringify(id)
})
console.log(response.text())
console.log("POST userID response: " + response.text())
if (response.ok) {
return true;
}
return false;
}
catch (error) {
console.log("feil");
console.log("feil under sending av userID");
return false;
}
}

// Called only once when page is loaded
useEffect(() => {
const generated = generateUserID();
setUserID(generated);
}, []);

// Called when userID is changed
useEffect(() => {
httpSendUserId(userID)
}, [userID]);

// Called continuously with the specified interval delay
useInterval(async () => {
const verified = await httpGetVerifiedAge(userID);
setVerified(verified);
}, VERIFY_REFRESH_INTERVAL);

return (
<div className="VerifyAge">
<p>You must be over 18 to continue</p>
<p>Verifiser at du er over 18.</p>
<QRCode value={path + '|over-18|' + userID}/>
<br/>
<br/>
<br/>
<button className="btn" onClick={() => httpSendUserId(userID)}>Send proof</button>
<br/>
<br/>
<br/>
<Link className="btn" to={history} onClick={() => checkAge(userID)}>Verify age</Link>
<p style={{color: verified ? "green" : "black"}}>Du er {!verified && "enda ikke"} verifisert.</p>
</div>
);
}

export default VerifyAge;
}
23 changes: 23 additions & 0 deletions verifier/verifier-app/src/hooks/useInterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useRef } from "react";

export function useInterval(callback, delay) {
const savedCallback = useRef();

// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback;
}, [callback]);

// Set up the interval
useEffect(() => {
function tick() {
savedCallback.current();
}
if (delay !== null) {
const id = setInterval(tick, delay);
return () => {
clearInterval(id);
};
}
}, [callback, delay])
}
51 changes: 29 additions & 22 deletions wallet/wallet-app/components/frames/ActivityFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { addCredentialShare } from '../../redux/CredentialShareSlice';
import { httpSendPresentation } from '../../utils/httpRequests';
import createVerifiablePresentationJWT from '../../utils/sign';


/**
* A frame with a botton to send proof to a verifier if you choose to share
* @returns A frame, sending the proof
Expand All @@ -20,24 +19,26 @@ export default function ActivityFrame() {
const [scanned, setScanned] = useState(false);
const navigation = useNavigation();
const { cred } = useSelector((state) => state.credentials);

async function sendPresentation(creds, audience, user) {
const jwtCreds = creds.map((c) => c.token);
const token = await createVerifiablePresentationJWT(jwtCreds, audience, user);
const verified = await httpSendPresentation(token);

if (verified) {
alert("Bevis sendt");
alert('Bevis sendt');
creds.map((c) =>
dispatch(
addCredentialShare({
id: Math.random().toString(),
credential_id: c.jti,
verifier: audience,
})
)
) } else {
alert("Bevis ble ikke sendt")
};
dispatch(
addCredentialShare({
id: Math.random().toString(),
credential_id: c.jti,
verifier: audience,
})
)
);
} else {
alert('Bevis ble ikke sendt');
}
setStatus(verified);
return verified;
}
Expand All @@ -55,14 +56,18 @@ export default function ActivityFrame() {
}
}

Alert.alert('TJENESTE SPØR OM BEVIS', `Vil du godkjenne at beviset ${vc} blir sendt til tjeneste ${verifier}?`, [
{
text: 'Ikke godkjenn',
onPress: () => navigation.navigate('Oversikt'),
style: 'cancel',
},
{ text: 'Godkjenn', onPress: () => sendPresentation([proof], verifier, userID) },
]);
Alert.alert(
'TJENESTE SPØR OM BEVIS',
`Vil du godkjenne at beviset ${vc} blir sendt til tjeneste ${verifier}?`,
[
{
text: 'Ikke godkjenn',
onPress: () => navigation.navigate('Oversikt') && setScanned(false),
style: 'cancel',
},
{ text: 'Godkjenn', onPress: () => sendPresentation([proof], verifier, userID) && setScanned(false) },
]
);
};

return (
Expand All @@ -83,7 +88,9 @@ export default function ActivityFrame() {
<Text>Du har ingen bevis</Text>
)} */}
<View>
<Text style = {styles.instructionText}>Skann QR-koden til en tjeneste du ønsker å dele et bevis med:</Text>
<Text style={styles.instructionText}>
Skann QR-koden til en tjeneste du ønsker å dele et bevis med:
</Text>
</View>
<View style={styles.camera}>
<BarCodeScanner
Expand Down