mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-22 06:02:09 +00:00
wip: implement BigNumber wrapper
This commit is contained in:
parent
d21d89fb36
commit
cda36bfcb3
20
lib/BigNumber.js
Normal file
20
lib/BigNumber.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { jsbn: { BigInteger } } = require('node-forge');
|
||||||
|
|
||||||
|
class BigNumber {
|
||||||
|
constructor(value = '') {
|
||||||
|
this._n = new BigInteger(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
toBEBuffer(length = undefined) {
|
||||||
|
const arr = this._n.toByteArray();
|
||||||
|
if (length && arr.length > length)
|
||||||
|
throw new Error('Number out of range.');
|
||||||
|
while (arr.length < length)
|
||||||
|
arr.unshift(0);
|
||||||
|
return Buffer.from(arr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BigNumber;
|
Loading…
Reference in New Issue
Block a user