-
Notifications
You must be signed in to change notification settings - Fork 0
Core API
The Core API is exposed by CertGadgetsCore. It is UI-independent and is available from both @pkistudio/certgadgets and @pkistudio/certgadgets/core.
import { CertGadgetsCore } from '@pkistudio/certgadgets';
const bytes = new Uint8Array(await file.arrayBuffer());
const certificate = CertGadgetsCore.createCertificateFromBytes(bytes, file.name);
const plans = CertGadgetsCore.collectNetworkValidationPlans(certificate);
console.log(CertGadgetsCore.version);
console.log(certificate.root.children?.length);
console.log(plans.map((plan) => plan.operation));Use createCertificateFromBytes(bytes, sourceName) to parse DER or PEM certificate input and create a CertificateDocument model.
The returned document includes:
- A stable document id.
- A display label derived from the certificate subject or source name.
- Source name, byte size, and load time.
- A root
CertificateTreeNodewith certificate details, DER bytes, and child nodes.
The browser app uses this same tree model for navigation, detail rendering, validation actions, and ASN.1 viewer routing.
Use createDemoCertificate() when a host needs a lightweight placeholder certificate document for demos or UI integration tests.
The demo data is not a replacement for parsing real certificate bytes.
Use collectNetworkValidationPlans(document) to collect unique network validation targets from a parsed certificate document.
Plans can describe resources such as:
- OCSP responder URLs.
- AIA CA Issuers certificate URLs.
- CRL Distribution Point URLs.
- Generic HTTP or HTTPS extension resources.
The Core API only describes possible network work. It does not fetch resources or prompt users. Hosts can pass plans to CertGadgetsValidation or implement their own confirmation and networking flow.
The Core API includes helpers for common browser data conversion work:
-
normalizeCertificateBytes(bytes): accept DER or PEM certificate bytes and return DER certificate bytes. -
derToPem(label, bytes): write a PEM block. -
pemToDer(text, expectedLabel?): parse a PEM block. -
hexToBytes(text): parse HEX input. -
bytesToHexPreview(bytes, maxBytes?): create a readable clipped HEX preview. -
bytesToBase64(bytes): encode bytes for PEM or display workflows. -
base64ToBytes(base64): decode Base64 to bytes. -
toArrayBuffer(bytes): create anArrayBufferfor structured parsing APIs.
Use canDecodeAsn1(bytes) to check whether a byte array is a complete ASN.1 DER object.
Use wrapBytesInOctetString(bytes) when raw validation response bytes should be opened in an ASN.1 viewer as an OCTET STRING wrapper.
Important exported types include:
-
CertificateDocument. -
CertificateTreeNode. -
CertificateDetail. -
CertificateNetworkResource. -
NetworkValidationPlan.
These types are designed to stay independent from DOM APIs, VS Code APIs, and host-specific networking behavior.