npm.io
1.7.0 • Published 2 weeks ago

bls-eth-wasm

Licence
BSD-3-Clause
Version
1.7.0
Deps
0
Size
1.2 MB
Vulns
0
Weekly
0
Stars
31

Build Status

BLS signature for Node.js by WebAssembly

Abstract

This module is built with BLS_ETH=1 for Ethereum 2.0 spec.

News

  • v1.6.0 : security fix: deserialize rejects an oversized input
  • v1.5.0 : build with clang instead of emcc
  • 2024/Sep/30 : About 4% performance improvement
  • 2024/Sep/18 : About 10% performance improvement
  • 2022/Jul/20 : 1.1 times improved
  • 2021/Aug/28 : improve performance of {G1,G2}::isValidOrder()
  • 2020/Nov/04 : break backward compatibility (bls.js is renamed to index.js)
    • use blsSetupFactory to make bls instance on browser (see the top of bls-demo.js)
  • 2020/Oct/01 : add bls.multiVerify to verify all {sigs, pubs, msgs}.
  • 2020/Jul/06 ; setETHmode(bls.ETH_MODE_DRAFT_07) is default mode

How to use

The version v0.4.2 breaks backward compatibility of the entry point.

  • Node.js : const bls = require('bls-eth-wasm')
  • React : const bls = require('bls-eth-wasm/browser')
  • HTML : <script src="https://herumi.github.io/bls-eth-wasm/browser/bls.js"></script>

Init as the followings:

await bls.init(bls.BLS12_381)

then, you can use the following eth2.0 functions.

bls-eth-wasm eth2.0 spec name
SecretKey::sign Sign
PublicKey::verify Verify
Sign::aggregate Aggregate
Sign::fastAggregateVerify FastAggregateVerify
Sign::aggregateVerifyNoCheck AggregateVerify

The size of message must be 32 byte.

Check functions:

  • verifySignatureOrder ; make deserialize check the correctness of the order
  • Sign::isValidOrder ; check the correctness of the order
  • verifyPublicKeyOrder ; make deserialize check the correctness of the order
  • PublicKey::isValidOrder ; check the correctness of the order
  • areAllMsgDifferent ; check that all messages are different each other

see bls

How to build src/bls_c.js

Since v1.5.0, src/bls_c.js is built with clang (wasm32 target), wasm-ld (lld), wasm-opt (binaryen) and python3 instead of Emscripten.

git submodule update --init --recursive
make -C src

Use make -C src LLVM_VER=-21 to select a versioned clang/wasm-ld such as clang-21. src/bls_c.js and browser/bls.js in the repository are regenerated by the GitHub Action build.yml on the dev branch.

Installation

This project uses pnpm for package management.

pnpm install

For Node.js

pnpm test

Browser demo

see bls-demo.

See browser/readme.md to make browser/bls.js.

for React

const bls = require('bls-eth-wasm/browser')

License

modified new BSD License http://opensource.org/licenses/BSD-3-Clause

Author

MITSUNARI Shigeo(herumi@nifty.com)

Sponsors welcome

GitHub Sponsor

Keywords