Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/zk-passport/openpassport int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
remicolin committed Oct 28, 2024
2 parents 5cddc9d + 61592f1 commit 07c4a0f
Show file tree
Hide file tree
Showing 27 changed files with 352 additions and 93 deletions.
47 changes: 28 additions & 19 deletions app/src/utils/qrCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,37 @@ export const scanQRCode = () => {

const handleQRCodeScan = (result: string, toast: any, setSelectedApp: any, setSelectedTab: any) => {
try {
const decodedResult = atob(result);
const uint8Array = new Uint8Array(decodedResult.split('').map(char => char.charCodeAt(0)));
const decompressedData = pako.inflate(uint8Array);
const unpackedData = msgpack.decode(decompressedData);
const openPassportApp: OpenPassportApp = unpackedData;
setSelectedApp(openPassportApp);
const dsc = useUserStore.getState().passportData?.dsc;
if (dsc) {

const dsc = useUserStore.getState().passportData.dsc;
const sigAlgName = parseDSC(dsc!);
const decodedResult = atob(result);
const uint8Array = new Uint8Array(decodedResult.split('').map(char => char.charCodeAt(0)));
const decompressedData = pako.inflate(uint8Array);
const unpackedData = msgpack.decode(decompressedData);
const openPassportApp: OpenPassportApp = unpackedData;
setSelectedApp(openPassportApp);

const circuitName = openPassportApp.mode === 'vc_and_disclose'
? 'vc_and_disclose'
: getCircuitName("prove" as Mode, sigAlgName.signatureAlgorithm, sigAlgName.hashFunction);
downloadZkey(circuitName as any);
const sigAlgName = parseDSC(dsc);

setSelectedTab("prove");
toast.show('✅', {
message: "QR code scanned",
customData: {
type: "success",
},
});
const circuitName = openPassportApp.mode === 'vc_and_disclose'
? 'vc_and_disclose'
: getCircuitName("prove" as Mode, sigAlgName.signatureAlgorithm, sigAlgName.hashFunction);
downloadZkey(circuitName as any);

setSelectedTab("prove");
toast.show('✅', {
message: "QR code scanned",
customData: {
type: "success",
},
});
}
else {
toast.show('Welcome', {
message: 'Please register your passport first',
type: 'info',
});
}
} catch (error) {
console.error('Error parsing QR code result:', error);
toast.show('Try again', {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions sdk/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { OpenPassportVerifierReport } from './src/OpenPassportVerifierReport';
import { OpenPassportVerifier } from './src/OpenPassportVerifier';
import { countryCodes } from '../../common/src/constants/constants';
import {
OpenPassportAttestation,
OpenPassportDynamicAttestation,
} from '../../common/src/utils/openPassportAttestation';
export {
OpenPassportVerifier,
OpenPassportAttestation,
OpenPassportDynamicAttestation,
OpenPassportVerifierReport,
countryCodes,
};
79 changes: 79 additions & 0 deletions sdk/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "@openpassport/core",
"version": "0.0.4",
"main": "dist/sdk/core/index.js",
"types": "dist/sdk/core/index.d.ts",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/zk-passport/openpassport"
},
"author": "turnoffthiscomputer",
"dependencies": {
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
"elliptic": "^6.5.7",
"fs": "^0.0.1-security",
"js-sha1": "^0.7.0",
"js-sha256": "^0.11.0",
"js-sha512": "^0.9.0",
"lottie-react": "^2.4.0",
"msgpack-lite": "^0.1.26",
"next": "^14.2.8",
"node-forge": "https://github.com/remicolin/forge",
"pako": "^2.1.0",
"pkijs": "^3.2.4",
"poseidon-lite": "^0.2.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"snarkjs": "^0.7.4",
"uuid": "^10.0.0",
"zlib": "^1.0.5",
"@zk-kit/imt": "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675"
},
"devDependencies": {
"@types/chai": "^4.3.6",
"@types/chai-as-promised": "^7.1.8",
"@types/circomlibjs": "^0.1.6",
"@types/expect": "^24.3.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.19",
"@types/node-forge": "^1.3.5",
"@types/pako": "^2.0.3",
"@types/snarkjs": "^0.7.8",
"asn1js": "^3.0.5",
"axios": "^1.7.2",
"chai": "^4.3.8",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.4.5",
"mocha": "^10.3.0",
"prettier": "^3.3.3",
"ts-loader": "^9.5.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "yarn ts-mocha -p ./tsconfig.json tests/openPassportVerifier.test.ts --exit",
"install-sdk": "cd ../common && yarn && cd ../sdk && yarn",
"download-circuits": "cd ../circuits && ./scripts/download_circuits_from_aws.sh && cd ../sdk",
"format": "prettier --write .",
"lint": "prettier --check ."
},
"files": [
"dist",
"common",
"circuits/**/*.json"
],
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"lottie-react": "^2.4.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
k_dsc_ecdsa,
countryNames,
countryCodes,
} from '../../common/src/constants/constants';
} from '../../../common/src/constants/constants';
import {
areArraysEqual,
getCurrentDateFormatted,
Expand All @@ -16,25 +16,23 @@ import {
import {
OpenPassportAttestation,
parsePublicSignalsDisclose,
} from '../../common/src/utils/openPassportAttestation';
import {
parsePublicSignalsDsc,
parsePublicSignalsProve,
} from '../../common/src/utils/openPassportAttestation';
} from '../../../common/src/utils/openPassportAttestation';
import { Mode } from 'fs';
import forge from 'node-forge';
import { parseCertificate } from '../../common/src/utils/certificates/handleCertificate';
import { parseCertificate } from '../../../common/src/utils/certificates/handleCertificate';
import {
castToScope,
formatForbiddenCountriesListFromCircuitOutput,
getAttributeFromUnpackedReveal,
getOlderThanFromCircuitOutput,
splitToWords,
} from '../../common/src/utils/utils';
import { unpackReveal } from '../../common/src/utils/revealBitmap';
import { getCSCAModulusMerkleTree } from '../../common/src/utils/csca';
} from '../../../common/src/utils/utils';
import { unpackReveal } from '../../../common/src/utils/revealBitmap';
import { getCSCAModulusMerkleTree } from '../../../common/src/utils/csca';
import { OpenPassportVerifierReport } from './OpenPassportVerifierReport';
import { fetchTreeFromUrl } from '../../common/src/utils/pubkeyTree';
import { fetchTreeFromUrl } from '../../../common/src/utils/pubkeyTree';

export class AttestationVerifier {
protected devMode: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import {
ArgumentsRegister,
Mode,
OpenPassportAppPartial,
} from '../../common/src/utils/appType';
OpenPassportApp
} from '../../../common/src/utils/appType';
import {
DEFAULT_RPC_URL,
MODAL_SERVER_ADDRESS,
WEBSOCKET_URL,
countryNames,
} from '../../common/src/constants/constants';
import { OpenPassportApp } from '../../common/src/utils/appType';
import { UserIdType } from '../../common/src/utils/utils';
} from '../../../common/src/constants/constants';
import { UserIdType } from '../../../common/src/utils/utils';
import * as pako from 'pako';
import msgpack from 'msgpack-lite';
import { OpenPassportAttestation } from '.';
import { AttestationVerifier } from './AttestationVerifier';
export class OpenPassportVerifier extends AttestationVerifier {
private mode: Mode;
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions sdk/tsconfig.json → sdk/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
"moduleResolution": "node"
},
"include": [
"src/index.ts",
"index.ts",
"src/index.node.ts",
"src/**/*",
"common/**/*",
"circuits/**/*",
"circuits/**/*.json",
"utils/utils.ts",
"../common/src/utils/openPassportAttestation.ts"
"../../common/src/utils/openPassportAttestation.ts"
],
"exclude": ["node_modules", "**/__tests__/*", "dist", "common/src/utils/csca.ts"]
}
"exclude": [
"node_modules",
"**/__tests__/*",
"dist",
"common/src/utils/csca.ts"
]
}
File renamed without changes.
24 changes: 12 additions & 12 deletions sdk/utils/utils.ts → sdk/core/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethers } from 'ethers';
import { getCurrentDateYYMMDD } from '../../common/src/utils/utils';
// import { ethers } from 'ethers';
import { getCurrentDateYYMMDD } from '../../../common/src/utils/utils';
import {
attributeToPosition,
circuitNameFromMode,
REGISTER_ABI,
REGISTER_CONTRACT_ADDRESS,
} from '../../common/src/constants/constants';
import { derToBytes } from '../../common/src/utils/csca';
} from '../../../common/src/constants/constants';
import { derToBytes } from '../../../common/src/utils/csca';
import forge from 'node-forge';
import { SKI_PEM, SKI_PEM_DEV } from './skiPem';
import {
Expand All @@ -17,8 +17,8 @@ import {
vkey_dsc_rsa_65537_sha256,
vkey_dsc_rsapss_65537_sha256,
vkey_vc_and_disclose,
} from '../../common/src/constants/vkey';
import { getCircuitName } from '../../common/src/utils/certificates/handleCertificate';
} from '../../../common/src/constants/vkey';
import { getCircuitName } from '../../../common/src/utils/certificates/handleCertificate';
import { Mode } from 'fs';

