# `SquatchMail.PublicId`
[🔗](https://github.com/Axio-Intelligence/Squatch-Mail/blob/v0.1.1/lib/squatch_mail/public_id.ex#L1)

Generates prefixed, URL-safe public identifiers backed by random bytes.

SquatchMail rows use opaque `bigserial` primary keys internally, but expose a
stable, non-enumerable `public_id` (e.g. `"em_4f9Kd2..."`) in URLs and APIs so
that internal row counts never leak. The random suffix is a base62 encoding of
cryptographically strong random bytes, keeping ids short and copy/paste-safe
(no `-`, `_`, `+`, or `/`).

This module has no external dependencies; it relies only on
`:crypto.strong_rand_bytes/1`.

# `encode`

```elixir
@spec encode(binary()) :: String.t()
```

Encodes a binary as a base62 string. An all-zero binary encodes to `"0"`.

# `generate`

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

Generates a prefixed public id, e.g. `generate("em")` => `"em_9aXd2Kf..."`.

`bytes` controls the amount of entropy (default 16 bytes / 128 bits).

# `random_base62`

```elixir
@spec random_base62(pos_integer()) :: String.t()
```

Returns a base62 string derived from `bytes` cryptographically random bytes.

Useful for opaque tokens (e.g. per-source webhook tokens) that don't need a
human-facing prefix.

---

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