Skip to content

Sync and Async APIs

One rule decides a function's timing across the whole library: pure DER/PEM decoding and in-memory transformation is synchronous; anything that touches WebCrypto (digest, sign, verify, key import/export/generation, PBES2) is asynchronous and must be awaited.

Per entrypoint

EntrypointSynchronousAsynchronous
micro509/dereverything
micro509/pemeverything
micro509/resulteverything
micro509/x509parsing, encode*/decode*, DN comparison and text helpers, subjectKeyIdentifier, source normalizerscreate*, certificateFingerprint, getSubjectPublicKey*, private-key matching
micro509/verifymatchServiceIdentity, matchCertificateServiceIdentity, checkExtendedKeyUsage, isSelfIssuedCertificate, trustAnchorFromCertificatechain verification, candidate-path building and validation, CSR verification
micro509/revocationparse*, isCertificateRevoked, revocationReasonFromCode, hasOcspNoCheckExtension, responder-URI discoveryCRL/OCSP creation, signature verification, validation, check* orchestration
micro509/keysinspectEncryptedPkcs8Der, parsePbes2AlgorithmIdentifierevery import/export/generation function, RSA-OAEP
micro509/pkcsparsePkcs7SignedData*, parsePkcs7CertBag*SignedData creation and verification, PFX creation and parsing, PKCS#12 MAC
micro509/cryptoecdsaSignatureDerToRaw, ecdsaSignatureRawToDersignData, verifySignature

PFX parsing is asynchronous even without an encrypted payload, and subjectKeyIdentifier is synchronous despite being a digest: it uses the library's own SHA-1, since WebCrypto has no synchronous hash.

micro509/x509 in detail

FunctionsTimingWhy
parseCertificate*, parseCertificateSigningRequest*syncPure PEM/DER decoding
parseCertificateChainPem, parseCertificate(s)FromSourcesyncPure PEM/DER decoding
encode*, build*, decode*, findExtension, and name text helperssyncPure transformation of in-memory data
compareDistinguishedNames, canonicalDnKey, IP helperssyncPure transformation of in-memory data
subjectKeyIdentifiersyncLibrary-internal SHA-1
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.