First Use
Load an A1 certificate, inspect the identity, and sign your first bytes — then an XML and a PDF — in a single Effect program.
What you'll do: assemble an Effect program that loads the A1 certificate, reads the identity, signs and verifies bytes — then signs an XML and a PDF reusing the same boundary.
Install
Add the core boundary and the A1 signer. Pull in
effectfor theEffectruntime andRedacted.bun add @signature-kit/signatures @signature-kit/a1 effectLoad the A1, inspect, sign and verify
a1SignaturesLayertakes the.pfxbytes and theRedactedpassword and provides theSignaturesservice. Inside oneEffect.gen,signatures.inspect()returns a normalizedSignerIdentity—documentcarries the e-CPF or e-CNPJ when present — thensignatures.signandsignatures.verifyrun over the same boundary.verifyreturns a value:result.validis aboolean, and a real failure surfaces as aSignatureKitErrorin the error channel, never a thrown exception.title="quickstart.ts"
import { a1SignaturesLayer } from "@signature-kit/a1/signer" import { signatures } from "@signature-kit/signatures" 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 ?? ""), }) export const program = Effect.gen(function* () { // normalized identity — identity.document carries e-CPF / e-CNPJ const identity = yield* signatures.inspect() const content = new TextEncoder().encode("content to sign") const artifact = yield* signatures.sign({ content, algorithm: "rsa-sha256", }) const result = yield* signatures.verify({ content, signature: artifact.signature, algorithm: artifact.algorithm, }) return { identity, artifact, result } }).pipe(Effect.provide(layer))Run the program
Run the
EffectwithEffect.runPromise, or call it from another Effect program.title="run.ts"
import { Effect } from "effect" const { result } = await Effect.runPromise(program) console.log(result.valid) // boolean — true if the signature checks outSign XML and PDF
Both formats consume the same boundary via
Effect.provide; thelayerline is identical to the previous step. XML also needsxmlRuntimeLayerand PDF needs thePdfCoreengine layer (pdfCoreFileLayeron Node/Bun,pdfCoreBrowserLayerin browsers);verifyXml/verifyPdfread the public key from the document and do not require the boundary.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, Redacted } from "effect" 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 might see
signature-kit.WRONG_PASSWORD— incorrect certificate password.signature-kit.SIGN_FAILED— failed to sign the content.signature-kit.VERIFY_FAILED— failed to verify the signature.