# Bls.createKeyPair

Creates a new BLS12-381 key pair consisting of a private key and its corresponding public key.

* G1 Point (Default): - short (48 bytes) - computes longer G2 Signatures (96 bytes) - G2 Point: - long (96 bytes) - computes short G1 Signatures (48 bytes)

## Imports

:::code-group
```ts [Named]
import { Bls } from 'ox'
```

```ts [Entrypoint]
import * as Bls from 'ox/Bls'
```
:::

## Examples

### Short G1 Public Keys (Default)

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

const { publicKey } = Bls.createKeyPair()
//      ^?
```

### Long G2 Public Keys

A G2 Public Key can be derived as a G2 point (96 bytes) using `size: 'long-key:short-sig'`.

This will allow you to compute G1 Signatures (48 bytes) with [`Bls.sign`](/api/Bls/sign).

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

const { publicKey } = Bls.createKeyPair({
  size: 'long-key:short-sig'
})

publicKey
// ^?
```

### Serializing

Public Keys can be serialized to hex or bytes using [`BlsPoint.toHex`](/api/BlsPoint/toHex) or [`BlsPoint.toBytes`](/api/BlsPoint/toBytes):

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

const { publicKey } = Bls.createKeyPair()

const publicKeyHex = BlsPoint.toHex(publicKey)
//    ^?

const publicKeyBytes = BlsPoint.toBytes(publicKey)
//    ^?
```

They can also be deserialized from hex or bytes using [`BlsPoint.fromHex`](/api/BlsPoint/fromHex) or [`BlsPoint.fromBytes`](/api/BlsPoint/fromBytes):

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

const publicKeyHex = '0x...'

const publicKey = BlsPoint.fromHex(publicKeyHex, 'G1')
//    ^?
```

## Definition

```ts
function createKeyPair<as, size>(
  options?: createKeyPair.Options<as, size>,
): createKeyPair.ReturnType<as, size>
```

**Source:** [src/core/Bls.ts](https://github.com/wevm/ox/blob/main/src/core/Bls.ts#L767)

## Parameters

### options

* **Type:** `createKeyPair.Options<as, size>`
* **Optional**

The options to generate the key pair.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

Format of the returned private key.

#### options.size

* **Type:** `size | Size`
* **Optional**

Size of the public key to compute.

* `'short-key:long-sig'`: 48 bytes; computes long signatures (96 bytes)
* `'long-key:short-sig'`: 96 bytes; computes short signatures (48 bytes)

## Return Type

The generated key pair containing both private and public keys.

`createKeyPair.ReturnType<as, size>`
