initial commit

This commit is contained in:
Vladislav Hristov
2018-05-17 18:03:59 +03:00
parent cd37de3895
commit 1f947ff148
27 changed files with 1502 additions and 0 deletions

50
lib/orders/C52.js Normal file
View File

@@ -0,0 +1,50 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class C52 extends GenericOrder {
constructor (client, from, to) {
super(client);
this._from = from;
this._to = to;
this._schema.header = {
"@" : { authenticate: true },
static: {
HostID : this.hostId,
Nonce : this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID : this.userId,
Product : {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType : "C52",
OrderAttribute : "DZHNN",
StandardOrderParams: {
DateRange: {
Start: this._from,
End : this._to
}
},
},
BankPubKeyDigests: {
Authentication: {
"@": { Version: "X002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankX().publicDigest()
},
Encryption: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
}
},
SecurityMedium: "0000"
},
mutable: {
TransactionPhase: "Initialisation"
}
};
};
};

143
lib/orders/GenericOrder.js Normal file
View File

@@ -0,0 +1,143 @@
'use strict';
// const randHex = require('../../lib/utils').randHex;
const crypto = require("crypto");
const js2xmlparser = require('js2xmlparser');
const consts = require('../consts');
module.exports = class GenericOrder {
constructor(client) {
this.client = client;
this.hostId = client.hostId;
this.userId = client.userId;
this.partnerId = client.partnerId;
this.transactionId = '';
this.xmlOptions = {
declaration: {
include: true,
encoding: "utf-8"
},
format: {
doubleQuotes: true,
indent: '',
newline: '',
// indent: "\t",
// newline: "\r\n",
pretty: true
}
};
this._schema = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "urn:org:ebics:H004",
Version: "H004",
Revision: "1"
},
header: {},
AuthSignature: this.authSignature(),
body: {}
};
}
authSignature() {
return {
"ds:SignedInfo": {
"ds:CanonicalizationMethod": {
"@": {
Algorithm:
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
}
},
"ds:SignatureMethod": {
"@": {
Algorithm:
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
}
},
"ds:Reference": {
"@": { URI: "#xpointer(//*[@authenticate='true'])" },
"ds:Transforms": {
"ds:Transform": {
"@": {
Algorithm:
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
}
}
},
"ds:DigestMethod": {
"@": {
Algorithm:
"http://www.w3.org/2001/04/xmlenc#sha256"
}
},
"ds:DigestValue": {}
}
},
"ds:SignatureValue": {}
};
}
get schema() {
return this._schema;
}
get productString() {
return consts.productString;
}
nonce() {
return crypto.randomBytes(16).toString('hex');
}
timestamp() {
return new Date().toISOString();
}
root() {
return "ebicsRequest";
}
toReceiptXML() {
const xmlObj = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "urn:org:ebics:H004",
Version: "H004",
Revision: "1"
},
header: {
"@": { authenticate: true },
static: {
HostID: this.hostId,
TransactionID: this.transactionId
},
mutable: {
TransactionPhase: 'Receipt',
}
},
AuthSignature: this.authSignature(),
body: {
TransferReceipt: {
"@": { authenticate: true },
ReceiptCode: 0
}
}
};
return js2xmlparser.parse(this.root(), xmlObj, this.xmlOptions);
}
toXML() {
return js2xmlparser.parse(this.root(), this._schema, this.xmlOptions);
}
};

View File

