> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Secrets and keys

> Sealed values an operator sets, which only performers open, and host-held signing keys.

A secret is a sealed value an operator sets. Code never holds its clear value:
only a performer opens it, when it sends a task. Declare one with `secret()`
and place it in the app tree; its path is its name.

```ts bijection/crm.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { http, label, secret, t, target } from "@bijectionhq/bijection";

export const apiKey = secret();

export const createContact = target({
  label: label.public,
  via: http("https://api.crm.example/contacts", { bearer: apiKey }),
  args: { email: t.string },
  returns: { id: t.string },
  within: { minutes: 10 },
});
```

Set the value with the CLI. It reads the value from standard input or
`--from-file`, never from an argument, and setting it again rotates it:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
printf %s "$CRM_TOKEN" | bijection secret set crm.apiKey
```

A secret is used as:

* `http(url, { bearer })`, sent as `Authorization: Bearer <secret>`;
* a receiver's auth, for the [integrations](https://docs.bijection.com/integrations);
* a route verifier, `verifier.bearer(secret)` (see [Reactions](https://docs.bijection.com/functions/reactions.md#verify-a-route)).

## One value per member

`secret({ under: family })` holds one value per member of a
[family](https://docs.bijection.com/database/family-tables.md): each tenant's own credential.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export const tenantKey = secret({ under: tenant });
```

An operator sets one member's value with
`bijection secret set billing.tenantKey/acme`. For a mutation that accepts a
credential, declare its argument as `t.credential`. The caller supplies a
string. The host seals it before the handler runs, and the handler receives
a `Sealed<string>` it can store with `ctx.put(tenantKey.of(member), apiKey)`
under that member's label.

`ctx.retract(tenantKey.of(member))` removes the value.
`ctx.has(tenantKey.of(member))` checks whether a value is sealed. A send
presents the value of the member its task's label names.

## Keys

A key is a secret declared with its algorithm and uses, `secret({ alg, uses })`. The head
signs with `ed25519`, `rs256` and `es256` keys and computes MACs with
`hmac-sha256` keys. Key material stays in the host.

```ts bijection/receipts.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { secret } from "@bijectionhq/bijection";
import { verify } from "@bijectionhq/library-keys";

export const receipts = secret({ alg: "ed25519" });

const signature = await ctx.get(receipts.sign(payload));
const valid = await verify(ctx, receipts, payload, presented); // presented: Uint8Array
const jwks = await ctx.get(receipts.publicJwk);
```

Set the key with `bijection secret set receipts --alg ed25519`. At a branch
or a retained version, signing and MAC reads produce a deterministic trial
artifact. `publicJwk` returns `{ keys }` for the world's Version, with the
current signing key first and each unretired key identified by its `kid`.
Rotating at the same label and algorithm keeps the previous public key valid.
Run `bijection secret list` to find its `kid`, then retire it with
`bijection secret remove receipts --kid <kid>`. Removing the secret without
`--kid` withdraws the entire set at that Version.

Check a MAC with `ctx.get(key.equal({ mac: data, tag }))`, where `tag` is a
`Uint8Array`. MAC keys default to `uses: ["equal"]`. Add `"mac"` to
issue tags. Signing keys default to `["sign", "publicJwk"]`. The Program
carries these uses. `bijection secret set` supplies the material for the
declared algorithm. The kernel computes the expected tag through custody
using the real key at the world's Version, compares in constant time and
returns only a boolean. For signatures, `verify` checks against the public
keys valid at that Version. Trial artifacts are publicly computable and
never verify.
`@bijectionhq/library-keys` also provides `isTrialSignature`, `signJwt` and
`verifyJwt`, which ignores a token's trial mark and checks it against the
real key. To sign what a task sends, declare signing on its receiver so
the host signs at dispatch.

For configuration that is not secret, see
[Environment variables](https://docs.bijection.com/operate/configuration/environment-variables.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.