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'; 'use strict';
const crypto = require('crypto'); const crypto = require('crypto');
const BN = require('bn.js');
const BigNumber = require('../BigNumber.js');
const MFG_LEN = 32; const MFG_LEN = 32;
const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise
const rjust = (string, width, padding) => { const rjust = (string, width, padding = ' ') => {
padding = padding || ' ';
padding = padding.substr(0, 1); padding = padding.substr(0, 1);
if (string.length < width) if (string.length < width)
return padding.repeat(width - string.length) + string; return padding.repeat(width - string.length) + string;
@ -26,7 +26,7 @@ const i2osp = (x, len) => {
if (x >= 256 ** len) if (x >= 256 ** len)
throw new Error('Integer too large'); 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 = { module.exports = {