@@ -0,0 +1,63 @@
'use strict';
const zlib = require('zlib');
const crypto = require("crypto");
const js2xmlparser = require('js2xmlparser');
const GenericOrder = require('./GenericOrder');
module.exports = class GenericUploadOrder extends GenericOrder {
constructor(client, document) {
super(client);
this._document = document;
this._key = crypto.randomBytes(16);
this._schema.body = {
DataTransfer: {
DataEncryptionInfo: {
"@": { authenticate: true },
EncryptionPubKeyDigest: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
},
TransactionKey: Buffer.from(this.client.bankE().publicEncrypt(this._key)).toString('base64'),
},
SignatureData: {
"@": { authenticate: true },
"#": this.encryptedOrderSignature()
}
}
};
};
orderSignature() {
const xmlObj = {
"@": {
xmlns: "http://www.ebics.org/S001",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation": "http://www.ebics.org/S001 http://www.ebics.org/S001/ebics_signature.xsd"
},
OrderSignatureData: {
SignatureVersion: "A006",
SignatureValue: this.signatureValue(),
PartnerID: this.partnerId,
UserID: this.userId
}
};
return js2xmlparser.parse('UserSignatureData', xmlObj, this.xmlOptions);
};
signatureValue() {
const digested = crypto.createHash('sha256').update(this._document).digest();
};
encryptedOrderSignature() {
const dst = zlib.deflateSync(this.orderSignature());
const cipher = crypto.createCipheriv('aes-128-cbc', this._key, Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,])).setAutoPadding(false);
const encrypted = cipher.update(dst) + cipher.final();
return Buffer.from(encrypted).toString('base64');
};
};

43
lib/orders/HAA.js Normal file
View File

@@ -0,0 +1,43 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class HAA extends GenericOrder {
constructor (client) {
super(client);
this._schema.header = {
"@": { authenticate: true },
static: {
HostID: this.hostId,
Nonce: this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString
},
OrderDetails: {
OrderType: "HAA",
OrderAttribute: "DZHNN",
StandardOrderParams: ""
},
BankPubKeyDigests: {
Authentication: {
"@": { Version: "X002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankX().publicDigest()
},
Encryption: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
}
},
SecurityMedium: "0000"
},
mutable: {
TransactionPhase: "Initialisation"
}
};
};
};

54
lib/orders/HAC.js Normal file
View File

@@ -0,0 +1,54 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class HAC extends GenericOrder {
constructor (client, from = null, to = null) {
super(client);
this._from = from;
this._to = to;
this._schema.header = {
"@" : { authenticate: true },
static: {
HostID : this.hostId,
Nonce : this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID : this.userId,
Product : {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType : "HAC",
OrderAttribute : "DZHNN",
StandardOrderParams: this._hasDateRange() ? {
DateRange: {
Start: this._from,
End : this._to
}
} : ""
},
BankPubKeyDigests: {
Authentication: {
"@": { Version: "X002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankX().publicDigest()
},
Encryption: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
}
},
SecurityMedium: "0000"
},
mutable: {
TransactionPhase: "Initialisation"
}
};
};
_hasDateRange() {
return this._from && this._to;
}
};

85
lib/orders/HIA.js Normal file
View File

@@ -0,0 +1,85 @@
'use strict';
const zlib = require('zlib');
const js2xmlparser = require('js2xmlparser');
const GenericOrder = require('./GenericOrder');
module.exports = class HIA extends GenericOrder {
constructor(client) {
super(client);
this._schema = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "urn:org:ebics:H004",
Version: "H004",
Revision: "1"
},
header: {
"@": { authenticate: true },
static: {
HostID: this.hostId,
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType: "HIA",
OrderAttribute: "DZNNN"
},
SecurityMedium: "0000"
},
mutable: {}
},
body: {
DataTransfer: {
OrderData: Buffer.from(zlib.deflateSync(this.orderData())).toString('base64')
}
}
};
}
root() {
return "ebicsUnsecuredRequest";
};
orderData() {
const xmlOrderData = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "urn:org:ebics:H004"
},
AuthenticationPubKeyInfo: {
PubKeyValue: {
"ds:RSAKeyValue": {
"ds:Modulus": Buffer.from(this.client.x().n(), 'HEX').toString('base64'),
"ds:Exponent": "AQAB"
},
},
AuthenticationVersion: "X002"
},
EncryptionPubKeyInfo: {
PubKeyValue: {
"ds:RSAKeyValue": {
"ds:Modulus": Buffer.from(this.client.e().n(), 'HEX').toString('base64'),
"ds:Exponent": "AQAB"
},
},
EncryptionVersion: "E002"
},
PartnerID: this.partnerId,
UserID: this.userId
};
return js2xmlparser.parse("HIARequestOrderData", xmlOrderData, this.xmlOptions);
};
toXML() {
return js2xmlparser.parse(this.root(), this._schema, this.xmlOptions);
};
};

