@@ -25,12 +25,17 @@ router.get("/gen/running", async (req, res) => {
2525 "./circom2contract/running/circuit_final.zkey"
2626 ) ;
2727
28- const proofHex = convertProofToHex ( proof ) ;
28+ const proofArrObj = reorderDict ( proof ) ;
29+
30+ const tempProof = convertProofToHex ( proofArrObj )
31+ const formattedProof = convertObjectToHexPadded ( tempProof ) ;
2932 const pubSignalHex = convertToHexPadded ( publicSignals ) ;
3033
34+ console . log ( "length:" , formattedProof . length ) ;
35+
3136 res . send ( {
3237 proof : proof ,
33- proofHex : proofHex ,
38+ proofHex : formattedProof ,
3439 publicSignals : publicSignals ,
3540 publicSignalsHex : pubSignalHex ,
3641 } ) ;
@@ -44,11 +49,11 @@ router.get("/gen/sleeping", async (req, res) => {
4449 const input = {
4550 startTime : body . startTime ,
4651 endTime : body . endTime ,
47- sleepHour : body . sleepHour ,
52+ sleepTime : body . sleepTime ,
4853 sleepLength : body . sleepLength ,
4954 minStartTime : body . minStartTime ,
5055 maxEndTime : body . maxEndTime ,
51- maxSleepHour : body . maxSleepHour ,
56+ sleepBefore : body . sleepBefore ,
5257 minSleepLength : body . minSleepLength ,
5358 } ;
5459 try {
@@ -57,14 +62,17 @@ router.get("/gen/sleeping", async (req, res) => {
5762 "./circom2contract/sleeping/sleeping_js/sleeping.wasm" ,
5863 "./circom2contract/sleeping/circuit_final.zkey"
5964 ) ;
65+ const proofArrObj = reorderDict ( proof ) ;
6066
61- const proofObjHex = convertProofToObjectHex ( proof ) ;
62- const proofArrHex = convertObjectToHexPadded ( proofObjHex )
67+ const tempProof = convertProofToHex ( proofArrObj )
68+ const formattedProof = convertObjectToHexPadded ( tempProof ) ;
6369 const pubSignalHex = convertToHexPadded ( publicSignals ) ;
6470
71+ console . log ( "length:" , formattedProof . length ) ;
72+
6573 res . send ( {
6674 proof : proof ,
67- proofHex : proofArrHex ,
75+ proofHex : formattedProof ,
6876 publicSignals : publicSignals ,
6977 publicSignalsHex : pubSignalHex ,
7078 } ) ;
@@ -73,7 +81,43 @@ router.get("/gen/sleeping", async (req, res) => {
7381 }
7482} ) ;
7583
76- function convertProofToObjectHex ( proof ) {
84+ function convertObjectToHexPadded ( obj ) {
85+ const hexArray = [ ] ;
86+
87+ // Function to convert a single BigInt number to a padded hex string
88+ const toPaddedHexString = ( bigInt ) => {
89+ return "0x" + bigInt . toString ( 16 ) . padStart ( 64 , "0" ) ;
90+ } ;
91+
92+ // Iterate over each key in the object
93+ for ( const key of Object . keys ( obj ) ) {
94+ const value = obj [ key ] ;
95+
96+ // Check if the value is an array (handle nested arrays too)
97+ if ( Array . isArray ( value ) ) {
98+ // Handle nested arrays for points like A, B, C, etc.
99+ if ( Array . isArray ( value [ 0 ] ) ) {
100+ value . forEach ( ( innerArray ) => {
101+ innerArray . forEach ( ( number ) => {
102+ hexArray . push ( toPaddedHexString ( BigInt ( number ) ) ) ;
103+ } ) ;
104+ } ) ;
105+ } else {
106+ // Handle flat arrays for points like eval_a, eval_b, etc.
107+ value . forEach ( ( number ) => {
108+ hexArray . push ( toPaddedHexString ( BigInt ( number ) ) ) ;
109+ } ) ;
110+ }
111+ } else {
112+ // Handle single values that are not arrays
113+ hexArray . push ( toPaddedHexString ( BigInt ( value ) ) ) ;
114+ }
115+ }
116+
117+ return hexArray ;
118+ }
119+
120+ function convertProofToHex ( proof ) {
77121 // Helper function to convert to a 0x-prefixed hexadecimal string
78122 const toHex = ( numStr ) => {
79123 return "0x" + BigInt ( numStr ) . toString ( 16 ) ;
@@ -96,6 +140,32 @@ function convertProofToObjectHex(proof) {
96140 return convertedProof ;
97141}
98142
143+ function reorderDict ( dict ) {
144+ dictReorder = [
145+ { key : "A" , value : dict [ "A" ] } ,
146+ { key : "B" , value : dict [ "B" ] } ,
147+ { key : "C" , value : dict [ "C" ] } ,
148+ { key : "Z" , value : dict [ "Z" ] } ,
149+ { key : "T1" , value : dict [ "T1" ] } ,
150+ { key : "T2" , value : dict [ "T2" ] } ,
151+ { key : "T3" , value : dict [ "T3" ] } ,
152+ { key : "Wxi" , value : dict [ "Wxi" ] } ,
153+ { key : "Wxiw" , value : dict [ "Wxiw" ] } ,
154+ { key : "eval_a" , value : dict [ "eval_a" ] } ,
155+ { key : "eval_b" , value : dict [ "eval_b" ] } ,
156+ { key : "eval_c" , value : dict [ "eval_c" ] } ,
157+ { key : "eval_s1" , value : dict [ "eval_s1" ] } ,
158+ { key : "eval_s2" , value : dict [ "eval_s2" ] } ,
159+ { key : "eval_zw" , value : dict [ "eval_zw" ] } ,
160+ ] ;
161+ result = { }
162+ for ( let item of dictReorder ) {
163+ result [ item . key ] = item . value ;
164+ }
165+
166+ return result ;
167+ }
168+
99169function convertToHexPadded ( pubSignals ) {
100170 return pubSignals . map ( ( signal ) => {
101171 // Convert the decimal string to a BigInt
@@ -111,41 +181,4 @@ function convertToHexPadded(pubSignals) {
111181 return paddedHex ;
112182 } ) ;
113183}
114-
115- function convertObjectToHexPadded ( obj ) {
116- const hexArray = [ ] ;
117-
118- // Function to convert a single BigInt number to a padded hex string
119- const toPaddedHexString = ( bigInt ) => {
120- return "0x" + bigInt . toString ( 16 ) . padStart ( 64 , "0" ) ;
121- } ;
122-
123- // Iterate over each key in the object
124- for ( const key of Object . keys ( obj ) ) {
125- const value = obj [ key ] ;
126-
127- // Check if the value is an array (handle nested arrays too)
128- if ( Array . isArray ( value ) ) {
129- // Handle nested arrays for points like A, B, C, etc.
130- if ( Array . isArray ( value [ 0 ] ) ) {
131- value . forEach ( ( innerArray ) => {
132- innerArray . forEach ( ( number ) => {
133- hexArray . push ( toPaddedHexString ( BigInt ( number ) ) ) ;
134- } ) ;
135- } ) ;
136- } else {
137- // Handle flat arrays for points like eval_a, eval_b, etc.
138- value . forEach ( ( number ) => {
139- hexArray . push ( toPaddedHexString ( BigInt ( number ) ) ) ;
140- } ) ;
141- }
142- } else {
143- // Handle single values that are not arrays
144- hexArray . push ( toPaddedHexString ( BigInt ( value ) ) ) ;
145- }
146- }
147-
148- return hexArray ;
149- }
150-
151184module . exports = router ;
0 commit comments