diff --git a/common/package.json b/common/package.json index da86d975..1692191f 100644 --- a/common/package.json +++ b/common/package.json @@ -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", diff --git a/common/src/utils/csca.ts b/common/src/utils/csca.ts index d394b753..e885e937 100644 --- a/common/src/utils/csca.ts +++ b/common/src/utils/csca.ts @@ -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"; diff --git a/common/src/utils/generateInputs.ts b/common/src/utils/generateInputs.ts index 37c0487e..5a73d588 100644 --- a/common/src/utils/generateInputs.ts +++ b/common/src/utils/generateInputs.ts @@ -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( @@ -268,4 +269,4 @@ export function formatInput(input: any) { } else { return [BigInt(input).toString()]; } -} +} \ No newline at end of file diff --git a/common/src/utils/pubkeyTree.ts b/common/src/utils/pubkeyTree.ts index 84814068..bdd44bea 100644 --- a/common/src/utils/pubkeyTree.ts +++ b/common/src/utils/pubkeyTree.ts @@ -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'; @@ -65,13 +65,18 @@ export function getLeafCSCA(dsc: string): string { return customHasher([sigAlgIndex, ...pubkeyChunked]); } } + export async function getTreeFromTracker(): Promise { 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( (a: bigint, b: bigint) => poseidon2([a, b]), - [] - ); - imt.import(response.data) + commitmentTreeData, + (value: string) => BigInt(value) + ); return imt } @@ -95,9 +100,13 @@ export async function fetchTreeFromUrl(url: string): Promise { 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( + (a: bigint, b: bigint) => poseidon2([a, b]), + commitmentMerkleTree, + (value: string) => BigInt(value) + ); return tree; -} +} \ No newline at end of file diff --git a/common/src/utils/smtTree.ts b/common/src/utils/smtTree.ts index 4f3d9d21..ee300ebe 100644 --- a/common/src/utils/smtTree.ts +++ b/common/src/utils/smtTree.ts @@ -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) @@ -197,4 +197,4 @@ export function getDobLeaf(dobMrz: (bigint | number)[], i?: number): bigint { } catch (err) { console.log('err : Dob', err, i, dobMrz) } -} +} \ No newline at end of file diff --git a/common/src/utils/utils.ts b/common/src/utils/utils.ts index 4a2fc688..3a37e0dd 100644 --- a/common/src/utils/utils.ts +++ b/common/src/utils/utils.ts @@ -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'; @@ -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; -} +} \ No newline at end of file diff --git a/common/yarn.lock b/common/yarn.lock index 275694c2..f31d85a8 100644 --- a/common/yarn.lock +++ b/common/yarn.lock @@ -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" @@ -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" @@ -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/utils@1.2.1": + 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"