make sbt proof work (still "Invalid Proof" on Android)

This commit is contained in:
0xturboblitz
2024-05-21 15:53:34 +09:00
parent 0f92f33885
commit 4facd39e63
3 changed files with 50 additions and 20 deletions

View File

@@ -127,13 +127,22 @@ export const sbtApp: AppType = {
await new Promise(resolve => setTimeout(resolve, 10));
const reveal_bitmap = revealBitmapFromMapping(disclosure);
// const httpsAgent = new https.Agent({
// rejectUnauthorized: false
// })
// const serializedCommitmentTree = await axios.get(COMMITMENT_TREE_TRACKER_URL, { httpsAgent })
const serializedCommitmentTree = await axios.get(COMMITMENT_TREE_TRACKER_URL)
// const serializedCommitmentTree = await axios.get(COMMITMENT_TREE_TRACKER_URL)
// console.log('Fetching commitment tree from:', COMMITMENT_TREE_TRACKER_URL);
// const response = await RNFetchBlob.config({
// trusty: true, // This allows self-signed certificates
// }).fetch('GET', 'https://34.222.134.21/api/download-merkle-tree');
// const serializedCommitmentTree = await response.json();
// console.log(serializedCommitmentTree);
// const serializedCommitmentTree = "[[\"9366833337168993085050982292715343583458999801189875133285760454940954329736\",\"17067815450997614268337156469331439256078702232208444991806942459610897177755\"],[\"5757843324860707578753413472099376283217223062835733089254074659436006978958\"]]"
// const serializedCommitmentTree = "[[\"9366833337168993085050982292715343583458999801189875133285760454940954329736\",\"17067815450997614268337156469331439256078702232208444991806942459610897177755\",\"6218618977460894587557092460164616095207478656436068295742870309857616419830\"],[\"5757843324860707578753413472099376283217223062835733089254074659436006978958\",\"6218618977460894587557092460164616095207478656436068295742870309857616419830\"],[\"21507073014749590076447052772712414887309630021883814888490891898697250244046\"]]"
// const serializedCommitmentTree = "[[\"9366833337168993085050982292715343583458999801189875133285760454940954329736\",\"17067815450997614268337156469331439256078702232208444991806942459610897177755\",\"6218618977460894587557092460164616095207478656436068295742870309857616419830\",\"1009498555512750055176786258919772755314598234878788682229429740456064488924\"],[\"5757843324860707578753413472099376283217223062835733089254074659436006978958\",\"9384382887555344903988763589988369409408141218078864334664000402547342440893\"],[\"6444500081923737565029349850782686417529434309028817508928891238372057960879\"]]"
// const serializedCommitmentTree = "[[\"9366833337168993085050982292715343583458999801189875133285760454940954329736\",\"17067815450997614268337156469331439256078702232208444991806942459610897177755\",\"6218618977460894587557092460164616095207478656436068295742870309857616419830\",\"1009498555512750055176786258919772755314598234878788682229429740456064488924\",\"2317777252282411584898482846587421326341858131145081778162865818517424463113\"],[\"5757843324860707578753413472099376283217223062835733089254074659436006978958\",\"9384382887555344903988763589988369409408141218078864334664000402547342440893\",\"2317777252282411584898482846587421326341858131145081778162865818517424463113\"],[\"6444500081923737565029349850782686417529434309028817508928891238372057960879\",\"2317777252282411584898482846587421326341858131145081778162865818517424463113\"],[\"11484632410345214898912322261100606383648392524576747792553991794581959208396\"]]"
const serializedCommitmentTree = "[[\"9366833337168993085050982292715343583458999801189875133285760454940954329736\",\"17067815450997614268337156469331439256078702232208444991806942459610897177755\",\"6218618977460894587557092460164616095207478656436068295742870309857616419830\",\"1009498555512750055176786258919772755314598234878788682229429740456064488924\",\"2317777252282411584898482846587421326341858131145081778162865818517424463113\",\"14350861400343175672772758664935358862843556622155842278173685659399974430673\"],[\"5757843324860707578753413472099376283217223062835733089254074659436006978958\",\"9384382887555344903988763589988369409408141218078864334664000402547342440893\",\"20714514634358291855499138323356766695315870633431415798546884765927810445680\"],[\"6444500081923737565029349850782686417529434309028817508928891238372057960879\",\"20714514634358291855499138323356766695315870633431415798546884765927810445680\"],[\"13949165376611379310020797746578693825960496340786495286952352659551479278661\"]]"
console.log('serializedCommitmentTree:', serializedCommitmentTree);
const imt = new LeanIMT(
@@ -141,14 +150,14 @@ export const sbtApp: AppType = {
[]
);
imt.import(serializedCommitmentTree.data);
imt.import(serializedCommitmentTree);
try {
const inputs = generateCircuitInputsDisclose(
secret,
PASSPORT_ATTESTATION_ID,
passportData,
imt,
imt as any,
majority.toString().split(""),
reveal_bitmap,
sbtApp.scope,

View File

@@ -49,6 +49,10 @@ const useUserStore = create<UserState>((set, get) => ({
// - If the commitment is present in the tree, proceed to main screen
// - If the commitment is not present in the tree, proceed to main screen AND try registering it in the background
initUserStore: async () => {
// download zkeys if they are not already downloaded
downloadZkey("register_sha256WithRSAEncryption_65537"); // might move after nfc scanning
downloadZkey("disclose");
const passportDataCreds = await Keychain.getGenericPassword({ service: "passportData" });
if (!passportDataCreds) {
console.log("No passport data found, starting onboarding flow")

View File

@@ -126,26 +126,43 @@ export function generateCircuitInputsDisclose(
mrz_bytes[0],
mrz_bytes[1],
mrz_bytes[2]
]).toString();
const index = merkletree.indexOf(BigInt(commitment));
if (index === -1) {
throw new Error("This commitment was not found in the tree");
}
]);
console.log('commitment', commitment);
const index = findIndexInTree(merkletree, commitment);
const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(merkletree, index, PUBKEY_TREE_DEPTH)
return {
secret: secret,
attestation_id: attestation_id,
pubkey_leaf: pubkey_leaf.toString(),
secret: [secret],
attestation_id: [attestation_id],
pubkey_leaf: [pubkey_leaf.toString()],
mrz: formattedMrz.map(byte => String(byte)),
merkle_root: [merkletree.root.toString()],
merkletree_size: BigInt(merkletree.depth).toString(),
path: merkleProofIndices,
siblings: merkleProofSiblings,
merkletree_size: [BigInt(merkletree.depth).toString()],
path: merkleProofIndices.map(index => BigInt(index).toString()),
siblings: merkleProofSiblings.map(index => BigInt(index).toString()),
bitmap: bitmap,
scope: scope,
scope: [scope],
current_date: getCurrentDateYYMMDD().map(datePart => BigInt(datePart).toString()),
majority: majority.map(char => BigInt(char.charCodeAt(0)).toString()),
user_identifier: user_identifier,
user_identifier: [user_identifier],
};
}
// this get the commitment index whether it is a string or a bigint
// this is necessary rn because when the tree is send from the server in a serialized form,
// the bigints are converted to strings and I can't figure out how to use tree.import to load bigints there
function findIndexInTree(tree: LeanIMT, commitment: bigint): number {
let index = tree.indexOf(commitment);
if (index === -1) {
index = tree.indexOf(commitment.toString() as unknown as bigint);
}
if (index === -1) {
throw new Error("This commitment was not found in the tree");
} else {
console.log(`Index of commitment in the registry: ${index}`);
}
return index;
}