TestCrypto unstable
Provides a deterministic implementation of the Effect Crypto service for
tests.
Random bytes, numbers, shuffles, UUIDs, and ULIDs are derived from a seeded
pseudo-random generator. Digest operations are delegated to an underlying
platform Crypto service.
Constructors
Creates a deterministic Crypto service using a seeded pseudo-random
generator.
When to use
Use to construct a Crypto service whose random operations are reproducible
in tests while preserving the digest implementation of a platform Crypto
service.
Details
The effect requires an existing Crypto service and delegates digest
operations to it. Each evaluation starts a new random sequence from seed;
every other random operation is derived from that sequence.
Gotchas
The generated values are deterministic and must not be used for
security-sensitive purposes. The sequence depends on the order in which
random operations are evaluated. UUIDv7 and ULID values also include the
current Clock time, which must be controlled separately when their complete
output needs to be reproducible.
See
- layer for providing the service as a layer
Signature
declare const make: (seed: string | number) => Effect.Effect<Crypto.Crypto, never, Crypto.Crypto>Layers
Creates a layer that provides deterministic Crypto random operations from
a seed.
When to use
Use to provide reproducible random bytes, numbers, shuffles, UUIDs, and ULIDs to an Effect program under test.
Details
The layer requires an existing platform Crypto service whose digest
implementation is retained. Each layer build starts the random sequence from
seed.
Gotchas
UUIDv7 and ULID values also depend on the current Clock. Provide a test
clock when their complete output needs to be reproducible.
See
- make for constructing the service directly
Signature
declare function layer(seed: string | number): Layer<Crypto, never, Crypto>