Merge branch 'dev' of github.com:zk-passport/proof-of-passport into dev

This commit is contained in:
ashpect
2024-08-08 03:25:30 +05:30
131 changed files with 10610 additions and 2349 deletions

View File

@@ -83,4 +83,5 @@ template Register_ecdsaWithSHA1Encryption(n, k, max_datahashes_bytes, nLevels, s
signal output commitment <== poseidon_hasher.out;
}
// We hardcode 7 here for ecdsa_with_SHA1
component main { public [ attestation_id ] } = Register_ecdsaWithSHA1Encryption(43, 6, 320, 16, 7);

View File

@@ -83,4 +83,5 @@ template Register_ecdsaWithSHA256Encryption(n, k, max_datahashes_bytes, nLevels,
signal output commitment <== poseidon_hasher.out;
}
// We hardcode 8 here for ecdsa_with_SHA256
component main { public [ attestation_id ] } = Register_ecdsaWithSHA256Encryption(43, 6, 320, 16, 8);

View File

@@ -62,5 +62,5 @@ template Register_sha1WithRSAEncryption_65537(n, k, max_datahashes_bytes, nLevel
}
// We hardcode 1 here for sha1WithRSAEncryption_65537
// We hardcode 3 here for sha1WithRSAEncryption_65537
component main { public [ attestation_id ] } = Register_sha1WithRSAEncryption_65537(121, 17, 320, 16, 3);

View File

@@ -62,5 +62,5 @@ template register_sha256WithRSASSAPSS_65537(n, k, max_datahashes_bytes, nLevels,
}
// We hardcode 1 here for sha256WithRSAEncryption_65537
// We hardcode 4 here for sha256WithRSASSAPSS_65537
component main { public [ attestation_id ] } = register_sha256WithRSASSAPSS_65537(64, 32, 320, 16, 4);

View File

@@ -1,61 +0,0 @@
pragma circom 2.1.5;
include "circomlib/circuits/poseidon.circom";
include "@zk-email/circuits/utils/bytes.circom";
include "./verifier/passport_verifier_sha256WithRSASSAPSS_65537.circom";
include "../utils/chunk_data.circom";
include "../utils/compute_pubkey_leaf.circom";
include "binary-merkle-root.circom";
template register_sha256WithRSASSAPSS_65537(n, k, max_datahashes_bytes, nLevels, signatureAlgorithm) {
signal input secret;
signal input mrz[93];
signal input dg1_hash_offset;
signal input econtent[max_datahashes_bytes];
signal input datahashes_padded_length;
signal input signed_attributes[104];
signal input signature[k];
signal input pubkey[k];
signal input merkle_root;
signal input path[nLevels];
signal input siblings[nLevels];
signal input attestation_id;
// Verify inclusion of the pubkey in the pubkey tree
signal leaf <== ComputePubkeyLeaf(n, k, signatureAlgorithm)(pubkey);
signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
merkle_root === computed_merkle_root;
// Verify passport validity
component PV = PassportVerifier_sha256WithRSASSAPSS_65537(n, k, max_datahashes_bytes);
PV.mrz <== mrz;
PV.dg1_hash_offset <== dg1_hash_offset;
PV.dataHashes <== econtent;
PV.datahashes_padded_length <== datahashes_padded_length;
PV.eContentBytes <== signed_attributes;
PV.pubkey <== pubkey;
PV.signature <== signature;
// Generate the commitment
component poseidon_hasher = Poseidon(6);
poseidon_hasher.inputs[0] <== secret;
poseidon_hasher.inputs[1] <== attestation_id;
poseidon_hasher.inputs[2] <== leaf;
signal mrz_packed[3] <== PackBytes(93)(mrz);
for (var i = 0; i < 3; i++) {
poseidon_hasher.inputs[i + 3] <== mrz_packed[i];
}
signal output commitment <== poseidon_hasher.out;
// Generate the nullifier
var chunk_size = 11; // Since ceil(32 / 3) in integer division is 11
signal chunked_signature[chunk_size] <== ChunkData(n, k, chunk_size)(signature);
signal output nullifier <== Poseidon(chunk_size)(chunked_signature);
}
// We hardcode 1 here for sha256WithRSAEncryption_65537
component main { public [ merkle_root, attestation_id ] } = register_sha256WithRSASSAPSS_65537(121, 17, 320, 16, 4);

View File

@@ -35,7 +35,7 @@ describe('Disclose', function () {
const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
attestation_id = poseidon1([BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))]).toString();
const majority = ['1', '8'];
const majority = '18';
const user_identifier = '0xE6E4b6a802F2e0aeE5676f6010e0AF5C9CDd0a50';
const bitmap = Array(90).fill('1');
const scope = poseidon1([BigInt(Buffer.from('VOTEEEEE').readUIntBE(0, 6))]).toString();

View File

