A small library to create micro-services with AES-256-CTR encryption on top of micro.
Install
npm i micro-encrypt
Usage
auths
To use this library the first thing you have to do is create a json file where you define all of your authentications/users. The format is key/value.
Every key of the json is an user. We will call it API_KEY
, and the value of that API_KEY
is the API_SECRET
. You can add as much as you want. Use just one API_KEY
for each client you connect with.
Example:
/micro
This module is a wrapper of micro with the difference that you have to pass an object
with two mandatory parameters:
-
auths:
Object
-
endpoints:
Array
const micro = const create = const auths = user1213151: 'the_password'const endpoints = endpoints const server = server
/endpoints
to do
/request
This module is just a function that creates a wrapper of request-promise which is also a promise wrapper of request.
const request = const encryption = API_KEY API_SECRET // Any of those you have defined previously in auths.jsonconst body = symbol: 'BTC' const address = await
If you want to use request as standalone you can do it this way:
const request = const encrypt decrypt = const body = const headers = authorization: API_KEY
Error handling
A successful request always gets 2XX as statusCode. Any other statusCode will be an error. And you must handle it with try-catch.
const request = try const address = await catche console // 404 console // { "message": "Not Found" }
If you want to use request
const request =
/encryption
to do