Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::nodejs Namespace Reference

Namespaces

namespace  lmdb_store
 
namespace  msgpack_client
 

Classes

class  AsyncMessageProcessor
 
class  AsyncOperation
 Encapsulatest some work that can be done off the JavaScript main thread. More...
 
class  AvmSimulateNapi
 NAPI wrapper for the C++ AVM simulation. More...
 
struct  CallbackResults
 Helper struct to pass data between C++ worker thread and JS main thread. More...
 
class  ThreadedAsyncOperation
 Runs work on a dedicated std::thread instead of the libuv thread pool. More...
 
class  TsCallbackContractDB
 Implementation of ContractDBInterface that uses NAPI callbacks to TypeScript. More...
 

Typedefs

using async_fn = std::function< void(msgpack::sbuffer &)>
 

Functions

std::string extract_error_from_napi_value (const Napi::CallbackInfo &cb_info)
 Extracts error message from a Napi value (string or Error object)
 
Napi::Function create_buffer_resolve_handler (Napi::Env env, std::shared_ptr< CallbackResults > cb_results)
 Creates a resolve handler for promises that return Buffer | undefined.
 
Napi::Function create_string_resolve_handler (Napi::Env env, std::shared_ptr< CallbackResults > cb_results)
 Creates a resolve handler for promises that return string | undefined.
 
Napi::Function create_void_resolve_handler (Napi::Env env, std::shared_ptr< CallbackResults > cb_results)
 Creates a resolve handler for promises that return void.
 
Napi::Function create_reject_handler (Napi::Env env, std::shared_ptr< CallbackResults > cb_results)
 Creates a reject handler for promises.
 
void attach_promise_handlers (Napi::Promise promise, Napi::Function resolve_handler, Napi::Function reject_handler)
 Attaches resolve and reject handlers to a promise.
 
template<typename T >
std::vector< uint8_t > serialize_to_msgpack (const T &data)
 Serializes data to msgpack format.
 
template<typename T >
deserialize_from_msgpack (const std::vector< uint8_t > &data, const std::string &type_name)
 Deserializes msgpack data to a specific type.
 
std::optional< std::vector< uint8_t > > invoke_ts_callback_with_promise (const Napi::ThreadSafeFunction &callback, const std::string &operation_name, std::function< void(Napi::Env, Napi::Function, std::shared_ptr< CallbackResults >)> call_js_function, std::chrono::seconds timeout=std::chrono::seconds(60))
 Generic callback invoker that handles the full BlockingCall pattern.
 
std::optional< std::vector< uint8_t > > invoke_single_string_callback (const Napi::ThreadSafeFunction &callback, const std::string &input_str, const std::string &operation_name)
 Helper for callbacks that take a single string argument and return Buffer | undefined.
 
std::optional< std::vector< uint8_t > > invoke_double_string_callback (const Napi::ThreadSafeFunction &callback, const std::string &input_str1, const std::string &input_str2, const std::string &operation_name)
 Helper for callbacks that take two string arguments and return string | undefined.
 
void invoke_buffer_void_callback (const Napi::ThreadSafeFunction &callback, std::vector< uint8_t > buffer_data, const std::string &operation_name)
 Helper for callbacks that take a buffer and return void.
 
template std::vector< uint8_t > serialize_to_msgpack (const bb::avm2::ContractDeploymentData &data)
 
template bb::avm2::ContractInstance deserialize_from_msgpack (const std::vector< uint8_t > &data, const std::string &type_name)
 
std::string ff_to_string (const bb::avm2::FF &value)
 Converts an FF (field element) to a hex string.
 
Napi::Promise promise_reject (const Napi::Env &env, const Napi::Value &err)
 

Typedef Documentation

◆ async_fn

using bb::nodejs::async_fn = typedef std::function<void(msgpack::sbuffer&)>

Definition at line 16 of file async_op.hpp.

Function Documentation

◆ attach_promise_handlers()

void bb::nodejs::attach_promise_handlers ( Napi::Promise  promise,
Napi::Function  resolve_handler,
Napi::Function  reject_handler 
)

Attaches resolve and reject handlers to a promise.

Definition at line 118 of file ts_callback_utils.cpp.

◆ create_buffer_resolve_handler()

Napi::Function bb::nodejs::create_buffer_resolve_handler ( Napi::Env  env,
std::shared_ptr< CallbackResults cb_results 
)

Creates a resolve handler for promises that return Buffer | undefined.

Note
Takes shared_ptr to ensure CallbackResults outlives the Promise handler

Definition at line 28 of file ts_callback_utils.cpp.

◆ create_reject_handler()

Napi::Function bb::nodejs::create_reject_handler ( Napi::Env  env,
std::shared_ptr< CallbackResults cb_results 
)

