wip: migrate MFG1 to BigNumber

This commit is contained in:
nanov 2019-11-06 17:16:56 +02:00
parent cda36bfcb3
commit bb8d1cfaa0

View File

@ -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 = {