diff --git a/circuits/circuits/prove/openpassport_prove.circom b/circuits/circuits/prove/openpassport_prove.circom index d5998075..19874bba 100644 --- a/circuits/circuits/prove/openpassport_prove.circom +++ b/circuits/circuits/prove/openpassport_prove.circom @@ -23,7 +23,8 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M signal input signed_attr_econtent_hash_offset; signal input pubKey[kScaled]; signal input signature[kScaled]; - // diclose related inputs + signal input selector_mode; // 0 - disclose, 1 - registration + // disclose related inputs signal input selector_dg1[88]; signal input selector_older_than; signal input current_date[6]; // YYMMDD - num @@ -36,6 +37,9 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M signal attestation_id <== 1; + // assert selector_mode is 0 or 1 + selector_mode * (selector_mode - 1) === 0; + // verify passport signature PassportVerifier(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, MAX_SIGNED_ATTR_PADDED_LEN)(dg1,dg1_hash_offset, dg2_hash, eContent,eContent_padded_length, signed_attr, signed_attr_padded_length, signed_attr_econtent_hash_offset, pubKey, signature); @@ -57,9 +61,11 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M // REGISTRATION (optional) // generate the commitment signal leaf <== LeafHasher(kScaled)(pubKey, signatureAlgorithm); - signal output commitment <== ComputeCommitment()(secret, attestation_id, leaf, dg1, dg2_hash); + signal commitmentPrivate <== ComputeCommitment()(secret, attestation_id, leaf, dg1, dg2_hash); + signal output commitment <== commitmentPrivate * selector_mode; // blinded dsc commitment signal pubkeyHash <== CustomHasher(kScaled)(pubKey); - signal output blinded_dsc_commitment <== Poseidon(2)([dsc_secret, pubkeyHash]); + signal blindedDscCommitmenPrivate <== Poseidon(2)([dsc_secret, pubkeyHash]); + signal output blinded_dsc_commitment <== blindedDscCommitmenPrivate * selector_mode; } \ No newline at end of file diff --git a/circuits/tests/prove.test.ts b/circuits/tests/prove.test.ts index f9be38ea..d9185acb 100644 --- a/circuits/tests/prove.test.ts +++ b/circuits/tests/prove.test.ts @@ -34,10 +34,14 @@ sigAlgs.forEach(({ sigAlg, hashFunction }) => { const scope = '@coboyApp'; const selector_dg1 = Array(88).fill('1'); const selector_older_than = '1'; + const secret = 0; + const dsc_secret = 0; + const selector_mode = 1; const inputs = generateCircuitInputsProve( - BigInt(0).toString(), - BigInt(0).toString(), + selector_mode, + secret, + dsc_secret, passportData, scope, selector_dg1, diff --git a/common/src/utils/generateInputs.ts b/common/src/utils/generateInputs.ts index 4fc006ec..18e81c1b 100644 --- a/common/src/utils/generateInputs.ts +++ b/common/src/utils/generateInputs.ts @@ -130,8 +130,9 @@ export function findIndexInTree(tree: LeanIMT, commitment: bigint): number { export function generateCircuitInputsProve( - secret: string, - dsc_secret: string, + selector_mode: number | string, + secret: number | string, + dsc_secret: number | string, passportData: PassportData, scope: string, selector_dg1: string[], @@ -173,7 +174,6 @@ export function generateCircuitInputsProve( ) } - const dg1 = formatMrz(mrz); const formattedMrz = formatMrz(mrz); const dg1Hash = hash(hashFunction, formattedMrz); @@ -202,28 +202,36 @@ export function generateCircuitInputsProve( MAX_PADDED_SIGNED_ATTR_LEN[signatureAlgorithmFullName] ); - const current_date = getCurrentDateYYMMDD().map(datePart => BigInt(datePart).toString()); - // Ensure majority is at least two digits const formattedMajority = majority.length === 1 ? `0${majority}` : majority; + const majority_ascii = formattedMajority.split('').map(char => char.charCodeAt(0)) return { - dg1: dg1.map(byte => String(byte)), - dg1_hash_offset: [dg1HashOffset.toString()], // uncomment when adding new circuits + selector_mode: formatInput(selector_mode), + dg1: formatInput(formattedMrz), + dg1_hash_offset: formatInput(dg1HashOffset), dg2_hash: formatDg2Hash(dg2Hash), eContent: Array.from(eContentPadded).map((x) => x.toString()), - eContent_padded_length: [eContentLen.toString()], + eContent_padded_length: formatInput(eContentLen), signed_attr: Array.from(signedAttrPadded).map((x) => x.toString()), - signed_attr_padded_length: [signedAttrPaddedLen.toString()], - signed_attr_econtent_hash_offset: [eContentHashOffset.toString()], + signed_attr_padded_length: formatInput(signedAttrPaddedLen), + signed_attr_econtent_hash_offset: formatInput(eContentHashOffset), signature: signature, pubKey: pubKey, - current_date: current_date, - selector_dg1: selector_dg1, - selector_older_than: [BigInt(selector_older_than).toString()], - majority: formattedMajority.split('').map(char => BigInt(char.charCodeAt(0)).toString()), - user_identifier: [parseUIDToBigInt(user_identifier, user_identifier_type)], - scope: [castFromScope(scope)], - secret: [secret], - dsc_secret: [dsc_secret], + current_date: formatInput(getCurrentDateYYMMDD()), + selector_dg1: formatInput(selector_dg1), + selector_older_than: formatInput(selector_older_than), + majority: formatInput(majority_ascii), + user_identifier: formatInput(parseUIDToBigInt(user_identifier, user_identifier_type)), + scope: formatInput(castFromScope(scope)), + secret: formatInput(secret), + dsc_secret: formatInput(dsc_secret), }; -} \ No newline at end of file +} + +function formatInput(input: any) { + if (Array.isArray(input)) { + return input.map(item => BigInt(item).toString()); + } else { + return [BigInt(input).toString()]; + } +}