-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeJS bindings #1
Conversation
exports["FIELD_ELEMENTS_PER_BLOB"] = Napi::Number::New(env, FIELD_ELEMENTS_PER_BLOB); | ||
exports["BYTES_PER_FIELD"] = Napi::Number::New(env, BYTES_PER_FIELD); | ||
|
||
return exports; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the interface of the JavaScript module which can be imported by a NodeJS program. node-gyp
turns this into kzg.node
.
Napi::ArrayBuffer buffer = Napi::ArrayBuffer::New( | ||
env, | ||
vector->data(), | ||
length /* size in bytes */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might not matter, but should this be set to the vector capacity rather than length? I dunno of any stdlib that uses a different capacity at construction tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean and I think it should be the byte length supplied to the function, not the allocation for the vector, even in the case where they differ
bindings/node.js/kzg.cxx
Outdated
auto polynomial = (Polynomial*)calloc(blobs_count, sizeof(Polynomial)); | ||
auto commitments = (KZGCommitment*)calloc(blobs_count, sizeof(KZGCommitment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well wrap these in a vector to avoid manually (and possibly forgetting to) freeing the allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried for an hour and I don't think it's possible to make a std::vector<Blob>
. https://stackoverflow.com/questions/16970624/cant-make-a-vector-of-fixed-size-arrays
Do you know how to do it? I think I want to just manage the memory manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is
error: object expression of non-scalar type 'unsigned char[131072]' cannot be used in a pseudo-destructor expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I can do it that way instead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't really understand how to use those structs. Do you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a version of this on a new branch, struct_blob
, ptal.
Moving to dankrad#3 |
This PR adds NodeJS bindings with the following interface:
I also added blst as a submodule.
Most of diff is a yarn lockfile.
Test instructions: README