From 34eba4c6f2de38f509fb6f43887804e37d7036e4 Mon Sep 17 00:00:00 2001 From: turnoffthiscomputer Date: Wed, 16 Oct 2024 11:43:25 -0700 Subject: [PATCH] yarn format --- circuits/tests/disclose/disclose.test.ts | 15 +- .../tests/other_circuits/leaf_hasher.test.ts | 17 +- sdk/package.json | 2 +- sdk/src/AttestationVerifier.ts | 492 +++++++++--------- sdk/src/OpenPassportVerifier.ts | 2 +- sdk/src/QRcode/OpenPassportQRcode.d.ts | 1 - sdk/src/QRcode/utils/websocket.ts | 86 +-- sdk/tests/web-app/src/app/disclose/page.tsx | 10 +- sdk/tests/web-app/src/app/register/page.tsx | 18 +- sdk/tsconfig.json | 9 +- sdk/utils/utils.ts | 7 +- 11 files changed, 341 insertions(+), 318 deletions(-) diff --git a/circuits/tests/disclose/disclose.test.ts b/circuits/tests/disclose/disclose.test.ts index a45b3eac..794b958f 100644 --- a/circuits/tests/disclose/disclose.test.ts +++ b/circuits/tests/disclose/disclose.test.ts @@ -64,9 +64,20 @@ describe('Disclose', function () { const forbidden_countries_list = ['ALG', 'DZA']; inputs = generateCircuitInputsDisclose( - secret, PASSPORT_ATTESTATION_ID, passportData, scope, selector_dg1, selector_older_than, tree, majority, smt, selector_ofac, forbidden_countries_list, user_identifier + secret, + PASSPORT_ATTESTATION_ID, + passportData, + scope, + selector_dg1, + selector_older_than, + tree, + majority, + smt, + selector_ofac, + forbidden_countries_list, + user_identifier ); - console.log("inputs", inputs); + console.log('inputs', inputs); }); it('should compile and load the circuit', async function () { diff --git a/circuits/tests/other_circuits/leaf_hasher.test.ts b/circuits/tests/other_circuits/leaf_hasher.test.ts index 6800b10a..cb364d4d 100644 --- a/circuits/tests/other_circuits/leaf_hasher.test.ts +++ b/circuits/tests/other_circuits/leaf_hasher.test.ts @@ -11,7 +11,14 @@ import { mock_csca_sha1_rsa_2048, mock_dsc_sha256_ecdsa, } from '../../../common/src/constants/mockCertificates'; -import { formatDg2Hash, formatMrz, hexToDecimal, packBytes, splitToWords, toUnsignedByte } from '../../../common/src/utils/utils'; +import { + formatDg2Hash, + formatMrz, + hexToDecimal, + packBytes, + splitToWords, + toUnsignedByte, +} from '../../../common/src/utils/utils'; import { getLeaf, customHasher, generateCommitment } from '../../../common/src/utils/pubkeyTree'; import { k_dsc, @@ -115,7 +122,13 @@ describe('LeafHasher Light', function () { const leafValueCircom = (await circuit.getOutput(witness, ['out'])).out; console.log('\x1b[34m', 'hashValueCircom: ', leafValueCircom, '\x1b[0m'); const mrz_bytes_packed = packBytes(formattedMrz); - const commitment = generateCommitment(BigInt(secret).toString(), BigInt(attestation_id).toString(), BigInt(leaf).toString(), mrz_bytes_packed, dg2HashFormatted); + const commitment = generateCommitment( + BigInt(secret).toString(), + BigInt(attestation_id).toString(), + BigInt(leaf).toString(), + mrz_bytes_packed, + dg2HashFormatted + ); console.log('\x1b[34m', 'commitment in js : ', commitment, '\x1b[0m'); expect(BigInt(leafValueCircom).toString()).to.equal(BigInt(commitment).toString()); }); diff --git a/sdk/package.json b/sdk/package.json index 2a73dd6b..c56341e8 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -81,4 +81,4 @@ "react": "^18.0.0", "react-dom": "^18.0.0" } -} \ No newline at end of file +} diff --git a/sdk/src/AttestationVerifier.ts b/sdk/src/AttestationVerifier.ts index 1e43489c..e449acb1 100644 --- a/sdk/src/AttestationVerifier.ts +++ b/sdk/src/AttestationVerifier.ts @@ -1,36 +1,36 @@ import { groth16 } from 'snarkjs'; import { - n_dsc, - k_dsc, - ECDSA_K_LENGTH_FACTOR, - k_dsc_ecdsa, - circuitNameFromMode, - countryNames, - countryCodes, + n_dsc, + k_dsc, + ECDSA_K_LENGTH_FACTOR, + k_dsc_ecdsa, + circuitNameFromMode, + countryNames, + countryCodes, } from '../../common/src/constants/constants'; import { - areArraysEqual, - getCurrentDateFormatted, - getVkeyFromArtifacts, - verifyDSCValidity, + areArraysEqual, + getCurrentDateFormatted, + getVkeyFromArtifacts, + verifyDSCValidity, } from '../utils/utils'; import { - OpenPassportAttestation, - parsePublicSignalsDisclose + OpenPassportAttestation, + parsePublicSignalsDisclose, } from '../../common/src/utils/openPassportAttestation'; import { - parsePublicSignalsDsc, - parsePublicSignalsProve, + parsePublicSignalsDsc, + parsePublicSignalsProve, } from '../../common/src/utils/openPassportAttestation'; import { Mode } from 'fs'; import forge from 'node-forge'; import { parseCertificate } from '../../common/src/utils/certificates/handleCertificate'; import { - castToScope, - formatForbiddenCountriesListFromCircuitOutput, - getAttributeFromUnpackedReveal, - getOlderThanFromCircuitOutput, - splitToWords, + castToScope, + formatForbiddenCountriesListFromCircuitOutput, + getAttributeFromUnpackedReveal, + getOlderThanFromCircuitOutput, + splitToWords, } from '../../common/src/utils/utils'; import { unpackReveal } from '../../common/src/utils/revealBitmap'; import { getCSCAModulusMerkleTree } from '../../common/src/utils/csca'; @@ -38,263 +38,255 @@ import { OpenPassportVerifierReport } from './OpenPassportVerifierReport'; import { fetchTreeFromUrl } from '../../common/src/utils/pubkeyTree'; export class AttestationVerifier { - protected devMode: boolean; - protected scope: string; - protected report: OpenPassportVerifierReport; - protected minimumAge: { enabled: boolean; value: string } = { enabled: false, value: '18' }; - protected nationality: { enabled: boolean; value: (typeof countryNames)[number] } = { - enabled: false, - value: '' as (typeof countryNames)[number], - }; - protected excludedCountries: { enabled: boolean; value: (typeof countryNames)[number][] } = { - enabled: false, - value: [], - }; - protected ofac: boolean = false; - protected commitmentMerkleTreeUrl: string = ''; + protected devMode: boolean; + protected scope: string; + protected report: OpenPassportVerifierReport; + protected minimumAge: { enabled: boolean; value: string } = { enabled: false, value: '18' }; + protected nationality: { enabled: boolean; value: (typeof countryNames)[number] } = { + enabled: false, + value: '' as (typeof countryNames)[number], + }; + protected excludedCountries: { enabled: boolean; value: (typeof countryNames)[number][] } = { + enabled: false, + value: [], + }; + protected ofac: boolean = false; + protected commitmentMerkleTreeUrl: string = ''; + constructor(devMode: boolean = false) { + this.devMode = devMode; + this.report = new OpenPassportVerifierReport(); + } - constructor(devMode: boolean = false) { - this.devMode = devMode; - this.report = new OpenPassportVerifierReport(); - } - - public async verify(attestation: OpenPassportAttestation): Promise { - const kScaled = - attestation.proof.signatureAlgorithm === 'ecdsa' - ? ECDSA_K_LENGTH_FACTOR * k_dsc_ecdsa - : k_dsc; + public async verify(attestation: OpenPassportAttestation): Promise { + const kScaled = + attestation.proof.signatureAlgorithm === 'ecdsa' + ? ECDSA_K_LENGTH_FACTOR * k_dsc_ecdsa + : k_dsc; - let parsedPublicSignals; - if (attestation.proof.mode === 'vc_and_disclose') { - parsedPublicSignals = parsePublicSignalsDisclose( - attestation.proof.value.publicSignals - ); - } else { - parsedPublicSignals = parsePublicSignalsProve( - attestation.proof.value.publicSignals, - kScaled - ); - } + let parsedPublicSignals; + if (attestation.proof.mode === 'vc_and_disclose') { + parsedPublicSignals = parsePublicSignalsDisclose(attestation.proof.value.publicSignals); + } else { + parsedPublicSignals = parsePublicSignalsProve(attestation.proof.value.publicSignals, kScaled); + } - this.verifyAttribute('scope', castToScope(parsedPublicSignals.scope), this.scope); + this.verifyAttribute('scope', castToScope(parsedPublicSignals.scope), this.scope); - await this.verifyProof( - attestation.proof.mode, - attestation.proof.value.proof, - attestation.proof.value.publicSignals, - attestation.proof.signatureAlgorithm, - attestation.proof.hashFunction - ); + await this.verifyProof( + attestation.proof.mode, + attestation.proof.value.proof, + attestation.proof.value.publicSignals, + attestation.proof.signatureAlgorithm, + attestation.proof.hashFunction + ); - switch (attestation.proof.mode) { - case 'register': - await this.verifyRegister(attestation); - break; - case 'prove_onchain': - await this.verifyProveOnChain(attestation); - break; - case 'prove_offchain': - await this.verifyProveOffChain(attestation); - break; - case 'vc_and_disclose': - await this.verifyDisclose(attestation); - break; - } - return this.report; + switch (attestation.proof.mode) { + case 'register': + await this.verifyRegister(attestation); + break; + case 'prove_onchain': + await this.verifyProveOnChain(attestation); + break; + case 'prove_offchain': + await this.verifyProveOffChain(attestation); + break; + case 'vc_and_disclose': + await this.verifyDisclose(attestation); + break; } + return this.report; + } - private async verifyRegister(attestation: OpenPassportAttestation) { - // verify dscProof - await this.verifyDscProof(attestation); - // verify that the blinded dscCommitments of proof and dscProof match - this.verifyBlindedDscCommitments(attestation); - // verify the root of the csca merkle tree - this.verifyCSCARoot(attestation); - } + private async verifyRegister(attestation: OpenPassportAttestation) { + // verify dscProof + await this.verifyDscProof(attestation); + // verify that the blinded dscCommitments of proof and dscProof match + this.verifyBlindedDscCommitments(attestation); + // verify the root of the csca merkle tree + this.verifyCSCARoot(attestation); + } - private async verifyProveOffChain(attestation: OpenPassportAttestation) { - // verify disclose attributes - this.verifyDiscloseAttributes(attestation); - // verify certificate chain - this.verifyCertificateChain(attestation); - } + private async verifyProveOffChain(attestation: OpenPassportAttestation) { + // verify disclose attributes + this.verifyDiscloseAttributes(attestation); + // verify certificate chain + this.verifyCertificateChain(attestation); + } - private async verifyProveOnChain(attestation: OpenPassportAttestation) { - // verify attributes - this.verifyDiscloseAttributes(attestation); - // verify the dsc proof - await this.verifyDscProof(attestation); - // verify that the blinded dscCommitments of proof and dscProof match - this.verifyBlindedDscCommitments(attestation); - // verify the root of the csca merkle tree - this.verifyCSCARoot(attestation); - } + private async verifyProveOnChain(attestation: OpenPassportAttestation) { + // verify attributes + this.verifyDiscloseAttributes(attestation); + // verify the dsc proof + await this.verifyDscProof(attestation); + // verify that the blinded dscCommitments of proof and dscProof match + this.verifyBlindedDscCommitments(attestation); + // verify the root of the csca merkle tree + this.verifyCSCARoot(attestation); + } + + private async verifyDisclose(attestation: OpenPassportAttestation) { + // verify the root of the commitment + this.verifyCommitment(attestation); + // verify disclose attributes + this.verifyDiscloseAttributes(attestation); + } - private async verifyDisclose(attestation: OpenPassportAttestation) { - // verify the root of the commitment - this.verifyCommitment(attestation); - // verify disclose attributes - this.verifyDiscloseAttributes(attestation); + private verifyDiscloseAttributes(attestation: OpenPassportAttestation) { + let parsedPublicSignals; + if (attestation.proof.mode === 'vc_and_disclose') { + parsedPublicSignals = parsePublicSignalsDisclose(attestation.proof.value.publicSignals); + } else { + parsedPublicSignals = parsePublicSignalsProve(attestation.proof.value.publicSignals, k_dsc); } + this.verifyAttribute( + 'current_date', + parsedPublicSignals.current_date.toString(), + getCurrentDateFormatted().toString() + ); - private verifyDiscloseAttributes(attestation: OpenPassportAttestation) { - let parsedPublicSignals; - if (attestation.proof.mode === 'vc_and_disclose') { - parsedPublicSignals = parsePublicSignalsDisclose( - attestation.proof.value.publicSignals - ); - } else { - parsedPublicSignals = parsePublicSignalsProve( - attestation.proof.value.publicSignals, - k_dsc - ); - } - this.verifyAttribute( - 'current_date', - parsedPublicSignals.current_date.toString(), - getCurrentDateFormatted().toString() + const unpackedReveal = unpackReveal(parsedPublicSignals.revealedData_packed); + if (this.minimumAge.enabled) { + const attributeValueInt = getOlderThanFromCircuitOutput(parsedPublicSignals.older_than); + const selfAttributeOlderThan = parseInt(this.minimumAge.value); + if (attributeValueInt < selfAttributeOlderThan) { + this.report.exposeAttribute( + 'older_than', + attributeValueInt.toString(), + this.minimumAge.value.toString() ); - - const unpackedReveal = unpackReveal(parsedPublicSignals.revealedData_packed); - if (this.minimumAge.enabled) { - const attributeValueInt = getOlderThanFromCircuitOutput(parsedPublicSignals.older_than); - const selfAttributeOlderThan = parseInt(this.minimumAge.value); - if (attributeValueInt < selfAttributeOlderThan) { - this.report.exposeAttribute( - 'older_than', - attributeValueInt.toString(), - this.minimumAge.value.toString() - ); - } else { - console.log('\x1b[32m%s\x1b[0m', '- minimum age verified'); - } - } - if (this.nationality.enabled) { - const attributeValue = getAttributeFromUnpackedReveal(unpackedReveal, 'nationality'); - this.verifyAttribute('nationality', countryCodes[attributeValue], this.nationality.value); - } - if (this.ofac) { - const attributeValue = parsedPublicSignals.ofac_result.toString(); - this.verifyAttribute('ofac', attributeValue, '1'); - } - if (this.excludedCountries.enabled) { - const formattedCountryList = formatForbiddenCountriesListFromCircuitOutput( - parsedPublicSignals.forbidden_countries_list_packed_disclosed - ); - const formattedCountryListFullCountryNames = formattedCountryList.map( - (countryCode) => countryCodes[countryCode] - ); - this.verifyAttribute( - 'forbidden_countries_list', - formattedCountryListFullCountryNames.toString(), - this.excludedCountries.value.toString() - ); - } + } else { + console.log('\x1b[32m%s\x1b[0m', '- minimum age verified'); + } } - - private verifyCSCARoot(attestation: OpenPassportAttestation) { - // verify the root of the csca merkle tree - const parsedDscPublicSignals = parsePublicSignalsDsc(attestation.dscProof.value.publicSignals); - const cscaMerkleTreeFromDscProof = parsedDscPublicSignals.merkle_root; - const cscaMerkleTree = getCSCAModulusMerkleTree(); - const cscaRoot = cscaMerkleTree.root; - this.verifyAttribute('merkle_root_csca', cscaRoot, cscaMerkleTreeFromDscProof); + if (this.nationality.enabled) { + const attributeValue = getAttributeFromUnpackedReveal(unpackedReveal, 'nationality'); + this.verifyAttribute('nationality', countryCodes[attributeValue], this.nationality.value); } - - private async verifyCommitment(attestation: OpenPassportAttestation) { - const tree = await fetchTreeFromUrl(this.commitmentMerkleTreeUrl); - const parsedPublicSignals = parsePublicSignalsDisclose(attestation.proof.value.publicSignals); - this.verifyAttribute('merkle_root_commitment', tree.root.toString(), parsedPublicSignals.merkle_root); - + if (this.ofac) { + const attributeValue = parsedPublicSignals.ofac_result.toString(); + this.verifyAttribute('ofac', attributeValue, '1'); + } + if (this.excludedCountries.enabled) { + const formattedCountryList = formatForbiddenCountriesListFromCircuitOutput( + parsedPublicSignals.forbidden_countries_list_packed_disclosed + ); + const formattedCountryListFullCountryNames = formattedCountryList.map( + (countryCode) => countryCodes[countryCode] + ); + this.verifyAttribute( + 'forbidden_countries_list', + formattedCountryListFullCountryNames.toString(), + this.excludedCountries.value.toString() + ); } + } - private verifyCertificateChain(attestation: OpenPassportAttestation) { - const dscCertificate = forge.pki.certificateFromPem(attestation.dsc.value); - const verified_certificate = verifyDSCValidity(dscCertificate, this.devMode); - if (!verified_certificate) { - this.report.exposeAttribute('dsc', attestation.dsc.value, 'certificate chain is not valid'); - } else { - console.log('\x1b[32m%s\x1b[0m', '- certificate verified'); - } + private verifyCSCARoot(attestation: OpenPassportAttestation) { + // verify the root of the csca merkle tree + const parsedDscPublicSignals = parsePublicSignalsDsc(attestation.dscProof.value.publicSignals); + const cscaMerkleTreeFromDscProof = parsedDscPublicSignals.merkle_root; + const cscaMerkleTree = getCSCAModulusMerkleTree(); + const cscaRoot = cscaMerkleTree.root; + this.verifyAttribute('merkle_root_csca', cscaRoot, cscaMerkleTreeFromDscProof); + } - const parsedDsc = parseCertificate(attestation.dsc.value); - const signatureAlgorithmDsc = parsedDsc.signatureAlgorithm; - if (signatureAlgorithmDsc === 'ecdsa') { - throw new Error('ECDSA not supported yet'); - } else { - const dscModulus = parsedDsc.modulus; - const dscModulusBigInt = BigInt(`0x${dscModulus}`); - const dscModulusWords = splitToWords(dscModulusBigInt, n_dsc, k_dsc); - const pubKeyFromProof = parsePublicSignalsProve( - attestation.proof.value.publicSignals, - k_dsc - ).pubKey_disclosed; + private async verifyCommitment(attestation: OpenPassportAttestation) { + const tree = await fetchTreeFromUrl(this.commitmentMerkleTreeUrl); + const parsedPublicSignals = parsePublicSignalsDisclose(attestation.proof.value.publicSignals); + this.verifyAttribute( + 'merkle_root_commitment', + tree.root.toString(), + parsedPublicSignals.merkle_root + ); + } - const verified_modulus = areArraysEqual(dscModulusWords, pubKeyFromProof); - if (!verified_modulus) { - this.report.exposeAttribute( - 'pubKey', - pubKeyFromProof, - 'pubKey from proof does not match pubKey from DSC certificate' - ); - } else { - console.log('\x1b[32m%s\x1b[0m', '- modulus verified'); - } - } + private verifyCertificateChain(attestation: OpenPassportAttestation) { + const dscCertificate = forge.pki.certificateFromPem(attestation.dsc.value); + const verified_certificate = verifyDSCValidity(dscCertificate, this.devMode); + if (!verified_certificate) { + this.report.exposeAttribute('dsc', attestation.dsc.value, 'certificate chain is not valid'); + } else { + console.log('\x1b[32m%s\x1b[0m', '- certificate verified'); } - private verifyBlindedDscCommitments(attestation: OpenPassportAttestation) { - const parsedPublicSignals = parsePublicSignalsProve( - attestation.proof.value.publicSignals, - k_dsc - ); - const proofBlindedDscCommitment = parsedPublicSignals.blinded_dsc_commitment; + const parsedDsc = parseCertificate(attestation.dsc.value); + const signatureAlgorithmDsc = parsedDsc.signatureAlgorithm; + if (signatureAlgorithmDsc === 'ecdsa') { + throw new Error('ECDSA not supported yet'); + } else { + const dscModulus = parsedDsc.modulus; + const dscModulusBigInt = BigInt(`0x${dscModulus}`); + const dscModulusWords = splitToWords(dscModulusBigInt, n_dsc, k_dsc); + const pubKeyFromProof = parsePublicSignalsProve( + attestation.proof.value.publicSignals, + k_dsc + ).pubKey_disclosed; - const parsedDscPublicSignals = parsePublicSignalsDsc(attestation.dscProof.value.publicSignals); - const dscBlindedDscCommitment = parsedDscPublicSignals.blinded_dsc_commitment; - - this.verifyAttribute( - 'blinded_dsc_commitment', - proofBlindedDscCommitment, - dscBlindedDscCommitment + const verified_modulus = areArraysEqual(dscModulusWords, pubKeyFromProof); + if (!verified_modulus) { + this.report.exposeAttribute( + 'pubKey', + pubKeyFromProof, + 'pubKey from proof does not match pubKey from DSC certificate' ); + } else { + console.log('\x1b[32m%s\x1b[0m', '- modulus verified'); + } } + } - private async verifyProof( - mode: Mode, - proof: string[], - publicSignals: string[], - signatureAlgorithm: string, - hashFunction: string - ): Promise { - const circuitName = circuitNameFromMode[mode]; - const vkey = getVkeyFromArtifacts(circuitName, signatureAlgorithm, hashFunction); - const isVerified = await groth16.verify(vkey, publicSignals, proof as any); - this.verifyAttribute('proof', isVerified.toString(), 'true'); - } + private verifyBlindedDscCommitments(attestation: OpenPassportAttestation) { + const parsedPublicSignals = parsePublicSignalsProve( + attestation.proof.value.publicSignals, + k_dsc + ); + const proofBlindedDscCommitment = parsedPublicSignals.blinded_dsc_commitment; - private async verifyDscProof(attestation: OpenPassportAttestation) { - const dscSignatureAlgorithm = attestation.dscProof.signatureAlgorithm; - const dscHashFunction = attestation.dscProof.hashFunction; - const vkey = getVkeyFromArtifacts('dsc', dscSignatureAlgorithm, dscHashFunction); - const isVerified = await groth16.verify( - vkey, - attestation.dscProof.value.publicSignals, - attestation.dscProof.value.proof as any - ); - this.verifyAttribute('dscProof', isVerified.toString(), 'true'); - } + const parsedDscPublicSignals = parsePublicSignalsDsc(attestation.dscProof.value.publicSignals); + const dscBlindedDscCommitment = parsedDscPublicSignals.blinded_dsc_commitment; + + this.verifyAttribute( + 'blinded_dsc_commitment', + proofBlindedDscCommitment, + dscBlindedDscCommitment + ); + } + + private async verifyProof( + mode: Mode, + proof: string[], + publicSignals: string[], + signatureAlgorithm: string, + hashFunction: string + ): Promise { + const circuitName = circuitNameFromMode[mode]; + const vkey = getVkeyFromArtifacts(circuitName, signatureAlgorithm, hashFunction); + const isVerified = await groth16.verify(vkey, publicSignals, proof as any); + this.verifyAttribute('proof', isVerified.toString(), 'true'); + } + + private async verifyDscProof(attestation: OpenPassportAttestation) { + const dscSignatureAlgorithm = attestation.dscProof.signatureAlgorithm; + const dscHashFunction = attestation.dscProof.hashFunction; + const vkey = getVkeyFromArtifacts('dsc', dscSignatureAlgorithm, dscHashFunction); + const isVerified = await groth16.verify( + vkey, + attestation.dscProof.value.publicSignals, + attestation.dscProof.value.proof as any + ); + this.verifyAttribute('dscProof', isVerified.toString(), 'true'); + } - private verifyAttribute( - attribute: keyof OpenPassportVerifierReport, - value: string, - expectedValue: string - ) { - if (value !== expectedValue) { - this.report.exposeAttribute(attribute, value, expectedValue); - } else { - console.log('\x1b[32m%s\x1b[0m', `- attribute ${attribute} verified`); - } + private verifyAttribute( + attribute: keyof OpenPassportVerifierReport, + value: string, + expectedValue: string + ) { + if (value !== expectedValue) { + this.report.exposeAttribute(attribute, value, expectedValue); + } else { + console.log('\x1b[32m%s\x1b[0m', `- attribute ${attribute} verified`); } + } } diff --git a/sdk/src/OpenPassportVerifier.ts b/sdk/src/OpenPassportVerifier.ts index 9f3a357d..70eef0e9 100644 --- a/sdk/src/OpenPassportVerifier.ts +++ b/sdk/src/OpenPassportVerifier.ts @@ -125,7 +125,7 @@ export class OpenPassportVerifier extends AttestationVerifier { break; case 'register': if (!this.commitmentMerkleTreeUrl) { - throw new Error('Commitment merkle tree URL is required for mode \'register\''); + throw new Error("Commitment merkle tree URL is required for mode 'register'"); } const argsRegisterOnChain: ArgumentsRegister = { modalServerUrl: this.modalServerUrl, diff --git a/sdk/src/QRcode/OpenPassportQRcode.d.ts b/sdk/src/QRcode/OpenPassportQRcode.d.ts index fa2fa531..65f74187 100644 --- a/sdk/src/QRcode/OpenPassportQRcode.d.ts +++ b/sdk/src/QRcode/OpenPassportQRcode.d.ts @@ -15,4 +15,3 @@ interface OpenPassportQRcodeProps { declare const OpenPassportQRcode: React.FC; export { OpenPassportQRcode, OpenPassportQRcodeProps }; - diff --git a/sdk/src/QRcode/utils/websocket.ts b/sdk/src/QRcode/utils/websocket.ts index 3966b14d..366b1789 100644 --- a/sdk/src/QRcode/utils/websocket.ts +++ b/sdk/src/QRcode/utils/websocket.ts @@ -18,54 +18,54 @@ const handleWebSocketMessage = openPassportVerifier: OpenPassportVerifier, onSuccess: (proof: OpenPassportAttestation) => void ) => - async (data) => { - console.log('received mobile status:', data.status); - switch (data.status) { - case 'mobile_connected': - setProofStep(QRcodeSteps.MOBILE_CONNECTED); - break; - case 'mobile_disconnected': - setProofStep(QRcodeSteps.WAITING_FOR_MOBILE); - break; - case 'proof_generation_started': - setProofStep(QRcodeSteps.PROOF_GENERATION_STARTED); - break; - case 'proof_generated': - setProofStep(QRcodeSteps.PROOF_GENERATED); - break; - case 'proof_generation_failed': - setProofVerified(false); - setProofStep(QRcodeSteps.PROOF_VERIFIED); - console.log('Proof generation failed'); - break; - } + async (data) => { + console.log('received mobile status:', data.status); + switch (data.status) { + case 'mobile_connected': + setProofStep(QRcodeSteps.MOBILE_CONNECTED); + break; + case 'mobile_disconnected': + setProofStep(QRcodeSteps.WAITING_FOR_MOBILE); + break; + case 'proof_generation_started': + setProofStep(QRcodeSteps.PROOF_GENERATION_STARTED); + break; + case 'proof_generated': + setProofStep(QRcodeSteps.PROOF_GENERATED); + break; + case 'proof_generation_failed': + setProofVerified(false); + setProofStep(QRcodeSteps.PROOF_VERIFIED); + console.log('Proof generation failed'); + break; + } - if (data.proof) { - console.log(data.proof); - try { - const local_proofVerified = await openPassportVerifier.verify(data.proof); - setProofVerified(local_proofVerified.valid); - setProofStep(QRcodeSteps.PROOF_VERIFIED); - setTimeout(() => { - newSocket.emit('proof_verified', { - sessionId, - proofVerified: local_proofVerified.toString(), - }); - if (local_proofVerified) { - onSuccess(data.proof); - } - }, 1500); // wait for animation to finish before sending the proof to mobile - } catch (error) { - console.error('Error verifying proof:', error); - setProofVerified(false); - setProofStep(QRcodeSteps.PROOF_VERIFIED); + if (data.proof) { + console.log(data.proof); + try { + const local_proofVerified = await openPassportVerifier.verify(data.proof); + setProofVerified(local_proofVerified.valid); + setProofStep(QRcodeSteps.PROOF_VERIFIED); + setTimeout(() => { newSocket.emit('proof_verified', { sessionId, - proofVerified: { valid: false, error: error.message }, + proofVerified: local_proofVerified.toString(), }); - } + if (local_proofVerified) { + onSuccess(data.proof); + } + }, 1500); // wait for animation to finish before sending the proof to mobile + } catch (error) { + console.error('Error verifying proof:', error); + setProofVerified(false); + setProofStep(QRcodeSteps.PROOF_VERIFIED); + newSocket.emit('proof_verified', { + sessionId, + proofVerified: { valid: false, error: error.message }, + }); } - }; + } + }; export function initWebSocket( websocketUrl: string, diff --git a/sdk/tests/web-app/src/app/disclose/page.tsx b/sdk/tests/web-app/src/app/disclose/page.tsx index 44c8a335..90648bd1 100644 --- a/sdk/tests/web-app/src/app/disclose/page.tsx +++ b/sdk/tests/web-app/src/app/disclose/page.tsx @@ -8,7 +8,12 @@ export default function Prove() { const userId = uuidv4(); const scope = 'scope'; - const openPassportVerifierDisclose = new OpenPassportVerifier('vc_and_disclose', scope).setCommitmentMerkleTreeUrl(COMMITMENT_TREE_TRACKER_URL).excludeCountries('Albania').setMinimumAge(20).enableOFACCheck().setNationality('Germany'); + const openPassportVerifierDisclose = new OpenPassportVerifier('vc_and_disclose', scope) + .setCommitmentMerkleTreeUrl(COMMITMENT_TREE_TRACKER_URL) + .excludeCountries('Albania') + .setMinimumAge(20) + .enableOFACCheck() + .setNationality('Germany'); return (
{ - }} + onSuccess={(attestation) => {}} />
); diff --git a/sdk/tests/web-app/src/app/register/page.tsx b/sdk/tests/web-app/src/app/register/page.tsx index 1ff8fde5..dfd16d9a 100644 --- a/sdk/tests/web-app/src/app/register/page.tsx +++ b/sdk/tests/web-app/src/app/register/page.tsx @@ -8,7 +8,10 @@ import axios from 'axios'; export default function Prove() { const userId = uuidv4(); const scope = 'scope'; - const openPassportVerifier = new OpenPassportVerifier('register', scope).setCommitmentMerkleTreeUrl(COMMITMENT_TREE_TRACKER_URL); + const openPassportVerifier = new OpenPassportVerifier( + 'register', + scope + ).setCommitmentMerkleTreeUrl(COMMITMENT_TREE_TRACKER_URL); return (
{ - axios.post('https://proofofpassport-merkle-tree.xyz/api/verifier/register', attestation).then((response) => { - console.log('Registration response:', response); - }).catch((error) => { - console.error('Error registering attestation:', error); - }); + axios + .post('https://proofofpassport-merkle-tree.xyz/api/verifier/register', attestation) + .then((response) => { + console.log('Registration response:', response); + }) + .catch((error) => { + console.error('Error registering attestation:', error); + }); }} />
diff --git a/sdk/tsconfig.json b/sdk/tsconfig.json index cfec6421..88dfeace 100644 --- a/sdk/tsconfig.json +++ b/sdk/tsconfig.json @@ -23,10 +23,5 @@ "utils/utils.ts", "../common/src/utils/openPassportAttestation.ts" ], - "exclude": [ - "node_modules", - "**/__tests__/*", - "dist", - "common/src/utils/csca.ts" - ] -} \ No newline at end of file + "exclude": ["node_modules", "**/__tests__/*", "dist", "common/src/utils/csca.ts"] +} diff --git a/sdk/utils/utils.ts b/sdk/utils/utils.ts index 670d419e..09db70d3 100644 --- a/sdk/utils/utils.ts +++ b/sdk/utils/utils.ts @@ -15,7 +15,7 @@ import { vkey_dsc_rsa_65537_sha1, vkey_dsc_rsa_65537_sha256, vkey_dsc_rsapss_65537_sha256, - vkey_vc_and_disclose + vkey_vc_and_disclose, } from '../../common/src/constants/vkey'; import { getCircuitName } from '../../common/src/utils/certificates/handleCertificate'; @@ -28,7 +28,10 @@ export function getVkeyFromArtifacts( signatureAlgorithm: string, hashFunction: string ) { - const circuitName = circuit === 'vc_and_disclose' ? circuit : getCircuitName(circuit, signatureAlgorithm, hashFunction); + const circuitName = + circuit === 'vc_and_disclose' + ? circuit + : getCircuitName(circuit, signatureAlgorithm, hashFunction); // console.log('\x1b[90m%s\x1b[0m', 'circuit name:', circuitName); switch (circuitName) { case 'vc_and_disclose':