Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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