Skip to content
// EFFECT DAYS 2026

WebCrypto unstable

The WebCrypto Crypto object that the effect/crypto modules run on.

The layerWebCrypto layers of the family modules, such as Digest.layerWebCrypto, and key functions that touch crypto.subtle, such as Mac.toBytes, read the WebCrypto reference. It defaults to globalThis.crypto. Provide layer to run them on a polyfill, a worker's object, or a test double.

Gotchas

Browsers expose crypto.subtle only in secure contexts. Elsewhere, every operation that needs it dies with "crypto.subtle is unavailable". Layers still build, and SecureRandom and the pure TypeScript algorithms, such as MD5, keep working.

3 exports Since v4.0.0 Source

Layers

layer

unstable
Since v4.0.0

Layer that sets the WebCrypto reference.

When to use

Use to run the effect/crypto modules on a polyfill, a worker's Crypto object, or a test double.

Signature

declare function layer(crypto: Crypto): Layer<never>

Example

import { Effect } from "effect"
import { Digest, WebCrypto } from "effect/crypto"
const program = Effect.gen(function*() {
const digest = yield* Digest.Digest
return yield* digest.digestHex(Digest.sha256, new TextEncoder().encode("abc"))
}).pipe(Effect.provide(Digest.layerWebCrypto))
const hex = await Effect.runPromise(program.pipe(Effect.provide(WebCrypto.layer(globalThis.crypto))))
hex.length // => 64

Models

CryptoKey

interface unstable
Since v4.1.1

A WebCrypto CryptoKey, declared structurally so the effect declarations type-check without the DOM library and with any @types/node version. Keys from crypto.subtle and Node's webcrypto are assignable to it.

Signature

interface CryptoKey {
readonly algorithm: {
readonly name: string;
};
readonly extractable: boolean;
readonly type: "secret" | "public" | "private";
readonly usages: readonly Array<string>;
}

References

WebCrypto

unstable
Since v4.0.0

Reference to the WebCrypto Crypto object, defaulting to globalThis.crypto.

See

Signature

declare const WebCrypto: Context.Reference<Crypto>