Bls.getPublicKey
Computes the BLS12-381 public key from a provided private key.
Public Keys can be derived as a point on one of the BLS12-381 groups:
- G1 Point (Default): - short (48 bytes) - computes longer G2 Signatures (96 bytes) - G2 Point: - long (96 bytes) - computes short G1 Signatures (48 bytes)
Imports
Named
import { Bls } from 'ox'
Examples
Short G1 Public Keys (Default)
import { Bls } from 'ox'
const const publicKey: {
x: bigint;
y: bigint;
z: bigint;
}publicKey = Bls.getPublicKey({ privateKey: '0x...' })
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
.
import { Bls } from 'ox'
const publicKey = Bls.getPublicKey({
privateKey: '0x...',
size: 'long-key:short-sig',
})
const publicKey: {
x: {
c0: bigint;
c1: bigint;
};
y: {
c0: bigint;
c1: bigint;
};
z: {
c0: bigint;
c1: bigint;
};
}publicKey
Serializing
Public Keys can be serialized to hex or bytes using BlsPoint.toHex
or BlsPoint.toBytes
:
import { Bls, BlsPoint } from 'ox'
const publicKey = Bls.getPublicKey({ privateKey: '0x...' })
const const publicKeyHex: BlsPoint.G1HexpublicKeyHex = BlsPoint.toHex(publicKey)
const const publicKeyBytes: BlsPoint.G1BytespublicKeyBytes = BlsPoint.toBytes(publicKey)
They can also be deserialized from hex or bytes using BlsPoint.fromHex
or BlsPoint.fromBytes
:
import { Bls, BlsPoint } from 'ox'
const publicKeyHex = '0x...'
const const publicKey: {
x: bigint;
y: bigint;
z: bigint;
}publicKey = BlsPoint.fromHex(publicKeyHex, 'G1')
Definition
function getPublicKey<size>(
options: getPublicKey.Options<size>,
): size extends 'short-key:long-sig' ? BlsPoint.G1 : BlsPoint.G2
Source: src/core/Bls.ts
Parameters
options
- Type:
getPublicKey.Options<size>
The options to compute the public key.
options.privateKey
- Type:
0x${string} | Uint8Array
Private key to compute the public key from.
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 computed public key.
size extends 'short-key:long-sig' ? BlsPoint.G1 : BlsPoint.G2