Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
1aea88b
simplify swig to see changes
matthewkeil Nov 22, 2022
603e54a
found bug in linking. back to stable build
matthewkeil Nov 22, 2022
31d9d0c
feat(addon): SecretKey.keygen()
matthewkeil Nov 22, 2022
bf608f4
feat(addon): SecretKey.fromBytes()
matthewkeil Nov 22, 2022
eb04c65
feat(addon): PrivateKey serializes and deserializes
matthewkeil Nov 22, 2022
c3f7f64
roughed out core Classes. started unit tests
matthewkeil Nov 23, 2022
216df99
feat(addon): secretKey.getPublicKey works. unit tests
matthewkeil Nov 24, 2022
896330f
feat(addon): SecretKey, PublicKey, Signature work with unit tests
matthewkeil Nov 26, 2022
ecc0bbf
refactor(addon): better memory management
matthewkeil Nov 27, 2022
6dd5836
fix(addon): fix ifdef guards
matthewkeil Nov 27, 2022
410fca6
feat(addon): aggregatePublicKeys
matthewkeil Nov 28, 2022
ed338c7
feat(addon): remove suppressDestruct call
matthewkeil Nov 28, 2022
05092f1
feat(addon): ByteArray class
matthewkeil Nov 30, 2022
8ded774
feat(addon): build ByteArray and update core classes.
matthewkeil Dec 5, 2022
937ed4e
test(addon): verification against swig bindings
matthewkeil Dec 5, 2022
6001298
refactor(addon): move swig bindings to src/swig
matthewkeil Dec 5, 2022
61e4b69
fix(addon): found ByteArray bug
matthewkeil Dec 5, 2022
c6635e7
fix(addon): isolate segfault and made move constructor for ByteArray
matthewkeil Dec 5, 2022
12d09a2
feat(addon): add exec, watch and dev scripts
matthewkeil Dec 6, 2022
e70e1a1
feat(addon): update bindings.gyp for linux
matthewkeil Dec 6, 2022
02c36f2
feat(addon): update bindings.gyp
matthewkeil Dec 7, 2022
c58a627
chore: yarn install chokidar
matthewkeil Dec 7, 2022
b77a220
refactor: remove setting.json
matthewkeil Dec 7, 2022
5ec9e24
refactor(scripts): update dev and exec
matthewkeil Dec 7, 2022
ec75e2e
fix(addon): bug in ByteArray move constructor
matthewkeil Dec 8, 2022
14b8cf2
test(addon): finish aggPubKeys with unit tests
matthewkeil Dec 8, 2022
b29d59a
feat(addon): update bindings.gyp
matthewkeil Dec 8, 2022
73c2b44
refactor(addon): change ByteArray::Clear to look at pointer
matthewkeil Dec 8, 2022
262fed6
test(addon): check for try/catch with -fno-exceptions flag
matthewkeil Dec 8, 2022
d7abafc
feat(scripts): watch for test changes
matthewkeil Dec 8, 2022
e72179c
feat(addon): remove point[] and use single temp
matthewkeil Dec 8, 2022
fd6438d
refactor(addon): rebuild ByteArray using vector
matthewkeil Dec 13, 2022
2163b26
feat: turn exceptions back on
matthewkeil Dec 13, 2022
2f2c807
verifyMultipleAggregateSignatures works. need to debug dealloc bug
matthewkeil Dec 13, 2022
717ee02
bug(addon): turn on ByteArray tests
matthewkeil Dec 13, 2022
861d22d
feat(addon): multi-threading works
matthewkeil Dec 14, 2022
33b4e1f
test(addon): add test:bindings:timing
matthewkeil Dec 14, 2022
1c4c454
fix(addon): fixed bug in verifyMultipleAggregateSignatures by adding …
matthewkeil Dec 15, 2022
eefd5ad
add build/test addon to workflow (comment rest out for now)
matthewkeil Dec 15, 2022
247564b
refactor(addon): clean up ThreadPool
matthewkeil Dec 16, 2022
d8f9f22
feat(workflow): remove install script and update workflow
matthewkeil Dec 16, 2022
5112aa6
bug(workflow): turn off tess
matthewkeil Dec 16, 2022
50a680e
feat(workflow): build libsodium in workflow
matthewkeil Dec 16, 2022
c0a5bea
fix(workflow): fix package script for ci
matthewkeil Dec 16, 2022
4cc06e8
debugging workflow
matthewkeil Dec 16, 2022
28e6b54
debugging workflow
matthewkeil Dec 16, 2022
4eaf878
debugging workflow
matthewkeil Dec 16, 2022
f15b4b6
debugging workflow
matthewkeil Dec 16, 2022
ddf1797
debugging workflow
matthewkeil Dec 16, 2022
0b12fba
debugging workflow
matthewkeil Dec 16, 2022
a181769
debugging workflow
matthewkeil Dec 16, 2022
3a64f71
debugging workflow
matthewkeil Dec 16, 2022
e13be76
debugging workflow
matthewkeil Dec 16, 2022
648b7e0
debugging workflow
matthewkeil Dec 16, 2022
38d4ce8
debugging workflow
matthewkeil Dec 16, 2022
82f031e
debugging workflow
matthewkeil Dec 16, 2022
c418800
debugging workflow
matthewkeil Dec 16, 2022
db80e87
debugging workflow
matthewkeil Dec 16, 2022
f30a897
turn swig tests back on
matthewkeil Dec 16, 2022
68a16be
turn libsodium back on
matthewkeil Dec 16, 2022
d2ac5ee
test windows workflow
matthewkeil Dec 16, 2022
99fe3f5
debugging workflow
matthewkeil Dec 16, 2022
af7bc18
workflow(addon): turn off windows
matthewkeil Dec 16, 2022
4f7faad
refactor(functions): make sync/async ver_mul_agg_sigs
matthewkeil Dec 17, 2022
b803a29
feat(addon): substantially complete with aggregate_verify
matthewkeil Dec 17, 2022
a4a1de3
feat(addon): agg_pub_keys sync and Promise apis
matthewkeil Dec 17, 2022
2c461ef
feat(functions): add agg_pub_keys.h
matthewkeil Dec 19, 2022
2f3c19c
test(addon): start perf benchmarks
matthewkeil Dec 19, 2022
3c59123
feat(addon): swap openssl for libsodium
matthewkeil Dec 19, 2022
7f29477
test(bindings): add perf tests for SecretKey, PublicKey, Signature
matthewkeil Dec 19, 2022
687fd73
refactor(bindings): move code that will be deprecated to deprecated/
matthewkeil Jan 28, 2023
9eafae0
refactor: move tests to deprecated and bring back 1 by 1
matthewkeil Jan 28, 2023
3e82563
feat: add .VSCodeCounter to .gitignore
matthewkeil Jan 28, 2023
4d793e8
refactor: cleanup package.json scripts and install bindings to deps
matthewkeil Jan 28, 2023
184f482
refactor: fix typings and module exports
matthewkeil Jan 28, 2023
0bb9c03
refactor: update API and fix imports/usage where broken. comment some…
matthewkeil Jan 28, 2023
743765c
feat: build GlobalState, implement Napi::Addon and rough out SecretKey
matthewkeil Jan 28, 2023
32d6e2b
feat(addon): addon builds for context-aware
matthewkeil Feb 6, 2023
373f108
refactor: reorganize folder structure
matthewkeil Feb 6, 2023
654dd77
feat: SecretKey working
matthewkeil Feb 6, 2023
f3e676f
refactor: move macros to utils
matthewkeil Feb 6, 2023
349d61b
feat: PublicKey turned on but have segfault to find
matthewkeil Feb 6, 2023
91d7a49
fix: found bug in ToPublicKey
matthewkeil Feb 6, 2023
24ae926
refactor: clean up ToPublicKey
matthewkeil Feb 6, 2023
b726a1c
refactor(scripts): moved swig scripts to deprecated and fixed paths i…
matthewkeil Feb 7, 2023
e1fcab3
test: turned back on unit tests
matthewkeil Feb 7, 2023
90bdb34
feat: rough-out signature
matthewkeil Feb 7, 2023
fa8dcc8
feat: add sig and key validate. getting virtual function call to debug
matthewkeil Feb 7, 2023
1ca7e6d
fix: found bug in async methods. substantially complete with SK, PK a…
matthewkeil Feb 8, 2023
549f334
feat(SecretKey): add info prop to keygen
matthewkeil Feb 9, 2023
44f6884
test(Signature): turn on tests
matthewkeil Feb 9, 2023
0ecfe45
feat: add .vscode/setting.json to .gitignore
matthewkeil Feb 9, 2023
103c4e7
test(bindings): CONSTANTS
matthewkeil Feb 9, 2023
b6fbf13
wip: substantially complete. need to turn on/debug though
matthewkeil Feb 17, 2023
0a74041
feat: move away from macros and get wip working on secret_key
matthewkeil Feb 20, 2023
dc89465
feat: remove all macros
matthewkeil Feb 20, 2023
8a33e74
wip: turning on functions
matthewkeil Feb 20, 2023
ef464c8
feat: add debugging launch.json
matthewkeil Feb 20, 2023
ad3666e
fix: found the bug in PublicKeyArg copy constructor. aggregatePublicK…
matthewkeil Feb 20, 2023
34f8399
feat: pass argument validation errors out through workers
matthewkeil Feb 20, 2023
660e15d
feat: finish SignatureArg, SignatureArgArray and aggregateSignatures …
matthewkeil Feb 21, 2023
c9022df
feat: substantially complete. need to finish debugging the aggregatio…
matthewkeil Feb 21, 2023
e8729f0
refactor: remove some cruft after viewing draft pr
matthewkeil Feb 21, 2023
0ea4f26
refactor: remove deprecated folder, will bring back some of the tests…
matthewkeil Feb 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
386 changes: 198 additions & 188 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build
dist
node_modules
prebuild/*.node
.VSCodeCounter
.vscode/settings.json

npm-debug.log
yarn-error.log
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "blst"]
path = blst
path = deps/blst
url = https://github.com/supranational/blst.git
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/matthewkeil/.node-gyp/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.0.1",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug Native Addon",
"cwd": "${workspaceRoot}",
"preLaunchTask": "npm: build:debug",
"program": "node",
"args": ["node_modules/.bin/mocha", "test/unit/**/*.test.ts"]
}
]
}
66 changes: 66 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
'targets': [
{
'target_name': 'blst_ts_addon',
'sources': [
'deps/blst/src/server.c',
'deps/blst/build/assembly.S',
'src/addon.cc',
'src/functions.cc',
'src/public_key.cc',
'src/secret_key.cc',
'src/signature.cc',
],
'dependencies': [ "<!(node -p \"require('node-addon-api').gyp\")" ],
'include_dirs': [
'deps/blst/bindings',
"<!@(node -p \"require('node-addon-api').include_dir\")",
],
'defines': [ 'NAPI_CPP_EXCEPTIONS' ],
'cflags!': [
'-fno-exceptions',
'-fno-builtin-memcpy',
'-Wextern-c-compat',
'-Werror',
'-Wall',
'-Wextra',
'-Wpedantic',
'-Wunused-parameter',
],
'cflags_cc!': [
'-fno-exceptions',
'-Werror',
'-Wall',
'-Wextra',
'-Wpedantic',
'-Wunused-parameter',
],
'conditions': [
[ 'OS=="win"', {
'sources': [ 'blst/build/win64/*-x86_64.asm' ],
'defines': [ '_HAS_EXCEPTIONS=1' ],
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1,
'EnablePREfast': 'true',
},
},
}
],
[ 'OS=="linux"', {
'ldflags': [ '-Wl,-Bsymbolic' ],
}
],
['OS=="mac"', {
'cflags+': ['-fvisibility=hidden'],
'xcode_settings': {
'OTHER_CFLAGS': ['-fvisibility=hidden'],
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '12',
}
}]
],
}
]
}
97 changes: 97 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Points are represented in two ways in BLST:
* - affine coordinates (x,y)
* - jacobian coordinates (x,y,z)
*
* The jacobian coordinates allow to aggregate points more efficiently,
* so if P1 points are aggregated often (Eth2.0) you want to keep the point
* cached in jacobian coordinates.
*/
export enum CoordType {
affine,
jacobian,
}

