UNPKG

@withstudiocms/effect

Version:

Effect-TS Utilities for Astro

92 lines (91 loc) 3.5 kB
import { type BinaryLike, type ScryptOptions } from 'node:crypto'; import { Brand, Context, Effect, Layer } from './effect.js'; declare const ScryptError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "ScryptError"; } & Readonly<A>; /** * Represents an error specific to the Scrypt operation. * * This class extends a tagged error to provide additional context * about errors that occur during Scrypt-related operations. * * @extends Data.TaggedError */ export declare class ScryptError extends ScryptError_base<{ error: Error; }> { } /** * Configuration options for the Scrypt key derivation function. * * @remarks * This type is branded to ensure type safety and prevent accidental misuse. * * @property encryptionKey - The secret key used for encryption. * @property keylen - The desired length of the derived key in bytes. * @property options - Additional options for the Scrypt algorithm. */ export type ScryptConfigOptions = { encryptionKey: BinaryLike; keylen: number; options: ScryptOptions; } & Brand.Brand<'ScryptConfigOptions'>; /** * Represents the configuration options for the Scrypt algorithm. * This is a nominal type to ensure type safety when working with Scrypt configurations. * * @remarks * The `Brand.nominal` utility is used to create a unique type that cannot be * accidentally substituted with other types, even if they have the same structure. * * @example * ```typescript * const config: ScryptConfigOptions = { * encryptionKey: 'my-secret-key', * keylen: 64, * options: { N: 16384, r: 8, p: 1 }, * }; * ``` */ export declare const ScryptConfigOptions: Brand.Brand.Constructor<ScryptConfigOptions>; declare const ScryptConfig_base: Context.TagClass<ScryptConfig, "ScryptConfig", ScryptConfigOptions>; /** * Context for Scrypt configuration. * * This context holds the Scrypt configuration options and provides a way to access them * throughout the application. * * @extends Context.Tag * @template {ScryptConfig} - The type of the context. */ export declare class ScryptConfig extends ScryptConfig_base { static Make: (opts: ScryptConfigOptions) => Layer.Layer<ScryptConfig, never, never>; } declare const Scrypt_base: Effect.Service.Class<Scrypt, "Scrypt", { readonly effect: Effect.Effect<{ run: (password: BinaryLike) => Effect.Effect<Buffer<ArrayBufferLike>, ScryptError, never>; }, never, ScryptConfig>; }>; /** * Scrypt service for key derivation. * * This service provides methods to derive keys using the Scrypt algorithm. * It uses the configuration provided by the ScryptConfig context. * * @extends Effect.Service * @template {Scrypt} - The type of the service. */ export declare class Scrypt extends Scrypt_base { /** * This is used to create a configuration layer for the Scrypt service. */ static makeConfig: (opts: ScryptConfigOptions) => Layer.Layer<ScryptConfig, never, never>; /** * Creates a live instance of the Scrypt service with the specified configuration options. * * @param opts - The configuration options for the Scrypt service. * @returns Layer that provides the Scrypt service with the specified configuration. */ static makeLive: (opts: ScryptConfigOptions) => Layer.Layer<Scrypt, never, never>; } export {};