diff --git a/package-lock.json b/package-lock.json index 32d8de8..9907e3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 2ce5988..666efd7 100644 --- a/package.json +++ b/package.json @@ -20,5 +20,7 @@ "tslint": "^5.11.0", "tslint-config-prettier": "^1.15.0" }, - "dependencies": {} + "dependencies": { + "@pushrocks/smartpromise": "^2.0.5" + } } diff --git a/test/test.ts b/test/test.ts index c57d67a..60cc130 100644 --- a/test/test.ts +++ b/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(); diff --git a/ts/index.ts b/ts/index.ts index 8565cb3..5db6f4e 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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'; \ No newline at end of file diff --git a/ts/smartkey.classes.keypair.ts b/ts/smartkey.classes.keypair.ts new file mode 100644 index 0000000..fd154c4 --- /dev/null +++ b/ts/smartkey.classes.keypair.ts @@ -0,0 +1,48 @@ +import * as plugins from './smartkey.plugins'; + +/** + * represents a keypair + */ +export class KeyPair { + // static + public static async createKeyPair (passphraseArg = ''): Promise { + const done = plugins.smartpromise.defer(); + 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; + } +} \ No newline at end of file diff --git a/ts/smartkey.classes.smartkey.ts b/ts/smartkey.classes.smartkey.ts new file mode 100644 index 0000000..e9b5162 --- /dev/null +++ b/ts/smartkey.classes.smartkey.ts @@ -0,0 +1,10 @@ +import * as plugins from './smartkey.plugins'; +import { KeyPair } from './smartkey.classes.keypair'; + + +export class SmartKey { + // instance + public async getKeypair(passohrase?: string): Promise { + return KeyPair.createKeyPair(); + } +} diff --git a/ts/smartkey.plugins.ts b/ts/smartkey.plugins.ts index d00ae0c..e9b4f33 100644 --- a/ts/smartkey.plugins.ts +++ b/ts/smartkey.plugins.ts @@ -1,4 +1,13 @@ -const removeme = {}; +// node native +import * as crypto from 'crypto'; + export { - removeme -} + crypto +}; + +// @pushrocks scope +import * as smartpromise from '@pushrocks/smartpromise'; + +export { + smartpromise +};