Skip to content

Commit

Permalink
feat(docs): updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
mxrcury committed Dec 6, 2023
1 parent c1ae125 commit 8b29d3b
Showing 1 changed file with 70 additions and 42 deletions.
112 changes: 70 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,91 @@
# Seishinverse

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
# Crypto

**This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)**
Compact and fast crypto module for hashing and comparing hashes

#### Installation

## Start the app
```sh
npm i @seishinverse/crypto

To start the development server run `nx serve seishinverse`. Open your browser and navigate to http://localhost:4200/. Happy coding!
# or with yarn
yarn add @seishinverse/crypto


## Generate code

If you happen to use Nx plugins, you can leverage code generators that might come with it.

Run `nx list` to get a list of available plugins and whether they have generators. Then run `nx list <plugin-name>` to see what generators are available.

Learn more about [Nx generators on the docs](https://nx.dev/plugin-features/use-code-generators).

## Running tasks

To execute tasks with Nx use the following syntax:

```
nx <target> <project> <...options>
# or with pnpm
pnpm i @seishinverse/crypto
```

You can also run multiple targets:
#### Example of usage for NestJS

```
nx run-many -t <target1> <target2>
```
In first import `CryptoModule` in `AppModule`.

..or add `-p` to filter specific projects
```typescript
import { CryptoModule } from '@seishinverse/crypto';
import { Module } from '@nestjs/common';

@Module({
imports: [CryptoModule.forRoot()],
})
export class AppModule {}
```
nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/core-features/run-tasks).

## Want better Editor Integration?

Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.
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
}
}
```

## Ready to deploy?
#### Example of usage in NodeJS

Just run `nx build demoapp` to build the application. The build artifacts will be stored in the `dist/` directory, ready to be deployed.
Import `CryptoService` and initialize it.

## Set up CI!
```typescript
import { CryptoService } from '@seishinverse/crypto';

Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further.
const cryptoService = new CryptoService();

- [Set up remote caching](https://nx.dev/core-features/share-your-cache)
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
- [Learn more how to setup CI](https://nx.dev/recipes/ci)
/*
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:(';

## Connect with us!
const isPasswordEqual = this.cryptoService.compare(incomingPassword, currentPassword);

- [Join the community](https://nx.dev/community)
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
- [Follow us on Twitter](https://twitter.com/nxdevtools)
console.log(isPasswordEqual); // false
```

0 comments on commit 8b29d3b

Please sign in to comment.