Skip to content

Sync and Async APIs

The X.509 entrypoint combines synchronous DER/PEM helpers with operations backed by WebCrypto. Async functions return a Promise and must be awaited; sync functions return their value or Result directly.

Execution model

FunctionsTimingWhy
parseCertificate*, parseCertificateSigningRequest*syncPure PEM/DER decoding
parseCertificateChainPemsyncPure PEM/DER decoding
encode*, build*, decode*, findExtension, and name text helperssyncPure transformation of in-memory data
certificateFingerprintasyncWebCrypto digest
createCertificate, createSelfSignedCertificateasyncWebCrypto key export, key generation, and signing
createCertificateSigningRequestasyncWebCrypto key export and signing
getSubjectPublicKey, getSubjectPublicKeyOrThrowasyncWebCrypto key import
certificateMatchesPrivateKey, matchCertificatePrivateKeyasyncWebCrypto key derivation and export

Every other function exported from micro509/x509 is synchronous.

Await the operation, not the Result

parseCertificatePem(pem) returns a ParseCertificateResult immediately. JavaScript permits await parseCertificatePem(pem), but the await has no effect.

certificateFingerprint(pem) returns a Promise<CertificateFingerprint>. In untyped JavaScript, destructuring it without await reads the Promise object, so colonHex is undefined. TypeScript rejects that destructuring when the library types are intact.

ts
const parsed = parseCertificatePem(pem); // ParseCertificateResult, available now
const fingerprint = await certificateFingerprint(pem); // CertificateFingerprint

Released under the MIT License.