return undefined if JS error is thrown (#267)

This commit is contained in:
Matthew Keil 2023-03-30 09:54:34 -04:00 committed by GitHub
parent e83ec0374c
commit ed4e795c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 23 deletions

View File

@ -173,11 +173,11 @@ Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Blob *blob = get_blob(env, info[0]);
if (blob == nullptr) {
return env.Null();
return env.Undefined();
}
KZGSettings *kzg_settings = get_kzg_settings(env, info);
if (kzg_settings == nullptr) {
return env.Null();
return env.Undefined();
}
KZGCommitment commitment;
@ -185,7 +185,7 @@ Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
if (ret != C_KZG_OK) {
Napi::Error::New(env, "Failed to convert blob to commitment")
.ThrowAsJavaScriptException();
return env.Null();
return env.Undefined();
}
return Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&commitment), BYTES_PER_COMMITMENT);
@ -206,15 +206,15 @@ Napi::Value ComputeKzgProof(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Blob *blob = get_blob(env, info[0]);
if (blob == nullptr) {
return env.Null();
return env.Undefined();
}
Bytes32 *z_bytes = get_bytes32(env, info[1], "zBytes");
if (z_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
KZGSettings *kzg_settings = get_kzg_settings(env, info);
if (kzg_settings == nullptr) {
return env.Null();
return env.Undefined();
}
KZGProof proof;
@ -230,7 +230,7 @@ Napi::Value ComputeKzgProof(const Napi::CallbackInfo& info) {
if (ret != C_KZG_OK) {
Napi::Error::New(env, "Failed to compute proof")
.ThrowAsJavaScriptException();
return env.Null();
return env.Undefined();
}
Napi::Array tuple = Napi::Array::New(env, 2);
@ -255,15 +255,15 @@ Napi::Value ComputeBlobKzgProof(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Blob *blob = get_blob(env, info[0]);
if (blob == nullptr) {
return env.Null();
return env.Undefined();
}
Bytes48 *commitment_bytes = get_bytes48(env, info[1], "commitmentBytes");
if (commitment_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
KZGSettings *kzg_settings = get_kzg_settings(env, info);
if (kzg_settings == nullptr) {
return env.Null();
return env.Undefined();
}
KZGProof proof;
@ -277,7 +277,7 @@ Napi::Value ComputeBlobKzgProof(const Napi::CallbackInfo& info) {
if (ret != C_KZG_OK) {
Napi::Error::New(env, "Error in computeBlobKzgProof")
.ThrowAsJavaScriptException();
return env.Null();
return env.Undefined();
}
return Napi::Buffer<uint8_t>::Copy(env, reinterpret_cast<uint8_t *>(&proof), BYTES_PER_PROOF);
@ -299,23 +299,23 @@ 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.Null();
return env.Undefined();
}
Bytes32 *z_bytes = get_bytes32(env, info[1], "zBytes");
if (z_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
Bytes32 *y_bytes = get_bytes32(env, info[2], "yBytes");
if (y_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
Bytes48 *proof_bytes = get_bytes48(env, info[3], "proofBytes");
if (proof_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
KZGSettings *kzg_settings = get_kzg_settings(env, info);
if (kzg_settings == nullptr) {
return env.Null();
return env.Undefined();
}
bool out;
@ -330,7 +330,7 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
if (ret != C_KZG_OK) {
Napi::TypeError::New(env, "Failed to verify KZG proof").ThrowAsJavaScriptException();
return env.Null();
return env.Undefined();
}
return Napi::Boolean::New(env, out);
@ -352,19 +352,19 @@ 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.Null();
return env.Undefined();
}
Bytes48 *commitment_bytes = get_bytes48(env, info[1], "commitmentBytes");
if (commitment_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
Bytes48 *proof_bytes = get_bytes48(env, info[2], "proofBytes");
if (proof_bytes == nullptr) {
return env.Null();
return env.Undefined();
}
KZGSettings *kzg_settings = get_kzg_settings(env, info);
if (kzg_settings == nullptr) {
return env.Null();
return env.Undefined();
}
bool out;
@ -377,7 +377,7 @@ Napi::Value VerifyBlobKzgProof(const Napi::CallbackInfo& info) {
if (ret != C_KZG_OK) {
Napi::TypeError::New(env, "Error in verifyBlobKzgProof").ThrowAsJavaScriptException();
return env.Null();
return env.Undefined();
}
return Napi::Boolean::New(env, out);
@ -413,7 +413,7 @@ 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.Null();
return env.Undefined();
}
uint32_t count = blobs_param.Length();
if (count != commitments_param.Length() || count != proofs_param.Length()) {