Skip to content

Commit

Permalink
Merge branch 'dev' into update/openpassport-zk-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
motemotech committed Oct 28, 2024
2 parents 7966723 + 61592f1 commit bf54241
Show file tree
Hide file tree
Showing 34 changed files with 374 additions and 120 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
1 change: 1 addition & 0 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "prettier --check ."
},
"dependencies": {
"@ashpect/smt": "https://github.com/ashpect/smt#main",
"@babel/runtime": "^7.23.4",
"@openpassport/zk-kit-imt": "^0.0.4",
"@openpassport/zk-kit-lean-imt": "^0.0.4",
Expand Down
2 changes: 1 addition & 1 deletion common/src/utils/csca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as forge from "node-forge";
import { bytesToBigDecimal, extractRSFromSignature, getNAndK, getNAndKCSCA, hexToDecimal, splitToWords } from "./utils";
import { CSCA_TREE_DEPTH, MODAL_SERVER_ADDRESS } from "../constants/constants";
import { poseidon2 } from "poseidon-lite";
import { IMT } from "@openpassport/zk-kit-imt";
import { IMT } from "@zk-kit/imt";
import serialized_csca_tree from "../../pubkeys/serialized_csca_tree.json"
import axios from "axios";
import { parseCertificate } from "./certificates/handleCertificate";
Expand Down
7 changes: 3 additions & 4 deletions common/src/utils/generateInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import {
formatCountriesList,
} from './utils';
import { generateCommitment, getLeaf } from "./pubkeyTree";
// import { LeanIMT } from "@zk-kit/imt";
import { LeanIMT } from "@openpassport/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 "@openpassport/zk-kit-smt"
import { SMT } from "@ashpect/smt"
import { parseCertificate } from './certificates/handleCertificate';

export function generateCircuitInputsDisclose(
Expand Down Expand Up @@ -269,4 +268,4 @@ export function formatInput(input: any) {
} else {
return [BigInt(input).toString()];
}
}
}
25 changes: 8 additions & 17 deletions common/src/utils/pubkeyTree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PUBKEY_TREE_DEPTH, COMMITMENT_TREE_TRACKER_URL, SignatureAlgorithmIndex } from "../constants/constants";
import { LeanIMT } from "@openpassport/zk-kit-lean-imt";
import { LeanIMT } from '@zk-kit/imt'
import axios from "axios";
import { poseidon16, poseidon2, poseidon6, poseidon7 } from 'poseidon-lite';
import { formatDg2Hash, getNAndK, getNAndKCSCA, hexToDecimal, splitToWords } from './utils';
Expand Down Expand Up @@ -65,18 +65,13 @@ export function getLeafCSCA(dsc: string): string {
return customHasher([sigAlgIndex, ...pubkeyChunked]);
}
}

export async function getTreeFromTracker(): Promise<LeanIMT> {
const response = await axios.get(COMMITMENT_TREE_TRACKER_URL)

const parsedResponse: string[][] = JSON.parse(response.data);
const commitmentTreeData: string = JSON.stringify(parsedResponse);

const imt = LeanIMT.import<bigint>(
const imt = new LeanIMT(
(a: bigint, b: bigint) => poseidon2([a, b]),
commitmentTreeData,
(value: string) => BigInt(value)
);
[]
);
imt.import(response.data)
return imt
}

Expand All @@ -100,13 +95,9 @@ export async function fetchTreeFromUrl(url: string): Promise<LeanIMT> {
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 = LeanIMT.import<bigint>(
(a: bigint, b: bigint) => poseidon2([a, b]),
commitmentMerkleTree,
(value: string) => BigInt(value)
);
const tree = new LeanIMT((a, b) => poseidon2([a, b]));
tree.import(commitmentMerkleTree);
return tree;
}
}
4 changes: 2 additions & 2 deletions common/src/utils/smtTree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { poseidon9, poseidon3, poseidon2, poseidon6, poseidon13 } from "poseidon-lite"
import { stringToAsciiBigIntArray } from "./utils";
import { SMT, ChildNodes } from "@openpassport/zk-kit-smt";
import { ChildNodes, SMT } from "@ashpect/smt"

// SMT trees for 3 levels :
// 1. Passport tree : level 3 (Absolute Match)
Expand Down Expand Up @@ -197,4 +197,4 @@ export function getDobLeaf(dobMrz: (bigint | number)[], i?: number): bigint {
} catch (err) {
console.log('err : Dob', err, i, dobMrz)
}
}
}
6 changes: 3 additions & 3 deletions common/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LeanIMT } from '@openpassport/zk-kit-lean-imt';
import { LeanIMT } from '@zk-kit/imt';
import { sha256 } from 'js-sha256';
import { sha1 } from 'js-sha1';
import { sha384, sha512_256 } from 'js-sha512';
import { SMT } from '@openpassport/zk-kit-smt';
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';
Expand Down Expand Up @@ -583,4 +583,4 @@ 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;
}
}
4 changes: 4 additions & 0 deletions common/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# yarn lockfile v1


"@ashpect/smt@https://github.com/ashpect/smt#main":
version "1.0.0"
resolved "https://github.com/ashpect/smt#4f73fd24adb06a7f8efd6fd2d3ed58e9e2f2691a"

"@babel/runtime@^7.23.4":
version "7.25.9"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.9.tgz#65884fd6dc255a775402cc1d9811082918f4bf00"
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.
Loading

0 comments on commit bf54241

Please sign in to comment.