Merge branch 'master' into herrie/additionalConfigItems

This commit is contained in:
Herrie 2021-03-30 11:03:35 +02:00 committed by GitHub
commit 9ef50081ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 276 additions and 10 deletions

View File

@ -28,6 +28,8 @@ The client is currently tested and verified to work with the following banks:
* [Raiffeisen Schweiz](https://www.raiffeisen.ch/rch/de.html) * [Raiffeisen Schweiz](https://www.raiffeisen.ch/rch/de.html)
* [BW Bank](https://www.bw-bank.de/de/home.html) * [BW Bank](https://www.bw-bank.de/de/home.html)
* [Bank GPB International S.A.](https://gazprombank.lu/e-banking) * [Bank GPB International S.A.](https://gazprombank.lu/e-banking)
* [Bank GPB AO](https://gazprombank.ru/)
* [J.P. Morgan](https://www.jpmorgan.com/)
## Inspiration ## Inspiration

View File

@ -20,11 +20,22 @@ const getDefaultEnv = () => {
return parArg || process.env.NODE_ENV; return parArg || process.env.NODE_ENV;
} }
const loadConfig = (configDirectory = path.join(__dirname, './config'), env = getDefaultEnv()) => { const getBankIdentifier = () => {
console.log(`Loading config form ${configDirectory} with env set to ${env}.`); const [,,,parArg] = process.argv;
return parArg || "testbank";
}
const getEntityIdentifier = () => {
const [,,,,parArg] = process.argv;
return parArg || ""
}
const loadConfig = (configDirectory = path.join(__dirname, './config'), env = getDefaultEnv(), bank = getBankIdentifier(), entity = getEntityIdentifier()) => {
entity ? console.log(`Loading config from ${configDirectory} with env set to ${env}, bank set to ${bank} and entity set to ${entity}.`) : console.log(`Loading config from ${configDirectory} with env set to ${env} and bank set to ${bank}.`);
global.entity = entity;
const baseConfigFile = path.join(configDirectory, 'config.json'); const baseConfigFile = path.join(configDirectory, 'config.json');
const envConfigFile = env ? path.join(configDirectory, `config.${env}.json`) : null; const envConfigFile = env ? entity ? path.join(configDirectory, `config.${env}.${bank}.${entity}.json`) : path.join(configDirectory, `config.${env}.${bank}.json`) : null;
return { return {
...safeLoadJson(baseConfigFile), ...safeLoadJson(baseConfigFile),

View File

@ -0,0 +1,28 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
client.send(Orders.C52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
.then((resp) => {
console.log('Response for C52 order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
// Parsing and processing the CAMT052 file should happen somewhere here, ideally after saving it to disk
const data = Buffer.from(resp.orderData);
let distPath = "CAMT052.zip";
const dstZip = fs.createWriteStream(distPath);
dstZip.write(data);
dstZip.end();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,28 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
client.send(Orders.C53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
.then((resp) => {
console.log('Response for C53 order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
// Parsing and processing the CAMT053 file should happen somewhere here, ideally after saving it to disk
const data = Buffer.from(resp.orderData);
let distPath = "CAMT053.zip";
const dstZip = fs.createWriteStream(distPath);
dstZip.write(data);
dstZip.end();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,28 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
client.send(Orders.G02(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
.then((resp) => {
console.log('Response for G02 order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
// Parsing and processing the G02 Pain.002.001.06 file should happen somewhere here, ideally after saving it to disk
const data = Buffer.from(resp.orderData);
let distPath = "G02.zip";
const dstZip = fs.createWriteStream(distPath);
dstZip.write(data);
dstZip.end();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,20 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
const paymentFile = fs.readFileSync('RUB_PAYMENT.xml').toString();
client.send(Orders.G1R(paymentFile))
.then((resp) => {
console.log('Response for G1R order %j', resp);
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,20 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
const paymentFile = fs.readFileSync('FCY_PAYMENT.xml').toString();
client.send(Orders.G1V(paymentFile))
.then((resp) => {
console.log('Response for G1V order %j', resp);
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,28 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
client.send(Orders.G52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
.then((resp) => {
console.log('Response for G52 order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
// Parsing and processing the CAMT052 file should happen somewhere here, ideally after saving it to disk
const data = Buffer.from(resp.orderData);
let distPath = "CAMT052-G52.zip";
const dstZip = fs.createWriteStream(distPath);
dstZip.write(data);
dstZip.end();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -0,0 +1,28 @@
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const client = require('./getClient')();
const { Orders } = require('../index');
// The bank keys must have been already saved
client.send(Orders.G53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
.then((resp) => {
console.log('Response for G53 order %j', resp);
if (resp.technicalCode !== '000000')
throw new Error('Something went wrong');
// Parsing and processing the CAMT053 file should happen somewhere here, ideally after saving it to disk
const data = Buffer.from(resp.orderData);
let distPath = "CAMT053-G53.zip";
const dstZip = fs.createWriteStream(distPath);
dstZip.write(data);
dstZip.end();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -67,12 +67,16 @@ module.exports = class Crypto {
} }
static sign(key, msg, salt = crypto.randomBytes(32)) { static sign(key, msg, salt = crypto.randomBytes(32)) {
// console.log(key.d());
const base = new BigNumber(emsaPSS(msg, salt)); const base = new BigNumber(emsaPSS(msg, salt));
const power = new BigNumber(key.d()); const power = new BigNumber(key.d());
const mod = new BigNumber(key.n()); const mod = new BigNumber(key.n());
const buffer = modPow(base, power, mod).toBEBuffer();
return (modPow(base, power, mod)).toBEBuffer().toString('base64'); if (buffer.byteLength !== 257 || buffer[0] === 0x00)
return buffer.slice(1).toString('base64');
// console.log('hex string of key starts with "00" and is 514 bytes long, fixing it to be 512 bytes long by stripping leading "00"');
return buffer.toString('base64');
} }
static pad(d) { static pad(d) {

View File

@ -0,0 +1,13 @@
'use strict';
const utils = require('../utils');
module.exports = (start = null, end = null) => ({
version: 'h004',
orderDetails: {
OrderType: 'G02',
OrderAttribute: 'DZHNN',
StandardOrderParams: utils.dateRange(start, end),
},
operation: 'download',
});

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = document => ({
version: 'h004',
orderDetails: { OrderType: 'G1R', OrderAttribute: 'DZHNN', StandardOrderParams: {} },
operation: 'upload',
document,
});

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = document => ({
version: 'h004',
orderDetails: { OrderType: 'G1V', OrderAttribute: 'DZHNN', StandardOrderParams: {} },
operation: 'upload',
document,
});

View File

@ -0,0 +1,13 @@
'use strict';
const utils = require('../utils');
module.exports = (start = null, end = null) => ({
version: 'h004',
orderDetails: {
OrderType: 'G52',
OrderAttribute: 'DZHNN',
StandardOrderParams: utils.dateRange(start, end),
},
operation: 'download',
});

View File

@ -0,0 +1,13 @@
'use strict';
const utils = require('../utils');
module.exports = (start = null, end = null) => ({
version: 'h004',
orderDetails: {
OrderType: 'G53',
OrderAttribute: 'DZHNN',
StandardOrderParams: utils.dateRange(start, end),
},
operation: 'download',
});

View File

@ -14,6 +14,8 @@ const CCS = require('./CCS');
const XE3 = require('./XE3'); const XE3 = require('./XE3');
const XCT = require('./XCT'); const XCT = require('./XCT');
const XG1 = require('./XG1'); const XG1 = require('./XG1');
const G1V = require('./G1V');
const G1R = require('./G1R');
const STA = require('./STA'); const STA = require('./STA');
const VMK = require('./VMK'); const VMK = require('./VMK');
@ -27,6 +29,9 @@ const Z53 = require('./Z53');
const DKI = require('./DKI'); const DKI = require('./DKI');
const C52 = require('./C52'); const C52 = require('./C52');
const C53 = require('./C53'); const C53 = require('./C53');
const G52 = require('./G52');
const G53 = require('./G53');
const G02 = require('./G02');
module.exports = { module.exports = {
INI, INI,
@ -44,6 +49,8 @@ module.exports = {
XE3, XE3,
XCT, XCT,
XG1, XG1,
G1V,
G1R,
STA, STA,
VMK, VMK,
@ -56,4 +63,7 @@ module.exports = {
DKI, DKI,
C52, C52,
C53, C53,
G52,
G53,
G02,
}; };

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "ebics-client", "name": "ebics-client",
"version": "0.1.6", "version": "0.1.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -4367,9 +4367,9 @@
"integrity": "sha512-HgS+X6zAztGa9zIK3Y3LXuJes33Lz9x+YyTxgrkIdabu2vqcGOWwdfCpf1hWLRrd553wd4QCDf6BBO6FfdsRiQ==" "integrity": "sha512-HgS+X6zAztGa9zIK3Y3LXuJes33Lz9x+YyTxgrkIdabu2vqcGOWwdfCpf1hWLRrd553wd4QCDf6BBO6FfdsRiQ=="
}, },
"xmldom": { "xmldom": {
"version": "0.3.0", "version": "0.5.0",
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz",
"integrity": "sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g==" "integrity": "sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA=="
}, },
"xpath": { "xpath": {
"version": "0.0.27", "version": "0.0.27",

View File

@ -51,6 +51,10 @@
{ {
"name": "chrwoizi", "name": "chrwoizi",
"url": "https://github.com/chrwoizi" "url": "https://github.com/chrwoizi"
},
{
"name": "Herrie",
"url": "https://github.com/Herrie82"
} }
], ],
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
@ -61,7 +65,7 @@
"request": "^2.88.2", "request": "^2.88.2",
"uuid": "^8.0.0", "uuid": "^8.0.0",
"xml-crypto": "^2.0.0", "xml-crypto": "^2.0.0",
"xmldom": "^0.3.0", "xmldom": "^0.5.0",
"xpath": "0.0.27" "xpath": "0.0.27"
}, },
"devDependencies": { "devDependencies": {