BLS12-381 implementation for Ruby.

gem install bls12-381 -v 0.1.0


BLS12::381 for Ruby Build Status Gem Version MIT License

This library is a Ruby BLS12-381 implementation based on the JavaScript implementation noble-bls12-381.

Note: This library has passed the same tests as noble-bls12-381, but has not been audited to prove its safety. Please be careful when using this.


Add this line to your application's Gemfile:

gem 'bls12-381'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install bls12-381


require 'bls'

# Generate private key.
private_key = SecureRandom.random_number(BLS::Curve::P)

# Or you can use hex string.
private_key = '67d53f170b908cabb9eb326c3c337762d59289a8fec79f7bc9254b584b73265c'

# Generate public key from private key.
public_key = BLS.get_public_key(private_key)
# Public key is BLS::PointG1 object.

# sign and verify
message = '64726e3da8'

signature = BLS.sign(message, private_key)
# signature is BLS::PointG2 object. You can get signature with hex format using #to_signature method.

is_correct = BLS.verify(signature, message, public_key)
=> true

# Sign 1 msg with 3 keys
private_keys = [
public_keys = { |p| BLS.get_public_key(p) }

signatures2 = { |p| BLS.sign(message, p) }
agg_public_keys2 = BLS.aggregate_public_keys(public_keys)
agg_signatures2 = BLS.aggregate_signatures(signatures2)
is_correct2 = BLS.verify(agg_signatures2, message, agg_public_keys2)
=> true

# Sign 3 msgs with 3 keys
messages = %w[d2 0d98 05caf3]
signatures3 = { |p, i| BLS.sign(messages[i], p)}
agg_signatures3 = BLS.aggregate_signatures(signatures3)
is_correct3 = BLS.verify_batch(agg_signatures3, messages, public_keys)
=> true


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Bls12::381 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.