Skip to content

Class: PublicKey ​

Defined in: keys.ts:51

A public key (KEM or signature). Safe to share, log and persist.

Accessors ​

algorithm ​

Get Signature ​

get algorithm(): string

Defined in: keys.ts:114

Canonical algorithm string, e.g. X25519+ML-KEM-768.

Throws ​

if the key has been freed.

Returns ​

string


migrationState ​

Get Signature ​

get migrationState(): MigrationState

Defined in: keys.ts:121

Migration state recorded with the key.

Throws ​

if the key has been freed.

Returns ​

MigrationState

Methods ​

[dispose]() ​

[dispose](): void

Defined in: keys.ts:179

Supports using key = ...; calls PublicKey.free.

Returns ​

void


fingerprint() ​

fingerprint(): string

Defined in: keys.ts:136

sha256(algorithm ‖ 0x00 ‖ key) as lowercase hex (identical to quantum-safe-py).

Returns ​

string

Throws ​

if the key has been freed.


fingerprintColon() ​

fingerprintColon(): string

Defined in: keys.ts:143

Fingerprint as colon-separated byte pairs.

Returns ​

string

Throws ​

if the key has been freed.


free() ​

free(): void

Defined in: keys.ts:175

Releases WASM memory. The object is unusable afterwards. Calling it again does nothing.

Returns ​

void


toBytes() ​

toBytes(): Uint8Array

Defined in: keys.ts:129

Raw key bytes in quantum-safe-py wire layout.

Returns ​

Uint8Array

A copy of the key bytes.

Throws ​

if the key has been freed.


toCbor() ​

toCbor(): Uint8Array

Defined in: keys.ts:150

CBOR serialization ({v, algo, ms, ktype, key}).

Returns ​

Uint8Array

Throws ​

if the key has been freed.


toJSON() ​

toJSON(): object

Defined in: keys.ts:187

JSON form used by JSON.stringify: the type tag, algorithm and full fingerprint (no key bytes).

Returns ​

object

algorithm ​

algorithm: string

fingerprint ​

fingerprint: string

type ​

type: "PublicKey"


toJwk() ​

toJwk(): string

Defined in: keys.ts:164

JWK serialization as a JSON string (kty: "AKP").

Returns ​

string

Throws ​

if the key has been freed.


toPem() ​

toPem(): string

Defined in: keys.ts:157

PEM serialization with qs-* headers.

Returns ​

string

Throws ​

if the key has been freed.


toString() ​

toString(): string

Defined in: keys.ts:183

Short description with the algorithm and the first 12 hex characters of the fingerprint.

Returns ​

string


fromBytes() ​

static fromBytes(algorithm, raw, migrationState?): PublicKey

Defined in: keys.ts:69

Builds a key from its raw bytes (for example read from a quantum-safe-py key). The raw length is checked against the algorithm.

Parameters ​

algorithm ​

string

Canonical algorithm string, e.g. X25519+ML-KEM-768.

raw ​

Uint8Array

Raw public key bytes in quantum-safe-py wire layout.

migrationState? ​

MigrationState

State to record with the key. Default: hybrid_transition for hybrid names and X-Wing, pqc_only otherwise.

Returns ​

PublicKey

The public key.

Throws ​

if algorithm is not a string, raw is empty or not bytes, or migrationState is unknown.

Throws ​

if the length of raw is not the public key length of algorithm.


fromCbor() ​

static fromCbor(data): PublicKey

Defined in: keys.ts:83

Parses to_cbor() output of quantum-safe-py or this library.

Parameters ​

data ​

Uint8Array

CBOR-encoded public key.

Returns ​

PublicKey

The public key.

Throws ​

if data is not a valid CBOR public key (a secret key is rejected too).

Throws ​

if the key was written by a newer format version.

Throws ​

if data exceeds the 10 MB limit.

Throws ​

if data is not bytes.


fromJwk() ​

static fromJwk(jwk): PublicKey

Defined in: keys.ts:105

Parses a JWK (kty: "AKP") given as a JSON string or object.

Parameters ​

jwk ​

string | Record<string, unknown>

The JWK as a JSON string or a plain object.

Returns ​

PublicKey

The public key.

Throws ​

if the JWK is not a valid public key JWK.

Throws ​

if the JWK text exceeds the 10 MB limit.


fromPem() ​

static fromPem(pem): PublicKey

Defined in: keys.ts:95

Parses a QUANTUM SAFE PUBLIC KEY PEM.

Parameters ​

pem ​

string

PEM text.

Returns ​

PublicKey

The public key.

Throws ​

if pem is not a valid PEM public key (a secret key PEM is rejected too).

Throws ​

if the key was written by a newer format version.

Throws ​

if pem exceeds the 10 MB limit.

Throws ​

if pem is not a string.

Apache-2.0.