# BlsPoint

Utility functions for working with BLS12-381 points.

:::info
The `BlsPoint` module is a friendly wrapper over [`@noble/curves/bls12-381`](https://github.com/paulmillr/noble-curves), an **audited** implementation of BLS12-381.
:::

## Examples

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

* [Public Keys or Signatures to Hex](#public-keys-or-signatures-to-hex)

* [Hex to Public Keys or Signatures](#hex-to-public-keys-or-signatures)

### Public Keys or Signatures to Hex

BLS points can be converted to hex using [`BlsPoint.toHex`](/api/BlsPoint/toHex):

```ts twoslash
import { Bls, BlsPoint } from 'ox'

const publicKey = Bls.getPublicKey({ privateKey: '0x...' })
const publicKeyHex = BlsPoint.toHex(publicKey)
// @log: '0xacafff52270773ad1728df2807c0f1b0b271fa6b37dfb8b2f75448573c76c81bcd6790328a60e40ef5a13343b32d9e66'

const signature = Bls.sign({
  payload: '0xdeadbeef',
  privateKey: '0x...'
})
const signatureHex = BlsPoint.toHex(signature)
// @log: '0xb4698f7611999fba87033b9cf72312c76c683bbc48175e2d4cb275907d6a267ab9840a66e3051e5ed36fd13aa712f9a9024f9fa9b67f716dfb74ae4efb7d9f1b7b43b4679abed6644cf476c12e79f309351ea8452487cd93f66e29e04ebe427c'
```

### Hex to Public Keys or Signatures

BLS points can be converted from hex using [`BlsPoint.fromHex`](/api/BlsPoint/fromHex):

```ts twoslash
import { Bls, BlsPoint } from 'ox'

const publicKey = BlsPoint.fromHex(
  '0xacafff52270773ad1728df2807c0f1b0b271fa6b37dfb8b2f75448573c76c81bcd6790328a60e40ef5a13343b32d9e66',
  'G1'
)
// @log: { x: 172...514n, y: 175...235n, z: 1n }

const signature = BlsPoint.fromHex(
  '0xb4698f7611999fba87033b9cf72312c76c683bbc48175e2d4cb275907d6a267ab9840a66e3051e5ed36fd13aa712f9a9024f9fa9b67f716dfb74ae4efb7d9f1b7b43b4679abed6644cf476c12e79f309351ea8452487cd93f66e29e04ebe427c',
  'G2'
)
// @log: { x: 1251...5152n, y: 1251...5152n, z: 1n }
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`BlsPoint.fromBytes`](/api/BlsPoint/fromBytes) | Converts [`Bytes.Bytes`](/api/Bytes/types#bytes) to a BLS point. |
| [`BlsPoint.fromHex`](/api/BlsPoint/fromHex) | Converts [`Hex.Hex`](/api/Hex/types#hex) to a BLS point. |
| [`BlsPoint.toBytes`](/api/BlsPoint/toBytes) | Converts a BLS point to [`Bytes.Bytes`](/api/Bytes/types#bytes). |
| [`BlsPoint.toHex`](/api/BlsPoint/toHex) | Converts a BLS point to [`Hex.Hex`](/api/Hex/types#hex). |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`BlsPoint.BlsPoint`](/api/BlsPoint/types#blspointblspoint) | Root type for a BLS point on the G1 or G2 curve. |
| [`BlsPoint.Fp`](/api/BlsPoint/types#blspointfp) | Type for a field element in the base field of the BLS12-381 curve. |
| [`BlsPoint.Fp2`](/api/BlsPoint/types#blspointfp2) | Type for a field element in the extension field of the BLS12-381 curve. |
| [`BlsPoint.G1`](/api/BlsPoint/types#blspointg1) | Type for a BLS point on the G1 curve. |
| [`BlsPoint.G1Bytes`](/api/BlsPoint/types#blspointg1bytes) | Branded type for a bytes representation of a G1 point. |
| [`BlsPoint.G1Hex`](/api/BlsPoint/types#blspointg1hex) | Branded type for a hex representation of a G1 point. |
| [`BlsPoint.G2`](/api/BlsPoint/types#blspointg2) | Type for a BLS point on the G2 curve. |
| [`BlsPoint.G2Bytes`](/api/BlsPoint/types#blspointg2bytes) | Branded type for a bytes representation of a G2 point. |
| [`BlsPoint.G2Hex`](/api/BlsPoint/types#blspointg2hex) | Branded type for a hex representation of a G2 point. |
