---
title: "Signatures — Svelte"
description: "Sign documents with a drawn, typed or uploaded signature and a key you control, check the signatures a document has, and warn before an edit breaks one."
framework: "Svelte"
other_frameworks:
  "React": "https://www.embedpdf.com/docs/headless/react/forms/signatures.md"
  "Vue": "https://www.embedpdf.com/docs/headless/vue/forms/signatures.md"
  "Angular": "https://www.embedpdf.com/docs/headless/angular/forms/signatures.md"
source: "https://www.embedpdf.com/docs/headless/svelte/forms/signatures"
---

# Signatures

A digital signature has two parts: the **mark**, what people see in the signature field, such as a
drawn signature; and the **key**, which seals the document so any later change shows. The signature
plugin signs with both, checks the signatures a document already has, and warns before an edit would
break one.

Register `signaturePlugin()` next to `formPlugin()` and `stampPlugin()`, with the key to sign with:

**`App.svelte`**

```svelte
<script lang="ts" module>
  import { DocumentGate, Viewer, type OpenInput } from '@embedpdf/svelte/runtime';
  import { Stage, stagePlugin } from '@embedpdf/svelte/stage';
  import { RenderLayer, renderPlugin } from '@embedpdf/svelte/render';
  import { interactionPlugin } from '@embedpdf/svelte/interaction';
  import { FormLayer, formPlugin } from '@embedpdf/svelte/form';
  import { stampPlugin } from '@embedpdf/svelte/stamp';
  import { createTestSigner, signaturePlugin } from '@embedpdf/svelte/signature';
  import { localEngine } from '@embedpdf/engine';
  import SignBar from './SignBar.svelte';

  import '../basic.css';

  const engine = localEngine();
  const assetEngine = engine; // a person's marks are stamps, kept as PDFs; they open here too
  // A throwaway key for the demo. Bring your own with `webCryptoSigner`, a
  // service with `remoteSigner`, or a person's own with `personalSigner`.
  const signer = createTestSigner({ commonName: 'Ada Lovelace' });
  const plugins = [
    stagePlugin(),
    renderPlugin(),
    interactionPlugin(),
    formPlugin(),
    stampPlugin({ assetEngine }),
    signaturePlugin({
      signingKey: () => signer,
      // Trust the demo key itself, so its signatures check out as 'valid'.
      trust: { anchors: async () => [(await signer).certificate] },
    }),
  ];

  const agreement = async (): Promise<OpenInput> => {
    const response = await fetch('https://www.embedpdf.com/pdfs/agreement.pdf');
    return { kind: 'bytes', id: 'agreement', bytes: new Uint8Array(await response.arrayBuffer()) };
  };
</script>

<Viewer {engine} {plugins} initialDocuments={[{ source: agreement }]}>
  <DocumentGate>
    {#snippet fallback()}
      <p class="loading">Loading…</p>
    {/snippet}
    <SignBar />
    <Stage class="stage">
      <RenderLayer />
      <!-- An empty signature field is "sign here": a click makes it the target -->
      <FormLayer />
    </Stage>
  </DocumentGate>
</Viewer>
```

**`basic.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

/* A mark's picture, inside its button */
.preview {
  display: block;
  height: 22px;
}

/* The pages */
.stage {
  height: 440px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`MarkButton.svelte`**

```svelte
<script lang="ts">
  import { useStampAssetPreviewUrl } from '@embedpdf/svelte/stamp';

  let { assetId, label, onPick }: { assetId: string; label: string; onPick: () => void } =
    $props();

  const url = useStampAssetPreviewUrl(() => assetId);
</script>

