SignatureKit

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.

  1. Install the packages

    Start with the @signature-kit/signatures runtime and the @signature-kit/a1 signer.

    @signature-kit/signatures @signature-kit/a1
  2. Provide the Signatures layer

    a1SignaturesLayer takes the .pfx bytes and the Redacted password, validates the certificate, and provides the Signatures service.

    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 ?? ""),
    })
  3. Sign and verify bytes

    The service exposes signatures.inspect, signatures.sign, and signatures.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: boolean
  4. Add XML and PDF

    PDF reuses the same boundary via Effect.provide(layer) and also needs the PdfCore engine layer (pdfCoreFileLayer on Node/Bun, pdfCoreBrowserLayer in browsers). XML also declares xmlRuntimeLayer, an explicit runtime dependency.

    @signature-kit/xml @signature-kit/pdf @signature-kit/pdf-core

    title="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:

Next steps

How is this guide?