
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
pq-key-encoder
Advanced tools
Post-quantum key encoding utilities for NIST PQC algorithms.
| :warning: | This package has not yet been independently audited. Security audit is pending. Use in production at your own risk. This notice will be updated with a link to the audit report once complete. See SECURITY.md. |
npm install pq-key-encoder
import {
fromDER,
fromPEM,
fromJWK,
fromSPKI,
fromPKCS8,
toDER,
toPEM,
toJWK,
toSPKI,
toPKCS8,
type KeyData,
type PQJwk,
} from 'pq-key-encoder';
// KeyData is the core type: { alg, type, bytes }
const publicKey: KeyData = {
alg: 'ML-KEM-768',
type: 'public',
bytes: publicKeyBytes, // Uint8Array from key generation
};
const privateKey: KeyData = {
alg: 'ML-KEM-768',
type: 'private',
bytes: privateKeyBytes,
};
// Encode to DER (auto-selects SPKI for public, PKCS8 for private)
const publicDer = toDER(publicKey);
const privateDer = toDER(privateKey);
// Decode from DER (auto-detects key type)
const parsedPublic = fromDER(publicDer);
const parsedPrivate = fromDER(privateDer);
// Explicit SPKI/PKCS8 functions
const spki = toSPKI(publicKey);
const pkcs8 = toPKCS8(privateKey);
const fromSpki = fromSPKI(spki);
const fromPkcs8 = fromPKCS8(pkcs8);
// Encode to PEM (PUBLIC KEY / PRIVATE KEY labels)
const publicPem = toPEM(publicKey);
const privatePem = toPEM(privateKey);
// Decode from PEM
const parsedPublicPem = fromPEM(publicPem);
const parsedPrivatePem = fromPEM(privatePem);
// Public key to JWK
const publicJwk = toJWK(publicKey);
// { kty: 'PQC', alg: 'ML-KEM-768', x: '<base64url>' }
// Private key to JWK (requires public key bytes)
const privateJwk = toJWK(privateKey, {
includePrivate: true,
publicKey: publicKey.bytes,
});
// { kty: 'PQC', alg: 'ML-KEM-768', x: '<base64url>', d: '<base64url>' }
// Decode from JWK
const fromPublicJwk = fromJWK(publicJwk);
const fromPrivateJwk = fromJWK(privateJwk);
Algorithms are validated against pq-oid metadata (OID + key sizes):
| Family | Algorithms |
|---|---|
| ML-KEM | ML-KEM-512, ML-KEM-768, ML-KEM-1024 |
| ML-DSA | ML-DSA-44, ML-DSA-65, ML-DSA-87 |
| SLH-DSA | SHA2/SHAKE variants (128s/f, 192s/f, 256s/f) |
import {
KeyEncoderError,
InvalidInputError,
InvalidEncodingError,
UnsupportedAlgorithmError,
KeySizeMismatchError,
} from 'pq-key-encoder';
try {
const key = fromDER(malformedData);
} catch (error) {
if (error instanceof KeySizeMismatchError) {
console.error(`Expected ${error.expected} bytes, got ${error.actual}`);
} else if (error instanceof UnsupportedAlgorithmError) {
console.error('Unknown algorithm OID');
} else if (error instanceof InvalidEncodingError) {
console.error('Malformed DER structure');
}
}
type AlgorithmName = 'ML-KEM-512' | 'ML-KEM-768' | ... ;
type KeyType = 'public' | 'private';
interface KeyData {
alg: AlgorithmName;
type: KeyType;
bytes: Uint8Array;
}
interface PQJwk {
kty: 'PQC';
alg: AlgorithmName;
x: string; // base64url public key
d?: string; // base64url private key (optional)
}
kty: 'PQC' for post-quantum keysfromJWK returns only private key bytes when both x and d are present (public key is validated but not returned). To get both keys, parse separately:
const privateKey = fromJWK(jwk);
const publicKey = fromJWK({ kty: jwk.kty, alg: jwk.alg, x: jwk.x });
MIT
FAQs
Post-quantum key encoding utilities
We found that pq-key-encoder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.