mirror of
https://github.com/selfxyz/self.git
synced 2026-01-15 01:28:18 -05:00
finally fixed the bug
This commit is contained in:
@@ -1784,9 +1784,640 @@ export const mockPassportData_sha384_ecdsa = {
|
||||
"photoBase64": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABjElEQVR42mL8//8/AyUYiBQYmIw3..."
|
||||
}
|
||||
|
||||
export const mockPassportData2_sha256_rsa_65537 = {
|
||||
"mrz": "P<FRATESTIN<<ABCDEFGH<ABCDEF<ABCDEF<<<<<<<<<42GH123454FRA0001011M4022225<<<<<<<<<<<<<<22",
|
||||
"signatureAlgorithm": "sha256WithRSASSAPSS",
|
||||
"pubKey": {
|
||||
"modulus": "24462187253413274681146293990014601117483150253485750502784042435672184694412963307122026240846907391312882376801424642119473345751861224453041335405750030091821974208795494089279845074559882616814677854700627123408815125641207116387150180075958682953326415376187334908428885389819481874887447587379894859906385655519567588675165038354987379327125622417796020195813417774532495071662150990707566936780047952622227454986438290561518433120591444215515025611804148686981931860883842745085825036432179109865379231910853752492302597965268640127145219080386320748404798990484447108886155687702517815916586904444799519356177",
|
||||
"exponent": "65537"
|
||||
},
|
||||
"dataGroupHashes": [
|
||||
-108,
|
||||
31,
|
||||
-26,
|
||||
62,
|
||||
-36,
|
||||
-36,
|
||||
113,
|
||||
-93,
|
||||
88,
|
||||
-94,
|
||||
90,
|
||||
-108,
|
||||
70,
|
||||
-11,
|
||||
-101,
|
||||
1,
|
||||
76,
|
||||
-53,
|
||||
60,
|
||||
-106,
|
||||
63,
|
||||
-124,
|
||||
-107,
|
||||
-28,
|
||||
111,
|
||||
97,
|
||||
47,
|
||||
66,
|
||||
120,
|
||||
-9,
|
||||
123,
|
||||
-5,
|
||||
-13,
|
||||
-49,
|
||||
82,
|
||||
60,
|
||||
28,
|
||||
116,
|
||||
89,
|
||||
-6,
|
||||
-96,
|
||||
-67,
|
||||
123,
|
||||
28,
|
||||
36,
|
||||
-4,
|
||||
-68,
|
||||
75,
|
||||
-15,
|
||||
-20,
|
||||
119,
|
||||
91,
|
||||
50,
|
||||
-33,
|
||||
-2,
|
||||
-2,
|
||||
-38,
|
||||
-16,
|
||||
44,
|
||||
-13,
|
||||
112,
|
||||
102,
|
||||
-66,
|
||||
82,
|
||||
-76,
|
||||
-21,
|
||||
-34,
|
||||
33,
|
||||
79,
|
||||
50,
|
||||
-104,
|
||||
-120,
|
||||
-114,
|
||||
35,
|
||||
116,
|
||||
-32,
|
||||
6,
|
||||
-14,
|
||||
-100,
|
||||
-115,
|
||||
-128,
|
||||
-8,
|
||||
10,
|
||||
61,
|
||||
98,
|
||||
86,
|
||||
-8,
|
||||
45,
|
||||
-49,
|
||||
-46,
|
||||
90,
|
||||
-24,
|
||||
-81,
|
||||
38,
|
||||
0,
|
||||
-62,
|
||||
104,
|
||||
108,
|
||||
-19,
|
||||
-10,
|
||||
97,
|
||||
-26,
|
||||
116,
|
||||
-58,
|
||||
69,
|
||||
110,
|
||||
26,
|
||||
87,
|
||||
17,
|
||||
89,
|
||||
110,
|
||||
-57,
|
||||
108,
|
||||
-6,
|
||||
36,
|
||||
21,
|
||||
39,
|
||||
87,
|
||||
110,
|
||||
102,
|
||||
-6,
|
||||
-43,
|
||||
-82,
|
||||
-125,
|
||||
-85,
|
||||
-82,
|
||||
-120,
|
||||
-101,
|
||||
87,
|
||||
-112,
|
||||
111,
|
||||
15,
|
||||
-104,
|
||||
127,
|
||||
85,
|
||||
25,
|
||||
-102,
|
||||
81,
|
||||
20,
|
||||
58,
|
||||
51,
|
||||
75,
|
||||
-63,
|
||||
116,
|
||||
-22,
|
||||
0,
|
||||
60,
|
||||
30,
|
||||
29,
|
||||
30,
|
||||
-73,
|
||||
-115,
|
||||
72,
|
||||
-9,
|
||||
-1,
|
||||
-53,
|
||||
100,
|
||||
124,
|
||||
41,
|
||||
-22,
|
||||
106,
|
||||
78,
|
||||
31,
|
||||
11,
|
||||
114,
|
||||
-119,
|
||||
-19,
|
||||
17,
|
||||
92,
|
||||
71,
|
||||
-122,
|
||||
47,
|
||||
62,
|
||||
78,
|
||||
-67,
|
||||
-23,
|
||||
-55,
|
||||
-42,
|
||||
53,
|
||||
4,
|
||||
47,
|
||||
-67,
|
||||
-55,
|
||||
-123,
|
||||
6,
|
||||
121,
|
||||
34,
|
||||
-125,
|
||||
64,
|
||||
-114,
|
||||
91,
|
||||
-34,
|
||||
-46,
|
||||
-63,
|
||||
62,
|
||||
-34,
|
||||
104,
|
||||
82,
|
||||
36,
|
||||
41,
|
||||
-118,
|
||||
-3,
|
||||
70,
|
||||
15,
|
||||
-108,
|
||||
-48,
|
||||
-100,
|
||||
45,
|
||||
105,
|
||||
-85,
|
||||
-15,
|
||||
-61,
|
||||
-71,
|
||||
43,
|
||||
-39,
|
||||
-94,
|
||||
-110,
|
||||
-55,
|
||||
-34,
|
||||
89,
|
||||
-18,
|
||||
38,
|
||||
76,
|
||||
123,
|
||||
-40,
|
||||
13,
|
||||
51,
|
||||
-29,
|
||||
72,
|
||||
-11,
|
||||
59,
|
||||
-63,
|
||||
-18,
|
||||
-90,
|
||||
103,
|
||||
49,
|
||||
23,
|
||||
-92,
|
||||
-85,
|
||||
-68,
|
||||
-62,
|
||||
-59,
|
||||
-100,
|
||||
-69,
|
||||
-7,
|
||||
28,
|
||||
-58,
|
||||
95,
|
||||
69,
|
||||
15,
|
||||
-74,
|
||||
56,
|
||||
54,
|
||||
38
|
||||
],
|
||||
"eContent": [
|
||||
49,
|
||||
102,
|
||||
48,
|
||||
21,
|
||||
6,
|
||||
9,
|
||||
42,
|
||||
-122,
|
||||
72,
|
||||
-122,
|
||||
-9,
|
||||
13,
|
||||
1,
|
||||
9,
|
||||
3,
|
||||
49,
|
||||
8,
|
||||
6,
|
||||
6,
|
||||
103,
|
||||
-127,
|
||||
8,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
48,
|
||||
28,
|
||||
6,
|
||||
9,
|
||||
42,
|
||||
-122,
|
||||
72,
|
||||
-122,
|
||||
-9,
|
||||
13,
|
||||
1,
|
||||
9,
|
||||
5,
|
||||
49,
|
||||
15,
|
||||
23,
|
||||
13,
|
||||
49,
|
||||
57,
|
||||
49,
|
||||
50,
|
||||
49,
|
||||
54,
|
||||
49,
|
||||
55,
|
||||
50,
|
||||
50,
|
||||
51,
|
||||
56,
|
||||
90,
|
||||
48,
|
||||
47,
|
||||
6,
|
||||
9,
|
||||
42,
|
||||
-122,
|
||||
72,
|
||||
-122,
|
||||
-9,
|
||||
13,
|
||||
1,
|
||||
9,
|
||||
4,
|
||||
49,
|
||||
34,
|
||||
4,
|
||||
32,
|
||||
-5,
|
||||
100,
|
||||
-110,
|
||||
-122,
|
||||
97,
|
||||
101,
|
||||
57,
|
||||
83,
|
||||
-95,
|
||||
14,
|
||||
7,
|
||||
14,
|
||||
-63,
|
||||
83,
|
||||
-57,
|
||||
-104,
|
||||
-21,
|
||||
114,
|
||||
-31,
|
||||
45,
|
||||
-31,
|
||||
74,
|
||||
-60,
|
||||
58,
|
||||
-37,
|
||||
-106,
|
||||
-113,
|
||||
-80,
|
||||
-49,
|
||||
-112,
|
||||
83,
|
||||
77
|
||||
],
|
||||
"encryptedDigest": [
|
||||
-97,
|
||||
-108,
|
||||
-50,
|
||||
54,
|
||||
29,
|
||||
77,
|
||||
47,
|
||||
-128,
|
||||
26,
|
||||
-86,
|
||||
6,
|
||||
43,
|
||||
103,
|
||||
77,
|
||||
54,
|
||||
-105,
|
||||
-112,
|
||||
116,
|
||||
63,
|
||||
75,
|
||||
-127,
|
||||
9,
|
||||
68,
|
||||
112,
|
||||
-55,
|
||||
-91,
|
||||
-9,
|
||||
-17,
|
||||
24,
|
||||
55,
|
||||
-31,
|
||||
-31,
|
||||
76,
|
||||
-82,
|
||||
79,
|
||||
117,
|
||||
-15,
|
||||
46,
|
||||
59,
|
||||
-111,
|
||||
-33,
|
||||
-93,
|
||||
-46,
|
||||
-82,
|
||||
116,
|
||||
-35,
|
||||
70,
|
||||
-4,
|
||||
-41,
|
||||
-39,
|
||||
-34,
|
||||
-94,
|
||||
99,
|
||||
76,
|
||||
22,
|
||||
-62,
|
||||
96,
|
||||
106,
|
||||
-118,
|
||||
41,
|
||||
-2,
|
||||
-7,
|
||||
-103,
|
||||
-125,
|
||||
-74,
|
||||
-66,
|
||||
111,
|
||||
-5,
|
||||
-120,
|
||||
-76,
|
||||
-108,
|
||||
-106,
|
||||
-59,
|
||||
25,
|
||||
-124,
|
||||
-109,
|
||||
57,
|
||||
-108,
|
||||
76,
|
||||
0,
|
||||
80,
|
||||
-106,
|
||||
-23,
|
||||
116,
|
||||
64,
|
||||
35,
|
||||
-79,
|
||||
-93,
|
||||
-3,
|
||||
99,
|
||||
-61,
|
||||
-15,
|
||||
-41,
|
||||
-104,
|
||||
-17,
|
||||
-116,
|
||||
-67,
|
||||
-39,
|
||||
42,
|
||||
-34,
|
||||
100,
|
||||
61,
|
||||
-66,
|
||||
28,
|
||||
46,
|
||||
63,
|
||||
118,
|
||||
46,
|
||||
59,
|
||||
70,
|
||||
124,
|
||||
76,
|
||||
74,
|
||||
-38,
|
||||
-43,
|
||||
-73,
|
||||
62,
|
||||
-39,
|
||||
-99,
|
||||
58,
|
||||
-53,
|
||||
-56,
|
||||
81,
|
||||
-26,
|
||||
43,
|
||||
-6,
|
||||
-93,
|
||||
52,
|
||||
-37,
|
||||
-66,
|
||||
-40,
|
||||
-95,
|
||||
70,
|
||||
-118,
|
||||
-67,
|
||||
-55,
|
||||
-8,
|
||||
56,
|
||||
48,
|
||||
52,
|
||||
75,
|
||||
-5,
|
||||
16,
|
||||
64,
|
||||
-85,
|
||||
29,
|
||||
37,
|
||||
32,
|
||||
40,
|
||||
26,
|
||||
-13,
|
||||
7,
|
||||
-61,
|
||||
-49,
|
||||
-48,
|
||||
93,
|
||||
-29,
|
||||
-18,
|
||||
-12,
|
||||
-31,
|
||||
89,
|
||||
39,
|
||||
-45,
|
||||
-103,
|
||||
-26,
|
||||
-12,
|
||||
5,
|
||||
-29,
|
||||
-88,
|
||||
102,
|
||||
-107,
|
||||
-122,
|
||||
15,
|
||||
-43,
|
||||
-57,
|
||||
-44,
|
||||
83,
|
||||
100,
|
||||
7,
|
||||
116,
|
||||
-125,
|
||||
-78,
|
||||
-6,
|
||||
32,
|
||||
46,
|
||||
115,
|
||||
106,
|
||||
-81,
|
||||
90,
|
||||
-40,
|
||||
99,
|
||||
55,
|
||||
-128,
|
||||
41,
|
||||
-20,
|
||||
93,
|
||||
-58,
|
||||
71,
|
||||
50,
|
||||
-90,
|
||||
-52,
|
||||
-16,
|
||||
112,
|
||||
60,
|
||||
97,
|
||||
-84,
|
||||
7,
|
||||
-22,
|
||||
-23,
|
||||
-105,
|
||||
78,
|
||||
105,
|
||||
3,
|
||||
34,
|
||||
-105,
|
||||
-33,
|
||||
112,
|
||||
122,
|
||||
-43,
|
||||
24,
|
||||
-34,
|
||||
87,
|
||||
24,
|
||||
-95,
|
||||
-51,
|
||||
-81,
|
||||
-29,
|
||||
-31,
|
||||
18,
|
||||
-36,
|
||||
-38,
|
||||
-32,
|
||||
-64,
|
||||
-115,
|
||||
13,
|
||||
88,
|
||||
-85,
|
||||
6,
|
||||
-77,
|
||||
-122,
|
||||
-36,
|
||||
94,
|
||||
-106,
|
||||
-122,
|
||||
97,
|
||||
-43,
|
||||
-110,
|
||||
36,
|
||||
41,
|
||||
54,
|
||||
91,
|
||||
18,
|
||||
16,
|
||||
105,
|
||||
-124,
|
||||
-86
|
||||
],
|
||||
"photoBase64": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABjElEQVR42mL8//8/AyUYiBQYmIw3..."
|
||||
}
|
||||
|
||||
export const mockPassportDatas = [
|
||||
mockPassportData_sha256_rsa_65537,
|
||||
mockPassportData_sha1_rsa_65537,
|
||||
mockPassportData_sha256_rsapss_65537,
|
||||
mockPassportData2_sha256_rsa_65537
|
||||
// mockPassportData_SHA384withECDSA // temp cause formatting of ecdsa key is not done well now
|
||||
]
|
||||
|
||||
@@ -182,25 +182,25 @@ export function generateCircuitInputsOfac(
|
||||
const namedob_leaf = getNameDobLeaf(mrz_bytes.slice(10,49), mrz_bytes.slice(62, 68)) // [57-62] + 5 shift
|
||||
const name_leaf = getNameLeaf(mrz_bytes.slice(10,49)) // [6-44] + 5 shift
|
||||
|
||||
let root, depth, closestleaf, indices, exSiblings, membership;
|
||||
let root, depth, closestleaf, indices, siblings, membership;
|
||||
if(proofLevel == 3){
|
||||
({root, depth, closestleaf, indices, exSiblings, membership} = generateSMTProof(sparsemerkletree, passport_leaf));
|
||||
({root, depth, closestleaf, indices, siblings, membership} = generateSMTProof(sparsemerkletree, passport_leaf));
|
||||
} else if(proofLevel == 2){
|
||||
({root, depth, closestleaf, indices, exSiblings, membership} = generateSMTProof(sparsemerkletree, namedob_leaf));
|
||||
({root, depth, closestleaf, indices, siblings, membership} = generateSMTProof(sparsemerkletree, namedob_leaf));
|
||||
} else if (proofLevel == 1){
|
||||
({root, depth, closestleaf, indices, exSiblings, membership} = generateSMTProof(sparsemerkletree, name_leaf));
|
||||
({root, depth, closestleaf, indices, siblings, membership} = generateSMTProof(sparsemerkletree, name_leaf));
|
||||
} else {
|
||||
throw new Error("Invalid proof level")
|
||||
}
|
||||
const exists = membership ? 1 : 0;
|
||||
|
||||
|
||||
return {
|
||||
...finalResult,
|
||||
leaf_value: [BigInt(closestleaf).toString()],
|
||||
smt_root: [root.toString()],
|
||||
smt_root: [BigInt(root).toString()],
|
||||
smt_size: [BigInt(depth).toString()],
|
||||
smt_path : indices.map(index => BigInt(index).toString()),
|
||||
smt_siblings: exSiblings.map(index => BigInt(index).toString()),
|
||||
smt_siblings: siblings.map(index => BigInt(index).toString()),
|
||||
membership: [BigInt(exists).toString()],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { sha256 } from 'js-sha256';
|
||||
import { sha1 } from 'js-sha1';
|
||||
import { sha384 } from 'js-sha512';
|
||||
import { SMT } from '@ashpect/smt';
|
||||
import { poseidon2, poseidon3 } from 'poseidon-lite';
|
||||
|
||||
export function formatMrz(mrz: string) {
|
||||
const mrzCharcodes = [...mrz].map(char => char.charCodeAt(0));
|
||||
@@ -301,38 +302,38 @@ export function packBytes(unpacked) {
|
||||
|
||||
export function generateSMTProof(smt: SMT, leaf: bigint) {
|
||||
const {entry, matchingEntry, siblings, root, membership} = smt.createProof(leaf);
|
||||
// console.log("entry:",entry)
|
||||
// console.log("entry type",typeof entry)
|
||||
// console.log("entry length",entry.length)
|
||||
// console.log("sibilings length",siblings.length)
|
||||
// console.log("matching entry",matchingEntry)
|
||||
|
||||
const depth = siblings.length
|
||||
siblings.reverse()
|
||||
const bits = entry[0].toString(2)
|
||||
const arr = bits.padStart(256, "0").split("").reverse().map(Number)
|
||||
const path = arr.slice(0, depth).reverse()
|
||||
const exSiblings = new Array(256).fill(0n);
|
||||
const indices = new Array(256).fill(0);
|
||||
let closestleaf;
|
||||
if (!matchingEntry){
|
||||
closestleaf = entry[0];
|
||||
} else {
|
||||
closestleaf = matchingEntry[0];
|
||||
}
|
||||
|
||||
for (let i = 0; i < depth; i++) {
|
||||
exSiblings[i] = siblings[i];
|
||||
indices[i] = path[i];
|
||||
let closestleaf;
|
||||
if (!matchingEntry){ // we got the 0 leaf or membership
|
||||
// then check if entry[1] exists
|
||||
if(!entry[1]){
|
||||
// non membership proof
|
||||
console.log("entry[1] is 0")
|
||||
closestleaf = BigInt(0); // 0 leaf
|
||||
} else {
|
||||
closestleaf = poseidon3(entry); // leaf itself (memb proof)
|
||||
}
|
||||
} else {
|
||||
closestleaf = poseidon3(matchingEntry); // actual closest
|
||||
}
|
||||
|
||||
const bits = entry[0].toString(2).slice(-depth);
|
||||
let indices = bits.padEnd(256, "0").split("").map(Number)
|
||||
siblings.reverse()
|
||||
|
||||
while(indices.length < 256) indices.push(0);
|
||||
while(siblings.length < 256) siblings.push(BigInt(0));
|
||||
// get to 256 for computation in circuit
|
||||
|
||||
// CALCULATED ROOT FOR TESTING --
|
||||
// let calculatedNode = poseidon3(entry)
|
||||
// let calculatedNode = BigInt(0) // 0 node , if entry[1] is 0.
|
||||
// // CALCULATED ROOT FOR TESTING -- // Useful for debugging hence leaving as comments
|
||||
// closestleaf, depth, siblings, indices, root : needed
|
||||
// let calculatedNode = closestleaf;
|
||||
// console.log("Initial node while calculating",calculatedNode)
|
||||
// console.log(smt.verifyProof(smt.createProof(leaf)))
|
||||
// for (let i = 0; i < depth ; i++) {
|
||||
// const childNodes: any = indices[i] ? [exSiblings[i], calculatedNode] : [calculatedNode, exSiblings[i]]
|
||||
// for (let i= 0; i < depth ; i++) {
|
||||
// const childNodes: any = indices[i] ? [siblings[i], calculatedNode] : [calculatedNode, siblings[i]]
|
||||
// console.log(indices[i],childNodes)
|
||||
// calculatedNode = poseidon2(childNodes)
|
||||
// }
|
||||
// console.log("Actual node", root)
|
||||
@@ -343,7 +344,7 @@ export function generateSMTProof(smt: SMT, leaf: bigint) {
|
||||
depth,
|
||||
closestleaf,
|
||||
indices,
|
||||
exSiblings,
|
||||
siblings,
|
||||
membership,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user