Skip to content

State.passphraseEncryption reference

Source: src/State/PassphraseEncryption.ts Kind: Layer · Provides: StateEncryption

Encrypt the secrets in any state store with a passphrase.

Each secret (a Redacted value: a minted token, a Random value) is encrypted with AES-256-GCM under a data key before the store writes it, so the store only ever holds ciphertext. The data key is wrapped with a key derived from the passphrase by scrypt, and bound to its stack and stage. A deploy derives one key per stage it writes, so the cost doesn’t grow with the number of secrets.

Whoever has the passphrase can read every secret, and losing it loses them, so keep it in a secret manager and hand it to deploys as a secret. A key service such as AWS KMS (AWS.stateEncryption()) avoids sharing a passphrase at all: access is an IAM grant, can be scoped to one stage, and is logged.

passphraseEncryption: Encrypting with a Passphrase

Section titled “passphraseEncryption: Encrypting with a Passphrase”

Cloudflare state, passphrase from ALCHEMY_STATE_PASSPHRASE

import { passphraseEncryption } from "alchemy/State/PassphraseEncryption";
state: Cloudflare.state().pipe(Layer.provide(passphraseEncryption())),

Passphrase from another config key

state: localState().pipe(
Layer.provide(passphraseEncryption({ passphrase: Config.Redacted("STATE_KEY") })),
),