# MlDsa44

Utilities for working with ML-DSA-44 signatures and key pairs, as defined in [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final).

ML-DSA is a post-quantum digital signature scheme, standardized by NIST as the
primary quantum-resistant replacement for elliptic-curve signatures. The `44`
parameter set targets NIST security category 2 (128-bit classical security).

Private keys are the 32-byte FIPS 204 seed. Public keys are 1,312 bytes and
signatures are 2,420 bytes.

## Examples

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

* [Creating Key Pairs](#creating-key-pairs)

* [Signing & Verifying](#signing-&-verifying)

### Creating Key Pairs

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

const { privateKey, publicKey } = MlDsa44.createKeyPair()
```

### Signing & Verifying

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

const { privateKey, publicKey } = MlDsa44.createKeyPair()
const payload = '0xdeadbeef'

const signature = MlDsa44.sign({ payload, privateKey })
const isValid = MlDsa44.verify({
  payload,
  publicKey,
  signature
})
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`MlDsa44.createKeyPair`](/api/MlDsa44/createKeyPair) | Creates a new ML-DSA-44 key pair consisting of a private key and its corresponding public key. |
| [`MlDsa44.fromPrf`](/api/MlDsa44/fromPrf) | Derives an ML-DSA-44 private key from a 32-byte WebAuthn PRF output. |
| [`MlDsa44.getPublicKey`](/api/MlDsa44/getPublicKey) | Computes the ML-DSA-44 public key from a provided private key. |
| [`MlDsa44.randomPrivateKey`](/api/MlDsa44/randomPrivateKey) | Generates a random ML-DSA-44 private key (32-byte seed). |
| [`MlDsa44.sign`](/api/MlDsa44/sign) | Signs the payload with the provided private key and returns an ML-DSA-44 signature (2,420 bytes). |
| [`MlDsa44.verify`](/api/MlDsa44/verify) | Verifies a payload was signed by the provided public key. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`MlDsa44.InvalidContextSizeError`](/api/MlDsa44/errors#mldsa44invalidcontextsizeerror) | Thrown when a context string exceeds the 255-byte FIPS 204 limit. |
| [`MlDsa44.InvalidPrfSizeError`](/api/MlDsa44/errors#mldsa44invalidprfsizeerror) | Thrown when a WebAuthn PRF output is not 32 bytes. |
