Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
11f574536c | |||
b3d1dfc607 | |||
e73a29f643 | |||
503275a6a2 | |||
b75758882c |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartkey",
|
"name": "@pushrocks/smartkey",
|
||||||
"version": "1.0.3",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartkey",
|
"name": "@pushrocks/smartkey",
|
||||||
"version": "1.0.3",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "handle private/public key creation",
|
"description": "handle private/public key creation",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
26
readme.md
Normal file
26
readme.md
Normal file
@ -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
|
||||||
|
[](https://gitlab.com/pushrocks/smartkey/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartkey/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@pushrocks/smartkey)
|
||||||
|
[](https://snyk.io/test/npm/@pushrocks/smartkey)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](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)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
@ -3,34 +3,38 @@ import * as plugins from './smartkey.plugins';
|
|||||||
/**
|
/**
|
||||||
* represents a keypair
|
* represents a keypair
|
||||||
*/
|
*/
|
||||||
export class KeyPair {
|
export class KeyPair {
|
||||||
// static
|
// static
|
||||||
public static async createKeyPair (passphraseArg = ''): Promise<KeyPair> {
|
public static async createKeyPair(passphraseArg = ''): Promise<KeyPair> {
|
||||||
const done = plugins.smartpromise.defer<KeyPair>();
|
const done = plugins.smartpromise.defer<KeyPair>();
|
||||||
plugins.crypto.generateKeyPair('rsa', {
|
plugins.crypto.generateKeyPair(
|
||||||
modulusLength: 4096,
|
'rsa',
|
||||||
publicKeyEncoding: {
|
{
|
||||||
type: 'spki',
|
modulusLength: 4096,
|
||||||
format: 'pem'
|
publicKeyEncoding: {
|
||||||
|
type: 'spki',
|
||||||
|
format: 'pem'
|
||||||
|
},
|
||||||
|
privateKeyEncoding: {
|
||||||
|
type: 'pkcs8',
|
||||||
|
format: 'pem',
|
||||||
|
cipher: 'aes-256-cbc',
|
||||||
|
passphrase: passphraseArg
|
||||||
|
}
|
||||||
},
|
},
|
||||||
privateKeyEncoding: {
|
(err, publicKeyArg, privateKeyArg) => {
|
||||||
type: 'pkcs8',
|
// convey error
|
||||||
format: 'pem',
|
if (err) {
|
||||||
cipher: 'aes-256-cbc',
|
done.reject(err);
|
||||||
passphrase: passphraseArg
|
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;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +42,7 @@ export class KeyPair {
|
|||||||
public publicKey: string;
|
public publicKey: string;
|
||||||
public privateKey: string;
|
public privateKey: string;
|
||||||
|
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: { privateKey: string; publicKey: string }) {
|
||||||
privateKey: string;
|
|
||||||
publicKey: string;
|
|
||||||
}) {
|
|
||||||
this.privateKey = optionsArg.privateKey;
|
this.privateKey = optionsArg.privateKey;
|
||||||
this.publicKey = optionsArg.publicKey;
|
this.publicKey = optionsArg.publicKey;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import * as plugins from './smartkey.plugins';
|
import * as plugins from './smartkey.plugins';
|
||||||
import { KeyPair } from './smartkey.classes.keypair';
|
import { KeyPair } from './smartkey.classes.keypair';
|
||||||
|
|
||||||
|
|
||||||
export class SmartKey {
|
export class SmartKey {
|
||||||
// instance
|
// instance
|
||||||
public async getKeypair(passohrase?: string): Promise<KeyPair> {
|
public async getKeypair(passphraseArg?: string): Promise<KeyPair> {
|
||||||
return KeyPair.createKeyPair();
|
return KeyPair.createKeyPair(passphraseArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
// node native
|
// node native
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
export {
|
export { crypto };
|
||||||
crypto
|
|
||||||
};
|
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export {
|
export { smartpromise };
|
||||||
smartpromise
|
|
||||||
};
|
|
||||||
|
Reference in New Issue
Block a user