@@ -64,6 +64,6 @@ describe('DSC chain certificate - SHA1 RSA', function () {
});
it('should compute the correct output', async () => {
const witness = await circuit.calculateWitness(inputs, true);
const witness = await circuit.calculateWitness(inputs.inputs, true);
});
});

View File

@@ -63,6 +63,6 @@ describe('DSC chain certificate - SHA256 RSA', function () {
});
it('should compute the correct output', async () => {
const witness = await circuit.calculateWitness(inputs, true);
const witness = await circuit.calculateWitness(inputs.inputs, true);
});
});

View File

@@ -94,6 +94,6 @@ describe('DSC chain certificate - SHA256 RSA-PSS', function () {
});
it('should compute the correct output', async () => {
const witness = await circuit.calculateWitness(inputs, true);
const witness = await circuit.calculateWitness(inputs.inputs, true);
});
});

View File

@@ -32,7 +32,7 @@ function getPassportInputs(passportData: PassportData) {
BigInt(Buffer.from(attestation_name).readUIntBE(0, 6)),
]).toString();
const majority = ['1', '8'];
const majority = '18';
const user_identifier = '0xE6E4b6a802F2e0aeE5676f6010e0AF5C9CDd0a50';
const bitmap = Array(90).fill('1');
const scope = poseidon1([BigInt(Buffer.from('VOTEEEEE').readUIntBE(0, 6))]).toString();

View File

@@ -1,7 +1,7 @@
import { describe } from 'mocha';
import path from 'path';
import { poseidon1, poseidon6 } from 'poseidon-lite';
import { mockPassPortData_sha1_ecdsa } from '../../../common/src/constants/mockPassportData';
import { mockPassportData_sha1_ecdsa } from '../../../common/src/constants/mockPassportData';
import { generateCircuitInputsRegister } from '../../../common/src/utils/generateInputs';
import {
BigintToArray,
@@ -17,7 +17,7 @@ describe('Register - SHA1 WITH ECDSA', function () {
this.timeout(0);
let inputs: any;
let circuit: any;
let passportData = mockPassPortData_sha1_ecdsa;
let passportData = mockPassportData_sha1_ecdsa;
let attestation_id: string;
const attestation_name = 'E-PASSPORT';
const n_dsc = 43; // 43 * 6 = 258 > 254 Cirom field size

View File

@@ -27,7 +27,7 @@ describe('Register - SHA1 RSA', function () {
'./node_modules/@zk-kit/binary-merkle-root.circom/src',
'./node_modules/circomlib/circuits',
'./node_modules/dmpierre/sha1-circom/circuits',
'./node_modules/@zk-email/circuits ',
'./node_modules/@zk-email/circuits',
],
}
);

View File

@@ -55,17 +55,17 @@ describe('RSA Verifier', function () {
expect(isVerified).to.be.true;
});
it('should extract and log certificate information', async () => {
const csca_inputs = getCSCAInputs('0', dscCert_forge, cscaCert_forge, n, k, n, k, 2048, true);
const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha256', n, k);
// it('should extract and log certificate information', async () => {
// const csca_inputs = getCSCAInputs('0', dscCert_forge, cscaCert_forge, n, k, n, k, 2048, true);
// const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha256', n, k);
const inputs = {
message: tbsCertificateHashFormatted,
signature: csca_inputs.dsc_signature,
modulus: csca_inputs.csca_modulus,
};
const witness = await circuit.calculateWitness(inputs, true);
});
// const inputs = {
// message: tbsCertificateHashFormatted,
// signature: csca_inputs.inputs.dsc_signature,
// modulus: csca_inputs.inputs.dsc_modulus,
// };
// const witness = await circuit.calculateWitness(inputs, true);
// });
});
describe('SHA-1 certificates', () => {

View File

@@ -56,17 +56,17 @@ describe('RSAPSS Verifier', function () {
expect(isVerified).to.be.true;
});
it('should extract and log certificate information', async () => {
const csca_inputs = getCSCAInputs('0', dscCert_forge, cscaCert_forge, n, k, n, k, 960, true);
// const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha256', n, k);
// it('should extract and log certificate information', async () => {
// const csca_inputs = getCSCAInputs('0', dscCert_forge, cscaCert_forge, n, k, n, k, 960, true);
// // const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha256', n, k);
const inputs = {
raw_message: csca_inputs.raw_dsc_cert,
raw_message_padded_bytes: csca_inputs.raw_dsc_cert_padded_bytes,
signature: csca_inputs.dsc_signature,
modulus: csca_inputs.csca_modulus,
};
//const witness = await circuit.calculateWitness(inputs, true);
});
// const inputs = {
// raw_message: csca_inputs.inputs.raw_dsc_cert,
// raw_message_padded_bytes: csca_inputs.inputs.raw_dsc_cert_padded_bytes,
// signature: csca_inputs.inputs.dsc_signature,
// modulus: csca_inputs.inputs.dsc_modulus,
// };
// /const witness = await circuit.calculateWitness(inputs, true);
// });
});
});