Module: Eth::Bls
- Defined in:
- lib/eth/bls.rb
Overview
Helper methods for interacting with BLS12-381 points and signatures
Class Method Summary collapse
-
.decode_public_key(hex) ⇒ BLS::PointG1
Decode a compressed G1 public key from hex.
-
.decode_signature(hex) ⇒ BLS::PointG2
Decode a compressed G2 signature from hex.
-
.encode_public_key(point) ⇒ String
Encode a G1 public key to compressed hex.
-
.encode_signature(point) ⇒ String
Encode a G2 signature to compressed hex.
-
.get_public_key(priv_hex) ⇒ String
Derive a compressed public key from a private key.
-
.sign(message, priv_hex) ⇒ String
Sign a message digest with the given private key.
-
.verify(message, signature_hex, pubkey_hex) ⇒ Boolean
Verify a BLS signature using pairings.
Class Method Details
.decode_public_key(hex) ⇒ BLS::PointG1
Decode a compressed G1 public key from hex.
13 14 15 |
# File 'lib/eth/bls.rb', line 13 def decode_public_key(hex) BLS::PointG1.from_hex Util.remove_hex_prefix(hex) end |
.decode_signature(hex) ⇒ BLS::PointG2
Decode a compressed G2 signature from hex.
27 28 29 |
# File 'lib/eth/bls.rb', line 27 def decode_signature(hex) BLS::PointG2.from_hex Util.remove_hex_prefix(hex) end |
.encode_public_key(point) ⇒ String
Encode a G1 public key to compressed hex.
20 21 22 |
# File 'lib/eth/bls.rb', line 20 def encode_public_key(point) Util.prefix_hex point.to_hex(compressed: true) end |
.encode_signature(point) ⇒ String
Encode a G2 signature to compressed hex.
34 35 36 |
# File 'lib/eth/bls.rb', line 34 def encode_signature(point) Util.prefix_hex point.to_hex(compressed: true) end |
.get_public_key(priv_hex) ⇒ String
Derive a compressed public key from a private key.
41 42 43 44 |
# File 'lib/eth/bls.rb', line 41 def get_public_key(priv_hex) key = BLS.get_public_key Util.remove_hex_prefix(priv_hex) encode_public_key key end |
.sign(message, priv_hex) ⇒ String
Sign a message digest with the given private key.
50 51 52 53 54 |
# File 'lib/eth/bls.rb', line 50 def sign(, priv_hex) sig = BLS.sign Util.remove_hex_prefix(), Util.remove_hex_prefix(priv_hex) encode_signature sig end |
.verify(message, signature_hex, pubkey_hex) ⇒ Boolean
Verify a BLS signature using pairings. This mirrors the behaviour of the BLS12-381 pairing precompile.
62 63 64 65 66 |
# File 'lib/eth/bls.rb', line 62 def verify(, signature_hex, pubkey_hex) signature = decode_signature(signature_hex) pubkey = decode_public_key(pubkey_hex) BLS.verify(signature, Util.remove_hex_prefix(), pubkey) end |