Skip to content

Redacted

Redacted wraps sensitive values so string conversion, JSON serialization, and inspection print "<redacted>" instead of the secret. Wrap credentials, tokens, and API keys at the entry boundary to prevent accidental logging while keeping deliberate retrieval explicit.

APIPurpose
Redacted.make(secret)Wrap a value so String, JSON.stringify, and inspect render "<redacted>"
Redacted.value(wrapped)Extract the raw payload (throws after wiping)
Redacted.wipeUnsafe(wrapped)Clear the wrapper's reference to the payload
Redacted.makeEquivalence(eq)Lift an Equivalence to compare wrapped payloads without printing them

Wrapping sensitive values

const exampleKey = Redacted.make("example-key-not-a-real-secret")
String(exampleKey) // "<redacted>"
 
effect function reportConfiguration() {
  try Console.log(try Effect.try(() => JSON.stringify({ apiKey: exampleKey })))
}
// Run in an effect function:
//   try Console.log(String(exampleKey))
//   try reportConfiguration()
//   try Console.log(try Effect.try(() => JSON.stringify(exampleKey)))
<redacted>
{"apiKey":"<redacted>"}
"<redacted>"

Redacted.make hides the payload from casual formatting and serialization, but it is not encryption—any code holding the wrapper can still read it. Wrap secrets as soon as they enter the program, before telemetry or diagnostics can observe them.

Revealing values deliberately

service CredentialsClient {
  authenticate(token: string): boolean!!
}
 
effect function authenticate(secret: string) {
  const client = try CredentialsClient
  const token = Redacted.make(secret)
  const raw = try Effect.try(() => Redacted.value(token))
  return try client.authenticate(raw)
}
// boolean!Cause.UnknownError!CredentialsClient
// Run in an effect function: provide Layer.succeed(CredentialsClient, { authenticate: (token) => succeed(token === "example-token") }) { try Console.log(try authenticate("example-token"), try authenticate("wrong-token")) }
true false

Call Redacted.value only at the point where the raw secret is required. Once extracted, the plain string is unprotected—keep it out of error payloads, log annotations, and returned diagnostics.

Wiping stored secrets

effect function useOnce(raw: string) {
  const client = try CredentialsClient
  const token = Redacted.make(raw)
  return try ensuring(
    effect {
      const value = try Effect.try(() => Redacted.value(token))
      return try client.authenticate(value)
    },
    sync(() => Redacted.wipeUnsafe(token))
  )
}
// Run in an effect function:
//   provide Layer.succeed(CredentialsClient, { authenticate: (token) => succeed(token === "example-token") }) { try Console.log(try useOnce("example-token")) }
//   const wiped = Redacted.make("example-token")
//   Redacted.wipeUnsafe(wiped)
//   const failed = try exit(Effect.try(() => Redacted.value(wiped)))
//   try Console.log(Exit.isFailure(failed), String(wiped))
true
true <redacted>

Redacted.wipeUnsafe clears the wrapper's internal reference so subsequent Redacted.value calls throw; pairing it with ensuring guarantees cleanup on success, failure, and interruption. Wiping drops only the wrapper's reference—it cannot zero out the caller's original string or copies already held elsewhere in memory.

Comparing protected values

const same = Redacted.makeEquivalence(Equivalence.String)
const first = Redacted.make("example-a")
const second = Redacted.make("example-a")
const third = Redacted.make("example-b")
same(first, second) // true
same(first, third) // false
// Run in an effect function: try Console.log(same(first, second), same(first, third))
true false

Redacted.makeEquivalence compares wrapped values before wiping without printing either payload. The comparison is not constant-time—use dedicated cryptographic primitives for secret verification against timing attacks.


The matching Effect page: effect.website/docs/v4/data-types/redacted