From a3b11933ef1db07b0a5f3d393fb5b889587e8734 Mon Sep 17 00:00:00 2001 From: bkrith Date: Fri, 22 Feb 2019 02:44:22 +0200 Subject: [PATCH] Added BigInt Support --- .gitignore | 3 ++- lib/types.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b512c09..448c205 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.directory diff --git a/lib/types.js b/lib/types.js index 055635b..1a12d3b 100644 --- a/lib/types.js +++ b/lib/types.js @@ -153,6 +153,23 @@ module.exports.Buffer = { } } +/* + * bigInt - big integers + */ +module.exports.bigint = { + write: function (BN, data, path) { + if (typeof(BN) !== 'bigint') { + throw new TypeError('Expected a BigInt at ' + path + ', got ' + BN) + } + console.log(BN.toString(16)) + console.log(new Buffer(BN.toString(16), 'hex')); + exports.Buffer.write(new Buffer(BN.toString(16), 'hex'), data, path) + }, + read: function (state) { + return BigInt('0x' + exports.Buffer.read(state).toString('hex')) + } +} + /* * either 0x00 or 0x01 */ @@ -241,4 +258,4 @@ module.exports.date = { read: function (state) { return new Date(exports.uint.read(state)) } -} \ No newline at end of file +}