mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-12-23 12:51:48 +00:00
wip: migrate MFG1 to BigNumber
This commit is contained in:
parent
cda36bfcb3
commit
bb8d1cfaa0
@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const BN = require('bn.js');
|
||||
|
||||
const BigNumber = require('../BigNumber.js');
|
||||
|
||||
const MFG_LEN = 32;
|
||||
|
||||
const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise
|
||||
const rjust = (string, width, padding) => {
|
||||
padding = padding || ' ';
|
||||
const rjust = (string, width, padding = ' ') => {
|
||||
padding = padding.substr(0, 1);
|
||||
if (string.length < width)
|
||||
return padding.repeat(width - string.length) + string;
|
||||
@ -26,7 +26,7 @@ const i2osp = (x, len) => {
|
||||
if (x >= 256 ** len)
|
||||
throw new Error('Integer too large');
|
||||
|
||||
return Buffer.from(rjust((Buffer.from((new BN(x)).toArray('be', 4)).toString()).replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex
|
||||
return Buffer.from(rjust(new BigNumber(x).toBEBuffer(4).toString().replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user