mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-12-16 00:29:32 +00:00
feat: replace <request> with <rock-req>
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
const zlib = require("zlib");
|
||||
const crypto = require("crypto");
|
||||
const zlib = require('zlib');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const Crypto = require("../../crypto/Crypto");
|
||||
const Crypto = require('../../crypto/Crypto');
|
||||
|
||||
const { DOMParser, XMLSerializer } = require("@xmldom/xmldom");
|
||||
const xpath = require("xpath");
|
||||
const errors = require("./errors");
|
||||
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');
|
||||
const xpath = require('xpath');
|
||||
const errors = require('./errors');
|
||||
|
||||
const DEFAULT_IV = Buffer.from(Array(16).fill(0, 0, 15));
|
||||
|
||||
@@ -21,23 +21,23 @@ const lastChild = (node) => {
|
||||
|
||||
module.exports = (xml, keys) => ({
|
||||
keys,
|
||||
doc: new DOMParser().parseFromString(xml, "text/xml"),
|
||||
doc: new DOMParser().parseFromString(xml, 'text/xml'),
|
||||
|
||||
isSegmented() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
"//xmlns:header/xmlns:mutable/xmlns:SegmentNumber",
|
||||
this.doc
|
||||
'//xmlns:header/xmlns:mutable/xmlns:SegmentNumber',
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return !!node.length;
|
||||
},
|
||||
|
||||
isLastSegment() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
"//xmlns:header/xmlns:mutable/*[@lastSegment='true']",
|
||||
this.doc
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return !!node.length;
|
||||
@@ -45,20 +45,20 @@ module.exports = (xml, keys) => ({
|
||||
|
||||
orderData() {
|
||||
const orderDataNode = this.doc.getElementsByTagNameNS(
|
||||
"urn:org:ebics:H004",
|
||||
"OrderData"
|
||||
'urn:org:ebics:H004',
|
||||
'OrderData',
|
||||
);
|
||||
|
||||
if (!orderDataNode.length) return {};
|
||||
|
||||
const orderData = orderDataNode[0].textContent;
|
||||
const decipher = crypto
|
||||
.createDecipheriv("aes-128-cbc", this.transactionKey(), DEFAULT_IV)
|
||||
.createDecipheriv('aes-128-cbc', this.transactionKey(), DEFAULT_IV)
|
||||
.setAutoPadding(false);
|
||||
const data = Buffer.from(
|
||||
decipher.update(orderData, "base64", "binary") +
|
||||
decipher.final("binary"),
|
||||
"binary"
|
||||
decipher.update(orderData, 'base64', 'binary')
|
||||
+ decipher.final('binary'),
|
||||
'binary',
|
||||
);
|
||||
|
||||
return zlib.inflateSync(data);
|
||||
@@ -66,40 +66,40 @@ module.exports = (xml, keys) => ({
|
||||
|
||||
transactionKey() {
|
||||
const keyNodeText = this.doc.getElementsByTagNameNS(
|
||||
"urn:org:ebics:H004",
|
||||
"TransactionKey"
|
||||
'urn:org:ebics:H004',
|
||||
'TransactionKey',
|
||||
)[0].textContent;
|
||||
return Crypto.privateDecrypt(
|
||||
this.keys.e(),
|
||||
Buffer.from(keyNodeText, "base64")
|
||||
Buffer.from(keyNodeText, 'base64'),
|
||||
);
|
||||
},
|
||||
|
||||
transactionId() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
"//xmlns:header/xmlns:static/xmlns:TransactionID",
|
||||
this.doc
|
||||
'//xmlns:header/xmlns:static/xmlns:TransactionID',
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return node.length ? node[0].textContent : "";
|
||||
return node.length ? node[0].textContent : '';
|
||||
},
|
||||
|
||||
orderId() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
".//xmlns:header/xmlns:mutable/xmlns:OrderID",
|
||||
this.doc
|
||||
'.//xmlns:header/xmlns:mutable/xmlns:OrderID',
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return node.length ? node[0].textContent : "";
|
||||
return node.length ? node[0].textContent : '';
|
||||
},
|
||||
|
||||
businessCode() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const node = select("//xmlns:body/xmlns:ReturnCode", this.doc);
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select('//xmlns:body/xmlns:ReturnCode', this.doc);
|
||||
|
||||
return node.length ? node[0].textContent : "";
|
||||
return node.length ? node[0].textContent : '';
|
||||
},
|
||||
|
||||
businessSymbol(code) {
|
||||
@@ -115,23 +115,23 @@ module.exports = (xml, keys) => ({
|
||||
},
|
||||
|
||||
technicalCode() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
"//xmlns:header/xmlns:mutable/xmlns:ReturnCode",
|
||||
this.doc
|
||||
'//xmlns:header/xmlns:mutable/xmlns:ReturnCode',
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return node.length ? node[0].textContent : "";
|
||||
return node.length ? node[0].textContent : '';
|
||||
},
|
||||
|
||||
technicalSymbol() {
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select(
|
||||
"//xmlns:header/xmlns:mutable/xmlns:ReportText",
|
||||
this.doc
|
||||
'//xmlns:header/xmlns:mutable/xmlns:ReportText',
|
||||
this.doc,
|
||||
);
|
||||
|
||||
return node.length ? node[0].textContent : "";
|
||||
return node.length ? node[0].textContent : '';
|
||||
},
|
||||
|
||||
technicalShortText(code) {
|
||||
@@ -146,9 +146,9 @@ module.exports = (xml, keys) => ({
|
||||
const orderData = this.orderData().toString();
|
||||
if (!Object.keys(orderData).length) return {};
|
||||
|
||||
const doc = new DOMParser().parseFromString(orderData, "text/xml");
|
||||
const select = xpath.useNamespaces({ xmlns: "urn:org:ebics:H004" });
|
||||
const keyNodes = select("//xmlns:PubKeyValue", doc);
|
||||
const doc = new DOMParser().parseFromString(orderData, 'text/xml');
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const keyNodes = select('//xmlns:PubKeyValue', doc);
|
||||
const bankKeys = {};
|
||||
|
||||
if (!keyNodes.length) return {};
|
||||
@@ -157,15 +157,15 @@ module.exports = (xml, keys) => ({
|
||||
const type = lastChild(keyNodes[i].parentNode).textContent;
|
||||
const modulus = xpath.select(
|
||||
".//*[local-name(.)='Modulus']",
|
||||
keyNodes[i]
|
||||
keyNodes[i],
|
||||
)[0].textContent;
|
||||
const exponent = xpath.select(
|
||||
".//*[local-name(.)='Exponent']",
|
||||
keyNodes[i]
|
||||
keyNodes[i],
|
||||
)[0].textContent;
|
||||
|
||||
const mod = Buffer.from(modulus, "base64");
|
||||
const exp = Buffer.from(exponent, "base64");
|
||||
const mod = Buffer.from(modulus, 'base64');
|
||||
const exp = Buffer.from(exponent, 'base64');
|
||||
bankKeys[`bank${type}`] = {
|
||||
mod,
|
||||
exp,
|
||||
|
||||
Reference in New Issue
Block a user