From 503275a6a26dfb90bffd8122ef9ab5250c8eb1ef Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 23 Feb 2019 16:02:12 +0100 Subject: [PATCH] fix(readme): add --- npmextra.json | 2 +- package.json | 2 +- readme.md | 26 +++++++++++++++ ts/index.ts | 2 +- ts/smartkey.classes.keypair.ts | 59 +++++++++++++++++---------------- ts/smartkey.classes.smartkey.ts | 1 - ts/smartkey.plugins.ts | 8 ++--- 7 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 readme.md diff --git a/npmextra.json b/npmextra.json index cc6513a..d610158 100644 --- a/npmextra.json +++ b/npmextra.json @@ -14,4 +14,4 @@ "npmGlobalTools": [], "npmAccessLevel": "public" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index d5aa260..50ed61e 100644 --- a/package.json +++ b/package.json @@ -23,4 +23,4 @@ "dependencies": { "@pushrocks/smartpromise": "^2.0.5" } -} +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..efbaf0c --- /dev/null +++ b/readme.md @@ -0,0 +1,26 @@ +# @pushrocks/smartkey +handle private/public key creation + +## Availabililty and Links +* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartkey) +* [gitlab.com (source)](https://gitlab.com/pushrocks/smartkey) +* [github.com (source mirror)](https://github.com/pushrocks/smartkey) +* [docs (typedoc)](https://pushrocks.gitlab.io/smartkey/) + +## Status for master +[![build status](https://gitlab.com/pushrocks/smartkey/badges/master/build.svg)](https://gitlab.com/pushrocks/smartkey/commits/master) +[![coverage report](https://gitlab.com/pushrocks/smartkey/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartkey/commits/master) +[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartkey.svg)](https://www.npmjs.com/package/@pushrocks/smartkey) +[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartkey/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartkey) +[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) +[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) +[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) + +## Usage + +For further information read the linked docs at the top of this readme. + +> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) +| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) + +[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) diff --git a/ts/index.ts b/ts/index.ts index 5db6f4e..0065612 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,2 +1,2 @@ export * from './smartkey.classes.smartkey'; -export * from './smartkey.classes.keypair'; \ No newline at end of file +export * from './smartkey.classes.keypair'; diff --git a/ts/smartkey.classes.keypair.ts b/ts/smartkey.classes.keypair.ts index fd154c4..be309d0 100644 --- a/ts/smartkey.classes.keypair.ts +++ b/ts/smartkey.classes.keypair.ts @@ -3,34 +3,38 @@ import * as plugins from './smartkey.plugins'; /** * represents a keypair */ -export class KeyPair { +export class KeyPair { // static - public static async createKeyPair (passphraseArg = ''): Promise { + public static async createKeyPair(passphraseArg = ''): Promise { const done = plugins.smartpromise.defer(); - plugins.crypto.generateKeyPair('rsa', { - modulusLength: 4096, - publicKeyEncoding: { - type: 'spki', - format: 'pem' + plugins.crypto.generateKeyPair( + 'rsa', + { + modulusLength: 4096, + publicKeyEncoding: { + type: 'spki', + format: 'pem' + }, + privateKeyEncoding: { + type: 'pkcs8', + format: 'pem', + cipher: 'aes-256-cbc', + passphrase: passphraseArg + } }, - privateKeyEncoding: { - type: 'pkcs8', - format: 'pem', - cipher: 'aes-256-cbc', - passphrase: passphraseArg + (err, publicKeyArg, privateKeyArg) => { + // convey error + if (err) { + done.reject(err); + throw err; + } + const keyPairInstance = new KeyPair({ + privateKey: privateKeyArg, + publicKey: publicKeyArg + }); + done.resolve(keyPairInstance); } - }, (err, publicKeyArg, privateKeyArg) => { - // convey error - if (err) { - done.reject(err); - throw (err); - } - const keyPairInstance = new KeyPair({ - privateKey: privateKeyArg, - publicKey: publicKeyArg - }); - done.resolve(keyPairInstance); - }); + ); return done.promise; } @@ -38,11 +42,8 @@ export class KeyPair { public publicKey: string; public privateKey: string; - constructor(optionsArg: { - privateKey: string; - publicKey: string; - }) { + constructor(optionsArg: { privateKey: string; publicKey: string }) { this.privateKey = optionsArg.privateKey; this.publicKey = optionsArg.publicKey; } -} \ No newline at end of file +} diff --git a/ts/smartkey.classes.smartkey.ts b/ts/smartkey.classes.smartkey.ts index e9b5162..5d69d6d 100644 --- a/ts/smartkey.classes.smartkey.ts +++ b/ts/smartkey.classes.smartkey.ts @@ -1,7 +1,6 @@ import * as plugins from './smartkey.plugins'; import { KeyPair } from './smartkey.classes.keypair'; - export class SmartKey { // instance public async getKeypair(passohrase?: string): Promise { diff --git a/ts/smartkey.plugins.ts b/ts/smartkey.plugins.ts index e9b4f33..b870d7c 100644 --- a/ts/smartkey.plugins.ts +++ b/ts/smartkey.plugins.ts @@ -1,13 +1,9 @@ // node native import * as crypto from 'crypto'; -export { - crypto -}; +export { crypto }; // @pushrocks scope import * as smartpromise from '@pushrocks/smartpromise'; -export { - smartpromise -}; +export { smartpromise };