@zkpassport/sdk 0.2.11 → 0.2.13
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/index.js +24 -5
- package/dist/esm/index.js +24 -5
- package/package.json +2 -2
- package/src/index.ts +33 -7
package/dist/cjs/index.js
CHANGED
|
@@ -218,7 +218,15 @@ class ZKPassport {
|
|
|
218
218
|
}
|
|
219
219
|
else if (request.method === "done") {
|
|
220
220
|
logger_1.noLogger.debug(`User sent the query result`);
|
|
221
|
-
|
|
221
|
+
const formattedResult = request.params;
|
|
222
|
+
// Make sure to reconvert the dates to Date objects
|
|
223
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
224
|
+
formattedResult.birthdate.disclose.result = new Date(formattedResult.birthdate.disclose.result);
|
|
225
|
+
}
|
|
226
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
227
|
+
formattedResult.expiry_date.disclose.result = new Date(formattedResult.expiry_date.disclose.result);
|
|
228
|
+
}
|
|
229
|
+
this.topicToResults[topic] = formattedResult;
|
|
222
230
|
// Make sure all the proofs have been received, otherwise we'll handle the result later
|
|
223
231
|
// once the proofs have all been received
|
|
224
232
|
if (this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
@@ -403,7 +411,10 @@ class ZKPassport {
|
|
|
403
411
|
let commitmentOut;
|
|
404
412
|
let isCorrect = true;
|
|
405
413
|
let uniqueIdentifier;
|
|
406
|
-
const
|
|
414
|
+
const VALID_CERTIFICATE_REGISTRY_ROOT = [
|
|
415
|
+
BigInt("20192042006788880778219739574377003123593792072535937278552252195461520776494"),
|
|
416
|
+
BigInt("21301853597069384763054217328384418971999152625381818922211526730996340553696"),
|
|
417
|
+
];
|
|
407
418
|
const defaultDateValue = new Date(1111, 10, 11);
|
|
408
419
|
const currentTime = new Date();
|
|
409
420
|
const today = new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate(), 0, 0, 0, 0);
|
|
@@ -451,11 +462,11 @@ class ZKPassport {
|
|
|
451
462
|
if (proof.name?.startsWith("sig_check_dsc")) {
|
|
452
463
|
commitmentOut = (0, utils_1.getCommitmentFromDSCProof)(proofData);
|
|
453
464
|
const merkleRoot = (0, utils_1.getMerkleRootFromDSCProof)(proofData);
|
|
454
|
-
if (merkleRoot
|
|
465
|
+
if (!VALID_CERTIFICATE_REGISTRY_ROOT.includes(merkleRoot)) {
|
|
455
466
|
console.warn("The ID was signed by an unrecognized root certificate");
|
|
456
467
|
isCorrect = false;
|
|
457
468
|
queryResultErrors.sig_check_dsc.certificate = {
|
|
458
|
-
expected: `Certificate registry root: ${
|
|
469
|
+
expected: `Certificate registry root: ${VALID_CERTIFICATE_REGISTRY_ROOT.join(", ")}`,
|
|
459
470
|
received: `Certificate registry root: ${merkleRoot.toString()}`,
|
|
460
471
|
message: "The ID was signed by an unrecognized root certificate",
|
|
461
472
|
};
|
|
@@ -1240,12 +1251,20 @@ class ZKPassport {
|
|
|
1240
1251
|
* and a boolean indicating whether the proofs were successfully verified.
|
|
1241
1252
|
*/
|
|
1242
1253
|
async verify({ proofs, queryResult, validity, }) {
|
|
1254
|
+
const formattedResult = queryResult;
|
|
1255
|
+
// Make sure to reconvert the dates to Date objects
|
|
1256
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
1257
|
+
formattedResult.birthdate.disclose.result = new Date(formattedResult.birthdate.disclose.result);
|
|
1258
|
+
}
|
|
1259
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
1260
|
+
formattedResult.expiry_date.disclose.result = new Date(formattedResult.expiry_date.disclose.result);
|
|
1261
|
+
}
|
|
1243
1262
|
const { BarretenbergVerifier } = await Promise.resolve().then(() => tslib_1.__importStar(require("@aztec/bb.js")));
|
|
1244
1263
|
const verifier = new BarretenbergVerifier();
|
|
1245
1264
|
let verified = true;
|
|
1246
1265
|
let uniqueIdentifier;
|
|
1247
1266
|
let queryResultErrors;
|
|
1248
|
-
const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs,
|
|
1267
|
+
const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs, formattedResult, validity);
|
|
1249
1268
|
uniqueIdentifier = uniqueIdentifierFromPublicInputs;
|
|
1250
1269
|
verified = isCorrect;
|
|
1251
1270
|
queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
|
package/dist/esm/index.js
CHANGED
|
@@ -208,7 +208,15 @@ export class ZKPassport {
|
|
|
208
208
|
}
|
|
209
209
|
else if (request.method === "done") {
|
|
210
210
|
logger.debug(`User sent the query result`);
|
|
211
|
-
|
|
211
|
+
const formattedResult = request.params;
|
|
212
|
+
// Make sure to reconvert the dates to Date objects
|
|
213
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
214
|
+
formattedResult.birthdate.disclose.result = new Date(formattedResult.birthdate.disclose.result);
|
|
215
|
+
}
|
|
216
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
217
|
+
formattedResult.expiry_date.disclose.result = new Date(formattedResult.expiry_date.disclose.result);
|
|
218
|
+
}
|
|
219
|
+
this.topicToResults[topic] = formattedResult;
|
|
212
220
|
// Make sure all the proofs have been received, otherwise we'll handle the result later
|
|
213
221
|
// once the proofs have all been received
|
|
214
222
|
if (this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
@@ -393,7 +401,10 @@ export class ZKPassport {
|
|
|
393
401
|
let commitmentOut;
|
|
394
402
|
let isCorrect = true;
|
|
395
403
|
let uniqueIdentifier;
|
|
396
|
-
const
|
|
404
|
+
const VALID_CERTIFICATE_REGISTRY_ROOT = [
|
|
405
|
+
BigInt("20192042006788880778219739574377003123593792072535937278552252195461520776494"),
|
|
406
|
+
BigInt("21301853597069384763054217328384418971999152625381818922211526730996340553696"),
|
|
407
|
+
];
|
|
397
408
|
const defaultDateValue = new Date(1111, 10, 11);
|
|
398
409
|
const currentTime = new Date();
|
|
399
410
|
const today = new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate(), 0, 0, 0, 0);
|
|
@@ -441,11 +452,11 @@ export class ZKPassport {
|
|
|
441
452
|
if (proof.name?.startsWith("sig_check_dsc")) {
|
|
442
453
|
commitmentOut = getCommitmentFromDSCProof(proofData);
|
|
443
454
|
const merkleRoot = getMerkleRootFromDSCProof(proofData);
|
|
444
|
-
if (merkleRoot
|
|
455
|
+
if (!VALID_CERTIFICATE_REGISTRY_ROOT.includes(merkleRoot)) {
|
|
445
456
|
console.warn("The ID was signed by an unrecognized root certificate");
|
|
446
457
|
isCorrect = false;
|
|
447
458
|
queryResultErrors.sig_check_dsc.certificate = {
|
|
448
|
-
expected: `Certificate registry root: ${
|
|
459
|
+
expected: `Certificate registry root: ${VALID_CERTIFICATE_REGISTRY_ROOT.join(", ")}`,
|
|
449
460
|
received: `Certificate registry root: ${merkleRoot.toString()}`,
|
|
450
461
|
message: "The ID was signed by an unrecognized root certificate",
|
|
451
462
|
};
|
|
@@ -1230,12 +1241,20 @@ export class ZKPassport {
|
|
|
1230
1241
|
* and a boolean indicating whether the proofs were successfully verified.
|
|
1231
1242
|
*/
|
|
1232
1243
|
async verify({ proofs, queryResult, validity, }) {
|
|
1244
|
+
const formattedResult = queryResult;
|
|
1245
|
+
// Make sure to reconvert the dates to Date objects
|
|
1246
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
1247
|
+
formattedResult.birthdate.disclose.result = new Date(formattedResult.birthdate.disclose.result);
|
|
1248
|
+
}
|
|
1249
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
1250
|
+
formattedResult.expiry_date.disclose.result = new Date(formattedResult.expiry_date.disclose.result);
|
|
1251
|
+
}
|
|
1233
1252
|
const { BarretenbergVerifier } = await import("@aztec/bb.js");
|
|
1234
1253
|
const verifier = new BarretenbergVerifier();
|
|
1235
1254
|
let verified = true;
|
|
1236
1255
|
let uniqueIdentifier;
|
|
1237
1256
|
let queryResultErrors;
|
|
1238
|
-
const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs,
|
|
1257
|
+
const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs, formattedResult, validity);
|
|
1239
1258
|
uniqueIdentifier = uniqueIdentifierFromPublicInputs;
|
|
1240
1259
|
verified = isCorrect;
|
|
1241
1260
|
queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkpassport/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@aztec/bb.js": "^0.76.4",
|
|
42
42
|
"@noble/ciphers": "^1.2.1",
|
|
43
43
|
"@noble/secp256k1": "^2.2.3",
|
|
44
|
-
"@zkpassport/utils": "^0.2.
|
|
44
|
+
"@zkpassport/utils": "^0.2.24",
|
|
45
45
|
"buffer": "^6.0.3",
|
|
46
46
|
"i18n-iso-countries": "^7.12.0",
|
|
47
47
|
"pako": "^2.1.0",
|
package/src/index.ts
CHANGED
|
@@ -479,7 +479,19 @@ export class ZKPassport {
|
|
|
479
479
|
}
|
|
480
480
|
} else if (request.method === "done") {
|
|
481
481
|
logger.debug(`User sent the query result`)
|
|
482
|
-
|
|
482
|
+
const formattedResult: QueryResult = request.params
|
|
483
|
+
// Make sure to reconvert the dates to Date objects
|
|
484
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
485
|
+
formattedResult.birthdate.disclose.result = new Date(
|
|
486
|
+
formattedResult.birthdate.disclose.result,
|
|
487
|
+
)
|
|
488
|
+
}
|
|
489
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
490
|
+
formattedResult.expiry_date.disclose.result = new Date(
|
|
491
|
+
formattedResult.expiry_date.disclose.result,
|
|
492
|
+
)
|
|
493
|
+
}
|
|
494
|
+
this.topicToResults[topic] = formattedResult
|
|
483
495
|
// Make sure all the proofs have been received, otherwise we'll handle the result later
|
|
484
496
|
// once the proofs have all been received
|
|
485
497
|
if (this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
@@ -726,9 +738,10 @@ export class ZKPassport {
|
|
|
726
738
|
let commitmentOut: bigint | undefined
|
|
727
739
|
let isCorrect = true
|
|
728
740
|
let uniqueIdentifier: string | undefined
|
|
729
|
-
const
|
|
730
|
-
"
|
|
731
|
-
|
|
741
|
+
const VALID_CERTIFICATE_REGISTRY_ROOT = [
|
|
742
|
+
BigInt("20192042006788880778219739574377003123593792072535937278552252195461520776494"),
|
|
743
|
+
BigInt("21301853597069384763054217328384418971999152625381818922211526730996340553696"),
|
|
744
|
+
]
|
|
732
745
|
const defaultDateValue = new Date(1111, 10, 11)
|
|
733
746
|
const currentTime = new Date()
|
|
734
747
|
const today = new Date(
|
|
@@ -786,11 +799,11 @@ export class ZKPassport {
|
|
|
786
799
|
if (proof.name?.startsWith("sig_check_dsc")) {
|
|
787
800
|
commitmentOut = getCommitmentFromDSCProof(proofData)
|
|
788
801
|
const merkleRoot = getMerkleRootFromDSCProof(proofData)
|
|
789
|
-
if (merkleRoot
|
|
802
|
+
if (!VALID_CERTIFICATE_REGISTRY_ROOT.includes(merkleRoot)) {
|
|
790
803
|
console.warn("The ID was signed by an unrecognized root certificate")
|
|
791
804
|
isCorrect = false
|
|
792
805
|
queryResultErrors.sig_check_dsc.certificate = {
|
|
793
|
-
expected: `Certificate registry root: ${
|
|
806
|
+
expected: `Certificate registry root: ${VALID_CERTIFICATE_REGISTRY_ROOT.join(", ")}`,
|
|
794
807
|
received: `Certificate registry root: ${merkleRoot.toString()}`,
|
|
795
808
|
message: "The ID was signed by an unrecognized root certificate",
|
|
796
809
|
}
|
|
@@ -1709,6 +1722,19 @@ export class ZKPassport {
|
|
|
1709
1722
|
verified: boolean
|
|
1710
1723
|
queryResultErrors?: QueryResultErrors
|
|
1711
1724
|
}> {
|
|
1725
|
+
const formattedResult: QueryResult = queryResult
|
|
1726
|
+
// Make sure to reconvert the dates to Date objects
|
|
1727
|
+
if (formattedResult.birthdate && formattedResult.birthdate.disclose) {
|
|
1728
|
+
formattedResult.birthdate.disclose.result = new Date(
|
|
1729
|
+
formattedResult.birthdate.disclose.result,
|
|
1730
|
+
)
|
|
1731
|
+
}
|
|
1732
|
+
if (formattedResult.expiry_date && formattedResult.expiry_date.disclose) {
|
|
1733
|
+
formattedResult.expiry_date.disclose.result = new Date(
|
|
1734
|
+
formattedResult.expiry_date.disclose.result,
|
|
1735
|
+
)
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1712
1738
|
const { BarretenbergVerifier } = await import("@aztec/bb.js")
|
|
1713
1739
|
const verifier = new BarretenbergVerifier()
|
|
1714
1740
|
let verified = true
|
|
@@ -1718,7 +1744,7 @@ export class ZKPassport {
|
|
|
1718
1744
|
isCorrect,
|
|
1719
1745
|
uniqueIdentifier: uniqueIdentifierFromPublicInputs,
|
|
1720
1746
|
queryResultErrors: queryResultErrorsFromPublicInputs,
|
|
1721
|
-
} = await this.checkPublicInputs(proofs,
|
|
1747
|
+
} = await this.checkPublicInputs(proofs, formattedResult, validity)
|
|
1722
1748
|
uniqueIdentifier = uniqueIdentifierFromPublicInputs
|
|
1723
1749
|
verified = isCorrect
|
|
1724
1750
|
queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs
|