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);