mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
refactor circuits repo, clean circuits tests, implement new certificates scripts, fix all tests from circuits repo
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
pragma circom 2.1.5;
|
||||
|
||||
include "circomlib/circuits/bitify.circom";
|
||||
include "circomlib/circuits/poseidon.circom";
|
||||
include "circomlib/circuits/comparators.circom";
|
||||
include "@zk-email/circuits/lib/sha.circom";
|
||||
include "@zk-email/circuits/lib/rsa.circom";
|
||||
include "binary-merkle-root.circom";
|
||||
include "./utils/splitBytesToWords.circom";
|
||||
include "./utils/splitSignalsToWords.circom";
|
||||
include "./utils/leafHasher.circom";
|
||||
include "./utils/leafHasher2.circom";
|
||||
|
||||
template DSC(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) {
|
||||
signal input raw_dsc_cert[max_cert_bytes];
|
||||
signal input raw_dsc_cert_padded_bytes;
|
||||
signal input csca_modulus[k_csca];
|
||||
signal input dsc_signature[k_csca];
|
||||
signal input dsc_modulus[k_dsc];
|
||||
signal input start_index;
|
||||
signal input secret;
|
||||
|
||||
signal input merkle_root;
|
||||
signal input path[nLevels];
|
||||
signal input siblings[nLevels];
|
||||
|
||||
signal output blinded_dsc_commitment;
|
||||
|
||||
// verify the leaf
|
||||
// component leafHasher = LeafHasher(k_csca);
|
||||
// leafHasher.in <== csca_modulus;
|
||||
// signal leaf <== leafHasher.out;
|
||||
component leafHasher2 = LeafHasher2(n_csca,k_csca);
|
||||
leafHasher2.in <== csca_modulus;
|
||||
signal leaf <== leafHasher2.out;
|
||||
|
||||
|
||||
signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
|
||||
merkle_root === computed_merkle_root;
|
||||
|
||||
// variables verification
|
||||
assert(max_cert_bytes % 64 == 0);
|
||||
assert(n_csca * k_csca > max_cert_bytes);
|
||||
assert(n_csca <= (255 \ 2));
|
||||
|
||||
// hash raw TBS certificate
|
||||
signal sha[256] <== Sha256Bytes(max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes);
|
||||
// component bit2num = Bits2Num(256);
|
||||
// bit2num.in <== sha;
|
||||
// signal shaBigint <== bit2num.out;
|
||||
component splitSignalsToWords = SplitSignalsToWords(1,256, n_csca, k_csca);
|
||||
component splitSignalsToWords2 = SplitSignalsToWords(1,256, n_csca, k_csca);
|
||||
for (var i = 0; i < 256; i++) {
|
||||
splitSignalsToWords.in[i] <== sha[255 - i];
|
||||
splitSignalsToWords2.in[i] <== sha[i];
|
||||
}
|
||||
|
||||
var msg_len = (256+n_csca)\n_csca;
|
||||
component base_msg[msg_len];
|
||||
for (var i = 0; i < msg_len; i++) {
|
||||
base_msg[i] = Bits2Num(n_csca);
|
||||
}
|
||||
for (var i = 0; i < 256; i++) {
|
||||
base_msg[i\n_csca].in[i%n_csca] <== sha[255 - i];
|
||||
}
|
||||
for (var i = 256; i < n_csca*msg_len; i++) {
|
||||
base_msg[i\n_csca].in[i%n_csca] <== 0;
|
||||
}
|
||||
|
||||
// verify RSA dsc_signature
|
||||
component rsa = RSAVerifier65537(n_csca, k_csca);
|
||||
for (var i = 0; i < msg_len; i++) {
|
||||
rsa.message[i] <== base_msg[i].out;
|
||||
log("rsa.message[i]: ",i, base_msg[i].out);
|
||||
}
|
||||
for (var i = msg_len; i < k_csca; i++) {
|
||||
rsa.message[i] <== 0;
|
||||
log("rsa.message[i]: ",i, rsa.message[i]);
|
||||
}
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
log("splitSignalsToWords.out[i]: ",i, splitSignalsToWords.out[i]);
|
||||
log("splitSignalsToWords2.out[i]: ",i, splitSignalsToWords2.out[i]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
rsa.modulus[i] <== csca_modulus[i];
|
||||
}
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
rsa.signature[i] <== dsc_signature[i];
|
||||
}
|
||||
|
||||
// verify DSC csca_modulus
|
||||
component shiftLeft = VarShiftLeft(max_cert_bytes, dsc_mod_len);
|
||||
shiftLeft.in <== raw_dsc_cert;
|
||||
shiftLeft.shift <== start_index;
|
||||
component spbt_1 = SplitBytesToWords(dsc_mod_len, n_dsc, k_dsc);
|
||||
spbt_1.in <== shiftLeft.out;
|
||||
for (var i = 0; i < k_dsc; i++) {
|
||||
dsc_modulus[i] === spbt_1.out[i];
|
||||
}
|
||||
// generate blinded commitment
|
||||
component spbt_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
spbt_2.in <== dsc_modulus;
|
||||
component poseidon = Poseidon(10);
|
||||
poseidon.inputs[0] <== secret;
|
||||
for (var i = 0; i < 9; i++) {
|
||||
poseidon.inputs[i+1] <== spbt_2.out[i];
|
||||
}
|
||||
blinded_dsc_commitment <== poseidon.out;
|
||||
}
|
||||
|
||||
@@ -40,22 +40,16 @@ template DSC_SHA1_RSA(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len,
|
||||
|
||||
// hash raw TBS certificate
|
||||
signal sha[160] <== Sha1Bytes(max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes);
|
||||
component splitSignalsToWords = SplitSignalsToWords(1,160, n_csca, k_csca);
|
||||
component bits2Num = Bits2Num(160);
|
||||
component sstw_1 = SplitSignalsToWords(1,160, n_csca, k_csca);
|
||||
for (var i = 0; i < 160; i++) {
|
||||
splitSignalsToWords.in[i] <== sha[159 - i];
|
||||
bits2Num.in[i] <== sha[159 - i];
|
||||
sstw_1.in[i] <== sha[159 - i];
|
||||
}
|
||||
|
||||
//verify RSA dsc_signature
|
||||
component rsa = RSAVerify65537(n_csca, k_csca);
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
rsa.base_message[i] <== splitSignalsToWords.out[i];
|
||||
}
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
rsa.base_message[i] <== sstw_1.out[i];
|
||||
rsa.modulus[i] <== csca_modulus[i];
|
||||
}
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
rsa.signature[i] <== dsc_signature[i];
|
||||
}
|
||||
|
||||
@@ -69,12 +63,12 @@ template DSC_SHA1_RSA(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len,
|
||||
dsc_modulus[i] === spbt_1.out[i];
|
||||
}
|
||||
// generate blinded commitment
|
||||
component spbt_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
spbt_2.in <== dsc_modulus;
|
||||
component sstw_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
sstw_2.in <== dsc_modulus;
|
||||
component poseidon = Poseidon(10);
|
||||
poseidon.inputs[0] <== secret;
|
||||
for (var i = 0; i < 9; i++) {
|
||||
poseidon.inputs[i+1] <== spbt_2.out[i];
|
||||
poseidon.inputs[i+1] <== sstw_2.out[i];
|
||||
}
|
||||
blinded_dsc_commitment <== poseidon.out;
|
||||
}
|
||||
|
||||
@@ -41,22 +41,17 @@ template DSC_SHA256_RSA(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_le
|
||||
|
||||
// hash raw TBS certificate
|
||||
signal sha[256] <== Sha256Bytes(max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes);
|
||||
component splitSignalsToWords = SplitSignalsToWords(1,256, n_csca, k_csca);
|
||||
component shaBigint = Bits2Num(256);
|
||||
shaBigint.in <== sha;
|
||||
component sstw_1 = SplitSignalsToWords(1,256, n_csca, k_csca);
|
||||
for (var i = 0; i < 256; i++) {
|
||||
splitSignalsToWords.in[i] <== sha[255 - i];
|
||||
sstw_1.in[i] <== sha[255 - i];
|
||||
}
|
||||
log("shaofrawtbs", shaBigint.out);
|
||||
|
||||
// verify RSA dsc_signature
|
||||
component rsa = RSAVerifier65537(n_csca, k_csca);
|
||||
for (var i = 0; i < k_csca; i++) {
|
||||
log(splitSignalsToWords.out[i]);
|
||||
rsa.message[i] <== splitSignalsToWords.out[i];
|
||||
rsa.message[i] <== sstw_1.out[i];
|
||||
rsa.modulus[i] <== csca_modulus[i];
|
||||
rsa.signature[i] <== dsc_signature[i];
|
||||
|
||||
}
|
||||
|
||||
// verify DSC csca_modulus
|
||||
@@ -69,12 +64,12 @@ template DSC_SHA256_RSA(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_le
|
||||
dsc_modulus[i] === spbt_1.out[i];
|
||||
}
|
||||
// generate blinded commitment
|
||||
component spbt_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
spbt_2.in <== dsc_modulus;
|
||||
component sstw_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
sstw_2.in <== dsc_modulus;
|
||||
component poseidon = Poseidon(10);
|
||||
poseidon.inputs[0] <== secret;
|
||||
for (var i = 0; i < 9; i++) {
|
||||
poseidon.inputs[i+1] <== spbt_2.out[i];
|
||||
poseidon.inputs[i+1] <== sstw_2.out[i];
|
||||
}
|
||||
blinded_dsc_commitment <== poseidon.out;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ include "../utils/RSASSAPSS_padded.circom";
|
||||
include "../utils/leafHasher.circom";
|
||||
|
||||
|
||||
template DSC(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) {
|
||||
template DSC_SHA256_RSAPSS(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) {
|
||||
signal input raw_dsc_cert[max_cert_bytes];
|
||||
signal input raw_dsc_cert_padded_bytes;
|
||||
signal input csca_modulus[k_csca];
|
||||
@@ -61,12 +61,12 @@ template DSC(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels
|
||||
dsc_modulus[i] === spbt_1.out[i];
|
||||
}
|
||||
// generate blinded commitment
|
||||
component spbt = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
spbt.in <== dsc_modulus;
|
||||
component sstw_1 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9);
|
||||
sstw_1.in <== dsc_modulus;
|
||||
component poseidon = Poseidon(10);
|
||||
poseidon.inputs[0] <== secret;
|
||||
for (var i = 0; i < 9; i++) {
|
||||
poseidon.inputs[i+1] <== spbt.out[i];
|
||||
poseidon.inputs[i+1] <== sstw_1.out[i];
|
||||
}
|
||||
blinded_dsc_commitment <== poseidon.out;
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ pragma circom 2.1.6;
|
||||
|
||||
include "../../dsc/dsc_sha1_rsa.circom";
|
||||
|
||||
component main { public [ merkle_root ] } = DSC_SHA1_RSA(1664,121 ,17 ,121, 17, 256, 12);
|
||||
component main { public [ merkle_root ] } = DSC_SHA1_RSA(960,121 ,17 ,121, 17, 256, 12);
|
||||
@@ -2,4 +2,4 @@ pragma circom 2.1.6;
|
||||
|
||||
include "../../dsc/dsc_sha256_rsa.circom";
|
||||
|
||||
component main { public [ merkle_root ] } = DSC_SHA256_RSA(1664,64 ,32 ,64, 32, 256, 12);
|
||||
component main { public [ merkle_root ] } = DSC_SHA256_RSA(960,121 ,17 ,121, 17, 256, 12);
|
||||
@@ -2,4 +2,4 @@ pragma circom 2.1.6;
|
||||
|
||||
include "../../dsc/dsc_sha256_rsapss.circom";
|
||||
|
||||
component main { public [ merkle_root ] } = DSC(1664,64 ,32 ,64, 32, 256, 12);
|
||||
component main { public [ merkle_root ] } = DSC_SHA256_RSAPSS(960,64 ,32 ,64, 32, 256, 12);
|
||||
@@ -1,6 +1,6 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "../utils/isOlderThan.circom";
|
||||
include "../../utils/isOlderThan.circom";
|
||||
|
||||
template isOlderThan_tester() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "../utils/IsValid.circom";
|
||||
include "../../utils/IsValid.circom";
|
||||
|
||||
template IsValid_tester() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "../utils/leafHasher.circom";
|
||||
include "../../utils/leafHasher.circom";
|
||||
|
||||
component main = LeafHasher(32);
|
||||
@@ -1,5 +1,3 @@
|
||||
include "@zk-email/circuits/lib/rsa.circom";
|
||||
|
||||
|
||||
|
||||
component main = RSAVerifier65537(64, 32);
|
||||
@@ -14,17 +14,11 @@ template LeafHasher (n,k) {
|
||||
hash[i] = Poseidon(16);
|
||||
}
|
||||
for (var i = 0; i < 64 ; i ++){
|
||||
// if (i < k ){
|
||||
hash[ i % 4 ].inputs[ i \ 4 ] <== splitSignalsToWords.out[i];
|
||||
// }
|
||||
// else{
|
||||
// hash[ i % 4 ].inputs[ i \ 4 ] <== 0;
|
||||
// }
|
||||
}
|
||||
component finalHash = Poseidon(4);
|
||||
for (var i = 0 ; i < 4 ; i++){
|
||||
finalHash.inputs[i] <== hash[i].out;
|
||||
}
|
||||
log(finalHash.out);
|
||||
out <== finalHash.out;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "yarn ts-mocha test/**/*.test.ts --exit",
|
||||
"test": "yarn ts-mocha tests/**/*.test.ts --exit",
|
||||
"install-circuits": "cd ../common && yarn && cd ../circuits && yarn"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { assert, expect } from 'chai'
|
||||
import path from "path";
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { mockPassportData_sha256WithRSAEncryption_65537 } from '../../../common/src/utils/mockPassportData';
|
||||
import { mockPassportData_sha256_rsa_65537 } from '../../../common/src/constants/mockPassportData';
|
||||
import { formatMrz, packBytes } from '../../../common/src/utils/utils';
|
||||
import { attributeToPosition, COMMITMENT_TREE_DEPTH } from "../../../common/src/constants/constants";
|
||||
import { poseidon1, poseidon2, poseidon6 } from "poseidon-lite";
|
||||
@@ -10,17 +10,18 @@ import { getLeaf } from '../../../common/src/utils/pubkeyTree';
|
||||
import { generateCircuitInputsDisclose } from '../../../common/src/utils/generateInputs';
|
||||
import { unpackReveal } from '../../../common/src/utils/revealBitmap';
|
||||
|
||||
describe("start testing disclose.circom", function () {
|
||||
describe("Disclose", function () {
|
||||
this.timeout(0);
|
||||
let inputs: any;
|
||||
let circuit: any;
|
||||
let w: any;
|
||||
let passportData = mockPassportData_sha256WithRSAEncryption_65537;
|
||||
let passportData = mockPassportData_sha256_rsa_65537;
|
||||
let attestation_id: string;
|
||||
let tree: any;
|
||||
const attestation_name = "E-PASSPORT";
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(path.join(__dirname, "../circuits/disclose.circom"),
|
||||
circuit = await wasm_tester(path.join(__dirname, "../../circuits/disclose/disclose.circom"),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
@@ -31,7 +32,6 @@ describe("start testing disclose.circom", function () {
|
||||
);
|
||||
|
||||
const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
const attestation_name = "E-PASSPORT";
|
||||
attestation_id = poseidon1([
|
||||
BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))
|
||||
]).toString();
|
||||
@@ -82,8 +82,8 @@ describe("start testing disclose.circom", function () {
|
||||
const nullifier_js = poseidon2([inputs.secret, inputs.scope]).toString();
|
||||
const nullifier_circom = (await circuit.getOutput(w, ["nullifier"])).nullifier;
|
||||
|
||||
console.log("nullifier_circom", nullifier_circom);
|
||||
console.log("nullifier_js", nullifier_js);
|
||||
//console.log("nullifier_circom", nullifier_circom);
|
||||
//console.log("nullifier_js", nullifier_js);
|
||||
expect(nullifier_circom).to.equal(nullifier_js);
|
||||
});
|
||||
|
||||
@@ -174,7 +174,7 @@ describe("start testing disclose.circom", function () {
|
||||
const revealedData_packed = await circuit.getOutput(w, ["revealedData_packed[3]"])
|
||||
|
||||
const reveal_unpacked = unpackReveal(revealedData_packed);
|
||||
console.log("reveal_unpacked", reveal_unpacked)
|
||||
//console.log("reveal_unpacked", reveal_unpacked)
|
||||
|
||||
expect(reveal_unpacked[88]).to.equal("1");
|
||||
expect(reveal_unpacked[89]).to.equal("8");
|
||||
@@ -194,7 +194,7 @@ describe("start testing disclose.circom", function () {
|
||||
const revealedData_packed = await circuit.getOutput(w, ["revealedData_packed[3]"])
|
||||
|
||||
const reveal_unpacked = unpackReveal(revealedData_packed);
|
||||
console.log("reveal_unpacked", reveal_unpacked)
|
||||
//console.log("reveal_unpacked", reveal_unpacked)
|
||||
|
||||
expect(reveal_unpacked[88]).to.equal("\x00");
|
||||
expect(reveal_unpacked[89]).to.equal("\x00");
|
||||
|
||||
@@ -3,30 +3,24 @@ import fs from 'fs'
|
||||
const forge = require('node-forge');
|
||||
import path from 'path';
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { splitToWords } from '../../../common/src/utils/utils';
|
||||
import { sha256Pad } from '../../../common/src/utils/shaPad';
|
||||
import { findStartIndex, getCSCAInputs } from '../../../common/src/utils/csca';
|
||||
import { getCSCAInputs } from '../../../common/src/utils/csca';
|
||||
import { mock_dsc_sha1_rsa_2048, mock_csca_sha1_rsa_2048 } from '../../../common/src/constants/mockCertificates';
|
||||
|
||||
describe('DSC chain certificate', function () {
|
||||
describe('DSC chain certificate - SHA1 RSA', function () {
|
||||
this.timeout(0); // Disable timeout
|
||||
let circuit;
|
||||
const n_dsc = 121;
|
||||
const k_dsc = 17;
|
||||
const n_csca = 121;
|
||||
const k_csca = 17;
|
||||
const max_cert_bytes = 1664;
|
||||
const dsc = fs.readFileSync('../common/src/mock_certificates/sha1_rsa_2048/mock_dsc.crt', 'utf8');
|
||||
const csca = fs.readFileSync('../common/src/mock_certificates/sha1_rsa_2048/mock_csca.crt', 'utf8');
|
||||
const dscCert = forge.pki.certificateFromPem(dsc);
|
||||
const cscaCert = forge.pki.certificateFromPem(csca);
|
||||
|
||||
const max_cert_bytes = 960;
|
||||
const dscCert = forge.pki.certificateFromPem(mock_dsc_sha1_rsa_2048);
|
||||
const cscaCert = forge.pki.certificateFromPem(mock_csca_sha1_rsa_2048);
|
||||
|
||||
const inputs = getCSCAInputs(BigInt(0).toString(), dscCert, cscaCert, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, true);
|
||||
// console.log("inputs:", inputs);
|
||||
|
||||
before(async () => {
|
||||
const circuitPath = path.resolve(__dirname, '../../circuits/tests/dsc/dsc_sha1_rsa_2048.circom');
|
||||
console.log("Circuit path:", circuitPath);
|
||||
circuit = await wasm_tester(
|
||||
circuitPath,
|
||||
{
|
||||
@@ -40,42 +34,24 @@ describe('DSC chain certificate', function () {
|
||||
});
|
||||
|
||||
it('verify dsc has been signed by the csca', () => {
|
||||
// Extract the TBS (To Be Signed) portion of the DSC
|
||||
const dscCert = forge.pki.certificateFromPem(dsc);
|
||||
const tbsCertAsn1 = forge.pki.getTBSCertificate(dscCert);
|
||||
const tbsCertDer = forge.asn1.toDer(tbsCertAsn1).getBytes();
|
||||
|
||||
// Calculate SHA1 hash of the TBS
|
||||
const md = forge.md.sha1.create();
|
||||
md.update(tbsCertDer);
|
||||
const tbsHash = md.digest().getBytes();
|
||||
// convert the tbsHash to a bigint
|
||||
const tbsHashHex = forge.util.bytesToHex(tbsHash);
|
||||
const tbsHashBigInt = BigInt('0x' + tbsHashHex);
|
||||
console.log("tbsHashBigInt:", tbsHashBigInt); // 1257666055290860319966758211557505011700834915784n
|
||||
// 1257666055290860319966758211557505011700834915784
|
||||
|
||||
// Extract the signature from the DSC
|
||||
const signature = dscCert.signature;
|
||||
|
||||
// Get the public key from the CSCA certificate
|
||||
const cscaCert = forge.pki.certificateFromPem(csca);
|
||||
const cscaCert = forge.pki.certificateFromPem(mock_csca_sha1_rsa_2048);
|
||||
const publicKey = cscaCert.publicKey;
|
||||
|
||||
// Verify the signature
|
||||
const verified = publicKey.verify(tbsHash, signature);
|
||||
|
||||
expect(verified).to.be.true;
|
||||
})
|
||||
|
||||
// it('should compile and load the circuit', () => {
|
||||
// expect(circuit).to.not.be.undefined;
|
||||
// })
|
||||
it('should compile and load the circuit', () => {
|
||||
expect(circuit).to.not.be.undefined;
|
||||
})
|
||||
|
||||
it('should compute the correct output', async () => {
|
||||
console.log("Inputs:", inputs);
|
||||
const witness = await circuit.calculateWitness(inputs, true);
|
||||
console.log(witness);
|
||||
})
|
||||
|
||||
})
|
||||
@@ -3,30 +3,24 @@ import fs from 'fs'
|
||||
const forge = require('node-forge');
|
||||
import path from 'path';
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { findStartIndex, getCSCAInputs } from '../../../common/src/utils/csca';
|
||||
import { getCSCAInputs } from '../../../common/src/utils/csca';
|
||||
import { mock_dsc_sha256_rsa_2048, mock_csca_sha256_rsa_2048 } from '../../../common/src/constants/mockCertificates';
|
||||
|
||||
describe('DSC chain certificate', function () {
|
||||
describe('DSC chain certificate - SHA256 RSA', function () {
|
||||
this.timeout(0); // Disable timeout
|
||||
let circuit;
|
||||
const n_dsc = 64;
|
||||
const k_dsc = 32;
|
||||
const n_csca = 64;
|
||||
const k_csca = 32;
|
||||
const max_cert_bytes = 1664;
|
||||
const dsc = fs.readFileSync('../common/src/mock_certificates/sha256_rsa_2048/mock_dsc.crt', 'utf8');
|
||||
const csca = fs.readFileSync('../common/src/mock_certificates/sha256_rsa_2048/mock_csca.crt', 'utf8');
|
||||
const dscCert = forge.pki.certificateFromPem(dsc);
|
||||
const cscaCert = forge.pki.certificateFromPem(csca);
|
||||
|
||||
const n_dsc = 121;
|
||||
const k_dsc = 17;
|
||||
const n_csca = 121;
|
||||
const k_csca = 17;
|
||||
const max_cert_bytes = 960;
|
||||
const dscCert = forge.pki.certificateFromPem(mock_dsc_sha256_rsa_2048);
|
||||
const cscaCert = forge.pki.certificateFromPem(mock_csca_sha256_rsa_2048);
|
||||
|
||||
const inputs = getCSCAInputs(BigInt(0).toString(), dscCert, cscaCert, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, true);
|
||||
console.log("inputs:", inputs);
|
||||
|
||||
console.log("Current directory:", __dirname);
|
||||
|
||||
before(async () => {
|
||||
const circuitPath = path.resolve(__dirname, '../../circuits/tests/dsc/dsc_sha256_rsa_2048.circom');
|
||||
console.log("Circuit path:", circuitPath);
|
||||
circuit = await wasm_tester(
|
||||
circuitPath,
|
||||
{
|
||||
@@ -39,14 +33,24 @@ describe('DSC chain certificate', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('verify dsc has been signed by the csca', () => {
|
||||
const tbsCertAsn1 = forge.pki.getTBSCertificate(dscCert);
|
||||
const tbsCertDer = forge.asn1.toDer(tbsCertAsn1).getBytes();
|
||||
const md = forge.md.sha256.create();
|
||||
md.update(tbsCertDer);
|
||||
const tbsHash = md.digest().getBytes();
|
||||
const signature = dscCert.signature;
|
||||
const publicKey = cscaCert.publicKey;
|
||||
const verified = publicKey.verify(tbsHash, signature);
|
||||
expect(verified).to.be.true;
|
||||
})
|
||||
|
||||
it('should compile and load the circuit', () => {
|
||||
expect(circuit).to.not.be.undefined;
|
||||
})
|
||||
|
||||
it('should compute the correct output', async () => {
|
||||
console.log("Inputs:", inputs);
|
||||
const witness = await circuit.calculateWitness(inputs, true);
|
||||
console.log(witness);
|
||||
})
|
||||
|
||||
})
|
||||
@@ -1,29 +1,27 @@
|
||||
import { assert, expect } from 'chai'
|
||||
import fs from 'fs'
|
||||
import forge from 'node-forge';
|
||||
const forge = require('node-forge');
|
||||
import path from 'path';
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { getCSCAInputs } from '../../../common/src/utils/csca';
|
||||
import crypto from 'crypto';
|
||||
import { mock_dsc_sha256_rsapss_2048, mock_csca_sha256_rsapss_2048 } from '../../../common/src/constants/mockCertificates';
|
||||
|
||||
describe('DSC chain certificate', function () {
|
||||
describe('DSC chain certificate - SHA256 RSA-PSS', function () {
|
||||
this.timeout(0); // Disable timeout
|
||||
let circuit;
|
||||
const n_dsc = 64;
|
||||
const k_dsc = 32;
|
||||
const n_csca = 64;
|
||||
const k_csca = 32;
|
||||
const max_cert_bytes = 1664;
|
||||
const dsc_path = path.join(__dirname, '../../../common/src/mock_certificates/sha256_rsapss_2048/mock_dsc.pem');
|
||||
const csca_path = path.join(__dirname, '../../../common/src/mock_certificates/sha256_rsapss_2048/mock_csca.pem');
|
||||
const dscCert = forge.pki.certificateFromPem(fs.readFileSync(dsc_path, 'utf8'));
|
||||
const cscaCert = forge.pki.certificateFromPem(fs.readFileSync(csca_path, 'utf8'));
|
||||
const max_cert_bytes = 960;
|
||||
const dscCert = forge.pki.certificateFromPem(mock_dsc_sha256_rsapss_2048);
|
||||
const cscaCert = forge.pki.certificateFromPem(mock_csca_sha256_rsapss_2048);
|
||||
|
||||
const inputs = getCSCAInputs(BigInt(0).toString(), dscCert, cscaCert, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, true);
|
||||
console.log("inputs:", inputs);
|
||||
|
||||
before(async () => {
|
||||
const circuitPath = path.resolve(__dirname, '../../circuits/tests/dsc/dsc_sha256_rsapss_2048.circom');
|
||||
console.log("Circuit path:", circuitPath);
|
||||
circuit = await wasm_tester(
|
||||
circuitPath,
|
||||
{
|
||||
@@ -35,15 +33,55 @@ describe('DSC chain certificate', function () {
|
||||
}
|
||||
);
|
||||
});
|
||||
// TODO: Verify the certificate chain in ts too.
|
||||
// it('verify dsc has been signed by the csca using RSA-PSS', () => {
|
||||
// // Extract TBS (To Be Signed) certificate
|
||||
// const tbsCertAsn1 = forge.pki.getTBSCertificate(dscCert);
|
||||
// const tbsCertDer = forge.asn1.toDer(tbsCertAsn1).getBytes();
|
||||
|
||||
// // Create SHA-256 hash of the TBS certificate
|
||||
// const tbsHash = crypto.createHash('sha256').update(Buffer.from(tbsCertDer, 'binary')).digest();
|
||||
|
||||
// // Extract signature from DSC certificate
|
||||
// const signature = Buffer.from(dscCert.signature, 'binary');
|
||||
|
||||
// // Get public key from CSCA certificate
|
||||
// const publicKeyPem = forge.pki.publicKeyToPem(cscaCert.publicKey);
|
||||
// const publicKey = crypto.createPublicKey(publicKeyPem);
|
||||
|
||||
// // Verify signature
|
||||
// const pssOptions = {
|
||||
// saltLength: 32,
|
||||
// mgf1Hash: 'sha256'
|
||||
// };
|
||||
|
||||
// try {
|
||||
// const verifier = crypto.createVerify('RSA-SHA256');
|
||||
// verifier.update(tbsHash);
|
||||
// const isValid = verifier.verify({
|
||||
// key: publicKey,
|
||||
// padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
||||
// saltLength: pssOptions.saltLength
|
||||
// }, signature);
|
||||
|
||||
// console.log('TBS Hash:', tbsHash.toString('hex'));
|
||||
// console.log('Signature:', signature.toString('hex'));
|
||||
// console.log('Public Key:', publicKeyPem);
|
||||
// console.log('Verification result:', isValid);
|
||||
|
||||
// expect(isValid).to.be.true;
|
||||
// } catch (error) {
|
||||
// console.error('Verification error:', error);
|
||||
// throw error;
|
||||
// }
|
||||
// })
|
||||
|
||||
it('should compile and load the circuit', () => {
|
||||
expect(circuit).to.not.be.undefined;
|
||||
})
|
||||
|
||||
it('should compute the correct output', async () => {
|
||||
console.log("Inputs:", inputs);
|
||||
const witness = await circuit.calculateWitness(inputs, true);
|
||||
console.log(witness);
|
||||
})
|
||||
|
||||
})
|
||||
@@ -3,22 +3,24 @@ import { assert, expect } from 'chai'
|
||||
import path from "path";
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { poseidon1, poseidon6 } from "poseidon-lite";
|
||||
import { mockPassportData_sha1WithRSAEncryption_65537 } from "../../../common/src/utils/mockPassportData";
|
||||
import { mockPassportData_sha1_rsa_65537 } from "../../../common/src/constants/mockPassportData";
|
||||
import { generateCircuitInputsRegister } from '../../../common/src/utils/generateInputs';
|
||||
import { getLeaf } from '../../../common/src/utils/pubkeyTree';
|
||||
import { packBytes } from '../../../common/src/utils/utils';
|
||||
import { k_csca, k_dsc, n_csca, n_dsc } from '../../../common/src/constants/constants';
|
||||
|
||||
describe("Circuits - sha1WithRSAEncryption_65537 Register flow", function () {
|
||||
describe("Register - SHA1 RSA", function () {
|
||||
this.timeout(0);
|
||||
let inputs: any;
|
||||
let circuit: any;
|
||||
let passportData = mockPassportData_sha1WithRSAEncryption_65537;
|
||||
let passportData = mockPassportData_sha1_rsa_65537;
|
||||
let attestation_id: string;
|
||||
const attestation_name = "E-PASSPORT";
|
||||
const n_dsc = 121;
|
||||
const k_dsc = 17;
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "../circuits/register_sha1WithRSAEncryption_65537.circom"),
|
||||
path.join(__dirname, "../../circuits/register/register_sha1WithRSAEncryption_65537.circom"),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
@@ -30,16 +32,15 @@ describe("Circuits - sha1WithRSAEncryption_65537 Register flow", function () {
|
||||
);
|
||||
|
||||
const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
console.log("secret", secret);
|
||||
const dscSecret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
|
||||
const attestation_name = "E-PASSPORT";
|
||||
attestation_id = poseidon1([
|
||||
BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))
|
||||
]).toString();
|
||||
|
||||
inputs = generateCircuitInputsRegister(
|
||||
secret,
|
||||
BigInt(0).toString(),
|
||||
dscSecret,
|
||||
attestation_id,
|
||||
passportData,
|
||||
n_dsc,
|
||||
@@ -55,9 +56,13 @@ describe("Circuits - sha1WithRSAEncryption_65537 Register flow", function () {
|
||||
const w = await circuit.calculateWitness(inputs);
|
||||
await circuit.checkConstraints(w);
|
||||
|
||||
console.log("nullifier", (await circuit.getOutput(w, ["nullifier"])).nullifier);
|
||||
|
||||
const nullifier = (await circuit.getOutput(w, ["nullifier"])).nullifier;
|
||||
console.log("\x1b[34m%s\x1b[0m", "nullifier", nullifier);
|
||||
const commitment_circom = (await circuit.getOutput(w, ["commitment"])).commitment;
|
||||
console.log("\x1b[34m%s\x1b[0m", "commitment", commitment_circom);
|
||||
const blinded_dsc_commitment = (await circuit.getOutput(w, ["blinded_dsc_commitment"])).blinded_dsc_commitment;
|
||||
console.log("\x1b[34m%s\x1b[0m", "blinded_dsc_commitment", blinded_dsc_commitment);
|
||||
|
||||
const mrz_bytes = packBytes(inputs.mrz);
|
||||
const commitment_bytes = poseidon6([
|
||||
inputs.secret[0],
|
||||
@@ -72,8 +77,8 @@ describe("Circuits - sha1WithRSAEncryption_65537 Register flow", function () {
|
||||
mrz_bytes[2]
|
||||
]);
|
||||
const commitment_js = commitment_bytes.toString();
|
||||
console.log('commitment_js', commitment_js)
|
||||
console.log('commitment_circom', commitment_circom)
|
||||
//console.log('commitment_js', commitment_js)
|
||||
//console.log('commitment_circom', commitment_circom)
|
||||
expect(commitment_circom).to.be.equal(commitment_js);
|
||||
});
|
||||
|
||||
@@ -116,17 +121,4 @@ describe("Circuits - sha1WithRSAEncryption_65537 Register flow", function () {
|
||||
}
|
||||
});
|
||||
|
||||
// it("should fail to calculate witness with invalid merkle root", async function () {
|
||||
// try {
|
||||
// const invalidInputs = {
|
||||
// ...inputs,
|
||||
// merkle_root: inputs.merkle_root.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
|
||||
// }
|
||||
// await circuit.calculateWitness(invalidInputs);
|
||||
// expect.fail("Expected an error but none was thrown.");
|
||||
// } catch (error) {
|
||||
// expect(error.message).to.include("Assert Failed");
|
||||
// }
|
||||
// });
|
||||
|
||||
});
|
||||
@@ -3,23 +3,24 @@ import { assert, expect } from 'chai'
|
||||
import path from "path";
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { poseidon1, poseidon6 } from "poseidon-lite";
|
||||
import { mockPassportData_sha256WithRSAEncryption_65537 } from "../../../common/src/utils/mockPassportData";
|
||||
import { mockPassportData_sha256_rsa_65537 } from "../../../common/src/constants/mockPassportData";
|
||||
import { generateCircuitInputsRegister } from '../../../common/src/utils/generateInputs';
|
||||
import { getLeaf } from '../../../common/src/utils/pubkeyTree';
|
||||
import { packBytes } from '../../../common/src/utils/utils';
|
||||
|
||||
describe("Circuits - sha256WithRSAEncryption_65537 Register flow", function () {
|
||||
describe("Register - SHA256 RSA", function () {
|
||||
this.timeout(0);
|
||||
let inputs: any;
|
||||
let circuit: any;
|
||||
let passportData = mockPassportData_sha256WithRSAEncryption_65537;
|
||||
let passportData = mockPassportData_sha256_rsa_65537;
|
||||
let attestation_id: string;
|
||||
const attestation_name = "E-PASSPORT";
|
||||
const n_dsc = 121;
|
||||
const k_dsc = 17;
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "../circuits/register_sha256WithRSAEncryption_65537.circom"),
|
||||
path.join(__dirname, "../../circuits/register/register_sha256WithRSAEncryption_65537.circom"),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
@@ -29,23 +30,18 @@ describe("Circuits - sha256WithRSAEncryption_65537 Register flow", function () {
|
||||
},
|
||||
);
|
||||
|
||||
//const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
const secret = BigInt(0).toString();
|
||||
console.log("secret", secret);
|
||||
|
||||
const attestation_name = "E-PASSPORT";
|
||||
const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
const dscSecret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
attestation_id = poseidon1([
|
||||
BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))
|
||||
]).toString();
|
||||
|
||||
inputs = generateCircuitInputsRegister(
|
||||
secret,
|
||||
BigInt(0).toString(),
|
||||
dscSecret,
|
||||
attestation_id,
|
||||
passportData,
|
||||
n_dsc,
|
||||
k_dsc,
|
||||
[mockPassportData_sha256WithRSAEncryption_65537]
|
||||
k_dsc
|
||||
);
|
||||
});
|
||||
|
||||
@@ -57,12 +53,12 @@ describe("Circuits - sha256WithRSAEncryption_65537 Register flow", function () {
|
||||
const w = await circuit.calculateWitness(inputs);
|
||||
await circuit.checkConstraints(w);
|
||||
|
||||
console.log("nullifier", (await circuit.getOutput(w, ["nullifier"])).nullifier);
|
||||
|
||||
const nullifier = (await circuit.getOutput(w, ["nullifier"])).nullifier;
|
||||
console.log("\x1b[34m%s\x1b[0m", "nullifier", nullifier);
|
||||
const commitment_circom = (await circuit.getOutput(w, ["commitment"])).commitment;
|
||||
console.log("commitment_circom", commitment_circom)
|
||||
console.log("\x1b[34m%s\x1b[0m", "commitment", commitment_circom);
|
||||
const blinded_dsc_commitment = (await circuit.getOutput(w, ["blinded_dsc_commitment"])).blinded_dsc_commitment;
|
||||
console.log("blinded_dsc_commitment", blinded_dsc_commitment)
|
||||
console.log("\x1b[34m%s\x1b[0m", "blinded_dsc_commitment", blinded_dsc_commitment);
|
||||
|
||||
const mrz_bytes = packBytes(inputs.mrz);
|
||||
const commitment_bytes = poseidon6([
|
||||
@@ -78,8 +74,8 @@ describe("Circuits - sha256WithRSAEncryption_65537 Register flow", function () {
|
||||
mrz_bytes[2]
|
||||
]);
|
||||
const commitment_js = commitment_bytes.toString();
|
||||
console.log('commitment_js', commitment_js)
|
||||
console.log('commitment_circom', commitment_circom)
|
||||
//console.log('commitment_js', commitment_js)
|
||||
//console.log('commitment_circom', commitment_circom)
|
||||
expect(commitment_circom).to.be.equal(commitment_js);
|
||||
});
|
||||
|
||||
@@ -122,17 +118,4 @@ describe("Circuits - sha256WithRSAEncryption_65537 Register flow", function () {
|
||||
}
|
||||
});
|
||||
|
||||
// it("should fail to calculate witness with invalid merkle root", async function () {
|
||||
// try {
|
||||
// const invalidInputs = {
|
||||
// ...inputs,
|
||||
// merkle_root: inputs.merkle_root.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
|
||||
// }
|
||||
// await circuit.calculateWitness(invalidInputs);
|
||||
// expect.fail("Expected an error but none was thrown.");
|
||||
// } catch (error) {
|
||||
// expect(error.message).to.include("Assert Failed");
|
||||
// }
|
||||
// });
|
||||
|
||||
});
|
||||
@@ -3,22 +3,24 @@ import { assert, expect } from 'chai'
|
||||
import path from "path";
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import { poseidon1, poseidon6 } from "poseidon-lite";
|
||||
import { mockPassportData_sha256WithRSASSAPSS_65537 } from "../../../common/src/utils/mockPassportData";
|
||||
import { mockPassportData_sha256_rsapss_65537 } from "../../../common/src/constants/mockPassportData";
|
||||
import { generateCircuitInputsRegister } from '../../../common/src/utils/generateInputs';
|
||||
import { getLeaf } from '../../../common/src/utils/pubkeyTree';
|
||||
import { packBytes } from '../../../common/src/utils/utils';
|
||||
import { k_dsc, n_dsc } from '../../../common/src/constants/constants';
|
||||
|
||||
describe("Proof of Passport - Circuits - RSASSAPSS", function () {
|
||||
describe("Register - SHA256 RSASSAPSS", function () {
|
||||
this.timeout(0);
|
||||
let inputs: any;
|
||||
let circuit: any;
|
||||
let passportData = mockPassportData_sha256WithRSASSAPSS_65537;
|
||||
let passportData = mockPassportData_sha256_rsapss_65537;
|
||||
const attestation_name = "E-PASSPORT";
|
||||
let attestation_id: string;
|
||||
const n_dsc = 64;
|
||||
const k_dsc = 32;
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "../circuits/register_sha256WithRSASSAPSS_65537.circom"),
|
||||
path.join(__dirname, "../../circuits/register/register_sha256WithRSASSAPSS_65537.circom"),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
@@ -30,21 +32,18 @@ describe("Proof of Passport - Circuits - RSASSAPSS", function () {
|
||||
);
|
||||
|
||||
const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
console.log("secret", secret);
|
||||
|
||||
const attestation_name = "E-PASSPORT";
|
||||
const dscSecret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
|
||||
attestation_id = poseidon1([
|
||||
BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))
|
||||
]).toString();
|
||||
|
||||
inputs = generateCircuitInputsRegister(
|
||||
secret,
|
||||
BigInt(0).toString(),
|
||||
dscSecret,
|
||||
attestation_id,
|
||||
passportData,
|
||||
64,
|
||||
32,
|
||||
[passportData],
|
||||
n_dsc,
|
||||
k_dsc
|
||||
);
|
||||
|
||||
});
|
||||
@@ -59,9 +58,12 @@ describe("Proof of Passport - Circuits - RSASSAPSS", function () {
|
||||
console.timeEnd('calculateWitness')
|
||||
await circuit.checkConstraints(w);
|
||||
|
||||
console.log("nullifier", (await circuit.getOutput(w, ["nullifier"])).nullifier);
|
||||
|
||||
const nullifier = (await circuit.getOutput(w, ["nullifier"])).nullifier;
|
||||
console.log("\x1b[34m%s\x1b[0m", "nullifier", nullifier);
|
||||
const commitment_circom = (await circuit.getOutput(w, ["commitment"])).commitment;
|
||||
console.log("\x1b[34m%s\x1b[0m", "commitment", commitment_circom);
|
||||
const blinded_dsc_commitment = (await circuit.getOutput(w, ["blinded_dsc_commitment"])).blinded_dsc_commitment;
|
||||
console.log("\x1b[34m%s\x1b[0m", "blinded_dsc_commitment", blinded_dsc_commitment);
|
||||
|
||||
const mrz_bytes = packBytes(inputs.mrz);
|
||||
const commitment_bytes = poseidon6([
|
||||
@@ -77,8 +79,8 @@ describe("Proof of Passport - Circuits - RSASSAPSS", function () {
|
||||
mrz_bytes[2]
|
||||
]);
|
||||
const commitment_js = commitment_bytes.toString();
|
||||
console.log('commitment_js', commitment_js)
|
||||
console.log('commitment_circom', commitment_circom)
|
||||
//console.log('commitment_js', commitment_js)
|
||||
//console.log('commitment_circom', commitment_circom)
|
||||
expect(commitment_circom).to.be.equal(commitment_js);
|
||||
});
|
||||
|
||||
@@ -121,17 +123,4 @@ describe("Proof of Passport - Circuits - RSASSAPSS", function () {
|
||||
}
|
||||
});
|
||||
|
||||
it("should fail to calculate witness with invalid merkle root", async function () {
|
||||
try {
|
||||
const invalidInputs = {
|
||||
...inputs,
|
||||
merkle_root: inputs.merkle_root.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
|
||||
}
|
||||
await circuit.calculateWitness(invalidInputs);
|
||||
expect.fail("Expected an error but none was thrown.");
|
||||
} catch (error) {
|
||||
expect(error.message).to.include("Assert Failed");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe('DateIsLessChecker Circuit Test', function () {
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, '../circuits/tests/isOlderThan_tester.circom'),
|
||||
path.join(__dirname, '../../circuits/tests/utils/isOlderThan_tester.circom'),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('DateIsLessChecker Circuit Test', function () {
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, '../circuits/tests/isValid_tester.circom'),
|
||||
path.join(__dirname, '../../circuits/tests/utils/isValid_tester.circom'),
|
||||
{
|
||||
include: [
|
||||
"node_modules",
|
||||
|
||||
@@ -1,35 +1,27 @@
|
||||
import { expect } from 'chai';
|
||||
import fs from 'fs';
|
||||
import { X509Certificate, createPublicKey, KeyObject, createHash } from 'crypto';
|
||||
import { splitToWords } from '../../common/src/utils/utils';
|
||||
import { X509Certificate } from 'crypto';
|
||||
import path from 'path';
|
||||
import { derToBytes, getCSCAInputs, getTBSHash } from '../../common/src/utils/csca';
|
||||
import { getCSCAInputs, getTBSHash } from '../../../common/src/utils/csca';
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
import forge from 'node-forge';
|
||||
|
||||
function loadCertificates(dscCertPath: string, cscaCertPath: string) {
|
||||
const dscCert = new X509Certificate(fs.readFileSync(dscCertPath));
|
||||
const cscaCert = new X509Certificate(fs.readFileSync(cscaCertPath));
|
||||
const dscCert_forge = forge.pki.certificateFromPem(fs.readFileSync(dscCertPath).toString());
|
||||
const cscaCert_forge = forge.pki.certificateFromPem(fs.readFileSync(cscaCertPath).toString());
|
||||
import { mock_dsc_sha256_rsa_2048, mock_csca_sha256_rsa_2048, mock_dsc_sha1_rsa_2048, mock_csca_sha1_rsa_2048 } from '../../../common/src/constants/mockCertificates';
|
||||
|
||||
function loadCertificates(dscCertContent: string, cscaCertContent: string) {
|
||||
const dscCert = new X509Certificate(dscCertContent);
|
||||
const cscaCert = new X509Certificate(cscaCertContent);
|
||||
const dscCert_forge = forge.pki.certificateFromPem(dscCertContent);
|
||||
const cscaCert_forge = forge.pki.certificateFromPem(cscaCertContent);
|
||||
|
||||
return { dscCert, cscaCert, dscCert_forge, cscaCert_forge };
|
||||
}
|
||||
|
||||
|
||||
describe('DSC chain certificate', function () {
|
||||
describe('RSA Verifier', function () {
|
||||
this.timeout(0);
|
||||
|
||||
const dsc_sha256 = '../common/src/mock_certificates/sha256_rsa_2048/mock_dsc.crt';
|
||||
const csca_sha256 = '../common/src/mock_certificates/sha256_rsa_2048/mock_csca.crt';
|
||||
const dsc_sha1 = '../common/src/mock_certificates/sha1_rsa_2048/mock_dsc.crt';
|
||||
const csca_sha1 = '../common/src/mock_certificates/sha1_rsa_2048/mock_csca.crt';
|
||||
let circuit;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
const { dscCert, cscaCert } = loadCertificates(dsc_sha256, csca_sha256);
|
||||
const circuitPath = path.resolve(__dirname, '../../circuits/circuits/tests/rsa_verifier.circom');
|
||||
console.log("Circuit path:", circuitPath);
|
||||
const circuitPath = path.resolve(__dirname, '../../circuits/tests/utils/rsa_verifier.circom');
|
||||
circuit = await wasm_tester(
|
||||
circuitPath,
|
||||
{
|
||||
@@ -48,7 +40,7 @@ describe('DSC chain certificate', function () {
|
||||
});
|
||||
|
||||
describe('SHA-256 certificates', async () => {
|
||||
const { dscCert, cscaCert, dscCert_forge, cscaCert_forge } = loadCertificates(dsc_sha256, csca_sha256);
|
||||
const { dscCert, cscaCert, dscCert_forge, cscaCert_forge } = loadCertificates(mock_dsc_sha256_rsa_2048, mock_csca_sha256_rsa_2048);
|
||||
|
||||
it('should verify DSC has been signed by the CSCA', () => {
|
||||
const isVerified = dscCert.verify(cscaCert.publicKey);
|
||||
@@ -65,33 +57,31 @@ describe('DSC chain certificate', function () {
|
||||
"signature": csca_inputs.dsc_signature,
|
||||
"modulus": csca_inputs.csca_modulus
|
||||
}
|
||||
console.log("final inputs: ", inputs);
|
||||
const witness = await circuit.calculateWitness(inputs, true);
|
||||
console.log(witness);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SHA-1 certificates', () => {
|
||||
const { dscCert, cscaCert, dscCert_forge, cscaCert_forge } = loadCertificates(dsc_sha1, csca_sha1);
|
||||
const { dscCert, cscaCert, dscCert_forge, cscaCert_forge } = loadCertificates(mock_dsc_sha1_rsa_2048, mock_csca_sha1_rsa_2048);
|
||||
|
||||
it('should verify DSC has been signed by the CSCA', () => {
|
||||
const isVerified = dscCert.verify(cscaCert.publicKey);
|
||||
console.log(`SHA-1 DSC certificate verification result: ${isVerified}`);
|
||||
expect(isVerified).to.be.true;
|
||||
});
|
||||
/// TODO: Use SHA1RSA verifier circuit (won't work either case because of padding)
|
||||
// it('should extract and log certificate information', async () => {
|
||||
// const csca_inputs = getCSCAInputs("0", dscCert_forge, cscaCert_forge, 64, 32, 64, 32, 2048, true);
|
||||
// const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha1');
|
||||
|
||||
it('should extract and log certificate information', async () => {
|
||||
const csca_inputs = getCSCAInputs("0", dscCert_forge, cscaCert_forge, 64, 32, 64, 32, 2048, true);
|
||||
const tbsCertificateHashFormatted = getTBSHash(dscCert_forge, 'sha1');
|
||||
|
||||
const inputs = {
|
||||
"message": tbsCertificateHashFormatted,
|
||||
"signature": csca_inputs.dsc_signature,
|
||||
"modulus": csca_inputs.csca_modulus
|
||||
}
|
||||
console.log("final inputs: ", inputs);
|
||||
const witness = await circuit.calculateWitness(inputs, true);
|
||||
console.log(witness);
|
||||
});
|
||||
// const inputs = {
|
||||
// "message": tbsCertificateHashFormatted,
|
||||
// "signature": csca_inputs.dsc_signature,
|
||||
// "modulus": csca_inputs.csca_modulus
|
||||
// }
|
||||
// console.log("final inputs: ", inputs);
|
||||
// const witness = await circuit.calculateWitness(inputs, true);
|
||||
// console.log(witness);
|
||||
// });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user