[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Redacted](https://evolu.dev/docs/api-reference/common/Redacted) › Redacted

Defined in: [packages/common/src/Redacted.ts:77](https://github.com/evoluhq/evolu/blob/4eedb2272841bdeb2d7c3387784ba157d2f33f1c/packages/common/src/Redacted.ts#L77)

A wrapper type that prevents sensitive values from being accidentally exposed
through logging, serialization, or inspection.

The wrapped value is hidden and can only be accessed explicitly via
[revealRedacted](https://evolu.dev/docs/api-reference/common/Redacted/functions/revealRedacted). All standard methods (`toString`, `toJSON`, and
Node.js inspect) return `<redacted>`.

For type-level distinction between different secrets, use branded types.

Redacted guards against accidental exposure, such as logs, error reports, and
serialized payloads. It does not hide the value from a debugger: DevTools and
heap snapshots can still reach it.

A structured clone, such as a `postMessage` to a worker, does not copy the
hidden value and arrives as an empty object. Reveal the value before posting
it, and wrap it again on arrival if the receiver passes it to app code.

A wrapper equals only itself and has no hash, so neither can expose the
value. Two wrappers of the same value are not equal; compare revealed values
instead.

Implements `Disposable`, so the `using` syntax detaches the value when the
scope ends. Disposal does not overwrite the value or release other references
to it.

### Example

```ts
import {
  assertErr,
  assertEqual,
  createRedacted,
  revealRedacted,
  trySync,
  type Brand,
  type Redacted,
} from "@evolu/common";

type ApiKey = string & Brand<"ApiKey">;
type DbPassword = string & Brand<"DbPassword">;
type RedactedApiKey = Redacted<ApiKey>;

// Apply brands only after validation or at another trusted boundary.
const apiKey: ApiKey = "secret-123" as ApiKey;
using redactedKey: RedactedApiKey = createRedacted(apiKey);
const fetchUser = (key: RedactedApiKey): ApiKey => revealRedacted(key);

assertEqual(redactedKey.toString(), "<redacted>");
assertEqual(JSON.stringify({ apiKey: redactedKey }), '{"apiKey":"<redacted>"}');
assertEqual(fetchUser(redactedKey), apiKey);

using password = createRedacted("password" as DbPassword);
// @ts-expect-error Redacted secrets retain their distinct branded types.
fetchUser(password);

const disposedKey = (() => {
  using key = createRedacted(apiKey);
  return key;
})();
// Leaving the `using` scope detaches the value, so revealing it throws.
assertErr(trySync(() => revealRedacted(disposedKey)));
```

## Extends

- [`Brand`](https://evolu.dev/docs/api-reference/common/Brand/interfaces/Brand)\<`"Redacted"`\>
- [`Disposable`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management)

## Methods

<a id="dispose"></a>

### \[dispose\]()

```ts
[dispose](): void;
```

Defined in: node\_modules/@typescript/old/lib/lib.esnext.disposable.d.ts:34

#### Inherited from

`Disposable.[dispose]`

## Properties

<a id="___brand"></a>

### \[\_\_\_brand\]

```ts
readonly [___brand]: Readonly<Record<B, true>>;
```

Defined in: [packages/common/src/Brand.ts:76](https://github.com/evoluhq/evolu/blob/4eedb2272841bdeb2d7c3387784ba157d2f33f1c/packages/common/src/Brand.ts#L76)

#### Inherited from

[`Brand`](https://evolu.dev/docs/api-reference/common/Brand/interfaces/Brand).[`[___brand]`](/docs/api-reference/common/Brand/interfaces/Brand#___brand)

---

<a id="tojson"></a>

### toJSON

```ts
readonly toJSON: () => "<redacted>";
```

Defined in: [packages/common/src/Redacted.ts:84](https://github.com/evoluhq/evolu/blob/4eedb2272841bdeb2d7c3387784ba157d2f33f1c/packages/common/src/Redacted.ts#L84)

---

<a id="tostring"></a>

### toString

```ts
readonly toString: () => "<redacted>";
```

Defined in: [packages/common/src/Redacted.ts:83](https://github.com/evoluhq/evolu/blob/4eedb2272841bdeb2d7c3387784ba157d2f33f1c/packages/common/src/Redacted.ts#L83)

Returns a string representation of an object.

---

<a id="type"></a>

### Type

```ts
readonly Type: A;
```

Defined in: [packages/common/src/Redacted.ts:82](https://github.com/evoluhq/evolu/blob/4eedb2272841bdeb2d7c3387784ba157d2f33f1c/packages/common/src/Redacted.ts#L82)

The inner type. This is a type-only phantom property. Use it through
`typeof redacted.Type`; it does not exist at runtime.