isLastSegment() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select("//xmlns:header/xmlns:mutable/*[@lastSegment='true']", this.doc); return !!node.length; }
const digest = (doc) => { // get the xml node, where the digested value is supposed to be const nodeDigestValue = doc.getElementsByTagName('ds:DigestValue')[0]; // canonicalize the node that has authenticate='true' attribute const contentToDigest = xpath.select("//*[@authenticate='true']", doc) .map(x => new C14n().process(x)).join(''); // fix the canonicalization const fixedContent = contentToDigest.replace(/xmlns="urn:org:ebics:H004"/g, 'xmlns="urn:org:ebics:H004" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"'); if (nodeDigestValue) nodeDigestValue.textContent = Crypto.digestWithHash(fixedContent).toString('base64').trim(); return doc; }
/** * Set the value for a Tag (find by xpath) */ setTagValue(path, value) { const mdoc = new DOMParser().parseFromString(this.xmlContent, 'text/xml'); const mnode = xpath.select(path, mdoc); mnode[0].textContent = value; this.xmlContentEdited = serializer.serializeToString(mdoc); }
const sign = (doc, key) => { const nodeSignatureValue = doc.getElementsByTagName('ds:SignatureValue')[0]; if (nodeSignatureValue) { const select = xpath.useNamespaces({ ds: 'http://www.w3.org/2000/09/xmldsig#' }); const contentToSign = (new C14n().process(select('//ds:SignedInfo', doc)[0])).replace('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'); } return doc; }
https.get(url, res => { res.setEncoding("utf8"); let body = ""; res.on("data", data => { body += data; }); res.on("end", () => { // parse JSON // body = JSON.parse(body); //console.log(body); // parse HTML/XML var doc = new dom().parseFromString(body); var nodes = xpath.select("//h2[@itemprop='name']/text()", doc); nodes.forEach(function(node) { console.log(node.toString()); }); }); });
bankKeys() { 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 bankKeys = {}; if (!keyNodes.length) return {}; for (let i = 0; i < keyNodes.length; i++) { const type = lastChild(keyNodes[i].parentNode).textContent; const modulus = xpath.select(".//*[local-name(.)='Modulus']", keyNodes[i])[0].textContent; const exponent = xpath.select(".//*[local-name(.)='Exponent']", keyNodes[i])[0].textContent; const mod = Buffer.from(modulus, 'base64'); const exp = Buffer.from(exponent, 'base64'); bankKeys[`bank${type}`] = { mod, exp, }; } return bankKeys; }
orderId() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select('.//xmlns:header/xmlns:mutable/xmlns:OrderID', this.doc); return node.length ? node[0].textContent : ''; }
transactionId() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select('//xmlns:header/xmlns:static/xmlns:TransactionID', this.doc); return node.length ? node[0].textContent : ''; }
technicalCode() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select('//xmlns:header/xmlns:mutable/xmlns:ReturnCode', this.doc); 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); return node.length ? node[0].textContent : ''; }
technicalSymbol() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select('//xmlns:header/xmlns:mutable/xmlns:ReportText', this.doc); return node.length ? node[0].textContent : ''; }
isSegmented() { const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' }); const node = select('//xmlns:header/xmlns:mutable/xmlns:SegmentNumber', this.doc); return !!node.length; }