mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
add integration test for mint function
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { poseidon9, poseidon3, poseidon2, poseidon6, poseidon13 } from "poseidon-lite"
|
||||
import { stringToAsciiBigIntArray } from "./utils";
|
||||
import { ChildNodes,SMT } from "@ashpect/smt"
|
||||
import { hash, stringToAsciiBigIntArray } from "./utils";
|
||||
import { ChildNodes,SMT } from "@ashpect/smt";
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// SMT trees for 3 levels :
|
||||
// 1. Passport tree : level 3 (Absolute Match)
|
||||
@@ -47,6 +49,38 @@ export function buildSMT(field :any[], treetype:string): [number, number, SMT]{
|
||||
return [count, performance.now() - startTime, tree]
|
||||
}
|
||||
|
||||
export function exportSMTToJsonFile(count: number, time: number, smt: SMT, outputPath?: string) {
|
||||
const serializedSMT = smt.export();
|
||||
const data = {
|
||||
count: count,
|
||||
time: time,
|
||||
smt: serializedSMT
|
||||
};
|
||||
const jsonString = JSON.stringify(data, null, 2);
|
||||
const defaultPath = path.join(process.cwd(), 'smt.json');
|
||||
const finalPath = outputPath ? path.resolve(process.cwd(), outputPath) : defaultPath;
|
||||
|
||||
fs.writeFileSync(finalPath, jsonString, 'utf8');
|
||||
}
|
||||
|
||||
export function importSMTFromJsonFile(filePath?: string): SMT | null {
|
||||
try {
|
||||
const jsonString = fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf8');
|
||||
|
||||
const data = JSON.parse(jsonString);
|
||||
|
||||
const hash2 = (childNodes: ChildNodes) => (childNodes.length === 2 ? poseidon2(childNodes) : poseidon3(childNodes));
|
||||
const smt = new SMT(hash2, true);
|
||||
smt.import(data.smt);
|
||||
|
||||
console.log('Successfully imported SMT from JSON file');
|
||||
return smt;
|
||||
} catch (error) {
|
||||
console.error('Failed to import SMT from JSON file:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function processPassport(passno : string, index: number): bigint {
|
||||
if (passno.length > 9) {
|
||||
console.log('passport length is greater than 9:', index, passno)
|
||||
|
||||
@@ -5,6 +5,8 @@ import { sha384, sha512_256 } from 'js-sha512';
|
||||
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 * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function formatMrz(mrz: string) {
|
||||
const mrzCharcodes = [...mrz].map((char) => char.charCodeAt(0));
|
||||
@@ -351,6 +353,24 @@ export function generateSMTProof(smt: SMT, leaf: bigint) {
|
||||
};
|
||||
}
|
||||
|
||||
// I don't know if we need this function
|
||||
// export function saveSMTToJsonFile(count: number, time: number, smt: SMT, outputPath?: string): void {
|
||||
// const serializedSMT = smt.export();
|
||||
// const data = {
|
||||
// count: count,
|
||||
// time: time,
|
||||
// smt: serializedSMT
|
||||
// };
|
||||
|
||||
// const jsonString = JSON.stringify(data, null, 2);
|
||||
|
||||
// const defaultPath = path.join(__dirname, 'smtData.json');
|
||||
// const finalPath = outputPath ? path.resolve(__dirname, outputPath) : defaultPath;
|
||||
|
||||
// fs.writeFileSync(finalPath, jsonString, 'utf8');
|
||||
// console.log(`Saved json file here: ${finalPath}`);
|
||||
// }
|
||||
|
||||
export function generateMerkleProof(imt: LeanIMT, _index: number, maxDepth: number) {
|
||||
const { siblings: merkleProofSiblings, index } = imt.generateProof(_index);
|
||||
const depthForThisOne = merkleProofSiblings.length;
|
||||
|
||||
2
contracts/.gitignore
vendored
2
contracts/.gitignore
vendored
@@ -13,4 +13,4 @@ ignition/parameters.json
|
||||
ignition/deployments
|
||||
|
||||
#Local verifier
|
||||
contracts/verifiers/local/*
|
||||
contracts/verifiers/local/*
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ashpect/smt": "https://github.com/ashpect/smt#main",
|
||||
"@eth-optimism/hardhat-ovm": "^0.2.4",
|
||||
"@nomiclabs/hardhat-ethers": "^2.2.3",
|
||||
"@openzeppelin/contracts": "^4.9.2",
|
||||
|
||||
@@ -15,8 +15,14 @@ import {
|
||||
} from "../../../common/src/utils/csca";
|
||||
import { mock_dsc_sha256_rsa_4096 } from "../../../common/src/constants/mockCertificates";
|
||||
import { generateCircuitInputsProve } from "../../../common/src/utils/generateInputs";
|
||||
import { buildSMT } from "../../../common/src/utils/smtTree";
|
||||
import { convertProofTypeIntoInput } from "../../../common/src/utils/test/generateMockProof";
|
||||
import { buildSMT, importSMTFromJsonFile, exportSMTToJsonFile } from "../../../common/src/utils/smtTree";
|
||||
import { SMT } from "@ashpect/smt";
|
||||
// import { ChildNodes, SMT } from "@ashpect/smt";
|
||||
// import * as nameSMTJson from "../../../common/ofacdata/outputs/nameSMT.json";
|
||||
// import { poseidon3, poseidon2 } from "poseidon-lite"
|
||||
// import { convertProofTypeIntoInput } from "../../../common/src/utils/test/generateMockProof";
|
||||
// import path from 'path';
|
||||
// import { hash } from "crypto";
|
||||
|
||||
type CircuitArtifacts = {
|
||||
[key: string]: {
|
||||
@@ -30,6 +36,7 @@ type CircuitArtifacts = {
|
||||
}
|
||||
}
|
||||
|
||||
// Just test for mint function
|
||||
describe("Test one time verification flow", async function () {
|
||||
this.timeout(0);
|
||||
|
||||
@@ -83,26 +90,33 @@ describe("Test one time verification flow", async function () {
|
||||
}
|
||||
}
|
||||
|
||||
let dsc_circuits: CircuitArtifacts = {};
|
||||
if (process.env.TEST_ENV === "local") {
|
||||
dsc_circuits["prove_rsa_65537_sha256"] = {
|
||||
wasm: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_js/prove_rsa_65537_sha256.wasm",
|
||||
zkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_final.zkey",
|
||||
vkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_vkey.json"
|
||||
}
|
||||
} else if (process.env.TEST_ENV === "prod") {
|
||||
dsc_circuits["prove_rsa_65537_sha256"] = {
|
||||
wasm: "../circuits/build/fromAWS/prove_rsa_65537_sha256.wasm",
|
||||
zkey: "../circuits/build/fromAWS/prove_rsa_65537_sha256.zkey",
|
||||
vkey: "../circuits/build/fromAWS/prove_rsa_65537_sha256_vkey.json"
|
||||
}
|
||||
} else {
|
||||
dsc_circuits["prove_rsa_65537_sha256"] = {
|
||||
wasm: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_js/prove_rsa_65537_sha256.wasm",
|
||||
zkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_final.zkey",
|
||||
vkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_vkey.json"
|
||||
}
|
||||
}
|
||||
// TODO: After fix bug in witness gen in test code for dsc circuit
|
||||
// let dsc_circuits: CircuitArtifacts = {};
|
||||
// dsc_circuits["dsc_rsa_65537_sha256_4096"] = {
|
||||
// wasm: "../circuits/build/dsc/dsc_rsa_65537_sha256_4096/dsc_rsa_65537_sha256_4096_js/dsc_rsa_65537_sha256_4096.wasm",
|
||||
// zkey: "../circuits/build/dsc/dsc_rsa_65537_sha256_4096/dsc_rsa_65537_sha256_4096_final.zkey",
|
||||
// vkey: "../circuits/build/dsc/dsc_rsa_65537_sha256_4096/dsc_rsa_65537_sha256_4096_vkey.json"
|
||||
// }
|
||||
// // TODO: After dsc's wasm, zkey and vkey are uploaded to AWS
|
||||
// // if (process.env.TEST_ENV === "local") {
|
||||
// // prove_circuits["prove_rsa_65537_sha256"] = {
|
||||
// // wasm: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_js/prove_rsa_65537_sha256.wasm",
|
||||
// // zkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_final.zkey",
|
||||
// // vkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_vkey.json"
|
||||
// // }
|
||||
// // } else if (process.env.TEST_ENV === "prod") {
|
||||
// // prove_circuits["prove_rsa_65537_sha256"] = {
|
||||
// // wasm: "../circuits/build/fromAWS/prove_rsa_65537_sha256.wasm",
|
||||
// // zkey: "../circuits/build/fromAWS/prove_rsa_65537_sha256.zkey",
|
||||
// // vkey: "../circuits/build/fromAWS/prove_rsa_65537_sha256_vkey.json"
|
||||
// // }
|
||||
// // } else {
|
||||
// // prove_circuits["prove_rsa_65537_sha256"] = {
|
||||
// // wasm: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_js/prove_rsa_65537_sha256.wasm",
|
||||
// // zkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_final.zkey",
|
||||
// // vkey: "../circuits/build/prove/prove_rsa_65537_sha256/prove_rsa_65537_sha256_vkey.json"
|
||||
// // }
|
||||
// // }
|
||||
|
||||
before(async function() {
|
||||
[owner, addr1, addr2] = await ethers.getSigners();
|
||||
@@ -170,96 +184,21 @@ describe("Test one time verification flow", async function () {
|
||||
});
|
||||
|
||||
describe("test", async function() {
|
||||
it("Should be able to deploy", async function() {
|
||||
it("Should be able to mint and set attributes", async function() {
|
||||
|
||||
let selector_mode = [1, 0];
|
||||
let secret = "42";
|
||||
let dsc_secret = "4242";
|
||||
let scope = "1";
|
||||
let selector_dg1 = new Array(88).fill("1");;
|
||||
let selector_older_than = "1";
|
||||
let majority = "20";
|
||||
let name = fs.readFileSync("../common/ofacdata/inputs/names.json", "utf-8");
|
||||
let name_list = JSON.parse(name);
|
||||
// TODO: hardcode smt for test perfomance. Generate SMT everytime is not efficient.
|
||||
let mockSmt = buildSMT(name_list, "name");
|
||||
console.log(mockSmt);
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let selector_ofac = "0";
|
||||
let forbidden_countries_list = ["AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG","AFG"];
|
||||
let user_identifier = "70997970C51812dc3A010C7d01b50e0d17dc79C8";
|
||||
let user_identifier_type:"ascii" | "hex" | "uuid" | undefined = "hex";
|
||||
|
||||
let prove = generateCircuitInputsProve(
|
||||
selector_mode,
|
||||
secret,
|
||||
dsc_secret,
|
||||
mockPassport,
|
||||
scope,
|
||||
selector_dg1,
|
||||
selector_older_than,
|
||||
majority,
|
||||
mockSmt[2],
|
||||
selector_ofac,
|
||||
forbidden_countries_list,
|
||||
user_identifier,
|
||||
user_identifier_type
|
||||
);
|
||||
const proof_prove_result = await groth16.fullProve(
|
||||
prove,
|
||||
prove_circuits["prove_rsa_65537_sha256"].wasm,
|
||||
prove_circuits["prove_rsa_65537_sha256"].zkey
|
||||
);
|
||||
const proof_prove = proof_prove_result.proof;
|
||||
const publicSignals_prove = proof_prove_result.publicSignals;
|
||||
console.log("proof_prove: ", proof_prove);
|
||||
console.log("publicSignals_prove: ", publicSignals_prove);
|
||||
|
||||
const vKey_prove = JSON.parse(fs.readFileSync(prove_circuits["prove_rsa_65537_sha256"].vkey) as unknown as string);
|
||||
const verified_prove = await groth16.verify(
|
||||
vKey_prove,
|
||||
publicSignals_prove,
|
||||
proof_prove
|
||||
)
|
||||
// assert(verified_csca == true, 'Should verify')
|
||||
console.log("verified_prove: ", verified_prove);
|
||||
const rawCallData_prove = await groth16.exportSolidityCallData(proof_prove, publicSignals_prove);
|
||||
console.log(rawCallData_prove);
|
||||
let prove_proof = JSON.parse("[" + rawCallData_prove + "]");
|
||||
|
||||
let dsc = generateCircuitInputsDSC(
|
||||
"4242",
|
||||
mock_dsc_sha256_rsa_4096,
|
||||
1664
|
||||
);
|
||||
|
||||
// TODO: I tried to generate proof in the test code, but it failed.
|
||||
// console.log(dsc.inputs);
|
||||
// fs.writeFileSync("dsc.json", JSON.stringify(dsc.inputs));
|
||||
|
||||
// const proof_dsc_result = await groth16.fullProve(
|
||||
// dsc.inputs,
|
||||
// dsc_circuits["dsc_rsa_65537_sha256_4096"].wasm,
|
||||
// dsc_circuits["dsc_rsa_65537_sha256_4096"].zkey
|
||||
// );
|
||||
|
||||
// const proof_csca = proof_dsc_result.proof;
|
||||
// const publicSignals_csca = proof_dsc_result.publicSignals;
|
||||
|
||||
// const vKey_csca = JSON.parse(fs.readFileSync(dsc_circuits["dsc_rsa_65537_sha256_4096"].vkey) as unknown as string);
|
||||
// const verified_csca = await groth16.verify(
|
||||
// vKey_csca,
|
||||
// publicSignals_csca,
|
||||
// proof_csca
|
||||
// )
|
||||
// // assert(verified_csca == true, 'Should verify')
|
||||
// console.log("verified_csca: ", verified_csca);
|
||||
// console.log('\x1b[32m%s\x1b[0m', `Proof verified csca - ${"dsc_rsa_65537_sha256_4096"}`);
|
||||
|
||||
const response = await sendCSCARequest(dsc);
|
||||
console.log(response);
|
||||
const rawCallData_csca = await groth16.exportSolidityCallData(response.proof, response.pub_signals);
|
||||
let csca_proof = JSON.parse("[" + rawCallData_csca + "]");
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
await oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
@@ -271,13 +210,253 @@ describe("Test one time verification flow", async function () {
|
||||
pubSignals: prove_proof[3]
|
||||
},
|
||||
{
|
||||
a: csca_proof[0],
|
||||
b: csca_proof[1],
|
||||
c: csca_proof[2],
|
||||
pubSignals: csca_proof[3]
|
||||
a: dsc_proof[0],
|
||||
b: dsc_proof[1],
|
||||
c: dsc_proof[2],
|
||||
pubSignals: dsc_proof[3]
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid prove proof", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let invalid_prove_proof = prove_proof;
|
||||
invalid_prove_proof[0] = [0, 0];
|
||||
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
await expect(
|
||||
oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
DSC_RSA65537_SHA256_4096_VERIFIER_ID,
|
||||
{
|
||||
a: invalid_prove_proof[0],
|
||||
b: invalid_prove_proof[1],
|
||||
c: invalid_prove_proof[2],
|
||||
pubSignals: prove_proof[3]
|
||||
},
|
||||
{
|
||||
a: dsc_proof[0],
|
||||
b: dsc_proof[1],
|
||||
c: dsc_proof[2],
|
||||
pubSignals: dsc_proof[3]
|
||||
},
|
||||
)
|
||||
).to.be.revertedWithCustomError(
|
||||
oneTimeSBT,
|
||||
"INVALID_PROVE_PROOF"
|
||||
);
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid dsc proof", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
let invalid_dsc_proof = dsc_proof;
|
||||
invalid_dsc_proof[0] = [0, 0];
|
||||
|
||||
await expect(
|
||||
oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
DSC_RSA65537_SHA256_4096_VERIFIER_ID,
|
||||
{
|
||||
a: prove_proof[0],
|
||||
b: prove_proof[1],
|
||||
c: prove_proof[2],
|
||||
pubSignals: prove_proof[3]
|
||||
},
|
||||
{
|
||||
a: invalid_dsc_proof[0],
|
||||
b: invalid_dsc_proof[1],
|
||||
c: invalid_dsc_proof[2],
|
||||
pubSignals: dsc_proof[3]
|
||||
},
|
||||
)
|
||||
).to.be.revertedWithCustomError(
|
||||
oneTimeSBT,
|
||||
"INVALID_DSC_PROOF"
|
||||
);
|
||||
});
|
||||
|
||||
it("Should not be able to mint with invalid blinded dcs", async function() {
|
||||
let prove_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_prove.json")) {
|
||||
prove_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_prove.json", "utf-8"));
|
||||
} else {
|
||||
prove_proof = await generateProofRSAProve();
|
||||
}
|
||||
|
||||
let dsc_proof;
|
||||
if(fs.existsSync("./test/integrationTest/proof_dsc.json")) {
|
||||
dsc_proof = JSON.parse(fs.readFileSync("./test/integrationTest/proof_dsc.json", "utf-8"));
|
||||
} else {
|
||||
dsc_proof = await generateProofDSC();
|
||||
}
|
||||
|
||||
let invalid_prove_proof = prove_proof;
|
||||
invalid_prove_proof[3][PROVE_RSA_BLINDED_DSC_COMMITMENT_INDEX] = 0;
|
||||
|
||||
await expect(
|
||||
oneTimeSBT.mint(
|
||||
PROVE_RSA_65537_SHA256_VERIFIER_ID,
|
||||
DSC_RSA65537_SHA256_4096_VERIFIER_ID,
|
||||
{
|
||||
a: invalid_prove_proof[0],
|
||||
b: invalid_prove_proof[1],
|
||||
c: invalid_prove_proof[2],
|
||||
pubSignals: invalid_prove_proof[3]
|
||||
},
|
||||
{
|
||||
a: dsc_proof[0],
|
||||
b: dsc_proof[1],
|
||||
c: dsc_proof[2],
|
||||
pubSignals: dsc_proof[3]
|
||||
},
|
||||
)
|
||||
).to.be.revertedWithCustomError(
|
||||
oneTimeSBT,
|
||||
"UNEQUAL_BLINDED_DSC_COMMITMENT"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
// TODO: make this function able to take inputs
|
||||
// TODO: export check flow in other function
|
||||
async function generateProofRSAProve() {
|
||||
let selector_mode = [1, 0];
|
||||
let secret = "42";
|
||||
let dsc_secret = "4242";
|
||||
let scope = "1";
|
||||
let selector_dg1 = new Array(88).fill("1");;
|
||||
let selector_older_than = "1";
|
||||
let majority = "20";
|
||||
let name = fs.readFileSync("../common/ofacdata/inputs/names.json", "utf-8");
|
||||
let name_list = JSON.parse(name);
|
||||
|
||||
let mockSmt;
|
||||
if (fs.existsSync("./test/integrationTest/smt.json")) {
|
||||
mockSmt = importSMTFromJsonFile("./test/integrationTest/smt.json") as SMT;
|
||||
} else {
|
||||
const builtSmt = buildSMT(name_list, "name");
|
||||
exportSMTToJsonFile(builtSmt[0], builtSmt[1], builtSmt[2], "./test/integrationTest/smt.json");
|
||||
mockSmt = builtSmt[2] as SMT;
|
||||
}
|
||||
|
||||
let selector_ofac = "0";
|
||||
let forbidden_countries_list = ["AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA","AAA"];
|
||||
let user_identifier = "70997970C51812dc3A010C7d01b50e0d17dc79C8";
|
||||
let user_identifier_type:"ascii" | "hex" | "uuid" | undefined = "hex";
|
||||
|
||||
let prove = generateCircuitInputsProve(
|
||||
selector_mode,
|
||||
secret,
|
||||
dsc_secret,
|
||||
mockPassport,
|
||||
scope,
|
||||
selector_dg1,
|
||||
selector_older_than,
|
||||
majority,
|
||||
mockSmt,
|
||||
selector_ofac,
|
||||
forbidden_countries_list,
|
||||
user_identifier,
|
||||
user_identifier_type
|
||||
);
|
||||
const proof_prove_result = await groth16.fullProve(
|
||||
prove,
|
||||
prove_circuits["prove_rsa_65537_sha256"].wasm,
|
||||
prove_circuits["prove_rsa_65537_sha256"].zkey
|
||||
);
|
||||
|
||||
const jsonString = JSON.stringify(proof_prove_result);
|
||||
fs.writeFileSync("./test/integrationTest/proof_prove_result.json", jsonString);
|
||||
|
||||
const proof_prove_result_json = fs.readFileSync("./test/integrationTest/proof_prove_result.json", "utf-8");
|
||||
const proof_prove_result_obj = JSON.parse(proof_prove_result_json);
|
||||
console.log(proof_prove_result_obj.proof);
|
||||
console.log(proof_prove_result_obj.publicSignals);
|
||||
|
||||
const proof_prove = proof_prove_result_obj.proof;
|
||||
const publicSignals_prove = proof_prove_result.publicSignals;
|
||||
console.log("proof_prove: ", proof_prove);
|
||||
console.log("publicSignals_prove: ", publicSignals_prove);
|
||||
|
||||
const vKey_prove = JSON.parse(fs.readFileSync(prove_circuits["prove_rsa_65537_sha256"].vkey) as unknown as string);
|
||||
const verified_prove = await groth16.verify(
|
||||
vKey_prove,
|
||||
publicSignals_prove,
|
||||
proof_prove
|
||||
)
|
||||
// assert(verified_csca == true, 'Should verify')
|
||||
console.log("verified_prove: ", verified_prove);
|
||||
const rawCallData_prove = await groth16.exportSolidityCallData(proof_prove, publicSignals_prove);
|
||||
console.log(rawCallData_prove);
|
||||
let prove_proof = JSON.parse("[" + rawCallData_prove + "]");
|
||||
fs.writeFileSync("./test/integrationTest/proof_prove.json", JSON.stringify(prove_proof));
|
||||
return prove_proof;
|
||||
}
|
||||
|
||||
// TODO: make this function able to take inputs
|
||||
// TODO: I tried to generate proof in the test code, but it failed. I need to find out why
|
||||
// TODO: export check flow in other function
|
||||
async function generateProofDSC() {
|
||||
let dsc = generateCircuitInputsDSC(
|
||||
"4242",
|
||||
mock_dsc_sha256_rsa_4096,
|
||||
1664
|
||||
);
|
||||
|
||||
// TODO: I tried to generate proof in the test code, but it failed.
|
||||
// console.log(dsc.inputs);
|
||||
// fs.writeFileSync("dsc.json", JSON.stringify(dsc.inputs));
|
||||
|
||||
// const proof_dsc_result = await groth16.fullProve(
|
||||
// dsc.inputs,
|
||||
// dsc_circuits["dsc_rsa_65537_sha256_4096"].wasm,
|
||||
// dsc_circuits["dsc_rsa_65537_sha256_4096"].zkey
|
||||
// );
|
||||
|
||||
// const proof_csca = proof_dsc_result.proof;
|
||||
// const publicSignals_csca = proof_dsc_result.publicSignals;
|
||||
|
||||
// const vKey_csca = JSON.parse(fs.readFileSync(dsc_circuits["dsc_rsa_65537_sha256_4096"].vkey) as unknown as string);
|
||||
// const verified_csca = await groth16.verify(
|
||||
// vKey_csca,
|
||||
// publicSignals_csca,
|
||||
// proof_csca
|
||||
// )
|
||||
// // assert(verified_csca == true, 'Should verify')
|
||||
// console.log("verified_csca: ", verified_csca);
|
||||
// console.log('\x1b[32m%s\x1b[0m', `Proof verified csca - ${"dsc_rsa_65537_sha256_4096"}`);
|
||||
|
||||
const response = await sendCSCARequest(dsc);
|
||||
console.log(response);
|
||||
const rawCallData_dsc = await groth16.exportSolidityCallData(response.proof, response.pub_signals);
|
||||
let dsc_proof = JSON.parse("[" + rawCallData_dsc + "]");
|
||||
fs.writeFileSync("./test/integrationTest/proof_dsc.json", JSON.stringify(dsc_proof));
|
||||
return dsc_proof;
|
||||
}
|
||||
});
|
||||
|
||||
1
contracts/test/integrationTest/proof_dsc.json
Normal file
1
contracts/test/integrationTest/proof_dsc.json
Normal file
@@ -0,0 +1 @@
|
||||
[["0x0120659c66b80b91feb00b1fd7520dc308ffb677d5699f04daa3e5f0559a0137","0x0a34201a6ef724848bb229bbcdaeca648d94912e668816fc8d098eb7b3a1eda9"],[["0x100052a855324460908535ac28ea239b0f418bdb7cdd9701371e8e901bd1e65b","0x1a833379bfc97848c03aad346fdc78d2306556e95f51262831c2a4b42d924214"],["0x2d1113d8271fb870771e0d524e07efba4f1a114ed5f2900dd72f36ab590e9d40","0x2d633aa0206e307fa08c3b7ae11896d455694210b563febb0243f76e0cd875b6"]],["0x2ffd821b061473b90b6798fd73121f625019d5b8c9a34a01514ab6a24eedc856","0x27e0dd2ed262abacd03468f8f04a010b65a4b55fea0a1084fbd28dc96f3839dd"],["0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb"]]
|
||||
1
contracts/test/integrationTest/proof_prove.json
Normal file
1
contracts/test/integrationTest/proof_prove.json
Normal file
@@ -0,0 +1 @@
|
||||
[["0x088e2018ce1ddf45dc6a2959328a70b96cb7ccdd82a02451b81cf104e4ca412d","0x22c753b61eb15d9abcf0250ca00d3be8e1b2148c2142d4775758d1157f7260a0"],[["0x1b8bd9cd095850954ff12801d5855d3232775f271b744393c56744f814199f06","0x2d7907e6841b82b4c53a1f127551782ddb260b37bbfe24f91c2f138aae6bf0a6"],["0x1d5560b6c4537f2861b1167cd9c21286098ec0a641c76b421dbe7919e0d22552","0x28e247d9ade45264b22a54c5707fdf8637d48ecfd39f9310998cbd2172274fd6"]],["0x01f27b78d40461239b648f950ce8c569d861038f84c81e8dd432fed135de15a2","0x1e8ac6044a9e9f9cb37744c7d08c5c61bd6228fd6e32209adb5fa898bf326f1f"],["0x01e6e73285d61a967d0c3edd701303b575b66e589bba3b3c11d2457bd131b6c9","0x00413c534555484755483c45534e4f48504c413c3c544e4f5055444152463c50","0x003331303439415246343433323138414135313c3c3c3c3c3c3c3c545245424c","0x00000000000032303c3c3c3c3c3c3c3c3c3c3c3c3c3c353133303130344d3131","0x0000000000000000000000000000000000000000000000000000000000000032","0x0000000000000000000000000000000000000000000000000000000000000030","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0041414141414141414141414141414141414141414141414141414141414141","0x0000000000004141414141414141414141414141414141414141414141414141","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0030186e34532bd2527db97cb8452c23620434945a2a41faf060e74a5ca9aceb","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000004","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8","0x0000000000000000000000000000000000000000000000000000000000000419"]]
|
||||
5
contracts/test/integrationTest/smt.json
Normal file
5
contracts/test/integrationTest/smt.json
Normal file
File diff suppressed because one or more lines are too long
@@ -7,6 +7,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069"
|
||||
integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==
|
||||
|
||||
"@ashpect/smt@https://github.com/ashpect/smt#main":
|
||||
version "1.0.0"
|
||||
resolved "https://github.com/ashpect/smt#4f73fd24adb06a7f8efd6fd2d3ed58e9e2f2691a"
|
||||
|
||||
"@babel/code-frame@^7.12.13":
|
||||
version "7.24.7"
|
||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.24.7.tgz#882fd9e09e8ee324e496bd040401c6f046ef4465"
|
||||
|
||||
Reference in New Issue
Block a user