mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-21 21:52:07 +00:00
feat: replace <request> with <rock-req>
This commit is contained in:
parent
a03ec2283f
commit
b6b27516d5
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const $request = require('request');
|
const rock = require('rock-req');
|
||||||
|
|
||||||
const constants = require('./consts');
|
const constants = require('./consts');
|
||||||
const Keys = require('./keymanagers/Keys');
|
const Keys = require('./keymanagers/Keys');
|
||||||
@ -52,7 +52,6 @@ const stringifyKeys = (keys) => {
|
|||||||
* @property {string} storageLocation - Location where to store the files that are downloaded. This can be a network share for example.
|
* @property {string} storageLocation - Location where to store the files that are downloaded. This can be a network share for example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
module.exports = class Client {
|
module.exports = class Client {
|
||||||
/**
|
/**
|
||||||
*Creates an instance of Client.
|
*Creates an instance of Client.
|
||||||
@ -71,18 +70,17 @@ module.exports = class Client {
|
|||||||
languageCode,
|
languageCode,
|
||||||
storageLocation,
|
storageLocation,
|
||||||
}) {
|
}) {
|
||||||
if (!url)
|
if (!url) throw new Error('EBICS URL is required');
|
||||||
throw new Error('EBICS URL is required');
|
if (!partnerId) throw new Error('partnerId is required');
|
||||||
if (!partnerId)
|
if (!userId) throw new Error('userId is required');
|
||||||
throw new Error('partnerId is required');
|
if (!hostId) throw new Error('hostId is required');
|
||||||
if (!userId)
|
if (!passphrase) throw new Error('passphrase is required');
|
||||||
throw new Error('userId is required');
|
|
||||||
if (!hostId)
|
|
||||||
throw new Error('hostId is required');
|
|
||||||
if (!passphrase)
|
|
||||||
throw new Error('passphrase is required');
|
|
||||||
|
|
||||||
if (!keyStorage || typeof keyStorage.read !== 'function' || typeof keyStorage.write !== 'function')
|
if (
|
||||||
|
!keyStorage
|
||||||
|
|| typeof keyStorage.read !== 'function'
|
||||||
|
|| typeof keyStorage.write !== 'function'
|
||||||
|
)
|
||||||
throw new Error('keyStorage implementation missing or wrong');
|
throw new Error('keyStorage implementation missing or wrong');
|
||||||
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
@ -99,17 +97,25 @@ module.exports = class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async send(order) {
|
async send(order) {
|
||||||
const isInObject = ('operation' in order);
|
const isInObject = 'operation' in order;
|
||||||
|
|
||||||
if (!isInObject) throw new Error('Operation for the order needed');
|
if (!isInObject) throw new Error('Operation for the order needed');
|
||||||
|
|
||||||
if (order.operation.toUpperCase() === constants.orderOperations.ini) return this.initialization(order);
|
if (order.operation.toUpperCase() === constants.orderOperations.ini)
|
||||||
|
return this.initialization(order);
|
||||||
|
|
||||||
const keys = await this.keys();
|
const keys = await this.keys();
|
||||||
if (keys === null) throw new Error('No keys provided. Can not send the order or any other order for that matter.');
|
if (keys === null)
|
||||||
|
throw new Error(
|
||||||
|
'No keys provided. Can not send the order or any other order for that matter.',
|
||||||
|
);
|
||||||
|
|
||||||
if (order.operation.toUpperCase() === constants.orderOperations.upload) return this.upload(order);
|
if (order.operation.toUpperCase() === constants.orderOperations.upload)
|
||||||
if (order.operation.toUpperCase() === constants.orderOperations.download) return this.download(order);
|
return this.upload(order);
|
||||||
|
if (
|
||||||
|
order.operation.toUpperCase() === constants.orderOperations.download
|
||||||
|
)
|
||||||
|
return this.download(order);
|
||||||
|
|
||||||
throw new Error('Wrong order operation provided');
|
throw new Error('Wrong order operation provided');
|
||||||
}
|
}
|
||||||
@ -118,8 +124,7 @@ module.exports = class Client {
|
|||||||
const keys = await this.keys();
|
const keys = await this.keys();
|
||||||
if (keys === null) await this._generateKeys();
|
if (keys === null) await this._generateKeys();
|
||||||
|
|
||||||
if (this.tracesStorage)
|
if (this.tracesStorage) this.tracesStorage.new().ofType('ORDER.INI');
|
||||||
this.tracesStorage.new().ofType('ORDER.INI');
|
|
||||||
const res = await this.ebicsRequest(order);
|
const res = await this.ebicsRequest(order);
|
||||||
const xml = res.orderData();
|
const xml = res.orderData();
|
||||||
|
|
||||||
@ -132,7 +137,9 @@ module.exports = class Client {
|
|||||||
|
|
||||||
technicalCode: returnedTechnicalCode,
|
technicalCode: returnedTechnicalCode,
|
||||||
technicalCodeSymbol: res.technicalSymbol(),
|
technicalCodeSymbol: res.technicalSymbol(),
|
||||||
technicalCodeShortText: res.technicalShortText(returnedTechnicalCode),
|
technicalCodeShortText: res.technicalShortText(
|
||||||
|
returnedTechnicalCode,
|
||||||
|
),
|
||||||
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
|
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
|
||||||
|
|
||||||
businessCode: returnedBusinessCode,
|
businessCode: returnedBusinessCode,
|
||||||
@ -167,7 +174,9 @@ module.exports = class Client {
|
|||||||
|
|
||||||
technicalCode: returnedTechnicalCode,
|
technicalCode: returnedTechnicalCode,
|
||||||
technicalCodeSymbol: res.technicalSymbol(),
|
technicalCodeSymbol: res.technicalSymbol(),
|
||||||
technicalCodeShortText: res.technicalShortText(returnedTechnicalCode),
|
technicalCodeShortText: res.technicalShortText(
|
||||||
|
returnedTechnicalCode,
|
||||||
|
),
|
||||||
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
|
technicalCodeMeaning: res.technicalMeaning(returnedTechnicalCode),
|
||||||
|
|
||||||
businessCode: returnedBusinessCode,
|
businessCode: returnedBusinessCode,
|
||||||
@ -178,8 +187,7 @@ module.exports = class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async upload(order) {
|
async upload(order) {
|
||||||
if (this.tracesStorage)
|
if (this.tracesStorage) this.tracesStorage.new().ofType('ORDER.UPLOAD');
|
||||||
this.tracesStorage.new().ofType('ORDER.UPLOAD');
|
|
||||||
let res = await this.ebicsRequest(order);
|
let res = await this.ebicsRequest(order);
|
||||||
const transactionId = res.transactionId();
|
const transactionId = res.transactionId();
|
||||||
const orderId = res.orderId();
|
const orderId = res.orderId();
|
||||||
@ -197,32 +205,46 @@ module.exports = class Client {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const { version } = order;
|
const { version } = order;
|
||||||
const keys = await this.keys();
|
const keys = await this.keys();
|
||||||
const r = signer.version(version).sign((await serializer.use(order, this)).toXML(), keys.x());
|
const r = signer
|
||||||
|
.version(version)
|
||||||
|
.sign((await serializer.use(order, this)).toXML(), keys.x());
|
||||||
|
|
||||||
if (this.tracesStorage)
|
if (this.tracesStorage)
|
||||||
this.tracesStorage.label(`REQUEST.${order.orderDetails.OrderType}`).data(r).persist();
|
this.tracesStorage
|
||||||
|
.label(`REQUEST.${order.orderDetails.OrderType}`)
|
||||||
|
.data(r)
|
||||||
|
.persist();
|
||||||
|
|
||||||
$request.post({
|
rock.post(
|
||||||
url: this.url,
|
this.url,
|
||||||
|
{
|
||||||
body: r,
|
body: r,
|
||||||
headers: { 'content-type': 'text/xml;charset=UTF-8' },
|
headers: { 'content-type': 'text/xml;charset=UTF-8' },
|
||||||
}, (err, res, data) => {
|
},
|
||||||
|
(err, res, data) => {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
|
|
||||||
const ebicsResponse = response.version(version)(data, keys);
|
const ebicsResponse = response.version(version)(data, keys);
|
||||||
|
|
||||||
if (this.tracesStorage)
|
if (this.tracesStorage)
|
||||||
this.tracesStorage.label(`RESPONSE.${order.orderDetails.OrderType}`).connect().data(ebicsResponse.toXML()).persist();
|
this.tracesStorage
|
||||||
|
.label(`RESPONSE.${order.orderDetails.OrderType}`)
|
||||||
|
.connect()
|
||||||
|
.data(ebicsResponse.toXML())
|
||||||
|
.persist();
|
||||||
|
|
||||||
resolve(ebicsResponse);
|
resolve(ebicsResponse);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async signOrder(order) {
|
async signOrder(order) {
|
||||||
const { version } = order;
|
const { version } = order;
|
||||||
const keys = await this.keys();
|
const keys = await this.keys();
|
||||||
return signer.version(version).sign((await serializer.use(order, this)).toXML(), keys.x());
|
return signer
|
||||||
|
.version(version)
|
||||||
|
.sign((await serializer.use(order, this)).toXML(), keys.x());
|
||||||
}
|
}
|
||||||
|
|
||||||
async keys() {
|
async keys() {
|
||||||
@ -253,6 +275,8 @@ module.exports = class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_writeKeys(keysObject) {
|
_writeKeys(keysObject) {
|
||||||
return this.keyStorage.write(this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)));
|
return this.keyStorage.write(
|
||||||
|
this.keyEncryptor.encrypt(stringifyKeys(keysObject.keys)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
const H004Signer = require("../orders/H004/signer");
|
const H004Signer = require('../orders/H004/signer');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
version(v) {
|
version(v) {
|
||||||
if (v.toUpperCase() === "H004") return H004Signer;
|
if (v.toUpperCase() === 'H004') return H004Signer;
|
||||||
|
|
||||||
throw Error("Error from middleware/signer.js: Invalid version number");
|
throw Error('Error from middleware/signer.js: Invalid version number');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
const zlib = require("zlib");
|
const zlib = require('zlib');
|
||||||
const crypto = require("crypto");
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const Crypto = require("../../crypto/Crypto");
|
const Crypto = require('../../crypto/Crypto');
|
||||||
|
|
||||||
const { DOMParser, XMLSerializer } = require("@xmldom/xmldom");
|
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');
|
||||||
const xpath = require("xpath");
|
const xpath = require('xpath');
|
||||||
const errors = require("./errors");
|
const errors = require('./errors');
|
||||||
|
|
||||||
const DEFAULT_IV = Buffer.from(Array(16).fill(0, 0, 15));
|
const DEFAULT_IV = Buffer.from(Array(16).fill(0, 0, 15));
|
||||||
|
|
||||||
@ -21,23 +21,23 @@ const lastChild = (node) => {
|
|||||||
|
|
||||||
module.exports = (xml, keys) => ({
|
module.exports = (xml, keys) => ({
|
||||||
keys,
|
keys,
|
||||||
doc: new DOMParser().parseFromString(xml, "text/xml"),
|
doc: new DOMParser().parseFromString(xml, 'text/xml'),
|
||||||
|
|
||||||
isSegmented() {
|
isSegmented() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
"//xmlns:header/xmlns:mutable/xmlns:SegmentNumber",
|
'//xmlns:header/xmlns:mutable/xmlns:SegmentNumber',
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return !!node.length;
|
return !!node.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
isLastSegment() {
|
isLastSegment() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
"//xmlns:header/xmlns:mutable/*[@lastSegment='true']",
|
"//xmlns:header/xmlns:mutable/*[@lastSegment='true']",
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return !!node.length;
|
return !!node.length;
|
||||||
@ -45,20 +45,20 @@ module.exports = (xml, keys) => ({
|
|||||||
|
|
||||||
orderData() {
|
orderData() {
|
||||||
const orderDataNode = this.doc.getElementsByTagNameNS(
|
const orderDataNode = this.doc.getElementsByTagNameNS(
|
||||||
"urn:org:ebics:H004",
|
'urn:org:ebics:H004',
|
||||||
"OrderData"
|
'OrderData',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!orderDataNode.length) return {};
|
if (!orderDataNode.length) return {};
|
||||||
|
|
||||||
const orderData = orderDataNode[0].textContent;
|
const orderData = orderDataNode[0].textContent;
|
||||||
const decipher = crypto
|
const decipher = crypto
|
||||||
.createDecipheriv("aes-128-cbc", this.transactionKey(), DEFAULT_IV)
|
.createDecipheriv('aes-128-cbc', this.transactionKey(), DEFAULT_IV)
|
||||||
.setAutoPadding(false);
|
.setAutoPadding(false);
|
||||||
const data = Buffer.from(
|
const data = Buffer.from(
|
||||||
decipher.update(orderData, "base64", "binary") +
|
decipher.update(orderData, 'base64', 'binary')
|
||||||
decipher.final("binary"),
|
+ decipher.final('binary'),
|
||||||
"binary"
|
'binary',
|
||||||
);
|
);
|
||||||
|
|
||||||
return zlib.inflateSync(data);
|
return zlib.inflateSync(data);
|
||||||
@ -66,40 +66,40 @@ module.exports = (xml, keys) => ({
|
|||||||
|
|
||||||
transactionKey() {
|
transactionKey() {
|
||||||
const keyNodeText = this.doc.getElementsByTagNameNS(
|
const keyNodeText = this.doc.getElementsByTagNameNS(
|
||||||
"urn:org:ebics:H004",
|
'urn:org:ebics:H004',
|
||||||
"TransactionKey"
|
'TransactionKey',
|
||||||
)[0].textContent;
|
)[0].textContent;
|
||||||
return Crypto.privateDecrypt(
|
return Crypto.privateDecrypt(
|
||||||
this.keys.e(),
|
this.keys.e(),
|
||||||
Buffer.from(keyNodeText, "base64")
|
Buffer.from(keyNodeText, 'base64'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
transactionId() {
|
transactionId() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
"//xmlns:header/xmlns:static/xmlns:TransactionID",
|
'//xmlns:header/xmlns:static/xmlns:TransactionID',
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return node.length ? node[0].textContent : "";
|
return node.length ? node[0].textContent : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
orderId() {
|
orderId() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
".//xmlns:header/xmlns:mutable/xmlns:OrderID",
|
'.//xmlns:header/xmlns:mutable/xmlns:OrderID',
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return node.length ? node[0].textContent : "";
|
return node.length ? node[0].textContent : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
businessCode() {
|
businessCode() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select("//xmlns:body/xmlns:ReturnCode", this.doc);
|
const node = select('//xmlns:body/xmlns:ReturnCode', this.doc);
|
||||||
|
|
||||||
return node.length ? node[0].textContent : "";
|
return node.length ? node[0].textContent : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
businessSymbol(code) {
|
businessSymbol(code) {
|
||||||
@ -115,23 +115,23 @@ module.exports = (xml, keys) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
technicalCode() {
|
technicalCode() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
"//xmlns:header/xmlns:mutable/xmlns:ReturnCode",
|
'//xmlns:header/xmlns:mutable/xmlns:ReturnCode',
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return node.length ? node[0].textContent : "";
|
return node.length ? node[0].textContent : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
technicalSymbol() {
|
technicalSymbol() {
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const node = select(
|
const node = select(
|
||||||
"//xmlns:header/xmlns:mutable/xmlns:ReportText",
|
'//xmlns:header/xmlns:mutable/xmlns:ReportText',
|
||||||
this.doc
|
this.doc,
|
||||||
);
|
);
|
||||||
|
|
||||||
return node.length ? node[0].textContent : "";
|
return node.length ? node[0].textContent : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
technicalShortText(code) {
|
technicalShortText(code) {
|
||||||
@ -146,9 +146,9 @@ module.exports = (xml, keys) => ({
|
|||||||
const orderData = this.orderData().toString();
|
const orderData = this.orderData().toString();
|
||||||
if (!Object.keys(orderData).length) return {};
|
if (!Object.keys(orderData).length) return {};
|
||||||
|
|
||||||
const doc = new DOMParser().parseFromString(orderData, "text/xml");
|
const doc = new DOMParser().parseFromString(orderData, 'text/xml');
|
||||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||||
const keyNodes = select("//xmlns:PubKeyValue", doc);
|
const keyNodes = select('//xmlns:PubKeyValue', doc);
|
||||||
const bankKeys = {};
|
const bankKeys = {};
|
||||||
|
|
||||||
if (!keyNodes.length) return {};
|
if (!keyNodes.length) return {};
|
||||||
@ -157,15 +157,15 @@ module.exports = (xml, keys) => ({
|
|||||||
const type = lastChild(keyNodes[i].parentNode).textContent;
|
const type = lastChild(keyNodes[i].parentNode).textContent;
|
||||||
const modulus = xpath.select(
|
const modulus = xpath.select(
|
||||||
".//*[local-name(.)='Modulus']",
|
".//*[local-name(.)='Modulus']",
|
||||||
keyNodes[i]
|
keyNodes[i],
|
||||||
)[0].textContent;
|
)[0].textContent;
|
||||||
const exponent = xpath.select(
|
const exponent = xpath.select(
|
||||||
".//*[local-name(.)='Exponent']",
|
".//*[local-name(.)='Exponent']",
|
||||||
keyNodes[i]
|
keyNodes[i],
|
||||||
)[0].textContent;
|
)[0].textContent;
|
||||||
|
|
||||||
const mod = Buffer.from(modulus, "base64");
|
const mod = Buffer.from(modulus, 'base64');
|
||||||
const exp = Buffer.from(exponent, "base64");
|
const exp = Buffer.from(exponent, 'base64');
|
||||||
bankKeys[`bank${type}`] = {
|
bankKeys[`bank${type}`] = {
|
||||||
mod,
|
mod,
|
||||||
exp,
|
exp,
|
||||||
|
@ -1,49 +1,48 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
// const crypto = require('crypto');
|
// const crypto = require('crypto');
|
||||||
const Crypto = require("../../crypto/Crypto");
|
const Crypto = require('../../crypto/Crypto');
|
||||||
|
|
||||||
const { DOMParser, XMLSerializer } = require("@xmldom/xmldom");
|
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');
|
||||||
const xpath = require("xpath");
|
const xpath = require('xpath');
|
||||||
const C14n =
|
const C14n = require('xml-crypto/lib/c14n-canonicalization').C14nCanonicalization;
|
||||||
require("xml-crypto/lib/c14n-canonicalization").C14nCanonicalization;
|
|
||||||
|
|
||||||
const digest = (doc) => {
|
const digest = (doc) => {
|
||||||
// get the xml node, where the digested value is supposed to be
|
// get the xml node, where the digested value is supposed to be
|
||||||
const nodeDigestValue = doc.getElementsByTagName("ds:DigestValue")[0];
|
const nodeDigestValue = doc.getElementsByTagName('ds:DigestValue')[0];
|
||||||
|
|
||||||
// canonicalize the node that has authenticate='true' attribute
|
// canonicalize the node that has authenticate='true' attribute
|
||||||
const contentToDigest = xpath
|
const contentToDigest = xpath
|
||||||
.select("//*[@authenticate='true']", doc)
|
.select("//*[@authenticate='true']", doc)
|
||||||
.map((x) => new C14n().process(x))
|
.map(x => new C14n().process(x))
|
||||||
.join("");
|
.join('');
|
||||||
|
|
||||||
// fix the canonicalization
|
// fix the canonicalization
|
||||||
const fixedContent = contentToDigest.replace(
|
const fixedContent = contentToDigest.replace(
|
||||||
/xmlns="urn:org:ebics:H004"/g,
|
/xmlns="urn:org:ebics:H004"/g,
|
||||||
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"'
|
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (nodeDigestValue)
|
if (nodeDigestValue)
|
||||||
nodeDigestValue.textContent = Crypto.digestWithHash(fixedContent)
|
nodeDigestValue.textContent = Crypto.digestWithHash(fixedContent)
|
||||||
.toString("base64")
|
.toString('base64')
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sign = (doc, key) => {
|
const sign = (doc, key) => {
|
||||||
const nodeSignatureValue = doc.getElementsByTagName("ds:SignatureValue")[0];
|
const nodeSignatureValue = doc.getElementsByTagName('ds:SignatureValue')[0];
|
||||||
|
|
||||||
if (nodeSignatureValue) {
|
if (nodeSignatureValue) {
|
||||||
const select = xpath.useNamespaces({
|
const select = xpath.useNamespaces({
|
||||||
ds: "http://www.w3.org/2000/09/xmldsig#",
|
ds: 'http://www.w3.org/2000/09/xmldsig#',
|
||||||
});
|
});
|
||||||
const contentToSign = new C14n()
|
const contentToSign = new C14n()
|
||||||
.process(select("//ds:SignedInfo", doc)[0])
|
.process(select('//ds:SignedInfo', doc)[0])
|
||||||
.replace(
|
.replace(
|
||||||
'xmlns:ds="http://www.w3.org/2000/09/xmldsig#"',
|
'xmlns:ds="http://www.w3.org/2000/09/xmldsig#"',
|
||||||
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"'
|
'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"',
|
||||||
);
|
);
|
||||||
|
|
||||||
nodeSignatureValue.textContent = Crypto.privateSign(key, contentToSign); // this.keys.x().key.sign(contentToSign, 'base64');
|
nodeSignatureValue.textContent = Crypto.privateSign(key, contentToSign); // this.keys.x().key.sign(contentToSign, 'base64');
|
||||||
@ -52,11 +51,11 @@ const sign = (doc, key) => {
|
|||||||
return doc;
|
return doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
const toXML = (doc) => new XMLSerializer().serializeToString(doc);
|
const toXML = doc => new XMLSerializer().serializeToString(doc);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sign(data, keyX) {
|
sign(data, keyX) {
|
||||||
const doc = new DOMParser().parseFromString(data, "text/xml");
|
const doc = new DOMParser().parseFromString(data, 'text/xml');
|
||||||
|
|
||||||
return toXML(sign(digest(doc), keyX));
|
return toXML(sign(digest(doc), keyX));
|
||||||
},
|
},
|
||||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -14,6 +14,7 @@
|
|||||||
"js2xmlparser": "^5.0.0",
|
"js2xmlparser": "^5.0.0",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
|
"rock-req": "^5.1.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"xml-crypto": "^4.0.1",
|
"xml-crypto": "^4.0.1",
|
||||||
"xpath": "0.0.32"
|
"xpath": "0.0.32"
|
||||||
@ -4277,6 +4278,14 @@
|
|||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/rock-req": {
|
||||||
|
"version": "5.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/rock-req/-/rock-req-5.1.3.tgz",
|
||||||
|
"integrity": "sha512-aorqEtp9YKws/KRiHlEbAHDWof/ILjTViTXMTe9juAgLjNrT9jsuQNM/cMbpK+zZsrFEHSHMCSK/wzi0DWelZA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/run-async": {
|
"node_modules/run-async": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"lint-fix": "eslint --fix .",
|
||||||
"test": "nyc mocha test/**/*.js",
|
"test": "nyc mocha test/**/*.js",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"version": "auto-changelog -p -t changelog-template.hbs && git add CHANGELOG.md"
|
"version": "auto-changelog -p -t changelog-template.hbs && git add CHANGELOG.md"
|
||||||
@ -59,13 +60,13 @@
|
|||||||
],
|
],
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@xmldom/xmldom": "^0.8.10",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"js2xmlparser": "^5.0.0",
|
"js2xmlparser": "^5.0.0",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"request": "^2.88.2",
|
"rock-req": "^5.1.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"xml-crypto": "^4.0.1",
|
"xml-crypto": "^4.0.1",
|
||||||
"@xmldom/xmldom": "^0.8.10",
|
|
||||||
"xpath": "0.0.32"
|
"xpath": "0.0.32"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
/* eslint-env node, mocha */
|
/* eslint-env node, mocha */
|
||||||
|
|
||||||
const { assert } = require("chai");
|
const { assert } = require('chai');
|
||||||
|
|
||||||
const path = require("path");
|
const path = require('path');
|
||||||
const fs = require("fs");
|
const fs = require('fs');
|
||||||
|
|
||||||
const ebics = require("../../");
|
const ebics = require('../../');
|
||||||
|
|
||||||
const libxml = require("libxmljs");
|
const libxml = require('libxmljs');
|
||||||
|
|
||||||
const schemaPath = path.resolve(__dirname, "../xsd/ebics_H004.xsd");
|
const schemaPath = path.resolve(__dirname, '../xsd/ebics_H004.xsd');
|
||||||
const schemaDoc = libxml.parseXml(
|
const schemaDoc = libxml.parseXml(
|
||||||
fs.readFileSync(schemaPath, { encoding: "utf8" })
|
fs.readFileSync(schemaPath, { encoding: 'utf8' }),
|
||||||
);
|
);
|
||||||
|
|
||||||
const schemaDir = path.dirname(schemaPath);
|
const schemaDir = path.dirname(schemaPath);
|
||||||
@ -32,13 +32,13 @@ const validateXML = (str) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = new ebics.Client({
|
||||||
url: "https://iso20022test.credit-suisse.com/ebicsweb/ebicsweb",
|
url: 'https://iso20022test.credit-suisse.com/ebicsweb/ebicsweb',
|
||||||
partnerId: "CRS04381",
|
partnerId: 'CRS04381',
|
||||||
userId: "CRS04381",
|
userId: 'CRS04381',
|
||||||
hostId: "CRSISOTB",
|
hostId: 'CRSISOTB',
|
||||||
passphrase: "test",
|
passphrase: 'test',
|
||||||
keyStorage: ebics.fsKeysStorage(
|
keyStorage: ebics.fsKeysStorage(
|
||||||
path.resolve(__dirname, "../support/TEST_KEYS.key")
|
path.resolve(__dirname, '../support/TEST_KEYS.key'),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,8 +56,8 @@ const CCS = require('./CCS');
|
|||||||
const XE3 = require('./XE3');
|
const XE3 = require('./XE3');
|
||||||
const XCT = require('./XCT');
|
const XCT = require('./XCT');
|
||||||
*/
|
*/
|
||||||
const uploadBuilder = (fn) => fn("");
|
const uploadBuilder = fn => fn('');
|
||||||
const dateBuilder = (fn) => fn("2018-01-01", "2019-01-01");
|
const dateBuilder = fn => fn('2018-01-01', '2019-01-01');
|
||||||
|
|
||||||
const fnOrders = {
|
const fnOrders = {
|
||||||
// upload | document
|
// upload | document
|
||||||
@ -87,12 +87,12 @@ const fnOrders = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getOrderObject = (name, order) => {
|
const getOrderObject = (name, order) => {
|
||||||
if (typeof order === "object") return order;
|
if (typeof order === 'object') return order;
|
||||||
if (fnOrders[name]) return fnOrders[name](order);
|
if (fnOrders[name]) return fnOrders[name](order);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("H004 order generation", () => {
|
describe('H004 order generation', () => {
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const [name, orderDefinition] of Object.entries(Orders)) {
|
for (const [name, orderDefinition] of Object.entries(Orders)) {
|
||||||
const order = getOrderObject(name, orderDefinition);
|
const order = getOrderObject(name, orderDefinition);
|
||||||
|
Loading…
Reference in New Issue
Block a user