In this short guide we will roughly implement generated witnesscalc .cpp files from circom in react-native app.
I'll do it in
And finally, we will use
- configure path in your
.bashrcor.zshrcconfig file

- clone
follow readme "preparation" to install necessary deps
Now let's take a look at src folder:
- create
witnesscalc_auth.cppandwitnesscalc_auth.hfiles under src folder
You could check all the same files, their content is exact same, except the name, so we have done like so.
- now add these files to
./CMakeLists.txt
as before, you should notice, that this code is the same as code above in this file, so we just copied them and changed name
And these steps should be done for every .cpp & .dat files you will add.
in this case you can use
in root ./CMakeLists.txt file
and also except src/witnesscalc.h, it’s necessary too
Now you can run these commands to compile your executable files
./build_gmp.sh android // only once
make android // every time u want to compile new wtns calcs
The result:
to turn it on.
We will implement our generated file in for that.
so let's start
npx create-react-native-library@latest wtnscalcs
this is what we see after scaffolding our module, and to modify the code, it’s would be better to open via android-studio
we ARE NOT going to open this android folder, but should open a root android folder, this one:
here is our module, and by modifying it, our code in ./modules/[module]/android folder will be changed too
so what we see now:
and the cmake structure which points to our CMakeLists.txt, which is register our future cpp file with logic
and then .h file for it
Now, let’s back to our "frontend perspective" e.g IDE or editor where your react-native project are, and take a look in to spec file in module, which responsible to register our module with native code and define top-level interface
By defining methods in this "Spec" interface
And by exposing method from index.tsx we will be able to call method from module as a regular npm-pkg
Nice, now let's jump straight in to hard mode:
let's define what we need:
1) first of all, at the very top level we have "inputs" which witness calculator will accept in the future
2) we need to send these inputs to our native module, pass it to .so file
3) execute and return bytes, it should be the same as circom compiles .wtns file, but we will keep file content in ram, instead of file
Now, let's write this implementation code, and leave it empty for a while
and paste there our auth.dat file
- get back to "Frontend perspective", create lib folder under modules/android directory and paste there a
.sofile
cmake_minimum_required(VERSION 3.4.1)
project(RnWtnscalcs)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 14)
add_library(rn-wtnscalcs SHARED
../cpp/rn-wtnscalcs.cpp
cpp-adapter.cpp
)
# Specifies a path to native header files.
include_directories(
../cpp
)
link_directories(lib)
add_library(auth SHARED IMPORTED)
set_target_properties(auth PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_auth.so)
target_link_libraries(rn-wtnscalcs
android
auth)
what we have done:
- We linked directories where we've placed our .so file
- Registered our .so file as library
- And finally ‘target_link_libraries’ will compile it for us in one executable file, which we can call in runtime
After these steps we will be able to execute .so file in runtime
let's write the code to call it:
these steps will create binded function in our rn-wtnscalcs.cpp file, but let’s move it to cpp-adapter.cpp
and use it in implemented function in our module.kt file, which we have leaved empty:
SOCIAL SHARE CARD GENERATOR