Skip to content

Commit

Permalink
Squashed 'src/dashbls/' changes from 22b066020c..9329803969
Browse files Browse the repository at this point in the history
9329803969 wip: fix FromBytesUnchecked (dashpay#68)
767713de3d feat: js bindings in camel case (dashpay#66)
06df92693a chore(release): bump version (dashpay#64)
73593feefd fix: the JS bundle script and bindings (dashpay#47)
38a8f768c6 Merge pull request dashpay#61 from kittywhiskers/compat_support
d9b375145e ci: ensure that CMakeFiles are compatible with LTS-bundled cmake
5ba1b520cc build: restore CMake 3.14.0 compatibility
d1c1b66e5f backport: merge bls-signatures#332 (Python 3.11)

git-subtree-dir: src/dashbls
git-subtree-split: 9329803969fd325dc0d5c9029ab15669d658ed5d
  • Loading branch information
kwvg committed Mar 16, 2023
1 parent 8bf0c81 commit c1992c1
Show file tree
Hide file tree
Showing 21 changed files with 4,650 additions and 444 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/build-binds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ jobs:
matrix:
os: [macos-latest, ubuntu-latest]
golang: [ '1.17' ]
python: ['3.7', '3.8', '3.9', '3.10']
python: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/setup-python@v2
name: Install Python
- uses: chia-network/actions/setup-python@main
with:
python-version: ${{ matrix.python }}

Expand Down Expand Up @@ -60,9 +59,7 @@ jobs:
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -qq --yes snap libgmp-dev
sudo apt-get remove --purge cmake -y
sudo snap install cmake --classic
sudo apt-get install -qq --yes valgrind libgmp-dev cmake
hash -r
cmake --version
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ jobs:
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -qq --yes valgrind snap libgmp-dev libsodium-dev
sudo apt-get remove --purge cmake -y
sudo snap install cmake --classic
sudo apt-get install -qq --yes valgrind libgmp-dev cmake
hash -r
cmake --version
Expand All @@ -49,7 +47,7 @@ jobs:
run: |
ls -l
export MACOSX_DEPLOYMENT_TARGET=10.14
brew install autoconf automake gmp
brew install autoconf automake gmp pkg-config
- name: Build library using CMake
if: startsWith(matrix.builder, 'cmake')
Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,34 @@ jobs:
python:
- major-dot-minor: '3.7'
cibw-build: 'cp37-*'
manylinux:
arch: manylinux2014
intel: manylinux2010
matrix: '3.7'
- major-dot-minor: '3.8'
cibw-build: 'cp38-*'
manylinux:
arch: manylinux2014
intel: manylinux2010
matrix: '3.8'
- major-dot-minor: '3.9'
cibw-build: 'cp39-*'
manylinux:
arch: manylinux2014
intel: manylinux2010
matrix: '3.9'
- major-dot-minor: '3.10'
cibw-build: 'cp310-*'
manylinux:
arch: manylinux2014
intel: manylinux2010
matrix: '3.10'
- major-dot-minor: '3.11'
cibw-build: 'cp311-*'
manylinux:
arch: manylinux2014
intel: manylinux2014
matrix: '3.11'
arch:
- name: ARM
matrix: arm
Expand Down Expand Up @@ -114,25 +132,24 @@ jobs:
- name: Install pipx
run: |
pip install pipx
- name: Build and test
uses: pypa/cibuildwheel@v2.7.0
with:
output-dir: dist
env:
CIBW_PRERELEASE_PYTHONS: True
CIBW_BUILD_VERBOSITY_MACOS: 0
CIBW_BUILD_VERBOSITY_LINUX: 0
CIBW_BUILD_VERBOSITY_WINDOWS: 0
CIBW_BUILD: ${{ matrix.python.cibw-build }}
CIBW_SKIP: '*-manylinux_i686 *-win32 *-musllinux_*'
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010
CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.17.3-Linux-`uname -m`/bin:$PATH"
CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.python.manylinux['arm'] }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.python.manylinux['intel'] }}
CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.14.3-Linux-`uname -m`/bin:$PATH"
CIBW_BEFORE_ALL_LINUX: >
yum -y install epel-release
&& echo "epel-release installed"
&& yum -y install lzip
&& echo "lzip installed"
&& curl -L https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-`uname -m`.sh > cmake.sh
&& curl -L https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3-Linux-`uname -m`.sh > cmake.sh
&& yes | sh cmake.sh | cat
&& rm -f /usr/bin/cmake
&& curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | tar x --lzip
Expand Down Expand Up @@ -176,6 +193,8 @@ jobs:
&& cp {wheel} {dest_dir}
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: py.test -v {project}/python-bindings/test.py
run:
pipx run --spec='cibuildwheel==2.9.0' cibuildwheel --output-dir dist 2>&1

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
6 changes: 5 additions & 1 deletion depends/catch2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ project(
LANGUAGES CXX
)


set(
${PROJECT_NAME}_HEADERS
catch2/catch.hpp
Expand All @@ -22,6 +21,11 @@ list(
add_library(
${PROJECT_NAME}
INTERFACE
)

target_sources(
${PROJECT_NAME}
INTERFACE
"${${PROJECT_NAME}_HEADERS}"
)

Expand Down
2 changes: 1 addition & 1 deletion include/dashbls/bls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BLS {

static void SetSecureAllocator(Util::SecureAllocCallback allocCb, Util::SecureFreeCallback freeCb);

static void CheckRelicErrors();
static void CheckRelicErrors(bool should_throw = true);
};
} // end namespace bls

Expand Down
12 changes: 7 additions & 5 deletions js-bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@ include_directories(
file(GLOB_RECURSE WRAP_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/*.h)
file(GLOB_RECURSE WRAP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/*.cpp)

add_executable(blsjs ${CMAKE_CURRENT_SOURCE_DIR}/jsbindings.cpp
add_executable(blsjstmp ${CMAKE_CURRENT_SOURCE_DIR}/jsbindings.cpp
${WRAP_HEADERS} ${WRAP_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/helpers.h ${CMAKE_CURRENT_SOURCE_DIR}/helpers.cpp
)
add_custom_target(install_npm_dependencies npm ci)
add_dependencies(blsjs install_npm_dependencies)
target_link_libraries(blsjs PRIVATE dashbls)
add_dependencies(blsjstmp install_npm_dependencies)
target_link_libraries(blsjstmp PRIVATE dashbls)

# Copy necessary files for the npm package
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package.json package.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json package-lock.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/blsjs.d.ts blsjs.d.ts COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.md README.md COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bundle_wasm_for_web.js bundle_wasm_for_web.js COPYONLY)

# Copy test files
file(GLOB JS_BINDINGS_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.js ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.ts)
file(GLOB JS_BINDINGS_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/tests/*)
foreach(file ${JS_BINDINGS_TESTS})
message(FILE ${file})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/${file} tests/${file} COPYONLY)
endforeach()

set_target_properties(blsjs PROPERTIES LINK_FLAGS "--bind -Oz --closure 1 -s MODULARIZE=1")
set_target_properties(blsjstmp PROPERTIES LINK_FLAGS "--bind -Oz --closure 1 -s MODULARIZE=1 -s NODEJS_CATCH_EXIT=1 -s NODEJS_CATCH_REJECTION=1")
add_custom_command(TARGET blsjstmp POST_BUILD COMMAND npm run build:web)
74 changes: 37 additions & 37 deletions js-bindings/blsjs.d.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
export declare class AugSchemeMPL {
static sk_to_g1(sk: PrivateKey): G1Element;
static key_gen(msg: Uint8Array): PrivateKey;
static skToG1(sk: PrivateKey): G1Element;
static keyGen(msg: Uint8Array): PrivateKey;
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
static sign_prepend(sk: PrivateKey, msg: Uint8Array, prependPk: G1Element): G2Element;
static signPrepend(sk: PrivateKey, msg: Uint8Array, prependPk: G1Element): G2Element;
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
static aggregate(g2Elements: G2Element[]): G2Element;
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
}

export declare class BasicSchemeMPL {
static sk_to_g1(sk: PrivateKey): G1Element;
static key_gen(msg: Uint8Array): PrivateKey;
static skToG1(sk: PrivateKey): G1Element;
static keyGen(msg: Uint8Array): PrivateKey;
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
static aggregate(g2Elements: G2Element[]): G2Element;
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
}

export declare class PopSchemeMPL {
static sk_to_g1(sk: PrivateKey): G1Element;
static key_gen(msg: Uint8Array): PrivateKey;
static skToG1(sk: PrivateKey): G1Element;
static keyGen(msg: Uint8Array): PrivateKey;
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
static aggregate(g2Elements: G2Element[]): G2Element;
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
static pop_prove(sk: PrivateKey): G2Element;
static pop_verify(pk: G1Element, signatureProof: G2Element): boolean;
static fast_aggregate_verify(pks: G1Element[], msg: Uint8Array, sig: G2Element): boolean;
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
static popProve(sk: PrivateKey): G2Element;
static popVerify(pk: G1Element, signatureProof: G2Element): boolean;
static fastAggregateVerify(pks: G1Element[], msg: Uint8Array, sig: G2Element): boolean;
}

export declare class G1Element {
static SIZE: number;
static from_bytes(bytes: Uint8Array): G1Element;
static fromBytes(bytes: Uint8Array): G1Element;
static generator(): G2Element;
serialize(): Uint8Array;
negate(): G1Element;
deepcopy(): G1Element;
get_fingerprint(): number;
getFingerprint(): number;
add(el: G1Element): G1Element;
mul(bn: Bignum): G1Element;
equal_to(el: G1Element): boolean;
equalTo(el: G1Element): boolean;
delete(): void;
}

export declare class G2Element {
static SIZE: number;
static from_bytes(bytes: Uint8Array): G2Element;
static from_g2(sk: G2Element): G2Element;
static aggregate_sigs(sigs: G2Element[]): G2Element;
static fromBytes(bytes: Uint8Array): G2Element;
static fromG2(sk: G2Element): G2Element;
static aggregateSigs(sigs: G2Element[]): G2Element;
static generator(): G2Element;
serialize(): Uint8Array;
negate(): G2Element;
deepcopy(): G2Element;
add(el: G2Element): G2Element;
mul(bn: Bignum): G2Element;
equal_to(el: G2Element): boolean;
equalTo(el: G2Element): boolean;
delete(): void;
}

export declare class PrivateKey {
static PRIVATE_KEY_SIZE: number;
static from_bytes(bytes: Uint8Array, modOrder: boolean): PrivateKey;
static fromBytes(bytes: Uint8Array, modOrder: boolean): PrivateKey;
static aggregate(pks: PrivateKey[]): PrivateKey;
deepcopy(): PrivateKey;
serialize(): Uint8Array;
get_g1(): G1Element;
get_g2(): G2Element;
mul_g1(el: G1Element): G1Element;
mul_g2(el: G2Element): G2Element;
equal_to(key: PrivateKey): boolean;
getG1(): G1Element;
getG2(): G2Element;
mulG1(el: G1Element): G1Element;
mulG2(el: G2Element): G2Element;
equalTo(key: PrivateKey): boolean;
delete(): void;
}

export declare class Bignum {
static from_string(s: string, radix: number): Bignum;
static fromString(s: string, radix: number): Bignum;
toString(radix: number): string;
delete(): void;
}

export declare class Util {
static hash256(msg: Uint8Array): Uint8Array;
static hex_str(msg: Uint8Array): string;
static hexStr(msg: Uint8Array): string;
}

export interface ModuleInstance {
Expand Down
37 changes: 37 additions & 0 deletions js-bindings/bundle_wasm_for_web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// The code manipulation from this file needs to be done for Chrome, as
// it requires wasm to be loaded asynchronously, and it doesn't
// work when bundling complex projects. With this solution, wasm is
// included right into the bundle itself in a form of base64 string
// and compiled asynchronously, just as Chrome requires

const fs = require('fs');

const outputPath = './blsjs.js';

const wasm = fs.readFileSync('./blsjstmp.wasm');
const wasmBase = wasm.toString('base64');

const codeToPrepend = `
if (typeof window === "object") {
var buf = Buffer.from("${wasmBase}", "base64");
var blob = new Blob([buf], { type: "application/wasm" });
var wasmUrl = URL.createObjectURL(blob);
}
`;

const originalSourceCode = fs.readFileSync('./blsjstmp.js', 'utf-8');
const modifiedSourceCode = originalSourceCode
.replace(/fetch\(.,/g, "fetch(wasmUrl,");

const modifiedSourceBuffer = Buffer.from(modifiedSourceCode, 'utf-8');

const bundleFileDescriptor = fs.openSync(outputPath, 'w+');

const bufferToPrepend = Buffer.from(codeToPrepend);

fs.writeSync(bundleFileDescriptor, bufferToPrepend, 0, bufferToPrepend.length, 0);
fs.writeSync(bundleFileDescriptor, modifiedSourceBuffer, 0, modifiedSourceBuffer.length, bufferToPrepend.length);

fs.close(bundleFileDescriptor, (err) => {
if (err) throw err;
});
Loading

0 comments on commit c1992c1

Please sign in to comment.