Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/openpassport zk kit #228

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"lint": "prettier --check ."
},
"dependencies": {
"@ashpect/smt": "https://github.com/ashpect/smt#main",
"@babel/runtime": "^7.23.4",
"@zk-kit/imt": "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675",
"@openpassport/zk-kit-imt": "^0.0.1",
"@openpassport/zk-kit-lean-imt": "^0.0.1",
"@openpassport/zk-kit-smt": "^0.0.1",
"asn1.js": "^5.4.1",
"asn1js": "^3.0.5",
"axios": "^1.7.2",
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 "@zk-kit/imt";
import { IMT } from "@openpassport/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: 4 additions & 3 deletions common/src/utils/generateInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {
formatCountriesList,
} from './utils';
import { generateCommitment, getLeaf } from "./pubkeyTree";
import { LeanIMT } from "@zk-kit/imt";
// import { LeanIMT } from "@zk-kit/imt";
import { LeanIMT } from "@openpassport/zk-kit-lean-imt";
import { getCountryLeaf, getNameLeaf, getNameDobLeaf, getPassportNumberLeaf } from "./smtTree";
import { packBytes } from "../utils/utils";
import { SMT } from "@ashpect/smt"
import { SMT } from "@openpassport/zk-kit-smt"
import { parseCertificate } from './certificates/handleCertificate';

export function generateCircuitInputsDisclose(
Expand Down Expand Up @@ -268,4 +269,4 @@ export function formatInput(input: any) {
} else {
return [BigInt(input).toString()];
}
}
}
25 changes: 17 additions & 8 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 '@zk-kit/imt'
import { LeanIMT } from "@openpassport/zk-kit-lean-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,13 +65,18 @@ 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 imt = new LeanIMT(

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

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

Expand All @@ -95,9 +100,13 @@ 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 = new LeanIMT((a, b) => poseidon2([a, b]));
tree.import(commitmentMerkleTree);
const tree = LeanIMT.import<bigint>(
(a: bigint, b: bigint) => poseidon2([a, b]),
commitmentMerkleTree,
(value: string) => BigInt(value)
);
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 { ChildNodes, SMT } from "@ashpect/smt"
import { SMT, ChildNodes } from "@openpassport/zk-kit-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 '@zk-kit/imt';
import { LeanIMT } from '@openpassport/zk-kit-lean-imt';
import { sha256 } from 'js-sha256';
import { sha1 } from 'js-sha1';
import { sha384, sha512_256 } from 'js-sha512';
import { SMT } from '@ashpect/smt';
import { SMT } from '@openpassport/zk-kit-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;
}
}
32 changes: 25 additions & 7 deletions common/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# 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 All @@ -18,6 +14,25 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0"
integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==

"@openpassport/zk-kit-imt@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@openpassport/zk-kit-imt/-/zk-kit-imt-0.0.1.tgz#4f68810fcd38f300054d8b8b4814f02a6534136b"
integrity sha512-wz4ApTvOYd2+XArOMsZgNKXfMVb/s1K3JRYJ6FcqU8duk6R3Sd90kfBgpf6wi+YZ92TrJtEO41jFWlkFX0YRGw==
dependencies:
"@zk-kit/utils" "1.2.1"

"@openpassport/zk-kit-lean-imt@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@openpassport/zk-kit-lean-imt/-/zk-kit-lean-imt-0.0.1.tgz#6fbd3e6207c621dfb947e9ea17e67326aaf3292a"
integrity sha512-6CeUEX951hbELDYfadFS5bRQyEbxAt/vPBoCeyRcPkwPmQj/2ys8D7XlGFulicdsNYHjW3V9oZ/CFLCr93shJA==
dependencies:
"@zk-kit/utils" "1.2.1"

"@openpassport/zk-kit-smt@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@openpassport/zk-kit-smt/-/zk-kit-smt-0.0.1.tgz#d447ed24e7b57146d5dee8d7458ac3886346b4d2"
integrity sha512-P7Hkd5fD8JxGbqJ48lUq6gGKmZTaVzCB5I8FsOSUmljqf7VMeZmbyqo2ZmXt/lk6ltPXrmcrQ+QNhHXKZNcWhg==

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand All @@ -37,9 +52,12 @@
dependencies:
undici-types "~6.19.2"

"@zk-kit/imt@https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675":
version "2.0.0-beta.1"
resolved "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675#38244ea6eef75dc1ad7fff3ff2a22dd5f1a2593a"
"@zk-kit/[email protected]":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@zk-kit/utils/-/utils-1.2.1.tgz#6cb38120535c73ab68cd0f09684882af148f256d"
integrity sha512-H2nTsyWdicVOyvqC5AjgU7tsTgmR6PDrruFJNmlmdhKp7RxEia/E1B1swMZjaasYa2QMp4Zc6oB7cWchty7B2Q==
dependencies:
buffer "^6.0.3"

ansi-colors@^4.1.3:
version "4.1.3"
Expand Down
Loading