New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hapiness/crypto

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapiness/crypto - npm Package Compare versions

Comparing version 1.0.0-rc.6.2 to 1.0.0-rc.7

47

documentation/PEMService.md

@@ -56,3 +56,5 @@ <img src='http://bit.ly/2mxmKKI' width='500' alt='Hapiness' />

* [.readPkcs12(bufferOrPath[, options])](#readpkcs12bufferorpath-options)
* [.checkPkcs12(bufferOrPath[, passphrase])](#checkpkcs12bufferorpath-passphrase)
* [.verifySigningChain(certificate, ca)](#verifysigningchaincertificate-ca)
* [.checkCertificate(certificate[, passphrase])](#checkcertificate-passphrase)
* [Parameters types in detail](#parameters-types-in-detail)

@@ -321,2 +323,23 @@ * [PrivateKeyCreationOptions](#privatekeycreationoptions)

### `.checkPkcs12(bufferOrPath[, passphrase])`
Verifies a `PKCS12 keystore`.
**Parameters:**
> - ***{string} bufferOrPath*** *(required): `Buffer` representation or `path` to `PKCS12 keystore`.*
> - ***{string} passphrase*** *(optional): `Passphrase` which will be used to open the `keystore`.*
**Response:**
> *{[RxJS.Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)} The successfully `verified` will be passed as a `boolean`.*
**Example:**
```javascript
this._pemService.checkPkcs12([BUFFER])
.subscribe(
(verified: boolean) => console.log(verified), // Show `verified` boolean in the console
e => console.error(e.message) // Show error message in the console
);
```
[Back to top](#table-of-contents)
### `.verifySigningChain(certificate, ca)`

@@ -343,2 +366,23 @@

### `.checkCertificate(certificate[, passphrase])`
`Check` / `verify` consistency of a `certificate`.
**Parameters:**
> - ***{string} certificate*** *(required): `PEM encoded certificate`.*
> - ***{string} passphrase*** *(optional): `Passphrase` which will be used to open the `cretificate`.*
**Response:**
> *{[RxJS.Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)} The successfully `verified` will be passed as a `boolean`.*
**Example:**
```javascript
this._pemService.checkCertificate([BUFFER])
.subscribe(
(verified: boolean) => console.log(verified), // Show `verified` boolean in the console
e => console.error(e.message) // Show error message in the console
);
```
[Back to top](#table-of-contents)
## Parameters types in detail

@@ -393,2 +437,5 @@

* Add new methods (2017-09-26)
* [.checkPkcs12(bufferOrPath[, passphrase])](#checkpkcs12bufferorpath-passphrase)
* [.checkCertificate(certificate[, passphrase])](#checkcertificate-passphrase)
* Implementation of all methods (2017-07-28)

@@ -395,0 +442,0 @@ * [.createPrivateKey([keyBitsize, options])](#createprivatekeykeybitsize-options)

2

module/crypto.module.js

@@ -31,3 +31,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

core_1.HapinessModule({
version: '1.0.0-rc.6.2',
version: '1.0.0-rc.7',
exports: [

@@ -34,0 +34,0 @@ services_1.RandomstringService,

@@ -46,3 +46,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

// clone buffer
const keyBuffer = new Buffer(derivedKey);
const keyBuffer = Buffer.from(derivedKey);
// get aes256 key

@@ -49,0 +49,0 @@ const key = keyBuffer.slice(0, 32).toString('hex');

@@ -190,2 +190,11 @@ import { Observable } from 'rxjs/Observable';

/**
* Verifies a PKCS12 keystore.
*
* @param {string} bufferOrPath is a PKCS12 keystore as a Buffer or the path to a file
* @param {string} [passphrase] is an optional passphrase which will be used to open the keystore
*
* @return {Observable<boolean>}
*/
checkPkcs12(bufferOrPath: string, passphrase?: string): Observable<boolean>;
/**
* Verifies the signing chain of the passed certificate

@@ -199,2 +208,11 @@ *

verifySigningChain(certificate: string, ca: string[]): Observable<boolean>;
/**
* Check / verify consistency of a certificate.
*
* @param {string} certificate is a PEM encoded certificate string
* @param {string} [passphrase] is an optional passphrase which will be used to open the certificate
*
* @return {Observable<boolean>}
*/
checkCertificate(certificate: string, passphrase?: string): Observable<boolean>;
}

@@ -201,0 +219,0 @@ /**

@@ -180,2 +180,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

/**
* Verifies a PKCS12 keystore.
*
* @param {string} bufferOrPath is a PKCS12 keystore as a Buffer or the path to a file
* @param {string} [passphrase] is an optional passphrase which will be used to open the keystore
*
* @return {Observable<boolean>}
*/
checkPkcs12(bufferOrPath, passphrase) {
return Observable_1.Observable.bindNodeCallback(pem.checkPkcs12)(bufferOrPath, passphrase);
}
/**
* Verifies the signing chain of the passed certificate

@@ -191,2 +202,13 @@ *

}
/**
* Check / verify consistency of a certificate.
*
* @param {string} certificate is a PEM encoded certificate string
* @param {string} [passphrase] is an optional passphrase which will be used to open the certificate
*
* @return {Observable<boolean>}
*/
checkCertificate(certificate, passphrase) {
return Observable_1.Observable.bindNodeCallback(pem.checkCertificate)(certificate, passphrase);
}
};

@@ -193,0 +215,0 @@ PEMService = __decorate([

@@ -10,4 +10,4 @@ /// <reference types="node" />

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of decrypted data
* @return {Observable<Buffer>} Buffer of decrypted data
*/
export declare function decryptWithAesKey<T>(data: Buffer): Observable<T>;
export declare function decryptWithAesKey<AESKeyCreationResult>(this: Observable<AESKeyCreationResult>, data: Buffer): Observable<Buffer>;

@@ -22,8 +22,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of decrypted data
* @return {Observable<Buffer>} Buffer of decrypted data
*/
function decryptWithAesKey(data) {
return this.lift(new DecryptWithAesKeyOperator(this, data));
return higherOrder(data)(this);
}
exports.decryptWithAesKey = decryptWithAesKey;
function higherOrder(data) {
return (source) => source.lift(new DecryptWithAesKeyOperator(data));
}
/**

@@ -36,7 +39,5 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(_source, _data) {
this._source = _source;
constructor(_data) {
this._data = _data;

@@ -53,3 +54,3 @@ }

call(subscriber, source) {
return source.subscribe(new DecryptWithAesKeySubscriber(subscriber, this._source, this._data));
return source.subscribe(new DecryptWithAesKeySubscriber(subscriber, this._data));
}

@@ -65,8 +66,6 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(destination, _source, _data) {
constructor(destination, _data) {
super(destination);
this._source = _source;
this._data = _data;

@@ -77,19 +76,17 @@ }

*
* @param value result for next subscriber
* @param aesKey key from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((aesKey) => {
try {
const decipher = crypto_1.createDecipheriv('aes-256-cbc', new buffer_1.Buffer(aesKey.key, 'hex'), new buffer_1.Buffer(aesKey.iv, 'hex'));
const bufDecrypted = decipher.update(new buffer_1.Buffer(this._data));
const bufFinal = decipher.final();
this.destination.next(buffer_1.Buffer.concat([bufDecrypted, bufFinal]));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(aesKey) {
try {
const decipher = crypto_1.createDecipheriv('aes-256-cbc', buffer_1.Buffer.from(aesKey.key, 'hex'), buffer_1.Buffer.from(aesKey.iv, 'hex'));
const bufDecrypted = decipher.update(buffer_1.Buffer.from(this._data));
const bufFinal = decipher.final();
this.destination.next(buffer_1.Buffer.concat([bufDecrypted, bufFinal]));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -96,0 +93,0 @@ }

@@ -10,4 +10,4 @@ /// <reference types="node" />

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of encrypted data
* @return {Observable<Buffer>} Buffer of encrypted data
*/
export declare function encryptWithAesKey<T>(data: Buffer): Observable<T>;
export declare function encryptWithAesKey<AESKeyCreationResult>(data: Buffer): Observable<Buffer>;

@@ -22,8 +22,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of encrypted data
* @return {Observable<Buffer>} Buffer of encrypted data
*/
function encryptWithAesKey(data) {
return this.lift(new EncryptWithAesKeyOperator(this, data));
return higherOrder(data)(this);
}
exports.encryptWithAesKey = encryptWithAesKey;
function higherOrder(data) {
return (source) => source.lift(new EncryptWithAesKeyOperator(data));
}
/**

@@ -36,7 +39,5 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(_source, _data) {
this._source = _source;
constructor(_data) {
this._data = _data;

@@ -53,3 +54,3 @@ }

call(subscriber, source) {
return source.subscribe(new EncryptWithAesKeySubscriber(subscriber, this._source, this._data));
return source.subscribe(new EncryptWithAesKeySubscriber(subscriber, this._data));
}

@@ -65,8 +66,6 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(destination, _source, _data) {
constructor(destination, _data) {
super(destination);
this._source = _source;
this._data = _data;

@@ -77,19 +76,17 @@ }

*
* @param value result for next subscriber
* @param aesKey key from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((aesKey) => {
try {
const cipher = crypto_1.createCipheriv('aes-256-cbc', new buffer_1.Buffer(aesKey.key, 'hex'), new buffer_1.Buffer(aesKey.iv, 'hex'));
const bufEncrypted = cipher.update(new buffer_1.Buffer(this._data));
const bufFinal = cipher.final();
this.destination.next(buffer_1.Buffer.concat([bufEncrypted, bufFinal]));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(aesKey) {
try {
const cipher = crypto_1.createCipheriv('aes-256-cbc', buffer_1.Buffer.from(aesKey.key, 'hex'), buffer_1.Buffer.from(aesKey.iv, 'hex'));
const bufEncrypted = cipher.update(buffer_1.Buffer.from(this._data));
const bufFinal = cipher.final();
this.destination.next(buffer_1.Buffer.concat([bufEncrypted, bufFinal]));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -96,0 +93,0 @@ }

@@ -13,4 +13,4 @@ /// <reference types="node" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function decryptPrivate<T>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<T>;
export declare function decryptPrivate<NodeRSA, R>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<R>;

@@ -21,8 +21,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function decryptPrivate(data, encoding) {
return this.lift(new DecryptPrivateOperator(this, data, encoding));
return higherOrder(data, encoding)(this);
}
exports.decryptPrivate = decryptPrivate;
function higherOrder(data, encoding) {
return (source) => source.lift(new DecryptPrivateOperator(data, encoding));
}
/**

@@ -35,8 +38,6 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(_source, _data, _encoding) {
this._source = _source;
constructor(_data, _encoding) {
this._data = _data;

@@ -54,3 +55,3 @@ this._encoding = _encoding;

call(subscriber, source) {
return source.subscribe(new DecryptPrivateSubscriber(subscriber, this._source, this._data, this._encoding));
return source.subscribe(new DecryptPrivateSubscriber(subscriber, this._data, this._encoding));
}

@@ -66,9 +67,7 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(destination, _source, _data, _encoding) {
constructor(destination, _data, _encoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -80,17 +79,14 @@ this._encoding = _encoding;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.decrypt(this._data, this._encoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.decrypt(this._data, this._encoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -97,0 +93,0 @@ }

@@ -13,4 +13,4 @@ /// <reference types="node" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function decryptPublic<T>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<T>;
export declare function decryptPublic<NodeRSA, R>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<R>;

@@ -21,8 +21,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function decryptPublic(data, encoding) {
return this.lift(new DecryptPublicOperator(this, data, encoding));
return higherOrder(data, encoding)(this);
}
exports.decryptPublic = decryptPublic;
function higherOrder(data, encoding) {
return (source) => source.lift(new DecryptPublicOperator(data, encoding));
}
/**

@@ -35,8 +38,6 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(_source, _data, _encoding) {
this._source = _source;
constructor(_data, _encoding) {
this._data = _data;

@@ -54,3 +55,3 @@ this._encoding = _encoding;

call(subscriber, source) {
return source.subscribe(new DecryptPublicSubscriber(subscriber, this._source, this._data, this._encoding));
return source.subscribe(new DecryptPublicSubscriber(subscriber, this._data, this._encoding));
}

@@ -66,9 +67,7 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(destination, _source, _data, _encoding) {
constructor(destination, _data, _encoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -80,17 +79,14 @@ this._encoding = _encoding;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.decryptPublic(this._data, this._encoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.decryptPublic(this._data, this._encoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -97,0 +93,0 @@ }

@@ -14,4 +14,4 @@ /// <reference types="node-rsa" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function encryptPrivate<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T>;
export declare function encryptPrivate<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R>;

@@ -22,8 +22,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function encryptPrivate(data, encoding, sourceEncoding) {
return this.lift(new EncryptPrivateOperator(this, data, encoding, sourceEncoding));
return higherOrder(data, encoding, sourceEncoding)(this);
}
exports.encryptPrivate = encryptPrivate;
function higherOrder(data, encoding, sourceEncoding) {
return (source) => source.lift(new EncryptPrivateOperator(data, encoding, sourceEncoding));
}
/**

@@ -36,3 +39,2 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -42,4 +44,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(_source, _data, _encoding, _sourceEncoding) {
this._source = _source;
constructor(_data, _encoding, _sourceEncoding) {
this._data = _data;

@@ -58,3 +59,3 @@ this._encoding = _encoding;

call(subscriber, source) {
return source.subscribe(new EncryptPrivateSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
return source.subscribe(new EncryptPrivateSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -70,3 +71,2 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -76,5 +76,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination, _source, _data, _encoding, _sourceEncoding) {
constructor(destination, _data, _encoding, _sourceEncoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -87,17 +86,14 @@ this._encoding = _encoding;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.encryptPrivate(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.encryptPrivate(this._data, this._encoding, this._sourceEncoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -104,0 +100,0 @@ }

@@ -14,4 +14,4 @@ /// <reference types="node-rsa" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function encryptPublic<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T>;
export declare function encryptPublic<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R>;

@@ -22,8 +22,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function encryptPublic(data, encoding, sourceEncoding) {
return this.lift(new EncryptPublicOperator(this, data, encoding, sourceEncoding));
return higherOrder(data, encoding, sourceEncoding)(this);
}
exports.encryptPublic = encryptPublic;
function higherOrder(data, encoding, sourceEncoding) {
return (source) => source.lift(new EncryptPublicOperator(data, encoding, sourceEncoding));
}
/**

@@ -36,3 +39,2 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -42,4 +44,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(_source, _data, _encoding, _sourceEncoding) {
this._source = _source;
constructor(_data, _encoding, _sourceEncoding) {
this._data = _data;

@@ -58,3 +59,3 @@ this._encoding = _encoding;

call(subscriber, source) {
return source.subscribe(new EncryptPublicSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
return source.subscribe(new EncryptPublicSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -70,3 +71,2 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -76,5 +76,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination, _source, _data, _encoding, _sourceEncoding) {
constructor(destination, _data, _encoding, _sourceEncoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -87,17 +86,14 @@ this._encoding = _encoding;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.encrypt(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.encrypt(this._data, this._encoding, this._sourceEncoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -104,0 +100,0 @@ }

/// <reference types="node-rsa" />
import { Observable } from 'rxjs/Observable';
import { Format } from 'node-rsa';
import { Format, Key } from 'node-rsa';
/**

@@ -11,4 +11,4 @@ * New observable operator

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<Key>}
*/
export declare function exportKey<T>(format?: Format): Observable<T>;
export declare function exportKey<NodeRSA>(format?: Format): Observable<Key>;

@@ -20,8 +20,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<Key>}
*/
function exportKey(format) {
return this.lift(new ExportKeyOperator(this, format));
return higherOrder(format)(this);
}
exports.exportKey = exportKey;
function higherOrder(format) {
return (source) => source.lift(new ExportKeyOperator(format));
}
/**

@@ -34,7 +37,5 @@ * Operator class definition

*
* @param _source subscriber source
* @param _format key format
*/
constructor(_source, _format) {
this._source = _source;
constructor(_format) {
this._format = _format;

@@ -51,3 +52,3 @@ }

call(subscriber, source) {
return source.subscribe(new ExportKeySubscriber(subscriber, this._source, this._format));
return source.subscribe(new ExportKeySubscriber(subscriber, this._format));
}

@@ -63,8 +64,6 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _format key format
*/
constructor(destination, _source, _format) {
constructor(destination, _format) {
super(destination);
this._source = _source;
this._format = _format;

@@ -75,17 +74,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.exportKey(this._format);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.exportKey(this._format));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -92,0 +88,0 @@ }

@@ -8,4 +8,4 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
export declare function generateKeyPair<T>(bits?: number, exponent?: number): Observable<T>;
export declare function generateKeyPair<NodeRSA>(bits?: number, exponent?: number): Observable<NodeRSA>;

@@ -19,8 +19,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
function generateKeyPair(bits, exponent) {
return this.lift(new GenerateKeyPairOperator(this, bits, exponent));
return higherOrder(bits, exponent)(this);
}
exports.generateKeyPair = generateKeyPair;
function higherOrder(bits, exponent) {
return (source) => source.lift(new GenerateKeyPairOperator(bits, exponent));
}
/**

@@ -33,8 +36,6 @@ * Operator class definition

*
* @param _source subscriber source
* @param _bits Key size in bits. 2048 by default.
* @param _exponent public exponent. 65537 by default.
*/
constructor(_source, _bits, _exponent) {
this._source = _source;
constructor(_bits, _exponent) {
this._bits = _bits;

@@ -52,3 +53,3 @@ this._exponent = _exponent;

call(subscriber, source) {
return source.subscribe(new GenerateKeyPairSubscriber(subscriber, this._source, this._bits, this._exponent));
return source.subscribe(new GenerateKeyPairSubscriber(subscriber, this._bits, this._exponent));
}

@@ -64,9 +65,7 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _bits Key size in bits. 2048 by default.
* @param _exponent public exponent. 65537 by default.
*/
constructor(destination, _source, _bits, _exponent) {
constructor(destination, _bits, _exponent) {
super(destination);
this._source = _source;
this._bits = _bits;

@@ -78,17 +77,15 @@ this._exponent = _exponent;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
nodeRSA.generateKeyPair(this._bits, this._exponent);
this.destination.next(nodeRSA);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
nodeRSA.generateKeyPair(this._bits, this._exponent);
this.destination.next(nodeRSA);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -95,0 +92,0 @@ }

@@ -7,4 +7,4 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
export declare function getKeySize<T>(): Observable<T>;
export declare function getKeySize<NodeRSA>(): Observable<number>;

@@ -18,8 +18,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
function getKeySize() {
return this.lift(new GetKeySizeOperator(this));
return higherOrder()(this);
}
exports.getKeySize = getKeySize;
function higherOrder() {
return (source) => source.lift(new GetKeySizeOperator());
}
/**

@@ -31,7 +34,4 @@ * Operator class definition

* Class constructor
*
* @param _source subscriber source
*/
constructor(_source) {
this._source = _source;
constructor() {
}

@@ -47,3 +47,3 @@ /**

call(subscriber, source) {
return source.subscribe(new GetKeySizeSubscriber(subscriber, this._source));
return source.subscribe(new GetKeySizeSubscriber(subscriber));
}

@@ -59,7 +59,5 @@ }

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination, _source) {
constructor(destination) {
super(destination);
this._source = _source;
}

@@ -69,17 +67,14 @@ /**

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.getKeySize();
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.getKeySize());
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -86,0 +81,0 @@ }

@@ -7,4 +7,4 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
export declare function getMaxMessageSize<T>(): Observable<T>;
export declare function getMaxMessageSize<NodeRSA>(): Observable<number>;

@@ -18,8 +18,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
function getMaxMessageSize() {
return this.lift(new GetMaxMessageSizeOperator(this));
return higherOrder()(this);
}
exports.getMaxMessageSize = getMaxMessageSize;
function higherOrder() {
return (source) => source.lift(new GetMaxMessageSizeOperator());
}
/**

@@ -31,7 +34,4 @@ * Operator class definition

* Class constructor
*
* @param _source subscriber source
*/
constructor(_source) {
this._source = _source;
constructor() {
}

@@ -47,3 +47,3 @@ /**

call(subscriber, source) {
return source.subscribe(new GetMaxMessageSizeSubscriber(subscriber, this._source));
return source.subscribe(new GetMaxMessageSizeSubscriber(subscriber));
}

@@ -59,7 +59,5 @@ }

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination, _source) {
constructor(destination) {
super(destination);
this._source = _source;
}

@@ -69,17 +67,14 @@ /**

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.getMaxMessageSize();
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.getMaxMessageSize());
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -86,0 +81,0 @@ }

@@ -12,4 +12,4 @@ /// <reference types="node-rsa" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
export declare function importKey<T>(key: Key, format?: Format): Observable<T>;
export declare function importKey<NodeRSA>(key: Key, format?: Format): Observable<NodeRSA>;

@@ -21,8 +21,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
function importKey(key, format) {
return this.lift(new ImportKeyOperator(this, key, format));
return higherOrder(key, format)(this);
}
exports.importKey = importKey;
function higherOrder(key, format) {
return (source) => source.lift(new ImportKeyOperator(key, format));
}
/**

@@ -35,8 +38,6 @@ * Operator class definition

*
* @param _source subscriber source
* @param _key key from PEM string, PEM/DER Buffer or components
* @param _format key format
*/
constructor(_source, _key, _format) {
this._source = _source;
constructor(_key, _format) {
this._key = _key;

@@ -54,3 +55,3 @@ this._format = _format;

call(subscriber, source) {
return source.subscribe(new ImportKeySubscriber(subscriber, this._source, this._key, this._format));
return source.subscribe(new ImportKeySubscriber(subscriber, this._key, this._format));
}

@@ -66,9 +67,7 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _key key from PEM string, PEM/DER Buffer or components
* @param _format key format
*/
constructor(destination, _source, _key, _format) {
constructor(destination, _key, _format) {
super(destination);
this._source = _source;
this._key = _key;

@@ -80,17 +79,15 @@ this._format = _format;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
nodeRSA.importKey(this._key, this._format);
this.destination.next(nodeRSA);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
nodeRSA.importKey(this._key, this._format);
this.destination.next(nodeRSA);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -97,0 +94,0 @@ }

@@ -7,4 +7,4 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
export declare function isEmptyKey<T>(): Observable<T>;
export declare function isEmptyKey<NodeRSA>(): Observable<boolean>;

@@ -18,8 +18,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
function isEmptyKey() {
return this.lift(new IsEmptyKeyOperator(this));
return higherOrder()(this);
}
exports.isEmptyKey = isEmptyKey;
function higherOrder() {
return (source) => source.lift(new IsEmptyKeyOperator());
}
/**

@@ -31,7 +34,4 @@ * Operator class definition

* Class constructor
*
* @param _source subscriber source
*/
constructor(_source) {
this._source = _source;
constructor() {
}

@@ -47,3 +47,3 @@ /**

call(subscriber, source) {
return source.subscribe(new IsEmptyKeySubscriber(subscriber, this._source));
return source.subscribe(new IsEmptyKeySubscriber(subscriber));
}

@@ -59,7 +59,5 @@ }

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination, _source) {
constructor(destination) {
super(destination);
this._source = _source;
}

@@ -69,17 +67,14 @@ /**

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.isEmpty();
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.isEmpty());
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -86,0 +81,0 @@ }

@@ -5,4 +5,6 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* Return true if key is private.
*
* @return {Observable<boolean>}
*/
export declare function isPrivate<T>(): Observable<T>;
export declare function isPrivate<NodeRSA>(): Observable<boolean>;

@@ -16,8 +16,13 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* Return true if key is private.
*
* @return {Observable<boolean>}
*/
function isPrivate() {
return this.lift(new IsPrivateOperator(this));
return higherOrder()(this);
}
exports.isPrivate = isPrivate;
function higherOrder() {
return (source) => source.lift(new IsPrivateOperator());
}
/**

@@ -29,7 +34,4 @@ * Operator class definition

* Class constructor
*
* @param _source subscriber source
*/
constructor(_source) {
this._source = _source;
constructor() {
}

@@ -45,3 +47,3 @@ /**

call(subscriber, source) {
return source.subscribe(new IsPrivateSubscriber(subscriber, this._source));
return source.subscribe(new IsPrivateSubscriber(subscriber));
}

@@ -57,7 +59,5 @@ }

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination, _source) {
constructor(destination) {
super(destination);
this._source = _source;
}

@@ -67,17 +67,14 @@ /**

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.isPrivate();
this.destination.next(!!k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(!!nodeRSA.isPrivate());
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -84,0 +81,0 @@ }

@@ -7,4 +7,4 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
export declare function isPublic<T>(strict?: boolean): Observable<T>;
export declare function isPublic<NodeRSA>(strict?: boolean): Observable<boolean>;

@@ -18,8 +18,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
function isPublic(strict) {
return this.lift(new IsPublicOperator(this, strict));
return higherOrder(strict)(this);
}
exports.isPublic = isPublic;
function higherOrder(strict) {
return (source) => source.lift(new IsPublicOperator(strict));
}
/**

@@ -32,7 +35,5 @@ * Operator class definition

*
* @param _source subscriber source
* @param _strict if true method will return false if key pair have private exponent. Default false.
*/
constructor(_source, _strict) {
this._source = _source;
constructor(_strict) {
this._strict = _strict;

@@ -49,3 +50,3 @@ }

call(subscriber, source) {
return source.subscribe(new IsPublicSubscriber(subscriber, this._source, this._strict));
return source.subscribe(new IsPublicSubscriber(subscriber, this._strict));
}

@@ -61,8 +62,6 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _strict if true method will return false if key pair have private exponent. Default false.
*/
constructor(destination, _source, _strict) {
constructor(destination, _strict) {
super(destination);
this._source = _source;
this._strict = _strict;

@@ -73,17 +72,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.isPublic(this._strict);
this.destination.next(!!k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(!!nodeRSA.isPublic(this._strict));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -90,0 +86,0 @@ }

@@ -14,4 +14,4 @@ /// <reference types="node-rsa" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function sign<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T>;
export declare function sign<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R>;

@@ -22,8 +22,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function sign(data, encoding, sourceEncoding) {
return this.lift(new SignOperator(this, data, encoding, sourceEncoding));
return higherOrder(data, encoding, sourceEncoding)(this);
}
exports.sign = sign;
function higherOrder(data, encoding, sourceEncoding) {
return (source) => source.lift(new SignOperator(data, encoding, sourceEncoding));
}
/**

@@ -36,3 +39,2 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for signing. Object and array will convert to JSON string.

@@ -42,4 +44,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(_source, _data, _encoding, _sourceEncoding) {
this._source = _source;
constructor(_data, _encoding, _sourceEncoding) {
this._data = _data;

@@ -58,3 +59,3 @@ this._encoding = _encoding;

call(subscriber, source) {
return source.subscribe(new SignSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
return source.subscribe(new SignSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -70,3 +71,2 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for signing. Object and array will convert to JSON string.

@@ -76,5 +76,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination, _source, _data, _encoding, _sourceEncoding) {
constructor(destination, _data, _encoding, _sourceEncoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -87,17 +86,14 @@ this._encoding = _encoding;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.sign(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.sign(this._data, this._encoding, this._sourceEncoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -104,0 +100,0 @@ }

@@ -16,4 +16,4 @@ /// <reference types="node-rsa" />

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export declare function verify<T>(data: Data | Buffer, signature: string | Buffer, sourceEncoding?: Encoding, signatureEncoding?: Encoding): Observable<T>;
export declare function verify<NodeRSA, R>(data: Data | Buffer, signature: string | Buffer, sourceEncoding?: Encoding, signatureEncoding?: Encoding): Observable<R>;

@@ -24,8 +24,11 @@ (function (factory) {

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
function verify(data, signature, sourceEncoding, signatureEncoding) {
return this.lift(new VerifyOperator(this, data, signature, sourceEncoding, signatureEncoding));
return higherOrder(data, signature, sourceEncoding, signatureEncoding)(this);
}
exports.verify = verify;
function higherOrder(data, signature, sourceEncoding, signatureEncoding) {
return (source) => source.lift(new VerifyOperator(data, signature, sourceEncoding, signatureEncoding));
}
/**

@@ -38,3 +41,2 @@ * Operator class definition

*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - signed data.

@@ -46,4 +48,3 @@ * @param _signature {string|Buffer} - signature from sign method.

*/
constructor(_source, _data, _signature, _sourceEncoding, _signatureEncoding) {
this._source = _source;
constructor(_data, _signature, _sourceEncoding, _signatureEncoding) {
this._data = _data;

@@ -63,3 +64,3 @@ this._signature = _signature;

call(subscriber, source) {
return source.subscribe(new VerifySubscriber(subscriber, this._source, this._data, this._signature, this._sourceEncoding, this._signatureEncoding));
return source.subscribe(new VerifySubscriber(subscriber, this._data, this._signature, this._sourceEncoding, this._signatureEncoding));
}

@@ -75,3 +76,2 @@ }

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - signed data.

@@ -83,5 +83,4 @@ * @param _signature {string|Buffer} - signature from sign method.

*/
constructor(destination, _source, _data, _signature, _sourceEncoding, _signatureEncoding) {
constructor(destination, _data, _signature, _sourceEncoding, _signatureEncoding) {
super(destination);
this._source = _source;
this._data = _data;

@@ -95,17 +94,14 @@ this._signature = _signature;

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
_next(value) {
this._source.subscribe((nodeRSA) => {
try {
const k = nodeRSA.verify(this._data, this._signature, this._sourceEncoding, this._signatureEncoding);
this.destination.next(k);
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
});
_next(nodeRSA) {
try {
this.destination.next(nodeRSA.verify(this._data, this._signature, this._sourceEncoding, this._signatureEncoding));
this.destination.complete();
}
catch (e) {
this.destination.error(e);
}
}

@@ -112,0 +108,0 @@ }

@@ -1,1 +0,1 @@

{"name":"@hapiness/crypto","version":"1.0.0-rc.6.2","description":"Crypto module provides some functions for security features like AES key, Key pair, RSA key, PKCS12, Certificate, PEM and more","main":"index.js","types":"index.d.ts","private":false,"repository":{"type":"git","url":"git@github.com:hapinessjs/crypto-module.git"},"keywords":["Crypto","RSA","PEM","PrivateKey","PublicKey","Certificate","RandomString","AES","PKCS12","KeyPair","JWT","Hapiness","Framework","NodeJS","Node","HTTP","API","REST","Streams","Async","Decorator","RxJS","Rx","ReactiveX","Observable","Observer","Module","ES2015","ES2016","ES2017","ES6","ES7","ES8","Typescript"],"contributors":[{"name":"Julien Fauville","url":"https://github.com/Juneil"},{"name":"Antoine Gomez","url":"https://github.com/antoinegomez"},{"name":"Sébastien Ritz","url":"https://github.com/srz09"},{"name":"Nicolas Jessel","url":"https://github.com/njl07"}],"license":"SEE LICENSE IN https://github.com/hapinessjs/crypto-module/blob/master/LICENSE.md","bugs":{"url":"https://github.com/hapinessjs/crypto-module/issues"},"homepage":"https://github.com/hapinessjs/crypto-module#readme","dependencies":{"@types/jsonwebtoken":"^7.2.2","@types/node":"^8.0.17","@types/node-rsa":"^0.4.0","@types/pem":"^1.9.2","@types/randomstring":"^1.1.6","jsonwebtoken":"^7.4.1","node-rsa":"^0.4.2","pem":"^1.9.7","randomstring":"^1.1.5"},"peerDependencies":{"@hapiness/core":"^1.0.0-rc.6","rxjs":"^5.4.2"},"engines":{"node":">=7.0.0"}}
{"name":"@hapiness/crypto","version":"1.0.0-rc.7","description":"Crypto module provides some functions for security features like AES key, Key pair, RSA key, PKCS12, Certificate, PEM and more","main":"index.js","types":"index.d.ts","private":false,"repository":{"type":"git","url":"git@github.com:hapinessjs/crypto-module.git"},"keywords":["Crypto","RSA","PEM","PrivateKey","PublicKey","Certificate","RandomString","AES","PKCS12","KeyPair","JWT","Hapiness","Framework","NodeJS","Node","HTTP","API","REST","Streams","Async","Decorator","RxJS","Rx","ReactiveX","Observable","Observer","Module","ES2015","ES2016","ES2017","ES6","ES7","ES8","Typescript"],"contributors":[{"name":"Julien Fauville","url":"https://github.com/Juneil"},{"name":"Antoine Gomez","url":"https://github.com/antoinegomez"},{"name":"Sébastien Ritz","url":"https://github.com/srz09"},{"name":"Nicolas Jessel","url":"https://github.com/njl07"}],"license":"SEE LICENSE IN https://github.com/hapinessjs/crypto-module/blob/master/LICENSE.md","bugs":{"url":"https://github.com/hapinessjs/crypto-module/issues"},"homepage":"https://github.com/hapinessjs/crypto-module#readme","dependencies":{"@types/jsonwebtoken":"^7.2.3","@types/node":"^8.0.30","@types/node-rsa":"^0.4.0","@types/pem":"^1.9.2","@types/randomstring":"^1.1.6","jsonwebtoken":"^8.0.1","node-rsa":"^0.4.2","pem":"^1.11.2","randomstring":"^1.1.5"},"peerDependencies":{"@hapiness/core":"1.0.0-rc.7","rxjs":"^5.4.3"},"engines":{"node":">=7.0.0"}}

@@ -68,5 +68,5 @@ <img src="http://bit.ly/2mxmKKI" width="500" alt="Hapiness" />

"dependencies": {
"@hapiness/core": "^1.0.0-rc.6",
"@hapiness/crypto": "^1.0.0-rc.6.2",
"rxjs": "^5.4.2",
"@hapiness/core": "^1.0.0-rc.7",
"@hapiness/crypto": "^1.0.0-rc.7",
"rxjs": "^5.4.3",
//...

@@ -97,3 +97,3 @@ }

You can use `AESService`, `HashService`, `PEMService`, `RandomstringService` and `RSAService` anywhere in your module with **dependency injection**.
You can use `AESService`, `HashService`, `PEMService`, `RandomstringService`, `JWTService` and `RSAService` anywhere in your module with **dependency injection**.

@@ -147,2 +147,9 @@ ```javascript

* v1.0.0-rc.7 (2017-09-26)
* Implementation of `PemService.checkPkcs12()` and `PemService.checkCertificate()`.
* Fix all operators related to latest `rxjs` version.
* Related tests.
* Latest packages' versions.
* Documentation.
* Module version related to core version.
* v1.0.0-rc.6.2 (2017-08-02)

@@ -163,3 +170,3 @@ * Implementation of `JWTService`

<tr>
<td colspan="4" align="center"><a href="https://www.tadaweb.com"><img src="https://tadaweb.com/images/tadaweb/logo.png" width="117" alt="tadaweb" /></a></td>
<td colspan="4" align="center"><a href="https://www.tadaweb.com"><img src="http://bit.ly/2xHQkTi" width="117" alt="tadaweb" /></a></td>
</tr>

@@ -166,0 +173,0 @@ <tr>

@@ -6,3 +6,3 @@ import { CoreModuleWithProviders, HapinessModule } from '@hapiness/core';

@HapinessModule({
version: '1.0.0-rc.6.2',
version: '1.0.0-rc.7',
exports: [

@@ -9,0 +9,0 @@ RandomstringService,

@@ -36,3 +36,3 @@ import { Injectable } from '@hapiness/core';

// clone buffer
const keyBuffer = new Buffer(derivedKey);
const keyBuffer = Buffer.from(derivedKey);

@@ -39,0 +39,0 @@ // get aes256 key

import { Injectable } from '@hapiness/core';
import { Observable } from 'rxjs/Observable';
import { pbkdf2 } from 'crypto';
import { Buffer } from 'buffer';
import 'rxjs/add/observable/bindNodeCallback';

@@ -6,0 +5,0 @@

@@ -263,2 +263,15 @@ import { Observable } from 'rxjs/Observable';

/**
* Verifies a PKCS12 keystore.
*
* @param {string} bufferOrPath is a PKCS12 keystore as a Buffer or the path to a file
* @param {string} [passphrase] is an optional passphrase which will be used to open the keystore
*
* @return {Observable<boolean>}
*/
checkPkcs12(bufferOrPath: string, passphrase?: string): Observable<boolean> {
return (<(bufferOrPath: string, passphrase?: string) =>
Observable<boolean>> Observable.bindNodeCallback((<any>pem).checkPkcs12))(bufferOrPath, passphrase);
}
/**
* Verifies the signing chain of the passed certificate

@@ -275,2 +288,15 @@ *

}
/**
* Check / verify consistency of a certificate.
*
* @param {string} certificate is a PEM encoded certificate string
* @param {string} [passphrase] is an optional passphrase which will be used to open the certificate
*
* @return {Observable<boolean>}
*/
checkCertificate(certificate: string, passphrase?: string): Observable<boolean> {
return (<(certificate: string, passphrase?: string) =>
Observable<boolean>> Observable.bindNodeCallback((<any>pem).checkCertificate))(certificate, passphrase);
}
}

@@ -277,0 +303,0 @@

@@ -6,2 +6,3 @@ import { Observable } from 'rxjs/Observable';

import { Decipher, createDecipheriv } from 'crypto';
import { AESKeyCreationResult } from '../../..';

@@ -15,19 +16,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of decrypted data
* @return {Observable<Buffer>} Buffer of decrypted data
*/
export function decryptWithAesKey<T>(data: Buffer): Observable<T> {
return this.lift(new DecryptWithAesKeyOperator(this, data));
export function decryptWithAesKey<AESKeyCreationResult>(this: Observable<AESKeyCreationResult>, data: Buffer): Observable<Buffer> {
return higherOrder<AESKeyCreationResult>(data)(this);
}
function higherOrder<AESKeyCreationResult>(data: Buffer): (source: Observable<AESKeyCreationResult>) => Observable<Buffer> {
return (source: Observable<AESKeyCreationResult>) => <Observable<Buffer>> source.lift(new DecryptWithAesKeyOperator(data));
}
/**
* Operator class definition
*/
class DecryptWithAesKeyOperator<T> implements Operator<T, T> {
class DecryptWithAesKeyOperator<R> implements Operator<AESKeyCreationResult, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(private _source: Observable<T>, private _data: Buffer) {
constructor(private _data: Buffer) {
}

@@ -43,4 +47,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new DecryptWithAesKeySubscriber(subscriber, this._source, this._data));
call(subscriber: Subscriber<R>, source: Observable<AESKeyCreationResult>): any {
return source.subscribe(new DecryptWithAesKeySubscriber(subscriber, this._data));
}

@@ -52,3 +56,3 @@ }

*/
class DecryptWithAesKeySubscriber<T> extends Subscriber<T> {
class DecryptWithAesKeySubscriber<R> extends Subscriber<AESKeyCreationResult> {
/**

@@ -58,6 +62,5 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _data: Buffer) {
constructor(destination: Subscriber<R>, private _data: Buffer) {
super(destination);

@@ -69,21 +72,18 @@ }

*
* @param value result for next subscriber
* @param aesKey key from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((aesKey: any) => {
try {
const decipher: Decipher = createDecipheriv('aes-256-cbc', new Buffer(aesKey.key, 'hex'), new Buffer(aesKey.iv, 'hex'));
const bufDecrypted: Buffer = decipher.update(new Buffer(this._data));
const bufFinal: Buffer = decipher.final();
protected _next(aesKey: AESKeyCreationResult): void {
try {
const decipher: Decipher = createDecipheriv('aes-256-cbc', Buffer.from(aesKey.key, 'hex'), Buffer.from(aesKey.iv, 'hex'));
const bufDecrypted: Buffer = decipher.update(Buffer.from(this._data));
const bufFinal: Buffer = decipher.final();
this.destination.next(Buffer.concat([bufDecrypted, bufFinal]));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
this.destination.next(Buffer.concat([bufDecrypted, bufFinal]));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}

@@ -6,2 +6,3 @@ import { Observable } from 'rxjs/Observable';

import { Cipher, createCipheriv } from 'crypto';
import { AESKeyCreationResult } from '../../..';

@@ -15,19 +16,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>} Buffer of encrypted data
* @return {Observable<Buffer>} Buffer of encrypted data
*/
export function encryptWithAesKey<T>(data: Buffer): Observable<T> {
return this.lift(new EncryptWithAesKeyOperator(this, data));
export function encryptWithAesKey<AESKeyCreationResult>(data: Buffer): Observable<Buffer> {
return higherOrder<AESKeyCreationResult>(data)(this);
}
function higherOrder<AESKeyCreationResult>(data: Buffer): (source: Observable<AESKeyCreationResult>) => Observable<Buffer> {
return (source: Observable<AESKeyCreationResult>) => <Observable<Buffer>> source.lift(new EncryptWithAesKeyOperator(data));
}
/**
* Operator class definition
*/
class EncryptWithAesKeyOperator<T> implements Operator<T, T> {
class EncryptWithAesKeyOperator<R> implements Operator<AESKeyCreationResult, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(private _source: Observable<T>, private _data: Buffer) {
constructor(private _data: Buffer) {
}

@@ -43,4 +47,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new EncryptWithAesKeySubscriber(subscriber, this._source, this._data));
call(subscriber: Subscriber<R>, source: Observable<AESKeyCreationResult>): any {
return source.subscribe(new EncryptWithAesKeySubscriber(subscriber, this._data));
}

@@ -52,3 +56,3 @@ }

*/
class EncryptWithAesKeySubscriber<T> extends Subscriber<T> {
class EncryptWithAesKeySubscriber<R> extends Subscriber<AESKeyCreationResult> {
/**

@@ -58,6 +62,5 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - data for encrypting.
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _data: Buffer) {
constructor(destination: Subscriber<R>, private _data: Buffer) {
super(destination);

@@ -69,21 +72,18 @@ }

*
* @param value result for next subscriber
* @param aesKey key from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((aesKey: any) => {
try {
const cipher: Cipher = createCipheriv('aes-256-cbc', new Buffer(aesKey.key, 'hex'), new Buffer(aesKey.iv, 'hex'));
const bufEncrypted: Buffer = cipher.update(new Buffer(this._data));
const bufFinal: Buffer = cipher.final();
protected _next(aesKey: AESKeyCreationResult): void {
try {
const cipher: Cipher = createCipheriv('aes-256-cbc', Buffer.from(aesKey.key, 'hex'), Buffer.from(aesKey.iv, 'hex'));
const bufEncrypted: Buffer = cipher.update(Buffer.from(this._data));
const bufFinal: Buffer = cipher.final();
this.destination.next(Buffer.concat([bufEncrypted, bufFinal]));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
this.destination.next(Buffer.concat([bufEncrypted, bufFinal]));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -15,20 +15,24 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function decryptPrivate<T>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<T> {
return this.lift(new DecryptPrivateOperator(this, data, encoding));
export function decryptPrivate<NodeRSA, R>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<R> {
return higherOrder<NodeRSA, R>(data, encoding)(this);
}
function higherOrder<NodeRSA, R>(data: Buffer | string,
encoding?: 'buffer' | Encoding | 'json'): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) => <Observable<R>> source.lift(new DecryptPrivateOperator(data, encoding));
}
/**
* Operator class definition
*/
class DecryptPrivateOperator<T> implements Operator<T, T> {
class DecryptPrivateOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(private _source: Observable<T>, private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
constructor(private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
}

@@ -44,4 +48,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new DecryptPrivateSubscriber(subscriber, this._source, this._data, this._encoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new DecryptPrivateSubscriber(subscriber, this._data, this._encoding));
}

@@ -53,3 +57,3 @@ }

*/
class DecryptPrivateSubscriber<T> extends Subscriber<T> {
class DecryptPrivateSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -59,8 +63,6 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
constructor(destination: Subscriber<R>, private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
super(destination);

@@ -72,18 +74,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).decrypt(this._data, this._encoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.decrypt(this._data, <any> this._encoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -15,20 +15,24 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function decryptPublic<T>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<T> {
return this.lift(new DecryptPublicOperator(this, data, encoding));
export function decryptPublic<NodeRSA, R>(data: Buffer | string, encoding?: 'buffer' | Encoding | 'json'): Observable<R> {
return higherOrder<NodeRSA, R>(data, encoding)(this);
}
function higherOrder<NodeRSA, R>(data: Buffer | string,
encoding?: 'buffer' | Encoding | 'json'): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) => <Observable<R>> source.lift(new DecryptPublicOperator(data, encoding));
}
/**
* Operator class definition
*/
class DecryptPublicOperator<T> implements Operator<T, T> {
class DecryptPublicOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(private _source: Observable<T>, private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
constructor(private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
}

@@ -44,4 +48,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new DecryptPublicSubscriber(subscriber, this._source, this._data, this._encoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new DecryptPublicSubscriber(subscriber, this._data, this._encoding));
}

@@ -53,3 +57,3 @@ }

*/
class DecryptPublicSubscriber<T> extends Subscriber<T> {
class DecryptPublicSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -59,8 +63,6 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {Buffer} - buffer for decrypting
* @param _encoding - encoding for result string, can also take 'json' or 'buffer' for the automatic conversion of this type
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
constructor(destination: Subscriber<R>, private _data: Buffer | string, private _encoding?: 'buffer' | Encoding | 'json') {
super(destination);

@@ -72,18 +74,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).decryptPublic(this._data, this._encoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.decryptPublic(this._data, <any> this._encoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding, Data } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -16,16 +16,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function encryptPrivate<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T> {
return this.lift(new EncryptPrivateOperator(this, data, encoding, sourceEncoding));
export function encryptPrivate<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R> {
return higherOrder<NodeRSA, R>(data, encoding, sourceEncoding)(this);
}
function higherOrder<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding,
sourceEncoding?: Encoding): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) => <Observable<R>> source.lift(new EncryptPrivateOperator(data, encoding, sourceEncoding));
}
/**
* Operator class definition
*/
class EncryptPrivateOperator<T> implements Operator<T, T> {
class EncryptPrivateOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -35,4 +39,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
}

@@ -48,4 +51,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new EncryptPrivateSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new EncryptPrivateSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -57,3 +60,3 @@ }

*/
class EncryptPrivateSubscriber<T> extends Subscriber<T> {
class EncryptPrivateSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -63,3 +66,2 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -69,4 +71,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(destination: Subscriber<R>, private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding,
private _sourceEncoding?: Encoding) {
super(destination);

@@ -78,18 +80,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).encryptPrivate(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.encryptPrivate(<any> this._data, <any> this._encoding, this._sourceEncoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding, Data } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -16,16 +16,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function encryptPublic<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T> {
return this.lift(new EncryptPublicOperator(this, data, encoding, sourceEncoding));
export function encryptPublic<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R> {
return higherOrder<NodeRSA, R>(data, encoding, sourceEncoding)(this);
}
function higherOrder<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding,
sourceEncoding?: Encoding): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) => <Observable<R>> source.lift(new EncryptPublicOperator(data, encoding, sourceEncoding));
}
/**
* Operator class definition
*/
class EncryptPublicOperator<T> implements Operator<T, T> {
class EncryptPublicOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -35,4 +39,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
}

@@ -48,4 +51,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new EncryptPublicSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new EncryptPublicSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -57,3 +60,3 @@ }

*/
class EncryptPublicSubscriber<T> extends Subscriber<T> {
class EncryptPublicSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -63,3 +66,2 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.

@@ -69,4 +71,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(destination: Subscriber<R>, private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding,
private _sourceEncoding?: Encoding) {
super(destination);

@@ -78,18 +80,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).encrypt(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.encrypt(<any> this._data, <any> this._encoding, this._sourceEncoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import { Format } from 'node-rsa';
import * as NodeRSA from 'node-rsa';
import { Format, Key } from 'node-rsa';

@@ -13,19 +14,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<Key>}
*/
export function exportKey<T>(format?: Format): Observable<T> {
return this.lift(new ExportKeyOperator(this, format));
export function exportKey<NodeRSA>(format?: Format): Observable<Key> {
return higherOrder<NodeRSA>(format)(this);
}
function higherOrder<NodeRSA>(format?: Format): (source: Observable<NodeRSA>) => Observable<Key> {
return (source: Observable<NodeRSA>) => <Observable<Key>> source.lift(new ExportKeyOperator(format));
}
/**
* Operator class definition
*/
class ExportKeyOperator<T> implements Operator<T, T> {
class ExportKeyOperator<Key> implements Operator<NodeRSA, Key> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _format key format
*/
constructor(private _source: Observable<T>, private _format?: Format) {
constructor(private _format?: Format) {
}

@@ -41,4 +45,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new ExportKeySubscriber(subscriber, this._source, this._format));
call(subscriber: Subscriber<Key>, source: Observable<NodeRSA>): any {
return source.subscribe(new ExportKeySubscriber(subscriber, this._format));
}

@@ -50,3 +54,3 @@ }

*/
class ExportKeySubscriber<T> extends Subscriber<T> {
class ExportKeySubscriber<Key> extends Subscriber<NodeRSA> {
/**

@@ -56,6 +60,5 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _format key format
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _format?: Format) {
constructor(destination: Subscriber<Key>, private _format?: Format) {
super(destination);

@@ -67,18 +70,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).exportKey(this._format);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.exportKey(this._format));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}

@@ -11,20 +11,23 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
export function generateKeyPair<T>(bits?: number, exponent?: number): Observable<T> {
return this.lift(new GenerateKeyPairOperator(this, bits, exponent));
export function generateKeyPair<NodeRSA>(bits?: number, exponent?: number): Observable<NodeRSA> {
return higherOrder<NodeRSA>(bits, exponent)(this);
}
function higherOrder<NodeRSA>(bits?: number, exponent?: number): (source: Observable<NodeRSA>) => Observable<NodeRSA> {
return (source: Observable<NodeRSA>) => <Observable<NodeRSA>> source.lift(new GenerateKeyPairOperator(bits, exponent));
}
/**
* Operator class definition
*/
class GenerateKeyPairOperator<T> implements Operator<T, T> {
class GenerateKeyPairOperator<NodeRSA> implements Operator<NodeRSA, NodeRSA> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _bits Key size in bits. 2048 by default.
* @param _exponent public exponent. 65537 by default.
*/
constructor(private _source: Observable<T>, private _bits?: number, private _exponent?: number) {
constructor(private _bits?: number, private _exponent?: number) {
}

@@ -40,4 +43,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new GenerateKeyPairSubscriber(subscriber, this._source, this._bits, this._exponent));
call(subscriber: Subscriber<NodeRSA>, source: Observable<NodeRSA>): any {
return source.subscribe(new GenerateKeyPairSubscriber(subscriber, this._bits, this._exponent));
}

@@ -49,3 +52,3 @@ }

*/
class GenerateKeyPairSubscriber<T> extends Subscriber<T> {
class GenerateKeyPairSubscriber<NodeRSA> extends Subscriber<NodeRSA> {
/**

@@ -55,7 +58,6 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _bits Key size in bits. 2048 by default.
* @param _exponent public exponent. 65537 by default.
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _bits?: number, private _exponent?: number) {
constructor(destination: Subscriber<NodeRSA>, private _bits?: number, private _exponent?: number) {
super(destination);

@@ -67,18 +69,15 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
(<any> nodeRSA).generateKeyPair(this._bits, this._exponent);
this.destination.next(nodeRSA);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
(<any> nodeRSA).generateKeyPair(this._bits, this._exponent);
this.destination.next(nodeRSA);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';

@@ -10,18 +11,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
export function getKeySize<T>(): Observable<T> {
return this.lift(new GetKeySizeOperator(this));
export function getKeySize<NodeRSA>(): Observable<number> {
return higherOrder<NodeRSA>()(this);
}
function higherOrder<NodeRSA>(): (source: Observable<NodeRSA>) => Observable<number> {
return (source: Observable<NodeRSA>) => <Observable<number>> source.lift(new GetKeySizeOperator());
}
/**
* Operator class definition
*/
class GetKeySizeOperator<T> implements Operator<T, T> {
class GetKeySizeOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
*/
constructor(private _source: Observable<T>) {
constructor() {
}

@@ -37,4 +40,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new GetKeySizeSubscriber(subscriber, this._source));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new GetKeySizeSubscriber(subscriber));
}

@@ -46,3 +49,3 @@ }

*/
class GetKeySizeSubscriber<T> extends Subscriber<T> {
class GetKeySizeSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -52,5 +55,4 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>) {
constructor(destination: Subscriber<R>) {
super(destination);

@@ -62,18 +64,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).getKeySize();
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.getKeySize());
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';

@@ -10,18 +11,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<number>}
*/
export function getMaxMessageSize<T>(): Observable<T> {
return this.lift(new GetMaxMessageSizeOperator(this));
export function getMaxMessageSize<NodeRSA>(): Observable<number> {
return higherOrder<NodeRSA>()(this);
}
function higherOrder<NodeRSA>(): (source: Observable<NodeRSA>) => Observable<number> {
return (source: Observable<NodeRSA>) => <Observable<number>> source.lift(new GetMaxMessageSizeOperator());
}
/**
* Operator class definition
*/
class GetMaxMessageSizeOperator<T> implements Operator<T, T> {
class GetMaxMessageSizeOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
*/
constructor(private _source: Observable<T>) {
constructor() {
}

@@ -37,4 +40,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new GetMaxMessageSizeSubscriber(subscriber, this._source));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new GetMaxMessageSizeSubscriber(subscriber));
}

@@ -46,3 +49,3 @@ }

*/
class GetMaxMessageSizeSubscriber<T> extends Subscriber<T> {
class GetMaxMessageSizeSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -52,5 +55,4 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>) {
constructor(destination: Subscriber<R>) {
super(destination);

@@ -62,18 +64,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).getMaxMessageSize();
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.getMaxMessageSize());
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}

@@ -14,20 +14,23 @@ import { Observable } from 'rxjs/Observable';

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<NodeRSA>}
*/
export function importKey<T>(key: Key, format?: Format): Observable<T> {
return this.lift(new ImportKeyOperator(this, key, format));
export function importKey<NodeRSA>(key: Key, format?: Format): Observable<NodeRSA> {
return higherOrder<NodeRSA>(key, format)(this);
}
function higherOrder<NodeRSA>(key: Key, format?: Format): (source: Observable<NodeRSA>) => Observable<NodeRSA> {
return (source: Observable<NodeRSA>) => <Observable<NodeRSA>> source.lift(new ImportKeyOperator(key, format));
}
/**
* Operator class definition
*/
class ImportKeyOperator<T> implements Operator<T, T> {
class ImportKeyOperator<NodeRSA> implements Operator<NodeRSA, NodeRSA> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _key key from PEM string, PEM/DER Buffer or components
* @param _format key format
*/
constructor(private _source: Observable<T>, private _key: Key, private _format?: Format) {
constructor(private _key: Key, private _format?: Format) {
}

@@ -43,4 +46,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new ImportKeySubscriber(subscriber, this._source, this._key, this._format));
call(subscriber: Subscriber<NodeRSA>, source: Observable<NodeRSA>): any {
return source.subscribe(new ImportKeySubscriber(subscriber, this._key, this._format));
}

@@ -52,3 +55,3 @@ }

*/
class ImportKeySubscriber<T> extends Subscriber<T> {
class ImportKeySubscriber<NodeRSA> extends Subscriber<NodeRSA> {
/**

@@ -58,7 +61,6 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _key key from PEM string, PEM/DER Buffer or components
* @param _format key format
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _key: Key, private _format?: Format) {
constructor(destination: Subscriber<NodeRSA>, private _key: Key, private _format?: Format) {
super(destination);

@@ -70,18 +72,15 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
(<any> nodeRSA).importKey(this._key, this._format);
this.destination.next(nodeRSA);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
(<any> nodeRSA).importKey(this._key, this._format);
this.destination.next(nodeRSA);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';

@@ -10,18 +11,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
export function isEmptyKey<T>(): Observable<T> {
return this.lift(new IsEmptyKeyOperator(this));
export function isEmptyKey<NodeRSA>(): Observable<boolean> {
return higherOrder<NodeRSA>()(this);
}
function higherOrder<NodeRSA>(): (source: Observable<NodeRSA>) => Observable<boolean> {
return (source: Observable<NodeRSA>) => <Observable<boolean>> source.lift(new IsEmptyKeyOperator());
}
/**
* Operator class definition
*/
class IsEmptyKeyOperator<T> implements Operator<T, T> {
class IsEmptyKeyOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
*/
constructor(private _source: Observable<T>) {
constructor() {
}

@@ -37,4 +40,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new IsEmptyKeySubscriber(subscriber, this._source));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new IsEmptyKeySubscriber(subscriber));
}

@@ -46,3 +49,3 @@ }

*/
class IsEmptyKeySubscriber<T> extends Subscriber<T> {
class IsEmptyKeySubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -52,5 +55,4 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>) {
constructor(destination: Subscriber<R>) {
super(destination);

@@ -62,18 +64,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).isEmpty();
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.isEmpty());
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';

@@ -8,18 +9,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* Return true if key is private.
*
* @return {Observable<boolean>}
*/
export function isPrivate<T>(): Observable<T> {
return this.lift(new IsPrivateOperator(this));
export function isPrivate<NodeRSA>(): Observable<boolean> {
return higherOrder<NodeRSA>()(this);
}
function higherOrder<NodeRSA>(): (source: Observable<NodeRSA>) => Observable<boolean> {
return (source: Observable<NodeRSA>) => <Observable<boolean>> source.lift(new IsPrivateOperator());
}
/**
* Operator class definition
*/
class IsPrivateOperator<T> implements Operator<T, T> {
class IsPrivateOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
*/
constructor(private _source: Observable<T>) {
constructor() {
}

@@ -35,4 +40,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new IsPrivateSubscriber(subscriber, this._source));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new IsPrivateSubscriber(subscriber));
}

@@ -44,3 +49,3 @@ }

*/
class IsPrivateSubscriber<T> extends Subscriber<T> {
class IsPrivateSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -50,5 +55,4 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>) {
constructor(destination: Subscriber<R>) {
super(destination);

@@ -60,18 +64,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).isPrivate();
this.destination.next(!!k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(!!nodeRSA.isPrivate());
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';

@@ -10,19 +11,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<boolean>}
*/
export function isPublic<T>(strict?: boolean): Observable<T> {
return this.lift(new IsPublicOperator(this, strict));
export function isPublic<NodeRSA>(strict?: boolean): Observable<boolean> {
return higherOrder<NodeRSA>(strict)(this);
}
function higherOrder<NodeRSA>(strict?: boolean): (source: Observable<NodeRSA>) => Observable<boolean> {
return (source: Observable<NodeRSA>) => <Observable<boolean>> source.lift(new IsPublicOperator(strict));
}
/**
* Operator class definition
*/
class IsPublicOperator<T> implements Operator<T, T> {
class IsPublicOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _strict if true method will return false if key pair have private exponent. Default false.
*/
constructor(private _source: Observable<T>, private _strict?: boolean) {
constructor(private _strict?: boolean) {
}

@@ -38,4 +42,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new IsPublicSubscriber(subscriber, this._source, this._strict));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new IsPublicSubscriber(subscriber, this._strict));
}

@@ -47,3 +51,3 @@ }

*/
class IsPublicSubscriber<T> extends Subscriber<T> {
class IsPublicSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -53,6 +57,5 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _strict if true method will return false if key pair have private exponent. Default false.
*/
constructor(destination: Subscriber<T>, private _source: Observable<T>, private _strict?: boolean) {
constructor(destination: Subscriber<R>, private _strict?: boolean) {
super(destination);

@@ -64,18 +67,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).isPublic(this._strict);
this.destination.next(!!k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(!!nodeRSA.isPublic(this._strict));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding, Data } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -16,16 +16,20 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function sign<T>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<T> {
return this.lift(new SignOperator(this, data, encoding, sourceEncoding));
export function sign<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding, sourceEncoding?: Encoding): Observable<R> {
return higherOrder<NodeRSA, R>(data, encoding, sourceEncoding)(this);
}
function higherOrder<NodeRSA, R>(data: Data | Buffer, encoding?: 'buffer' | Encoding,
sourceEncoding?: Encoding): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) => <Observable<R>> source.lift(new SignOperator(data, encoding, sourceEncoding));
}
/**
* Operator class definition
*/
class SignOperator<T> implements Operator<T, T> {
class SignOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for signing. Object and array will convert to JSON string.

@@ -35,4 +39,3 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
}

@@ -48,4 +51,4 @@

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new SignSubscriber(subscriber, this._source, this._data, this._encoding, this._sourceEncoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new SignSubscriber(subscriber, this._data, this._encoding, this._sourceEncoding));
}

@@ -57,3 +60,3 @@ }

*/
class SignSubscriber<T> extends Subscriber<T> {
class SignSubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -63,3 +66,2 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - data for signing. Object and array will convert to JSON string.

@@ -69,4 +71,4 @@ * @param _encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.

*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding, private _sourceEncoding?: Encoding) {
constructor(destination: Subscriber<R>, private _data: Data | Buffer, private _encoding?: 'buffer' | Encoding,
private _sourceEncoding?: Encoding) {
super(destination);

@@ -78,18 +80,14 @@ }

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).sign(this._data, this._encoding, this._sourceEncoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.sign(<any> this._data, <any> this._encoding, this._sourceEncoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import * as NodeRSA from 'node-rsa';
import { Encoding, Data } from 'node-rsa';
import { Buffer } from 'buffer';

@@ -18,17 +18,22 @@ /**

*
* @return {Observable<T>|WebSocketSubject<T>}
* @return {Observable<R>}
*/
export function verify<T>(data: Data | Buffer, signature: string | Buffer,
sourceEncoding?: Encoding, signatureEncoding?: Encoding): Observable<T> {
return this.lift(new VerifyOperator(this, data, signature, sourceEncoding, signatureEncoding));
export function verify<NodeRSA, R>(data: Data | Buffer, signature: string | Buffer,
sourceEncoding?: Encoding, signatureEncoding?: Encoding): Observable<R> {
return higherOrder<NodeRSA, R>(data, signature, sourceEncoding, signatureEncoding)(this);
}
function higherOrder<NodeRSA, R>(data: Data | Buffer, signature: string | Buffer,
sourceEncoding?: Encoding, signatureEncoding?: Encoding): (source: Observable<NodeRSA>) => Observable<R> {
return (source: Observable<NodeRSA>) =>
<Observable<R>> source.lift(new VerifyOperator(data, signature, sourceEncoding, signatureEncoding));
}
/**
* Operator class definition
*/
class VerifyOperator<T> implements Operator<T, T> {
class VerifyOperator<R> implements Operator<NodeRSA, R> {
/**
* Class constructor
*
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - signed data.

@@ -40,4 +45,3 @@ * @param _signature {string|Buffer} - signature from sign method.

*/
constructor(private _source: Observable<T>,
private _data: Data | Buffer, private _signature: string | Buffer,
constructor(private _data: Data | Buffer, private _signature: string | Buffer,
private _sourceEncoding?: Encoding, private _signatureEncoding?: Encoding) {

@@ -54,5 +58,5 @@ }

*/
call(subscriber: Subscriber<T>, source: any): any {
return source.subscribe(new VerifySubscriber(subscriber, this._source,
this._data, this._signature, this._sourceEncoding, this._signatureEncoding));
call(subscriber: Subscriber<R>, source: Observable<NodeRSA>): any {
return source.subscribe(new VerifySubscriber(subscriber, this._data, this._signature, this._sourceEncoding,
this._signatureEncoding));
}

@@ -64,3 +68,3 @@ }

*/
class VerifySubscriber<T> extends Subscriber<T> {
class VerifySubscriber<R> extends Subscriber<NodeRSA> {
/**

@@ -70,3 +74,2 @@ * Class constructor

* @param destination subscriber destination
* @param _source subscriber source
* @param _data {string|number|object|array|Buffer} - signed data.

@@ -78,4 +81,3 @@ * @param _signature {string|Buffer} - signature from sign method.

*/
constructor(destination: Subscriber<T>, private _source: Observable<T>,
private _data: Data | Buffer, private _signature: string | Buffer,
constructor(destination: Subscriber<R>, private _data: Data | Buffer, private _signature: string | Buffer,
private _sourceEncoding?: Encoding, private _signatureEncoding?: Encoding) {

@@ -88,18 +90,14 @@ super(destination);

*
* @param value result for next subscriber
* @param nodeRSA object from previous subscriber
*
* @private
*/
protected _next(value: T): void {
this._source.subscribe((nodeRSA) => {
try {
const k = (<any> nodeRSA).verify(this._data, this._signature, this._sourceEncoding, this._signatureEncoding);
this.destination.next(k);
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
);
protected _next(nodeRSA: NodeRSA): void {
try {
this.destination.next(nodeRSA.verify(this._data, <any> this._signature, <any> this._sourceEncoding, this._signatureEncoding));
this.destination.complete();
} catch (e) {
this.destination.error(e);
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc