diff --git a/circuits/tests/disclose/disclose.test.ts b/circuits/tests/disclose/disclose.test.ts index a7e1c3d6d..b6900ecd9 100644 --- a/circuits/tests/disclose/disclose.test.ts +++ b/circuits/tests/disclose/disclose.test.ts @@ -1,11 +1,9 @@ import { assert, expect } from 'chai'; import path from 'path'; import { wasm as wasm_tester } from 'circom_tester'; -import { mockPassportData_sha256_rsa_65537 } from '../../../common/src/constants/mockPassportData'; import { formatMrz, packBytes } from '../../../common/src/utils/utils'; import { attributeToPosition, - COMMITMENT_TREE_DEPTH, PASSPORT_ATTESTATION_ID, } from '../../../common/src/constants/constants'; import { poseidon1, poseidon2, poseidon6 } from 'poseidon-lite'; @@ -14,13 +12,14 @@ import { getLeaf } from '../../../common/src/utils/pubkeyTree'; import { generateCircuitInputsDisclose } from '../../../common/src/utils/generateInputs'; import { formatAndUnpackReveal } from '../../../common/src/utils/revealBitmap'; import crypto from 'crypto'; +import { genMockPassportData } from '../../../common/src/utils/genMockPassportData'; describe('Disclose', function () { this.timeout(0); let inputs: any; let circuit: any; let w: any; - let passportData = mockPassportData_sha256_rsa_65537; + const passportData = genMockPassportData('rsa_sha256', 'FRA', '000101', '300101'); let tree: any; before(async () => { diff --git a/common/src/utils/generateInputs.ts b/common/src/utils/generateInputs.ts index 24fd98a3f..25cb48523 100644 --- a/common/src/utils/generateInputs.ts +++ b/common/src/utils/generateInputs.ts @@ -132,7 +132,7 @@ export function generateCircuitInputsRegister( dscModulusComponents = { dsc_modulus: splitToWords( - BigInt(hexToDecimal(modulus as string)), + BigInt(hexToDecimal(modulus)), n_dsc, k_dsc ) diff --git a/common/src/utils/pubkeyTree.ts b/common/src/utils/pubkeyTree.ts index 802abf391..545d9cace 100644 --- a/common/src/utils/pubkeyTree.ts +++ b/common/src/utils/pubkeyTree.ts @@ -7,8 +7,9 @@ import { PassportData } from "./types"; import { getSignatureAlgorithm } from "./handleCertificate"; export function getLeaf(passportData: PassportData): bigint { - const { signatureAlgorithm, modulus, x, y } = getSignatureAlgorithm(passportData.dsc); - + const { signatureAlgorithm, hashFunction, modulus, x, y } = getSignatureAlgorithm(passportData.dsc); + const sigAlgIndex = SignatureAlgorithmIndex[`${signatureAlgorithm}_${hashFunction}`] + if (signatureAlgorithm === 'ecdsa') { let qx = splitToWords(BigInt(hexToDecimal(x)), 43, 6); let qy = splitToWords(BigInt(hexToDecimal(y)), 43, 6); @@ -17,15 +18,17 @@ export function getLeaf(passportData: PassportData): bigint { let y_hash = poseidon6(qy); return poseidon3([ - SignatureAlgorithmIndex[signatureAlgorithm], + sigAlgIndex, x_hash, y_hash, ]); } else { - const pubkeyChunked = splitToWords(BigInt(modulus), 230, 9); - return poseidon10( - [SignatureAlgorithmIndex[signatureAlgorithm], ...pubkeyChunked] - ); + const pubkeyChunked = splitToWords(BigInt(hexToDecimal(modulus)), 230, 9); + + return poseidon10([ + sigAlgIndex, + ...pubkeyChunked + ]); } }