# `Countersign.Certificate`
[🔗](https://github.com/mkreyman/countersign/blob/v0.1.0/lib/countersign/certificate.ex#L1)

The signing certificate: one page saying who signed what, proven how, and
when, built from the signed request and two labels the host gives
(`c:Countersign.Signable.type_label/1` and
`c:Countersign.Signable.role_label/2`).

It holds the agency, the subject's kind and id, the content hash the
signature was taken against, the signer's name as signed, role and
relationship, the delivery channel and the address hint, the first send
and every resend, every code verification, the consent version and the
disclosure's hash, the time of signing, the method, the signer's IP
address and user agent, and the host's signature reference. It holds no
address, no signature image and nothing of the subject's content.

`html/4` builds a self-contained page (its CSS inline, nothing fetched);
`render/3` turns it into a PDF through `c:Countersign.Host.html_to_pdf/1`.
`Countersign.Workers.Certificate` renders and stores it.

## Options

  * `:time_zone` - a time zone name; each time is then shown in it as
    well as in UTC. Shifting needs the host's time zone database
    (`Calendar.put_time_zone_database/1`). Default: UTC only.

# `facts`

```elixir
@type facts() :: %{
  agency: String.t(),
  type_label: String.t(),
  subject_id: String.t(),
  content_sha256: String.t(),
  signer_name: String.t(),
  role_label: String.t(),
  relationship: String.t() | nil,
  delivery_channel: atom(),
  to_hint: String.t(),
  sent_at: DateTime.t(),
  resent_times: [DateTime.t()],
  unrecorded_resends: non_neg_integer(),
  last_sent_at: DateTime.t() | nil,
  verified_times: [DateTime.t()],
  consent_version: pos_integer() | nil,
  consent_sha256: String.t() | nil,
  signed_at: DateTime.t(),
  sign_method: :drawn | :typed | nil,
  sign_ip: String.t() | nil,
  sign_user_agent: String.t() | nil,
  signature_ref: String.t()
}
```

The facts the page shows.

# `facts`

```elixir
@spec facts(
  Countersign.Config.t(),
  Countersign.Request.t(),
  Countersign.Signable.subject()
) :: facts()
```

The facts of a signed `request` on `subject`.

# `html`

```elixir
@spec html(
  Countersign.Config.t(),
  Countersign.Request.t(),
  Countersign.Signable.subject(),
  keyword()
) ::
  iodata()
```

The certificate of a signed `request` on `subject`, as a self-contained HTML page.

# `render`

```elixir
@spec render(Countersign.Config.t(), Countersign.Request.t(), keyword()) ::
  {:ok, binary()} | {:error, :not_found | term()}
```

The certificate of a signed `request` as a PDF: the subject fetched in the
request's scope, the page built by `html/4` and rendered by the host.
Answers `{:error, :not_found}` when the subject is gone and the host's
error when rendering fails.

# `render`

```elixir
@spec render(
  Countersign.Config.t(),
  Countersign.Request.t(),
  Countersign.Signable.subject(),
  keyword()
) ::
  {:ok, binary()} | {:error, term()}
```

As `render/3`, for a `subject` the caller has already fetched.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
