跳到主要内容

@nest-boot/hash

Classes

HashModule

Defined in: packages/hash/src/hash.module.ts:30

Module that provides password hashing services using Argon2.

Example

import { HashModule } from '@nest-boot/hash';

@Module({
imports: [
HashModule.register({
secret: 'your-secret-key',
isGlobal: true,
}),
],
})
export class AppModule {}

Extends

  • ConfigurableModuleClass

Indexable

[key: string]: any

Constructors

Constructor
new HashModule(): HashModule;

Defined in: node_modules/.pnpm/@nestjs+common@11.1.9/node_modules/@nestjs/common/module-utils/interfaces/configurable-module-cls.interface.d.ts:12

Returns

HashModule

Inherited from
ConfigurableModuleClass.constructor

Methods

register()
static register(options): DynamicModule;

Defined in: packages/hash/src/hash.module.ts:36

Registers the HashModule with the given options.

Parameters
ParameterTypeDescription
optionsHashModuleOptions & Partial<{ }>Configuration options including secret and isGlobal
Returns

DynamicModule

Dynamic module configuration

Overrides
ConfigurableModuleClass.register
registerAsync()
static registerAsync(options): DynamicModule;

Defined in: packages/hash/src/hash.module.ts:45

Registers the HashModule asynchronously with factory functions.

Parameters
ParameterTypeDescription
optionsConfigurableModuleAsyncOptions<HashModuleOptions, "create"> & Partial<{ }>Async configuration options
Returns

DynamicModule

Dynamic module configuration

Overrides
ConfigurableModuleClass.registerAsync

HashService

Defined in: packages/hash/src/hash.service.ts:29

Service that provides password hashing and verification using Argon2 algorithm.

Example

import { HashService } from '@nest-boot/hash';

@Injectable()
export class AuthService {
constructor(private readonly hashService: HashService) {}

async hashPassword(password: string): Promise<string> {
return this.hashService.create(password);
}

async verifyPassword(hash: string, password: string): Promise<boolean> {
return this.hashService.verify(hash, password);
}
}

Constructors

Constructor
new HashService(options): HashService;

Defined in: packages/hash/src/hash.service.ts:36

Creates an instance of HashService.

Parameters
ParameterTypeDescription
optionsHashModuleOptionsConfiguration options for the hash service
Returns

HashService

Methods

create()
create(value, secret?): Promise<string>;

Defined in: packages/hash/src/hash.service.ts:55

Creates a hash from the given value using Argon2.

Parameters
ParameterTypeDescription
valuestring | Buffer<ArrayBufferLike>The value to hash (password or other sensitive data)
secret?stringOptional secret key to use instead of the default
Returns

Promise<string>

The hashed string

verify()
verify(
hashed,
value,
secret?): Promise<boolean>;

Defined in: packages/hash/src/hash.service.ts:68

Verifies a value against a hash.

Parameters
ParameterTypeDescription
hashedstring | Buffer<ArrayBufferLike>The hash to verify against
valuestring | Buffer<ArrayBufferLike>The value to verify
secret?stringOptional secret key to use instead of the default
Returns

Promise<boolean>

True if the value matches the hash, false otherwise

Interfaces

HashModuleOptions

Defined in: packages/hash/src/hash-module-options.interface.ts:4

Configuration options for the HashModule.

Properties

secret?
optional secret: string;

Defined in: packages/hash/src/hash-module-options.interface.ts:9

The secret key used for hashing. If not provided, falls back to HASH_SECRET or APP_SECRET environment variables.