cli/utils/user-utils
Esta página aún no está disponible en tu idioma.
Classes
Section titled “Classes”Scrypt
Section titled “Scrypt”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.
Dependencies
Section titled “Dependencies”ScryptConfig.Layer
: Provides the configuration for the scrypt algorithm, including salt, key length, and options.
Logging
Section titled “Logging”- Logs are generated using the
genLogger
andpipeLogger
utilities for tracing the execution flow.
Errors
Section titled “Errors”- If an error occurs during the hashing process, it is wrapped in a
ScryptError
and handled using theEffect.fail
mechanism.
Scrypt
Template
Section titled “Template”Memberof
Section titled “Memberof”studiocms/lib/auth/utils/scrypt
Extends
Section titled “Extends”any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Scrypt(): Scrypt
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”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
ScryptConfig
Section titled “ScryptConfig”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.
Template
Section titled “Template”The type of the configuration class.
Template
Section titled “Template”The type of the configuration options.
Extends
Section titled “Extends”any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ScryptConfig(): ScryptConfig
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Context.Tag('studiocms/lib/auth/utils/scrypt/ScryptConfig')< ScryptConfig, ScryptConfigOptions>().constructor
Properties
Section titled “Properties”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
).
ScryptError
Section titled “ScryptError”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.
Template
Section titled “Template”The shape of the additional error context.
Extends
Section titled “Extends”any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ScryptError(): ScryptError
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Data.TaggedError('ScryptError')<{ error: Error }>.constructor
Functions
Section titled “Functions”hashPassword()
Section titled “hashPassword()”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.
Parameters
Section titled “Parameters”password
Section titled “password”string
The plain text password to hash.
_salt?
Section titled “_salt?”string
Returns
Section titled “Returns”any
A promise that resolves to the hashed password.