mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
add csca server proving (commented) and change register zkey (error during proving)
This commit is contained in:
@@ -36,7 +36,11 @@ export const attributeToPosition = {
|
||||
};
|
||||
|
||||
export const MAX_DATAHASHES_LEN = 320; // max formatted and concatenated datagroup hashes length in bytes
|
||||
|
||||
export const n_dsc = 121;
|
||||
export const k_dsc = 17;
|
||||
export const n_csca = 121;
|
||||
export const k_csca = 34;
|
||||
export const max_cert_bytes = 1664;
|
||||
export const countryCodes = {
|
||||
"AFG": "Afghanistan",
|
||||
"ALA": "Aland Islands",
|
||||
@@ -304,8 +308,8 @@ qzOBhID0Nxk4k9sW1uT6ocW1xp1SB2WotORssOKIAOLJM8IbPl6n/DkYNcfvyXI7
|
||||
-----END RSA PUBLIC KEY-----`;
|
||||
|
||||
export const DEFAULT_RPC_URL = "https://mainnet.optimism.io";
|
||||
export const REGISTER_CONTRACT_ADDRESS = "0xFd84F23Be557133DCa47Fc9aa22031AcCE557335";
|
||||
export const SBT_CONTRACT_ADDRESS = "0x98aA4401ef9d3dFed09D8c98B5a62FA325CF23b3";
|
||||
export const REGISTER_CONTRACT_ADDRESS = "0x395C63B95505BBa611d090d0a3021988EB57C3B9";
|
||||
export const SBT_CONTRACT_ADDRESS = "0x5d0E4aA46e16aDeBeF98EcB50651bC642CE53ebb";
|
||||
/*** ABI ***/
|
||||
|
||||
export const REGISTER_ABI = [
|
||||
|
||||
@@ -50,7 +50,7 @@ export function getCSCAInputs(dscCertificate: any, cscaCertificate: any = null,
|
||||
const csca_modulus = rsaPublicKey.n.toString(16).toLowerCase();
|
||||
const csca_modulus_number = BigInt(`0x${csca_modulus}`);
|
||||
csca_modulus_formatted = splitToWords(csca_modulus_number, BigInt(n_csca), BigInt(k_csca));
|
||||
console.log('csca_modulus_formatted', csca_modulus_formatted);
|
||||
//console.log('csca_modulus_formatted', csca_modulus_formatted);
|
||||
|
||||
|
||||
}
|
||||
@@ -60,19 +60,19 @@ export function getCSCAInputs(dscCertificate: any, cscaCertificate: any = null,
|
||||
const authorityKeyIdentifierExt = dscCertificate.extensions.find(
|
||||
(ext) => ext.name === 'authorityKeyIdentifier'
|
||||
);
|
||||
console.log('authorityKeyIdentifierExt', authorityKeyIdentifierExt);
|
||||
//console.log('authorityKeyIdentifierExt', authorityKeyIdentifierExt);
|
||||
const value = authorityKeyIdentifierExt.value;
|
||||
console.log('value', value);
|
||||
//console.log('value', value);
|
||||
const byteArray = derToBytes(value);
|
||||
console.log('Authority Key Identifier (byte array):', byteArray);
|
||||
//console.log('Authority Key Identifier (byte array):', byteArray);
|
||||
const formattedValue = byteArray.map(byte => byte.toString(16).padStart(2, '0').toUpperCase()).join(':');
|
||||
console.log('Formatted Authority Key Identifier:', formattedValue);
|
||||
//console.log('Formatted Authority Key Identifier:', formattedValue);
|
||||
const formattedValueAdjusted = formattedValue.substring(12); // Remove the first '30:16:80:14:' from the formatted string
|
||||
const csca_modulus = CSCA_AKI_MODULUS[formattedValueAdjusted as keyof typeof CSCA_AKI_MODULUS];
|
||||
const csca_modulus_cleaned = csca_modulus.replace(/:/g, '');
|
||||
const csca_modulus_bigint = BigInt(`0x${csca_modulus_cleaned}`);
|
||||
csca_modulus_formatted = splitToWords(csca_modulus_bigint, BigInt(n_csca), BigInt(k_csca));
|
||||
console.log('CSCA modulus as bigint:', csca_modulus_bigint);
|
||||
//console.log('CSCA modulus as bigint:', csca_modulus_bigint);
|
||||
console.log('CSCA modulus extracted from json:', csca_modulus_formatted);
|
||||
}
|
||||
|
||||
@@ -106,13 +106,13 @@ export function getCSCAInputs(dscCertificate: any, cscaCertificate: any = null,
|
||||
|
||||
return {
|
||||
"raw_dsc_cert": dsc_message_padded_formatted,
|
||||
"raw_dsc_cert_padded_bytes": dsc_messagePaddedLen_formatted,
|
||||
"raw_dsc_cert_padded_bytes": [dsc_messagePaddedLen_formatted],
|
||||
"csca_modulus": csca_modulus_formatted,
|
||||
"dsc_signature": dsc_signature_formatted,
|
||||
"dsc_modulus": dsc_modulus_formatted,
|
||||
"start_index": startIndex_formatted,
|
||||
"secret": "0",
|
||||
"merkle_root": root,
|
||||
"start_index": [startIndex_formatted],
|
||||
"secret": [BigInt(0).toString()],
|
||||
"merkle_root": [BigInt(root).toString()],
|
||||
"path": proof.pathIndices.map(index => index.toString()),
|
||||
"siblings": proof.siblings.flat().map(sibling => sibling.toString())
|
||||
}
|
||||
@@ -126,10 +126,33 @@ export function derToBytes(derValue: string) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function getCSCAModulusProof(leaf: string, n, k) {
|
||||
export function getCSCAModulusMerkleTree(n, k) {
|
||||
const tree = new IMT(poseidon2, CSCA_TREE_DEPTH, 0, 2);
|
||||
const csca_modulus_array = Object.values(CSCA_AKI_MODULUS);
|
||||
const csca_modulus_array_number = csca_modulus_array.map((modulus) => {
|
||||
const cleanedModulus = modulus.replace(/:/g, ''); // Remove colons
|
||||
return BigInt(`0x${cleanedModulus}`);
|
||||
});
|
||||
const csca_modulus_formatted = csca_modulus_array_number.map((modulus) => splitToWords(modulus, BigInt(n), BigInt(k)));
|
||||
|
||||
for (let i = 0; i < csca_modulus_formatted.length; i++) {
|
||||
const finalPoseidonHash = computeLeafFromModulus(csca_modulus_formatted[i]);
|
||||
tree.insert(finalPoseidonHash.toString());
|
||||
}
|
||||
return tree;
|
||||
|
||||
}
|
||||
|
||||
export function computeLeafFromModulus(modulus_formatted: string[]) {
|
||||
const poseidonHashOfTheFirst16 = poseidon16(modulus_formatted.slice(0, 16));
|
||||
const poseidonHashOfTheNext16 = poseidon16(modulus_formatted.slice(16, 32));
|
||||
const poseidonHashOfTheLast2 = poseidon2(modulus_formatted.slice(-2));
|
||||
const finalPoseidonHash = poseidon3([poseidonHashOfTheFirst16, poseidonHashOfTheNext16, poseidonHashOfTheLast2]);
|
||||
return finalPoseidonHash.toString();
|
||||
}
|
||||
|
||||
export function getCSCAModulusProof(leaf, n, k) {
|
||||
const tree = new IMT(poseidon2, CSCA_TREE_DEPTH, 0, 2);
|
||||
// get all the modulus
|
||||
// split them into 34 bit words of 121 bits using the splitToWords method
|
||||
const csca_modulus_array = Object.values(CSCA_AKI_MODULUS);
|
||||
const csca_modulus_array_number = csca_modulus_array.map((modulus) => {
|
||||
const cleanedModulus = modulus.replace(/:/g, ''); // Remove colons
|
||||
@@ -137,16 +160,12 @@ export function getCSCAModulusProof(leaf: string, n, k) {
|
||||
});
|
||||
const csca_modulus_formatted = csca_modulus_array_number.map((modulus) => splitToWords(modulus, BigInt(n), BigInt(k)));
|
||||
|
||||
// hash the first 16 using poseidon, hash the 16 next using poseidon, hash the last 2 ones using poseidon
|
||||
const hashedModuliGroups = [];
|
||||
for (let i = 0; i < csca_modulus_formatted.length; i++) {
|
||||
const finalPoseidonHash = computeLeafFromModulus(csca_modulus_formatted[i]);
|
||||
hashedModuliGroups.push(finalPoseidonHash.toString());
|
||||
tree.insert(finalPoseidonHash.toString());
|
||||
}
|
||||
//console.log('hashedModuliGroups', hashedModuliGroups);
|
||||
//console.log("size of the list", hashedModuliGroups.length);
|
||||
//console.log("root", tree.root);
|
||||
const index = tree.indexOf(leaf);
|
||||
if (index === -1) {
|
||||
throw new Error("Your public key was not found in the registry");
|
||||
@@ -158,12 +177,3 @@ export function getCSCAModulusProof(leaf: string, n, k) {
|
||||
|
||||
}
|
||||
|
||||
export function computeLeafFromModulus(modulus_formatted: string[]) {
|
||||
const poseidonHashOfTheFirst16 = poseidon16(modulus_formatted.slice(0, 16));
|
||||
const poseidonHashOfTheNext16 = poseidon16(modulus_formatted.slice(16, 32));
|
||||
const poseidonHashOfTheLast2 = poseidon2(modulus_formatted.slice(-2));
|
||||
const finalPoseidonHash = poseidon3([poseidonHashOfTheFirst16, poseidonHashOfTheNext16, poseidonHashOfTheLast2]);
|
||||
return finalPoseidonHash.toString();
|
||||
}
|
||||
//getCSCAModulusMerkleTree("7013779953511677452538135461619722358450225673833899813888513931978925381442", 121, 34);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type PassportData = {
|
||||
mrz: string;
|
||||
signatureAlgorithm: string;
|
||||
pubKey: {modulus?: string, exponent?: string, curveName?: string, publicKeyQ?: string};
|
||||
pubKey: { modulus?: string, exponent?: string, curveName?: string, publicKeyQ?: string };
|
||||
dataGroupHashes: number[];
|
||||
eContent: number[];
|
||||
encryptedDigest: number[];
|
||||
@@ -15,4 +15,16 @@ export type Proof = {
|
||||
c: [string, string]
|
||||
};
|
||||
pub_signals: string[];
|
||||
}
|
||||
}
|
||||
|
||||
export function castCSCAProof(proof: any): Proof {
|
||||
return {
|
||||
proof: {
|
||||
a: proof.proof.pi_a.slice(0, 2),
|
||||
b: [proof.proof.pi_b[0].slice(0, 2), proof.proof.pi_b[1].slice(0, 2)],
|
||||
c: proof.proof.pi_c.slice(0, 2)
|
||||
},
|
||||
pub_signals: proof.public
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user