@@ -55,9 +55,7 @@ type ffi_MerkleProof* = object
5555
5656# -------------------------------- Identity Generation -----------------------------------------
5757
58- proc ffi_key_gen * (
59- output: ptr ffi_IdentityCredential
60- ): bool {.importc : " ffi_key_gen" .}
58+ proc ffi_key_gen * (output: ptr ffi_IdentityCredential): bool {.importc : " ffi_key_gen" .}
6159
6260# # Generates identity trapdoor, identity nullifier, identity secret hash and id commitment
6361# # Output is written directly to the ffi_IdentityCredential struct
@@ -199,54 +197,89 @@ proc ffi_hash_to_field_be*(
199197# # Hashes arbitrary bytes to a field element (big-endian)
200198# # Returns true on success, false on failure
201199
202- proc ffi_poseidon_hash * (
203- inputs : ptr Vec [ CFr ], output : ptr CFr
204- ): bool {.importc : " ffi_poseidon_hash " .}
200+ proc ffi_poseidon_hash_pair * (
201+ a : ptr CFr , b : ptr CFr
202+ ): ptr CFr {.importc : " ffi_poseidon_hash_pair " .}
205203
206- # # Computes Poseidon hash of field elements
204+ # # Computes Poseidon hash of two field elements
207205# # Used for identity secret hash and external nullifier
208- # # Returns true on success, false on failure
206+ # # Returns pointer to boxed CFr result (must be freed with cfr_free)
209207
210208# -------------------------------- Serialization Utilities -----------------------------------------
211209
212- proc ffi_cfr_serialize * (
213- fr: ptr CFr , output: ptr Vec [uint8 ]
214- ): bool {.importc : " ffi_cfr_serialize" .}
210+ proc cfr_to_bytes_le * (cfr: ptr CFr ): Vec [uint8 ] {.importc : " cfr_to_bytes_le" .}
215211
216- # # Serializes a field element to bytes
217- # # Returns true on success, false on failure
212+ # # Serializes a field element to bytes (little-endian)
213+ # # Returns Vec[uint8] containing the serialized bytes
218214
219- proc ffi_cfr_deserialize * (
220- bytes: ptr Vec [uint8 ], output: ptr CFr
221- ): bool {.importc : " ffi_cfr_deserialize" .}
215+ proc cfr_to_bytes_be * (cfr: ptr CFr ): Vec [uint8 ] {.importc : " cfr_to_bytes_be" .}
222216
223- # # Deserializes bytes to a field element
224- # # Returns true on success, false on failure
217+ # # Serializes a field element to bytes (big-endian)
218+ # # Returns Vec[uint8] containing the serialized bytes
225219
226- proc ffi_vec_cfr_serialize * (
227- vec: ptr Vec [CFr ], output: ptr Vec [uint8 ]
228- ): bool {.importc : " ffi_vec_cfr_serialize" .}
220+ proc bytes_le_to_cfr * (bytes: ptr Vec [uint8 ]): ptr CFr {.importc : " bytes_le_to_cfr" .}
229221
230- # # Serializes a vector of field elements to bytes
231- # # Returns true on success, false on failure
222+ # # Deserializes bytes (little-endian) to a field element
223+ # # Returns pointer to boxed CFr (must be freed with cfr_free)
232224
233- proc ffi_vec_cfr_deserialize * (
234- bytes: ptr Vec [uint8 ], output: ptr Vec [CFr ]
235- ): bool {.importc : " ffi_vec_cfr_deserialize" .}
225+ proc bytes_be_to_cfr * (bytes: ptr Vec [uint8 ]): ptr CFr {.importc : " bytes_be_to_cfr" .}
236226
237- # # Deserializes bytes to a vector of field elements
238- # # Returns true on success, false on failure
227+ # # Deserializes bytes (big-endian) to a field element
228+ # # Returns pointer to boxed CFr (must be freed with cfr_free)
229+
230+ proc vec_cfr_to_bytes_le * (
231+ vec: ptr Vec [CFr ]
232+ ): Vec [uint8 ] {.importc : " vec_cfr_to_bytes_le" .}
233+
234+ # # Serializes a vector of field elements to bytes (little-endian)
235+ # # Returns Vec[uint8] containing the serialized bytes
236+
237+ proc vec_cfr_to_bytes_be * (
238+ vec: ptr Vec [CFr ]
239+ ): Vec [uint8 ] {.importc : " vec_cfr_to_bytes_be" .}
240+
241+ # # Serializes a vector of field elements to bytes (big-endian)
242+ # # Returns Vec[uint8] containing the serialized bytes
243+
244+ # # CResult type for functions that can return errors
245+ type CResult * [T, E] = object
246+ ok* : ptr T
247+ err* : ptr E
239248
240- proc ffi_cfr_from_uint * (
241- value: uint64 , output: ptr CFr
242- ): bool {.importc : " ffi_cfr_from_uint" .}
249+ proc bytes_le_to_vec_cfr * (
250+ bytes: ptr Vec [uint8 ]
251+ ): CResult [ptr Vec [CFr ], cstring ] {.importc : " bytes_le_to_vec_cfr" .}
252+
253+ # # Deserializes bytes (little-endian) to a vector of field elements
254+ # # Returns CResult with either ok (ptr Vec[CFr]) or err (cstring)
255+
256+ proc bytes_be_to_vec_cfr * (
257+ bytes: ptr Vec [uint8 ]
258+ ): CResult [ptr Vec [CFr ], cstring ] {.importc : " bytes_be_to_vec_cfr" .}
259+
260+ # # Deserializes bytes (big-endian) to a vector of field elements
261+ # # Returns CResult with either ok (ptr Vec[CFr]) or err (cstring)
262+
263+ proc uint_to_cfr * (value: uint32 ): ptr CFr {.importc : " uint_to_cfr" .}
243264
244265# # Creates a field element from an unsigned integer
245- # # Returns true on success, false on failure
266+ # # Returns pointer to boxed CFr (must be freed with cfr_free)
267+ # # Note: Takes uint32, not uint64
246268
247- proc ffi_cfr_zero * (output : ptr CFr ): bool {.importc : " ffi_cfr_zero " .}
269+ proc cfr_zero * () : ptr CFr {.importc : " cfr_zero " .}
248270# # Creates a zero field element
249- # # Returns true on success, false on failure
271+ # # Returns pointer to boxed CFr (must be freed with cfr_free)
272+
273+ proc cfr_one * (): ptr CFr {.importc : " cfr_one" .}
274+ # # Creates a one field element
275+ # # Returns pointer to boxed CFr (must be freed with cfr_free)
276+
277+ proc cfr_free * (cfr: ptr CFr ) {.importc : " cfr_free" .}
278+ # # Frees a boxed CFr
279+ # # Must be called for all CFr pointers returned by the API
280+
281+ proc cfr_debug * (cfr: ptr CFr ): cstring {.importc : " cfr_debug" .}
282+ # # Returns debug string representation of CFr
250283
251284# -------------------------------- Helper Procedures -----------------------------------------
252285
0 commit comments