.nib std
nib 0.3.0

module always in scope

Secret

A credential a program can use but never print or render, and which a journal records by label only. Secret.reveal is the one way the value comes out, spelled where a reader can see it.

A Secret holds a value like an API key or a bearer token: something the program needs to use and must never write down. It carries a label, which says what it is and is not secret, and the value. You can pass a secret around, store it in a record and hand it to an effector, but you cannot print it: a splice ("{key}") is a type error, Json.render refuses it, and a test or --run that answers one prints Secret(LABEL).

let key = Secret.of("API_KEY", "sk-0123");
(Secret.label(key), String.length(Secret.reveal(key)))
("API_KEY", 7)

Most secrets come from the environment rather than from source: @Env.Secrets.secret("OPENROUTER_KEY") answers one labelled with the variable's name (see Env.Secrets).

What a journal records

What is guaranteed: a recorded run (--journal-out) writes a Secret as its label alone, {"secret":"API_KEY"}, and never its value. A replay (--journal-in) therefore has the label and not the value: the secret comes back hollow, and revealing it answers the marker «secret:API_KEY». A replay cannot reproduce a computation over the secret's actual bytes, such as its length, because it never has them.

What is best-effort: once revealed, the value is an ordinary String, and it can reach a file or a socket the journal records. The journal remembers every value reveal handed out in the run and writes «secret:API_KEY» wherever those exact bytes appear in what it records. When the revealed text is written as is, that keeps it out of the journal, and a replay's entries match the recording's. It is matching by content, not by origin: nothing tracks where a string came from. So it is a safety net, not a guarantee. Text derived from the value in any other form gets through: base64 (an HTTP Basic header), a hash, a change of case, a URL-encoding, a slice, or the value split across two writes. And any other text that happens to contain the same bytes is masked too, which makes a short or common secret (admin, 1) a poor fit.

Across System.Remote

A secret is data a remote interface may carry. The daemon receives the value, because a credential store or a signing proxy needs it, while the journal of the same call still records only the label.

Functions

funcof
func of :: String, String -> Secret

Wraps a value the program already has, under a label. The label is what a journal, a diagnostic and Secret.label will show.

Secret.label(Secret.of("DB_PASSWORD", "correct horse"))
DB_PASSWORD
funclabel
func label :: Secret -> String

The secret's label: what it is, never what it holds.

Secret.label(Secret.of("TOKEN", "abc"))
TOKEN
funcreveal
func reveal :: Secret -> String

The value, as a String. This is the one way out of a secret, and it is named so a reader can find every place a credential leaves its wrapper, typically where a header is built:

let key = Secret.of("API_KEY", "sk-0123");
"Authorization: Bearer " ++ Secret.reveal(key)
Authorization: Bearer sk-0123

Past this point the value is a plain String: the type system no longer knows it is secret. A journal masks the exact revealed bytes wherever it records them (see "What a journal records" above), but not an encoding or a transformation of them, so reveal as late as you can, right where the value is sent. On a journal replay the secret is hollow, and reveal answers the marker «secret:LABEL».