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

A signing code (`signing_codes`): a six-digit one-time code sent to the
address the link went to.

The code is stored as a Bcrypt hash (`code_hash`) and, encrypted, as
`code_ciphertext`, so it never travels in clear through job arguments. It
expires 10 minutes after it is issued and allows `max_attempts/0`
guesses, each spent by a conditional UPDATE before Bcrypt runs.

# `t`

```elixir
@type t() :: %Countersign.Code{
  __meta__: term(),
  attempts: non_neg_integer() | nil,
  channel: :email | :sms | nil,
  code_ciphertext: binary() | nil,
  code_hash: String.t() | nil,
  consumed_at: DateTime.t() | nil,
  expires_at: DateTime.t() | nil,
  id: Ecto.UUID.t() | nil,
  inserted_at: DateTime.t() | nil,
  signing_request: term(),
  signing_request_id: Ecto.UUID.t() | nil,
  updated_at: DateTime.t() | nil
}
```

# `generate`

```elixir
@spec generate() :: String.t()
```

A uniformly random six-digit code, `"000000"` to `"999999"`.

Drawn by rejection sampling from 24 random bits, so no value is more
likely than another (a plain `rem` over 2^24 would favour the low values).

# `max_attempts`

```elixir
@spec max_attempts() :: pos_integer()
```

Guesses allowed per code.

# `ttl_seconds`

```elixir
@spec ttl_seconds() :: pos_integer()
```

Seconds a code stays valid after it is issued.

---

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