Creates a reject handler for promises.

Note
Takes shared_ptr to ensure CallbackResults outlives the Promise handler

Definition at line 105 of file ts_callback_utils.cpp.

◆ create_string_resolve_handler()

Napi::Function bb::nodejs::create_string_resolve_handler ( Napi::Env  env,
std::shared_ptr< CallbackResults cb_results 
)

Creates a resolve handler for promises that return string | undefined.

Note
Takes shared_ptr to ensure CallbackResults outlives the Promise handler

Definition at line 61 of file ts_callback_utils.cpp.

◆ create_void_resolve_handler()

Napi::Function bb::nodejs::create_void_resolve_handler ( Napi::Env  env,
std::shared_ptr< CallbackResults cb_results 
)

Creates a resolve handler for promises that return void.

Note
Takes shared_ptr to ensure CallbackResults outlives the Promise handler

Definition at line 93 of file ts_callback_utils.cpp.

◆ deserialize_from_msgpack() [1/2]

template<typename T >
T bb::nodejs::deserialize_from_msgpack ( const std::vector< uint8_t > &  data,
const std::string &  type_name 
)

Deserializes msgpack data to a specific type.

Definition at line 136 of file ts_callback_utils.cpp.

◆ deserialize_from_msgpack() [2/2]

template bb::avm2::ContractInstance bb::nodejs::deserialize_from_msgpack ( const std::vector< uint8_t > &  data,
const std::string &  type_name 
)

◆ extract_error_from_napi_value()

std::string bb::nodejs::extract_error_from_napi_value ( const Napi::CallbackInfo &  cb_info)

Extracts error message from a Napi value (string or Error object)

Definition at line 11 of file ts_callback_utils.cpp.

◆ ff_to_string()

std::string bb::nodejs::ff_to_string ( const bb::avm2::FF value)

Converts an FF (field element) to a hex string.

◆ invoke_buffer_void_callback()

void bb::nodejs::invoke_buffer_void_callback ( const Napi::ThreadSafeFunction &  callback,
std::vector< uint8_t >  buffer_data,
const std::string &  operation_name 
)

Helper for callbacks that take a buffer and return void.

Definition at line 252 of file ts_callback_utils.cpp.

◆ invoke_double_string_callback()

std::optional< std::vector< uint8_t > > bb::nodejs::invoke_double_string_callback ( const Napi::ThreadSafeFunction &  callback,
const std::string &  input_str1,
const std::string &  input_str2,
const std::string &  operation_name 
)

Helper for callbacks that take two string arguments and return string | undefined.

Definition at line 224 of file ts_callback_utils.cpp.

◆ invoke_single_string_callback()

std::optional< std::vector< uint8_t > > bb::nodejs::invoke_single_string_callback ( const Napi::ThreadSafeFunction &  callback,
const std::string &  input_str,
const std::string &  operation_name 
)

Helper for callbacks that take a single string argument and return Buffer | undefined.

Definition at line 199 of file ts_callback_utils.cpp.

◆ invoke_ts_callback_with_promise()

std::optional< std::vector< uint8_t > > bb::nodejs::invoke_ts_callback_with_promise ( const Napi::ThreadSafeFunction &  callback,
const std::string &  operation_name,
std::function< void(Napi::Env, Napi::Function, std::shared_ptr< CallbackResults >)>  call_js_function,
std::chrono::seconds  timeout = std::chrono::seconds(60) 
)

Generic callback invoker that handles the full BlockingCall pattern.

This template function encapsulates the entire promise-based async callback flow:

  1. Creates promise/future synchronization
  2. Invokes JS callback via BlockingCall
  3. Handles promise resolution/rejection
  4. Waits with timeout
  5. Returns optional result
Note
The call_js_function receives a shared_ptr to CallbackResults. The shared_ptr MUST be captured by the Promise handlers to ensure the CallbackResults outlives the Promise. This prevents use-after-free when timeouts occur before the Promise resolves.

Definition at line 149 of file ts_callback_utils.cpp.

◆ promise_reject()

Napi::Promise bb::nodejs::promise_reject ( const Napi::Env &  env,
const Napi::Value &  err 
)

Definition at line 6 of file promise.cpp.

◆ serialize_to_msgpack() [1/2]

template std::vector< uint8_t > bb::nodejs::serialize_to_msgpack ( const bb::avm2::ContractDeploymentData data)

◆ serialize_to_msgpack() [2/2]

template<typename T >
std::vector< uint8_t > bb::nodejs::serialize_to_msgpack ( const T &  data)

Serializes data to msgpack format.

Definition at line 129 of file ts_callback_utils.cpp.