Format node bindings with clang-format (#268)
This commit is contained in:
parent
dd5ec7ba7e
commit
e9c9c912f6
|
@ -27,9 +27,13 @@ jobs:
|
|||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
- name: Check formatting
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
working-directory: bindings/node.js
|
||||
run: make format
|
||||
- name: Build/test bindings
|
||||
working-directory: bindings/node.js
|
||||
run: make
|
||||
run: make build test bundle
|
||||
- name: Install distribution
|
||||
working-directory: bindings/node.js/dist
|
||||
run: npm install
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# This file is a copy/paste from the one at the root of this repo. It was
|
||||
# placed here for convenience as not all IDE's will pickup the settings
|
||||
# in the root file and there was a fight between the IDE formatting and the
|
||||
# official repo settings. Please keep this file in sync with the root file
|
||||
#
|
||||
|
||||
BasedOnStyle: llvm
|
||||
IndentWidth: 4
|
||||
AllowAllParametersOfDeclarationOnNextLine: True
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: OnlyFirstIf
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
BinPackArguments: False
|
||||
BinPackParameters: False
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PenaltyBreakAssignment: 100
|
|
@ -62,6 +62,7 @@ test: install
|
|||
.PHONY: format
|
||||
format: install
|
||||
@$(YARN) prettier --loglevel=warn --write .
|
||||
@clang-format -i src/kzg.cxx
|
||||
|
||||
# Publish package to npm (requires an auth token)
|
||||
.PHONY: publish
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <sstream> // std::ostringstream
|
||||
#include <string_view>
|
||||
#include <napi.h>
|
||||
#include "c_kzg_4844.h"
|
||||
#include "blst.h"
|
||||
#include "c_kzg_4844.h"
|
||||
#include <iostream>
|
||||
#include <napi.h>
|
||||
#include <sstream> // std::ostringstream
|
||||
#include <stdio.h>
|
||||
#include <string_view>
|
||||
|
||||
/**
|
||||
* Convert C_KZG_RET to a string representation for error messages.
|
||||
|
@ -23,7 +23,6 @@ std::string from_c_kzg_ret(C_KZG_RET ret) {
|
|||
std::ostringstream msg;
|
||||
msg << "UNKNOWN (" << ret << ")";
|
||||
return msg.str();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,9 +57,9 @@ typedef struct {
|
|||
* @param[in] data Pointer KzgAddonData stored by the runtime
|
||||
* @param[in] hint (unused)
|
||||
*/
|
||||
void delete_kzg_addon_data(napi_env /*env*/, void *data, void* /*hint*/) {
|
||||
if (((KzgAddonData*)data)->is_setup) {
|
||||
free_trusted_setup(&((KzgAddonData*)data)->settings);
|
||||
void delete_kzg_addon_data(napi_env /*env*/, void *data, void * /*hint*/) {
|
||||
if (((KzgAddonData *)data)->is_setup) {
|
||||
free_trusted_setup(&((KzgAddonData *)data)->settings);
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
|
@ -84,7 +83,11 @@ void delete_kzg_addon_data(napi_env /*env*/, void *data, void* /*hint*/) {
|
|||
KZGSettings *get_kzg_settings(Napi::Env &env, const Napi::CallbackInfo &info) {
|
||||
KzgAddonData *data = env.GetInstanceData<KzgAddonData>();
|
||||
if (!data->is_setup) {
|
||||
Napi::Error::New(env, "Must run loadTrustedSetup before running any other c-kzg functions").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(
|
||||
env,
|
||||
"Must run loadTrustedSetup before running any other c-kzg functions"
|
||||
)
|
||||
.ThrowAsJavaScriptException();
|
||||
return nullptr;
|
||||
}
|
||||
return &(data->settings);
|
||||
|
@ -121,9 +124,10 @@ inline uint8_t *get_bytes(
|
|||
const Napi::Env &env,
|
||||
const Napi::Value &val,
|
||||
size_t length,
|
||||
std::string_view name)
|
||||
{
|
||||
if (!val.IsTypedArray() || val.As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array) {
|
||||
std::string_view name
|
||||
) {
|
||||
if (!val.IsTypedArray() ||
|
||||
val.As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array) {
|
||||
std::ostringstream msg;
|
||||
msg << "Expected " << name << " to be a Uint8Array";
|
||||
Napi::TypeError::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
|
@ -139,22 +143,32 @@ inline uint8_t *get_bytes(
|
|||
return array.Data();
|
||||
}
|
||||
inline Blob *get_blob(const Napi::Env &env, const Napi::Value &val) {
|
||||
return reinterpret_cast<Blob *>(get_bytes(env, val, BYTES_PER_BLOB, "blob"));
|
||||
return reinterpret_cast<Blob *>(get_bytes(env, val, BYTES_PER_BLOB, "blob")
|
||||
);
|
||||
}
|
||||
inline Bytes32 *get_bytes32(const Napi::Env &env, const Napi::Value &val, std::string_view name) {
|
||||
return reinterpret_cast<Bytes32 *>(get_bytes(env, val, BYTES_PER_FIELD_ELEMENT, name));
|
||||
inline Bytes32 *get_bytes32(
|
||||
const Napi::Env &env, const Napi::Value &val, std::string_view name
|
||||
) {
|
||||
return reinterpret_cast<Bytes32 *>(
|
||||
get_bytes(env, val, BYTES_PER_FIELD_ELEMENT, name)
|
||||
);
|
||||
}
|
||||
inline Bytes48 *get_bytes48(const Napi::Env &env, const Napi::Value &val, std::string_view name) {
|
||||
return reinterpret_cast<Bytes48 *>(get_bytes(env, val, BYTES_PER_COMMITMENT, name));
|
||||
inline Bytes48 *get_bytes48(
|
||||
const Napi::Env &env, const Napi::Value &val, std::string_view name
|
||||
) {
|
||||
return reinterpret_cast<Bytes48 *>(
|
||||
get_bytes(env, val, BYTES_PER_COMMITMENT, name)
|
||||
);
|
||||
}
|
||||
|
||||
Napi::Value LoadTrustedSetup(const Napi::CallbackInfo& info) {
|
||||
Napi::Value LoadTrustedSetup(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
// Check if the trusted setup is already loaded
|
||||
KzgAddonData *data = env.GetInstanceData<KzgAddonData>();
|
||||
if (data->is_setup) {
|
||||
Napi::Error::New(env, "Error trusted setup is already loaded").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error trusted setup is already loaded")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
|
@ -162,7 +176,8 @@ Napi::Value LoadTrustedSetup(const Napi::CallbackInfo& info) {
|
|||
std::string file_path = info[0].As<Napi::String>().Utf8Value();
|
||||
FILE *file_handle = fopen(file_path.c_str(), "r");
|
||||
if (file_handle == nullptr) {
|
||||
Napi::Error::New(env, "Error opening trusted setup file: " + file_path).ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error opening trusted setup file: " + file_path)
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
|
@ -186,33 +201,36 @@ Napi::Value LoadTrustedSetup(const Napi::CallbackInfo& info) {
|
|||
/**
|
||||
* Convert a blob to a KZG commitment.
|
||||
*
|
||||
* @param[in] {Blob} blob - The blob representing the polynomial to be committed to
|
||||
* @param[in] {Blob} blob - The blob representing the polynomial to be
|
||||
* committed to
|
||||
*
|
||||
* @return {KZGCommitment} - The resulting commitment
|
||||
*
|
||||
* @throws {TypeError} - For invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
|
||||
Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
Blob *blob = get_blob(env, info[0]);
|
||||
if (blob == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
KZGCommitment commitment;
|
||||
C_KZG_RET ret = blob_to_kzg_commitment(&commitment, blob, kzg_settings);
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to convert blob to commitment: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Failed to convert blob to commitment: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
return Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&commitment), BYTES_PER_COMMITMENT);
|
||||
return Napi::Buffer<uint8_t>::Copy(
|
||||
env, reinterpret_cast<uint8_t *>(&commitment), BYTES_PER_COMMITMENT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,45 +244,44 @@ Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
|
|||
*
|
||||
* @throws {TypeError} - for invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value ComputeKzgProof(const Napi::CallbackInfo& info) {
|
||||
Napi::Value ComputeKzgProof(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
Blob *blob = get_blob(env, info[0]);
|
||||
if (blob == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes32 *z_bytes = get_bytes32(env, info[1], "zBytes");
|
||||
if (z_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
KZGProof proof;
|
||||
Bytes32 y_out;
|
||||
C_KZG_RET ret = compute_kzg_proof(
|
||||
&proof,
|
||||
&y_out,
|
||||
blob,
|
||||
z_bytes,
|
||||
kzg_settings
|
||||
&proof, &y_out, blob, z_bytes, kzg_settings
|
||||
);
|
||||
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to compute proof: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Failed to compute proof: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
Napi::Array tuple = Napi::Array::New(env, 2);
|
||||
tuple[(uint32_t)0] = Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&proof), BYTES_PER_PROOF);
|
||||
tuple[(uint32_t)1] = Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&y_out), BYTES_PER_FIELD_ELEMENT);
|
||||
tuple[(uint32_t)0] = Napi::Buffer<uint8_t>::Copy(
|
||||
env, reinterpret_cast<uint8_t *>(&proof), BYTES_PER_PROOF
|
||||
);
|
||||
tuple[(uint32_t)1] = Napi::Buffer<uint8_t>::Copy(
|
||||
env, reinterpret_cast<uint8_t *>(&y_out), BYTES_PER_FIELD_ELEMENT
|
||||
);
|
||||
return tuple;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a blob, return the KZG proof that is used to verify it against the
|
||||
* commitment.
|
||||
|
@ -276,43 +293,43 @@ Napi::Value ComputeKzgProof(const Napi::CallbackInfo& info) {
|
|||
*
|
||||
* @throws {TypeError} - for invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value ComputeBlobKzgProof(const Napi::CallbackInfo& info) {
|
||||
Napi::Value ComputeBlobKzgProof(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
Blob *blob = get_blob(env, info[0]);
|
||||
if (blob == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes48 *commitment_bytes = get_bytes48(env, info[1], "commitmentBytes");
|
||||
if (commitment_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
KZGProof proof;
|
||||
C_KZG_RET ret = compute_blob_kzg_proof(
|
||||
&proof,
|
||||
blob,
|
||||
commitment_bytes,
|
||||
kzg_settings
|
||||
&proof, blob, commitment_bytes, kzg_settings
|
||||
);
|
||||
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Error in computeBlobKzgProof: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Error in computeBlobKzgProof: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
return Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&proof), BYTES_PER_PROOF);
|
||||
return Napi::Buffer<uint8_t>::Copy(
|
||||
env, reinterpret_cast<uint8_t *>(&proof), BYTES_PER_PROOF
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a KZG poof claiming that `p(z) == y`.
|
||||
*
|
||||
* @param[in] {Bytes48} commitmentBytes - The serialized commitment corresponding to polynomial p(x)
|
||||
* @param[in] {Bytes48} commitmentBytes - The serialized commitment
|
||||
* corresponding to polynomial p(x)
|
||||
* @param[in] {Bytes32} zBytes - The serialized evaluation point
|
||||
* @param[in] {Bytes32} yBytes - The serialized claimed evaluation result
|
||||
* @param[in] {Bytes48} proofBytes - The serialized KZG proof
|
||||
|
@ -321,42 +338,37 @@ Napi::Value ComputeBlobKzgProof(const Napi::CallbackInfo& info) {
|
|||
*
|
||||
* @throws {TypeError} - for invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
|
||||
Napi::Value VerifyKzgProof(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
Bytes48 *commitment_bytes = get_bytes48(env, info[0], "commitmentBytes");
|
||||
if (commitment_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes32 *z_bytes = get_bytes32(env, info[1], "zBytes");
|
||||
if (z_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes32 *y_bytes = get_bytes32(env, info[2], "yBytes");
|
||||
if (y_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes48 *proof_bytes = get_bytes48(env, info[3], "proofBytes");
|
||||
if (proof_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
bool out;
|
||||
C_KZG_RET ret = verify_kzg_proof(
|
||||
&out,
|
||||
commitment_bytes,
|
||||
z_bytes,
|
||||
y_bytes,
|
||||
proof_bytes,
|
||||
kzg_settings
|
||||
&out, commitment_bytes, z_bytes, y_bytes, proof_bytes, kzg_settings
|
||||
);
|
||||
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Failed to verify KZG proof: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Failed to verify KZG proof: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
@ -376,36 +388,33 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
|
|||
*
|
||||
* @throws {TypeError} - for invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value VerifyBlobKzgProof(const Napi::CallbackInfo& info) {
|
||||
Napi::Value VerifyBlobKzgProof(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
Blob *blob_bytes = get_blob(env, info[0]);
|
||||
if (blob_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes48 *commitment_bytes = get_bytes48(env, info[1], "commitmentBytes");
|
||||
if (commitment_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
Bytes48 *proof_bytes = get_bytes48(env, info[2], "proofBytes");
|
||||
if (proof_bytes == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
bool out;
|
||||
C_KZG_RET ret = verify_blob_kzg_proof(
|
||||
&out,
|
||||
blob_bytes,
|
||||
commitment_bytes,
|
||||
proof_bytes,
|
||||
kzg_settings);
|
||||
&out, blob_bytes, commitment_bytes, proof_bytes, kzg_settings
|
||||
);
|
||||
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Error in verifyBlobKzgProof: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Error in verifyBlobKzgProof: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
|
@ -414,20 +423,22 @@ Napi::Value VerifyBlobKzgProof(const Napi::CallbackInfo& info) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Given an array of blobs and their proofs, verify that they corresponds to their
|
||||
* provided commitment.
|
||||
* Given an array of blobs and their proofs, verify that they corresponds to
|
||||
* their provided commitment.
|
||||
*
|
||||
* @remark blobs[0] relates to commitmentBytes[0] and proofBytes[0]
|
||||
*
|
||||
* @param[in] {Blob} blobs - An array of serialized blobs to verify
|
||||
* @param[in] {Bytes48} commitmentBytes - An array of serialized commitments to verify
|
||||
* @param[in] {Bytes48} proofBytes - An array of serialized KZG proofs for verification
|
||||
* @param[in] {Bytes48} commitmentBytes - An array of serialized commitments to
|
||||
* verify
|
||||
* @param[in] {Bytes48} proofBytes - An array of serialized KZG proofs for
|
||||
* verification
|
||||
*
|
||||
* @return {boolean} - true/false depending on batch validity
|
||||
*
|
||||
* @throws {TypeError} - for invalid arguments or failure of the native library
|
||||
*/
|
||||
Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo& info) {
|
||||
Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
C_KZG_RET ret;
|
||||
Blob *blobs = NULL;
|
||||
|
@ -435,7 +446,10 @@ Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo& info) {
|
|||
Bytes48 *proofs = NULL;
|
||||
Napi::Value result = env.Null();
|
||||
if (!(info[0].IsArray() && info[1].IsArray() && info[2].IsArray())) {
|
||||
Napi::Error::New(env, "Blobs, commitments, and proofs must all be arrays").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(
|
||||
env, "Blobs, commitments, and proofs must all be arrays"
|
||||
)
|
||||
.ThrowAsJavaScriptException();
|
||||
return result;
|
||||
}
|
||||
Napi::Array blobs_param = info[0].As<Napi::Array>();
|
||||
|
@ -443,26 +457,32 @@ Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo& info) {
|
|||
Napi::Array proofs_param = info[2].As<Napi::Array>();
|
||||
KZGSettings *kzg_settings = get_kzg_settings(env, info);
|
||||
if (kzg_settings == nullptr) {
|
||||
return env.Undefined();
|
||||
return env.Null();
|
||||
}
|
||||
uint32_t count = blobs_param.Length();
|
||||
if (count != commitments_param.Length() || count != proofs_param.Length()) {
|
||||
Napi::Error::New(env, "Requires equal number of blobs/commitments/proofs").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(
|
||||
env, "Requires equal number of blobs/commitments/proofs"
|
||||
)
|
||||
.ThrowAsJavaScriptException();
|
||||
return result;
|
||||
}
|
||||
blobs = (Blob *)calloc(count, sizeof(Blob));
|
||||
if (blobs == nullptr) {
|
||||
Napi::Error::New(env, "Error while allocating memory for blobs").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error while allocating memory for blobs")
|
||||
.ThrowAsJavaScriptException();
|
||||
goto out;
|
||||
}
|
||||
commitments = (Bytes48 *)calloc(count, sizeof(Bytes48));
|
||||
if (commitments == nullptr) {
|
||||
Napi::Error::New(env, "Error while allocating memory for commitments").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error while allocating memory for commitments")
|
||||
.ThrowAsJavaScriptException();
|
||||
goto out;
|
||||
}
|
||||
proofs = (Bytes48 *)calloc(count, sizeof(Bytes48));
|
||||
if (proofs == nullptr) {
|
||||
Napi::Error::New(env, "Error while allocating memory for proofs").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error while allocating memory for proofs")
|
||||
.ThrowAsJavaScriptException();
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -475,7 +495,9 @@ Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo& info) {
|
|||
goto out;
|
||||
}
|
||||
memcpy(&blobs[index], blob, BYTES_PER_BLOB);
|
||||
Bytes48 *commitment = get_bytes48(env, commitments_param[index], "commitmentBytes");
|
||||
Bytes48 *commitment = get_bytes48(
|
||||
env, commitments_param[index], "commitmentBytes"
|
||||
);
|
||||
if (commitment == nullptr) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -489,17 +511,12 @@ Napi::Value VerifyBlobKzgProofBatch(const Napi::CallbackInfo& info) {
|
|||
|
||||
bool out;
|
||||
ret = verify_blob_kzg_proof_batch(
|
||||
&out,
|
||||
blobs,
|
||||
commitments,
|
||||
proofs,
|
||||
count,
|
||||
kzg_settings
|
||||
&out, blobs, commitments, proofs, count, kzg_settings
|
||||
);
|
||||
|
||||
if (ret != C_KZG_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Error in verifyBlobKzgProofBatch: " << from_c_kzg_ret(ret) ;
|
||||
msg << "Error in verifyBlobKzgProofBatch: " << from_c_kzg_ret(ret);
|
||||
Napi::Error::New(env, msg.str()).ThrowAsJavaScriptException();
|
||||
goto out;
|
||||
}
|
||||
|
@ -513,35 +530,58 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
KzgAddonData* data = (KzgAddonData*)malloc(sizeof(KzgAddonData));
|
||||
KzgAddonData *data = (KzgAddonData *)malloc(sizeof(KzgAddonData));
|
||||
if (data == nullptr) {
|
||||
Napi::Error::New(env, "Error allocating memory for kzg setup handle").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error allocating memory for kzg setup handle")
|
||||
.ThrowAsJavaScriptException();
|
||||
return exports;
|
||||
}
|
||||
data->is_setup = false;
|
||||
napi_status status = napi_set_instance_data(env, data, delete_kzg_addon_data, NULL);
|
||||
napi_status status = napi_set_instance_data(
|
||||
env, data, delete_kzg_addon_data, NULL
|
||||
);
|
||||
if (status != napi_ok) {
|
||||
Napi::Error::New(env, "Error setting kzg bindings instance data").ThrowAsJavaScriptException();
|
||||
Napi::Error::New(env, "Error setting kzg bindings instance data")
|
||||
.ThrowAsJavaScriptException();
|
||||
return exports;
|
||||
}
|
||||
|
||||
// Functions
|
||||
exports["loadTrustedSetup"] = Napi::Function::New(env, LoadTrustedSetup, "setup");
|
||||
exports["blobToKzgCommitment"] = Napi::Function::New(env, BlobToKzgCommitment, "blobToKzgCommitment");
|
||||
exports["computeKzgProof"] = Napi::Function::New(env, ComputeKzgProof, "computeKzgProof");
|
||||
exports["computeBlobKzgProof"] = Napi::Function::New(env, ComputeBlobKzgProof, "computeBlobKzgProof");
|
||||
exports["verifyKzgProof"] = Napi::Function::New(env, VerifyKzgProof, "verifyKzgProof");
|
||||
exports["verifyBlobKzgProof"] = Napi::Function::New(env, VerifyBlobKzgProof, "verifyBlobKzgProof");
|
||||
exports["verifyBlobKzgProofBatch"] = Napi::Function::New(env, VerifyBlobKzgProofBatch, "verifyBlobKzgProofBatch");
|
||||
exports["loadTrustedSetup"] = Napi::Function::New(
|
||||
env, LoadTrustedSetup, "setup"
|
||||
);
|
||||
exports["blobToKzgCommitment"] = Napi::Function::New(
|
||||
env, BlobToKzgCommitment, "blobToKzgCommitment"
|
||||
);
|
||||
exports["computeKzgProof"] = Napi::Function::New(
|
||||
env, ComputeKzgProof, "computeKzgProof"
|
||||
);
|
||||
exports["computeBlobKzgProof"] = Napi::Function::New(
|
||||
env, ComputeBlobKzgProof, "computeBlobKzgProof"
|
||||
);
|
||||
exports["verifyKzgProof"] = Napi::Function::New(
|
||||
env, VerifyKzgProof, "verifyKzgProof"
|
||||
);
|
||||
exports["verifyBlobKzgProof"] = Napi::Function::New(
|
||||
env, VerifyBlobKzgProof, "verifyBlobKzgProof"
|
||||
);
|
||||
exports["verifyBlobKzgProofBatch"] = Napi::Function::New(
|
||||
env, VerifyBlobKzgProofBatch, "verifyBlobKzgProofBatch"
|
||||
);
|
||||
|
||||
// Constants
|
||||
exports["BYTES_PER_BLOB"] = Napi::Number::New(env, BYTES_PER_BLOB);
|
||||
exports["BYTES_PER_COMMITMENT"] = Napi::Number::New(env, BYTES_PER_COMMITMENT);
|
||||
exports["BYTES_PER_FIELD_ELEMENT"] = Napi::Number::New(env, BYTES_PER_FIELD_ELEMENT);
|
||||
exports["BYTES_PER_COMMITMENT"] = Napi::Number::New(
|
||||
env, BYTES_PER_COMMITMENT
|
||||
);
|
||||
exports["BYTES_PER_FIELD_ELEMENT"] = Napi::Number::New(
|
||||
env, BYTES_PER_FIELD_ELEMENT
|
||||
);
|
||||
exports["BYTES_PER_PROOF"] = Napi::Number::New(env, BYTES_PER_PROOF);
|
||||
exports["FIELD_ELEMENTS_PER_BLOB"] = Napi::Number::New(env, FIELD_ELEMENTS_PER_BLOB);
|
||||
exports["FIELD_ELEMENTS_PER_BLOB"] = Napi::Number::New(
|
||||
env, FIELD_ELEMENTS_PER_BLOB
|
||||
);
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue