Skip to content

Commit

Permalink
stringify null object
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Oct 2, 2023
1 parent d1cd4ae commit 53d320b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 53d320b

Please sign in to comment.