Installation
Install the core and the A1 signer, provide the Signatures layer, and sign your first bytes with typed errors.
What you'll do: install the runtime, load an A1 certificate, and sign bytes with typed errors. Formats and providers come later, without changing your application's contract.
Install the packages
Start with the
@signature-kit/signaturesruntime and the@signature-kit/a1signer.@signature-kit/signatures @signature-kit/a1Provide the Signatures layer
a1SignaturesLayertakes the.pfxbytes and theRedactedpassword, validates the certificate, and provides theSignaturesservice.title="signature-kit.ts"
import { a1SignaturesLayer } from "@signature-kit/a1/signer" import { signatures } from "@signature-kit/signatures" import { Effect, Redacted } from "effect" export const layer = a1SignaturesLayer({ pfx, // Uint8Array — bytes of the .pfx/.p12 password: Redacted.make(process.env.A1_PASSWORD ?? ""), })Sign and verify bytes
The service exposes
signatures.inspect,signatures.sign, andsignatures.verify. The algorithm is"rsa-sha256"or"rsa-sha512"; the catalog also accepts the legacy"rsa-sha1", supported for compatibility but discouraged.title="sign.ts"
const program = Effect.gen(function* () { const identity = yield* signatures.inspect() // e-CPF / e-CNPJ const artifact = yield* signatures.sign({ content, algorithm: "rsa-sha256", }) const result = yield* signatures.verify({ content, signature: artifact.signature, algorithm: artifact.algorithm, }) return { identity, result } }).pipe(Effect.provide(layer)) // result.valid: booleanAdd XML and PDF
PDF reuses the same boundary via
Effect.provide(layer)and also needs thePdfCoreengine layer (pdfCoreFileLayeron Node/Bun,pdfCoreBrowserLayerin browsers). XML also declaresxmlRuntimeLayer, an explicit runtime dependency.@signature-kit/xml @signature-kit/pdf @signature-kit/pdf-coretitle="documents.ts"
import { signXml } from "@signature-kit/xml/sign" import { xmlRuntimeLayer } from "@signature-kit/xml/runtime" import { signPdf } from "@signature-kit/pdf/sign" import { pdfCoreFileLayer } from "@signature-kit/pdf-core/file" import * as NodeServices from "@effect/platform-node/NodeServices" import { a1SignaturesLayer } from "@signature-kit/a1/signer" import { Effect, Layer, Redacted } from "effect" const pdfCoreLayer = pdfCoreFileLayer.pipe(Layer.provide(NodeServices.layer)) const layer = a1SignaturesLayer({ pfx, // Uint8Array — bytes of the .pfx/.p12 password: Redacted.make(process.env.A1_PASSWORD ?? ""), }) const signedXml = signXml({ xml, referenceId: "nfe-1" }) .pipe(Effect.provide(layer), Effect.provide(xmlRuntimeLayer)) const signedPdf = signPdf({ pdf, policy: "pades-icp-brasil" }) .pipe(Effect.provide(layer), Effect.provide(pdfCoreLayer))
Errors you may see
Every failure is a typed SignatureKitError on the error channel. The most common ones during installation:
signature-kit.WRONG_PASSWORD— "Wrong certificate password."signature-kit.NO_PRIVATE_KEY— "The file does not contain a private key."signature-kit.INVALID_FORMAT— the file is not a PKCS#12 (.pfx/.p12).