Saltearse al contenido

cli/utils/user-utils

Esta página aún no está disponible en tu idioma.

Defined in: studiocms/packages/studiocms/src/cli/utils/user-utils.ts:126^

The Scrypt class provides a service for securely hashing passwords using the scrypt algorithm. It is implemented as an Effect service and depends on the ScryptConfig configuration layer.

The service exposes a function that takes a password as input and returns a derived key as a Buffer. The hashing process is asynchronous and uses the Effect framework for error handling and logging.

  • ScryptConfig.Layer: Provides the configuration for the scrypt algorithm, including salt, key length, and options.
  • Logs are generated using the genLogger and pipeLogger utilities for tracing the execution flow.
  • If an error occurs during the hashing process, it is wrapped in a ScryptError and handled using the Effect.fail mechanism.

Scrypt

studiocms/lib/auth/utils/scrypt

  • any

new Scrypt(): Scrypt

Scrypt

Effect.Service<Scrypt>()('studiocms/cli/utils/user-utils.Scrypt', {
effect: genLogger('studiocms/cli/utils/user-utils.Scrypt.effect')(function () {
const { salt, keylen, options } = yield ScryptConfig;
const run = (password: string) =>
pipeLogger('studiocms/cli/utils/user-utils.Scrypt.Default')(
Effect.async<Buffer, ScryptError>((resume) => {
const req = scrypt(password, salt, keylen, options, (error, derivedKey) => {
if (error) {
const toFail = new ScryptError({ error });
resume(errorTap(Effect.fail(toFail), toFail));
} else {
resume(Effect.succeed(derivedKey));
}
});
return req;
})
);
return { run };
}),
dependencies: [ScryptConfig.Layer],
}).constructor

Defined in: studiocms/packages/studiocms/src/cli/utils/user-utils.ts:84^

Represents the configuration for the Scrypt encryption algorithm. This class extends a tagged context to provide a strongly-typed configuration for Scrypt-based encryption within the StudioCMS application.

The type of the configuration class.

The type of the configuration options.

  • any

new ScryptConfig(): ScryptConfig

ScryptConfig

Context.Tag('studiocms/lib/auth/utils/scrypt/ScryptConfig')<
ScryptConfig,
ScryptConfigOptions
>().constructor

static Layer: any;

Defined in: studiocms/packages/studiocms/src/cli/utils/user-utils.ts:88^

A static property that provides a pre-configured ScryptConfig instance using the provided encryption key and Scrypt options.

The configuration includes:

  • salt: A unique encryption key (CMS_ENCRYPTION_KEY) used for hashing.
  • keylen: The length of the derived key (default is 64 bytes).
  • options: An object containing Scrypt-specific parameters:
    • N: CPU/memory cost parameter (SCRYPT_N).
    • r: Block size parameter (SCRYPT_R).
    • p: Parallelization parameter (SCRYPT_P).

Defined in: studiocms/packages/studiocms/src/cli/utils/user-utils.ts:29^

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.

The shape of the additional error context.

  • any

new ScryptError(): ScryptError

ScryptError

Data.TaggedError('ScryptError')<{ error: Error }>.constructor

function hashPassword(password: string, _salt?: string): any

Defined in: studiocms/packages/studiocms/src/cli/utils/user-utils.ts:157^

Hashes a plain text password using script.

string

The plain text password to hash.

string

any

A promise that resolves to the hashed password.