In Besu, we often use C, Rust, or Go for the cryptographic part. This is mainly because these languages tend to offer better performance.
When we want to add a new native library to Besu, it is relatively straightforward. We simply need to add it to the project.
https://github.com/hyperledger/besu-native
Integrating a library into Besu can be done by following these general steps:
for example this one
https://github.com/hyperledger/besu-native/tree/main/gnark
In the directory, you will find two parts:
gnark-jni
which will contain the JNI wrapper allowing Java to call the Go library.go.mod
which will contain the import link to the Go library.gnark-jni.go
will contain the methods that Java can call, using //export
to indicate that the method is exposed.
In this class, you need to perform the necessary conversions to transform objects coming from Java into objects that can be used by the Go library.
build.sh
file of the Besu Native projectbuild.sh
file.You can create a Java class to test your code and verify that the JNI part is working correctly.