update common dir to openpassport zk kit

This commit is contained in:
motemotech
2024-10-27 00:37:51 +09:00
parent 5abc98041d
commit ebfe4eb8a5
7 changed files with 69 additions and 26 deletions

View File

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

View File

@@ -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()];
}
}
}

View File

@@ -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,32 @@ export function getLeafCSCA(dsc: string): string {
return customHasher([sigAlgIndex, ...pubkeyChunked]);
}
}
type AnyNestedArray = any[];
function deepConvertStringsToBigInt(data: AnyNestedArray): any {
return data.map(item => {
if (Array.isArray(item)) {
return deepConvertStringsToBigInt(item);
} else if (typeof item === 'string') {
return BigInt(item);
} else {
// 予期しない型の場合はそのまま返す、またはエラーを投げる
return item;
}
});
}
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
}
@@ -95,9 +114,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;
}
}

View File

@@ -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)
}
}
}

View File

@@ -1,8 +1,8 @@
import { LeanIMT } from '@zk-kit/lean-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;
}
}