@nest-boot/hash
Classes
HashModule
Defined in: packages/hash/src/hash.module.ts:80
Module that provides password hashing services using Argon2.
Example
import { HashModule } from '@nest-boot/hash';
@Module({
imports: [
HashModule.register({
secret: process.env.HASH_SECRET
}),
],
})
export class AppModule {}
Generate a secure secret:
node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"
Extends
ConfigurableModuleClass
Indexable
[key: string]: any
Constructors
Constructor
new HashModule(): HashModule;
Defined in: node_modules/.pnpm/@nestjs+common@11.1.11/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:86
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:95
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:19
Service that provides password hashing and verification using Argon2 algorithm.
Example
import { HashService } from '@nest-boot/hash';
// Initialize at application startup
HashService.init(process.env.HASH_SECRET);
// Use static methods
const hashed = await HashService.hash(password);
const isValid = await HashService.verify(hashed, password);
Constructors
Constructor
new HashService(secret?): HashService;
Defined in: packages/hash/src/hash.service.ts:111
Creates an instance of HashService.
Parameters
| Parameter | Type | Description |
|---|---|---|
secret? | string | Optional secret key to use for hashing |
Returns
Accessors
instance
Get Signature
get static instance(): HashService;
Defined in: packages/hash/src/hash.service.ts:27
Gets the static HashService instance.
Throws
Error if HashService has not been initialized via init()
Returns
The HashService instance
Methods
create()
create(value, secret?): Promise<string>;
Defined in: packages/hash/src/hash.service.ts:122
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
Deprecated
Use hash instead
hash()
hash(value, secret?): Promise<string>;
Defined in: packages/hash/src/hash.service.ts:132
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
hashSync()
hashSync(value, secret?): string;
Defined in: packages/hash/src/hash.service.ts:144
Creates a hash synchronously 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
string
The hashed string
verify()
verify(
hashed,
value,
secret?): Promise<boolean>;
Defined in: packages/hash/src/hash.service.ts:157
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
verifySync()
verifySync(
hashed,
value,
secret?): boolean;
Defined in: packages/hash/src/hash.service.ts:174
Verifies a value against a hash synchronously.
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
boolean
True if the value matches the hash, false otherwise
hash()
static hash(value, secret?): Promise<string>;
Defined in: packages/hash/src/hash.service.ts:58
Creates a hash from the given value using the static instance.
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
Throws
Error if HashService has not been initialized via init()
hashSync()
static hashSync(value, secret?): string;
Defined in: packages/hash/src/hash.service.ts:69
Creates a hash synchronously from the given value using the static instance.
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
string
The hashed string
Throws
Error if HashService has not been initialized via init()
init()
static init(secret?): void;
Defined in: packages/hash/src/hash.service.ts:47
Initializes the static HashService instance with the given secret. Call this method at application startup to configure the default secret.
Parameters
| Parameter | Type | Description |
|---|---|---|
secret? | string | The secret key to use for hashing |
Returns
void
Example
// In your application bootstrap
HashService.init(process.env.HASH_SECRET);
verify()
static verify(
hashed,
value,
secret?): Promise<boolean>;
Defined in: packages/hash/src/hash.service.ts:81
Verifies a value against a hash using the static instance.
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
Throws
Error if HashService has not been initialized via init()
verifySync()
static verifySync(
hashed,
value,
secret?): boolean;
Defined in: packages/hash/src/hash.service.ts:97
Verifies a value against a hash synchronously using the static instance.
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
boolean
True if the value matches the hash, false otherwise
Throws
Error if HashService has not been initialized via init()
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.