@zkpassport/sdk 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/assets/abi/ZKPassportVerifier.json +11 -11
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +58 -15
- package/dist/esm/assets/abi/ZKPassportVerifier.json +11 -11
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +59 -16
- package/package.json +4 -4
- package/src/assets/abi/ZKPassportVerifier.json +11 -11
- package/src/index.ts +65 -15
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getAlpha3Code, registerLocale } from "i18n-iso-countries";
|
|
2
|
-
import { getProofData, getCommitmentFromDSCProof, getCommitmentInFromIDDataProof, getCommitmentOutFromIDDataProof, getNullifierFromDisclosureProof, getCommitmentInFromIntegrityProof, getCommitmentOutFromIntegrityProof, getCommitmentInFromDisclosureProof, getMerkleRootFromDSCProof, getCurrentDateFromIntegrityProof, DisclosedData, formatName,
|
|
2
|
+
import { getProofData, getCommitmentFromDSCProof, getCommitmentInFromIDDataProof, getCommitmentOutFromIDDataProof, getNullifierFromDisclosureProof, getCommitmentInFromIntegrityProof, getCommitmentOutFromIntegrityProof, getCommitmentInFromDisclosureProof, getMerkleRootFromDSCProof, getCurrentDateFromIntegrityProof, DisclosedData, formatName, getNumberOfPublicInputs, getParameterCommitmentFromDisclosureProof, getCountryParameterCommitment, getDiscloseParameterCommitment, getDateParameterCommitment, getCertificateRegistryRootFromOuterProof, getParamCommitmentsFromOuterProof, getCurrentDateFromCommittedInputs, getMinAgeFromCommittedInputs, getMaxAgeFromCommittedInputs, getAgeParameterCommitment, getMinDateFromCommittedInputs, getMaxDateFromCommittedInputs, getCurrentDateFromOuterProof, getNullifierFromOuterProof, getAgeEVMParameterCommitment, getDateEVMParameterCommitment, getDiscloseEVMParameterCommitment, getCountryEVMParameterCommitment, rightPadArrayWithZeros, getCommittedInputCount, ProofType, getScopeHash, getScopeFromOuterProof, getSubscopeFromOuterProof, getServiceScopeHash, getBindEVMParameterCommitment, getBindParameterCommitment, formatBoundData, getCircuitRegistryRootFromOuterProof, } from "@zkpassport/utils";
|
|
3
3
|
import { bytesToHex } from "@noble/ciphers/utils";
|
|
4
4
|
import { noLogger as logger } from "./logger";
|
|
5
5
|
import i18en from "i18n-iso-countries/langs/en.json";
|
|
@@ -9,7 +9,7 @@ import { hexToBytes } from "@noble/hashes/utils";
|
|
|
9
9
|
import ZKPassportVerifierAbi from "./assets/abi/ZKPassportVerifier.json";
|
|
10
10
|
import { RegistryClient } from "@zkpassport/registry";
|
|
11
11
|
import { Bridge } from "@obsidion/bridge";
|
|
12
|
-
const VERSION = "0.
|
|
12
|
+
const VERSION = "0.5.0";
|
|
13
13
|
const DEFAULT_DATE_VALUE = new Date(1111, 10, 11);
|
|
14
14
|
// If Buffer is not defined, then we use the Buffer from the buffer package
|
|
15
15
|
if (typeof globalThis.Buffer === "undefined") {
|
|
@@ -282,6 +282,9 @@ export class ZKPassport {
|
|
|
282
282
|
},
|
|
283
283
|
gte: (key, value) => {
|
|
284
284
|
numericalCompare("gte", key, value, topic, this.topicToConfig);
|
|
285
|
+
if (key === "age" && (value < 1 || value >= 100)) {
|
|
286
|
+
throw new Error("Age must be between 1 and 99 (inclusive)");
|
|
287
|
+
}
|
|
285
288
|
return this.getZkPassportRequest(topic);
|
|
286
289
|
},
|
|
287
290
|
/*gt: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => {
|
|
@@ -1258,17 +1261,8 @@ export class ZKPassport {
|
|
|
1258
1261
|
// Maintained certificate registry settled onchain
|
|
1259
1262
|
// Here we use Ethereum Sepolia
|
|
1260
1263
|
const registryClient = new RegistryClient({ chainId: 11155111 });
|
|
1261
|
-
await registryClient.
|
|
1262
|
-
|
|
1263
|
-
catch (error) {
|
|
1264
|
-
console.warn(error);
|
|
1265
|
-
// Check the legacy static roots that were used before the registry was deployed onchain
|
|
1266
|
-
const VALID_CERTIFICATE_REGISTRY_ROOT = [
|
|
1267
|
-
BigInt("20192042006788880778219739574377003123593792072535937278552252195461520776494"),
|
|
1268
|
-
BigInt("21301853597069384763054217328384418971999152625381818922211526730996340553696"),
|
|
1269
|
-
BigInt("10839898448097753834842514286432152806152415606387598803678317315409344029817"),
|
|
1270
|
-
];
|
|
1271
|
-
if (!VALID_CERTIFICATE_REGISTRY_ROOT.includes(BigInt(root))) {
|
|
1264
|
+
const isValid = await registryClient.isCertificateRootValid(root);
|
|
1265
|
+
if (!isValid) {
|
|
1272
1266
|
console.warn("The ID was signed by an unrecognized root certificate");
|
|
1273
1267
|
isCorrect = false;
|
|
1274
1268
|
queryResultErrors[outer ? "outer" : "sig_check_dsc"].certificate = {
|
|
@@ -1278,6 +1272,43 @@ export class ZKPassport {
|
|
|
1278
1272
|
};
|
|
1279
1273
|
}
|
|
1280
1274
|
}
|
|
1275
|
+
catch (error) {
|
|
1276
|
+
console.warn(error);
|
|
1277
|
+
console.warn("The ID was signed by an unrecognized root certificate");
|
|
1278
|
+
isCorrect = false;
|
|
1279
|
+
queryResultErrors[outer ? "outer" : "sig_check_dsc"].certificate = {
|
|
1280
|
+
expected: `A valid root from ZKPassport Registry`,
|
|
1281
|
+
received: `Got invalid certificate registry root: ${root}`,
|
|
1282
|
+
message: "The ID was signed by an unrecognized root certificate",
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
return { isCorrect, queryResultErrors };
|
|
1286
|
+
}
|
|
1287
|
+
async checkCircuitRegistryRoot(root, queryResultErrors) {
|
|
1288
|
+
let isCorrect = true;
|
|
1289
|
+
try {
|
|
1290
|
+
const registryClient = new RegistryClient({ chainId: 11155111 });
|
|
1291
|
+
const isValid = await registryClient.isCircuitRootValid(root);
|
|
1292
|
+
if (!isValid) {
|
|
1293
|
+
console.warn("The proof uses unrecognized circuits");
|
|
1294
|
+
isCorrect = false;
|
|
1295
|
+
queryResultErrors.outer.circuit = {
|
|
1296
|
+
expected: `A valid circuit from ZKPassport Registry`,
|
|
1297
|
+
received: `Got invalid circuit registry root: ${root}`,
|
|
1298
|
+
message: "The proof uses an unrecognized circuit",
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
catch (error) {
|
|
1303
|
+
console.warn(error);
|
|
1304
|
+
console.warn("The proof uses unrecognized circuits");
|
|
1305
|
+
isCorrect = false;
|
|
1306
|
+
queryResultErrors.outer.circuit = {
|
|
1307
|
+
expected: `A valid circuit from ZKPassport Registry`,
|
|
1308
|
+
received: `Got invalid circuit registry root: ${root}`,
|
|
1309
|
+
message: "The proof uses an unrecognized circuit",
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1281
1312
|
return { isCorrect, queryResultErrors };
|
|
1282
1313
|
}
|
|
1283
1314
|
checkBindPublicInputs(queryResult, boundData) {
|
|
@@ -1385,6 +1416,13 @@ export class ZKPassport {
|
|
|
1385
1416
|
...queryResultErrors,
|
|
1386
1417
|
...queryResultErrorsCertificateRegistryRoot,
|
|
1387
1418
|
};
|
|
1419
|
+
const circuitRegistryRoot = getCircuitRegistryRootFromOuterProof(proofData);
|
|
1420
|
+
const { isCorrect: isCorrectCircuitRegistryRoot, queryResultErrors: queryResultErrorsCircuitRegistryRoot, } = await this.checkCircuitRegistryRoot(circuitRegistryRoot.toString(16), queryResultErrors);
|
|
1421
|
+
isCorrect = isCorrect && isCorrectCircuitRegistryRoot;
|
|
1422
|
+
queryResultErrors = {
|
|
1423
|
+
...queryResultErrors,
|
|
1424
|
+
...queryResultErrorsCircuitRegistryRoot,
|
|
1425
|
+
};
|
|
1388
1426
|
const currentDate = getCurrentDateFromOuterProof(proofData);
|
|
1389
1427
|
const todayToCurrentDate = today.getTime() - currentDate.getTime();
|
|
1390
1428
|
const differenceInDays = validity ?? 180;
|
|
@@ -2016,9 +2054,14 @@ export class ZKPassport {
|
|
|
2016
2054
|
}
|
|
2017
2055
|
// Only proceed with the proof verification if the public inputs are correct
|
|
2018
2056
|
if (verified) {
|
|
2057
|
+
const registryClient = new RegistryClient({ chainId: 11155111 });
|
|
2058
|
+
const circuitManifest = await registryClient.getCircuitManifest(undefined, {
|
|
2059
|
+
// We assume all proofs have the same version
|
|
2060
|
+
version: proofs[0].version,
|
|
2061
|
+
});
|
|
2019
2062
|
for (const proof of proofs) {
|
|
2020
2063
|
const proofData = getProofData(proof.proof, getNumberOfPublicInputs(proof.name));
|
|
2021
|
-
const hostedPackagedCircuit = await
|
|
2064
|
+
const hostedPackagedCircuit = await registryClient.getPackagedCircuit(proof.name, circuitManifest);
|
|
2022
2065
|
if (proof.name?.startsWith("outer_evm")) {
|
|
2023
2066
|
try {
|
|
2024
2067
|
const { createPublicClient, http } = await import("viem");
|
|
@@ -2081,7 +2124,7 @@ export class ZKPassport {
|
|
|
2081
2124
|
if (network === "ethereum_sepolia") {
|
|
2082
2125
|
return {
|
|
2083
2126
|
...baseConfig,
|
|
2084
|
-
address: "
|
|
2127
|
+
address: "0xEE9F10f38319eAE2730dBa28fB09081dB806c5E5",
|
|
2085
2128
|
};
|
|
2086
2129
|
}
|
|
2087
2130
|
else if (network === "local_anvil") {
|
|
@@ -2187,7 +2230,7 @@ export class ZKPassport {
|
|
|
2187
2230
|
}
|
|
2188
2231
|
committedInputs.push({ circuitName, inputs: compressedCommittedInputs });
|
|
2189
2232
|
}
|
|
2190
|
-
const parameterCommitments = proofData.publicInputs.slice(
|
|
2233
|
+
const parameterCommitments = proofData.publicInputs.slice(12, proofData.publicInputs.length - 1);
|
|
2191
2234
|
let compressedCommittedInputs = "";
|
|
2192
2235
|
let committedInputCountsArray = [];
|
|
2193
2236
|
for (const commitment of parameterCommitments) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkpassport/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Privacy-preserving identity verification using passports and ID cards",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"@noble/ciphers": "^1.2.1",
|
|
43
43
|
"@noble/hashes": "^1.7.2",
|
|
44
44
|
"@noble/secp256k1": "^2.2.3",
|
|
45
|
-
"@obsidion/bridge": "^0.10.
|
|
46
|
-
"@zkpassport/registry": "^0.
|
|
47
|
-
"@zkpassport/utils": "^0.
|
|
45
|
+
"@obsidion/bridge": "^0.10.2",
|
|
46
|
+
"@zkpassport/registry": "^0.5.1",
|
|
47
|
+
"@zkpassport/utils": "^0.13.1",
|
|
48
48
|
"buffer": "^6.0.3",
|
|
49
49
|
"i18n-iso-countries": "^7.12.0",
|
|
50
50
|
"pako": "^2.1.0",
|