Skip to content

Commit

Permalink
Merge pull request #229 from zk-passport/revert-228-update/openpasspo…
Browse files Browse the repository at this point in the history
…rt-zk-kit

Revert "Update/openpassport zk kit"
  • Loading branch information
remicolin authored Oct 27, 2024
2 parents 5865032 + ba28099 commit e3c5302
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 55 deletions.
5 changes: 2 additions & 3 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"lint": "prettier --check ."
},
"dependencies": {
"@ashpect/smt": "https://github.com/ashpect/smt#main",
"@babel/runtime": "^7.23.4",
"@openpassport/zk-kit-imt": "^0.0.1",
"@openpassport/zk-kit-lean-imt": "^0.0.1",
"@openpassport/zk-kit-smt": "^0.0.1",
"@zk-kit/imt": "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675",
"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 "@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;
}
}
32 changes: 7 additions & 25 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 All @@ -14,25 +18,6 @@
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 @@ -52,12 +37,9 @@
dependencies:
undici-types "~6.19.2"

"@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"
"@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"

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

0 comments on commit e3c5302

Please sign in to comment.