Remove SWIG

This commit is contained in:
dancoffman 2022-11-02 13:27:00 -07:00
parent 40db00f643
commit b169d4ab6e
No known key found for this signature in database
GPG Key ID: 47B1F53E36A9B3CC
10 changed files with 10 additions and 213 deletions

View File

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

View File

@ -1,12 +1,10 @@
clean:
yarn clean
rm -rf build
rm -f ckzg.node
rm -f ckzg_wrap.cxx
rm -f kzg.node
build: ckzg.cxx ckzg.h Makefile
# cd ../../src; make lib
# swig -c++ -javascript -node ckzg.swg
build: kzg.cxx Makefile
cd ../../src; make lib
yarn build
cp build/Release/kzg.node .

View File

@ -16,21 +16,6 @@
"<!(node -p \"require('node-addon-api').gyp\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
},
# {
# 'target_name': 'ckzg-swig',
# "cflags!": [ "-fno-exceptions" ],
# "cflags_cc!": [ "-fno-exceptions" ],
# 'sources': [
# 'ckzg.cxx',
# # SWIG-generated wrapper around ckzg.cxx
# 'ckzg_wrap.cxx',
# ],
# 'include_dirs': ['../../inc', '../../src'],
# 'libraries': [
# '/Users/coffman@coinbase.com/src/c-kzg/bindings/node.js/c_kzg_4844.o',
# '/Users/coffman@coinbase.com/src/c-kzg/lib/libblst.a'
# ],
# }
}
]
}

View File

@ -1,104 +0,0 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "ckzg.h"
int testFunction() {
return test_function();
}
// https://stackoverflow.com/questions/59799509/how-to-return-a-c-class-to-node-js
// https://github.com/nodejs/node-addon-api/blob/main/doc/node-gyp.md
KZGSettings* loadTrustedSetup(const char* file) {
KZGSettings* out = (KZGSettings*)malloc(sizeof(KZGSettings));
if (out == NULL) return NULL;
FILE* f = fopen(file, "r");
if (f == NULL) { free(out); return NULL; }
if (load_trusted_setup(out, f) != C_KZG_OK) { free(out); return NULL; }
return out;
}
void freeTrustedSetup(KZGSettings *s) {
free_trusted_setup(s);
free(s);
}
// void blobToKzgCommitment(uint8_t out[48], const uint8_t blob[FIELD_ELEMENTS_PER_BLOB * 32], const KZGSettings *s) {
// Polynomial p;
// for (size_t i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++)
// bytes_to_bls_field(&p[i], &blob[i * 32]);
// KZGCommitment c;
// blob_to_kzg_commitment(&c, p, s);
// bytes_from_g1(out, &c);
// }
// int verifyAggregateKzgProof(const uint8_t blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s) {
// Polynomial* p = (Polynomial*)calloc(n, sizeof(Polynomial));
// if (p == NULL) return -1;
// KZGCommitment* c = (KZGCommitment*)calloc(n, sizeof(KZGCommitment));
// if (c == NULL) { free(p); return -1; }
// C_KZG_RET ret;
// for (size_t i = 0; i < n; i++) {
// for (size_t j = 0; j < FIELD_ELEMENTS_PER_BLOB; j++)
// bytes_to_bls_field(&p[i][j], &blobs[i * FIELD_ELEMENTS_PER_BLOB * 32 + j * 32]);
// ret = bytes_to_g1(&c[i], &commitments[i * 48]);
// if (ret != C_KZG_OK) { free(c); free(p); return -1; }
// }
// KZGProof f;
// ret = bytes_to_g1(&f, proof);
// if (ret != C_KZG_OK) { free(c); free(p); return -1; }
// bool b;
// ret = verify_aggregate_kzg_proof(&b, p, c, n, &f, s);
// if (ret != C_KZG_OK) { free(c); free(p); return -1; }
// free(c); free(p);
// return b ? 0 : 1;
// }
// C_KZG_RET computeAggregateKzgProof(uint8_t out[48], const uint8_t blobs[], size_t n, const KZGSettings *s) {
// Polynomial* p = (Polynomial*)calloc(n, sizeof(Polynomial));
// if (p == NULL) return C_KZG_ERROR;
// for (size_t i = 0; i < n; i++)
// for (size_t j = 0; j < FIELD_ELEMENTS_PER_BLOB; j++)
// bytes_to_bls_field(&p[i][j], &blobs[i * FIELD_ELEMENTS_PER_BLOB * 32 + j * 32]);
// KZGProof f;
// C_KZG_RET ret = compute_aggregate_kzg_proof(&f, p, n, s);
// free(p);
// if (ret != C_KZG_OK) return ret;
// bytes_from_g1(out, &f);
// return C_KZG_OK;
// }
// int verifyKzgProof(const uint8_t c[48], const uint8_t x[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s) {
// KZGCommitment commitment;
// KZGProof proof;
// BLSFieldElement fx, fy;
// bool out;
// bytes_to_bls_field(&fx, x);
// bytes_to_bls_field(&fy, y);
// if (bytes_to_g1(&commitment, c) != C_KZG_OK) return -1;
// if (bytes_to_g1(&proof, p) != C_KZG_OK) return -1;
// if (verify_kzg_proof(&out, &commitment, &fx, &fy, &proof, s) != C_KZG_OK)
// return -2;
// return out ? 0 : 1;
// }

