Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
11f574536c | |||
b3d1dfc607 | |||
e73a29f643 | |||
503275a6a2 | |||
b75758882c | |||
adc3e245bc | |||
693a26bba7 |
5
package-lock.json
generated
5
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartkey",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.6",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -175,8 +175,7 @@
|
||||
"@pushrocks/smartpromise": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
|
||||
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==",
|
||||
"dev": true
|
||||
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
|
||||
},
|
||||
"@pushrocks/smartrequest": {
|
||||
"version": "1.1.14",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartkey",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.6",
|
||||
"private": false,
|
||||
"description": "handle private/public key creation",
|
||||
"main": "dist/index.js",
|
||||
@ -20,5 +20,7 @@
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^2.0.5"
|
||||
}
|
||||
}
|
||||
|
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)
|
20
test/test.ts
20
test/test.ts
@ -1,8 +1,20 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartkey from '../ts/index'
|
||||
import * as smartkey from '../ts/index';
|
||||
|
||||
let testSmartkey: smartkey.SmartKey;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smartkey.standardExport)
|
||||
})
|
||||
testSmartkey = new smartkey.SmartKey();
|
||||
expect(testSmartkey).to.be.instanceOf(smartkey.SmartKey);
|
||||
});
|
||||
|
||||
tap.start()
|
||||
tap.test('should create a valid keypair', async () => {
|
||||
const keyPair = await testSmartkey.getKeypair();
|
||||
expect(keyPair).to.be.instanceOf(smartkey.KeyPair);
|
||||
console.log(keyPair.publicKey);
|
||||
console.log(keyPair.privateKey);
|
||||
|
||||
console.log('note: these keys do not have any function, they are just a test ReferenceError.');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,3 +1,2 @@
|
||||
import * as plugins from './smartkey.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export * from './smartkey.classes.smartkey';
|
||||
export * from './smartkey.classes.keypair';
|
||||
|
49
ts/smartkey.classes.keypair.ts
Normal file
49
ts/smartkey.classes.keypair.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import * as plugins from './smartkey.plugins';
|
||||
|
||||
/**
|
||||
* represents a keypair
|
||||
*/
|
||||
export class KeyPair {
|
||||
// static
|
||||
public static async createKeyPair(passphraseArg = ''): Promise<KeyPair> {
|
||||
const done = plugins.smartpromise.defer<KeyPair>();
|
||||
plugins.crypto.generateKeyPair(
|
||||
'rsa',
|
||||
{
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem'
|
||||
},
|
||||
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);
|
||||
}
|
||||
);
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
// instance
|
||||
public publicKey: string;
|
||||
public privateKey: string;
|
||||
|
||||
constructor(optionsArg: { privateKey: string; publicKey: string }) {
|
||||
this.privateKey = optionsArg.privateKey;
|
||||
this.publicKey = optionsArg.publicKey;
|
||||
}
|
||||
}
|
9
ts/smartkey.classes.smartkey.ts
Normal file
9
ts/smartkey.classes.smartkey.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import * as plugins from './smartkey.plugins';
|
||||
import { KeyPair } from './smartkey.classes.keypair';
|
||||
|
||||
export class SmartKey {
|
||||
// instance
|
||||
public async getKeypair(passphraseArg?: string): Promise<KeyPair> {
|
||||
return KeyPair.createKeyPair(passphraseArg);
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
const removeme = {};
|
||||
export {
|
||||
removeme
|
||||
}
|
||||
// node native
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
export { crypto };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { smartpromise };
|
||||
|
Reference in New Issue
Block a user