Countersign.Config (Countersign v0.1.0)

Copy Markdown View Source

Everything Countersign needs from its host, passed to every call.

A host builds it in one function at its boundary and passes it on; Countersign itself reads no application or OS environment and keeps no global state of its own.

def config do
  Countersign.Config.new!(
    repo: MyApp.Repo,
    host: MyApp.Signing.Host,
    signable: MyApp.Signing.Signable,
    delivery: MyApp.Signing.Delivery,
    base_url: MyAppWeb.Endpoint.url(),
    secret_key_base: MyAppWeb.Endpoint.config(:secret_key_base)
  )
end

:disclosure is the electronic-records disclosure a signer accepts before signing: %{version: pos_integer, text: String.t} (an optional :sha256 must match the text). Left out, it is Countersign.Disclosure.default/0; nil turns consent off, and then nothing can be signed.

:signature_pad, when given, is {module, function}: a function component the signing page renders, with an :id assign, to capture a drawn signature. It must push "signature_captured" with %{"image_data" => "data:image/png;base64,..."}. Left out, the page offers a typed signature only.

:sign_path, default "/sign", is where the host mounts the signing page; a link is base_url <> sign_path <> "/" <> token.

:session_key, default "countersign", is the session key Countersign.Web.LinkController keeps a verified code under.

:client_ip_session_key, when given, is the session key under which the host's own plug keeps the signer's client IP, derived from a header the host's proxy sets and a client cannot forge. The signing page records that IP when the session holds one, and the socket's peer address otherwise. A page served behind a proxy needs it: the peer there is the proxy.

:code_worker, when given, is a module that uses Countersign.Workers.Code: Countersign.Requests.request_code/2 then enqueues the code's delivery on :oban (default Oban) in the transaction that wrote the code, instead of delivering it in the caller's process.

:certificate_worker, when given, is a module that uses Countersign.Workers.Certificate: Countersign.Requests.sign/3 then enqueues the signing certificate on :oban in the sign transaction.

Summary

Functions

The callbacks of behaviour that module does not export, as name/arity strings.

Builds and validates a config from a keyword list or map.

Types

disclosure()

@type disclosure() :: %{version: pos_integer(), text: String.t(), sha256: String.t()}

t()

@type t() :: %Countersign.Config{
  base_url: String.t(),
  certificate_worker: module() | nil,
  client_ip_session_key: String.t() | nil,
  code_worker: module() | nil,
  delivery: module(),
  disclosure: disclosure() | nil,
  host: module(),
  oban: Oban.name(),
  repo: module(),
  secret_key_base: String.t(),
  session_key: String.t(),
  sign_path: String.t(),
  signable: module(),
  signature_pad: {module(), atom()} | nil
}

Functions

missing_callbacks(module, behaviour)

@spec missing_callbacks(module(), module()) :: [String.t()]

The callbacks of behaviour that module does not export, as name/arity strings.

new!(opts)

@spec new!(keyword() | map()) :: t()

Builds and validates a config from a keyword list or map.

Raises ArgumentError naming any missing key, any unknown key, a module that cannot be loaded or does not export every callback of its behaviour, a repo that is not an Ecto.Repo, a base_url that is not an absolute http(s) URL, a secret_key_base shorter than 64 bytes, a malformed :disclosure, or a :sign_path that is not an absolute path.