Generate bindings using SWIG and node-gyp

This commit is contained in:
dancoffman 2022-11-01 15:00:00 -07:00
parent a581964b11
commit 6ec86af547
No known key found for this signature in database
GPG Key ID: 47B1F53E36A9B3CC
7 changed files with 60 additions and 3 deletions

View File

@ -1 +1,3 @@
build build
ckzg.node
ckzg_wrap.cxx

12
bindings/node.js/Makefile Normal file
View File

@ -0,0 +1,12 @@
clean:
rm -rf build
rm -f ckzg.node
rm -f ckzg_wrap.cxx
build: ../../src/c_kzg_4844.c
swig -c++ -javascript -node ckzg.swg
node-gyp rebuild
cp build/Release/ckzg.node .
test:
env NODE_PATH=.: node runnable.js

View File

@ -1,8 +1,9 @@
{ {
'targets': [ 'targets': [
{ {
'target_name': 'c-kzg', 'target_name': 'ckzg',
'sources': [ 'sources': [
'ckzg_wrap.cxx',
'../../src/c_kzg_4844.c', '../../src/c_kzg_4844.c',
], ],
'include_dirs': [ '../../inc' ], 'include_dirs': [ '../../inc' ],

35
bindings/node.js/ckzg.swg Normal file
View File

@ -0,0 +1,35 @@
/* File : ckzg.swg */
%module ckzg
%{
#include "../../src/c_kzg_4844.h"
%}
extern C_KZG_RET load_trusted_setup(KZGSettings *out,
FILE *in);
extern void free_trusted_setup(
KZGSettings *s);
extern C_KZG_RET compute_aggregate_kzg_proof(KZGProof *out,
const Polynomial blobs[],
size_t n,
const KZGSettings *s);
extern C_KZG_RET verify_aggregate_kzg_proof(bool *out,
const Polynomial blobs[],
const KZGCommitment expected_kzg_commitments[],
size_t n,
const KZGProof *kzg_aggregated_proof,
const KZGSettings *s);
extern void blob_to_kzg_commitment(KZGCommitment *out,
const BLSFieldElement blob[FIELD_ELEMENTS_PER_BLOB],
const KZGSettings *s);
extern C_KZG_RET verify_kzg_proof(bool *out,
const KZGCommitment *polynomial_kzg,
const BLSFieldElement *z,
const BLSFieldElement *y,
const KZGProof *kzg_proof,
const KZGSettings *s);

View File

@ -0,0 +1,7 @@
'use strict';
console.log('testing...');
const blst = require('ckzg');
console.log(blst);

View File

@ -904,7 +904,7 @@ static void g1_lincomb(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint6
} }
} }
void blob_to_kzg_commitment(KZGCommitment *out, const Polynomial blob, const KZGSettings *s) { void blob_to_kzg_commitment(KZGCommitment *out, const BLSFieldElement blob[FIELD_ELEMENTS_PER_BLOB], const KZGSettings *s) {
g1_lincomb(out, s->g1_values, blob, FIELD_ELEMENTS_PER_BLOB); g1_lincomb(out, s->g1_values, blob, FIELD_ELEMENTS_PER_BLOB);
} }

View File

@ -108,7 +108,7 @@ C_KZG_RET verify_aggregate_kzg_proof(bool *out,
const KZGSettings *s); const KZGSettings *s);
void blob_to_kzg_commitment(KZGCommitment *out, void blob_to_kzg_commitment(KZGCommitment *out,
const Polynomial blob, const BLSFieldElement blob[FIELD_ELEMENTS_PER_BLOB],
const KZGSettings *s); const KZGSettings *s);
C_KZG_RET verify_kzg_proof(bool *out, C_KZG_RET verify_kzg_proof(bool *out,