mirror of
https://github.com/selfxyz/self.git
synced 2026-01-22 21:17:59 -05:00
abiility to skip scan and retrieve cached data
This commit is contained in:
5
app/.babelrc
Normal file
5
app/.babelrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
["module:react-native-dotenv"]
|
||||
]
|
||||
}
|
||||
58
app/App.tsx
58
app/App.tsx
@@ -23,18 +23,33 @@ import {
|
||||
} from 'react-native/Libraries/NewAppScreen';
|
||||
// @ts-ignore
|
||||
import PassportReader from 'react-native-passport-reader';
|
||||
import {checkInputs} from './utils/checks';
|
||||
import {checkInputs, getFirstName} from './utils/checks';
|
||||
import {DEFAULT_PNUMBER, DEFAULT_DOB, DEFAULT_DOE, DEFAULT_ADDRESS} from '@env';
|
||||
|
||||
const CACHE_PASSPORT_DATA = true;
|
||||
console.log('DEFAULT_PNUMBER', DEFAULT_PNUMBER);
|
||||
|
||||
const CACHE_DATA_IN_LOCAL_SERVER = true;
|
||||
const SKIP_SCAN = true;
|
||||
|
||||
type PassportData = {
|
||||
mrzInfo: any;
|
||||
publicKey: any;
|
||||
publicKeyPEM: any;
|
||||
dataGroupHashes: any;
|
||||
eContent: any;
|
||||
encryptedDigest: any;
|
||||
contentBytes: any;
|
||||
eContentDecomposed: any;
|
||||
};
|
||||
|
||||
function App(): JSX.Element {
|
||||
const isDarkMode = useColorScheme() === 'dark';
|
||||
const [passportNumber, setPassportNumber] = useState('19HA34828');
|
||||
const [dateOfBirth, setDateOfBirth] = useState('000719');
|
||||
const [dateOfExpiry, setDateOfExpiry] = useState('291209');
|
||||
const [address, setAddress] = useState('');
|
||||
const [passportNumber, setPassportNumber] = useState(DEFAULT_PNUMBER ?? '');
|
||||
const [dateOfBirth, setDateOfBirth] = useState(DEFAULT_DOB ?? '');
|
||||
const [dateOfExpiry, setDateOfExpiry] = useState(DEFAULT_DOE ?? '');
|
||||
const [address, setAddress] = useState(DEFAULT_ADDRESS ?? '');
|
||||
const [passportData, setPassportData] = useState<PassportData | null>(null);
|
||||
const [step, setStep] = useState('enterDetails');
|
||||
const [firstName, setFirstName] = useState('');
|
||||
|
||||
const backgroundStyle = {
|
||||
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
|
||||
@@ -50,6 +65,17 @@ function App(): JSX.Element {
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (SKIP_SCAN && passportData === null) {
|
||||
console.log('skipping scan step...');
|
||||
fetch('http://192.168.1.22:3000/passportData')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('passport data fetched');
|
||||
setPassportData(data);
|
||||
setStep('scanCompleted');
|
||||
});
|
||||
}
|
||||
|
||||
async function handleResponse(response: any) {
|
||||
const {
|
||||
mrzInfo,
|
||||
@@ -82,11 +108,12 @@ function App(): JSX.Element {
|
||||
console.log('contentBytes', passportData.contentBytes);
|
||||
console.log('eContentDecomposed', passportData.eContentDecomposed);
|
||||
|
||||
// Stores data in local server to avoid having to scan the passport each time
|
||||
// For development purposes only
|
||||
setPassportData(passportData);
|
||||
|
||||
if (CACHE_PASSPORT_DATA) {
|
||||
fetch('http://192.168.1.22:3000/passportData', {
|
||||
if (CACHE_DATA_IN_LOCAL_SERVER) {
|
||||
// Caches data in local server to avoid having to scan the passport each time
|
||||
// For development purposes only
|
||||
fetch('http://192.168.1.22:3000/post', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -100,11 +127,6 @@ function App(): JSX.Element {
|
||||
});
|
||||
}
|
||||
|
||||
const firstName = passportData.mrzInfo.secondaryIdentifier.split('<')[0];
|
||||
setFirstName(
|
||||
firstName.charAt(0).toUpperCase() + firstName.slice(1).toLowerCase(),
|
||||
);
|
||||
|
||||
// 1. Compute the eContent from the dg1File
|
||||
|
||||
// 2. Format all the data as calldata for the verifier contract
|
||||
@@ -192,7 +214,9 @@ function App(): JSX.Element {
|
||||
{step === 'scanCompleted' ? (
|
||||
<View style={styles.sectionContainer}>
|
||||
<Text style={styles.header}>Connection successful</Text>
|
||||
<Text style={styles.sectionDescription}>Hi {firstName} </Text>
|
||||
<Text style={styles.header}>
|
||||
Hi {getFirstName(passportData?.mrzInfo)} !{' '}
|
||||
</Text>
|
||||
<Text style={styles.header}>Input your address or ens</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
|
||||
1
app/declarations.d.ts
vendored
Normal file
1
app/declarations.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module '@env';
|
||||
@@ -29,12 +29,14 @@
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/node-forge": "^1.3.3",
|
||||
"@types/react": "^18.0.24",
|
||||
"@types/react-native-dotenv": "^0.2.0",
|
||||
"@types/react-test-renderer": "^18.0.0",
|
||||
"babel-jest": "^29.2.1",
|
||||
"eslint": "^8.19.0",
|
||||
"jest": "^29.2.1",
|
||||
"metro-react-native-babel-preset": "0.76.7",
|
||||
"prettier": "^2.4.1",
|
||||
"react-native-dotenv": "^3.4.9",
|
||||
"react-test-renderer": "18.2.0",
|
||||
"typescript": "4.8.4"
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ const app = express();
|
||||
// parse application/json
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.post('/passportData', (req: Request, res: Response) => {
|
||||
app.post('/post', (req: Request, res: Response) => {
|
||||
const data = req.body;
|
||||
fs.writeFile('passportData.json', JSON.stringify(data, null, 2), err => {
|
||||
if (err) {
|
||||
@@ -19,6 +19,17 @@ app.post('/passportData', (req: Request, res: Response) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/passportData', (req: Request, res: Response) => {
|
||||
fs.readFile('passportData.json', (err, data) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(500).json({message: 'An error occurred while reading file'});
|
||||
} else {
|
||||
res.json(JSON.parse(data.toString()));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const port = 3000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running on http://localhost:${port}`);
|
||||
|
||||
@@ -14,3 +14,8 @@ export function checkInputs(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function getFirstName(mrzInfo: any): string {
|
||||
const firstName = mrzInfo.secondaryIdentifier.split('<')[0];
|
||||
return firstName.charAt(0).toUpperCase() + firstName.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
@@ -1961,6 +1961,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
|
||||
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==
|
||||
|
||||
"@types/react-native-dotenv@^0.2.0":
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-native-dotenv/-/react-native-dotenv-0.2.0.tgz#32c58422a422c1adf68acce363ed791314d5a8e7"
|
||||
integrity sha512-ZxX+dU/yoQc0jTk+/NWttkiuXceJyN5FpOSqDl0WynN5GDzxwH7OMruQ47qcY8llo2RD3irjvzJ9BwC8gDiq0A==
|
||||
|
||||
"@types/react-test-renderer@^18.0.0":
|
||||
version "18.0.0"
|
||||
resolved "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-18.0.0.tgz"
|
||||
@@ -2989,6 +2994,11 @@ doctrine@^3.0.0:
|
||||
dependencies:
|
||||
esutils "^2.0.2"
|
||||
|
||||
dotenv@^16.3.1:
|
||||
version "16.3.1"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
|
||||
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
|
||||
|
||||
ee-first@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz"
|
||||
@@ -5638,6 +5648,13 @@ react-is@^17.0.1:
|
||||
resolved "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz"
|
||||
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
||||
|
||||
react-native-dotenv@^3.4.9:
|
||||
version "3.4.9"
|
||||
resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-3.4.9.tgz#621c5b0c1d0c5c7f569bfe5a1d804bec7885c010"
|
||||
integrity sha512-dbyd+mcy7SUzxEgmt33TRf1FGcNe6swJhXmB0unKkI49F7+pidog9kPtjxMLTAfmKA8gcN2XHQSKltGfGbGCLQ==
|
||||
dependencies:
|
||||
dotenv "^16.3.1"
|
||||
|
||||
react-native-passport-reader@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmjs.org/react-native-passport-reader/-/react-native-passport-reader-1.0.3.tgz"
|
||||
|
||||
Reference in New Issue
Block a user