mirror of
https://github.com/selfxyz/self.git
synced 2026-01-22 21:17:59 -05:00
adapt passport_majority.test.ts to new input generation
This commit is contained in:
@@ -1,723 +0,0 @@
|
||||
{
|
||||
"mrz": [
|
||||
"97",
|
||||
"91",
|
||||
"95",
|
||||
"31",
|
||||
"88",
|
||||
"80",
|
||||
"60",
|
||||
"70",
|
||||
"82",
|
||||
"65",
|
||||
"84",
|
||||
"65",
|
||||
"86",
|
||||
"69",
|
||||
"82",
|
||||
"78",
|
||||
"73",
|
||||
"69",
|
||||
"82",
|
||||
"60",
|
||||
"60",
|
||||
"70",
|
||||
"76",
|
||||
"79",
|
||||
"82",
|
||||
"69",
|
||||
"78",
|
||||
"84",
|
||||
"60",
|
||||
"72",
|
||||
"85",
|
||||
"71",
|
||||
"85",
|
||||
"69",
|
||||
"83",
|
||||
"60",
|
||||
"74",
|
||||
"69",
|
||||
"65",
|
||||
"78",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"49",
|
||||
"57",
|
||||
"72",
|
||||
"65",
|
||||
"51",
|
||||
"52",
|
||||
"56",
|
||||
"50",
|
||||
"56",
|
||||
"52",
|
||||
"70",
|
||||
"82",
|
||||
"65",
|
||||
"48",
|
||||
"48",
|
||||
"48",
|
||||
"55",
|
||||
"49",
|
||||
"57",
|
||||
"49",
|
||||
"77",
|
||||
"50",
|
||||
"57",
|
||||
"49",
|
||||
"50",
|
||||
"48",
|
||||
"57",
|
||||
"53",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"60",
|
||||
"48",
|
||||
"50"
|
||||
],
|
||||
"reveal_bitmap": [
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"dataHashes": [
|
||||
"48",
|
||||
"130",
|
||||
"1",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"0",
|
||||
"48",
|
||||
"11",
|
||||
"6",
|
||||
"9",
|
||||
"96",
|
||||
"134",
|
||||
"72",
|
||||
"1",
|
||||
"101",
|
||||
"3",
|
||||
"4",
|
||||
"2",
|
||||
"1",
|
||||
"48",
|
||||
"130",
|
||||
"1",
|
||||
"17",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"1",
|
||||
"4",
|
||||
"32",
|
||||
"99",
|
||||
"19",
|
||||
"179",
|
||||
"205",
|
||||
"55",
|
||||
"104",
|
||||
"45",
|
||||
"214",
|
||||
"133",
|
||||
"101",
|
||||
"233",
|
||||
"177",
|
||||
"130",
|
||||
"1",
|
||||
"37",
|
||||
"89",
|
||||
"125",
|
||||
"229",
|
||||
"139",
|
||||
"34",
|
||||
"132",
|
||||
"146",
|
||||
"28",
|
||||
"116",
|
||||
"248",
|
||||
"186",
|
||||
"63",
|
||||
"195",
|
||||
"96",
|
||||
"151",
|
||||
"26",
|
||||
"215",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"2",
|
||||
"4",
|
||||
"32",
|
||||
"63",
|
||||
"234",
|
||||
"106",
|
||||
"78",
|
||||
"31",
|
||||
"16",
|
||||
"114",
|
||||
"137",
|
||||
"237",
|
||||
"17",
|
||||
"92",
|
||||
"71",
|
||||
"134",
|
||||
"47",
|
||||
"62",
|
||||
"78",
|
||||
"189",
|
||||
"233",
|
||||
"201",
|
||||
"213",
|
||||
"53",
|
||||
"4",
|
||||
"47",
|
||||
"189",
|
||||
"201",
|
||||
"133",
|
||||
"6",
|
||||
"121",
|
||||
"34",
|
||||
"131",
|
||||
"64",
|
||||
"142",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"3",
|
||||
"4",
|
||||
"32",
|
||||
"136",
|
||||
"155",
|
||||
"87",
|
||||
"144",
|
||||
"121",
|
||||
"15",
|
||||
"152",
|
||||
"127",
|
||||
"85",
|
||||
"25",
|
||||
"154",
|
||||
"80",
|
||||
"20",
|
||||
"58",
|
||||
"51",
|
||||
"75",
|
||||
"193",
|
||||
"116",
|
||||
"234",
|
||||
"0",
|
||||
"60",
|
||||
"30",
|
||||
"29",
|
||||
"30",
|
||||
"183",
|
||||
"141",
|
||||
"72",
|
||||
"247",
|
||||
"255",
|
||||
"203",
|
||||
"100",
|
||||
"124",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"11",
|
||||
"4",
|
||||
"32",
|
||||
"0",
|
||||
"194",
|
||||
"104",
|
||||
"108",
|
||||
"237",
|
||||
"246",
|
||||
"97",
|
||||
"230",
|
||||
"116",
|
||||
"198",
|
||||
"69",
|
||||
"110",
|
||||
"26",
|
||||
"87",
|
||||
"17",
|
||||
"89",
|
||||
"110",
|
||||
"199",
|
||||
"108",
|
||||
"250",
|
||||
"36",
|
||||
"21",
|
||||
"39",
|
||||
"87",
|
||||
"110",
|
||||
"102",
|
||||
"250",
|
||||
"213",
|
||||
"174",
|
||||
"131",
|
||||
"171",
|
||||
"174",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"12",
|
||||
"4",
|
||||
"32",
|
||||
"190",
|
||||
"82",
|
||||
"180",
|
||||
"235",
|
||||
"222",
|
||||
"33",
|
||||
"79",
|
||||
"50",
|
||||
"152",
|
||||
"136",
|
||||
"142",
|
||||
"35",
|
||||
"116",
|
||||
"224",
|
||||
"6",
|
||||
"242",
|
||||
"156",
|
||||
"141",
|
||||
"128",
|
||||
"247",
|
||||
"10",
|
||||
"61",
|
||||
"98",
|
||||
"86",
|
||||
"248",
|
||||
"45",
|
||||
"207",
|
||||
"210",
|
||||
"90",
|
||||
"232",
|
||||
"175",
|
||||
"38",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"13",
|
||||
"4",
|
||||
"32",
|
||||
"91",
|
||||
"222",
|
||||
"210",
|
||||
"193",
|
||||
"63",
|
||||
"222",
|
||||
"104",
|
||||
"82",
|
||||
"36",
|
||||
"41",
|
||||
"138",
|
||||
"253",
|
||||
"70",
|
||||
"15",
|
||||
"148",
|
||||
"208",
|
||||
"156",
|
||||
"45",
|
||||
"105",
|
||||
"171",
|
||||
"241",
|
||||
"195",
|
||||
"185",
|
||||
"43",
|
||||
"217",
|
||||
"162",
|
||||
"146",
|
||||
"201",
|
||||
"222",
|
||||
"89",
|
||||
"238",
|
||||
"38",
|
||||
"48",
|
||||
"37",
|
||||
"2",
|
||||
"1",
|
||||
"14",
|
||||
"4",
|
||||
"32",
|
||||
"76",
|
||||
"123",
|
||||
"216",
|
||||
"13",
|
||||
"52",
|
||||
"227",
|
||||
"72",
|
||||
"245",
|
||||
"59",
|
||||
"193",
|
||||
"238",
|
||||
"166",
|
||||
"103",
|
||||
"49",
|
||||
"24",
|
||||
"164",
|
||||
"171",
|
||||
"188",
|
||||
"194",
|
||||
"197",
|
||||
"156",
|
||||
"187",
|
||||
"249",
|
||||
"28",
|
||||
"198",
|
||||
"95",
|
||||
"69",
|
||||
"15",
|
||||
"182",
|
||||
"56",
|
||||
"54",
|
||||
"38",
|
||||
"128",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"9",
|
||||
"72"
|
||||
],
|
||||
"datahashes_padded_length": "320",
|
||||
"eContentBytes": [
|
||||
"49",
|
||||
"102",
|
||||
"48",
|
||||
"21",
|
||||
"6",
|
||||
"9",
|
||||
"42",
|
||||
"134",
|
||||
"72",
|
||||
"134",
|
||||
"247",
|
||||
"13",
|
||||
"1",
|
||||
"9",
|
||||
"3",
|
||||
"49",
|
||||
"8",
|
||||
"6",
|
||||
"6",
|
||||
"103",
|
||||
"129",
|
||||
"8",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"48",
|
||||
"28",
|
||||
"6",
|
||||
"9",
|
||||
"42",
|
||||
"134",
|
||||
"72",
|
||||
"134",
|
||||
"247",
|
||||
"13",
|
||||
"1",
|
||||
"9",
|
||||
"5",
|
||||
"49",
|
||||
"15",
|
||||
"23",
|
||||
"13",
|
||||
"49",
|
||||
"57",
|
||||
"49",
|
||||
"50",
|
||||
"49",
|
||||
"54",
|
||||
"49",
|
||||
"55",
|
||||
"50",
|
||||
"50",
|
||||
"51",
|
||||
"56",
|
||||
"90",
|
||||
"48",
|
||||
"47",
|
||||
"6",
|
||||
"9",
|
||||
"42",
|
||||
"134",
|
||||
"72",
|
||||
"134",
|
||||
"247",
|
||||
"13",
|
||||
"1",
|
||||
"9",
|
||||
"4",
|
||||
"49",
|
||||
"34",
|
||||
"4",
|
||||
"32",
|
||||
"176",
|
||||
"96",
|
||||
"59",
|
||||
"213",
|
||||
"131",
|
||||
"82",
|
||||
"89",
|
||||
"248",
|
||||
"105",
|
||||
"125",
|
||||
"37",
|
||||
"177",
|
||||
"158",
|
||||
"162",
|
||||
"137",
|
||||
"43",
|
||||
"13",
|
||||
"39",
|
||||
"115",
|
||||
"6",
|
||||
"59",
|
||||
"229",
|
||||
"81",
|
||||
"110",
|
||||
"49",
|
||||
"75",
|
||||
"255",
|
||||
"184",
|
||||
"155",
|
||||
"73",
|
||||
"116",
|
||||
"86"
|
||||
],
|
||||
"signature": [
|
||||
"1004979219314799894",
|
||||
"6361443755252600907",
|
||||
"6439012883494616023",
|
||||
"9400879716815088139",
|
||||
"17551897985575934811",
|
||||
"11779273958797828281",
|
||||
"2536315921873401485",
|
||||
"3748173260178203981",
|
||||
"12475215309213288577",
|
||||
"6281117468118442715",
|
||||
"1336292932993922350",
|
||||
"14238156234566069988",
|
||||
"11985045093510507012",
|
||||
"3585865343992378960",
|
||||
"16170829868787473084",
|
||||
"17039645001628184779",
|
||||
"486540501180074772",
|
||||
"5061439412388381188",
|
||||
"12478821212163933993",
|
||||
"7430448406248319432",
|
||||
"746345521572597865",
|
||||
"5002454658692185142",
|
||||
"3715069341922830389",
|
||||
"11010599232161942094",
|
||||
"1577500614971981868",
|
||||
"13656226284809645063",
|
||||
"3918261659477120323",
|
||||
"5578832687955645075",
|
||||
"3416933977282345392",
|
||||
"15829829506526117610",
|
||||
"17465616637242519010",
|
||||
"6519177967447716150"
|
||||
],
|
||||
"signatureAlgorithm": "1",
|
||||
"pubkey": [
|
||||
"9539992759301679521",
|
||||
"1652651398804391575",
|
||||
"7756096264856639170",
|
||||
"15028348881266521487",
|
||||
"13451582891670014060",
|
||||
"11697656644529425980",
|
||||
"14590137142310897374",
|
||||
"1172377360308996086",
|
||||
"6389592621616098288",
|
||||
"6767780215543232436",
|
||||
"11347756978427069433",
|
||||
"2593119277386338350",
|
||||
"18385617576997885505",
|
||||
"14960211320702750252",
|
||||
"8706817324429498800",
|
||||
"15168543370367053559",
|
||||
"8708916123725550363",
|
||||
"18006178692029805686",
|
||||
"6398208271038376723",
|
||||
"15000821494077560096",
|
||||
"17674982305626887153",
|
||||
"2867958270953137726",
|
||||
"9287774520059158342",
|
||||
"9813100051910281130",
|
||||
"13494313215150203208",
|
||||
"7792741716144106392",
|
||||
"6553490305289731807",
|
||||
"32268224696386820",
|
||||
"15737886769048580611",
|
||||
"669518601007982974",
|
||||
"11424760966478363403",
|
||||
"16073833083611347461"
|
||||
],
|
||||
"pathIndices": [
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"siblings": [
|
||||
"20516282398390866580647417962347415258712802604212003365416596890852644939364",
|
||||
"20547289806543281108128197867250295423223489766069952889766689677695750842294",
|
||||
"17092860852967512812593771487649838995106203215624858397482169733546970246117",
|
||||
"19141872343555753276227561835732941623954902346285308564941039231845690663515",
|
||||
"2888260764701592030713638283446165050628606750519377550369633789586724212406",
|
||||
"17037943129534065359096662792322618985598809624384219749636863003643326502177",
|
||||
"21260541151470016589788332273091943678373855676584683193443363340566713593750",
|
||||
"9681119423869145671286918102040570804786474221694907866875171055859965502010",
|
||||
"3999714159260652982057321310481110903729446356195536109316994934664982988519",
|
||||
"14359042263488593594514913785064471775842285148703143594475594381078274944550",
|
||||
"10696856845043652409316424831381338144209147199074363427177722046972515079299",
|
||||
"2796323689030312622891330190155708704921773618732461037692992858528069077360",
|
||||
"1379184643939692456020535864077563679018059205165852146212742699309755722087",
|
||||
"17834317267514482863629341626611816587254867008433493508231639322166589549456",
|
||||
"1473918712602583605383280948484316645101117513102582419100942131704211814519",
|
||||
"15819538789928229930262697811477882737253464456578333862691129291651619515538"
|
||||
],
|
||||
"root": "4080578225172475068086778061870548445929343471785864518431540330127324371840",
|
||||
"address": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8"
|
||||
}
|
||||
@@ -32,7 +32,6 @@ describe('Circuit tests', function () {
|
||||
|
||||
// This adds the pubkey of the passportData to the registry even if it's not there for testing purposes.
|
||||
// Comment when testing with real passport data
|
||||
|
||||
tree.insert(getLeaf({
|
||||
signatureAlgorithm: passportData.signatureAlgorithm,
|
||||
issuer: 'C = TS, O = Government of Syldavia, OU = Ministry of tests, CN = CSCA-TEST',
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import chai, { assert, expect } from 'chai'
|
||||
import path from "path";
|
||||
import { getPassportData } from "../../common/src/utils/passportData";
|
||||
import { hash, toUnsignedByte, arraysAreEqual, bytesToBigDecimal, formatMrz, splitToWords } from '../../common/src/utils/utils'
|
||||
import { MAX_DATAHASHES_LEN, attributeToPosition } from '../../common/src/constants/constants'
|
||||
import { getCurrentDateYYMMDD } from '../../common/src/utils/utils';
|
||||
import { sha256Pad } from '@zk-email/helpers'; // Ensure this import is added
|
||||
import { TREE_DEPTH } from '../../common/src/constants/constants'
|
||||
import { generateCircuitInputs } from '../../common/src/utils/generateInputs';
|
||||
import { getLeaf } from '../../common/src/utils/pubkeyTree';
|
||||
import { IMT } from '@zk-kit/imt';
|
||||
import { poseidon2 } from 'poseidon-lite';
|
||||
import fs from 'fs';
|
||||
const wasm_tester = require("circom_tester").wasm;
|
||||
|
||||
describe.only("start testing of proof_of_passport_majority.circom", function () {
|
||||
@@ -13,7 +15,6 @@ describe.only("start testing of proof_of_passport_majority.circom", function ()
|
||||
let inputs: any;
|
||||
let circuit: any;
|
||||
let w: any;
|
||||
let current_date: any;
|
||||
let majority: any = [49, 56];
|
||||
|
||||
before(async () => {
|
||||
@@ -23,41 +24,29 @@ describe.only("start testing of proof_of_passport_majority.circom", function ()
|
||||
);
|
||||
const passportData = getPassportData();
|
||||
|
||||
const formattedMrz = formatMrz(passportData.mrz);
|
||||
|
||||
const concatenatedDataHashesHashDigest = hash(passportData.dataGroupHashes);
|
||||
assert(
|
||||
arraysAreEqual(passportData.eContent.slice(72, 72 + 33), concatenatedDataHashesHashDigest),
|
||||
'concatenatedDataHashesHashDigest is at the right place in passportData.eContent'
|
||||
)
|
||||
|
||||
const serializedTree = JSON.parse(fs.readFileSync("../common/pubkeys/serialized_tree.json") as unknown as string)
|
||||
const tree = new IMT(poseidon2, TREE_DEPTH, 0, 2)
|
||||
tree.setNodes(serializedTree)
|
||||
|
||||
// This adds the pubkey of the passportData to the registry even if it's not there for testing purposes.
|
||||
// Comment when testing with real passport data
|
||||
tree.insert(getLeaf({
|
||||
signatureAlgorithm: passportData.signatureAlgorithm,
|
||||
issuer: 'C = TS, O = Government of Syldavia, OU = Ministry of tests, CN = CSCA-TEST',
|
||||
modulus: passportData.pubKey.modulus,
|
||||
exponent: passportData.pubKey.exponent
|
||||
}).toString())
|
||||
|
||||
const reveal_bitmap = Array(90).fill('1');
|
||||
const [messagePadded, messagePaddedLen] = sha256Pad(
|
||||
new Uint8Array(passportData.dataGroupHashes),
|
||||
MAX_DATAHASHES_LEN
|
||||
const address = "0x70997970c51812dc3a010c7d01b50e0d17dc79c8";
|
||||
|
||||
inputs = generateCircuitInputs(
|
||||
passportData,
|
||||
tree,
|
||||
reveal_bitmap,
|
||||
address
|
||||
);
|
||||
|
||||
current_date = getCurrentDateYYMMDD();
|
||||
inputs = {
|
||||
mrz: formattedMrz.map(byte => String(byte)),
|
||||
reveal_bitmap: reveal_bitmap.map(byte => String(byte)),
|
||||
dataHashes: Array.from(messagePadded).map((x) => x.toString()), // Use the padded data hashes
|
||||
datahashes_padded_length: messagePaddedLen.toString(), // Include the padded length if needed
|
||||
eContentBytes: passportData.eContent.map(toUnsignedByte).map(byte => String(byte)),
|
||||
pubkey: splitToWords(
|
||||
BigInt(passportData.pubKey.modulus),
|
||||
BigInt(64),
|
||||
BigInt(32)
|
||||
),
|
||||
signature: splitToWords(
|
||||
BigInt(bytesToBigDecimal(passportData.encryptedDigest)),
|
||||
BigInt(64),
|
||||
BigInt(32)
|
||||
),
|
||||
address: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", // sample address
|
||||
current_date: current_date,
|
||||
majority: majority.map(byte => String(byte))
|
||||
}
|
||||
|
||||
w = await circuit.calculateWitness(inputs);
|
||||
|
||||
});
|
||||
@@ -70,7 +59,7 @@ describe.only("start testing of proof_of_passport_majority.circom", function ()
|
||||
await circuit.checkConstraints(w);
|
||||
});
|
||||
|
||||
it("verify reveal_packed outputs for major", async function () {
|
||||
it("verify reveal_packed outputs for majority", async function () {
|
||||
const outputs = await circuit.getOutput(w, ["reveal_packed[3]"]);
|
||||
const unpackedReveals = unpackRevealPacked(outputs);
|
||||
const expectedReveals = generateExpectedReveals(inputs, majority);
|
||||
|
||||
Reference in New Issue
Block a user