node-ebics-client/lib/BankLetter.js

56 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2018-05-17 15:03:59 +00:00
'use strict';
2018-06-01 13:16:43 +00:00
const moment = require('moment');
2018-05-17 15:03:59 +00:00
const handlebars = require('handlebars');
2018-06-01 13:16:43 +00:00
const BN = require('bn.js');
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
const registerHelpers = () => {
handlebars.registerHelper('today', () => moment().format('DD.MM.YYYY'));
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('now', () => moment().format('HH:mm:ss'));
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8);
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('keyModulusBits', k => k.key.getKeySize());
// return Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8;
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('keyExponent', k => k.e());
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('keyModulus', k => k.n().toUpperCase().match(/.{1,2}/g).join(' '));
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
handlebars.registerHelper('sha256', (k) => {
const digest = Buffer.from(k.publicDigest(), 'base64').toString('HEX');
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
return digest.toUpperCase().match(/.{1,2}/g).join(' ');
});
};
module.exports = class BankLetter {
constructor({
client,
bankName,
template,
}) {
this.client = client;
this.bankName = bankName;
this.template = template;
}
2018-05-17 15:03:59 +00:00
generate() {
2018-06-01 13:16:43 +00:00
registerHelpers();
2018-05-17 15:03:59 +00:00
2018-06-01 13:16:43 +00:00
const templ = handlebars.compile(this.template);
2018-05-17 15:03:59 +00:00
const data = {
2018-06-01 13:16:43 +00:00
bankName: this.bankName,
userId: this.client.userId,
2018-05-17 15:03:59 +00:00
partnerId: this.client.partnerId,
2018-06-01 13:16:43 +00:00
A006: this.client.a(),
X002: this.client.x(),
E002: this.client.e(),
2018-05-17 15:03:59 +00:00
};
return templ(data);
}
2018-06-01 13:16:43 +00:00
};