From 53d320be3eab478caffaaa641c402790b237eb34 Mon Sep 17 00:00:00 2001 From: krlosMata Date: Mon, 2 Oct 2023 11:06:34 +0200 Subject: [PATCH] stringify null object --- src/utils.js | 2 ++ test/utils.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/utils.js b/src/utils.js index f1eb893..a52d3b5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,6 +2,8 @@ import * as Scalar from "./scalar.js"; export function stringifyBigInts(o) { + if (o === null) return null; + if (typeof o == "bigint" || o.eq !== undefined) { return o.toString(10); } else if (o instanceof Uint8Array) { diff --git a/test/utils.js b/test/utils.js index 80799ac..6a57075 100644 --- a/test/utils.js +++ b/test/utils.js @@ -28,6 +28,18 @@ describe("Utils native", () => { assert(ScalarN.eq(num, numFromStr), true); }); + it("Should stringify bigInt & null", () => { + const obj = { + num: num, + other: null + }; + + const strObj = utilsN.stringifyBigInts(obj); + const objFromStr = utilsN.unstringifyBigInts(strObj); + + assert.deepStrictEqual(obj, objFromStr); + }); + it("Should generate buffer little-endian without trailing non-zero element", () => { for (let i = 1; i < 33; i++) { var buff = utilsN.leInt2Buff(BigInt(42), i);