mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-22 06:02:09 +00:00
Add serialize function to BankLetter class
This commit is contained in:
parent
5d4e9f8309
commit
548c17a868
2
index.js
2
index.js
@ -3,9 +3,11 @@
|
|||||||
const Client = require('./lib/Client');
|
const Client = require('./lib/Client');
|
||||||
const Orders = require('./lib/predefinedOrders');
|
const Orders = require('./lib/predefinedOrders');
|
||||||
const fsKeysStorage = require('./lib/storages/fsKeysStorage');
|
const fsKeysStorage = require('./lib/storages/fsKeysStorage');
|
||||||
|
const BankLetter = require('./lib/BankLetter');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Client,
|
Client,
|
||||||
Orders,
|
Orders,
|
||||||
|
BankLetter,
|
||||||
fsKeysStorage,
|
fsKeysStorage,
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const handlebars = require('handlebars');
|
const handlebars = require('handlebars');
|
||||||
const BN = require('bn.js');
|
const Crypto = require('./crypto/Crypto');
|
||||||
|
// const BN = require('bn.js');
|
||||||
|
|
||||||
const registerHelpers = () => {
|
const registerHelpers = () => {
|
||||||
handlebars.registerHelper('today', () => moment().format('DD.MM.YYYY'));
|
handlebars.registerHelper('today', () => moment().format('DD.MM.YYYY'));
|
||||||
|
|
||||||
handlebars.registerHelper('now', () => moment().format('HH:mm:ss'));
|
handlebars.registerHelper('now', () => moment().format('HH:mm:ss'));
|
||||||
|
|
||||||
handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8);
|
handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(k.e()) * 8);
|
||||||
|
// handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8);
|
||||||
|
|
||||||
handlebars.registerHelper('keyModulusBits', k => k.key.getKeySize());
|
handlebars.registerHelper('keyModulusBits', k => k.key.getKeySize());
|
||||||
// return Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8;
|
// return Buffer.byteLength(new BN(k.key.keyPair.e).toBuffer()) * 8;
|
||||||
@ -19,7 +23,8 @@ const registerHelpers = () => {
|
|||||||
handlebars.registerHelper('keyModulus', k => k.n('hex').toUpperCase().match(/.{1,2}/g).join(' '));
|
handlebars.registerHelper('keyModulus', k => k.n('hex').toUpperCase().match(/.{1,2}/g).join(' '));
|
||||||
|
|
||||||
handlebars.registerHelper('sha256', (k) => {
|
handlebars.registerHelper('sha256', (k) => {
|
||||||
const digest = Buffer.from(k.publicDigest(), 'base64').toString('HEX');
|
const digest = Buffer.from(Crypto.digestPublicKey(k), 'base64').toString('HEX');
|
||||||
|
// const digest = Buffer.from(k.publicDigest(), 'base64').toString('HEX');
|
||||||
|
|
||||||
return digest.toUpperCase().match(/.{1,2}/g).join(' ');
|
return digest.toUpperCase().match(/.{1,2}/g).join(' ');
|
||||||
});
|
});
|
||||||
@ -36,20 +41,33 @@ module.exports = class BankLetter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
generate() {
|
async generate() {
|
||||||
registerHelpers();
|
registerHelpers();
|
||||||
|
|
||||||
const templ = handlebars.compile(this.template);
|
const templ = handlebars.compile(this.template);
|
||||||
|
const keys = await this.client.keys();
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
bankName: this.bankName,
|
bankName: this.bankName,
|
||||||
userId: this.client.userId,
|
userId: this.client.userId,
|
||||||
partnerId: this.client.partnerId,
|
partnerId: this.client.partnerId,
|
||||||
A006: this.client.a(),
|
A006: keys.a(),
|
||||||
X002: this.client.x(),
|
X002: keys.x(),
|
||||||
E002: this.client.e(),
|
E002: keys.e(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return templ(data);
|
return templ(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async serialize(path) {
|
||||||
|
const letter = await this.generate();
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(path, letter);
|
||||||
|
console.log("Data written to file");
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user