Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringify null object #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Loading