<button type="button" class="button" title={label} onclick={onPick}>
  {#if url.current}
    <img src={url.current} alt={label} class="preview" />
  {:else}
    {label}
  {/if}
</button>
```

**`SignBar.svelte`**

```svelte
<script lang="ts">
  import { untrack } from 'svelte';
  import { useStage } from '@embedpdf/svelte/stage';
  import { toFieldRef, useForm, useFormState } from '@embedpdf/svelte/form';
  import { useStamp } from '@embedpdf/svelte/stamp';
  import { useSignature, useSignatureState, useSignerRows } from '@embedpdf/svelte/signature';
  import MarkButton from './MarkButton.svelte';

  const form = useForm();
  const stamp = useStamp();
  const stage = useStage();
  const signature = useSignature();
  const signatureState = useSignatureState();
  const rows = useSignerRows();
  const status = useFormState((formState) => formState.status);
  const field = useFormState((formState) =>
    formState.fields.find((candidate) => candidate.kind === 'signature'),
  );
  const person = $derived(rows.current[0]);
  // Ada's signature, once she signs: the agreement already carries Lanternfield's.
  const signed = $derived(signatureState.signatures.find((each) => each.fieldName === 'approval'));
  let error = $state<string | null>(null);

  // Start at the agreement's signature field. The browser holds no signatures
  // yet: add one person with a typed signature.
  let done = false;
  $effect(() => {
    if (status.current !== 'ready' || done) return;
    done = true;
    untrack(async () => {
      // Bring the agreement's signature field into view.
      const [widget] = form.getWidgets(toFieldRef('approval'));
      if (widget) stage.reveal(widget.page, { rect: widget.rect });
      const { library } = await stamp.createLibrary('Ada Lovelace', { kind: 'signatures' });
      await stamp.createAsset({
        libraryId: library.id,
        name: 'signature',
        label: 'Signature',
        mark: { kind: 'text', text: 'Ada Lovelace', fontFamily: 'times-italic', color: '#1d2b53' },
      });
    });
  });

  // The target is the field someone clicked; without one, the form's signature field.
  function sign(assetId: string) {
    const destination = signatureState.target ?? field.current?.ref;
    if (!destination) return;
    error = null;
    signature
      .placeMark({ assetId }, { field: destination })
      .catch((reason: Error) => (error = reason.message));
  }

  const readout = $derived.by(() => {
    if (!person || !field.current) return 'Getting ready…';
    if (error) return error;
    if (signatureState.busy) return 'Signing…';
    if (signed) return `Signed by ${signed.signer.name}: ${signed.verdict?.summary ?? 'checking…'}`;
    if (signatureState.target) return 'Now pick the signature';
    return 'Click the field, or pick the signature';
  });
</script>

<div class="toolbar">
  {#each person?.signatures ?? [] as asset (asset.id)}
    <MarkButton assetId={asset.id} label={asset.label} onPick={() => sign(asset.id)} />
  {/each}
  <output class="readout">{readout}</output>
</div>
```

**`signature-plugin.ts`**

```typescript
import { formPlugin } from '@embedpdf/svelte/form';
import { indexedDbKeyStore, personalSigner, signaturePlugin } from '@embedpdf/svelte/signature';
import { stampPlugin } from '@embedpdf/svelte/stamp';
import { rootCertificate } from './certificates';

export const plugins = [
  /* … */
  formPlugin(),
  stampPlugin(),
  signaturePlugin({
    signingKey: () =>
      personalSigner({ subject: 'Ada Lovelace', store: indexedDbKeyStore('my-app-keys') }),
    trust: { anchors: async () => [rootCertificate] }, // the certificates you trust
  }),
];
```

## Sign a field

```ts
const { version } = await signature.sign({
  field: toFieldRef('approval'),
  mark: { assetId },
  signer: { reason: 'Approved', location: 'Amsterdam' },
});
```

The mark becomes what the field shows, the key seals the document, and the signed document is saved
as a new version. If anything fails along the way, nothing is left half-signed.

A mark is a stamp from a person's signature library, or image bytes you bring:

```ts
{ assetId } // a stamp, drawn, typed or uploaded; see "A person's signatures" below
{ source: pngBytes } // a PNG, a JPEG, or a one-page PDF
```

## Let people click to sign

People can also arm their signature and click where it goes, as in Preview. With the stamp plugin, arm
a mark from a signature library:

- **over an empty signature field**, the click signs it;
- **over a signed field**, nothing happens;
- **anywhere else**, the mark is placed as a stamp.

`placeMark()` does the same from code:

```ts
await signature.placeMark({ assetId }, { field: toFieldRef('approval') }); // signs the field
await signature.placeMark({ assetId }, { page: page.ref, center: { x: 120, y: 90 } }); // a stamp
```

What happens in a field depends on `mode`: `'sign'` signs it, `'visual'` only draws the mark in,
and `'ask'` asks your UI first through `onSignRequested`, so you can show your own sign dialog.

**`App.svelte`**

```svelte
<script lang="ts" module>
  import { DocumentGate, Viewer, type OpenInput } from '@embedpdf/svelte/runtime';
  import { Stage, stagePlugin } from '@embedpdf/svelte/stage';
  import { RenderLayer, renderPlugin } from '@embedpdf/svelte/render';
  import { interactionPlugin } from '@embedpdf/svelte/interaction';
  import { AnnotationLayer, annotationPlugin } from '@embedpdf/svelte/annotation';
  import { FormLayer, formPlugin } from '@embedpdf/svelte/form';
  import { stampPlugin } from '@embedpdf/svelte/stamp';
  import { createTestSigner, signaturePlugin } from '@embedpdf/svelte/signature';
  import { localEngine } from '@embedpdf/engine';
  import ArmBar from './ArmBar.svelte';

  import '../click-to-sign.css';

  const engine = localEngine();
  const assetEngine = engine; // a person's marks are stamps, kept as PDFs; they open here too
  const signer = createTestSigner({ commonName: 'Ada Lovelace' });
  const plugins = [
    stagePlugin(),
    renderPlugin(),
    interactionPlugin(),
    annotationPlugin(),
    formPlugin(),
    stampPlugin({ assetEngine }),
    signaturePlugin({ signingKey: () => signer }),
  ];

  const agreement = async (): Promise<OpenInput> => {
    const response = await fetch('https://www.embedpdf.com/pdfs/agreement.pdf');
    return { kind: 'bytes', id: 'agreement', bytes: new Uint8Array(await response.arrayBuffer()) };
  };
</script>

<Viewer {engine} {plugins} initialDocuments={[{ source: agreement }]}>
  <DocumentGate>
    {#snippet fallback()}
      <p class="loading">Loading…</p>
    {/snippet}
    <ArmBar />
    <Stage class="stage">
      <RenderLayer />
      <AnnotationLayer />
      <FormLayer />
    </Stage>
  </DocumentGate>
</Viewer>
```

**`click-to-sign.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--tint);
  border-color: var(--line-strong);
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

/* The pages */
.stage {
  height: 440px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`ArmBar.svelte`**

```svelte
<script lang="ts">
  import { untrack } from 'svelte';
  import { useStage } from '@embedpdf/svelte/stage';
  import { toFieldRef, useForm, useFormState } from '@embedpdf/svelte/form';
  import { useStamp, useStampState } from '@embedpdf/svelte/stamp';
  import { useSignatureState, useSignerRows } from '@embedpdf/svelte/signature';

  const form = useForm();
  const stamp = useStamp();
  const stage = useStage();
  const stampState = useStampState();
  const signatureState = useSignatureState();
  const rows = useSignerRows();
  const status = useFormState((formState) => formState.status);
  const mark = $derived(rows.current[0]?.signatures[0]);

  // On load: the agreement, where the form's signature field is, and a person's signature, armed.
  let done = false;
  $effect(() => {
    if (status.current !== 'ready' || done) return;
    done = true;
    untrack(async () => {
      // Bring the agreement's signature field into view.
      const [widget] = form.getWidgets(toFieldRef('approval'));
      if (widget) stage.reveal(widget.page, { rect: widget.rect });
      const { library } = await stamp.createLibrary('Ada Lovelace', { kind: 'signatures' });
      const { asset } = await stamp.createAsset({
        libraryId: library.id,
        name: 'signature',
        label: 'Signature',
        mark: { kind: 'text', text: 'Ada Lovelace', fontFamily: 'times-italic', color: '#1d2b53' },
      });
      await stamp.armAsset(asset.id, { targetWidth: 160 });
    });
  });

  const hint = $derived.by(() => {
    // Ada's signature, once she signs: the agreement already carries Lanternfield's.
    const signed = signatureState.signatures.find((each) => each.fieldName === 'approval');
    if (signed) return `The field is signed by ${signed.signer.name}`;
    if (stampState.armedAsset) return 'Click the empty field to sign it, or anywhere else to place it';
    if (mark) return 'Arm the signature, then click where it goes';
    return 'Getting ready…';
  });

  function toggleArmed() {
    if (stampState.armedAsset) stamp.disarm();
    else if (mark) void stamp.armAsset(mark.id);
  }
</script>

<div class="toolbar">
  <button
    type="button"
    class="button"
    disabled={!mark}
    aria-pressed={stampState.armedAsset !== null}
    onclick={toggleArmed}
  >
    {stampState.armedAsset ? 'Disarm' : 'Arm the signature'}
  </button>
  <output class="readout">{hint}</output>
</div>
```

## Fill a field without signing

Sometimes a signature only needs to look signed, such as for a form that gets printed. Draw the mark
into the field without sealing anything:

```ts
await signature.fillField(toFieldRef('approval'), { source: pngBytes });
await signature.clearField(toFieldRef('approval'));
```

A signed field can't be filled or cleared: what it shows is part of what was signed.

**`App.svelte`**

```svelte
<script lang="ts" module>
  import { DocumentGate, Viewer, type OpenInput } from '@embedpdf/svelte/runtime';
  import { Stage, stagePlugin } from '@embedpdf/svelte/stage';
  import { RenderLayer, renderPlugin } from '@embedpdf/svelte/render';
  import { interactionPlugin } from '@embedpdf/svelte/interaction';
  import { formPlugin } from '@embedpdf/svelte/form';
  import { stampPlugin } from '@embedpdf/svelte/stamp';
  import { signaturePlugin } from '@embedpdf/svelte/signature';
  import { localEngine } from '@embedpdf/engine';
  import FillBar from './FillBar.svelte';

  import '../fill.css';

  const engine = localEngine();
  const assetEngine = engine; // a person's marks are stamps, kept as PDFs; they open here too
  // No key: a mark is only drawn in, nothing is sealed.
  const plugins = [
    stagePlugin(),
    renderPlugin(),
    interactionPlugin(),
    formPlugin(),
    stampPlugin({ assetEngine }),
    signaturePlugin(),
  ];

  const agreement = async (): Promise<OpenInput> => {
    const response = await fetch('https://www.embedpdf.com/pdfs/agreement.pdf');
    return { kind: 'bytes', id: 'agreement', bytes: new Uint8Array(await response.arrayBuffer()) };
  };
</script>

<Viewer {engine} {plugins} initialDocuments={[{ source: agreement }]}>
  <DocumentGate>
    {#snippet fallback()}
      <p class="loading">Loading…</p>
    {/snippet}
    <FillBar />
    <Stage class="stage">
      <RenderLayer />
    </Stage>
  </DocumentGate>
</Viewer>
```

**`fill.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

/* The pages */
.stage {
  height: 440px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`FillBar.svelte`**

```svelte
<script lang="ts">
  import { untrack } from 'svelte';
  import { useStage } from '@embedpdf/svelte/stage';
  import { toFieldRef, useForm, useFormState } from '@embedpdf/svelte/form';
  import { useStamp } from '@embedpdf/svelte/stamp';
  import { useSignature, useSignatureEvent } from '@embedpdf/svelte/signature';

  const APPROVAL = toFieldRef('approval');

  const form = useForm();
  const stamp = useStamp();
  const stage = useStage();
  const signature = useSignature();
  const status = useFormState((formState) => formState.status);
  let assetId = $state<string | null>(null);
  let drawn = $state(false);

  useSignatureEvent(
    (plugin) => plugin.onFilled,
    () => (drawn = true),
  );
  useSignatureEvent(
    (plugin) => plugin.onCleared,
    () => (drawn = false),
  );

  // On load: Ada's typed signature, ready to draw in, and the signature field in view.
  let done = false;
  $effect(() => {
    if (status.current !== 'ready' || done) return;
    done = true;
    untrack(async () => {
      // Bring the agreement's signature field into view.
      const [widget] = form.getWidgets(APPROVAL);
      if (widget) stage.reveal(widget.page, { rect: widget.rect });
      const { library } = await stamp.createLibrary('Ada Lovelace', { kind: 'signatures' });
      const { asset } = await stamp.createAsset({
        libraryId: library.id,
        name: 'signature',
        label: 'Signature',
        mark: { kind: 'text', text: 'Ada Lovelace', fontFamily: 'times-italic', color: '#1d2b53' },
      });
      assetId = asset.id;
    });
  });

  function drawIn() {
    if (assetId) void signature.fillField(APPROVAL, { assetId });
  }
</script>

<div class="toolbar">
  <button type="button" class="button" disabled={!assetId || drawn} onclick={drawIn}>
    Draw it in
  </button>
  <button
    type="button"
    class="button"
    disabled={!drawn}
    onclick={() => void signature.clearField(APPROVAL)}
  >
    Take it out
  </button>
  <output class="readout">
    {drawn ? 'Drawn in, not signed: no key sealed anything' : 'The field is empty'}
  </output>
</div>
```

## The key

The engine never holds a key. You give the plugin a **signer**, which does the signing.
`@embedpdf/svelte/signature` has one for each case:

```ts
// Your own key and certificate chain
webCryptoSigner({ privateKey, certificateChain: [leaf, issuer] });

// Your signing service or hardware module: only the document's fingerprint leaves the browser
remoteSigner({ sign: ({ digest, algorithm, subFilter }) => api.sign(digest, algorithm, subFilter) });

// A key per person, created in the browser and kept there, never readable
personalSigner({ subject: 'Ada Lovelace', store: indexedDbKeyStore('my-app-keys') });

// For tests and demos
createTestSigner({ commonName: 'Demo' });
```

A personal signer works like signing in Preview, with real cryptography: a reader who trusts that
person's certificate sees a valid signature, and everyone else sees "validity unknown", the honest
answer for a key the person made themselves. For signatures everyone can check, sign with a
certificate from a trusted provider, through `webCryptoSigner` or `remoteSigner`.

### Signing in two steps

When the key signs somewhere else, such as on a phone or in a signing service that asks for approval,
split the signing in two:

```ts
const { signingId, digest } = await signature.prepareSignature({ field, mark: { assetId } });
const cms = await myService.sign(digest); // may take minutes
await signature.completeSignature(signingId, cms);
```

While a signature is prepared, the document can't be changed, so nothing can slip in between.
`signature.cancelPending()` gives up.

`completeSignature()` checks what the key returned before it seals anything. When it fails,
nothing is written and the signature stays prepared:

- **The timestamp authority didn't answer** (`Network`): call `completeSignature()` again with the
  same `cms`. The key doesn't sign twice.
- **The `cms` was refused** (`SignatureRefused`), for example because it signs another
  fingerprint: it will be refused again. Call `cancelPending()` and start over.

### A timestamp with every signature

A signature says when it was made, by the signer's own clock. A timestamp authority vouches for
that time, so a reader doesn't have to take the signer's word for it, and the signature can still
be checked after the signer's certificate expires. Set one when you register the plugin, and every
signature it seals carries a timestamp:

```ts
signaturePlugin({
  signingKey,
  timestampAuthority: httpTimestampAuthority({
    url: '/api/timestamp',
  }),
});
```

`httpTimestampAuthority()` comes from the same place as the signers. Most authorities can't be
called from a web page, so `url` is a route of your own that passes the request on;
[Reach the authority from a browser](https://www.embedpdf.com/docs/engine/forms/signatures.md#reach-the-authority-from-a-browser)
has one.

- **A timestamp is never skipped.** When the authority can't be reached or its answer doesn't
  check out, the signing fails and nothing is signed.
- **One signature without a timestamp:** pass `timestampAuthority: null` to that `sign()` or
  `prepareSignature()`. Pass another authority to use that one instead.
- **In two steps**, `prepareSignature()` reserves room for the timestamp and
  `completeSignature()` adds it.
- **With `trust` set, the authority must be one you trust.** The plugin won't seal a timestamp
  from an authority your `trust` doesn't cover, so a wrong address fails at the first signature
  and not at the first reader. List the authority's root under `timestampAnchors`:

```ts
signaturePlugin({
  signingKey,
  timestampAuthority,
  trust: {
    anchors: async () => [companyRoot],
    timestampAnchors: async () => [authorityRoot],
  },
});
```

### Keep a signature checkable for years

A timestamp proves when a signature was made. To check the signature years later, a reader also
has to know that the signer's certificate had not been withdrawn by then, and its issuer may no
longer answer that question. Set `revocation`, and every signature the plugin seals gets those
answers right after, stored in the file. Acrobat shows such a signature as "LTV enabled":

```ts
signaturePlugin({
  signingKey,
  timestampAuthority: httpTimestampAuthority({ url: '/api/timestamp' }),
  revocation: httpRevocationSource({ url: '/api/revocation' }),
  documentTimestamp: true,
  trust,
});
```

`httpRevocationSource()` comes from the same place as the signers. A web page can't call a
certificate's issuer, so `url` is a route of your own that passes the question on;
[Reach the issuers from a browser](https://www.embedpdf.com/docs/engine/forms/signatures.md#reach-the-issuers-from-a-browser)
has one.

- **It needs `trust` and a timestamp.** The answers kept are the ones for the certificates
  between the signer and a certificate you trust, at the time the timestamp proves.
- **`documentTimestamp: true` adds a document timestamp after the answers**, from
  `timestampAuthority`. It proves the answers were in the file by then, which a strict validator
  asks for.
- **The signature is sealed first.** The answers go into the file after the signature, so a
  failure there can't undo it: `sign()` still resolves, and its result says what happened.

```ts
const result = await signature.sign({ field, mark });

result.validationInfo;
// { added: { certificates: 3, ocspResponses: 2, crls: 0 },
//   documentTimestamp: { kind: 'fqn', name: 'Timestamp1' } }

if (result.validationInfoError) {
  // Signed, but the file doesn't hold the answers yet. Try again later:
  await signature.addValidationInfo(result.signature.field);
}
```

- **Only the signature just made is covered.** Other people's signatures may name issuers that
  no longer answer. `signature.addValidationInfo()` with no field covers every signature, and
  rejects when one can't be covered.
- **It takes the `doc.sign` permission.** Someone who may only sign their own group's fields
  signs without it, and `result.validationInfo` is `null`. Whoever finishes the document then
  calls `signature.addValidationInfo()` once, for everyone.
- **`completeSignature()` and `placeMark()` do the same** as `sign()`.

## Check the signatures

**`signature-list.svelte`**

```svelte
<script lang="ts">
  import { useSignatureState } from '@embedpdf/svelte/signature';

  const state = useSignatureState();
</script>

<ul>
  {#each state.signatures as sig (sig.fieldName)}
    <li>{sig.fieldName}: {sig.verdict?.summary ?? 'checking…'}</li>
  {/each}
</ul>
```

A verdict's `summary` is:

| Summary             | Means                                                                |
| :------------------ | :------------------------------------------------------------------- |
| `'valid'`           | Nothing changed since it was signed, and you trust the signer        |
| `'valid-untrusted'` | Nothing changed, but the signer's certificate isn't one you trust    |
| `'invalid'`         | The document changed in a way the signature doesn't allow            |
| `'indeterminate'`   | It couldn't be checked, for example because a certificate is missing |

The plugin checks the signatures when the document opens, and again after every change. For a
detailed report of what changed since a signature, rule by rule, use `signature.analyzeChanges()`.

`'valid'` means the signer's certificate is within its dates and leads to one you trust.
Whether it was withdrawn is in `verdict.revocation`: `'good'`, `'revoked'` or `'unknown'`, read
from the answers the file holds. Proof of a withdrawal makes the summary `'invalid'`, and
`'unknown'` never changes it. The plugin asks nobody when it checks, so opening a document
doesn't tell a certificate authority who is reading it.

### Whether it can be checked for years

`verdict.longTerm` says whether the file holds everything a reader needs, with no network:

```ts
const { longTerm } = verdict;

longTerm.enabled; // true: what Acrobat calls "LTV enabled"
longTerm.expiresAt; // the day that proof runs out, or null
longTerm.missing; // what stands in the way: [{ certificate, reason }]
```

For a signature that isn't there yet, offer to add what is missing:

```ts
if (!verdict.longTerm.enabled && signature.canAddValidationInfo()) {
  await signature.addValidationInfo(verdict.signature.field);
}
```

`addValidationInfo()` asks through the `revocation` setting, stores the answers, and adds a
document timestamp when `documentTimestamp` is set and the answers aren't covered by one yet. It
rejects, and stores nothing, when an answer is missing: `error.details.reason` says why
(`'no-timestamp'`, `'untrusted'`, `'no-answer'` or `'revoked'`), and `error.details.source` names
an address that didn't answer. [Long-term validation](https://www.embedpdf.com/docs/engine/forms/signatures.md#long-term-validation)
has every field.

### When it was signed

A signature with a timestamp has a second verdict, in `verdict.timestamp`: `null` when the
signature has none. Show the time the authority vouches for when you trust it, and the signer's
own claim otherwise:

```ts
const stamp = verdict.timestamp;
const when =
  stamp?.summary === 'valid'
    ? `${stamp.stampedAt}, confirmed by ${stamp.authorityName}`
    : `${verdict.signature.signer.signedAt}, the signer's clock`;
```

A timestamp's verdict never changes the signature's `summary`: a valid signature with a broken
timestamp is still valid.

Each certificate is judged at the signature's trusted timestamp, when it has one, so a
signature whose signer's certificate has expired since still reads `'valid'`. To judge every
certificate as of now:

```ts
await signature.validate({
  validationTime: { kind: 'now' },
});
```

[The timestamp](https://www.embedpdf.com/docs/engine/forms/signatures.md#the-timestamp) has every field of the verdict, and
what this option does and doesn't check.

## Warn before an edit breaks a signature

After an approval signature, filling in the form, commenting and adding more signatures keep it
valid, as in Acrobat. Other changes break it once the file is saved, such as adding a form field. The
plugin warns you the moment a change would do that, as Acrobat does:

**`break-warning.svelte`**

```svelte
<script lang="ts">
  import { useSignature, useSignatureEvent } from '@embedpdf/svelte/signature';
  import { toast } from './toast';

  const signature = useSignature();

  useSignatureEvent(
    (s) => s.onInvalidationPredicted,
    ({ field }) => {
      const name = signature.getSignature(field)?.fieldName;
      toast(`This change will break the signature in "${name}" when saved.`);
    },
  );
</script>
```

`signature.getProtection()` tells you what the document's signatures allow, before anyone tries. A
signer who wants to rule out more, such as comments, certifies the document to allow form filling
only: the engine then refuses those changes instead of warning about them.

**`App.svelte`**

```svelte
<script lang="ts" module>
  import { DocumentGate, Viewer, type OpenInput } from '@embedpdf/svelte/runtime';
  import { Stage, stagePlugin } from '@embedpdf/svelte/stage';
  import { RenderLayer, renderPlugin } from '@embedpdf/svelte/render';
  import { interactionPlugin } from '@embedpdf/svelte/interaction';
  import { AnnotationLayer, annotationPlugin } from '@embedpdf/svelte/annotation';
  import { formPlugin } from '@embedpdf/svelte/form';
  import { signaturePlugin } from '@embedpdf/svelte/signature';
  import { localEngine } from '@embedpdf/engine';
  import WarningBar from './WarningBar.svelte';

  import '../break-warning.css';

  const engine = localEngine();

  // The certificate Lanternfield signed the agreement with, published next to it. Trusting it is
  // what makes the signature read 'valid'; your app trusts its own certificates the same way.
  const lanternfieldCertificate = async () => {
    const response = await fetch('https://www.embedpdf.com/pdfs/agreement.cer');
    return new Uint8Array(await response.arrayBuffer());
  };

  const plugins = [
    stagePlugin(),
    renderPlugin(),
    interactionPlugin(),
    annotationPlugin(),
    formPlugin(),
    signaturePlugin({ trust: { anchors: async () => [await lanternfieldCertificate()] } }),
  ];

  const agreement = async (): Promise<OpenInput> => {
    const response = await fetch('https://www.embedpdf.com/pdfs/agreement.pdf');
    return { kind: 'bytes', id: 'agreement', bytes: new Uint8Array(await response.arrayBuffer()) };
  };
</script>

<Viewer {engine} {plugins} initialDocuments={[{ source: agreement }]}>
  <DocumentGate>
    {#snippet fallback()}
      <p class="loading">Loading…</p>
    {/snippet}
    <WarningBar />
    <Stage class="stage">
      <RenderLayer />
      <AnnotationLayer />
    </Stage>
  </DocumentGate>
</Viewer>
```

**`break-warning.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --warn: #b45309;
  --warn-tint: #fffbeb;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.warning {
  flex: 1 1 100%;
  font-size: 13px;
  color: var(--warn);
  background: var(--warn-tint);
  border: 1px solid #fde68a;
  border-radius: 9px;
  padding: 8px 12px;
}

/* The pages */
.stage {
  height: 440px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`WarningBar.svelte`**

```svelte
<!-- Two edits after an approval signature: a comment keeps it valid, a new form field breaks it. -->
<script lang="ts">
  import { untrack } from 'svelte';
  import { useStage } from '@embedpdf/svelte/stage';
  import { useAnnotation } from '@embedpdf/svelte/annotation';
  import { toFieldRef, useForm, useFormState } from '@embedpdf/svelte/form';
  import { useSignature, useSignatureEvent, useSignatureState } from '@embedpdf/svelte/signature';

  // Lanternfield's signature field, signed before the agreement was sent.
  const PROVIDER = toFieldRef('provider');

  const form = useForm();
  const stage = useStage();
  const annotation = useAnnotation();
  const signature = useSignature();
  const signatureState = useSignatureState();
  const status = useFormState((formState) => formState.status);
  const signed = $derived(signatureState.signatures.find((each) => each.signed));
  let warning = $state<string | null>(null);
  let made = $state({ comment: false, field: false });

  // Where the signature is: the edits go next to it.
  function signatureWidget() {
    return form.getWidgets(PROVIDER)[0];
  }

  // On load: the signatures, in view. Nothing is changed until a button is pressed.
  let revealed = false;
  $effect(() => {
    if (status.current !== 'ready' || revealed) return;
    revealed = true;
    untrack(() => {
      const widget = signatureWidget();
      if (widget) stage.reveal(widget.page, { rect: widget.rect });
    });
  });

  // The moment a change would break a signature once it's saved, as Acrobat warns.
  useSignatureEvent(
    (plugin) => plugin.onInvalidationPredicted,
    ({ field }) => {
      const name = signature.getSignature(field)?.fieldName;
      warning = `This change will break the signature in "${name}" when saved.`;
    },
  );

  async function addComment() {
    const widget = signatureWidget();
    if (!widget) return;
    const { rect } = widget;
    await annotation.create(widget.page, {
      subtype: 'text',
      rect: { x: rect.x + rect.width + 6, y: rect.y, width: 20, height: 20 },
      contents: 'Looks good to us.',
    });
    made.comment = true;
  }

  async function addField() {
    const widget = signatureWidget();
    if (!widget) return;
    const { rect } = widget;
    await form.create({
      kind: 'text',
      name: 'purchase_order',
      widgets: [
        {
          page: widget.page,
          rect: { x: rect.x, y: rect.y + rect.height + 36, width: rect.width, height: 24 },
        },
      ],
    });
    made.field = true;
  }
</script>

<div class="toolbar">
  <button type="button" class="button" disabled={!signed || made.comment} onclick={addComment}>
    Add a comment
  </button>
  <button type="button" class="button" disabled={!signed || made.field} onclick={addField}>
    Add a form field
  </button>
  <output class="readout">
    {signed
      ? `Signed by ${signed.signer.name}: ${signed.verdict?.summary ?? 'checking…'}`
      : 'Opening…'}
  </output>
  {#if warning}<output class="warning">{warning}</output>{/if}
</div>
```

> **Try it:** Lanternfield signed this agreement before sending it. Add a comment: the signature
> stays valid. Add a form field: the warning shows before anything is saved.

## A person's signatures

A person's signature and initials are stamps, in a library of kind `'signatures'`, drawn, typed or
uploaded with the [stamp plugin](https://www.embedpdf.com/docs/headless/svelte/annotations/stamps.md):

```ts
const { library } = await stamp.createLibrary('Ada Lovelace', { kind: 'signatures' });
await stamp.createAsset({ libraryId: library.id, name: 'signature', label: 'Signature', mark: { kind: 'ink', strokes } });
await stamp.createAsset({
  libraryId: library.id,
  name: 'initials',
  label: 'Initials',
  mark: { kind: 'text', text: 'AL', fontFamily: 'times-italic' },
});
```

`useSignerRows()` lists each person with their signature and initials, for a picker. The library is
a normal PDF, so Acrobat can open it too.

## "Sign here" in a form

With the [form layer](https://www.embedpdf.com/docs/headless/svelte/forms.md), an empty signature field can be clicked. The layer draws no "sign
here" text in it: the field is a button with nothing in it, named after the field for screen readers.
Clicking it makes the field the **target**: the next mark the person picks goes there. A signed field,
clicked, asks your UI to show its details:

```ts
signature.setTarget(toFieldRef('approval')); // the next mark goes here; null clears
```

| Event                   | Fires when                                     | Show                    |
| :---------------------- | :--------------------------------------------- | :---------------------- |
| `onTargetChanged`       | A field became the target                      | your signatures panel   |
| `onSignRequested`       | In `'ask'` mode, a mark was dropped on a field | your sign dialog        |
| `onInspectionRequested` | A signed field was clicked                     | the signature's details |

## Methods

Everything `useSignature()` gives you.

| Method                                                                                            | What it does                                                                                                                                                                                                                                                                                                                     |
| :------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sign({ field, mark })`                                                                           | Signs a field: the mark becomes what it shows, and the key seals the document. Also takes `signer`, a per-call `signingKey` and `timestampAuthority`, `certify` and `lock`, and resolves `{ signature, version, protection, validationInfo, validationInfoError }`. [Sign a field](#sign-a-field)                                |
| `placeMark(mark, { field })`, `placeMark(mark, { page, center })`                                 | Does what a click with an armed mark does: in a field, signs, fills or asks, by `mode`; anywhere else, places a stamp. Resolves what it did as `kind`: `'signed'`, `'filled'`, `'requested'` or `'placed'`. [Let people click to sign](#let-people-click-to-sign)                                                                |
| `fillField(field, mark)`, `clearField(field)`                                                     | Draws a mark into a field without signing, or takes it out again. Refused on a signed field. [Fill a field without signing](#fill-a-field-without-signing)                                                                                                                                                                       |
| `prepareSignature({ field, mark })`, `completeSignature(signingId, cms)`                          | Signs in two steps: the first resolves `{ signingId, digest }` for your key to sign, the second checks what the key returned, adds the timestamp when an authority is set, and seals the document. [Signing in two steps](#signing-in-two-steps)                                                                                 |
| `cancelPending()`                                                                                 | Gives up a signature prepared in two steps, so the document can be changed again                                                                                                                                                                                                                                                 |
| `validate({ until?, validationTime? })`                                                           | Checks every signature again and resolves the verdicts. `until: 'persisted'` checks the file as it was opened; `validationTime` judges each signature at its timestamp. [Which bytes are checked](#which-bytes-are-checked), [When it was signed](#when-it-was-signed)                                                           |
| `validateField(field)`                                                                            | Checks one signed field and resolves its verdict                                                                                                                                                                                                                                                                                 |
| `addValidationInfo(field?)`                                                                       | Asks whether a signed field's certificates were good at its timestamp, stores the answers in the file, and adds a document timestamp when `documentTimestamp` is set. Without `field`, for every signature. Resolves `{ added, documentTimestamp }`. [Whether it can be checked for years](#whether-it-can-be-checked-for-years) |
| `getVerdict(field)`, `listVerdicts()`                                                             | One signed field's verdict from the last check, or every verdict; `null` before the first check. [Check the signatures](#check-the-signatures)                                                                                                                                                                                   |
| `getSignature(field)`                                                                             | One signature field's facts, signed or not, such as `fieldName`, `signed` and `signer`, or `null`                                                                                                                                                                                                                                |
| `listUnsignedFields()`                                                                            | The signature fields still to sign, in document order                                                                                                                                                                                                                                                                            |
| `analyzeChanges({ since })`                                                                       | What changed after a signature (`{ signatureIndex }`) or a version of the file (`{ revisionIndex }`), rule by rule                                                                                                                                                                                                               |
| `readRevision(field)`, `readRevision({ revisionIndex })`                                          | The exact bytes of the file version a signature covers. [The signed bytes](#the-signed-bytes)                                                                                                                                                                                                                                    |
| `setTarget(field)`                                                                                | Makes a field the target, where the next mark the person picks goes; `null` clears. ["Sign here" in a form](#sign-here-in-a-form)                                                                                                                                                                                                |
| `requestInspection(field)`                                                                        | Asks your UI to show a signed field's details, as clicking it does: `onInspectionRequested` fires                                                                                                                                                                                                                                |
| `getMode()`                                                                                       | The mode in effect: the `mode` setting, or its default. [Settings](#settings)                                                                                                                                                                                                                                                    |
| `getSnapshot()`                                                                                   | Everything at once, as the engine reads it: every signature field, signed or not, the file's versions, and `protection`                                                                                                                                                                                                          |
| `refresh()`                                                                                       | Reads the signatures again. You rarely need it: the plugin reads and checks them again after every change.                                                                                                                                                                                                                       |
| `canSign(field)`, `canCertify()`, `canFill(field)`, `canReadRevision()`, `canAddValidationInfo()` | Whether signing a field, certifying, drawing a mark into a field without signing, reading the signed bytes, and adding validation data are allowed. [Permissions](#permissions)                                                                                                                                                  |
| `getSettings()`, `updateSettings(changes)`, `resetSettings()`                                     | Reads the settings, changes them while the app runs, or goes back to what you registered. In a component, use `useSignatureSettings()`. [Settings](#settings)                                                                                                                                                                    |

`field` is a field's ref, such as `toFieldRef('approval')`; the methods that only read also take the
ref of the field's box. Every method that returns a promise also takes a `signal` in its options, to
cancel it.

## State

Everything `useSignatureState()` gives you, as one reactive object: read its fields, and your markup updates when they change. The method in the last column reads the same value once.

| Field        | What it is                                                                                                                                                       | Read once          |
| :----------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------- |
| `signatures` | The signed fields, in document order, each with its `verdict` once checked                                                                                       | `listSignatures()` |
| `protection` | What the document's signatures allow, or `null` before they're read                                                                                              | `getProtection()`  |
| `target`     | The field the next mark goes to, or `null`                                                                                                                       | `getTarget()`      |
| `busy`       | Whether a signing or a fill is running                                                                                                                           | `isBusy()`         |
| `pending`    | A signature prepared in two steps and not completed yet, as `{ signingId, field }`, or `null`. Until it's completed or cancelled, the document can't be changed. | `getPending()`     |
| `status`     | Whether the signatures are read: `'idle'`, `'loading'`, `'ready'`, `'forbidden'` or `'error'`                                                                    | `getStatus()`      |

## Settings

Set them when you register the plugin, and change them while the app runs with
`signature.updateSettings({ … })`; `signature.resetSettings()` goes back to what you registered, and
`useSignatureSettings()` gives you the current settings.

| Setting              | What it does                                                                                                             | Default                              |
| :------------------- | :----------------------------------------------------------------------------------------------------------------------- | :----------------------------------- |
| `signingKey`         | The signer, or a function that returns one when someone signs                                                            | none                                 |
| `timestampAuthority` | The timestamp authority: every signature the plugin seals carries its timestamp                                          | none                                 |
| `revocation`         | Where revocation answers come from: every signature the plugin seals gets its validation data right after. Needs `trust` | none                                 |
| `documentTimestamp`  | Add a document timestamp after the validation data. Needs `timestampAuthority`                                           | `false`                              |
| `mode`               | What a mark does in a field: `'sign'`, `'visual'` or `'ask'`                                                             | `'sign'` with a key, else `'visual'` |
| `trust`              | The certificates you trust: for checking signatures, and for the timestamps you seal                                     | none                                 |
| `allowCertify`       | Let a first signature be a certification, which sets what stays allowed                                                  | `false`                              |

## Events

**`save-warning.svelte`**

```svelte
<script lang="ts">
  import { useSignatureEvent } from '@embedpdf/svelte/signature';
  import { showWarning } from './warnings';

  useSignatureEvent(
    (signature) => signature.onInvalidationPredicted,
    () => showWarning('Saving this change will break a signature.'),
  );
</script>
```

| Event                     | Fires when                                           | Carries                       |
| :------------------------ | :--------------------------------------------------- | :---------------------------- |
| `onSigned`                | A field was signed, whoever signed it                | `field`, `result`, `origin`   |
| `onFilled`, `onCleared`   | A mark was drawn into a field, or removed            | `field`                       |
| `onValidated`             | The signatures were checked                          | `verdicts`                    |
| `onProtectionChanged`     | What the signatures allow changed                    | `protection`                  |
| `onInvalidationPredicted` | A change would break a signature once saved          | `field`, `detail`             |
| `onTargetChanged`         | A field became the target, or the target was cleared | `field` (`null` when cleared) |
| `onSignRequested`         | In `'ask'` mode, a mark was dropped on a field       | `field`, `mark`               |
| `onInspectionRequested`   | A signed field was clicked                           | `field`                       |
| `onSettingsChanged`       | The settings changed                                 | `settings`, `changedKeys`     |

`result` is the `{ signature, version, protection }` that `sign()` resolves. ["Sign here" in a form](#sign-here-in-a-form) says what to show
for the last three.

## Permissions

| Permission         | What it allows                                  | Check                              |
| :----------------- | :---------------------------------------------- | :--------------------------------- |
| `doc.sign`         | Signing                                         | `signature.canSign(field)`         |
| `doc.sign`         | Adding validation data and a document timestamp | `signature.canAddValidationInfo()` |
| `doc.sign.certify` | Signing a certification                         | `signature.canCertify()`           |
| `doc.sign`         | Drawing a mark into a field without signing     | `signature.canFill(field)`         |
| `doc.download`     | Reading the exact bytes a signature covers      | `signature.canReadRevision()`      |

A mark in a signature field is its signer's to place, so drawing one takes what signing takes. A user
with a `fields:sign` permission for one group signs that group's fields only, and draws marks only into
them, so the checks take the field. See [Signers and groups](https://www.embedpdf.com/docs/engine/forms/groups.md). On a
signed document, the engine also refuses what its signatures forbid.

## Good to know

### Which bytes are checked

The plugin checks the document as it is in the viewer, with changes that haven't been downloaded yet,
so the verdict is the one the downloaded file will get. `validate({ until: 'persisted' })` checks the
file as it was opened.

### The signed bytes

`signature.readRevision({ revisionIndex })` gives you the exact version of the file a signature
covers, for an audit trail.

> How signatures are stored, and what each certification allows, is on
> [Digital signatures](https://www.embedpdf.com/docs/engine/forms/signatures.md).
