Skip to content

BlsPoint

Utility functions for working with BLS12-381 points.

Examples

Below are some examples demonstrating common usages of the BlsPoint module:

Public Keys or Signatures to Hex

BLS points can be converted to hex using BlsPoint.toHex:

import { Bls, BlsPoint } from 'ox'
 
const publicKey = Bls.getPublicKey({ privateKey: '0x...' })
const publicKeyHex = BlsPoint.toHex(publicKey)
'0xacafff52270773ad1728df2807c0f1b0b271fa6b37dfb8b2f75448573c76c81bcd6790328a60e40ef5a13343b32d9e66'
const signature = Bls.sign({ payload: '0xdeadbeef', privateKey: '0x...' }) const signatureHex = BlsPoint.toHex(signature)
'0xb4698f7611999fba87033b9cf72312c76c683bbc48175e2d4cb275907d6a267ab9840a66e3051e5ed36fd13aa712f9a9024f9fa9b67f716dfb74ae4efb7d9f1b7b43b4679abed6644cf476c12e79f309351ea8452487cd93f66e29e04ebe427c'

Hex to Public Keys or Signatures

BLS points can be converted from hex using BlsPoint.fromHex:

import { Bls, BlsPoint } from 'ox'
 
const publicKey = BlsPoint.fromHex('0xacafff52270773ad1728df2807c0f1b0b271fa6b37dfb8b2f75448573c76c81bcd6790328a60e40ef5a13343b32d9e66', 'G1')
{ x: 172...514n, y: 175...235n, z: 1n }
const signature = BlsPoint.fromHex('0xb4698f7611999fba87033b9cf72312c76c683bbc48175e2d4cb275907d6a267ab9840a66e3051e5ed36fd13aa712f9a9024f9fa9b67f716dfb74ae4efb7d9f1b7b43b4679abed6644cf476c12e79f309351ea8452487cd93f66e29e04ebe427c', 'G2')
{ x: 1251...5152n, y: 1251...5152n, z: 1n }

Functions

NameDescription
BlsPoint.fromBytesConverts Bytes.Bytes to a BLS point.
BlsPoint.fromHexConverts Hex.Hex to a BLS point.
BlsPoint.toBytesConverts a BLS point to Bytes.Bytes.
BlsPoint.toHexConverts a BLS point to Hex.Hex.

Types

NameDescription
BlsPoint.BlsPointRoot type for a BLS point on the G1 or G2 curve.
BlsPoint.FpType for a field element in the base field of the BLS12-381 curve.
BlsPoint.Fp2Type for a field element in the extension field of the BLS12-381 curve.
BlsPoint.G1Type for a BLS point on the G1 curve.
BlsPoint.G1BytesBranded type for a bytes representation of a G1 point.
BlsPoint.G1HexBranded type for a hex representation of a G1 point.
BlsPoint.G2Type for a BLS point on the G2 curve.
BlsPoint.G2BytesBranded type for a bytes representation of a G2 point.
BlsPoint.G2HexBranded type for a hex representation of a G2 point.