Skip to content

Instance Method

add(mldsa:kid:parser:serializer:)

Adds an MLDSA key to the collection using an MLDSAKey.
@discardableResult func add(mldsa key: some MLDSAKey, kid: JWKIdentifier? = nil, parser: some JWTParser = DefaultJWTParser(), serializer: some JWTSerializer = DefaultJWTSerializer()) -> Self

Parameters

key

The MLDSAKey used for MLDSA signing. Passing a private key allows both signing and verifying, while passing a public key only allows verifying.

kid

An optional JWKIdentifier (Key ID). Providing this identifier allows the JWT kid header field to reference this specific signer.

parser

An optional custom parser that conforms to JWTParser. If not specified, a DefaultJWTParser is used for parsing JWTs.

serializer

An optional custom serializer that conforms to JWTSerializer. If not specified, a DefaultJWTSerializer is used for serializing JWTs.

Return Value

The same instance of the collection (Self), useful for chaining multiple configuration calls.

Discussion

This method incorporates an MLDSA (Module-Lattice-Based Digital Signature Algorithm) signer into the collection. MLDSA is a post-quantum signature scheme, whose use in JWTs is defined by RFC 9964.

Usage Example:

let privateKey = try MLDSA87PrivateKey(seedRepresentation: seed)
let collection = await JWTKeyCollection()
    .add(mldsa: privateKey)