43
lib/orders/HKD.js Normal file
View File

@@ -0,0 +1,43 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class HKD extends GenericOrder {
constructor (client) {
super(client);
this._schema.header = {
"@": { authenticate: true },
static: {
HostID: this.hostId,
Nonce: this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType: "HKD",
OrderAttribute: "DZHNN",
StandardOrderParams: ""
},
BankPubKeyDigests: {
Authentication: {
"@": { Version: "X002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankX().publicDigest()
},
Encryption: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
}
},
SecurityMedium: "0000"
},
mutable: {
TransactionPhase: "Initialisation"
}
};
};
};

34
lib/orders/HPB.js Normal file
View File

@@ -0,0 +1,34 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class HPB extends GenericOrder {
constructor (client) {
super(client);
this._schema.header = {
"@": { authenticate: true },
static: {
HostID: this.hostId,
Nonce: this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType: "HPB",
OrderAttribute: "DZHNN"
},
SecurityMedium: "0000"
},
mutable: {}
};
};
root() {
return "ebicsNoPubKeyDigestsRequest";
};
};

43
lib/orders/HTD.js Normal file
View File

@@ -0,0 +1,43 @@
'use strict';
const GenericOrder = require('./GenericOrder');
module.exports = class HTD extends GenericOrder {
constructor (client) {
super(client);
this._schema.header = {
"@": { authenticate: true },
static: {
HostID: this.hostId,
Nonce: this.nonce(),
Timestamp: this.timestamp(),
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType: "HTD",
OrderAttribute: "DZHNN",
StandardOrderParams: ""
},
BankPubKeyDigests: {
Authentication: {
"@": { Version: "X002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankX().publicDigest()
},
Encryption: {
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
"#": this.client.bankE().publicDigest()
}
},
SecurityMedium: "0000"
},
mutable: {
TransactionPhase: "Initialisation"
}
};
};
};

77
lib/orders/INI.js Normal file
View File

@@ -0,0 +1,77 @@
'use strict';
const zlib = require('zlib');
const js2xmlparser = require('js2xmlparser');
const GenericOrder = require('./GenericOrder');
module.exports = class INI extends GenericOrder {
constructor (client) {
super(client);
this._schema = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "urn:org:ebics:H004",
Version: "H004",
Revision: "1"
},
header: {
"@": { authenticate: true },
static: {
HostID: this.hostId,
PartnerID: this.partnerId,
UserID: this.userId,
Product: {
"@": { Language: "de" },
"#": this.productString,
},
OrderDetails: {
OrderType: "INI",
OrderAttribute: "DZNNN"
},
SecurityMedium: "0000"
},
mutable: {}
},
body: {
DataTransfer: {
OrderData: Buffer.from(zlib.deflateSync(this.keySignature())).toString('base64')
}
}
};
}
root() {
return "ebicsUnsecuredRequest";
};
keySignature() {
const xmlOrderData = {
"@": {
"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
xmlns: "http://www.ebics.org/S001"
},
SignaturePubKeyInfo: {
PubKeyValue: {
"ds:RSAKeyValue": {
"ds:Modulus": Buffer.from(this.client.a().n(), 'HEX').toString('base64'),
"ds:Exponent": "AQAB"
},
TimeStamp: this.timestamp()
},
SignatureVersion: "A006"
},
PartnerID: this.partnerId,
UserID: this.userId
};
return js2xmlparser.parse("SignaturePubKeyOrderData", xmlOrderData, this.xmlOptions);
};
toXML() {
return js2xmlparser.parse(this.root(), this._schema, this.xmlOptions);
}
};