implement register flow (#100)

Co-authored-by: Nicolas Brugneaux <nicolas.brugneaux@gmail.com>
This commit is contained in:
turnoffthiscomputer
2025-02-13 20:51:38 +01:00
committed by GitHub
parent 6a36b55cb8
commit 7fa3c8e5d7
4 changed files with 52 additions and 12 deletions

View File

@@ -12,7 +12,7 @@ import miscAnimation from '../../assets/animations/loading/misc.json';
import useHapticNavigation from '../../hooks/useHapticNavigation';
import { usePassport } from '../../stores/passportDataProvider';
import { ProofStatusEnum, useProofInfo } from '../../stores/proofProvider';
import { sendDscPayload } from '../../utils/proving/payload';
import { registerPassport } from '../../utils/proving/payload';
const LoadingScreen: React.FC = () => {
const { setData } = usePassport();
@@ -53,7 +53,7 @@ const LoadingScreen: React.FC = () => {
);
const passportDataInit = initPassportDataParsing(passportData);
setData(passportDataInit);
await sendDscPayload(passportDataInit);
await registerPassport(passportDataInit);
} catch (error) {
console.error('Error processing payload:', error);
setStatus(ProofStatusEnum.ERROR);

View File

@@ -21,6 +21,7 @@ import {
generateCircuitInputsVCandDisclose,
} from '../../../../common/src/utils/circuits/generateInputs';
import { generateCommitment } from '../../../../common/src/utils/passports/passport';
import { getDSCTree, getLeafDscTree } from '../../../../common/src/utils/trees';
import { PassportData } from '../../../../common/src/utils/types';
import { sendPayload } from './tee';
@@ -168,3 +169,43 @@ export async function sendVcAndDisclosePayload(
const { inputs, circuitName } = generateTeeInputsVCAndDisclose(passportData);
await sendPayload(inputs, circuitName, WS_RPC_URL_VC_AND_DISCLOSE);
}
/*** Logic Flow ****/
function isUserRegistered(_passportData: PassportData) {
// check if user is already registered
// if registered, return true
// if not registered, return false
return false;
}
async function checkIdPassportDscIsInTree(passportData: PassportData) {
// download the dsc tree and check if the passport leaf is in the tree
const dscTree = await getDSCTree(false);
const hashFunction = (a: any, b: any) => poseidon2([a, b]);
const tree = LeanIMT.import(hashFunction, dscTree);
const leaf = getLeafDscTree(
passportData.dsc_parsed,
passportData.csca_parsed,
);
console.log('DSC leaf:', leaf);
const index = tree.indexOf(BigInt(leaf));
if (index === -1) {
console.log('DSC is not found in the tree, sending DSC payload');
await sendDscPayload(passportData);
} else {
console.log('DSC is found in the tree, skipping DSC payload');
}
}
export async function registerPassport(passportData: PassportData) {
// check if user is already registered
const isRegistered = isUserRegistered(passportData);
if (isRegistered) {
return; // TODO: show a screen explaining that the passport is already registered, needs to bring passphrase or secret from icloud backup
}
// download the dsc tree and check if the passport leaf is in the tree
await checkIdPassportDscIsInTree(passportData);
// send the register payload
await sendRegisterPayload(passportData);
}