1.1.0 • Published 5 months ago

virgil-zt v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Introduction

Virgil ZT Middleware

It's middleware for nodejs backend servers! Allow to simply implement information encoding. Using as core virgil-crypto lib!

Using guide

After this initialize class instance

import { ZtMiddleware } from 'build';

const virgil = new ZtMiddleware(KeyPairType.ED25519, '/login');
KeyPairType.ED25519

Argument it's key type, you can check other values on KeyPairType enum

/login

It's login url, that will accept your frontend key

You can pass more than this two parameters:

  • Storage interface function storageControl
  • Encoding default value is base64

What is storage

Let's see a full elements that ypu can pass into constructor

const TemplateStorage: Map<string, any> = new Map<string, any>();

const storageSave = (key: unknown, isClient: boolean) => {
	TemplateStorage.set(isClient ? 'client' : 'server', key);
};

const storageLoad = (isClient: boolean) => {
	return isClient ? TemplateStorage.get('client') : TemplateStorage.get('server');
};

function storage(isSave: boolean, isClient: boolean, key?: unknown) {
	if (isSave) {
		storageSave(key, isClient);
		return;
	}
	return storageLoad(isClient);
}

const virgil = new ZtMiddleware(KeyPairType.ED25519, '/login', storage, 'base64');

The storage function is interface for working with files or another save instrument. Upper we realize simple storage, to collect server and clients keys. We are saving this in TypeScript Map, then convert in .json file after server broke. When server is up again we can load this keys and using them. You can create your own storage logic, all that you need is create function like:

storage(isSave: boolean, isClient: boolean, key?: unknown)

Then pass it inside constructor, we will save keys and get it, if needed.

Pass middleware into nodejs

app.use(virgil.zeroTrustMiddleware);

After this, on frontend you need to pass keys on login url. Save key on frontend and that's all. Encryption is ready for use!

For more information you can check example/backend and example/frontend to see how it's working.

1.1.0

5 months ago

1.0.7

5 months ago

1.0.5

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago