@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
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
| Parameter | Type | Description |
|---|---|---|
options | HashModuleOptions & 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
| Parameter | Type | Description |
|---|---|---|
options | ConfigurableModuleAsyncOptions<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
| Parameter | Type | Description |
|---|---|---|
options | HashModuleOptions | Configuration options for the hash service |
Returns
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
| Parameter | Type | Description |
|---|---|---|
value | string | Buffer<ArrayBufferLike> | The value to hash (password or other sensitive data) |
secret? | string | Optional 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
| Parameter | Type | Description |
|---|---|---|
hashed | string | Buffer<ArrayBufferLike> | The hash to verify against |
value | string | Buffer<ArrayBufferLike> | The value to verify |
secret? | string | Optional 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.