export type BlstBuffer = Uint8Array | Buffer;
export type PublicKeyArg = BlstBuffer | PublicKey;
export type SignatureArg = BlstBuffer | Signature;
export interface SignatureSet {
msg: BlstBuffer;
publicKey: PublicKeyArg;
signature: SignatureArg;
}
export interface Serializable {
serialize(): Uint8Array;
}

/*
* Private constructor. Randomly generate ikm when new'ing a key if no
* ikm is provided.
*
* Use static methods `SecretKey.deserialize`, `SecretKey.fromKeygen` or
* `SecretKey.fromKeygenSync` to generate `SecretKey`s from your own
* material (ie serialized key or ikm).
*
* example:
* ```typescript
* const ikm = UintArray8.from(Buffer.from("your very own ikm"));
* const keyInfo = "Some key info";
* const key: SecretKey = SecretKey.fromKeygen(ikm, keyInfo);
*
* key = SecretKey.fromBytes(key.serialize());
* ```
*/
export class SecretKey implements Serializable {
private constructor();
static fromKeygen(ikm?: BlstBuffer, info?: string): Promise<SecretKey>;
static fromKeygenSync(ikm?: BlstBuffer, info?: string): SecretKey;
static deserialize(skBytes: BlstBuffer, info?: string): SecretKey;
serialize(): Buffer;
toPublicKey(): PublicKey;
sign(msg: BlstBuffer): Promise<Signature>;
signSync(msg: BlstBuffer): Signature;
}
export class PublicKey implements Serializable {
constructor(sk: BlstBuffer | SecretKey);
static deserialize(skBytes: BlstBuffer, coordType?: CoordType): PublicKey;
serialize(compress?: boolean): Buffer;
keyValidate(): Promise<void>;
keyValidateSync(): void;
}
export class Signature implements Serializable {
private constructor();
static deserialize(skBytes: BlstBuffer, coordType?: CoordType): Signature;
serialize(compress?: boolean): Buffer;
sigValidate(): Promise<void>;
sigValidateSync(): void;
}
// export const functions: {
export function aggregatePublicKeys(keys: PublicKeyArg[]): Promise<PublicKey>;
export function aggregatePublicKeysSync(keys: PublicKeyArg[]): PublicKey;
export function aggregateSignatures(signatures: SignatureArg[]): Promise<Signature>;
export function aggregateSignaturesSync(signatures: SignatureArg[]): Signature;
export function verify(msg: BlstBuffer, publicKey: PublicKeyArg, signature: SignatureArg): Promise<boolean>;
export function verifySync(msg: BlstBuffer, publicKey: PublicKeyArg, signature: SignatureArg): boolean;
export function aggregateVerify(
msgs: BlstBuffer[],
publicKeys: PublicKeyArg[],
signature: SignatureArg
): Promise<boolean>;
export function aggregateVerifySync(msgs: BlstBuffer[], publicKeys: PublicKeyArg[], signature: SignatureArg): boolean;
export function fastAggregateVerify(
msg: BlstBuffer,
publicKeys: PublicKeyArg[],
signature: SignatureArg
): Promise<boolean>;
export function fastAggregateVerifySync(msg: BlstBuffer, publicKeys: PublicKeyArg[], signature: SignatureArg): boolean;
export function verifyMultipleAggregateSignatures(sets: SignatureSet[]): Promise<boolean>;
export function verifyMultipleAggregateSignaturesSync(sets: SignatureSet[]): boolean;
// };
export const BLST_CONSTANTS: {
DST: string;
SECRET_KEY_LENGTH: number;
PUBLIC_KEY_LENGTH_UNCOMPRESSED: number;
PUBLIC_KEY_LENGTH_COMPRESSED: number;
SIGNATURE_LENGTH_UNCOMPRESSED: number;
SIGNATURE_LENGTH_COMPRESSED: number;
};
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-call
module.exports = exports = require("bindings")("blst_ts_addon");
32 changes: 20 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
"name": "@chainsafe/blst",
"version": "0.2.6",
"description": "Typescript wrapper for supranational/blst native bindings, a highly performant BLS12-381 signature library",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"dist",
"prebuild",
"blst"
"deps",
"lib",
"src"
],
"scripts": {
"install": "node dist/scripts/install.js",
"dev": "ts-node tools/dev",
"test": "yarn test:unit && yarn test:spec && yarn test:perf",
"lint": "eslint --color --ext .ts src/ test/",
"build": "tsc --project tsconfig.build.json",
"bootstrap": "yarn install --ignore-scripts && yarn build && yarn install",
"clean": "rm -rf prebuild/*.node dist blst/libblst.a blst/bindings/libblst.a blst/bindings/node.js/blst.node blst/bindings/node.js/blst_wrap.cpp",
"test": "yarn test:unit && yarn test:spec",
"clean": "node-gyp clean && node-gyp configure",
"build": "node-gyp build",
"build:clean": "npm run clean && npm run build",
"build:debug": "node-gyp build --debug",
"test:unit": "mocha test/unit/**/*.test.ts",
"test:spec": "mocha 'test/spec/**/*.test.ts'",
"download-spec-tests": "node -r ts-node/register test/spec/downloadTests.ts"
"test:perf": "benchmark test/perf/**/*.perf.ts",
"download-spec-tests": "ts-node test/spec/downloadTests.ts",
"bootstrap": "yarn install --ignore-scripts && yarn build && yarn install",
"clean:swig": "rm -rf prebuild/*.node dist blst/libblst.a blst/bindings/libblst.a blst/bindings/node.js/blst.node blst/bindings/node.js/blst_wrap.cpp"
},
"repository": {
"type": "git",
Expand All @@ -32,6 +36,7 @@
},
"homepage": "https://github.com/ChainSafe/blst-ts#readme",
"devDependencies": {
"@dapplion/benchmark": "^0.2.2",
"@types/chai": "^4.2.13",
"@types/js-yaml": "^4.0.5",
"@types/mocha": "^8.0.3",
Expand All @@ -40,6 +45,7 @@
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"chai": "^4.2.0",
"chokidar": "^3.5.3",
"eslint": "^7.23.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -52,7 +58,9 @@
"typescript": "^4.0.3"
},
"dependencies": {
"bindings": "^1.5.0",
"node-addon-api": "^4.3.0",
"node-fetch": "^2.6.1",
"node-gyp": "^8.4.0"
"node-gyp": "^9.3.0"
}
}
Loading