export function getCurrentDateFormatted() {
Expand Down Expand Up @@ -58,12 +58,12 @@ export function getVkeyFromArtifacts(
}
}

// OpenPassport2Step
export async function checkMerkleRoot(rpcUrl: string, merkleRoot: number) {
const provider = new ethers.JsonRpcProvider(rpcUrl);
const contract = new ethers.Contract(REGISTER_CONTRACT_ADDRESS, REGISTER_ABI, provider);
return await contract.checkRoot(merkleRoot);
}
// // OpenPassport2Step
// export async function checkMerkleRoot(rpcUrl: string, merkleRoot: number) {
// const provider = new ethers.JsonRpcProvider(rpcUrl);
// const contract = new ethers.Contract(REGISTER_CONTRACT_ADDRESS, REGISTER_ABI, provider);
// return await contract.checkRoot(merkleRoot);
// }

// OpenPassport1Step
function getCSCAPem(formattedValueAdjusted: string, dev_mode: boolean): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { OpenPassportAttestation, OpenPassportVerifier } from '..';
import { UserIdType } from '../../../common/src/utils/utils';
import { OpenPassportAttestation, OpenPassportVerifier } from '@openpassport/core';
import { UserIdType } from '../../common/src/utils/utils';

interface OpenPassportQRcodeProps {
appName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useEffect, useState } from 'react';
import { OpenPassportAttestation } from '../../../common/src/utils/openPassportAttestation';
import { OpenPassportVerifier } from '../OpenPassportVerifier';
import { OpenPassportAttestation } from '../../common/src/utils/openPassportAttestation';
import { OpenPassportVerifier } from '@openpassport/core';
import { BounceLoader } from 'react-spinners';
import Lottie from 'lottie-react';
import CHECK_ANIMATION from './animations/check_animation.json';
import X_ANIMATION from './animations/x_animation.json';
import LED from './components/LED';
import { WEBSOCKET_URL } from '../../../common/src/constants/constants';
import { UserIdType } from '../../../common/src/utils/utils';
import { WEBSOCKET_URL } from '../../common/src/constants/constants';
import { UserIdType } from '../../common/src/utils/utils';
import { v4 as uuidv4 } from 'uuid';
import { QRcodeSteps } from './utils/utils';
import { containerStyle, ledContainerStyle, qrContainerStyle } from './utils/styles';
Expand All @@ -27,6 +27,22 @@ interface OpenPassportQRcodeProps {
size?: number;
}

// Create a wrapper component that handles client-side rendering
const OpenPassportQRcodeWrapper: React.FC<OpenPassportQRcodeProps> = (props) => {
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
}, []);

if (!isClient) {
return null;
}

return <OpenPassportQRcode {...props} />;
};

// Your existing OpenPassportQRcode component
const OpenPassportQRcode: React.FC<OpenPassportQRcodeProps> = ({
appName,
userId,
Expand All @@ -37,7 +53,7 @@ const OpenPassportQRcode: React.FC<OpenPassportQRcodeProps> = ({
size = 300,
}) => {
const [proofStep, setProofStep] = useState(QRcodeSteps.WAITING_FOR_MOBILE);
const [proofVerified, setProofVerified] = useState(null);
const [proofVerified, setProofVerified] = useState(false);
const [sessionId, setSessionId] = useState(uuidv4());

useEffect(() => {
Expand Down Expand Up @@ -109,4 +125,4 @@ const OpenPassportQRcode: React.FC<OpenPassportQRcodeProps> = ({
return <div style={containerStyle}>{renderProofStatus()}</div>;
};

export { OpenPassportQRcode };
export default OpenPassportQRcodeWrapper;
Loading

0 comments on commit 07c4a0f

Please sign in to comment.