From d5d80ee1b88648f19985954dce664963b732a6bb Mon Sep 17 00:00:00 2001 From: Vladislav Hristov Date: Tue, 12 Jun 2018 11:27:56 +0300 Subject: [PATCH] clean up the code --- lib/OrderBuilder.js | 12 ------------ lib/versions/H004/Response.js | 6 ------ lib/versions/H004/serializers/GenericSerializer.js | 12 +++++++++--- .../H004/serializers/InitializationSerializer.js | 4 ++-- lib/versions/H004/serializers/PaymentSerializer.js | 3 +-- lib/versions/H004/serializers/StatusSerializer.js | 3 +-- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/OrderBuilder.js b/lib/OrderBuilder.js index 3643090..5d23e62 100644 --- a/lib/OrderBuilder.js +++ b/lib/OrderBuilder.js @@ -7,8 +7,6 @@ const crypto = require('crypto'); module.exports = class OrderBuilder { constructor() { this._transactionKey = crypto.randomBytes(16); - this._root = {}; - this._body = {}; } details(data) { @@ -32,7 +30,6 @@ module.exports = class OrderBuilder { ini() { this._type = 'ini'; - this._root.nodeName = 'ebicsUnsecuredRequest'; return this; } @@ -41,13 +38,6 @@ module.exports = class OrderBuilder { const builder = new OrderBuilder(); builder._version = 'H004'; - builder._root.nodeName = 'ebicsRequest'; - builder._root.nodeAttributes = { - 'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#', - xmlns: 'urn:org:ebics:H004', - Version: 'H004', - Revision: '1', - }; return builder; } @@ -56,8 +46,6 @@ module.exports = class OrderBuilder { * Getters */ get type() { return this._type; } - get root() { return this._root; } - get body() { return this._body; } get data() { return this._data; } get orderDetails() { return this._data.orderDetails; } get transactionId() { return this._data.transactionId; } diff --git a/lib/versions/H004/Response.js b/lib/versions/H004/Response.js index cf2367b..506d892 100644 --- a/lib/versions/H004/Response.js +++ b/lib/versions/H004/Response.js @@ -105,12 +105,6 @@ module.exports = class Response { const exp = new BN(Buffer.from(exponent, 'base64')).toNumber(); bankKeys[`bank${type}`] = { mod, exp }; - - // const bank = new NodeRSA(); - - // bank.importKey({ n: mod, e: exp }, 'components-public'); - - // this.keys[`${this.hostId}.${type}`] = new Key(bank); } return bankKeys; diff --git a/lib/versions/H004/serializers/GenericSerializer.js b/lib/versions/H004/serializers/GenericSerializer.js index 8a2f7c5..39bc0e5 100644 --- a/lib/versions/H004/serializers/GenericSerializer.js +++ b/lib/versions/H004/serializers/GenericSerializer.js @@ -2,6 +2,7 @@ const js2xmlparser = require('js2xmlparser'); +const consts = require('../../../consts'); const xmlOptions = { declaration: { include: true, @@ -54,17 +55,22 @@ const authSignature = ({ module.exports = class GenericSerializer { constructor(orderBuilder) { this._order = orderBuilder; + this._rootName = 'ebicsRequest'; + this._rootAttributes = { + 'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#', + xmlns: 'urn:org:ebics:H004', + Version: 'H004', + Revision: '1', + }; this._orderDetails = orderBuilder.orderDetails; this._hostId = orderBuilder.hostId; this._partnerId = orderBuilder.partnerId; this._userId = orderBuilder.userId; this._keys = orderBuilder.keys; this._transactionId = orderBuilder.transactionId; - this._rootName = orderBuilder.root.nodeName; - this._rootAttributes = orderBuilder.root.nodeAttributes; - this._xmlOptions = xmlOptions; this._xml = {}; + this._productString = consts.productString; } static authSignature() { diff --git a/lib/versions/H004/serializers/InitializationSerializer.js b/lib/versions/H004/serializers/InitializationSerializer.js index f5dc57d..e09d573 100644 --- a/lib/versions/H004/serializers/InitializationSerializer.js +++ b/lib/versions/H004/serializers/InitializationSerializer.js @@ -3,7 +3,6 @@ const zlib = require('zlib'); const js2xmlparser = require('js2xmlparser'); -const consts = require('../../../consts'); const Crypto = require('../../../crypto/Crypto'); const GenericSerializer = require('./GenericSerializer'); @@ -24,7 +23,7 @@ module.exports = class InitializationSerializer extends GenericSerializer { UserID: this._userId, Product: { '@': { Language: 'en' }, - '#': consts.productString, + '#': this._productString, }, OrderDetails: this._orderDetails, SecurityMedium: '0000', @@ -37,6 +36,7 @@ module.exports = class InitializationSerializer extends GenericSerializer { delete this._xml.header.static.Nonce; delete this._xml.header.static.Timestamp; + this._rootName = 'ebicsUnsecuredRequest'; this._xml.body = { DataTransfer: { OrderData: this.orderData(), diff --git a/lib/versions/H004/serializers/PaymentSerializer.js b/lib/versions/H004/serializers/PaymentSerializer.js index 3ee4f33..c143439 100644 --- a/lib/versions/H004/serializers/PaymentSerializer.js +++ b/lib/versions/H004/serializers/PaymentSerializer.js @@ -5,7 +5,6 @@ const crypto = require('crypto'); const js2xmlparser = require('js2xmlparser'); -const consts = require('../../../consts'); const Crypto = require('../../../crypto/Crypto'); const GenericSerializer = require('./GenericSerializer'); @@ -28,7 +27,7 @@ module.exports = class PaymentSerializer extends GenericSerializer { UserID: this._userId, Product: { '@': { Language: 'en' }, - '#': consts.productString, + '#': this._productString, }, OrderDetails: this._orderDetails, BankPubKeyDigests: { diff --git a/lib/versions/H004/serializers/StatusSerializer.js b/lib/versions/H004/serializers/StatusSerializer.js index baab03e..580f036 100644 --- a/lib/versions/H004/serializers/StatusSerializer.js +++ b/lib/versions/H004/serializers/StatusSerializer.js @@ -1,6 +1,5 @@ 'use strict'; -const consts = require('../../../consts'); const Crypto = require('../../../crypto/Crypto'); const GenericSerializer = require('./GenericSerializer'); @@ -21,7 +20,7 @@ module.exports = class StatusSerializer extends GenericSerializer { UserID: this._userId, Product: { '@': { Language: 'en' }, - '#': consts.productString, + '#': this._productString, }, OrderDetails: this._orderDetails, BankPubKeyDigests: {