mirror of
https://github.com/selfxyz/self.git
synced 2026-01-23 13:38:04 -05:00
add passport data contribution
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.3",
|
||||
"react-native-canvas": "^0.1.39",
|
||||
"react-native-dialog": "^9.3.0",
|
||||
"react-native-fs": "^2.20.0",
|
||||
"react-native-get-random-values": "^1.11.0",
|
||||
"react-native-keychain": "^8.2.0",
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { YStack, XStack, Text, Button, Tabs, Sheet, Label, Fieldset, Input, Switch, H2, Image, useWindowDimensions, H4, H3 } from 'tamagui'
|
||||
import { HelpCircle, IterationCw, VenetianMask, Cog, CheckCircle2, ChevronLeft } from '@tamagui/lucide-icons';
|
||||
import { HelpCircle, IterationCw, VenetianMask, Cog, CheckCircle2, ChevronLeft, Share } from '@tamagui/lucide-icons';
|
||||
import X from '../images/x.png'
|
||||
import Telegram from '../images/telegram.png'
|
||||
import Github from '../images/github.png'
|
||||
import Internet from "../images/internet.png"
|
||||
import ScanScreen from './ScanScreen';
|
||||
import ProveScreen from './ProveScreen';
|
||||
import { Steps } from '../utils/utils';
|
||||
import AppScreen from './AppScreen';
|
||||
@@ -22,10 +21,14 @@ import useNavigationStore from '../stores/navigationStore';
|
||||
import NfcScreen from './NfcScreen';
|
||||
import CameraScreen from './CameraScreen';
|
||||
import { mockPassportData_sha256WithRSAEncryption_65537 } from '../../../common/src/utils/mockPassportData';
|
||||
import Dialog from "react-native-dialog";
|
||||
import { contribute } from '../utils/contribute';
|
||||
|
||||
|
||||
const MainScreen: React.FC = () => {
|
||||
const [NFCScanIsOpen, setNFCScanIsOpen] = useState(false);
|
||||
const [SettingsIsOpen, setSettingsIsOpen] = useState(false);
|
||||
const [DialogContributeIsOpen, setDialogContributeIsOpen] = useState(false);
|
||||
const [HelpIsOpen, setHelpIsOpen] = useState(false);
|
||||
const [brokenCamera, setBrokenCamera] = useState(false);
|
||||
const [sheetIsOpen, setSheetIsOpen] = useState(false);
|
||||
@@ -39,6 +42,7 @@ const MainScreen: React.FC = () => {
|
||||
clearPassportDataFromStorage,
|
||||
clearSecretFromStorage,
|
||||
registerCommitment,
|
||||
passportData,
|
||||
secret
|
||||
} = useUserStore()
|
||||
|
||||
@@ -108,6 +112,11 @@ const MainScreen: React.FC = () => {
|
||||
scan();
|
||||
}
|
||||
}
|
||||
function handleContribute() {
|
||||
contribute(passportData);
|
||||
setDialogContributeIsOpen(false);
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (passportNumber?.length === 9 && (dateOfBirth?.length === 6 && dateOfExpiry?.length === 6)) {
|
||||
@@ -285,6 +294,27 @@ const MainScreen: React.FC = () => {
|
||||
</Switch>
|
||||
</Fieldset>
|
||||
|
||||
<Fieldset gap="$4" mt="$1" horizontal>
|
||||
<Label color={textColor1} width={200} justifyContent="flex-end" htmlFor="restart">
|
||||
Contribute
|
||||
</Label>
|
||||
<Button bg={componentBgColor} jc="center" borderColor={borderColor} borderWidth={1.2} size="$3.5" ml="$2" onPress={() => setDialogContributeIsOpen(true)}>
|
||||
<Share color={textColor1} />
|
||||
</Button>
|
||||
</Fieldset>
|
||||
|
||||
<Dialog.Container visible={DialogContributeIsOpen}>
|
||||
<Dialog.Title>Contribute</Dialog.Title>
|
||||
<Dialog.Description>
|
||||
By pressing yes, you accept sending your passport data.
|
||||
Passport data are encrypted and will be deleted once the signature algorithm is implemented.
|
||||
</Dialog.Description>
|
||||
<Dialog.Button onPress={() => setDialogContributeIsOpen(false)} label="Cancel" />
|
||||
<Dialog.Button onPress={() => handleContribute()} label="Contribute" />
|
||||
</Dialog.Container>
|
||||
|
||||
|
||||
|
||||
<Fieldset gap="$4" mt="$1" horizontal>
|
||||
<Label color={textColor1} width={200} justifyContent="flex-end" htmlFor="restart">
|
||||
Restart to step 1
|
||||
|
||||
58
app/src/utils/contribute.ts
Normal file
58
app/src/utils/contribute.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import axios from 'axios';
|
||||
import { contribute_publicKey } from '../../../common/src/constants/constants';
|
||||
import forge from 'node-forge';
|
||||
|
||||
export async function contribute(passportData: any): Promise<void> {
|
||||
|
||||
console.log("Contributing...")
|
||||
const textToEncrypt = JSON.stringify(passportData);
|
||||
console.log("Text to Encrypt:", textToEncrypt);
|
||||
|
||||
try {
|
||||
const aesKey = forge.random.getBytesSync(32);
|
||||
const iv = forge.random.getBytesSync(16);
|
||||
|
||||
console.log("Generated AES Key (base64):", forge.util.encode64(aesKey));
|
||||
console.log("Generated IV (base64):", forge.util.encode64(iv));
|
||||
|
||||
const cipher = forge.cipher.createCipher('AES-CBC', aesKey);
|
||||
cipher.start({ iv: iv });
|
||||
cipher.update(forge.util.createBuffer(textToEncrypt, 'utf8'));
|
||||
cipher.finish();
|
||||
const encryptedData = cipher.output.getBytes();
|
||||
|
||||
console.log("Encrypted Data (base64):", forge.util.encode64(encryptedData));
|
||||
|
||||
const publicKey = forge.pki.publicKeyFromPem(contribute_publicKey);
|
||||
const encryptedAesKey = publicKey.encrypt(aesKey, 'RSA-OAEP', {
|
||||
md: forge.md.sha256.create(),
|
||||
mgf1: {
|
||||
md: forge.md.sha256.create()
|
||||
}
|
||||
});
|
||||
|
||||
const aesKeyBase64 = forge.util.encode64(encryptedAesKey);
|
||||
const ivBase64 = forge.util.encode64(iv);
|
||||
const encryptedDataBase64 = forge.util.encode64(encryptedData);
|
||||
|
||||
console.log("Encrypted AES Key (base64):", aesKeyBase64);
|
||||
console.log("Encrypted Data (base64):", encryptedDataBase64);
|
||||
|
||||
const data = {
|
||||
aesKey: aesKeyBase64,
|
||||
iv: ivBase64,
|
||||
encryptedData: encryptedDataBase64
|
||||
};
|
||||
|
||||
console.log("Data to be sent:", JSON.stringify(data));
|
||||
|
||||
const response = await axios.post('https://app.proofofpassport.com/contribute', {
|
||||
nullifier: forge.md.sha256.create().update(passportData.encryptedDigest.toString()).digest().toHex(),
|
||||
data: data
|
||||
});
|
||||
console.log("Server Response:", response.data);
|
||||
} catch (error) {
|
||||
console.error("Encryption Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,3 +287,17 @@ export const countryCodes = {
|
||||
"ZMB": "Zambia",
|
||||
"ZWE": "Zimbabwe"
|
||||
}
|
||||
|
||||
export const contribute_publicKey = `-----BEGIN RSA PUBLIC KEY-----
|
||||
MIICCgKCAgEAv/hm7FZZ2KBmaeDHmLoRwuWmCcNKT561RqbsW8ZuYSyPWJUldE9U
|
||||
Cf0lW3K1H5lsSDkl0Cq84cooL9f6X59Mffb/N24ZKTdL0xdcPwjk4LbcrVm8qubL
|
||||
0a/4uCNoZZ1my4nxbpLxYtbr8CNmUGvBOVKf8IcjsY6VghIZrO63G6BN/G44su1Z
|
||||
WcHpboGt9SDQK4enCyKxnCD+PbDYlewSA0n3GRajFfZex1bj1EvrS2hTLv8oNH5e
|
||||
9H+3TUke0uO6Ttl0bZepoMmPlpAXhJByISqC6SLth4WFIH+G1I/xt9AEM7hOfLMl
|
||||
KQv/3wlLEgEueRryKAHB2tqkaDKVJyw+tOyWj2iWA+nVgQKAxO4hOw01ljyVbcx6
|
||||
KboXwnamlZPFIx4tjEaZ+ClXCFqvXhE9LDFK11QsYzJZl0aRVfTNqcurhEt7SK0f
|
||||
qzOBhID0Nxk4k9sW1uT6ocW1xp1SB2WotORssOKIAOLJM8IbPl6n/DkYNcfvyXI7
|
||||
4BlUrf6M2DgZMYATabIy94AvopHJOyiRfh4NpQPDntWnShiI1em2MmtXiWFCdVFV
|
||||
6/QfJTKVixJpVfDh386ALXc97EPWDMWIalUwYoV/eRSMnuV8nZ0+Ctp3Qrtk/JYd
|
||||
+FWhKbtlPeRjmGVr6mVlvDJ7KqtY5/RqqwfWeXhXezGhQqQ/OoQQCRkCAwEAAQ==
|
||||
-----END RSA PUBLIC KEY-----`;
|
||||
|
||||
Reference in New Issue
Block a user