Skip to content
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 #3

Merged
merged 46 commits into from
Nov 4, 2022
Merged

NodeJS bindings #3

merged 46 commits into from
Nov 4, 2022

Conversation

dgcoffman
Copy link

This PR adds NodeJS bindings with the following interface:

  loadTrustedSetup: (filePath: string) => SetupHandle;

  freeTrustedSetup: (setupHandle: SetupHandle) => void;

  blobToKzgCommitment: (blob: Blob, setupHandle: SetupHandle) => KZGCommitment;

  computeAggregateKzgProof: (
    blobs: Blob[],
    setupHandle: SetupHandle
  ) => KZGProof;

  verifyAggregateKzgProof: (
    blobs: Blob[],
    expectedKzgCommitments: KZGCommitment[],
    kzgAggregatedProof: KZGProof,
    setupHandle: SetupHandle
  ) => boolean;

  // Not used in 4844(?), not exported and not covered with test automation. But I think it probably works.
  verifyKzgProof: (
    polynomialKzg: KZGCommitment,
    z: BLSFieldElement,
    y: BLSFieldElement,
    kzgProof: KZGProof,
    setupHandle: SetupHandle
  ) => boolean;

I also added blst as a submodule.

Most of diff is a yarn lockfile.

Test instructions: README

@dgcoffman dgcoffman marked this pull request as ready for review November 4, 2022 20:37
for (uint32_t blob_index = 0; blob_index < blobs_count; blob_index++) {
Napi::Value blob = blobs_param[blob_index];
auto blob_bytes = blob.As<Napi::Uint8Array>().Data();
memcpy(blobs[blob_index], blob_bytes, BYTES_PER_BLOB);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this copying is unfortunate - does passing blobs_param more directly not work? (like in the python version). not a big deal if you have to copy though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I have tried a bunch of things but can't figure out anything other than memcpy.

blobs_param is of type Napi::Array. I've been googling and trying things. Nothing so far is working.

bindings/node.js/kzg.cxx Outdated Show resolved Hide resolved
bindings/node.js/kzg.cxx Outdated Show resolved Hide resolved
Copy link
Collaborator

@xrchz xrchz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the bindings actually build and work (I haven't tested) this looks great to me.

@xrchz xrchz merged commit 7e77900 into dankrad:4844_3038 Nov 4, 2022
@dgcoffman dgcoffman mentioned this pull request Nov 7, 2022
25 tasks
@dapplion dapplion mentioned this pull request Jan 4, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants