Skip to content

Commit c1992c1

Browse files
committed
Squashed 'src/dashbls/' changes from 22b066020c..9329803969
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
1 parent 8bf0c81 commit c1992c1

File tree

21 files changed

+4650
-444
lines changed

21 files changed

+4650
-444
lines changed

.github/workflows/build-binds.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ jobs:
2424
matrix:
2525
os: [macos-latest, ubuntu-latest]
2626
golang: [ '1.17' ]
27-
python: ['3.7', '3.8', '3.9', '3.10']
27+
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
2828

2929
steps:
3030
- name: Checkout code
3131
uses: actions/checkout@v3
3232

33-
- uses: actions/setup-python@v2
34-
name: Install Python
33+
- uses: chia-network/actions/setup-python@main
3534
with:
3635
python-version: ${{ matrix.python }}
3736

@@ -60,9 +59,7 @@ jobs:
6059
if: startsWith(matrix.os, 'ubuntu')
6160
run: |
6261
sudo apt-get update
63-
sudo apt-get install -qq --yes snap libgmp-dev
64-
sudo apt-get remove --purge cmake -y
65-
sudo snap install cmake --classic
62+
sudo apt-get install -qq --yes valgrind libgmp-dev cmake
6663
hash -r
6764
cmake --version
6865

.github/workflows/build-test.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ jobs:
3838
if: startsWith(matrix.os, 'ubuntu')
3939
run: |
4040
sudo apt-get update
41-
sudo apt-get install -qq --yes valgrind snap libgmp-dev libsodium-dev
42-
sudo apt-get remove --purge cmake -y
43-
sudo snap install cmake --classic
41+
sudo apt-get install -qq --yes valgrind libgmp-dev cmake
4442
hash -r
4543
cmake --version
4644
@@ -49,7 +47,7 @@ jobs:
4947
run: |
5048
ls -l
5149
export MACOSX_DEPLOYMENT_TARGET=10.14
52-
brew install autoconf automake gmp
50+
brew install autoconf automake gmp pkg-config
5351
5452
- name: Build library using CMake
5553
if: startsWith(matrix.builder, 'cmake')

.github/workflows/build-wheels.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,34 @@ jobs:
4343
python:
4444
- major-dot-minor: '3.7'
4545
cibw-build: 'cp37-*'
46+
manylinux:
47+
arch: manylinux2014
48+
intel: manylinux2010
4649
matrix: '3.7'
4750
- major-dot-minor: '3.8'
4851
cibw-build: 'cp38-*'
52+
manylinux:
53+
arch: manylinux2014
54+
intel: manylinux2010
4955
matrix: '3.8'
5056
- major-dot-minor: '3.9'
5157
cibw-build: 'cp39-*'
58+
manylinux:
59+
arch: manylinux2014
60+
intel: manylinux2010
5261
matrix: '3.9'
5362
- major-dot-minor: '3.10'
5463
cibw-build: 'cp310-*'
64+
manylinux:
65+
arch: manylinux2014
66+
intel: manylinux2010
5567
matrix: '3.10'
68+
- major-dot-minor: '3.11'
69+
cibw-build: 'cp311-*'
70+
manylinux:
71+
arch: manylinux2014
72+
intel: manylinux2014
73+
matrix: '3.11'
5674
arch:
5775
- name: ARM
5876
matrix: arm
@@ -114,25 +132,24 @@ jobs:
114132
- name: Install pipx
115133
run: |
116134
pip install pipx
135+
117136
- name: Build and test
118-
uses: pypa/[email protected]
119-
with:
120-
output-dir: dist
121137
env:
138+
CIBW_PRERELEASE_PYTHONS: True
122139
CIBW_BUILD_VERBOSITY_MACOS: 0
123140
CIBW_BUILD_VERBOSITY_LINUX: 0
124141
CIBW_BUILD_VERBOSITY_WINDOWS: 0
125142
CIBW_BUILD: ${{ matrix.python.cibw-build }}
126143
CIBW_SKIP: '*-manylinux_i686 *-win32 *-musllinux_*'
127-
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
128-
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010
129-
CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.17.3-Linux-`uname -m`/bin:$PATH"
144+
CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.python.manylinux['arm'] }}
145+
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.python.manylinux['intel'] }}
146+
CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.14.3-Linux-`uname -m`/bin:$PATH"
130147
CIBW_BEFORE_ALL_LINUX: >
131148
yum -y install epel-release
132149
&& echo "epel-release installed"
133150
&& yum -y install lzip
134151
&& echo "lzip installed"
135-
&& curl -L https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-`uname -m`.sh > cmake.sh
152+
&& curl -L https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3-Linux-`uname -m`.sh > cmake.sh
136153
&& yes | sh cmake.sh | cat
137154
&& rm -f /usr/bin/cmake
138155
&& curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | tar x --lzip
@@ -176,6 +193,8 @@ jobs:
176193
&& cp {wheel} {dest_dir}
177194
CIBW_TEST_REQUIRES: pytest
178195
CIBW_TEST_COMMAND: py.test -v {project}/python-bindings/test.py
196+
run:
197+
pipx run --spec='cibuildwheel==2.9.0' cibuildwheel --output-dir dist 2>&1
179198