View File

@ -1,22 +0,0 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
// #include <node.h>
// #include <node_version.h>
// #include <v8.h>
#include "c_kzg_4844.h"
int testFunction();
KZGSettings* loadTrustedSetup(const char* file);
void freeTrustedSetup(KZGSettings *s);
// void blobToKzgCommitment(uint8_t out[48], const uint8_t blob[FIELD_ELEMENTS_PER_BLOB * 32], const KZGSettings *s);
// int verifyKzgProof(const uint8_t c[48], const uint8_t x[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s);
// int verifyAggregateKzgProof(const uint8_t blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s);
// C_KZG_RET computeAggregateKzgProof(uint8_t out[48], const uint8_t blobs[], size_t n, const KZGSettings *s);

View File

@ -1,9 +0,0 @@
/* File : ckzg.swg */
%module ckzg
%include <typemaps.i>
%{
#include "ckzg.h"
%}
%include "ckzg.h"

View File

@ -1,32 +1,12 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define NAPI_EXPERIMENTAL
#include <napi.h>
#include "c_kzg_4844.h"
#include "blst.h"
KZGSettings* loadTrustedSetup(const char* file) {
KZGSettings* out = (KZGSettings*)malloc(sizeof(KZGSettings));
if (out == NULL) return NULL;
FILE* f = fopen(file, "r");
if (f == NULL) { free(out); return NULL; }
if (load_trusted_setup(out, f) != C_KZG_OK) { free(out); return NULL; }
return out;
}
void freeTrustedSetup(KZGSettings *s) {
free_trusted_setup(s);
free(s);
}
void blobToKzgCommitment(uint8_t out[48], const uint8_t blob[FIELD_ELEMENTS_PER_BLOB * 32], const KZGSettings *s) {
Polynomial p;
for (size_t i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++)
@ -137,25 +117,16 @@ Napi::Value LoadTrustedSetup(const Napi::CallbackInfo& info) {
return env.Null();
}
// https://github.com/nodejs/node-addon-api/issues/667
Napi::External<KZGSettings> kzgSettingsPointer = Napi::External<KZGSettings>::New(info.Env(), kzgSettings);
kzgSettingsPointer.As<Napi::Object>().AddFinalizer([](Napi::Env, KZGSettings* kzgSettings) {
printf(" finalize \n"
" test %p "
"*test %x "
"&test %p\n", kzgSettings, *kzgSettings, &kzgSettings);
}, kzgSettings);
return kzgSettingsPointer;
return Napi::External<KZGSettings>::New(info.Env(), kzgSettings);
}
void FreeTrustedSetup(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
KZGSettings* kzgSettings = info[0].As<Napi::External<KZGSettings>>().Data();
printf("Freeing: kzgSettings %p *kzgSettings %s &kzgSettings %p\n", kzgSettings, *kzgSettings, &kzgSettings);
freeTrustedSetup(kzgSettings);
free_trusted_setup(kzgSettings);
free(kzgSettings);
}
Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
}

View File

@ -1,19 +0,0 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "c_kzg_4844.h"
int testFunction();
KZGSettings* loadTrustedSetup(const char* file);
void freeTrustedSetup(KZGSettings *s);
// void blobToKzgCommitment(uint8_t out[48], const uint8_t blob[FIELD_ELEMENTS_PER_BLOB * 32], const KZGSettings *s);
// int verifyKzgProof(const uint8_t c[48], const uint8_t x[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s);
// int verifyAggregateKzgProof(const uint8_t blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s);
// C_KZG_RET computeAggregateKzgProof(uint8_t out[48], const uint8_t blobs[], size_t n, const KZGSettings *s);

Binary file not shown.

View File

@ -29,15 +29,13 @@
#include "blst.h"
// Allow a library built from this code to be used from C++
#ifdef __cplusplus
extern "C" {
#endif
#define FIELD_ELEMENTS_PER_BLOB 4096
typedef blst_p1 g1_t; /**< Internal G1 group element type */
typedef blst_p2 g2_t; /**< Internal G2 group element type */
typedef blst_fr fr_t; /**< Internal Fr field element type */