Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
c_bind.cpp
Go to the documentation of this file.
1#include "c_bind.hpp"
4#include "barretenberg/bbapi/generated/bb_dispatch.hpp"
7#include <cstdlib>
8#include <cstring>
9#include <vector>
10
11namespace bb::bbapi {
12
13namespace {
14// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
15BBApiRequest global_request;
16} // namespace
17
18} // namespace bb::bbapi
19
20// WASM-exported bbapi entry point. Takes msgpack-encoded `[ [name, payload] ]`
21// (tuple-wrapped command in NamedUnion shape), returns msgpack-encoded
22// `[name, payload]` (response in NamedUnion shape). The codegen-emitted
23// dispatcher owns the command-name → handle_<method> table and runs the
24// per-call deserialize / serialize / exception → ErrorResponse plumbing.
25WASM_EXPORT void bbapi(const uint8_t* input_in, size_t input_len_in, uint8_t** output_out, size_t* output_len_out)
26{
27 auto handler = bb::bbapi::make_bb_handler(bb::bbapi::global_request);
28 std::vector<uint8_t> input(input_in, input_in + input_len_in);
29 std::vector<uint8_t> response = handler(input);
30
31 *output_out = static_cast<uint8_t*>(aligned_alloc(64, response.size() + 1));
32 std::memcpy(*output_out, response.data(), response.size());
33 *output_len_out = response.size();
34}
Non-template handler declarations for the bb service.
Shared type definitions for the Barretenberg RPC API.
WASM_EXPORT void bbapi(const uint8_t *input_in, size_t input_len_in, uint8_t **output_out, size_t *output_len_out)
Definition c_bind.cpp:25
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define WASM_EXPORT