180199
- name: Upload artifacts
181200
uses: actions/upload-artifact@v3

depends/catch2/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ project(
88
LANGUAGES CXX
99
)
1010

11-
1211
set(
1312
${PROJECT_NAME}_HEADERS
1413
catch2/catch.hpp
@@ -22,6 +21,11 @@ list(
2221
add_library(
2322
${PROJECT_NAME}
2423
INTERFACE
24+
)
25+
26+
target_sources(
27+
${PROJECT_NAME}
28+
INTERFACE
2529
"${${PROJECT_NAME}_HEADERS}"
2630
)
2731

include/dashbls/bls.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class BLS {
4141

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

44-
static void CheckRelicErrors();
44+
static void CheckRelicErrors(bool should_throw = true);
4545
};
4646
} // end namespace bls
4747

js-bindings/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ include_directories(
1313
file(GLOB_RECURSE WRAP_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/*.h)
1414
file(GLOB_RECURSE WRAP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/*.cpp)
1515

16-
add_executable(blsjs ${CMAKE_CURRENT_SOURCE_DIR}/jsbindings.cpp
16+
add_executable(blsjstmp ${CMAKE_CURRENT_SOURCE_DIR}/jsbindings.cpp
1717
${WRAP_HEADERS} ${WRAP_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/helpers.h ${CMAKE_CURRENT_SOURCE_DIR}/helpers.cpp
1818
)
1919
add_custom_target(install_npm_dependencies npm ci)
20-
add_dependencies(blsjs install_npm_dependencies)
21-
target_link_libraries(blsjs PRIVATE dashbls)
20+
add_dependencies(blsjstmp install_npm_dependencies)
21+
target_link_libraries(blsjstmp PRIVATE dashbls)
2222

2323
# Copy necessary files for the npm package
2424
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package.json package.json COPYONLY)
2525
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json package-lock.json COPYONLY)
2626
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/blsjs.d.ts blsjs.d.ts COPYONLY)
2727
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.md README.md COPYONLY)
28+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bundle_wasm_for_web.js bundle_wasm_for_web.js COPYONLY)
2829

2930
# Copy test files
30-
file(GLOB JS_BINDINGS_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.js ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.ts)
31+
file(GLOB JS_BINDINGS_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/tests/*)
3132
foreach(file ${JS_BINDINGS_TESTS})
3233
message(FILE ${file})
3334
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/${file} tests/${file} COPYONLY)
3435
endforeach()
3536

36-
set_target_properties(blsjs PROPERTIES LINK_FLAGS "--bind -Oz --closure 1 -s MODULARIZE=1")
37+
set_target_properties(blsjstmp PROPERTIES LINK_FLAGS "--bind -Oz --closure 1 -s MODULARIZE=1 -s NODEJS_CATCH_EXIT=1 -s NODEJS_CATCH_REJECTION=1")
38+
add_custom_command(TARGET blsjstmp POST_BUILD COMMAND npm run build:web)

js-bindings/blsjs.d.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
11
export declare class AugSchemeMPL {
2-
static sk_to_g1(sk: PrivateKey): G1Element;
3-
static key_gen(msg: Uint8Array): PrivateKey;
2+
static skToG1(sk: PrivateKey): G1Element;
3+
static keyGen(msg: Uint8Array): PrivateKey;
44
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
5-
static sign_prepend(sk: PrivateKey, msg: Uint8Array, prependPk: G1Element): G2Element;
5+
static signPrepend(sk: PrivateKey, msg: Uint8Array, prependPk: G1Element): G2Element;
66
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
77
static aggregate(g2Elements: G2Element[]): G2Element;
8-
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
9-
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
10-
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
11-
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
8+
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
9+
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
10+
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
11+
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
1212
}
1313

1414
export declare class BasicSchemeMPL {
15-
static sk_to_g1(sk: PrivateKey): G1Element;
16-
static key_gen(msg: Uint8Array): PrivateKey;
15+
static skToG1(sk: PrivateKey): G1Element;
16+
static keyGen(msg: Uint8Array): PrivateKey;
1717
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
1818
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
1919
static aggregate(g2Elements: G2Element[]): G2Element;
20-
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
21-
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
22-
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
23-
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
20+
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
21+
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
22+
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
23+
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
2424
}
2525

2626
export declare class PopSchemeMPL {
27-
static sk_to_g1(sk: PrivateKey): G1Element;
28-
static key_gen(msg: Uint8Array): PrivateKey;
27+
static skToG1(sk: PrivateKey): G1Element;
28+
static keyGen(msg: Uint8Array): PrivateKey;
2929
static sign(sk: PrivateKey, msg: Uint8Array): G2Element;
3030
static verify(pk: G1Element, msg: Uint8Array, sig: G2Element): boolean;
3131
static aggregate(g2Elements: G2Element[]): G2Element;
32-
static aggregate_verify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
33-
static derive_child_sk(sk: PrivateKey, index: number): PrivateKey;
34-
static derive_child_sk_unhardened(sk: PrivateKey, index: number): PrivateKey;
35-
static derive_child_pk_unhardened(pk: G1Element, index: number): G1Element;
36-
static pop_prove(sk: PrivateKey): G2Element;
37-
static pop_verify(pk: G1Element, signatureProof: G2Element): boolean;
38-
static fast_aggregate_verify(pks: G1Element[], msg: Uint8Array, sig: G2Element): boolean;
32+
static aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element): boolean;
33+
static deriveChildSk(sk: PrivateKey, index: number): PrivateKey;
34+
static deriveChildSkUnhardened(sk: PrivateKey, index: number): PrivateKey;
35+
static deriveChildPkUnhardened(pk: G1Element, index: number): G1Element;
36+
static popProve(sk: PrivateKey): G2Element;
37+
static popVerify(pk: G1Element, signatureProof: G2Element): boolean;
38+
static fastAggregateVerify(pks: G1Element[], msg: Uint8Array, sig: G2Element): boolean;
3939
}
4040

4141
export declare class G1Element {
4242
static SIZE: number;
43-
static from_bytes(bytes: Uint8Array): G1Element;
43+
static fromBytes(bytes: Uint8Array): G1Element;
4444
static generator(): G2Element;
4545
serialize(): Uint8Array;
4646
negate(): G1Element;
4747
deepcopy(): G1Element;
48-
get_fingerprint(): number;
48+
getFingerprint(): number;
4949
add(el: G1Element): G1Element;
5050
mul(bn: Bignum): G1Element;
51-
equal_to(el: G1Element): boolean;
51+
equalTo(el: G1Element): boolean;
5252
delete(): void;
5353
}
5454

5555
export declare class G2Element {
5656
static SIZE: number;
57-
static from_bytes(bytes: Uint8Array): G2Element;
58-
static from_g2(sk: G2Element): G2Element;
59-
static aggregate_sigs(sigs: G2Element[]): G2Element;
57+
static fromBytes(bytes: Uint8Array): G2Element;
58+
static fromG2(sk: G2Element): G2Element;
59+
static aggregateSigs(sigs: G2Element[]): G2Element;
6060
static generator(): G2Element;
6161
serialize(): Uint8Array;
6262
negate(): G2Element;
6363
deepcopy(): G2Element;
6464
add(el: G2Element): G2Element;
6565
mul(bn: Bignum): G2Element;
66-
equal_to(el: G2Element): boolean;
66+
equalTo(el: G2Element): boolean;
6767
delete(): void;
6868
}
6969

7070
export declare class PrivateKey {
7171
static PRIVATE_KEY_SIZE: number;
72-
static from_bytes(bytes: Uint8Array, modOrder: boolean): PrivateKey;
72+
static fromBytes(bytes: Uint8Array, modOrder: boolean): PrivateKey;
7373
static aggregate(pks: PrivateKey[]): PrivateKey;
7474
deepcopy(): PrivateKey;
7575
serialize(): Uint8Array;
76-
get_g1(): G1Element;
77-
get_g2(): G2Element;
78-
mul_g1(el: G1Element): G1Element;
79-
mul_g2(el: G2Element): G2Element;
80-
equal_to(key: PrivateKey): boolean;
76+
getG1(): G1Element;
77+
getG2(): G2Element;
78+
mulG1(el: G1Element): G1Element;
79+
mulG2(el: G2Element): G2Element;
80+
equalTo(key: PrivateKey): boolean;
8181
delete(): void;
8282
}
8383

8484
export declare class Bignum {
85-
static from_string(s: string, radix: number): Bignum;
85+
static fromString(s: string, radix: number): Bignum;
8686
toString(radix: number): string;
8787
delete(): void;
8888
}
8989

9090
export declare class Util {
9191
static hash256(msg: Uint8Array): Uint8Array;
92-
static hex_str(msg: Uint8Array): string;
92+
static hexStr(msg: Uint8Array): string;
9393
}
9494

9595
export interface ModuleInstance {

js-bindings/bundle_wasm_for_web.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// The code manipulation from this file needs to be done for Chrome, as
2+
// it requires wasm to be loaded asynchronously, and it doesn't
3+
// work when bundling complex projects. With this solution, wasm is
4+
// included right into the bundle itself in a form of base64 string
5+
// and compiled asynchronously, just as Chrome requires
6+
7+
const fs = require('fs');
8+
9+
const outputPath = './blsjs.js';
10+
11+
const wasm = fs.readFileSync('./blsjstmp.wasm');
12+
const wasmBase = wasm.toString('base64');
13+
14+
const codeToPrepend = `
15+
if (typeof window === "object") {
16+
var buf = Buffer.from("${wasmBase}", "base64");
17+
var blob = new Blob([buf], { type: "application/wasm" });
18+
var wasmUrl = URL.createObjectURL(blob);
19+
}
20+
`;
21+
22+
const originalSourceCode = fs.readFileSync('./blsjstmp.js', 'utf-8');
23+
const modifiedSourceCode = originalSourceCode
24+
.replace(/fetch\(.,/g, "fetch(wasmUrl,");
25+
26+
const modifiedSourceBuffer = Buffer.from(modifiedSourceCode, 'utf-8');
27+
28+
const bundleFileDescriptor = fs.openSync(outputPath, 'w+');
29+
30+
const bufferToPrepend = Buffer.from(codeToPrepend);
31+
32+
fs.writeSync(bundleFileDescriptor, bufferToPrepend, 0, bufferToPrepend.length, 0);
33+
fs.writeSync(bundleFileDescriptor, modifiedSourceBuffer, 0, modifiedSourceBuffer.length, bufferToPrepend.length);
34+
35+
fs.close(bundleFileDescriptor, (err) => {
36+
if (err) throw err;
37+
});

0 commit comments

Comments
 (0)