mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
@@ -2,7 +2,7 @@ import { SignatureAlgorithm } from "../utils/types"
|
||||
|
||||
export const RELAYER_URL = "https://0pw5u65m3a.execute-api.eu-north-1.amazonaws.com/api-stage/mint"
|
||||
//export const COMMITMENT_TREE_TRACKER_URL = "https://app.proofofpassport.com/apiv2/download-merkle-tree"
|
||||
export const COMMITMENT_TREE_TRACKER_URL = "https://proofofpassport-merkle-tree.xyz/api/download-merkle-tree"
|
||||
export const COMMITMENT_TREE_TRACKER_URL = "https://proofofpassport-merkle-tree.xyz/api/merkle-tree/download"
|
||||
export const WEBSOCKET_URL = "https://proofofpassport-merkle-tree.xyz"
|
||||
export const PUBKEY_TREE_DEPTH = 16
|
||||
export const CSCA_TREE_DEPTH = 12
|
||||
@@ -13,7 +13,7 @@ export const MODAL_SERVER_ADDRESS = "https://zk-passport--dsc-prover-generate-ds
|
||||
|
||||
export const PASSPORT_ATTESTATION_NAME = "E-PASSPORT"
|
||||
// poseidon1([BigInt(Buffer.from(PASSPORT_ATTESTATION_NAME).readUIntBE(0, 6))]).toString();
|
||||
export const PASSPORT_ATTESTATION_ID = "8518753152044246090169372947057357973469996808638122125210848696986717482788"
|
||||
export const PASSPORT_ATTESTATION_ID = "1";//"8518753152044246090169372947057357973469996808638122125210848696986717482788"
|
||||
|
||||
export const CHAIN_NAME = "optimism"
|
||||
export const RPC_URL = "https://opt-mainnet.g.alchemy.com/v2/Mjj_SdklUaCdR6EPfVKXb7m6Pj5TjzWL"
|
||||
@@ -49,6 +49,13 @@ export const MAX_CERT_BYTES: Partial<Record<keyof typeof SignatureAlgorithmIndex
|
||||
export const ECDSA_K_LENGTH_FACTOR = 2;
|
||||
// possible values because of sha1 constaints: 192,320,384, 448, 576, 640
|
||||
|
||||
export const circuitNameFromMode = {
|
||||
prove_onchain: 'prove',
|
||||
prove_offchain: 'prove',
|
||||
register: 'prove',
|
||||
vc_and_disclose: 'vc_and_disclose',
|
||||
}
|
||||
|
||||
export enum SignatureAlgorithmIndex {
|
||||
rsa_65537_sha256_2048 = 1,
|
||||
rsa_65537_sha1_2048 = 3,
|
||||
@@ -337,6 +344,262 @@ export const countryCodes = {
|
||||
"ZMB": "Zambia",
|
||||
"ZWE": "Zimbabwe"
|
||||
}
|
||||
export function getCountryCode(countryName: string): string | string {
|
||||
const entries = Object.entries(countryCodes);
|
||||
const found = entries.find(([_, name]) => name.toLowerCase() === countryName.toLowerCase());
|
||||
return found ? found[0] : 'undefined';
|
||||
}
|
||||
export const countryNames = [
|
||||
"Afghanistan",
|
||||
"Aland Islands",
|
||||
"Albania",
|
||||
"Algeria",
|
||||
"American Samoa",
|
||||
"Andorra",
|
||||
"Angola",
|
||||
"Anguilla",
|
||||
"Antarctica",
|
||||
"Antigua and Barbuda",
|
||||
"Argentina",
|
||||
"Armenia",
|
||||
"Aruba",
|
||||
"Australia",
|
||||
"Austria",
|
||||
"Azerbaijan",
|
||||
"Bahamas",
|
||||
"Bahrain",
|
||||
"Bangladesh",
|
||||
"Barbados",
|
||||
"Belarus",
|
||||
"Belgium",
|
||||
"Belize",
|
||||
"Benin",
|
||||
"Bermuda",
|
||||
"Bhutan",
|
||||
"Bolivia (Plurinational State of)",
|
||||
"Bonaire, Sint Eustatius and Saba",
|
||||
"Bosnia and Herzegovina",
|
||||
"Botswana",
|
||||
"Bouvet Island",
|
||||
"Brazil",
|
||||
"British Indian Ocean Territory",
|
||||
"Brunei Darussalam",
|
||||
"Bulgaria",
|
||||
"Burkina Faso",
|
||||
"Burundi",
|
||||
"Cabo Verde",
|
||||
"Cambodia",
|
||||
"Cameroon",
|
||||
"Canada",
|
||||
"Cayman Islands",
|
||||
"Central African Republic",
|
||||
"Chad",
|
||||
"Chile",
|
||||
"China",
|
||||
"Christmas Island",
|
||||
"Cocos (Keeling) Islands",
|
||||
"Colombia",
|
||||
"Comoros",
|
||||
"Congo",
|
||||
"Congo, Democratic Republic of the",
|
||||
"Cook Islands",
|
||||
"Costa Rica",
|
||||
"Cote d'Ivoire",
|
||||
"Croatia",
|
||||
"Cuba",
|
||||
"Curacao",
|
||||
"Cyprus",
|
||||
"Czechia",
|
||||
"Denmark",
|
||||
"Djibouti",
|
||||
"Dominica",
|
||||
"Dominican Republic",
|
||||
"Ecuador",
|
||||
"Egypt",
|
||||
"El Salvador",
|
||||
"Equatorial Guinea",
|
||||
"Eritrea",
|
||||
"Estonia",
|
||||
"Eswatini",
|
||||
"Ethiopia",
|
||||
"Falkland Islands (Malvinas)",
|
||||
"Faroe Islands",
|
||||
"Fiji",
|
||||
"Finland",
|
||||
"France",
|
||||
"French Guiana",
|
||||
"French Polynesia",
|
||||
"French Southern Territories",
|
||||
"Gabon",
|
||||
"Gambia",
|
||||
"Georgia",
|
||||
"Germany",
|
||||
"Ghana",
|
||||
"Gibraltar",
|
||||
"Greece",
|
||||
"Greenland",
|
||||
"Grenada",
|
||||
"Guadeloupe",
|
||||
"Guam",
|
||||
"Guatemala",
|
||||
"Guernsey",
|
||||
"Guinea",
|
||||
"Guinea-Bissau",
|
||||
"Guyana",
|
||||
"Haiti",
|
||||
"Heard Island and McDonald Islands",
|
||||
"Holy See",
|
||||
"Honduras",
|
||||
"Hong Kong",
|
||||
"Hungary",
|
||||
"Iceland",
|
||||
"India",
|
||||
"Indonesia",
|
||||
"Iran (Islamic Republic of)",
|
||||
"Iraq",
|
||||
"Ireland",
|
||||
"Isle of Man",
|
||||
"Israel",
|
||||
"Italy",
|
||||
"Jamaica",
|
||||
"Japan",
|
||||
"Jersey",
|
||||
"Jordan",
|
||||
"Kazakhstan",
|
||||
"Kenya",
|
||||
"Kiribati",
|
||||
"Korea (Democratic People's Republic of)",
|
||||
"Korea, Republic of",
|
||||
"Kuwait",
|
||||
"Kyrgyzstan",
|
||||
"Lao People's Democratic Republic",
|
||||
"Latvia",
|
||||
"Lebanon",
|
||||
"Lesotho",
|
||||
"Liberia",
|
||||
"Libya",
|
||||
"Liechtenstein",
|
||||
"Lithuania",
|
||||
"Luxembourg",
|
||||
"Macao",
|
||||
"Madagascar",
|
||||
"Malawi",
|
||||
"Malaysia",
|
||||
"Maldives",
|
||||
"Mali",
|
||||
"Malta",
|
||||
"Marshall Islands",
|
||||
"Martinique",
|
||||
"Mauritania",
|
||||
"Mauritius",
|
||||
"Mayotte",
|
||||
"Mexico",
|
||||
"Micronesia (Federated States of)",
|
||||
"Moldova, Republic of",
|
||||
"Monaco",
|
||||
"Mongolia",
|
||||
"Montenegro",
|
||||
"Montserrat",
|
||||
"Morocco",
|
||||
"Mozambique",
|
||||
"Myanmar",
|
||||
"Namibia",
|
||||
"Nauru",
|
||||
"Nepal",
|
||||
"Netherlands",
|
||||
"New Caledonia",
|
||||
"New Zealand",
|
||||
"Nicaragua",
|
||||
"Niger",
|
||||
"Nigeria",
|
||||
"Niue",
|
||||
"Norfolk Island",
|
||||
"North Macedonia",
|
||||
"Northern Mariana Islands",
|
||||
"Norway",
|
||||
"Oman",
|
||||
"Pakistan",
|
||||
"Palau",
|
||||
"Palestine, State of",
|
||||
"Panama",
|
||||
"Papua New Guinea",
|
||||
"Paraguay",
|
||||
"Peru",
|
||||
"Philippines",
|
||||
"Pitcairn",
|
||||
"Poland",
|
||||
"Portugal",
|
||||
"Puerto Rico",
|
||||
"Qatar",
|
||||
"Reunion",
|
||||
"Romania",
|
||||
"Russian Federation",
|
||||
"Rwanda",
|
||||
"Saint Barthelemy",
|
||||
"Saint Helena, Ascension and Tristan da Cunha",
|
||||
"Saint Kitts and Nevis",
|
||||
"Saint Lucia",
|
||||
"Saint Martin (French part)",
|
||||
"Saint Pierre and Miquelon",
|
||||
"Saint Vincent and the Grenadines",
|
||||
"Samoa",
|
||||
"San Marino",
|
||||
"Sao Tome and Principe",
|
||||
"Saudi Arabia",
|
||||
"Senegal",
|
||||
"Serbia",
|
||||
"Seychelles",
|
||||
"Sierra Leone",
|
||||
"Singapore",
|
||||
"Sint Maarten (Dutch part)",
|
||||
"Slovakia",
|
||||
"Slovenia",
|
||||
"Solomon Islands",
|
||||
"Somalia",
|
||||
"South Africa",
|
||||
"South Georgia and the South Sandwich Islands",
|
||||
"South Sudan",
|
||||
"Spain",
|
||||
"Sri Lanka",
|
||||
"Sudan",
|
||||
"Suriname",
|
||||
"Svalbard and Jan Mayen",
|
||||
"Sweden",
|
||||
"Switzerland",
|
||||
"Syrian Arab Republic",
|
||||
"Taiwan, Province of China",
|
||||
"Tajikistan",
|
||||
"Tanzania, United Republic of",
|
||||
"Thailand",
|
||||
"Timor-Leste",
|
||||
"Togo",
|
||||
"Tokelau",
|
||||
"Tonga",
|
||||
"Trinidad and Tobago",
|
||||
"Tunisia",
|
||||
"Turkey",
|
||||
"Turkmenistan",
|
||||
"Turks and Caicos Islands",
|
||||
"Tuvalu",
|
||||
"Uganda",
|
||||
"Ukraine",
|
||||
"United Arab Emirates",
|
||||
"United Kingdom of Great Britain and Northern Ireland",
|
||||
"United States of America",
|
||||
"United States Minor Outlying Islands",
|
||||
"Uruguay",
|
||||
"Uzbekistan",
|
||||
"Vanuatu",
|
||||
"Venezuela (Bolivarian Republic of)",
|
||||
"Viet Nam",
|
||||
"Virgin Islands (British)",
|
||||
"Virgin Islands (U.S.)",
|
||||
"Wallis and Futuna",
|
||||
"Western Sahara",
|
||||
"Yemen",
|
||||
"Zambia",
|
||||
"Zimbabwe"
|
||||
] as const;
|
||||
|
||||
export const contribute_publicKey = `-----BEGIN RSA PUBLIC KEY-----
|
||||
MIICCgKCAgEAv/hm7FZZ2KBmaeDHmLoRwuWmCcNKT561RqbsW8ZuYSyPWJUldE9U
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const vkey_disclose = {
|
||||
export const vkey_vc_and_disclose = {
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128",
|
||||
"nPublic": 14,
|
||||
"nPublic": 20,
|
||||
"vk_alpha_1": [
|
||||
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
||||
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
||||
@@ -37,12 +37,12 @@ export const vkey_disclose = {
|
||||
],
|
||||
"vk_delta_2": [
|
||||
[
|
||||
"6942436740229168666595536581519256291593117600832247164924519038970269461046",
|
||||
"17557865657217054151399710026819127874171362865266657132072043760282335721027"
|
||||
"2285641925224838978222516003838691301522837942576149813249618262683607431978",
|
||||
"8933979452959246793652418502124635637608136544198967823461038471987929468463"
|
||||
],
|
||||
[
|
||||
"15629082942757783052734933529055204330846116501031658743204188522840567440030",
|
||||
"866803245463331646327183913175583329159450203348438102150009828684148559895"
|
||||
"16099512190238976912962671487125443206965718241797607052101309249042700281031",
|
||||
"13866973425260784693055729377971041037525083882024304009793262309055835677530"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
@@ -81,82 +81,112 @@ export const vkey_disclose = {
|
||||
],
|
||||
"IC": [
|
||||
[
|
||||
"10998553002727424987884583305349753345629818748955483305954960876370686844925",
|
||||
"18369020735737057562107768810182682586161750799521907185011795199521493953276",
|
||||
"17675992131793847472607582103290528032110944356332065253938771650575512637150",
|
||||
"3334529637547487349647542974294469269353530698716058653313633946852810587219",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"3870156317905136354369536369223776179854927352937539086581682263147147725326",
|
||||
"947908099816727525943796981035826395896386995128918341433720280874486019589",
|
||||
"4073040853156698088579125842860781690905988024237850240402200045640356184109",
|
||||
"4679018198189152660097843382950080652306538412548068412033586660232563193013",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"9619614659642762666110070745787072277198407288262286655564043642023793950605",
|
||||
"1444870940646607538213811271690623291794427513321591343855928143309974143815",
|
||||
"15776533017793451196514777082124337882856102873453705308829629571923075424417",
|
||||
"14232490066350175683786572931273695352468015232518411187366417165893912115230",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"10290556281387838061211784545032614883237381276187632418810139452226710406378",
|
||||
"12820288689147023950592422696432066467590193138126598372596214785570201388663",
|
||||
"1180945442359952286721463819274447148908421750703875389048309699338667338411",
|
||||
"6539452064449720183898998074274190026127754682197287334130838477279315254881",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"10044189939644279332588298610988772483187101321076758071894028734198440253205",
|
||||
"15016612240779620571490237444430121691511928826472608688773111463692886510804",
|
||||
"13806944210187274185057734594353372528156342424366258241133564778474054935868",
|
||||
"7800429229653987231645474546639647711164156063512193001130226490464812892063",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"6158786594227478832634691320618082224218218524296943509099128649963428556955",
|
||||
"2818896662082406397657145229256654653904841140122301210666395782176903475916",
|
||||
"5522822939351592924817275047393709421174176326835572758552827440001401610167",
|
||||
"11245123080087310106980015850199801755152167910673823675982721730905258212233",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"200295911748915977788397688942615122670319721182540082686195028815964792730",
|
||||
"16374098866162622474777608838325780437892472095191094825634065695603492498672",
|
||||
"5627481952482064829757269526369949776646066892934683965609154755505296555965",
|
||||
"4545484539969611530913200236731153733781933150464540998302850238315475023119",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"1001933084599581827076405562561115761770358156189382784432273793509010836288",
|
||||
"13618159500648302749264797924828312592779374840705268445533823753672345860949",
|
||||
"20423400711755442910136460433293470952040919967735945317336472158180565467951",
|
||||
"6378416884992747212393622109218662385874688399353342355554228954581250524736",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"12152127135355257668073159516593687751413730484411437719952408933610175077761",
|
||||
"15590965974244077225547659000022179448961631917634079092877797469009672737373",
|
||||
"4373305143599295486105733121446353133863889257489542032576171376300323541304",
|
||||
"4026684213449689055353486192784741961832172326825055022163307876785200324637",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"14643873766083688335082369233094018379987105460165787549629338089338629672719",
|
||||
"18976194036990056092890684065171543382286602242265347684324001010669281606450",
|
||||
"5068833407180337147676969453261920994101725947652623057924700035380226397907",
|
||||
"11087944526730366835444251823404529324958715143332979454630299083515861157072",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"4974359282562923295097396773583362835614429754286473873410152881834388935350",
|
||||
"2615967425575591157936435871031665935046196308487298765704452331348089292330",
|
||||
"21831082589187376499865612459731026493616836999924912561891098220429445525521",
|
||||
"10842131628581855605843884617846867779319917434679079988533026500378178602950",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"16489750714044704248135942822786071904168862423655325973193848507501139487825",
|
||||
"4644993658884496411511912365771411317040070112230395754480725062427812526601",
|
||||
"14267596758527912595273989225764996478640991994242422111486793250630191081468",
|
||||
"18694764448853871920117677375229746676709722363749986739355723996303104296068",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"11801682757910657983396995619983996921870874978799260563404809167285348391422",
|
||||
"19228652101325919244735412842681375925619382430642205708320466729501949572254",
|
||||
"10612001726856359227588948695393307655456532716872467807420271676133645773510",
|
||||
"1540081878138518609133189078681275557428892906987071405333678709982239141734",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"4495248066509783309072792039672520701419947625749866524660708846549914823847",
|
||||
"4585216314173588273427806971446529726371555267351812069737927114283850919560",
|
||||
"7645334938708591281146159611078021141015093576924464549682793344782173540643",
|
||||
"5041018151127409344023520612676035165867301524846720998477901879854547090576",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"18719866673490039760627957665040843673978402675108669037278157044178865894074",
|
||||
"11183065716352601580915387671262116390467334689778841393328736869598818253587",
|
||||
"8883975772061177470672187114470132395286660826025700056750575280427708604951",
|
||||
"8320685858262483078856712401649683261512346806365950058502541940795537677566",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"19770351503660034123641636433521671083703252249281883512457304565751018243912",
|
||||
"1942705439280745753504371271759370270294305194237531295574972095513458387941",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"15226311176844690062341353072910557091317547496535044902570312644662561307949",
|
||||
"19296708345054645579869153897992480989971014206920627404347102350029660305578",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"5436668919010108586842015267897845254611520180011711994231132539697114737868",
|
||||
"21034924479027562029885591632326051974733967422882023235118894616793689864649",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"17617503314542022213516716240700336131305032342072938364934850750624139958532",
|
||||
"7535025988359437238238236154472398858799932717035093350843709570356278900481",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"15079990665367846194463669410480448234210628628217480894032215566550223721508",
|
||||
"14422402677444824910876930195543885009950058186617851677855759748496927334854",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"15949464882252583714786988301769970813994683305898379568444041314948594948891",
|
||||
"10982667165993413891579207656117800635412428118849500079522502265949839258411",
|
||||
"1"
|
||||
]
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
export const vkey_prove_rsa_65537_sha256 = {
|
||||
"protocol": "groth16",
|
||||
@@ -1191,4 +1221,304 @@ export const vkey_prove_rsapss_65537_sha256 = {
|
||||
"1"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
export const vkey_dsc_rsa_65537_sha1 = {
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128",
|
||||
"nPublic": 2,
|
||||
"vk_alpha_1": [
|
||||
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
||||
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
||||
"1"
|
||||
],
|
||||
"vk_beta_2": [
|
||||
[
|
||||
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
||||
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
||||
],
|
||||
[
|
||||
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
||||
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_gamma_2": [
|
||||
[
|
||||
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
||||
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
||||
],
|
||||
[
|
||||
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
||||
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_delta_2": [
|
||||
[
|
||||
"13609834548161300582477853991526320293433640330539801500903753457627888495381",
|
||||
"8441806186745188372537460321981116999801031201583499966958826604947980830000"
|
||||
],
|
||||
[
|
||||
"8448384202753302962223109595229113261664582566011624155734783894938928271855",
|
||||
"14114983069796580083449425790812236094683577678022815810458824633453412210627"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_alphabeta_12": [
|
||||
[
|
||||
[
|
||||
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
||||
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
||||
],
|
||||
[
|
||||
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
||||
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
||||
],
|
||||
[
|
||||
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
||||
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
||||
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
||||
],
|
||||
[
|
||||
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
||||
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
||||
],
|
||||
[
|
||||
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
||||
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
||||
]
|
||||
]
|
||||
],
|
||||
"IC": [
|
||||
[
|
||||
"8080423910694661461576427977746141048179131345871564682235127365538915251175",
|
||||
"15077260046277123685110202133518064301144478802752095822556731494534324607918",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"16011015387972163546219334947336021918538394305813640145299036166236111586389",
|
||||
"19422172264639146231714658451804174650252945098828793769061895536286758622279",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"2543445962105990625291559091474595879940066015891597850114251320085420659626",
|
||||
"1917249161113849432608012443620967377861258824599427135619631874160142518773",
|
||||
"1"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
export const vkey_dsc_rsa_65537_sha256 = {
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128",
|
||||
"nPublic": 2,
|
||||
"vk_alpha_1": [
|
||||
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
||||
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
||||
"1"
|
||||
],
|
||||
"vk_beta_2": [
|
||||
[
|
||||
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
||||
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
||||
],
|
||||
[
|
||||
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
||||
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_gamma_2": [
|
||||
[
|
||||
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
||||
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
||||
],
|
||||
[
|
||||
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
||||
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_delta_2": [
|
||||
[
|
||||
"8403974525672515951605465754909425916978281298593354504437469807907113049853",
|
||||
"12233134836151850512596961158180983853133742935319340320561432564845137384819"
|
||||
],
|
||||
[
|
||||
"3209155548902127778431906050698597513646227271655778722256683596743569531044",
|
||||
"16830777068052670490128170305087202969267881418665601837992321846223880096264"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_alphabeta_12": [
|
||||
[
|
||||
[
|
||||
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
||||
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
||||
],
|
||||
[
|
||||
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
||||
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
||||
],
|
||||
[
|
||||
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
||||
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
||||
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
||||
],
|
||||
[
|
||||
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
||||
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
||||
],
|
||||
[
|
||||
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
||||
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
||||
]
|
||||
]
|
||||
],
|
||||
"IC": [
|
||||
[
|
||||
"16231288969314859968324689058413762096922845561563844884666690734569347763082",
|
||||
"5910239835236935696830364945179549816839705839711095023727334010208312533092",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"6260576084748320398294355533743833076081106851106584793995576172400792840042",
|
||||
"21319331746978162427565186170902229291674424766799571029877219503610111212711",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"16479555690731841331208639285970255252465816317199429107438320860232249030762",
|
||||
"3783712303962417058251692820237130203111118349896777989119917429903130718416",
|
||||
"1"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
export const vkey_dsc_rsapss_65537_sha256 = {
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128",
|
||||
"nPublic": 2,
|
||||
"vk_alpha_1": [
|
||||
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
||||
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
||||
"1"
|
||||
],
|
||||
"vk_beta_2": [
|
||||
[
|
||||
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
||||
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
||||
],
|
||||
[
|
||||
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
||||
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_gamma_2": [
|
||||
[
|
||||
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
||||
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
||||
],
|
||||
[
|
||||
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
||||
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_delta_2": [
|
||||
[
|
||||
"6017862818859039949402494358517294962820240623943684783826304039772640083873",
|
||||
"11178871189289476718066796914086694937261254534191355355208715473729459679073"
|
||||
],
|
||||
[
|
||||
"18289536515878615632378439677874060078266723798016506833131127246101859022607",
|
||||
"8005285279181761514246985809032780535330313241768111893953981130952718939039"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_alphabeta_12": [
|
||||
[
|
||||
[
|
||||
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
||||
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
||||
],
|
||||
[
|
||||
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
||||
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
||||
],
|
||||
[
|
||||
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
||||
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
||||
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
||||
],
|
||||
[
|
||||
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
||||
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
||||
],
|
||||
[
|
||||
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
||||
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
||||
]
|
||||
]
|
||||
],
|
||||
"IC": [
|
||||
[
|
||||
"8938477176893632284539660223582989287068454472173218831171935317066824606917",
|
||||
"9409256007408490215082527289125535503645664704563806461206465772769775389099",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"9406714425071299321475031445293798140218018985951799864352153321364734136304",
|
||||
"16190677786472274760082919772279780726948507745938757138812410377304364738549",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"17636847760071529621476637340355013609204110513013412005293780563117471695582",
|
||||
"16269304104382842638426610869142550901209834485529174763447294867648099217552",
|
||||
"1"
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -2,150 +2,50 @@ import { DEFAULT_USER_ID_TYPE, WEBSOCKET_URL } from "../constants/constants";
|
||||
import { UserIdType } from "./utils";
|
||||
|
||||
export type CircuitName = "prove" | "disclose";
|
||||
export type CircuitMode = "prove" | "register" | '';
|
||||
export type CircuitMode = "prove_onchain" | "register" | 'prove_offchain';
|
||||
export type Mode = "prove_offchain" | "prove_onchain" | "register" | "vc_and_disclose";
|
||||
|
||||
export interface AppType {
|
||||
name: string,
|
||||
scope: string,
|
||||
userId: string,
|
||||
userIdType: UserIdType,
|
||||
websocketUrl: string,
|
||||
sessionId: string,
|
||||
circuit: CircuitName,
|
||||
circuitMode: CircuitMode,
|
||||
arguments: ArgumentsProve | ArgumentsRegister | ArgumentsDisclose,
|
||||
getDisclosureOptions?: () => Record<string, string>
|
||||
// OpenPassportAppType
|
||||
export interface OpenPassportAppPartial {
|
||||
mode: Mode;
|
||||
appName: string;
|
||||
scope: string;
|
||||
websocketUrl: string;
|
||||
sessionId: string;
|
||||
userId: string;
|
||||
userIdType: UserIdType;
|
||||
}
|
||||
|
||||
export interface ArgumentsProve {
|
||||
disclosureOptions: {
|
||||
older_than?: string,
|
||||
nationality?: string,
|
||||
},
|
||||
export interface OpenPassportApp extends OpenPassportAppPartial {
|
||||
args: ArgumentsProveOffChain | ArgumentsProveOnChain | ArgumentsRegister | ArgumentsDisclose
|
||||
}
|
||||
|
||||
export interface ArgumentsProveOffChain {
|
||||
disclosureOptions: DisclosureOptions,
|
||||
}
|
||||
|
||||
export interface ArgumentsProveOnChain {
|
||||
disclosureOptions: DisclosureOptions,
|
||||
modalServerUrl: string,
|
||||
merkleTreeUrl: string,
|
||||
}
|
||||
|
||||
export interface ArgumentsRegister {
|
||||
merkleTreeUrl: string,
|
||||
cscaMerkleTreeUrl: string,
|
||||
commitmentMerkleTreeUrl: string,
|
||||
modalServerUrl: string,
|
||||
}
|
||||
|
||||
|
||||
export interface ArgumentsDisclose {
|
||||
disclosureOptions: {
|
||||
older_than?: string,
|
||||
nationality?: string,
|
||||
},
|
||||
merkle_root: string,
|
||||
merkletree_size: string,
|
||||
disclosureOptions: DisclosureOptions,
|
||||
commitmentMerkleTreeUrl: string,
|
||||
}
|
||||
|
||||
export interface DisclosureOptions {
|
||||
minimumAge: { enabled: boolean; value: string }
|
||||
nationality: { enabled: boolean; value: string }
|
||||
excludedCountries: { enabled: boolean; value: string[] }
|
||||
ofac: boolean
|
||||
}
|
||||
|
||||
export function reconstructAppType(json: any): AppType {
|
||||
if (typeof json !== 'object' || json === null) {
|
||||
throw new Error('Input must be a non-null object');
|
||||
}
|
||||
|
||||
if (!json.name || typeof json.name !== 'string') {
|
||||
throw new Error('Invalid or missing name');
|
||||
}
|
||||
|
||||
if (!json.scope || typeof json.scope !== 'string') {
|
||||
throw new Error('Invalid or missing scope');
|
||||
}
|
||||
|
||||
if (json.circuit !== 'register' && (!json.userId || typeof json.userId !== 'string')) {
|
||||
throw new Error('Invalid or missing userId');
|
||||
}
|
||||
|
||||
if (!json.sessionId || typeof json.sessionId !== 'string') {
|
||||
throw new Error('Invalid or missing sessionId');
|
||||
}
|
||||
|
||||
if (!json.circuit || !['prove', 'register', 'disclose'].includes(json.circuit)) {
|
||||
throw new Error('Invalid or missing circuit');
|
||||
}
|
||||
|
||||
if (!json.circuitMode || !['prove', 'register', ''].includes(json.circuitMode)) {
|
||||
throw new Error('Invalid or missing circuitMode');
|
||||
}
|
||||
|
||||
if (!json.arguments || typeof json.arguments !== 'object') {
|
||||
throw new Error('Invalid or missing arguments');
|
||||
}
|
||||
|
||||
let circuitArgs: ArgumentsProve | ArgumentsRegister | ArgumentsDisclose;
|
||||
|
||||
switch (json.circuit) {
|
||||
case 'disclose':
|
||||
if (!json.arguments.disclosureOptions || typeof json.arguments.disclosureOptions !== 'object') {
|
||||
throw new Error('Invalid or missing disclosureOptions for prove/disclose');
|
||||
}
|
||||
circuitArgs = {
|
||||
disclosureOptions: {
|
||||
older_than: json.arguments.disclosureOptions.older_than,
|
||||
nationality: json.arguments.disclosureOptions.nationality,
|
||||
},
|
||||
};
|
||||
if (json.circuit === 'disclose') {
|
||||
if (!json.arguments.merkle_root || typeof json.arguments.merkle_root !== 'string') {
|
||||
throw new Error('Invalid or missing merkle_root for disclose');
|
||||
}
|
||||
if (!json.arguments.merkletree_size || typeof json.arguments.merkletree_size !== 'string') {
|
||||
throw new Error('Invalid or missing merkletree_size for disclose');
|
||||
}
|
||||
(circuitArgs as ArgumentsDisclose).merkle_root = json.arguments.merkle_root;
|
||||
(circuitArgs as ArgumentsDisclose).merkletree_size = json.arguments.merkletree_size;
|
||||
}
|
||||
break;
|
||||
case 'prove':
|
||||
if (json.circuitMode === 'register') {
|
||||
// if (!json.arguments.attestation_id || typeof json.arguments.attestation_id !== 'string') {
|
||||
// throw new Error('Invalid or missing attestation_id for register circuit');
|
||||
// }
|
||||
// if (!json.arguments.merkleTreeUrl || typeof json.arguments.merkleTreeUrl !== 'string') {
|
||||
// throw new Error('Invalid or missing merkleTreeUrl for register circuit');
|
||||
// }
|
||||
if (!json.arguments.modalServerUrl) {
|
||||
throw new Error('Invalid or missing modalServerUrl');
|
||||
}
|
||||
circuitArgs = {
|
||||
merkleTreeUrl: json.arguments.merkleTreeUrl,
|
||||
modalServerUrl: json.arguments.modalServerUrl,
|
||||
};
|
||||
}
|
||||
else {
|
||||
if (!json.arguments.disclosureOptions || typeof json.arguments.disclosureOptions !== 'object') {
|
||||
throw new Error('Invalid or missing disclosureOptions for prove/disclose');
|
||||
}
|
||||
circuitArgs = {
|
||||
disclosureOptions: {
|
||||
older_than: json.arguments.disclosureOptions.older_than,
|
||||
nationality: json.arguments.disclosureOptions.nationality,
|
||||
},
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unexpected circuit type');
|
||||
}
|
||||
|
||||
return {
|
||||
name: json.name,
|
||||
scope: json.scope || '',
|
||||
userId: json.userId || '',
|
||||
userIdType: json.userIdType || DEFAULT_USER_ID_TYPE,
|
||||
sessionId: json.sessionId,
|
||||
circuit: json.circuit as CircuitName,
|
||||
circuitMode: json.circuitMode as CircuitMode,
|
||||
arguments: circuitArgs,
|
||||
websocketUrl: json.websocketUrl || WEBSOCKET_URL,
|
||||
getDisclosureOptions: function () {
|
||||
if (this.circuit === 'prove' || this.circuit === 'disclose') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(this.arguments.disclosureOptions)
|
||||
.filter(([_, value]) => value !== '' && value !== undefined)
|
||||
) as Record<string, string>;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -41,9 +41,8 @@ export function findStartIndex(modulus: string, messagePadded: Uint8Array): numb
|
||||
}
|
||||
|
||||
|
||||
export function generateCircuitInputsDSC(dscSecret: string, dscCertificate: any, max_cert_bytes: number) {
|
||||
export function generateCircuitInputsDSC(dscSecret: string, dscCertificate: any, max_cert_bytes: number, devMode: boolean = false) {
|
||||
|
||||
// get the tbs certificate, first instiate the certificate
|
||||
const dscCert = forge.pki.certificateFromPem(dscCertificate);
|
||||
const dscTbs = dscCert.tbsCertificate;
|
||||
const dscTbsCertDer = forge.asn1.toDer(dscTbs).getBytes();
|
||||
@@ -51,7 +50,6 @@ export function generateCircuitInputsDSC(dscSecret: string, dscCertificate: any,
|
||||
const dscTbsCertUint8Array = Uint8Array.from(dscTbsCertBytes.map(byte => parseInt(byte.toString(16), 16)));
|
||||
|
||||
const { signatureAlgorithm, hashFunction, publicKeyDetails, x, y, modulus, curve, exponent, bits, subjectKeyIdentifier, authorityKeyIdentifier } = parseCertificate(dscCertificate);
|
||||
// console.log('authorityKeyIdentifier', authorityKeyIdentifier);
|
||||
let dsc_message_padded;
|
||||
let dsc_messagePaddedLen;
|
||||
switch (hashFunction) {
|
||||
@@ -74,16 +72,12 @@ export function generateCircuitInputsDSC(dscSecret: string, dscCertificate: any,
|
||||
|
||||
let pubKey, signature;
|
||||
|
||||
|
||||
|
||||
const startIndex = findStartIndex(modulus, dsc_message_padded);
|
||||
const startIndex_formatted = startIndex.toString();
|
||||
const dsc_message_padded_formatted = Array.from(dsc_message_padded).map((x) => x.toString())
|
||||
const dsc_messagePaddedLen_formatted = BigInt(dsc_messagePaddedLen).toString()
|
||||
|
||||
const cscaPemPROD = (SKI_PEM as any)[authorityKeyIdentifier];
|
||||
const cscaPemDEV = (SKI_PEM_DEV as any)[authorityKeyIdentifier];
|
||||
const cscaPem = cscaPemPROD || cscaPemDEV;
|
||||
const cscaPem = getCSCAFromSKI(authorityKeyIdentifier, devMode);
|
||||
|
||||
const { x: csca_x, y: csca_y, modulus: csca_modulus, signature_algorithm: csca_signature_algorithm } = parseCertificate(cscaPem);
|
||||
const { n: n_csca, k: k_csca } = getNAndKCSCA(csca_signature_algorithm);
|
||||
@@ -145,6 +139,16 @@ export function generateCircuitInputsDSC(dscSecret: string, dscCertificate: any,
|
||||
|
||||
}
|
||||
|
||||
export function getCSCAFromSKI(ski: string, devMode: boolean): string | null {
|
||||
const cscaPemPROD = (SKI_PEM as any)[ski];
|
||||
const cscaPemDEV = (SKI_PEM_DEV as any)[ski];
|
||||
const cscaPem = devMode ? cscaPemDEV || cscaPemPROD : cscaPemPROD;
|
||||
if (!cscaPem) {
|
||||
console.log('\x1b[31m%s\x1b[0m', `CSCA with SKI ${ski} not found`, 'devMode: ', devMode);
|
||||
}
|
||||
return cscaPem;
|
||||
}
|
||||
|
||||
export function derToBytes(derValue: string) {
|
||||
const bytes = [];
|
||||
for (let i = 0; i < derValue.length; i++) {
|
||||
|
||||
@@ -21,32 +21,33 @@ import {
|
||||
formatCountriesList,
|
||||
} from './utils';
|
||||
import { generateCommitment, getLeaf } from "./pubkeyTree";
|
||||
import { LeanIMT } from "@zk-kit/lean-imt";
|
||||
import { LeanIMT } from "@zk-kit/imt";
|
||||
import { getCountryLeaf, getNameLeaf, getNameDobLeaf, getPassportNumberLeaf } from "./smtTree";
|
||||
import { packBytes } from "../utils/utils";
|
||||
import { SMT } from "@ashpect/smt"
|
||||
import { parseCertificate } from './certificates/handleCertificate';
|
||||
import { poseidon2 } from 'poseidon-lite';
|
||||
import namejson from '../../../common/ofacdata/outputs/nameSMT.json';
|
||||
|
||||
export function generateCircuitInputsDisclose(
|
||||
secret: string,
|
||||
attestation_id: string,
|
||||
passportData: PassportData,
|
||||
scope: string,
|
||||
selector_dg1: string[],
|
||||
selector_older_than: string | number,
|
||||
merkletree: LeanIMT,
|
||||
majority: string,
|
||||
selector_dg1: string[],
|
||||
selector_older_than: string,
|
||||
scope: string,
|
||||
name_smt: SMT,
|
||||
selector_ofac: string | number,
|
||||
forbidden_countries_list: string[],
|
||||
user_identifier: string
|
||||
) {
|
||||
|
||||
const pubkey_leaf = getLeaf(passportData.dsc);
|
||||
|
||||
const formattedMrz = formatMrz(passportData.mrz);
|
||||
const mrz_bytes = packBytes(formattedMrz);
|
||||
const mrz_bytes_packed = packBytes(formattedMrz);
|
||||
|
||||
const commitment = generateCommitment(secret, attestation_id, pubkey_leaf, mrz_bytes, passportData.dg2Hash);
|
||||
const commitment = generateCommitment(BigInt(secret).toString(), BigInt(attestation_id).toString(), BigInt(pubkey_leaf).toString(), mrz_bytes_packed, formatDg2Hash(passportData.dg2Hash));
|
||||
console.log("\x1b[90mcommitment:\x1b[0m", commitment);
|
||||
|
||||
const index = findIndexInTree(merkletree, commitment);
|
||||
|
||||
@@ -55,23 +56,35 @@ export function generateCircuitInputsDisclose(
|
||||
index,
|
||||
PUBKEY_TREE_DEPTH
|
||||
);
|
||||
const formattedMajority = majority.length === 1 ? `0${majority}` : majority;
|
||||
const majority_ascii = formattedMajority.split('').map(char => char.charCodeAt(0));
|
||||
|
||||
// SMT - OFAC
|
||||
|
||||
const name_leaf = getNameLeaf(formattedMrz.slice(10, 49)) // [6-44] + 5 shift
|
||||
const { root: smt_root, closestleaf: smt_leaf_value, siblings: smt_siblings } = generateSMTProof(name_smt, name_leaf);
|
||||
|
||||
return {
|
||||
secret: [secret],
|
||||
attestation_id: [attestation_id],
|
||||
pubkey_leaf: [pubkey_leaf.toString()],
|
||||
dg1: formattedMrz.map((byte) => String(byte)),
|
||||
dg2_hash: formatDg2Hash(passportData.dg2Hash),
|
||||
merkle_root: [merkletree.root.toString()],
|
||||
merkletree_size: [BigInt(depthForThisOne).toString()],
|
||||
path: merkleProofIndices.map((index) => BigInt(index).toString()),
|
||||
siblings: merkleProofSiblings.map((index) => BigInt(index).toString()),
|
||||
selector_dg1: selector_dg1,
|
||||
selector_older_than: [BigInt(selector_older_than).toString()],
|
||||
scope: [castFromScope(scope)],
|
||||
current_date: getCurrentDateYYMMDD().map(datePart => BigInt(datePart).toString()),
|
||||
majority: majority.split('').map(char => BigInt(char.charCodeAt(0)).toString()),
|
||||
user_identifier: [castFromUUID(user_identifier)],
|
||||
secret: formatInput(secret),
|
||||
attestation_id: formatInput(attestation_id),
|
||||
pubkey_leaf: formatInput(pubkey_leaf),
|
||||
dg1: formatInput(formattedMrz),
|
||||
dg2_hash: formatInput(formatDg2Hash(passportData.dg2Hash)),
|
||||
merkle_root: formatInput(merkletree.root),
|
||||
merkletree_size: formatInput(depthForThisOne),
|
||||
path: formatInput(merkleProofIndices),
|
||||
siblings: formatInput(merkleProofSiblings),
|
||||
selector_dg1: formatInput(selector_dg1),
|
||||
selector_older_than: formatInput(selector_older_than),
|
||||
scope: formatInput(castFromScope(scope)),
|
||||
current_date: formatInput(getCurrentDateYYMMDD()),
|
||||
majority: formatInput(majority_ascii),
|
||||
user_identifier: formatInput(castFromUUID(user_identifier)),
|
||||
smt_root: formatInput(smt_root),
|
||||
smt_leaf_value: formatInput(smt_leaf_value),
|
||||
smt_siblings: formatInput(smt_siblings),
|
||||
selector_ofac: formatInput(selector_ofac),
|
||||
forbidden_countries_list: formatInput(formatCountriesList(forbidden_countries_list))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -150,7 +163,7 @@ export function generateCircuitInputsProve(
|
||||
selector_older_than: string | number,
|
||||
majority: string,
|
||||
name_smt: SMT,
|
||||
selector_ofac,
|
||||
selector_ofac: string | number,
|
||||
forbidden_countries_list: string[],
|
||||
user_identifier: string,
|
||||
user_identifier_type: 'uuid' | 'hex' | 'ascii' = DEFAULT_USER_ID_TYPE
|
||||
|
||||
@@ -8,10 +8,12 @@ import {
|
||||
bigIntToHex,
|
||||
castToScope,
|
||||
castToUUID,
|
||||
formatForbiddenCountriesListFromCircuitOutput,
|
||||
UserIdType,
|
||||
} from './utils';
|
||||
import { unpackReveal } from './revealBitmap';
|
||||
import { getAttributeFromUnpackedReveal } from './utils'
|
||||
import { Mode } from 'fs';
|
||||
|
||||
export interface OpenPassportAttestation {
|
||||
'@context': string[];
|
||||
@@ -37,8 +39,12 @@ export interface OpenPassportAttestation {
|
||||
pubKey?: string[];
|
||||
valid?: boolean;
|
||||
nullifier?: string;
|
||||
blinded_dsc_commitment?: string;
|
||||
};
|
||||
proof: {
|
||||
mode: Mode;
|
||||
signatureAlgorithm: string;
|
||||
hashFunction: string;
|
||||
type: string;
|
||||
verificationMethod: string;
|
||||
value: {
|
||||
@@ -48,6 +54,8 @@ export interface OpenPassportAttestation {
|
||||
vkey: string;
|
||||
};
|
||||
dscProof: {
|
||||
signatureAlgorithm: string;
|
||||
hashFunction: string;
|
||||
type: string;
|
||||
verificationMethod: string;
|
||||
value: {
|
||||
@@ -64,28 +72,33 @@ export interface OpenPassportAttestation {
|
||||
}
|
||||
|
||||
export function buildAttestation(options: {
|
||||
userIdType: UserIdType;
|
||||
mode: Mode;
|
||||
proof: string[];
|
||||
publicSignals: string[];
|
||||
signatureAlgorithm: string;
|
||||
hashFunction: string;
|
||||
dscProof?: string[];
|
||||
dscPublicSignals?: string[];
|
||||
dsc: string;
|
||||
userIdType?: UserIdType;
|
||||
signatureAlgorithmDsc?: string;
|
||||
hashFunctionDsc?: string;
|
||||
dsc?: string;
|
||||
}): OpenPassportDynamicAttestation {
|
||||
const {
|
||||
mode,
|
||||
proof,
|
||||
publicSignals,
|
||||
dscProof,
|
||||
dscPublicSignals,
|
||||
dsc,
|
||||
userIdType = 'uuid',
|
||||
signatureAlgorithm,
|
||||
hashFunction,
|
||||
dscProof = [],
|
||||
dscPublicSignals = [],
|
||||
signatureAlgorithmDsc = '',
|
||||
hashFunctionDsc = '',
|
||||
dsc = '',
|
||||
userIdType,
|
||||
} = options;
|
||||
|
||||
// Parse the DSC (Document Signing Certificate)
|
||||
const dscParsed = parseDSC(dsc);
|
||||
|
||||
// Determine the scaling factor based on the signature algorithm
|
||||
let kScaled: number;
|
||||
const { signatureAlgorithm } = dscParsed;
|
||||
switch (signatureAlgorithm) {
|
||||
case 'ecdsa':
|
||||
kScaled = ECDSA_K_LENGTH_FACTOR * k_dsc_ecdsa;
|
||||
@@ -94,10 +107,15 @@ export function buildAttestation(options: {
|
||||
kScaled = k_dsc;
|
||||
}
|
||||
|
||||
// Parse the public signals
|
||||
const parsedPublicSignals = parsePublicSignalsProve(publicSignals, kScaled);
|
||||
let parsedPublicSignals;
|
||||
switch (mode) {
|
||||
case 'vc_and_disclose':
|
||||
parsedPublicSignals = parsePublicSignalsDisclose(publicSignals);
|
||||
break;
|
||||
default:
|
||||
parsedPublicSignals = parsePublicSignalsProve(publicSignals, kScaled);
|
||||
}
|
||||
|
||||
// Get user identifier
|
||||
const rawUserId = parsedPublicSignals.user_identifier;
|
||||
let userId: string;
|
||||
switch (userIdType) {
|
||||
@@ -121,7 +139,6 @@ export function buildAttestation(options: {
|
||||
parsedPublicSignals.revealedData_packed
|
||||
);
|
||||
|
||||
// Extract attributes from unpackedReveal
|
||||
const attributeNames = [
|
||||
'issuing_state',
|
||||
'name',
|
||||
@@ -131,26 +148,28 @@ export function buildAttestation(options: {
|
||||
'gender',
|
||||
'expiry_date',
|
||||
'older_than',
|
||||
'owner_of',
|
||||
];
|
||||
|
||||
const formattedCountryList = formatForbiddenCountriesListFromCircuitOutput(parsedPublicSignals.forbidden_countries_list_packed_disclosed);
|
||||
const credentialSubject: any = {
|
||||
userId: userId,
|
||||
application: scope,
|
||||
nullifier: bigIntToHex(BigInt(parsedPublicSignals.nullifier)),
|
||||
scope: scope,
|
||||
current_date: parsedPublicSignals.current_date.toString(),
|
||||
blinded_dsc_commitment: parsedPublicSignals.blinded_dsc_commitment ?? '',
|
||||
not_in_ofac_list: parsedPublicSignals.ofac_result.toString(),
|
||||
not_in_countries: formattedCountryList,
|
||||
};
|
||||
|
||||
|
||||
attributeNames.forEach((attrName) => {
|
||||
const value = getAttributeFromUnpackedReveal(unpackedReveal, attrName);
|
||||
if (value !== undefined && value !== null) {
|
||||
credentialSubject[attrName] = value;
|
||||
}
|
||||
});
|
||||
|
||||
// Include pubKey if needed
|
||||
credentialSubject.pubKey = parsedPublicSignals.pubKey_disclosed;
|
||||
credentialSubject.pubKey = parsedPublicSignals.pubKey_disclosed ?? [];
|
||||
|
||||
const attestation: OpenPassportAttestation = {
|
||||
'@context': [
|
||||
@@ -162,6 +181,9 @@ export function buildAttestation(options: {
|
||||
issuanceDate: new Date().toISOString(),
|
||||
credentialSubject: credentialSubject,
|
||||
proof: {
|
||||
mode: mode,
|
||||
signatureAlgorithm: signatureAlgorithm,
|
||||
hashFunction: hashFunction,
|
||||
type: 'ZeroKnowledgeProof',
|
||||
verificationMethod:
|
||||
'https://github.com/zk-passport/openpassport',
|
||||
@@ -169,9 +191,11 @@ export function buildAttestation(options: {
|
||||
proof: proof,
|
||||
publicSignals: publicSignals,
|
||||
},
|
||||
vkey: '',
|
||||
vkey: 'https://github.com/zk-passport/openpassport/blob/main/common/src/constants/vkey.ts',
|
||||
},
|
||||
dscProof: {
|
||||
signatureAlgorithm: signatureAlgorithmDsc,
|
||||
hashFunction: hashFunctionDsc,
|
||||
type: 'ZeroKnowledgeProof',
|
||||
verificationMethod:
|
||||
'https://github.com/zk-passport/openpassport',
|
||||
@@ -179,7 +203,7 @@ export function buildAttestation(options: {
|
||||
proof: dscProof || [],
|
||||
publicSignals: dscPublicSignals || [],
|
||||
},
|
||||
vkey: '',
|
||||
vkey: 'https://github.com/zk-passport/openpassport/blob/main/common/src/constants/vkey.ts',
|
||||
},
|
||||
dsc: {
|
||||
type: 'X509Certificate',
|
||||
@@ -218,6 +242,9 @@ export class OpenPassportDynamicAttestation implements OpenPassportAttestation {
|
||||
nullifier?: string;
|
||||
};
|
||||
proof: {
|
||||
mode: Mode;
|
||||
signatureAlgorithm: string;
|
||||
hashFunction: string;
|
||||
type: string;
|
||||
verificationMethod: string;
|
||||
value: {
|
||||
@@ -227,6 +254,8 @@ export class OpenPassportDynamicAttestation implements OpenPassportAttestation {
|
||||
vkey;
|
||||
};
|
||||
dscProof: {
|
||||
signatureAlgorithm: string;
|
||||
hashFunction: string;
|
||||
type: string;
|
||||
verificationMethod: string;
|
||||
value: {
|
||||
@@ -254,28 +283,31 @@ export class OpenPassportDynamicAttestation implements OpenPassportAttestation {
|
||||
this.dscProof = attestation.dscProof;
|
||||
this.dsc = attestation.dsc;
|
||||
this.userIdType = userIdType;
|
||||
this.parsedPublicSignals = this.parsePublicSignals();
|
||||
}
|
||||
|
||||
private parsePublicSignals() {
|
||||
const dscParsed = parseDSC(this.dsc.value);
|
||||
|
||||
let kScaled: number;
|
||||
const { signatureAlgorithm } = dscParsed;
|
||||
switch (signatureAlgorithm) {
|
||||
case 'ecdsa':
|
||||
kScaled = ECDSA_K_LENGTH_FACTOR * k_dsc_ecdsa;
|
||||
break;
|
||||
default:
|
||||
kScaled = k_dsc;
|
||||
if (this.proof.mode === 'vc_and_disclose') {
|
||||
return parsePublicSignalsDisclose(this.proof.value.publicSignals);
|
||||
}
|
||||
else {
|
||||
let kScaled: number;
|
||||
switch (this.proof.signatureAlgorithm) {
|
||||
case 'ecdsa':
|
||||
kScaled = ECDSA_K_LENGTH_FACTOR * k_dsc_ecdsa;
|
||||
break;
|
||||
default:
|
||||
kScaled = k_dsc;
|
||||
}
|
||||
return parsePublicSignalsProve(this.proof.value.publicSignals, kScaled);
|
||||
}
|
||||
|
||||
|
||||
// Parse the public signals
|
||||
return parsePublicSignalsProve(this.proof.value.publicSignals, kScaled);
|
||||
}
|
||||
|
||||
getUserId(): string {
|
||||
const rawUserId = (this.parsedPublicSignals as any).user_identifier;
|
||||
const parsedPublicSignals = this.parsePublicSignals();
|
||||
const rawUserId = (parsedPublicSignals as any).user_identifier;
|
||||
switch (this.userIdType) {
|
||||
case 'ascii':
|
||||
return castToScope(BigInt(rawUserId));
|
||||
@@ -289,7 +321,27 @@ export class OpenPassportDynamicAttestation implements OpenPassportAttestation {
|
||||
}
|
||||
|
||||
getNullifier(): string {
|
||||
return bigIntToHex(BigInt(this.parsedPublicSignals.nullifier));
|
||||
const parsedPublicSignals = this.parsePublicSignals();
|
||||
return bigIntToHex(BigInt(parsedPublicSignals.nullifier));
|
||||
}
|
||||
|
||||
getCommitment(): string {
|
||||
const parsedPublicSignals = this.parsePublicSignals();
|
||||
if (this.proof.mode === 'vc_and_disclose') {
|
||||
return '';
|
||||
}
|
||||
else {
|
||||
return (parsedPublicSignals as any).commitment;
|
||||
}
|
||||
}
|
||||
getCSCAMerkleRoot(): string {
|
||||
if (this.dscProof.value.publicSignals) {
|
||||
const parsedPublicSignalsDsc = parsePublicSignalsDsc(this.dscProof.value.publicSignals);
|
||||
return parsedPublicSignalsDsc.merkle_root;
|
||||
}
|
||||
else {
|
||||
throw new Error('No DSC proof found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,12 +351,36 @@ export function parsePublicSignalsProve(publicSignals, kScaled) {
|
||||
revealedData_packed: [publicSignals[1], publicSignals[2], publicSignals[3]],
|
||||
older_than: [publicSignals[4], publicSignals[5]],
|
||||
pubKey_disclosed: publicSignals.slice(6, 6 + kScaled),
|
||||
forbidden_countries_list_packed_disclosed: publicSignals.slice(6 + kScaled, 6 + kScaled + 2),
|
||||
forbidden_countries_list_packed_disclosed: publicSignals.slice(6 + kScaled, 8 + kScaled),
|
||||
ofac_result: publicSignals[8 + kScaled],
|
||||
commitment: publicSignals[9 + kScaled],
|
||||
blinded_dsc_commitment: publicSignals[10 + kScaled],
|
||||
current_date: publicSignals.slice(11 + kScaled, 11 + kScaled + 6),
|
||||
user_identifier: publicSignals[12 + kScaled + 6],
|
||||
scope: publicSignals[13 + kScaled + 6],
|
||||
user_identifier: publicSignals[17 + kScaled],
|
||||
scope: publicSignals[18 + kScaled],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePublicSignalsDsc(publicSignals) {
|
||||
return {
|
||||
blinded_dsc_commitment: publicSignals[0],
|
||||
merkle_root: publicSignals[1],
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePublicSignalsDisclose(publicSignals) {
|
||||
return {
|
||||
nullifier: publicSignals[0],
|
||||
revealedData_packed: publicSignals.slice(1, 4),
|
||||
older_than: publicSignals.slice(4, 6),
|
||||
forbidden_countries_list_packed_disclosed: publicSignals.slice(6, 8),
|
||||
ofac_result: publicSignals[8],
|
||||
attestation_id: publicSignals[9],
|
||||
merkle_root: publicSignals[10],
|
||||
scope: publicSignals[11],
|
||||
current_date: publicSignals.slice(12, 18),
|
||||
user_identifier: publicSignals[18],
|
||||
smt_root: publicSignals[19],
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,4 +87,17 @@ export function generateCommitment(secret: string, attestation_id: string, pubke
|
||||
dg2Hash2
|
||||
]);
|
||||
return commitment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function fetchTreeFromUrl(url: string): Promise<LeanIMT> {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const commitmentMerkleTree = await response.json();
|
||||
console.log("\x1b[90m%s\x1b[0m", "commitment merkle tree: ", commitmentMerkleTree);
|
||||
const tree = new LeanIMT((a, b) => poseidon2([a, b]));
|
||||
tree.import(commitmentMerkleTree);
|
||||
return tree;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { attributeToPosition } from "../constants/constants";
|
||||
import { DisclosureOptions } from "./appType";
|
||||
|
||||
export function revealBitmapFromMapping(attributeToReveal: { [key: string]: string }): string[] {
|
||||
const reveal_bitmap = Array(90).fill('0');
|
||||
@@ -12,23 +13,27 @@ export function revealBitmapFromMapping(attributeToReveal: { [key: string]: stri
|
||||
|
||||
return reveal_bitmap;
|
||||
}
|
||||
export function revealBitmapFromAttributes(attributeToReveal: { [key: string]: boolean }): string[] {
|
||||
const reveal_bitmap = Array(90).fill('0');
|
||||
export function revealBitmapFromAttributes(disclosureOptions: DisclosureOptions): string[] {
|
||||
const reveal_bitmap = Array(88).fill('0');
|
||||
|
||||
Object.entries(attributeToReveal).forEach(([attribute, reveal]) => {
|
||||
const [start, end] = attributeToPosition[attribute as keyof typeof attributeToPosition];
|
||||
reveal_bitmap.fill('1', start, end + 1);
|
||||
Object.entries(disclosureOptions).forEach(([attribute, { enabled }]) => {
|
||||
if (enabled && attribute in attributeToPosition) {
|
||||
const [start, end] = attributeToPosition[attribute as keyof typeof attributeToPosition];
|
||||
reveal_bitmap.fill('1', start, end + 1);
|
||||
}
|
||||
});
|
||||
|
||||
return reveal_bitmap;
|
||||
}
|
||||
|
||||
|
||||
export function unpackReveal(revealedData_packed: string[]): string[] {
|
||||
export function unpackReveal(revealedData_packed: string | string[]): string[] {
|
||||
// If revealedData_packed is not an array, convert it to an array
|
||||
const packedArray = Array.isArray(revealedData_packed) ? revealedData_packed : [revealedData_packed];
|
||||
|
||||
const bytesCount = [31, 31, 28]; // nb of bytes in each of the first three field elements
|
||||
const bytesArray = revealedData_packed.flatMap((element: string, index: number) => {
|
||||
const bytes = bytesCount[index];
|
||||
const bytesArray = packedArray.flatMap((element: string, index: number) => {
|
||||
const bytes = bytesCount[index] || 31; // Use 31 as default if index is out of range
|
||||
const elementBigInt = BigInt(element);
|
||||
const byteMask = BigInt(255); // 0xFF
|
||||
const bytesOfElement = [...Array(bytes)].map((_, byteIndex) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { sha384, sha512_256 } from 'js-sha512';
|
||||
import { SMT } from '@ashpect/smt';
|
||||
import forge from 'node-forge';
|
||||
import { n_dsc, k_dsc, n_dsc_ecdsa, k_dsc_ecdsa, n_csca, k_csca, attributeToPosition } from '../constants/constants';
|
||||
import { unpackReveal } from './revealBitmap';
|
||||
|
||||
export function formatMrz(mrz: string) {
|
||||
const mrzCharcodes = [...mrz].map((char) => char.charCodeAt(0));
|
||||
@@ -554,7 +555,32 @@ export function getAttributeFromUnpackedReveal(unpackedReveal: string[], attribu
|
||||
const position = attributeToPosition[attribute];
|
||||
let attributeValue = '';
|
||||
for (let i = position[0]; i <= position[1]; i++) {
|
||||
attributeValue += unpackedReveal[i];
|
||||
if (unpackedReveal[i] !== '\u0000') {
|
||||
attributeValue += unpackedReveal[i];
|
||||
}
|
||||
}
|
||||
return attributeValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatForbiddenCountriesListFromCircuitOutput(forbiddenCountriesList: string[]): string[] {
|
||||
const countryList1 = unpackReveal(forbiddenCountriesList[0]);
|
||||
const countryList2 = unpackReveal(forbiddenCountriesList[1]);
|
||||
const concatenatedCountryList = countryList1.concat(countryList2);
|
||||
// dump every '\x00' value from the list
|
||||
const cleanedCountryList = concatenatedCountryList.filter(value => value !== '\x00');
|
||||
// Concatenate every 3 elements to form country codes
|
||||
const formattedCountryList = [];
|
||||
for (let i = 0; i < cleanedCountryList.length; i += 3) {
|
||||
const countryCode = cleanedCountryList.slice(i, i + 3).join('');
|
||||
if (countryCode.length === 3) {
|
||||
formattedCountryList.push(countryCode);
|
||||
}
|
||||
}
|
||||
return formattedCountryList;
|
||||
}
|
||||
|
||||
export function getOlderThanFromCircuitOutput(olderThan: string[]): number {
|
||||
const ageString = olderThan.map(code => String.fromCharCode(parseInt(code))).join('');
|
||||
const age = parseInt(ageString, 10);
|
||||
return isNaN(age) ? 0 : age;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user