# @seishinverse/crypto

> Compact and fast crypto module for hashing and comparing hashes

Latest version **1.0.0** (published 2023-12-06) · 0 weekly downloads

## Install

```sh
npm install @seishinverse/crypto
pnpm add @seishinverse/crypto
yarn add @seishinverse/crypto
bun add @seishinverse/crypto
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-12-06 |
| First published | 2023-12-06 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mxrcury |

## Links

- npm: https://www.npmjs.com/package/@seishinverse/crypto
- npm.io page: https://npm.io/package/@seishinverse/crypto

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 1.0.0 (latest) — 2023-12-06
- 0.0.3 — 2023-12-06
- 0.0.2 — 2023-12-06
- 0.0.1 — 2023-12-06

## README

# Crypto

Compact and fast crypto module for hashing and comparing hashes

#### Installation

```sh
npm i @seishinverse/crypto

# or with yarn
yarn add @seishinverse/crypto

# or with pnpm
pnpm i @seishinverse/crypto
```

#### Example of usage for NestJS

In first import `CryptoModule` in `AppModule`.

```typescript
import { CryptoModule } from '@seishinverse/crypto';
import { Module } from '@nestjs/common';

@Module({
  imports: [CryptoModule.forRoot()],
})
export class AppModule {}
```

Then inject service with decorator `InjectCrypto`.

```typescript
import { CryptoModule, InjectCrypto, CryptoService } from '@seishinverse/crypto';
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  constructor(@InjectCrypto() private cryptoService: CryptoService) {}

  /*
    Generating salt and hashing password.
  */
  signUp() {
    const SALT_ROUNDS = 5;
    const hashSalt = this.cryptoService.genSalt(SALT_ROUNDS);
    const hashedPassword = this.cryptoService.hash('very secret pass!', hashSalt);
    // ...
  }

  /*
    Comparing current password with incoming.
  */
  signIn() {
    const currentPassword = 'very secret pass!';
    const incomingPassword = 'not secret pass:(';

    const isPasswordEqual = this.cryptoService.compare(incomingPassword, currentPassword);

    console.log(isPasswordEqual); // false
  }
}
```

#### Example of usage in NodeJS

Import `CryptoService` and initialize it.

```typescript
import { CryptoService } from '@seishinverse/crypto';

const cryptoService = new CryptoService();

/*
  Generating salt and hashing password.
*/
const SALT_ROUNDS = 5;
const hashSalt = this.cryptoService.genSalt(SALT_ROUNDS);
const hashedPassword = this.cryptoService.hash('very secret pass!', hashSalt);
/*
  Comparing current password with incoming.
*/
const currentPassword = hashedPassword;
const incomingPassword = 'not secret pass:(';

const isPasswordEqual = this.cryptoService.compare(incomingPassword, currentPassword);

console.log(isPasswordEqual); // false
```

---
_Source: https://npm.io/package/@seishinverse/crypto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
