ffi-bbs-signatures
ffi-bbs-signatures copied to clipboard
Cannot add a string message to `bbs_sign_context`
I am currently writing a wrapper in c++ for this library (so it can eventually be used in React Native), but I am running into an issue that I do not know how to resolve.
Currently, I can call bbs_sign_context_init()
without any errors like this:
double NativeBbsSignatures::bbs_sign_context_init(jsi::Runtime &rt) {
ExternError *err = new ExternError();
uint64_t res = ::bbs_sign_context_init(err);
return res;
}
Then when calling bbs_sign_context_add_message_string()
:
double NativeBbsSignatures::bbs_sign_context_add_message_string(jsi::Runtime &rt, const jsi::Object &options) {
uint64_t handle = TurboModuleUtils::jsiToValue<uint64_t>(rt, options.getProperty(rt, "handle"));
std::string message = TurboModuleUtils::jsiToValue<std::string>(rt, options.getProperty(rt, "message"));
ExternError *err = new ExternError();
int32_t res = ::bbs_sign_context_add_message_string(handle, message.c_str(), err);
// error code : -1000
// error message: "handle has stale version number"
return res;
}
The error comes from ffi-support
when checking the validity of the handle. It says that the handle is stale and it indicates something equivalent to a use-after-free / double-free, etc.
Did this happen to anyone else writing a wrapper for this library? @tmarkovski @alexksg
Hey @blu3beri im unsure exactly of the issue you are facing here, I've not encountered this before, but I've also not tried the library with C++. If you are looking for RN support I'd recommend taking the objective-c and java wrappers published by these libraries and bringing them together in a TS/JS package using the react native native module bridge (https://reactnative.dev/docs/native-modules-ios)
I have not encountered this, seems odd that the library would report this. Does this happen if you make a call to context_init
and add_message_string
right after, not in a different API method? Could it be that RN unloads the library domain after each call?
Thanks for the responses. It seems to only error when we pass the handle over the bridge and then back when we want to do the next step (add_message_string
). Keeping the handle inside the cpp environment and then continuing the flow seems to work. The library is not closed as the handle is still in the concurrentHandleMap
but it seems that it refers to something else (Not the best explanation).
Keeping the handle inside cpp and only return back to RN when bbs_sign_context_finish()
is called seems to be the trick. Thanks for the help :).
pseudo code:
// This works
int main() {
ExternError *err = new ExternError();
auto handle = ::bbs_sign_context_init(err);
::bbs_sign_context_add_message(...);
return 0;
}
btw @tplooker for this library we are using React Native TurboModules instead of the NativeModules. They are for faster synchronous code but it is rather undocumented. Hopefully it will get a proper public release soon.